diff options
Diffstat (limited to 'core/java/android/widget/RemoteViews.java')
| -rw-r--r-- | core/java/android/widget/RemoteViews.java | 67 |
1 files changed, 67 insertions, 0 deletions
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. + * <p> + * The operation will be performed on the {@link Drawable} returned by the + * target {@link View#getBackground()}. + * <p> + */ + 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"); } @@ -2855,6 +2906,22 @@ public class RemoteViews implements Parcelable, Filter { /** * @hide + * Equivalent to calling + * {@link RippleDrawable#setColor(ColorStateList)} on the {@link Drawable} of a given view, + * assuming it's a {@link RippleDrawable}. + * <p> + * + * @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}. * * @param viewId The id of the view whose tint should change |
