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