@@ -330,10 +330,14 @@ abstract class BaseSlider<
330
330
private int trackCornerSize ;
331
331
private int trackInsideCornerSize ;
332
332
@ Nullable private Drawable trackIconActiveStart ;
333
+ private boolean trackIconActiveStartMutated = false ;
333
334
@ Nullable private Drawable trackIconActiveEnd ;
335
+ private boolean trackIconActiveEndMutated = false ;
334
336
@ Nullable private ColorStateList trackIconActiveColor ;
335
337
@ Nullable private Drawable trackIconInactiveStart ;
338
+ private boolean trackIconInactiveStartMutated = false ;
336
339
@ Nullable private Drawable trackIconInactiveEnd ;
340
+ private boolean trackIconInactiveEndMutated = false ;
337
341
@ Nullable private ColorStateList trackIconInactiveColor ;
338
342
@ Px private int trackIconSize ;
339
343
private int labelPadding ;
@@ -1992,13 +1996,29 @@ public void setTrackInsideCornerSize(@Px int cornerSize) {
1992
1996
* @see #getTrackIconActiveStart()
1993
1997
*/
1994
1998
public void setTrackIconActiveStart (@ Nullable Drawable icon ) {
1995
- if (this . trackIconActiveStart == icon ) {
1999
+ if (icon == trackIconActiveStart ) {
1996
2000
return ;
1997
2001
}
1998
- this .trackIconActiveStart = icon ;
2002
+
2003
+ trackIconActiveStart = icon ;
2004
+ trackIconActiveStartMutated = false ;
2005
+ updateTrackIconActiveStart ();
1999
2006
invalidate ();
2000
2007
}
2001
2008
2009
+ private void updateTrackIconActiveStart () {
2010
+ if (trackIconActiveStart != null ) {
2011
+ if (!trackIconActiveStartMutated && trackIconActiveColor != null ) {
2012
+ trackIconActiveStart = DrawableCompat .wrap (trackIconActiveStart ).mutate ();
2013
+ trackIconActiveStartMutated = true ;
2014
+ }
2015
+
2016
+ if (trackIconActiveStartMutated ) {
2017
+ DrawableCompat .setTintList (trackIconActiveStart , trackIconActiveColor );
2018
+ }
2019
+ }
2020
+ }
2021
+
2002
2022
/**
2003
2023
* Sets the active track start icon.
2004
2024
*
@@ -2037,13 +2057,29 @@ public Drawable getTrackIconActiveStart() {
2037
2057
* @see #getTrackIconActiveEnd()
2038
2058
*/
2039
2059
public void setTrackIconActiveEnd (@ Nullable Drawable icon ) {
2040
- if (this . trackIconActiveEnd == icon ) {
2060
+ if (icon == trackIconActiveEnd ) {
2041
2061
return ;
2042
2062
}
2043
- this .trackIconActiveEnd = icon ;
2063
+
2064
+ trackIconActiveEnd = icon ;
2065
+ trackIconActiveEndMutated = false ;
2066
+ updateTrackIconActiveEnd ();
2044
2067
invalidate ();
2045
2068
}
2046
2069
2070
+ private void updateTrackIconActiveEnd () {
2071
+ if (trackIconActiveEnd != null ) {
2072
+ if (!trackIconActiveEndMutated && trackIconActiveColor != null ) {
2073
+ trackIconActiveEnd = DrawableCompat .wrap (trackIconActiveEnd ).mutate ();
2074
+ trackIconActiveEndMutated = true ;
2075
+ }
2076
+
2077
+ if (trackIconActiveEndMutated ) {
2078
+ DrawableCompat .setTintList (trackIconActiveEnd , trackIconActiveColor );
2079
+ }
2080
+ }
2081
+ }
2082
+
2047
2083
/**
2048
2084
* Sets the active track end icon.
2049
2085
*
@@ -2107,10 +2143,13 @@ public int getTrackIconSize() {
2107
2143
* @see #getTrackIconActiveColor()
2108
2144
*/
2109
2145
public void setTrackIconActiveColor (@ Nullable ColorStateList color ) {
2110
- if (this . trackIconActiveColor == color ) {
2146
+ if (color == trackIconActiveColor ) {
2111
2147
return ;
2112
2148
}
2113
- this .trackIconActiveColor = color ;
2149
+
2150
+ trackIconActiveColor = color ;
2151
+ updateTrackIconActiveStart ();
2152
+ updateTrackIconActiveEnd ();
2114
2153
invalidate ();
2115
2154
}
2116
2155
@@ -2135,13 +2174,29 @@ public ColorStateList getTrackIconActiveColor() {
2135
2174
* @see #getTrackIconInactiveStart()
2136
2175
*/
2137
2176
public void setTrackIconInactiveStart (@ Nullable Drawable icon ) {
2138
- if (this . trackIconInactiveStart == icon ) {
2177
+ if (icon == trackIconInactiveStart ) {
2139
2178
return ;
2140
2179
}
2141
- this .trackIconInactiveStart = icon ;
2180
+
2181
+ trackIconInactiveStart = icon ;
2182
+ trackIconInactiveStartMutated = false ;
2183
+ updateTrackIconInactiveStart ();
2142
2184
invalidate ();
2143
2185
}
2144
2186
2187
+ private void updateTrackIconInactiveStart () {
2188
+ if (trackIconInactiveStart != null ) {
2189
+ if (!trackIconInactiveStartMutated && trackIconInactiveColor != null ) {
2190
+ trackIconInactiveStart = DrawableCompat .wrap (trackIconInactiveStart ).mutate ();
2191
+ trackIconInactiveStartMutated = true ;
2192
+ }
2193
+
2194
+ if (trackIconInactiveStartMutated ) {
2195
+ DrawableCompat .setTintList (trackIconInactiveStart , trackIconInactiveColor );
2196
+ }
2197
+ }
2198
+ }
2199
+
2145
2200
/**
2146
2201
* Sets the inactive track start icon.
2147
2202
*
@@ -2180,13 +2235,29 @@ public Drawable getTrackIconInactiveStart() {
2180
2235
* @see #getTrackIconInactiveEnd()
2181
2236
*/
2182
2237
public void setTrackIconInactiveEnd (@ Nullable Drawable icon ) {
2183
- if (this . trackIconInactiveEnd == icon ) {
2238
+ if (icon == trackIconInactiveEnd ) {
2184
2239
return ;
2185
2240
}
2186
- this .trackIconInactiveEnd = icon ;
2241
+
2242
+ trackIconInactiveEnd = icon ;
2243
+ trackIconInactiveEndMutated = false ;
2244
+ updateTrackIconInactiveEnd ();
2187
2245
invalidate ();
2188
2246
}
2189
2247
2248
+ private void updateTrackIconInactiveEnd () {
2249
+ if (trackIconInactiveEnd != null ) {
2250
+ if (!trackIconInactiveEndMutated && trackIconInactiveColor != null ) {
2251
+ trackIconInactiveEnd = DrawableCompat .wrap (trackIconInactiveEnd ).mutate ();
2252
+ trackIconInactiveEndMutated = true ;
2253
+ }
2254
+
2255
+ if (trackIconInactiveEndMutated ) {
2256
+ DrawableCompat .setTintList (trackIconInactiveEnd , trackIconInactiveColor );
2257
+ }
2258
+ }
2259
+ }
2260
+
2190
2261
/**
2191
2262
* Sets the inactive track end icon.
2192
2263
*
@@ -2224,10 +2295,13 @@ public Drawable getTrackIconInactiveEnd() {
2224
2295
* @see #getTrackIconInactiveColor()
2225
2296
*/
2226
2297
public void setTrackIconInactiveColor (@ Nullable ColorStateList color ) {
2227
- if (this . trackIconInactiveColor == color ) {
2298
+ if (color == trackIconInactiveColor ) {
2228
2299
return ;
2229
2300
}
2230
- this .trackIconInactiveColor = color ;
2301
+
2302
+ trackIconInactiveColor = color ;
2303
+ updateTrackIconInactiveStart ();
2304
+ updateTrackIconInactiveEnd ();
2231
2305
invalidate ();
2232
2306
}
2233
2307
@@ -2596,36 +2670,33 @@ private void drawTrackIcons(
2596
2670
2597
2671
// draw track start icons
2598
2672
calculateBoundsAndDrawTrackIcon (
2599
- canvas , activeTrackBounds , trackIconActiveStart , trackIconActiveColor , true );
2673
+ canvas , activeTrackBounds , trackIconActiveStart , true );
2600
2674
calculateBoundsAndDrawTrackIcon (
2601
- canvas , inactiveTrackBounds , trackIconInactiveStart , trackIconInactiveColor , true );
2675
+ canvas , inactiveTrackBounds , trackIconInactiveStart , true );
2602
2676
// draw track end icons
2603
2677
calculateBoundsAndDrawTrackIcon (
2604
- canvas , activeTrackBounds , trackIconActiveEnd , trackIconActiveColor , false );
2678
+ canvas , activeTrackBounds , trackIconActiveEnd , false );
2605
2679
calculateBoundsAndDrawTrackIcon (
2606
- canvas , inactiveTrackBounds , trackIconInactiveEnd , trackIconInactiveColor , false );
2680
+ canvas , inactiveTrackBounds , trackIconInactiveEnd , false );
2607
2681
}
2608
2682
2609
2683
private void calculateBoundsAndDrawTrackIcon (
2610
2684
@ NonNull Canvas canvas ,
2611
2685
@ NonNull RectF trackBounds ,
2612
2686
@ Nullable Drawable icon ,
2613
- @ Nullable ColorStateList iconColor ,
2614
2687
boolean isStart ) {
2615
2688
if (icon != null ) {
2616
2689
calculateTrackIconBounds (trackBounds , iconRectF , trackIconSize , isStart );
2617
2690
if (!iconRectF .isEmpty ()) {
2618
- drawTrackIcon (canvas , iconRectF , icon , iconColor );
2691
+ drawTrackIcon (canvas , iconRectF , icon );
2619
2692
}
2620
2693
}
2621
2694
}
2622
2695
2623
2696
private void drawTrackIcon (
2624
2697
@ NonNull Canvas canvas ,
2625
2698
@ NonNull RectF iconBounds ,
2626
- @ NonNull Drawable icon ,
2627
- @ Nullable ColorStateList color ) {
2628
- DrawableCompat .setTintList (icon , color );
2699
+ @ NonNull Drawable icon ) {
2629
2700
if (isVertical ()) {
2630
2701
rotationMatrix .mapRect (iconBounds );
2631
2702
}
0 commit comments