@@ -368,7 +368,8 @@ abstract class BaseSlider<
368
368
369
369
@ NonNull private final Path trackPath = new Path ();
370
370
@ NonNull private final RectF activeTrackRect = new RectF ();
371
- @ NonNull private final RectF inactiveTrackRect = new RectF ();
371
+ @ NonNull private final RectF inactiveTrackLeftRect = new RectF ();
372
+ @ NonNull private final RectF inactiveTrackRightRect = new RectF ();
372
373
@ NonNull private final RectF cornerRect = new RectF ();
373
374
@ NonNull private final Rect labelRect = new Rect ();
374
375
@ NonNull private final RectF iconRectF = new RectF ();
@@ -2410,15 +2411,14 @@ protected void onDraw(@NonNull Canvas canvas) {
2410
2411
2411
2412
int yCenter = calculateTrackCenter ();
2412
2413
2413
- float first = values . get ( 0 );
2414
- float last = values . get ( values . size () - 1 );
2415
- if ( last < valueTo || ( values . size () > 1 && first > valueFrom )) {
2416
- drawInactiveTrack ( canvas , trackWidth , yCenter );
2417
- }
2418
- if ( last > valueFrom ) {
2419
- drawActiveTrack (canvas , trackWidth , yCenter );
2414
+ drawInactiveTracks ( canvas , trackWidth , yCenter );
2415
+ drawActiveTracks ( canvas , trackWidth , yCenter );
2416
+
2417
+ if ( isRtl () || isVertical ()) {
2418
+ drawTrackIcons ( canvas , activeTrackRect , inactiveTrackLeftRect );
2419
+ } else {
2420
+ drawTrackIcons (canvas , activeTrackRect , inactiveTrackRightRect );
2420
2421
}
2421
- drawTrackIcons (canvas , activeTrackRect , inactiveTrackRect );
2422
2422
2423
2423
maybeDrawTicks (canvas );
2424
2424
maybeDrawStopIndicator (canvas , yCenter );
@@ -2446,34 +2446,50 @@ private float[] getActiveRange() {
2446
2446
return isRtl () || isVertical () ? new float [] {right , left } : new float [] {left , right };
2447
2447
}
2448
2448
2449
- private void drawInactiveTrack (@ NonNull Canvas canvas , int width , int yCenter ) {
2450
- int trackCornerSize = getTrackCornerSize ();
2449
+ private void drawInactiveTracks (@ NonNull Canvas canvas , int width , int yCenter ) {
2450
+ populateInactiveTrackRightRect (width , yCenter );
2451
+ updateTrack (
2452
+ canvas ,
2453
+ inactiveTrackPaint ,
2454
+ inactiveTrackRightRect ,
2455
+ getTrackCornerSize (),
2456
+ FullCornerDirection .RIGHT );
2457
+
2458
+ // Also draw inactive track to the left if there is any
2459
+ populateInactiveTrackLeftRect (width , yCenter );
2460
+ updateTrack (
2461
+ canvas ,
2462
+ inactiveTrackPaint ,
2463
+ inactiveTrackLeftRect ,
2464
+ getTrackCornerSize (),
2465
+ FullCornerDirection .LEFT );
2466
+ }
2467
+
2468
+ private void populateInactiveTrackRightRect (int width , int yCenter ) {
2451
2469
float [] activeRange = getActiveRange ();
2452
2470
float right = trackSidePadding + activeRange [1 ] * width ;
2453
2471
if (right < trackSidePadding + width ) {
2454
- inactiveTrackRect .set (
2472
+ inactiveTrackRightRect .set (
2455
2473
right + thumbTrackGapSize ,
2456
2474
yCenter - trackThickness / 2f ,
2457
- trackSidePadding + width + trackCornerSize ,
2475
+ trackSidePadding + width + getTrackCornerSize () ,
2458
2476
yCenter + trackThickness / 2f );
2459
- updateTrack (
2460
- canvas ,
2461
- inactiveTrackPaint ,
2462
- inactiveTrackRect ,
2463
- trackCornerSize ,
2464
- FullCornerDirection .RIGHT );
2477
+ } else {
2478
+ inactiveTrackRightRect .setEmpty ();
2465
2479
}
2480
+ }
2466
2481
2467
- // Also draw inactive track to the left if there is any
2482
+ private void populateInactiveTrackLeftRect (int width , int yCenter ) {
2483
+ float [] activeRange = getActiveRange ();
2468
2484
float left = trackSidePadding + activeRange [0 ] * width ;
2469
2485
if (left > trackSidePadding ) {
2470
- inactiveTrackRect .set (
2471
- trackSidePadding - trackCornerSize ,
2486
+ inactiveTrackLeftRect .set (
2487
+ trackSidePadding - getTrackCornerSize () ,
2472
2488
yCenter - trackThickness / 2f ,
2473
2489
left - thumbTrackGapSize ,
2474
2490
yCenter + trackThickness / 2f );
2475
- updateTrack (
2476
- canvas , inactiveTrackPaint , inactiveTrackRect , trackCornerSize , FullCornerDirection . LEFT );
2491
+ } else {
2492
+ inactiveTrackLeftRect . setEmpty ( );
2477
2493
}
2478
2494
}
2479
2495
@@ -2489,10 +2505,14 @@ private float normalizeValue(float value) {
2489
2505
return normalized ;
2490
2506
}
2491
2507
2492
- private void drawActiveTrack (@ NonNull Canvas canvas , int width , int yCenter ) {
2508
+ private void drawActiveTracks (@ NonNull Canvas canvas , int width , int yCenter ) {
2493
2509
float [] activeRange = getActiveRange ();
2494
2510
float right = trackSidePadding + activeRange [1 ] * width ;
2495
2511
float left = trackSidePadding + activeRange [0 ] * width ;
2512
+ if (left >= right ) {
2513
+ activeTrackRect .setEmpty ();
2514
+ return ;
2515
+ }
2496
2516
2497
2517
FullCornerDirection direction = FullCornerDirection .NONE ;
2498
2518
if (values .size () == 1 ) { // Only 1 thumb
@@ -2532,6 +2552,7 @@ private void drawActiveTrack(@NonNull Canvas canvas, int width, int yCenter) {
2532
2552
2533
2553
// Nothing to draw if left is bigger than right.
2534
2554
if (left >= right ) {
2555
+ activeTrackRect .setEmpty ();
2535
2556
continue ;
2536
2557
}
2537
2558
@@ -2652,6 +2673,10 @@ private enum FullCornerDirection {
2652
2673
2653
2674
private void updateTrack (
2654
2675
Canvas canvas , Paint paint , RectF bounds , float cornerSize , FullCornerDirection direction ) {
2676
+ if (bounds .isEmpty ()) {
2677
+ return ;
2678
+ }
2679
+
2655
2680
float leftCornerSize = calculateStartTrackCornerSize (cornerSize );
2656
2681
float rightCornerSize = calculateEndTrackCornerSize (cornerSize );
2657
2682
switch (direction ) {
0 commit comments