From b6d7002f365d92010c1d55910d7a231c82820314 Mon Sep 17 00:00:00 2001 From: Ming-Shin Lu Date: Fri, 27 Mar 2020 23:51:56 +0800 Subject: Add test APIs for makeCustomAnimation For CTS to verify activity custom transition duration with onAnimationStartedListener / onAnimationFinishedListener in ActivityOptions Bug: 150443017 Test: build, atest ActivityTransitionTests Change-Id: I603ab60a65343f3f336b311064ad55b01ead4929 --- core/java/android/app/ActivityOptions.java | 39 ++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'core/java/android/app/ActivityOptions.java') diff --git a/core/java/android/app/ActivityOptions.java b/core/java/android/app/ActivityOptions.java index 7fd0211215c5..9833536a510b 100644 --- a/core/java/android/app/ActivityOptions.java +++ b/core/java/android/app/ActivityOptions.java @@ -22,6 +22,7 @@ import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; import static android.view.Display.INVALID_DISPLAY; +import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.TestApi; @@ -369,7 +370,7 @@ public class ActivityOptions { */ public static ActivityOptions makeCustomAnimation(Context context, int enterResId, int exitResId) { - return makeCustomAnimation(context, enterResId, exitResId, null, null); + return makeCustomAnimation(context, enterResId, exitResId, null, null, null); } /** @@ -403,6 +404,38 @@ public class ActivityOptions { return opts; } + /** + * Create an ActivityOptions specifying a custom animation to run when + * the activity is displayed. + * + * @param context Who is defining this. This is the application that the + * animation resources will be loaded from. + * @param enterResId A resource ID of the animation resource to use for + * the incoming activity. Use 0 for no animation. + * @param exitResId A resource ID of the animation resource to use for + * the outgoing activity. Use 0 for no animation. + * @param handler If listener is non-null this must be a valid + * Handler on which to dispatch the callback; otherwise it should be null. + * @param startedListener Optional OnAnimationStartedListener to find out when the + * requested animation has started running. If for some reason the animation + * is not executed, the callback will happen immediately. + * @param finishedListener Optional OnAnimationFinishedListener when the animation + * has finished running. + * @return Returns a new ActivityOptions object that you can use to + * supply these options as the options Bundle when starting an activity. + * @hide + */ + @TestApi + public static @NonNull ActivityOptions makeCustomAnimation(@NonNull Context context, + int enterResId, int exitResId, @Nullable Handler handler, + @Nullable OnAnimationStartedListener startedListener, + @Nullable OnAnimationFinishedListener finishedListener) { + ActivityOptions opts = makeCustomAnimation(context, enterResId, exitResId, handler, + startedListener); + opts.setOnAnimationFinishedListener(handler, finishedListener); + return opts; + } + /** * Creates an ActivityOptions specifying a custom animation to run in place on an existing * activity. @@ -448,6 +481,7 @@ public class ActivityOptions { * to find out when the given animation has started running. * @hide */ + @TestApi public interface OnAnimationStartedListener { void onAnimationStarted(); } @@ -474,6 +508,7 @@ public class ActivityOptions { * to find out when the given animation has drawn its last frame. * @hide */ + @TestApi public interface OnAnimationFinishedListener { void onAnimationFinished(); } @@ -1089,7 +1124,7 @@ public class ActivityOptions { } /** @hide */ - public IRemoteCallback getOnAnimationStartListener() { + public IRemoteCallback getAnimationStartedListener() { return mAnimationStartedListener; } -- cgit v1.2.3