|
66 | 66 | import android.os.Bundle;
|
67 | 67 | import android.os.Parcel;
|
68 | 68 | import android.os.Parcelable;
|
| 69 | +import androidx.annotation.RequiresApi; |
69 | 70 | import androidx.appcompat.content.res.AppCompatResources;
|
70 | 71 | import android.text.TextUtils;
|
71 | 72 | import android.util.AttributeSet;
|
@@ -271,6 +272,7 @@ abstract class BaseSlider<
|
271 | 272 | private static final float THUMB_WIDTH_PRESSED_RATIO = .5f;
|
272 | 273 | private static final int TRACK_CORNER_SIZE_UNSET = -1;
|
273 | 274 | private static final float TOUCH_SLOP_RATIO = .8f;
|
| 275 | + private static final int DEFAULT_HALO_EFFECT_COLOR = 0x8dffffff; |
274 | 276 |
|
275 | 277 | static final int DEF_STYLE_RES = R.style.Widget_MaterialComponents_Slider;
|
276 | 278 | static final int UNIT_VALUE = 1;
|
@@ -383,6 +385,7 @@ abstract class BaseSlider<
|
383 | 385 | private boolean dirtyConfig;
|
384 | 386 |
|
385 | 387 | @NonNull private ColorStateList haloColor;
|
| 388 | + @NonNull private ColorStateList haloEffectColor; |
386 | 389 | @NonNull private ColorStateList tickColorActive;
|
387 | 390 | @NonNull private ColorStateList tickColorInactive;
|
388 | 391 | @NonNull private ColorStateList trackColorActive;
|
@@ -592,6 +595,15 @@ private void processAttributes(Context context, AttributeSet attrs, int defStyle
|
592 | 595 | ? haloColor
|
593 | 596 | : AppCompatResources.getColorStateList(context, R.color.material_slider_halo_color));
|
594 | 597 |
|
| 598 | + if (VERSION.SDK_INT >= VERSION_CODES.S) { |
| 599 | + ColorStateList haloEffectColor = |
| 600 | + MaterialResources.getColorStateList(context, a, R.styleable.Slider_haloEffectColor); |
| 601 | + setHaloEffectTintList( |
| 602 | + haloEffectColor != null |
| 603 | + ? haloEffectColor |
| 604 | + : ColorStateList.valueOf(DEFAULT_HALO_EFFECT_COLOR)); |
| 605 | + } |
| 606 | + |
595 | 607 | tickVisibilityMode =
|
596 | 608 | a.hasValue(R.styleable.Slider_tickVisibilityMode)
|
597 | 609 | ? a.getInt(R.styleable.Slider_tickVisibilityMode, -1)
|
@@ -1665,6 +1677,39 @@ public void setHaloTintList(@NonNull ColorStateList haloColor) {
|
1665 | 1677 | invalidate();
|
1666 | 1678 | }
|
1667 | 1679 |
|
| 1680 | + /** |
| 1681 | + * Returns the effect color of the halo. |
| 1682 | + * |
| 1683 | + * @see #setHaloEffectTintList(ColorStateList) |
| 1684 | + * @attr ref com.google.android.material.R.styleable#Slider_haloEffectColor |
| 1685 | + */ |
| 1686 | + @RequiresApi(api = VERSION_CODES.S) |
| 1687 | + @NonNull |
| 1688 | + public ColorStateList getHaloEffectTintList() { |
| 1689 | + return haloEffectColor; |
| 1690 | + } |
| 1691 | + |
| 1692 | + /** |
| 1693 | + * Sets the effect color of the halo. |
| 1694 | + * |
| 1695 | + * @see #getHaloEffectTintList() |
| 1696 | + * @attr ref com.google.android.material.R.styleable#Slider_haloEffectColor |
| 1697 | + */ |
| 1698 | + @RequiresApi(api = VERSION_CODES.S) |
| 1699 | + public void setHaloEffectTintList(@NonNull ColorStateList haloEffectColor) { |
| 1700 | + if (haloEffectColor.equals(this.haloEffectColor)) { |
| 1701 | + return; |
| 1702 | + } |
| 1703 | + |
| 1704 | + this.haloEffectColor = haloEffectColor; |
| 1705 | + |
| 1706 | + final Drawable background = getBackground(); |
| 1707 | + if (!shouldDrawCompatHalo() && background instanceof RippleDrawable) { |
| 1708 | + ((RippleDrawable) background).setEffectColor(haloEffectColor); |
| 1709 | + postInvalidate(); |
| 1710 | + } |
| 1711 | + } |
| 1712 | + |
1668 | 1713 | /**
|
1669 | 1714 | * Returns the color of the thumb.
|
1670 | 1715 | *
|
|
0 commit comments