23
23
import static java .lang .Math .min ;
24
24
25
25
import android .graphics .Canvas ;
26
+ import android .graphics .Color ;
26
27
import android .graphics .Paint ;
27
28
import android .graphics .Paint .Style ;
28
29
import android .graphics .Path ;
29
30
import android .graphics .Rect ;
30
31
import android .graphics .RectF ;
32
+ import androidx .annotation .ColorInt ;
31
33
import androidx .annotation .FloatRange ;
32
34
import androidx .annotation .IntRange ;
33
35
import androidx .annotation .NonNull ;
@@ -165,33 +167,9 @@ void fillIndicator(
165
167
adjustedEndX ,
166
168
displayedTrackThickness / 2 );
167
169
canvas .drawRoundRect (indicatorBounds , displayedCornerRadius , displayedCornerRadius , paint );
168
-
169
- // Draw stop indicator
170
- if (spec .trackStopIndicatorSize > 0 ) {
171
- drawStopIndicator (canvas , paint , drawableAlpha );
172
- }
173
170
canvas .restore ();
174
171
}
175
172
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
-
195
173
@ Override
196
174
void fillTrack (
197
175
@ NonNull Canvas canvas ,
@@ -215,4 +193,32 @@ void fillTrack(
215
193
Path .Direction .CCW );
216
194
canvas .drawPath (displayedTrackPath , paint );
217
195
}
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
+ }
218
224
}
0 commit comments