Skip to content

Commit b857c79

Browse files
ikim24ymarian
authored andcommitted
Change ripples on Chip to use the alphas provided in the ColorStateList.
RippleDrawable on different API levels will modulate the alphas differently for the pressed / focused / hovered states. Therefore, in order to get the desired alphas for pressed / focused / hovered states, we are using the mtrl_low_ripple_(pressed|focused|hovered|default)_alpha values which have been defined to account for the different implementations of RippleDrawable. PiperOrigin-RevId: 254737730
1 parent 0940c5f commit b857c79

4 files changed

Lines changed: 14 additions & 14 deletions

File tree

lib/java/com/google/android/material/chip/Chip.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ private void updateFrameworkRippleBackground() {
424424
//noinspection NewApi
425425
ripple =
426426
new RippleDrawable(
427-
RippleUtils.convertToRippleDrawableColor(chipDrawable.getRippleColor()),
427+
RippleUtils.sanitizeRippleDrawableColor(chipDrawable.getRippleColor()),
428428
getBackgroundDrawable(),
429429
null);
430430
chipDrawable.setUseCompatRipple(false);

lib/java/com/google/android/material/chip/ChipDrawable.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ private boolean onStateChange(int[] chipState, int[] closeIconState) {
10061006
}
10071007

10081008
int newCompatRippleColor =
1009-
compatRippleColor != null
1009+
compatRippleColor != null && RippleUtils.shouldDrawRippleCompat(chipState)
10101010
? compatRippleColor.getColorForState(chipState, currentCompatRippleColor)
10111011
: 0;
10121012
if (currentCompatRippleColor != newCompatRippleColor) {
@@ -1280,7 +1280,7 @@ private ColorFilter getTintColorFilter() {
12801280

12811281
private void updateCompatRippleColor() {
12821282
compatRippleColor =
1283-
useCompatRipple ? RippleUtils.convertToRippleDrawableColor(rippleColor) : null;
1283+
useCompatRipple ? RippleUtils.sanitizeRippleDrawableColor(rippleColor) : null;
12841284
}
12851285

12861286
private void setChipSurfaceColor(@Nullable ColorStateList chipSurfaceColor) {
@@ -1795,7 +1795,7 @@ public void setCloseIcon(@Nullable Drawable closeIcon) {
17951795
private void updateFrameworkCloseIconRipple() {
17961796
closeIconRipple =
17971797
new RippleDrawable(
1798-
RippleUtils.convertToRippleDrawableColor(getRippleColor()),
1798+
RippleUtils.sanitizeRippleDrawableColor(getRippleColor()),
17991799
closeIcon,
18001800
// A separate drawable with a solid background is needed for the mask because by
18011801
// default, the close icon has a transparent background.

lib/java/com/google/android/material/chip/res/color/mtrl_chip_ripple_color.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
<selector xmlns:android="http://schemas.android.com/apk/res/android">
1919

20-
<item android:alpha="0.16" android:color="?attr/colorOnSurface" android:state_pressed="true"/>
21-
<item android:alpha="0.16" android:color="?attr/colorOnSurface" android:state_focused="true" android:state_hovered="true"/>
22-
<item android:alpha="0.12" android:color="?attr/colorOnSurface" android:state_focused="true"/>
23-
<item android:alpha="0.04" android:color="?attr/colorOnSurface" android:state_hovered="true"/>
24-
<item android:alpha="0.00" android:color="?attr/colorOnSurface"/>
20+
<item android:alpha="@dimen/mtrl_low_ripple_pressed_alpha" android:color="?attr/colorOnSurface" android:state_pressed="true"/>
21+
<item android:alpha="@dimen/mtrl_low_ripple_focused_alpha" android:color="?attr/colorOnSurface" android:state_focused="true" android:state_hovered="true"/>
22+
<item android:alpha="@dimen/mtrl_low_ripple_focused_alpha" android:color="?attr/colorOnSurface" android:state_focused="true"/>
23+
<item android:alpha="@dimen/mtrl_low_ripple_hovered_alpha" android:color="?attr/colorOnSurface" android:state_hovered="true"/>
24+
<item android:alpha="@dimen/mtrl_low_ripple_default_alpha" android:color="?attr/colorOnSurface"/>
2525

2626
</selector>

lib/java/com/google/android/material/chip/res/color/mtrl_choice_chip_ripple_color.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
<selector xmlns:android="http://schemas.android.com/apk/res/android">
1919

20-
<item android:alpha="0.16" android:color="?attr/colorPrimary" android:state_pressed="true"/>
21-
<item android:alpha="0.16" android:color="?attr/colorOnSurface" android:state_focused="true" android:state_hovered="true"/>
22-
<item android:alpha="0.12" android:color="?attr/colorOnSurface" android:state_focused="true"/>
23-
<item android:alpha="0.04" android:color="?attr/colorOnSurface" android:state_hovered="true"/>
24-
<item android:alpha="0.00" android:color="?attr/colorOnSurface"/>
20+
<item android:alpha="@dimen/mtrl_low_ripple_pressed_alpha" android:color="?attr/colorPrimary" android:state_pressed="true"/>
21+
<item android:alpha="@dimen/mtrl_low_ripple_focused_alpha" android:color="?attr/colorOnSurface" android:state_focused="true" android:state_hovered="true"/>
22+
<item android:alpha="@dimen/mtrl_low_ripple_focused_alpha" android:color="?attr/colorOnSurface" android:state_focused="true"/>
23+
<item android:alpha="@dimen/mtrl_low_ripple_hovered_alpha" android:color="?attr/colorOnSurface" android:state_hovered="true"/>
24+
<item android:alpha="@dimen/mtrl_low_ripple_default_alpha" android:color="?attr/colorOnSurface"/>
2525

2626
</selector>

0 commit comments

Comments
 (0)