From 9cc966012f55e4ceb561f4648642ed4ef80dc127 Mon Sep 17 00:00:00 2001 From: Gus Prevas Date: Thu, 11 Oct 2018 11:24:23 -0400 Subject: Fixes touch ripples on media buttons. This change makes touch ripples appear correctly on the action buttons on media notifications. This involves the following changes: - NotificationViewWrapper.onReinflated() sets the notification content root's background to transparent rather than null when transferring the background color to the NotificationBackgroundView. This gives the ripples a surface to draw on. - The RemoteViews for the media templates are changed to use a fixed set of buttons instead of removing and re-adding them on every update. This prevents the update caused by whatever action the tap invokes from interrupting the ripples. - A method is added to RemoteViews allowing the ripple color to be specified. This allows us to change the ripple color to match the foreground color of the controls, which is necessary for the ripples to show up against a dark background. Test: manual Change-Id: I907f9a1a75efb48da496133ad357fc5150de4410 Fixes: 35856702 --- core/java/android/widget/RemoteViews.java | 67 +++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'core/java/android/widget/RemoteViews.java') diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java index 35ff6cc23499..8f17e96c144e 100644 --- a/core/java/android/widget/RemoteViews.java +++ b/core/java/android/widget/RemoteViews.java @@ -42,6 +42,7 @@ import android.graphics.PorterDuff; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.graphics.drawable.Icon; +import android.graphics.drawable.RippleDrawable; import android.net.Uri; import android.os.AsyncTask; import android.os.Binder; @@ -152,6 +153,7 @@ public class RemoteViews implements Parcelable, Filter { private static final int SET_REMOTE_INPUTS_ACTION_TAG = 18; private static final int LAYOUT_PARAM_ACTION_TAG = 19; private static final int OVERRIDE_TEXT_COLORS_TAG = 20; + private static final int SET_RIPPLE_DRAWABLE_COLOR_TAG = 21; /** * Application that hosts the remote views. @@ -1122,6 +1124,53 @@ public class RemoteViews implements Parcelable, Filter { PorterDuff.Mode filterMode; } + /** + * Equivalent to calling + * {@link RippleDrawable#setColor(ColorStateList)}, + * on the {@link Drawable} of a given view. + *

+ * The operation will be performed on the {@link Drawable} returned by the + * target {@link View#getBackground()}. + *

+ */ + private class SetRippleDrawableColor extends Action { + + ColorStateList mColorStateList; + + SetRippleDrawableColor(int id, ColorStateList colorStateList) { + this.viewId = id; + this.mColorStateList = colorStateList; + } + + SetRippleDrawableColor(Parcel parcel) { + viewId = parcel.readInt(); + mColorStateList = parcel.readParcelable(null); + } + + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(viewId); + dest.writeParcelable(mColorStateList, 0); + } + + @Override + public void apply(View root, ViewGroup rootParent, OnClickHandler handler) { + final View target = root.findViewById(viewId); + if (target == null) return; + + // Pick the correct drawable to modify for this view + Drawable targetDrawable = target.getBackground(); + + if (targetDrawable instanceof RippleDrawable) { + ((RippleDrawable) targetDrawable.mutate()).setColor(mColorStateList); + } + } + + @Override + public int getActionTag() { + return SET_RIPPLE_DRAWABLE_COLOR_TAG; + } + } + private final class ViewContentNavigation extends Action { final boolean mNext; @@ -2394,6 +2443,8 @@ public class RemoteViews implements Parcelable, Filter { return new LayoutParamAction(parcel); case OVERRIDE_TEXT_COLORS_TAG: return new OverrideTextColorsAction(parcel); + case SET_RIPPLE_DRAWABLE_COLOR_TAG: + return new SetRippleDrawableColor(parcel); default: throw new ActionException("Tag " + tag + " not found"); } @@ -2853,6 +2904,22 @@ public class RemoteViews implements Parcelable, Filter { addAction(new SetDrawableTint(viewId, targetBackground, colorFilter, mode)); } + /** + * @hide + * Equivalent to calling + * {@link RippleDrawable#setColor(ColorStateList)} on the {@link Drawable} of a given view, + * assuming it's a {@link RippleDrawable}. + *

+ * + * @param viewId The id of the view that contains the target + * {@link RippleDrawable} + * @param colorStateList Specify a color for a + * {@link ColorStateList} for this drawable. + */ + public void setRippleDrawableColor(int viewId, ColorStateList colorStateList) { + addAction(new SetRippleDrawableColor(viewId, colorStateList)); + } + /** * @hide * Equivalent to calling {@link android.widget.ProgressBar#setProgressTintList}. -- cgit v1.2.3