@@ -2218,25 +2218,41 @@ private void maybeDrawTicks(@NonNull Canvas canvas) {
2218
2218
}
2219
2219
2220
2220
float [] activeRange = getActiveRange ();
2221
- int leftPivotIndex = pivotIndex (ticksCoordinates , activeRange [0 ]);
2222
- int rightPivotIndex = pivotIndex (ticksCoordinates , activeRange [1 ]);
2223
2221
2224
- // Draw inactive ticks to the left of the smallest thumb.
2225
- canvas .drawPoints (ticksCoordinates , 0 , leftPivotIndex * 2 , inactiveTicksPaint );
2222
+ // Calculate the index of the left tick of the active track.
2223
+ final int leftActiveTickIndex =
2224
+ (int ) Math .ceil (activeRange [0 ] * (ticksCoordinates .length / 2f - 1 ));
2226
2225
2227
- // Draw active ticks between the thumbs.
2228
- canvas .drawPoints (
2229
- ticksCoordinates ,
2230
- leftPivotIndex * 2 ,
2231
- rightPivotIndex * 2 - leftPivotIndex * 2 ,
2232
- activeTicksPaint );
2226
+ // Calculate the index of the right tick of the active track.
2227
+ final int rightActiveTickIndex =
2228
+ (int ) Math .floor (activeRange [1 ] * (ticksCoordinates .length / 2f - 1 ));
2233
2229
2234
- // Draw inactive ticks to the right of the largest thumb.
2235
- canvas .drawPoints (
2236
- ticksCoordinates ,
2237
- rightPivotIndex * 2 ,
2238
- ticksCoordinates .length - rightPivotIndex * 2 ,
2239
- inactiveTicksPaint );
2230
+ // Draw ticks on the left inactive track (if any).
2231
+ if (leftActiveTickIndex > 0 ) {
2232
+ canvas .drawPoints (
2233
+ ticksCoordinates ,
2234
+ 0 ,
2235
+ leftActiveTickIndex * 2 ,
2236
+ inactiveTicksPaint );
2237
+ }
2238
+
2239
+ // Draw ticks on the active track (if any).
2240
+ if (leftActiveTickIndex <= rightActiveTickIndex ) {
2241
+ canvas .drawPoints (
2242
+ ticksCoordinates ,
2243
+ leftActiveTickIndex * 2 ,
2244
+ (rightActiveTickIndex - leftActiveTickIndex + 1 ) * 2 ,
2245
+ activeTicksPaint );
2246
+ }
2247
+
2248
+ // Draw ticks on the right inactive track (if any).
2249
+ if ((rightActiveTickIndex + 1 ) * 2 < ticksCoordinates .length ) {
2250
+ canvas .drawPoints (
2251
+ ticksCoordinates ,
2252
+ (rightActiveTickIndex + 1 ) * 2 ,
2253
+ ticksCoordinates .length - (rightActiveTickIndex + 1 ) * 2 ,
2254
+ inactiveTicksPaint );
2255
+ }
2240
2256
}
2241
2257
2242
2258
private void maybeDrawStopIndicator (@ NonNull Canvas canvas , int yCenter ) {
@@ -2413,17 +2429,6 @@ && abs(lastEvent.getY() - event.getY()) <= scaledTouchSlop) {
2413
2429
return true ;
2414
2430
}
2415
2431
2416
- /**
2417
- * Calculates the index the closest tick coordinates that the thumb should snap to.
2418
- *
2419
- * @param coordinates Tick coordinates defined in {@code #setTicksCoordinates()}.
2420
- * @param position Actual thumb position.
2421
- * @return Index of the closest tick coordinate.
2422
- */
2423
- private static int pivotIndex (float [] coordinates , float position ) {
2424
- return Math .round (position * (coordinates .length / 2f - 1 ));
2425
- }
2426
-
2427
2432
private double snapPosition (float position ) {
2428
2433
if (stepSize > 0.0f ) {
2429
2434
int stepCount = (int ) ((valueTo - valueFrom ) / stepSize );
0 commit comments