From 1ed322b123b5aa8cd02c036e5e3393b6a79f559f Mon Sep 17 00:00:00 2001 From: Gus Prevas Date: Thu, 17 Sep 2015 17:34:46 -0400 Subject: Adds an option to override RemoteViews transition. This change adds a configuration option, "config_overrideRemoteViewsActivityTransition", which is false by default and true on watches. If it's true, when a RemoteViews is clicked, it will use a new attribute on the active window animation style, "activityOpenRemoteViewsEnterAnimation", to determine the entry transition to use, instead of the current hard-coded default. Bug: 23534750 Change-Id: I91e92804a663ab71a3e46c3430fa579b87cc7931 --- core/java/android/widget/RemoteViews.java | 41 ++++++++++++++++++++++++++++--- core/res/res/values-watch/config.xml | 3 +++ core/res/res/values/attrs.xml | 7 ++++++ core/res/res/values/config.xml | 4 +++ core/res/res/values/styles_micro.xml | 1 + core/res/res/values/symbols.xml | 1 + 6 files changed, 54 insertions(+), 3 deletions(-) diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java index 7ca333947918..ca1b211bc291 100644 --- a/core/java/android/widget/RemoteViews.java +++ b/core/java/android/widget/RemoteViews.java @@ -31,6 +31,7 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.ColorStateList; import android.content.res.Configuration; import android.content.res.Resources; +import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.PorterDuff; import android.graphics.Rect; @@ -55,6 +56,8 @@ import android.view.ViewGroup; import android.widget.AdapterView.OnItemClickListener; import libcore.util.Objects; +import com.android.internal.R; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -206,14 +209,22 @@ public class RemoteViews implements Parcelable, Filter { /** @hide */ public static class OnClickHandler { + + private int mEnterAnimationId; + public boolean onClickHandler(View view, PendingIntent pendingIntent, Intent fillInIntent) { try { // TODO: Unregister this handler if PendingIntent.FLAG_ONE_SHOT? Context context = view.getContext(); - ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(view, - 0, 0, - view.getMeasuredWidth(), view.getMeasuredHeight()); + ActivityOptions opts; + if (mEnterAnimationId != 0) { + opts = ActivityOptions.makeCustomAnimation(context, mEnterAnimationId, 0); + } else { + opts = ActivityOptions.makeScaleUpAnimation(view, + 0, 0, + view.getMeasuredWidth(), view.getMeasuredHeight()); + } context.startIntentSender( pendingIntent.getIntentSender(), fillInIntent, Intent.FLAG_ACTIVITY_NEW_TASK, @@ -228,6 +239,10 @@ public class RemoteViews implements Parcelable, Filter { } return true; } + + public void setEnterAnimationId(int enterAnimationId) { + mEnterAnimationId = enterAnimationId; + } } /** @@ -2761,11 +2776,31 @@ public class RemoteViews implements Parcelable, Filter { inflater.setFilter(this); result = inflater.inflate(rvToApply.getLayoutId(), parent, false); + loadTransitionOverride(context, handler); + rvToApply.performApply(result, parent, handler); return result; } + private static void loadTransitionOverride(Context context, + RemoteViews.OnClickHandler handler) { + if (handler != null && context.getResources().getBoolean( + com.android.internal.R.bool.config_overrideRemoteViewsActivityTransition)) { + TypedArray windowStyle = context.getTheme().obtainStyledAttributes( + com.android.internal.R.styleable.Window); + int windowAnimations = windowStyle.getResourceId( + com.android.internal.R.styleable.Window_windowAnimationStyle, 0); + TypedArray windowAnimationStyle = context.obtainStyledAttributes( + windowAnimations, com.android.internal.R.styleable.WindowAnimation); + handler.setEnterAnimationId(windowAnimationStyle.getResourceId( + com.android.internal.R.styleable. + WindowAnimation_activityOpenRemoteViewsEnterAnimation, 0)); + windowStyle.recycle(); + windowAnimationStyle.recycle(); + } + } + /** * Applies all of the actions to the provided view. * diff --git a/core/res/res/values-watch/config.xml b/core/res/res/values-watch/config.xml index 41b05ea8757a..919519e5832a 100644 --- a/core/res/res/values-watch/config.xml +++ b/core/res/res/values-watch/config.xml @@ -54,4 +54,7 @@ false + + + true diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index cf8342211167..2828d2175047 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -2144,6 +2144,13 @@ i (which is exiting the screen). The wallpaper remains static behind the animation. --> + + + + diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index f1e26aafe963..0859e5a03856 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -2217,6 +2217,10 @@ true true + + false +