|
63 | 63 | import android.os.Bundle;
|
64 | 64 | import android.os.Parcel;
|
65 | 65 | import android.os.Parcelable;
|
| 66 | +import androidx.annotation.RequiresApi; |
66 | 67 | import androidx.appcompat.content.res.AppCompatResources;
|
67 | 68 | import android.util.AttributeSet;
|
68 | 69 | import android.util.Log;
|
@@ -265,6 +266,7 @@ abstract class BaseSlider<
|
265 | 266 | private static final double THRESHOLD = .0001;
|
266 | 267 | private static final float THUMB_WIDTH_PRESSED_RATIO = .5f;
|
267 | 268 | private static final int TRACK_CORNER_SIZE_UNSET = -1;
|
| 269 | + private static final int DEFAULT_HALO_EFFECT_COLOR = 0x8dffffff; |
268 | 270 |
|
269 | 271 | static final int DEF_STYLE_RES = R.style.Widget_MaterialComponents_Slider;
|
270 | 272 | static final int UNIT_VALUE = 1;
|
@@ -361,6 +363,7 @@ abstract class BaseSlider<
|
361 | 363 | private boolean dirtyConfig;
|
362 | 364 |
|
363 | 365 | @NonNull private ColorStateList haloColor;
|
| 366 | + @NonNull private ColorStateList haloEffectColor; |
364 | 367 | @NonNull private ColorStateList tickColorActive;
|
365 | 368 | @NonNull private ColorStateList tickColorInactive;
|
366 | 369 | @NonNull private ColorStateList trackColorActive;
|
@@ -566,6 +569,15 @@ private void processAttributes(Context context, AttributeSet attrs, int defStyle
|
566 | 569 | ? haloColor
|
567 | 570 | : AppCompatResources.getColorStateList(context, R.color.material_slider_halo_color));
|
568 | 571 |
|
| 572 | + if (VERSION.SDK_INT >= VERSION_CODES.S) { |
| 573 | + ColorStateList haloEffectColor = |
| 574 | + MaterialResources.getColorStateList(context, a, R.styleable.Slider_haloEffectColor); |
| 575 | + setHaloEffectTintList( |
| 576 | + haloEffectColor != null |
| 577 | + ? haloEffectColor |
| 578 | + : ColorStateList.valueOf(DEFAULT_HALO_EFFECT_COLOR)); |
| 579 | + } |
| 580 | + |
569 | 581 | tickVisible = a.getBoolean(R.styleable.Slider_tickVisible, true);
|
570 | 582 | boolean hasTickColor = a.hasValue(R.styleable.Slider_tickColor);
|
571 | 583 | int tickColorInactiveRes =
|
@@ -1646,6 +1658,39 @@ public void setHaloTintList(@NonNull ColorStateList haloColor) {
|
1646 | 1658 | invalidate();
|
1647 | 1659 | }
|
1648 | 1660 |
|
| 1661 | + /** |
| 1662 | + * Returns the effect color of the halo. |
| 1663 | + * |
| 1664 | + * @see #setHaloEffectTintList(ColorStateList) |
| 1665 | + * @attr ref com.google.android.material.R.styleable#Slider_haloEffectColor |
| 1666 | + */ |
| 1667 | + @RequiresApi(api = VERSION_CODES.S) |
| 1668 | + @NonNull |
| 1669 | + public ColorStateList getHaloEffectTintList() { |
| 1670 | + return haloEffectColor; |
| 1671 | + } |
| 1672 | + |
| 1673 | + /** |
| 1674 | + * Sets the effect color of the halo. |
| 1675 | + * |
| 1676 | + * @see #getHaloEffectTintList() |
| 1677 | + * @attr ref com.google.android.material.R.styleable#Slider_haloEffectColor |
| 1678 | + */ |
| 1679 | + @RequiresApi(api = VERSION_CODES.S) |
| 1680 | + public void setHaloEffectTintList(@NonNull ColorStateList haloEffectColor) { |
| 1681 | + if (haloEffectColor.equals(this.haloEffectColor)) { |
| 1682 | + return; |
| 1683 | + } |
| 1684 | + |
| 1685 | + this.haloEffectColor = haloEffectColor; |
| 1686 | + |
| 1687 | + final Drawable background = getBackground(); |
| 1688 | + if (!shouldDrawCompatHalo() && background instanceof RippleDrawable) { |
| 1689 | + ((RippleDrawable) background).setEffectColor(haloEffectColor); |
| 1690 | + postInvalidate(); |
| 1691 | + } |
| 1692 | + } |
| 1693 | + |
1649 | 1694 | /**
|
1650 | 1695 | * Returns the color of the thumb.
|
1651 | 1696 | *
|
|
0 commit comments