@@ -2218,25 +2218,41 @@ private void maybeDrawTicks(@NonNull Canvas canvas) {
22182218 }
22192219
22202220 float [] activeRange = getActiveRange ();
2221- int leftPivotIndex = pivotIndex (ticksCoordinates , activeRange [0 ]);
2222- int rightPivotIndex = pivotIndex (ticksCoordinates , activeRange [1 ]);
22232221
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 ));
22262225
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 ));
22332229
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+ }
22402256 }
22412257
22422258 private void maybeDrawStopIndicator (@ NonNull Canvas canvas , int yCenter ) {
@@ -2413,17 +2429,6 @@ && abs(lastEvent.getY() - event.getY()) <= scaledTouchSlop) {
24132429 return true ;
24142430 }
24152431
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-
24272432 private double snapPosition (float position ) {
24282433 if (stepSize > 0.0f ) {
24292434 int stepCount = (int ) ((valueTo - valueFrom ) / stepSize );
0 commit comments