Skip to content

Commit

Permalink
Change ripples on Chip to use the alphas provided in the ColorStateList.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ikim24 authored and ymarian committed Jun 24, 2019
1 parent 0940c5f commit b857c79
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/java/com/google/android/material/chip/Chip.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ private void updateFrameworkRippleBackground() {
//noinspection NewApi
ripple =
new RippleDrawable(
RippleUtils.convertToRippleDrawableColor(chipDrawable.getRippleColor()),
RippleUtils.sanitizeRippleDrawableColor(chipDrawable.getRippleColor()),
getBackgroundDrawable(),
null);
chipDrawable.setUseCompatRipple(false);
Expand Down
6 changes: 3 additions & 3 deletions lib/java/com/google/android/material/chip/ChipDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ private boolean onStateChange(int[] chipState, int[] closeIconState) {
}

int newCompatRippleColor =
compatRippleColor != null
compatRippleColor != null && RippleUtils.shouldDrawRippleCompat(chipState)
? compatRippleColor.getColorForState(chipState, currentCompatRippleColor)
: 0;
if (currentCompatRippleColor != newCompatRippleColor) {
Expand Down Expand Up @@ -1280,7 +1280,7 @@ private ColorFilter getTintColorFilter() {

private void updateCompatRippleColor() {
compatRippleColor =
useCompatRipple ? RippleUtils.convertToRippleDrawableColor(rippleColor) : null;
useCompatRipple ? RippleUtils.sanitizeRippleDrawableColor(rippleColor) : null;
}

private void setChipSurfaceColor(@Nullable ColorStateList chipSurfaceColor) {
Expand Down Expand Up @@ -1795,7 +1795,7 @@ public void setCloseIcon(@Nullable Drawable closeIcon) {
private void updateFrameworkCloseIconRipple() {
closeIconRipple =
new RippleDrawable(
RippleUtils.convertToRippleDrawableColor(getRippleColor()),
RippleUtils.sanitizeRippleDrawableColor(getRippleColor()),
closeIcon,
// A separate drawable with a solid background is needed for the mask because by
// default, the close icon has a transparent background.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

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

<item android:alpha="0.16" android:color="?attr/colorOnSurface" android:state_pressed="true"/>
<item android:alpha="0.16" android:color="?attr/colorOnSurface" android:state_focused="true" android:state_hovered="true"/>
<item android:alpha="0.12" android:color="?attr/colorOnSurface" android:state_focused="true"/>
<item android:alpha="0.04" android:color="?attr/colorOnSurface" android:state_hovered="true"/>
<item android:alpha="0.00" android:color="?attr/colorOnSurface"/>
<item android:alpha="@dimen/mtrl_low_ripple_pressed_alpha" android:color="?attr/colorOnSurface" android:state_pressed="true"/>
<item android:alpha="@dimen/mtrl_low_ripple_focused_alpha" android:color="?attr/colorOnSurface" android:state_focused="true" android:state_hovered="true"/>
<item android:alpha="@dimen/mtrl_low_ripple_focused_alpha" android:color="?attr/colorOnSurface" android:state_focused="true"/>
<item android:alpha="@dimen/mtrl_low_ripple_hovered_alpha" android:color="?attr/colorOnSurface" android:state_hovered="true"/>
<item android:alpha="@dimen/mtrl_low_ripple_default_alpha" android:color="?attr/colorOnSurface"/>

</selector>
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

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

<item android:alpha="0.16" android:color="?attr/colorPrimary" android:state_pressed="true"/>
<item android:alpha="0.16" android:color="?attr/colorOnSurface" android:state_focused="true" android:state_hovered="true"/>
<item android:alpha="0.12" android:color="?attr/colorOnSurface" android:state_focused="true"/>
<item android:alpha="0.04" android:color="?attr/colorOnSurface" android:state_hovered="true"/>
<item android:alpha="0.00" android:color="?attr/colorOnSurface"/>
<item android:alpha="@dimen/mtrl_low_ripple_pressed_alpha" android:color="?attr/colorPrimary" android:state_pressed="true"/>
<item android:alpha="@dimen/mtrl_low_ripple_focused_alpha" android:color="?attr/colorOnSurface" android:state_focused="true" android:state_hovered="true"/>
<item android:alpha="@dimen/mtrl_low_ripple_focused_alpha" android:color="?attr/colorOnSurface" android:state_focused="true"/>
<item android:alpha="@dimen/mtrl_low_ripple_hovered_alpha" android:color="?attr/colorOnSurface" android:state_hovered="true"/>
<item android:alpha="@dimen/mtrl_low_ripple_default_alpha" android:color="?attr/colorOnSurface"/>

</selector>

0 comments on commit b857c79

Please sign in to comment.