Fix emphasized button drawable to avoid ripple shape glitch.

Fixes: 191001646
Test: tap a button in the alarm notification
Change-Id: I3d8f77f96dc799bc36a44104874514c9320d11ce
This commit is contained in:
Jeff DeCew
2021-06-17 15:55:37 -04:00
parent 3ab0caf4c8
commit 5eeb0d554b
2 changed files with 15 additions and 14 deletions

View File

@@ -40,6 +40,7 @@ import com.android.internal.R;
@RemoteViews.RemoteView
public class EmphasizedNotificationButton extends Button {
private final RippleDrawable mRipple;
private final GradientDrawable mBackground;
private boolean mPriority;
public EmphasizedNotificationButton(Context context) {
@@ -57,9 +58,10 @@ public class EmphasizedNotificationButton extends Button {
public EmphasizedNotificationButton(Context context, AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
DrawableWrapper background = (DrawableWrapper) getBackground().mutate();
mRipple = (RippleDrawable) background.getDrawable();
mRipple = (RippleDrawable) getBackground();
mRipple.mutate();
DrawableWrapper inset = (DrawableWrapper) mRipple.getDrawable(0);
mBackground = (GradientDrawable) inset.getDrawable();
}
@RemotableViewMethod
@@ -70,8 +72,7 @@ public class EmphasizedNotificationButton extends Button {
@RemotableViewMethod
public void setButtonBackground(ColorStateList color) {
GradientDrawable inner = (GradientDrawable) mRipple.getDrawable(0);
inner.setColor(color);
mBackground.setColor(color);
invalidate();
}

View File

@@ -15,13 +15,13 @@
~ limitations under the License
-->
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="@dimen/button_inset_horizontal_material"
android:insetTop="@dimen/button_inset_vertical_material"
android:insetRight="@dimen/button_inset_horizontal_material"
android:insetBottom="@dimen/button_inset_vertical_material">
<ripple android:color="?attr/colorControlHighlight">
<item>
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="?attr/colorControlHighlight">
<item>
<inset
android:insetLeft="@dimen/button_inset_horizontal_material"
android:insetTop="@dimen/button_inset_vertical_material"
android:insetRight="@dimen/button_inset_horizontal_material"
android:insetBottom="@dimen/button_inset_vertical_material">
<shape android:shape="rectangle">
<corners android:radius="@dimen/notification_action_button_radius" />
<padding android:left="12dp"
@@ -30,6 +30,6 @@
android:bottom="@dimen/button_padding_vertical_material" />
<solid android:color="@color/white" />
</shape>
</item>
</ripple>
</inset>
</inset>
</item>
</ripple>