2323import static java .lang .Math .min ;
2424
2525import android .graphics .Canvas ;
26+ import android .graphics .Color ;
2627import android .graphics .Paint ;
2728import android .graphics .Paint .Style ;
2829import android .graphics .Path ;
2930import android .graphics .Rect ;
3031import android .graphics .RectF ;
32+ import androidx .annotation .ColorInt ;
3133import androidx .annotation .FloatRange ;
3234import androidx .annotation .IntRange ;
3335import androidx .annotation .NonNull ;
@@ -165,33 +167,9 @@ void fillIndicator(
165167 adjustedEndX ,
166168 displayedTrackThickness / 2 );
167169 canvas .drawRoundRect (indicatorBounds , displayedCornerRadius , displayedCornerRadius , paint );
168-
169- // Draw stop indicator
170- if (spec .trackStopIndicatorSize > 0 ) {
171- drawStopIndicator (canvas , paint , drawableAlpha );
172- }
173170 canvas .restore ();
174171 }
175172
176- private void drawStopIndicator (
177- @ NonNull Canvas canvas ,
178- @ NonNull Paint paint ,
179- @ IntRange (from = 0 , to = 255 ) int drawableAlpha ) {
180- int indicatorColor =
181- MaterialColors .compositeARGBWithAlpha (spec .indicatorColors [0 ], drawableAlpha );
182- paint .setColor (indicatorColor );
183- Rect trackBounds = canvas .getClipBounds ();
184- // Maintain proper ratio when stop is smaller than track height and offset from edges.
185- float offset = max (0 , displayedTrackThickness - spec .trackStopIndicatorSize );
186- RectF stopBounds =
187- new RectF (
188- trackBounds .right - displayedTrackThickness + offset / 2 ,
189- -(displayedTrackThickness - offset ) / 2 ,
190- trackBounds .right - offset / 2 ,
191- (displayedTrackThickness - offset ) / 2 );
192- canvas .drawRoundRect (stopBounds , displayedCornerRadius , displayedCornerRadius , paint );
193- }
194-
195173 @ Override
196174 void fillTrack (
197175 @ NonNull Canvas canvas ,
@@ -215,4 +193,32 @@ void fillTrack(
215193 Path .Direction .CCW );
216194 canvas .drawPath (displayedTrackPath , paint );
217195 }
196+
197+ @ Override
198+ void drawStopIndicator (
199+ @ NonNull Canvas canvas ,
200+ @ NonNull Paint paint ,
201+ @ ColorInt int color ,
202+ @ IntRange (from = 0 , to = 255 ) int drawableAlpha ) {
203+ int paintColor = MaterialColors .compositeARGBWithAlpha (color , drawableAlpha );
204+ if (spec .trackStopIndicatorSize > 0 && paintColor != Color .TRANSPARENT ) {
205+ // Draws the stop indicator at the end of the track if needed.
206+ paint .setStyle (Style .FILL );
207+ paint .setAntiAlias (true );
208+ paint .setColor (paintColor );
209+ canvas .save ();
210+ // Avoid the indicator being drawn out of the track.
211+ canvas .clipPath (displayedTrackPath );
212+ Rect trackBounds = canvas .getClipBounds ();
213+ float offset = max (0 , displayedTrackThickness - spec .trackStopIndicatorSize );
214+ RectF stopBounds =
215+ new RectF (
216+ trackBounds .right - displayedTrackThickness + offset / 2 ,
217+ -(displayedTrackThickness - offset ) / 2 ,
218+ trackBounds .right - offset / 2 ,
219+ (displayedTrackThickness - offset ) / 2 );
220+ canvas .drawRoundRect (stopBounds , displayedCornerRadius , displayedCornerRadius , paint );
221+ canvas .restore ();
222+ }
223+ }
218224}
0 commit comments