Skip to content

Commit b2deaa3

Browse files
cketchamdsn5ft
authored andcommitted
Update the radius of the Slider RippleDrawable
PiperOrigin-RevId: 286239127
1 parent d49fff3 commit b2deaa3

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

lib/java/com/google/android/material/drawable/DrawableUtils.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,9 @@ public static AttributeSet parseDrawableXml(
9696
}
9797

9898
@TargetApi(VERSION_CODES.LOLLIPOP)
99-
public static void setRippleDrawableRadius(@Nullable Drawable drawable, int radius) {
100-
if (!(drawable instanceof RippleDrawable)) {
101-
return;
102-
}
103-
99+
public static void setRippleDrawableRadius(@Nullable RippleDrawable drawable, int radius) {
104100
if (VERSION.SDK_INT >= VERSION_CODES.M) {
105-
((RippleDrawable) drawable).setRadius(radius);
101+
drawable.setRadius(radius);
106102
} else {
107103
try {
108104
@SuppressLint("PrivateApi")

lib/java/com/google/android/material/slider/Slider.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,10 @@ public Slider(@NonNull Context context, @Nullable AttributeSet attrs, int defSty
293293
activeTicksPaint.setStrokeWidth(trackHeight / 2.0f);
294294
activeTicksPaint.setStrokeCap(Cap.ROUND);
295295

296-
Drawable background = getBackground();
297296
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
297+
Drawable background = getBackground();
298298
if (background instanceof RippleDrawable) {
299299
((RippleDrawable) background).setColor(haloColor);
300-
DrawableUtils.setRippleDrawableRadius(background, haloRadius);
301300
}
302301
// Because the RippleDrawable can draw outside the bounds of the view, we can set the layer
303302
// type to hardware so we can use PorterDuffXfermode when drawing.
@@ -361,7 +360,7 @@ private void processAttributes(Context context, AttributeSet attrs, int defStyle
361360
label = parseLabelDrawable(context, a);
362361

363362
setThumbRadius(a.getDimensionPixelSize(R.styleable.Slider_thumbRadius, 0));
364-
haloRadius = a.getDimensionPixelSize(R.styleable.Slider_haloRadius, 0);
363+
setHaloRadius(a.getDimensionPixelSize(R.styleable.Slider_haloRadius, 0));
365364

366365
setThumbElevation(a.getDimension(R.styleable.Slider_thumbElevation, 0));
367366

@@ -673,6 +672,12 @@ public int getHaloRadius() {
673672
*/
674673
public void setHaloRadius(@IntRange(from = 0) @Dimension int radius) {
675674
haloRadius = radius;
675+
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
676+
Drawable background = getBackground();
677+
if (background instanceof RippleDrawable) {
678+
DrawableUtils.setRippleDrawableRadius((RippleDrawable) background, haloRadius);
679+
}
680+
}
676681
postInvalidate();
677682
}
678683

0 commit comments

Comments
 (0)