blob: b2b85d442301797c91e433d8e2efd5dacda1af85 [file] [log] [blame]
Dianne Hackborn6de01a92012-03-19 19:07:40 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.app;
18
Jorim Jaggi33a701a2017-12-01 14:58:18 +010019import static android.Manifest.permission.CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS;
Matthew Ngbf155872017-10-27 15:24:39 -070020import static android.app.ActivityManager.SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT;
Wale Ogunwale0568aed2017-09-08 13:29:37 -070021import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
22import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
Andrii Kulian16802aa2016-11-02 12:21:33 -070023import static android.view.Display.INVALID_DISPLAY;
Filip Gruszczynski90186c62015-10-26 14:07:00 -070024
Wale Ogunwale5122df02016-01-29 22:33:38 -080025import android.annotation.Nullable;
Jorim Jaggi33a701a2017-12-01 14:58:18 +010026import android.annotation.RequiresPermission;
Vladislav Kaznacheevacf147e2016-05-05 09:32:27 -070027import android.annotation.TestApi;
Mathew Inwood4fb17d12018-08-14 14:25:44 +010028import android.annotation.UnsupportedAppUsage;
Charles He2bf28322017-10-12 22:24:49 +010029import android.content.ComponentName;
Dianne Hackborn6de01a92012-03-19 19:07:40 -070030import android.content.Context;
George Mount62ab9b72014-05-02 13:51:17 -070031import android.content.Intent;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -070032import android.graphics.Bitmap;
Winson Chungaa7fa012017-05-24 15:50:06 -070033import android.graphics.Bitmap.Config;
34import android.graphics.GraphicBuffer;
Chong Zhang0fa656b2015-08-31 15:17:21 -070035import android.graphics.Rect;
Dianne Hackborn6de01a92012-03-19 19:07:40 -070036import android.os.Bundle;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -070037import android.os.Handler;
38import android.os.IRemoteCallback;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -070039import android.os.Parcelable;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -070040import android.os.RemoteException;
George Mountcb4b7d92014-02-25 10:47:55 -080041import android.os.ResultReceiver;
Tony Mak089c35e2017-12-18 20:34:14 +000042import android.os.UserHandle;
George Mount413739e2016-06-08 07:13:37 -070043import android.transition.Transition;
Ben Weisse0c37bd2016-10-26 11:18:32 +010044import android.transition.TransitionListenerAdapter;
George Mount413739e2016-06-08 07:13:37 -070045import android.transition.TransitionManager;
George Mounte1803372014-02-26 19:00:52 +000046import android.util.Pair;
Dianne Hackbornb5a380d2015-05-20 18:18:46 -070047import android.util.Slog;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -070048import android.view.AppTransitionAnimationSpec;
Jorim Jaggi34795e32017-05-12 17:27:46 +020049import android.view.IAppTransitionAnimationSpecsFuture;
Jorim Jaggi33a701a2017-12-01 14:58:18 +010050import android.view.RemoteAnimationAdapter;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -070051import android.view.View;
George Mount413739e2016-06-08 07:13:37 -070052import android.view.ViewGroup;
George Mount31a21722014-03-24 17:44:36 -070053import android.view.Window;
Dianne Hackborn6de01a92012-03-19 19:07:40 -070054
George Mount62ab9b72014-05-02 13:51:17 -070055import java.util.ArrayList;
George Mount0a778ed2013-12-13 13:35:36 -080056
Dianne Hackborn6de01a92012-03-19 19:07:40 -070057/**
58 * Helper class for building an options Bundle that can be used with
59 * {@link android.content.Context#startActivity(android.content.Intent, android.os.Bundle)
60 * Context.startActivity(Intent, Bundle)} and related methods.
61 */
62public class ActivityOptions {
Adam Powellcfbe9be2013-11-06 14:58:58 -080063 private static final String TAG = "ActivityOptions";
64
Dianne Hackborn6de01a92012-03-19 19:07:40 -070065 /**
Dianne Hackbornb5a380d2015-05-20 18:18:46 -070066 * A long in the extras delivered by {@link #requestUsageTimeReport} that contains
Dianne Hackborn67ba2c72015-06-05 14:23:38 -070067 * the total time (in ms) the user spent in the app flow.
Dianne Hackbornb5a380d2015-05-20 18:18:46 -070068 */
Dianne Hackborna750a632015-06-16 17:18:23 -070069 public static final String EXTRA_USAGE_TIME_REPORT = "android.activity.usage_time";
Dianne Hackbornb5a380d2015-05-20 18:18:46 -070070
71 /**
72 * A Bundle in the extras delivered by {@link #requestUsageTimeReport} that contains
73 * detailed information about the time spent in each package associated with the app;
74 * each key is a package name, whose value is a long containing the time (in ms).
75 */
Dianne Hackborn67ba2c72015-06-05 14:23:38 -070076 public static final String EXTRA_USAGE_TIME_REPORT_PACKAGES = "android.usage_time_packages";
Dianne Hackbornb5a380d2015-05-20 18:18:46 -070077
78 /**
Dianne Hackborn6de01a92012-03-19 19:07:40 -070079 * The package name that created the options.
80 * @hide
81 */
Dianne Hackborna750a632015-06-16 17:18:23 -070082 public static final String KEY_PACKAGE_NAME = "android:activity.packageName";
Dianne Hackborn6de01a92012-03-19 19:07:40 -070083
84 /**
Wale Ogunwale7a8fa602015-11-18 15:56:57 -080085 * The bounds (window size) that the activity should be launched in. Set to null explicitly for
86 * full screen. If the key is not found, previous bounds will be preserved.
87 * NOTE: This value is ignored on devices that don't have
Wale Ogunwale854809c2015-12-27 16:18:19 -080088 * {@link android.content.pm.PackageManager#FEATURE_FREEFORM_WINDOW_MANAGEMENT} or
89 * {@link android.content.pm.PackageManager#FEATURE_PICTURE_IN_PICTURE} enabled.
Chong Zhang0fa656b2015-08-31 15:17:21 -070090 * @hide
91 */
Wale Ogunwale7a8fa602015-11-18 15:56:57 -080092 public static final String KEY_LAUNCH_BOUNDS = "android:activity.launchBounds";
Chong Zhang0fa656b2015-08-31 15:17:21 -070093
94 /**
Dianne Hackborn8078d8c2012-03-20 11:11:26 -070095 * Type of animation that arguments specify.
96 * @hide
97 */
Dianne Hackborna750a632015-06-16 17:18:23 -070098 public static final String KEY_ANIM_TYPE = "android:activity.animType";
Dianne Hackborn8078d8c2012-03-20 11:11:26 -070099
100 /**
Dianne Hackborn6de01a92012-03-19 19:07:40 -0700101 * Custom enter animation resource ID.
102 * @hide
103 */
Dianne Hackborna750a632015-06-16 17:18:23 -0700104 public static final String KEY_ANIM_ENTER_RES_ID = "android:activity.animEnterRes";
Dianne Hackborn6de01a92012-03-19 19:07:40 -0700105
106 /**
107 * Custom exit animation resource ID.
108 * @hide
109 */
Dianne Hackborna750a632015-06-16 17:18:23 -0700110 public static final String KEY_ANIM_EXIT_RES_ID = "android:activity.animExitRes";
Dianne Hackborn6de01a92012-03-19 19:07:40 -0700111
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700112 /**
Winson Chung044d5292014-11-06 11:05:19 -0800113 * Custom in-place animation resource ID.
114 * @hide
115 */
Dianne Hackborna750a632015-06-16 17:18:23 -0700116 public static final String KEY_ANIM_IN_PLACE_RES_ID = "android:activity.animInPlaceRes";
Winson Chung044d5292014-11-06 11:05:19 -0800117
118 /**
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700119 * Bitmap for thumbnail animation.
120 * @hide
121 */
Dianne Hackborna750a632015-06-16 17:18:23 -0700122 public static final String KEY_ANIM_THUMBNAIL = "android:activity.animThumbnail";
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700123
124 /**
125 * Start X position of thumbnail animation.
126 * @hide
127 */
Dianne Hackborna750a632015-06-16 17:18:23 -0700128 public static final String KEY_ANIM_START_X = "android:activity.animStartX";
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700129
130 /**
131 * Start Y position of thumbnail animation.
132 * @hide
133 */
Dianne Hackborna750a632015-06-16 17:18:23 -0700134 public static final String KEY_ANIM_START_Y = "android:activity.animStartY";
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700135
136 /**
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700137 * Initial width of the animation.
138 * @hide
139 */
Dianne Hackborna750a632015-06-16 17:18:23 -0700140 public static final String KEY_ANIM_WIDTH = "android:activity.animWidth";
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700141
142 /**
143 * Initial height of the animation.
144 * @hide
145 */
Dianne Hackborna750a632015-06-16 17:18:23 -0700146 public static final String KEY_ANIM_HEIGHT = "android:activity.animHeight";
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700147
148 /**
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700149 * Callback for when animation is started.
150 * @hide
151 */
Dianne Hackborna750a632015-06-16 17:18:23 -0700152 public static final String KEY_ANIM_START_LISTENER = "android:activity.animStartListener";
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700153
Adam Powell18e905f2013-10-24 14:27:48 -0700154 /**
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700155 * Callback for when the last frame of the animation is played.
156 * @hide
157 */
158 private static final String KEY_ANIMATION_FINISHED_LISTENER =
159 "android:activity.animationFinishedListener";
160
161 /**
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700162 * Descriptions of app transition animations to be played during the activity launch.
163 */
164 private static final String KEY_ANIM_SPECS = "android:activity.animSpecs";
165
166 /**
Charles He2bf28322017-10-12 22:24:49 +0100167 * Whether the activity should be launched into LockTask mode.
Benjamin Franzcaffa772018-02-05 16:36:10 +0000168 * @see #setLockTaskEnabled(boolean)
Charles He2bf28322017-10-12 22:24:49 +0100169 */
170 private static final String KEY_LOCK_TASK_MODE = "android:activity.lockTaskMode";
171
172 /**
Andrii Kulian16802aa2016-11-02 12:21:33 -0700173 * The display id the activity should be launched into.
Andrii Kulian1981f5f2017-04-07 16:23:12 -0700174 * @see #setLaunchDisplayId(int)
Andrii Kulian16802aa2016-11-02 12:21:33 -0700175 * @hide
176 */
177 private static final String KEY_LAUNCH_DISPLAY_ID = "android.activity.launchDisplayId";
178
179 /**
Wale Ogunwale0568aed2017-09-08 13:29:37 -0700180 * The windowing mode the activity should be launched into.
Wale Ogunwale854809c2015-12-27 16:18:19 -0800181 * @hide
182 */
Wale Ogunwale0568aed2017-09-08 13:29:37 -0700183 private static final String KEY_LAUNCH_WINDOWING_MODE = "android.activity.windowingMode";
184
185 /**
186 * The activity type the activity should be launched as.
187 * @hide
188 */
189 private static final String KEY_LAUNCH_ACTIVITY_TYPE = "android.activity.activityType";
Wale Ogunwale854809c2015-12-27 16:18:19 -0800190
191 /**
Jorim Jaggi2adba072016-03-03 13:43:39 +0100192 * The task id the activity should be launched into.
193 * @hide
194 */
195 private static final String KEY_LAUNCH_TASK_ID = "android.activity.launchTaskId";
196
197 /**
Wale Ogunwale3b232392016-05-13 15:37:13 -0700198 * See {@link #setTaskOverlay}.
Jorim Jaggic875ae72016-04-26 22:41:06 -0700199 * @hide
200 */
Wale Ogunwale3b232392016-05-13 15:37:13 -0700201 private static final String KEY_TASK_OVERLAY = "android.activity.taskOverlay";
Jorim Jaggic875ae72016-04-26 22:41:06 -0700202
203 /**
Winson Chungcbcadc92017-01-12 15:54:12 -0800204 * See {@link #setTaskOverlay}.
205 * @hide
206 */
207 private static final String KEY_TASK_OVERLAY_CAN_RESUME =
208 "android.activity.taskOverlayCanResume";
209
210 /**
Winson Chunge2d72172018-01-25 17:46:20 +0000211 * See {@link #setAvoidMoveToFront()}.
212 * @hide
213 */
214 private static final String KEY_AVOID_MOVE_TO_FRONT = "android.activity.avoidMoveToFront";
215
216 /**
Matthew Ngbf155872017-10-27 15:24:39 -0700217 * Where the split-screen-primary stack should be positioned.
Filip Gruszczynski90186c62015-10-26 14:07:00 -0700218 * @hide
219 */
Matthew Ngbf155872017-10-27 15:24:39 -0700220 private static final String KEY_SPLIT_SCREEN_CREATE_MODE =
221 "android:activity.splitScreenCreateMode";
Filip Gruszczynski90186c62015-10-26 14:07:00 -0700222
223 /**
Winson Chungf7e03e12017-08-22 11:32:16 -0700224 * Determines whether to disallow the outgoing activity from entering picture-in-picture as the
225 * result of a new activity being launched.
226 * @hide
227 */
228 private static final String KEY_DISALLOW_ENTER_PICTURE_IN_PICTURE_WHILE_LAUNCHING =
229 "android:activity.disallowEnterPictureInPictureWhileLaunching";
230
231 /**
George Mount0a778ed2013-12-13 13:35:36 -0800232 * For Activity transitions, the calling Activity's TransitionListener used to
233 * notify the called Activity when the shared element and the exit transitions
234 * complete.
235 */
236 private static final String KEY_TRANSITION_COMPLETE_LISTENER
Dianne Hackborna750a632015-06-16 17:18:23 -0700237 = "android:activity.transitionCompleteListener";
George Mount0a778ed2013-12-13 13:35:36 -0800238
Dianne Hackborna750a632015-06-16 17:18:23 -0700239 private static final String KEY_TRANSITION_IS_RETURNING
240 = "android:activity.transitionIsReturning";
241 private static final String KEY_TRANSITION_SHARED_ELEMENTS
242 = "android:activity.sharedElementNames";
243 private static final String KEY_RESULT_DATA = "android:activity.resultData";
244 private static final String KEY_RESULT_CODE = "android:activity.resultCode";
245 private static final String KEY_EXIT_COORDINATOR_INDEX
246 = "android:activity.exitCoordinatorIndex";
George Mount62ab9b72014-05-02 13:51:17 -0700247
Dianne Hackborna750a632015-06-16 17:18:23 -0700248 private static final String KEY_USAGE_TIME_REPORT = "android:activity.usageTimeReport";
Robert Carrfd10cd12016-06-29 16:41:50 -0700249 private static final String KEY_ROTATION_ANIMATION_HINT = "android:activity.rotationAnimationHint";
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700250
Chad Brubaker06068612017-04-06 09:43:47 -0700251 private static final String KEY_INSTANT_APP_VERIFICATION_BUNDLE
252 = "android:instantapps.installerbundle";
Jorim Jaggi34795e32017-05-12 17:27:46 +0200253 private static final String KEY_SPECS_FUTURE = "android:activity.specsFuture";
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100254 private static final String KEY_REMOTE_ANIMATION_ADAPTER
255 = "android:activity.remoteAnimationAdapter";
Chad Brubaker06068612017-04-06 09:43:47 -0700256
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700257 /** @hide */
258 public static final int ANIM_NONE = 0;
259 /** @hide */
260 public static final int ANIM_CUSTOM = 1;
261 /** @hide */
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700262 public static final int ANIM_SCALE_UP = 2;
263 /** @hide */
Michael Jurka832cb222012-04-13 09:32:47 -0700264 public static final int ANIM_THUMBNAIL_SCALE_UP = 3;
Michael Jurka21385cd2012-05-03 10:57:31 -0700265 /** @hide */
Michael Jurka832cb222012-04-13 09:32:47 -0700266 public static final int ANIM_THUMBNAIL_SCALE_DOWN = 4;
Adam Powell18e905f2013-10-24 14:27:48 -0700267 /** @hide */
268 public static final int ANIM_SCENE_TRANSITION = 5;
George Mount0b6f3e12014-06-20 07:35:23 -0700269 /** @hide */
270 public static final int ANIM_DEFAULT = 6;
Craig Mautnerbb742462014-07-07 15:28:55 -0700271 /** @hide */
272 public static final int ANIM_LAUNCH_TASK_BEHIND = 7;
Winson Chunga4ccb862014-08-22 15:26:27 -0700273 /** @hide */
274 public static final int ANIM_THUMBNAIL_ASPECT_SCALE_UP = 8;
275 /** @hide */
276 public static final int ANIM_THUMBNAIL_ASPECT_SCALE_DOWN = 9;
Winson Chung044d5292014-11-06 11:05:19 -0800277 /** @hide */
278 public static final int ANIM_CUSTOM_IN_PLACE = 10;
Chet Haase10e23ab2015-02-11 15:08:38 -0800279 /** @hide */
280 public static final int ANIM_CLIP_REVEAL = 11;
Tony Mak089c35e2017-12-18 20:34:14 +0000281 /** @hide */
282 public static final int ANIM_OPEN_CROSS_PROFILE_APPS = 12;
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100283 /** @hide */
284 public static final int ANIM_REMOTE_ANIMATION = 13;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700285
Dianne Hackborn6de01a92012-03-19 19:07:40 -0700286 private String mPackageName;
Wale Ogunwale7a8fa602015-11-18 15:56:57 -0800287 private Rect mLaunchBounds;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700288 private int mAnimationType = ANIM_NONE;
Dianne Hackborn6de01a92012-03-19 19:07:40 -0700289 private int mCustomEnterResId;
290 private int mCustomExitResId;
Winson Chung044d5292014-11-06 11:05:19 -0800291 private int mCustomInPlaceResId;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700292 private Bitmap mThumbnail;
293 private int mStartX;
294 private int mStartY;
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200295 private int mWidth;
296 private int mHeight;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700297 private IRemoteCallback mAnimationStartedListener;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700298 private IRemoteCallback mAnimationFinishedListener;
George Mount62ab9b72014-05-02 13:51:17 -0700299 private ResultReceiver mTransitionReceiver;
300 private boolean mIsReturning;
301 private ArrayList<String> mSharedElementNames;
George Mount62ab9b72014-05-02 13:51:17 -0700302 private Intent mResultData;
303 private int mResultCode;
George Mount1fecfb22014-06-18 14:55:55 -0700304 private int mExitCoordinatorIndex;
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700305 private PendingIntent mUsageTimeReport;
Charles He2bf28322017-10-12 22:24:49 +0100306 private boolean mLockTaskMode = false;
Andrii Kulian16802aa2016-11-02 12:21:33 -0700307 private int mLaunchDisplayId = INVALID_DISPLAY;
Wale Ogunwale0568aed2017-09-08 13:29:37 -0700308 @WindowConfiguration.WindowingMode
309 private int mLaunchWindowingMode = WINDOWING_MODE_UNDEFINED;
310 @WindowConfiguration.ActivityType
311 private int mLaunchActivityType = ACTIVITY_TYPE_UNDEFINED;
Jorim Jaggi2adba072016-03-03 13:43:39 +0100312 private int mLaunchTaskId = -1;
Matthew Ngbf155872017-10-27 15:24:39 -0700313 private int mSplitScreenCreateMode = SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT;
Winson Chungf7e03e12017-08-22 11:32:16 -0700314 private boolean mDisallowEnterPictureInPictureWhileLaunching;
Wale Ogunwale3b232392016-05-13 15:37:13 -0700315 private boolean mTaskOverlay;
Winson Chungcbcadc92017-01-12 15:54:12 -0800316 private boolean mTaskOverlayCanResume;
Winson Chunge2d72172018-01-25 17:46:20 +0000317 private boolean mAvoidMoveToFront;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700318 private AppTransitionAnimationSpec mAnimSpecs[];
Robert Carrfd10cd12016-06-29 16:41:50 -0700319 private int mRotationAnimationHint = -1;
Chad Brubaker06068612017-04-06 09:43:47 -0700320 private Bundle mAppVerificationBundle;
Jorim Jaggi34795e32017-05-12 17:27:46 +0200321 private IAppTransitionAnimationSpecsFuture mSpecsFuture;
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100322 private RemoteAnimationAdapter mRemoteAnimationAdapter;
Dianne Hackborn6de01a92012-03-19 19:07:40 -0700323
324 /**
325 * Create an ActivityOptions specifying a custom animation to run when
326 * the activity is displayed.
327 *
328 * @param context Who is defining this. This is the application that the
329 * animation resources will be loaded from.
330 * @param enterResId A resource ID of the animation resource to use for
331 * the incoming activity. Use 0 for no animation.
332 * @param exitResId A resource ID of the animation resource to use for
333 * the outgoing activity. Use 0 for no animation.
334 * @return Returns a new ActivityOptions object that you can use to
335 * supply these options as the options Bundle when starting an activity.
336 */
337 public static ActivityOptions makeCustomAnimation(Context context,
338 int enterResId, int exitResId) {
Dianne Hackborn84375872012-06-01 19:03:50 -0700339 return makeCustomAnimation(context, enterResId, exitResId, null, null);
340 }
341
342 /**
343 * Create an ActivityOptions specifying a custom animation to run when
344 * the activity is displayed.
345 *
346 * @param context Who is defining this. This is the application that the
347 * animation resources will be loaded from.
348 * @param enterResId A resource ID of the animation resource to use for
349 * the incoming activity. Use 0 for no animation.
350 * @param exitResId A resource ID of the animation resource to use for
351 * the outgoing activity. Use 0 for no animation.
352 * @param handler If <var>listener</var> is non-null this must be a valid
353 * Handler on which to dispatch the callback; otherwise it should be null.
354 * @param listener Optional OnAnimationStartedListener to find out when the
355 * requested animation has started running. If for some reason the animation
356 * is not executed, the callback will happen immediately.
357 * @return Returns a new ActivityOptions object that you can use to
358 * supply these options as the options Bundle when starting an activity.
359 * @hide
360 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +0100361 @UnsupportedAppUsage
Dianne Hackborn84375872012-06-01 19:03:50 -0700362 public static ActivityOptions makeCustomAnimation(Context context,
363 int enterResId, int exitResId, Handler handler, OnAnimationStartedListener listener) {
Dianne Hackborn6de01a92012-03-19 19:07:40 -0700364 ActivityOptions opts = new ActivityOptions();
365 opts.mPackageName = context.getPackageName();
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700366 opts.mAnimationType = ANIM_CUSTOM;
Dianne Hackborn6de01a92012-03-19 19:07:40 -0700367 opts.mCustomEnterResId = enterResId;
368 opts.mCustomExitResId = exitResId;
Adam Powell18e905f2013-10-24 14:27:48 -0700369 opts.setOnAnimationStartedListener(handler, listener);
Dianne Hackborn6de01a92012-03-19 19:07:40 -0700370 return opts;
371 }
372
Winson Chung044d5292014-11-06 11:05:19 -0800373 /**
374 * Creates an ActivityOptions specifying a custom animation to run in place on an existing
375 * activity.
376 *
377 * @param context Who is defining this. This is the application that the
378 * animation resources will be loaded from.
379 * @param animId A resource ID of the animation resource to use for
380 * the incoming activity.
381 * @return Returns a new ActivityOptions object that you can use to
382 * supply these options as the options Bundle when running an in-place animation.
383 * @hide
384 */
385 public static ActivityOptions makeCustomInPlaceAnimation(Context context, int animId) {
386 if (animId == 0) {
387 throw new RuntimeException("You must specify a valid animation.");
388 }
389
390 ActivityOptions opts = new ActivityOptions();
391 opts.mPackageName = context.getPackageName();
392 opts.mAnimationType = ANIM_CUSTOM_IN_PLACE;
393 opts.mCustomInPlaceResId = animId;
394 return opts;
395 }
396
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700397 private void setOnAnimationStartedListener(final Handler handler,
398 final OnAnimationStartedListener listener) {
Dianne Hackborn84375872012-06-01 19:03:50 -0700399 if (listener != null) {
Dianne Hackborn84375872012-06-01 19:03:50 -0700400 mAnimationStartedListener = new IRemoteCallback.Stub() {
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700401 @Override
402 public void sendResult(Bundle data) throws RemoteException {
403 handler.post(new Runnable() {
Dianne Hackborn84375872012-06-01 19:03:50 -0700404 @Override public void run() {
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700405 listener.onAnimationStarted();
Dianne Hackborn84375872012-06-01 19:03:50 -0700406 }
407 });
408 }
409 };
410 }
411 }
412
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700413 /**
414 * Callback for use with {@link ActivityOptions#makeThumbnailScaleUpAnimation}
415 * to find out when the given animation has started running.
Dianne Hackborn9944ecd2012-04-10 15:54:19 -0700416 * @hide
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700417 */
418 public interface OnAnimationStartedListener {
419 void onAnimationStarted();
420 }
421
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700422 private void setOnAnimationFinishedListener(final Handler handler,
423 final OnAnimationFinishedListener listener) {
424 if (listener != null) {
425 mAnimationFinishedListener = new IRemoteCallback.Stub() {
426 @Override
427 public void sendResult(Bundle data) throws RemoteException {
428 handler.post(new Runnable() {
429 @Override
430 public void run() {
431 listener.onAnimationFinished();
432 }
433 });
434 }
435 };
436 }
437 }
438
439 /**
440 * Callback for use with {@link ActivityOptions#makeThumbnailAspectScaleDownAnimation}
441 * to find out when the given animation has drawn its last frame.
442 * @hide
443 */
444 public interface OnAnimationFinishedListener {
445 void onAnimationFinished();
446 }
447
Adam Powell18e905f2013-10-24 14:27:48 -0700448 /**
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700449 * Create an ActivityOptions specifying an animation where the new
450 * activity is scaled from a small originating area of the screen to
451 * its final full representation.
452 *
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700453 * <p>If the Intent this is being used with has not set its
454 * {@link android.content.Intent#setSourceBounds Intent.setSourceBounds},
455 * those bounds will be filled in for you based on the initial
456 * bounds passed in here.
457 *
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700458 * @param source The View that the new activity is animating from. This
459 * defines the coordinate space for <var>startX</var> and <var>startY</var>.
460 * @param startX The x starting location of the new activity, relative to <var>source</var>.
461 * @param startY The y starting location of the activity, relative to <var>source</var>.
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200462 * @param width The initial width of the new activity.
463 * @param height The initial height of the new activity.
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700464 * @return Returns a new ActivityOptions object that you can use to
465 * supply these options as the options Bundle when starting an activity.
466 */
467 public static ActivityOptions makeScaleUpAnimation(View source,
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200468 int startX, int startY, int width, int height) {
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700469 ActivityOptions opts = new ActivityOptions();
470 opts.mPackageName = source.getContext().getPackageName();
471 opts.mAnimationType = ANIM_SCALE_UP;
472 int[] pts = new int[2];
473 source.getLocationOnScreen(pts);
474 opts.mStartX = pts[0] + startX;
475 opts.mStartY = pts[1] + startY;
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200476 opts.mWidth = width;
477 opts.mHeight = height;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700478 return opts;
479 }
480
481 /**
Chet Haase10e23ab2015-02-11 15:08:38 -0800482 * Create an ActivityOptions specifying an animation where the new
483 * activity is revealed from a small originating area of the screen to
484 * its final full representation.
485 *
486 * @param source The View that the new activity is animating from. This
487 * defines the coordinate space for <var>startX</var> and <var>startY</var>.
488 * @param startX The x starting location of the new activity, relative to <var>source</var>.
489 * @param startY The y starting location of the activity, relative to <var>source</var>.
490 * @param width The initial width of the new activity.
491 * @param height The initial height of the new activity.
492 * @return Returns a new ActivityOptions object that you can use to
493 * supply these options as the options Bundle when starting an activity.
494 */
495 public static ActivityOptions makeClipRevealAnimation(View source,
496 int startX, int startY, int width, int height) {
497 ActivityOptions opts = new ActivityOptions();
498 opts.mAnimationType = ANIM_CLIP_REVEAL;
499 int[] pts = new int[2];
500 source.getLocationOnScreen(pts);
501 opts.mStartX = pts[0] + startX;
502 opts.mStartY = pts[1] + startY;
503 opts.mWidth = width;
504 opts.mHeight = height;
505 return opts;
506 }
507
508 /**
Tony Mak089c35e2017-12-18 20:34:14 +0000509 * Creates an {@link ActivityOptions} object specifying an animation where the new activity
510 * is started in another user profile by calling {@link
511 * android.content.pm.crossprofile.CrossProfileApps#startMainActivity(ComponentName, UserHandle)
512 * }.
513 * @hide
514 */
515 public static ActivityOptions makeOpenCrossProfileAppsAnimation() {
516 ActivityOptions options = new ActivityOptions();
517 options.mAnimationType = ANIM_OPEN_CROSS_PROFILE_APPS;
518 return options;
519 }
520
521 /**
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700522 * Create an ActivityOptions specifying an animation where a thumbnail
523 * is scaled from a given position to the new activity window that is
524 * being started.
525 *
Dianne Hackbornd367ca82012-05-07 15:49:39 -0700526 * <p>If the Intent this is being used with has not set its
527 * {@link android.content.Intent#setSourceBounds Intent.setSourceBounds},
528 * those bounds will be filled in for you based on the initial
529 * thumbnail location and size provided here.
530 *
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700531 * @param source The View that this thumbnail is animating from. This
532 * defines the coordinate space for <var>startX</var> and <var>startY</var>.
533 * @param thumbnail The bitmap that will be shown as the initial thumbnail
534 * of the animation.
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700535 * @param startX The x starting location of the bitmap, relative to <var>source</var>.
536 * @param startY The y starting location of the bitmap, relative to <var>source</var>.
Dianne Hackborn9944ecd2012-04-10 15:54:19 -0700537 * @return Returns a new ActivityOptions object that you can use to
538 * supply these options as the options Bundle when starting an activity.
539 */
540 public static ActivityOptions makeThumbnailScaleUpAnimation(View source,
541 Bitmap thumbnail, int startX, int startY) {
542 return makeThumbnailScaleUpAnimation(source, thumbnail, startX, startY, null);
543 }
544
545 /**
546 * Create an ActivityOptions specifying an animation where a thumbnail
547 * is scaled from a given position to the new activity window that is
548 * being started.
549 *
550 * @param source The View that this thumbnail is animating from. This
551 * defines the coordinate space for <var>startX</var> and <var>startY</var>.
552 * @param thumbnail The bitmap that will be shown as the initial thumbnail
553 * of the animation.
Dianne Hackborneabfb3a2012-04-16 16:28:22 -0700554 * @param startX The x starting location of the bitmap, relative to <var>source</var>.
555 * @param startY The y starting location of the bitmap, relative to <var>source</var>.
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700556 * @param listener Optional OnAnimationStartedListener to find out when the
557 * requested animation has started running. If for some reason the animation
558 * is not executed, the callback will happen immediately.
559 * @return Returns a new ActivityOptions object that you can use to
560 * supply these options as the options Bundle when starting an activity.
561 */
Jorim Jaggi34795e32017-05-12 17:27:46 +0200562 private static ActivityOptions makeThumbnailScaleUpAnimation(View source,
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700563 Bitmap thumbnail, int startX, int startY, OnAnimationStartedListener listener) {
Michael Jurka832cb222012-04-13 09:32:47 -0700564 return makeThumbnailAnimation(source, thumbnail, startX, startY, listener, true);
Michael Jurka21385cd2012-05-03 10:57:31 -0700565 }
566
Michael Jurka832cb222012-04-13 09:32:47 -0700567 private static ActivityOptions makeThumbnailAnimation(View source,
Michael Jurka21385cd2012-05-03 10:57:31 -0700568 Bitmap thumbnail, int startX, int startY, OnAnimationStartedListener listener,
Michael Jurka832cb222012-04-13 09:32:47 -0700569 boolean scaleUp) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700570 ActivityOptions opts = new ActivityOptions();
571 opts.mPackageName = source.getContext().getPackageName();
Michael Jurka832cb222012-04-13 09:32:47 -0700572 opts.mAnimationType = scaleUp ? ANIM_THUMBNAIL_SCALE_UP : ANIM_THUMBNAIL_SCALE_DOWN;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700573 opts.mThumbnail = thumbnail;
574 int[] pts = new int[2];
575 source.getLocationOnScreen(pts);
576 opts.mStartX = pts[0] + startX;
577 opts.mStartY = pts[1] + startY;
Adam Powell18e905f2013-10-24 14:27:48 -0700578 opts.setOnAnimationStartedListener(source.getHandler(), listener);
579 return opts;
580 }
581
582 /**
Jorim Jaggi34795e32017-05-12 17:27:46 +0200583 * Create an ActivityOptions specifying an animation where a list of activity windows and
584 * thumbnails are aspect scaled to/from a new location.
Winson Chunga4ccb862014-08-22 15:26:27 -0700585 * @hide
586 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +0100587 @UnsupportedAppUsage
Jorim Jaggi34795e32017-05-12 17:27:46 +0200588 public static ActivityOptions makeMultiThumbFutureAspectScaleAnimation(Context context,
589 Handler handler, IAppTransitionAnimationSpecsFuture specsFuture,
590 OnAnimationStartedListener listener, boolean scaleUp) {
591 ActivityOptions opts = new ActivityOptions();
592 opts.mPackageName = context.getPackageName();
593 opts.mAnimationType = scaleUp
594 ? ANIM_THUMBNAIL_ASPECT_SCALE_UP
595 : ANIM_THUMBNAIL_ASPECT_SCALE_DOWN;
596 opts.mSpecsFuture = specsFuture;
597 opts.setOnAnimationStartedListener(handler, listener);
598 return opts;
Winson Chunga4ccb862014-08-22 15:26:27 -0700599 }
600
601 /**
602 * Create an ActivityOptions specifying an animation where the new activity
603 * window and a thumbnail is aspect-scaled to a new location.
604 *
605 * @param source The View that this thumbnail is animating to. This
606 * defines the coordinate space for <var>startX</var> and <var>startY</var>.
607 * @param thumbnail The bitmap that will be shown as the final thumbnail
608 * of the animation.
609 * @param startX The x end location of the bitmap, relative to <var>source</var>.
610 * @param startY The y end location of the bitmap, relative to <var>source</var>.
Winson Chunge494c382014-12-17 10:12:54 -0800611 * @param handler If <var>listener</var> is non-null this must be a valid
612 * Handler on which to dispatch the callback; otherwise it should be null.
Winson Chunga4ccb862014-08-22 15:26:27 -0700613 * @param listener Optional OnAnimationStartedListener to find out when the
614 * requested animation has started running. If for some reason the animation
615 * is not executed, the callback will happen immediately.
616 * @return Returns a new ActivityOptions object that you can use to
617 * supply these options as the options Bundle when starting an activity.
618 * @hide
619 */
620 public static ActivityOptions makeThumbnailAspectScaleDownAnimation(View source,
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200621 Bitmap thumbnail, int startX, int startY, int targetWidth, int targetHeight,
Winson Chunge494c382014-12-17 10:12:54 -0800622 Handler handler, OnAnimationStartedListener listener) {
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200623 return makeAspectScaledThumbnailAnimation(source, thumbnail, startX, startY,
Winson Chunge494c382014-12-17 10:12:54 -0800624 targetWidth, targetHeight, handler, listener, false);
Winson Chunga4ccb862014-08-22 15:26:27 -0700625 }
626
627 private static ActivityOptions makeAspectScaledThumbnailAnimation(View source, Bitmap thumbnail,
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200628 int startX, int startY, int targetWidth, int targetHeight,
Winson Chunge494c382014-12-17 10:12:54 -0800629 Handler handler, OnAnimationStartedListener listener, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700630 ActivityOptions opts = new ActivityOptions();
631 opts.mPackageName = source.getContext().getPackageName();
632 opts.mAnimationType = scaleUp ? ANIM_THUMBNAIL_ASPECT_SCALE_UP :
633 ANIM_THUMBNAIL_ASPECT_SCALE_DOWN;
634 opts.mThumbnail = thumbnail;
635 int[] pts = new int[2];
636 source.getLocationOnScreen(pts);
637 opts.mStartX = pts[0] + startX;
638 opts.mStartY = pts[1] + startY;
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200639 opts.mWidth = targetWidth;
640 opts.mHeight = targetHeight;
Winson Chunge494c382014-12-17 10:12:54 -0800641 opts.setOnAnimationStartedListener(handler, listener);
Winson Chunga4ccb862014-08-22 15:26:27 -0700642 return opts;
643 }
644
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700645 /** @hide */
646 public static ActivityOptions makeThumbnailAspectScaleDownAnimation(View source,
647 AppTransitionAnimationSpec[] specs, Handler handler,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700648 OnAnimationStartedListener onAnimationStartedListener,
649 OnAnimationFinishedListener onAnimationFinishedListener) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700650 ActivityOptions opts = new ActivityOptions();
651 opts.mPackageName = source.getContext().getPackageName();
652 opts.mAnimationType = ANIM_THUMBNAIL_ASPECT_SCALE_DOWN;
653 opts.mAnimSpecs = specs;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700654 opts.setOnAnimationStartedListener(handler, onAnimationStartedListener);
655 opts.setOnAnimationFinishedListener(handler, onAnimationFinishedListener);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700656 return opts;
657 }
658
Winson Chunga4ccb862014-08-22 15:26:27 -0700659 /**
George Mounte1803372014-02-26 19:00:52 +0000660 * Create an ActivityOptions to transition between Activities using cross-Activity scene
661 * animations. This method carries the position of one shared element to the started Activity.
George Mount31a21722014-03-24 17:44:36 -0700662 * The position of <code>sharedElement</code> will be used as the epicenter for the
663 * exit Transition. The position of the shared element in the launched Activity will be the
664 * epicenter of its entering Transition.
George Mount0a778ed2013-12-13 13:35:36 -0800665 *
George Mount9826f632014-09-11 08:50:09 -0700666 * <p>This requires {@link android.view.Window#FEATURE_ACTIVITY_TRANSITIONS} to be
George Mount0a778ed2013-12-13 13:35:36 -0800667 * enabled on the calling Activity to cause an exit transition. The same must be in
668 * the called Activity to get an entering transition.</p>
George Mount62ab9b72014-05-02 13:51:17 -0700669 * @param activity The Activity whose window contains the shared elements.
George Mount0b6f3e12014-06-20 07:35:23 -0700670 * @param sharedElement The View to transition to the started Activity.
671 * @param sharedElementName The shared element name as used in the target Activity. This
672 * must not be null.
George Mounte1803372014-02-26 19:00:52 +0000673 * @return Returns a new ActivityOptions object that you can use to
674 * supply these options as the options Bundle when starting an activity.
George Mount31a21722014-03-24 17:44:36 -0700675 * @see android.transition.Transition#setEpicenterCallback(
676 * android.transition.Transition.EpicenterCallback)
Adam Powell18e905f2013-10-24 14:27:48 -0700677 */
George Mount62ab9b72014-05-02 13:51:17 -0700678 public static ActivityOptions makeSceneTransitionAnimation(Activity activity,
George Mount31a21722014-03-24 17:44:36 -0700679 View sharedElement, String sharedElementName) {
George Mount62ab9b72014-05-02 13:51:17 -0700680 return makeSceneTransitionAnimation(activity, Pair.create(sharedElement, sharedElementName));
George Mounte1803372014-02-26 19:00:52 +0000681 }
682
683 /**
684 * Create an ActivityOptions to transition between Activities using cross-Activity scene
685 * animations. This method carries the position of multiple shared elements to the started
George Mount62ab9b72014-05-02 13:51:17 -0700686 * Activity. The position of the first element in sharedElements
George Mount31a21722014-03-24 17:44:36 -0700687 * will be used as the epicenter for the exit Transition. The position of the associated
688 * shared element in the launched Activity will be the epicenter of its entering Transition.
George Mounte1803372014-02-26 19:00:52 +0000689 *
George Mount9826f632014-09-11 08:50:09 -0700690 * <p>This requires {@link android.view.Window#FEATURE_ACTIVITY_TRANSITIONS} to be
George Mounte1803372014-02-26 19:00:52 +0000691 * enabled on the calling Activity to cause an exit transition. The same must be in
692 * the called Activity to get an entering transition.</p>
George Mount62ab9b72014-05-02 13:51:17 -0700693 * @param activity The Activity whose window contains the shared elements.
694 * @param sharedElements The names of the shared elements to transfer to the called
695 * Activity and their associated Views. The Views must each have
696 * a unique shared element name.
George Mounte1803372014-02-26 19:00:52 +0000697 * @return Returns a new ActivityOptions object that you can use to
698 * supply these options as the options Bundle when starting an activity.
George Mount31a21722014-03-24 17:44:36 -0700699 * @see android.transition.Transition#setEpicenterCallback(
700 * android.transition.Transition.EpicenterCallback)
George Mounte1803372014-02-26 19:00:52 +0000701 */
George Mountd98f4ba2016-03-14 14:29:24 -0700702 @SafeVarargs
George Mount62ab9b72014-05-02 13:51:17 -0700703 public static ActivityOptions makeSceneTransitionAnimation(Activity activity,
704 Pair<View, String>... sharedElements) {
Adam Powell18e905f2013-10-24 14:27:48 -0700705 ActivityOptions opts = new ActivityOptions();
George Mount413739e2016-06-08 07:13:37 -0700706 makeSceneTransitionAnimation(activity, activity.getWindow(), opts,
707 activity.mExitTransitionListener, sharedElements);
708 return opts;
709 }
710
711 /**
712 * Call this immediately prior to startActivity to begin a shared element transition
713 * from a non-Activity. The window must support Window.FEATURE_ACTIVITY_TRANSITIONS.
714 * The exit transition will start immediately and the shared element transition will
715 * start once the launched Activity's shared element is ready.
716 * <p>
717 * When all transitions have completed and the shared element has been transfered,
718 * the window's decor View will have its visibility set to View.GONE.
719 *
720 * @hide
721 */
722 @SafeVarargs
723 public static ActivityOptions startSharedElementAnimation(Window window,
724 Pair<View, String>... sharedElements) {
725 ActivityOptions opts = new ActivityOptions();
726 final View decorView = window.getDecorView();
727 if (decorView == null) {
Eino-Ville Talvala563df3b2016-06-06 22:04:54 +0000728 return opts;
George Mount04073dc2016-05-27 11:02:13 -0700729 }
George Mount413739e2016-06-08 07:13:37 -0700730 final ExitTransitionCoordinator exit =
731 makeSceneTransitionAnimation(null, window, opts, null, sharedElements);
732 if (exit != null) {
733 HideWindowListener listener = new HideWindowListener(window, exit);
734 exit.setHideSharedElementsCallback(listener);
735 exit.startExit();
736 }
737 return opts;
738 }
739
740 /**
741 * This method should be called when the {@link #startSharedElementAnimation(Window, Pair[])}
742 * animation must be stopped and the Views reset. This can happen if there was an error
743 * from startActivity or a springboard activity and the animation should stop and reset.
744 *
745 * @hide
746 */
747 public static void stopSharedElementAnimation(Window window) {
748 final View decorView = window.getDecorView();
749 if (decorView == null) {
750 return;
751 }
752 final ExitTransitionCoordinator exit = (ExitTransitionCoordinator)
753 decorView.getTag(com.android.internal.R.id.cross_task_transition);
754 if (exit != null) {
755 exit.cancelPendingTransitions();
756 decorView.setTagInternal(com.android.internal.R.id.cross_task_transition, null);
757 TransitionManager.endTransitions((ViewGroup) decorView);
758 exit.resetViews();
759 exit.clearState();
760 decorView.setVisibility(View.VISIBLE);
761 }
762 }
763
764 static ExitTransitionCoordinator makeSceneTransitionAnimation(Activity activity, Window window,
765 ActivityOptions opts, SharedElementCallback callback,
766 Pair<View, String>[] sharedElements) {
767 if (!window.hasFeature(Window.FEATURE_ACTIVITY_TRANSITIONS)) {
768 opts.mAnimationType = ANIM_DEFAULT;
769 return null;
770 }
Adam Powell18e905f2013-10-24 14:27:48 -0700771 opts.mAnimationType = ANIM_SCENE_TRANSITION;
George Mount62ab9b72014-05-02 13:51:17 -0700772
773 ArrayList<String> names = new ArrayList<String>();
George Mount1fecfb22014-06-18 14:55:55 -0700774 ArrayList<View> views = new ArrayList<View>();
George Mount62ab9b72014-05-02 13:51:17 -0700775
776 if (sharedElements != null) {
777 for (int i = 0; i < sharedElements.length; i++) {
778 Pair<View, String> sharedElement = sharedElements[i];
George Mountd5f9d732014-06-05 15:43:06 -0700779 String sharedElementName = sharedElement.second;
780 if (sharedElementName == null) {
781 throw new IllegalArgumentException("Shared element name must not be null");
782 }
George Mountd5f9d732014-06-05 15:43:06 -0700783 names.add(sharedElementName);
George Mount1fecfb22014-06-18 14:55:55 -0700784 View view = sharedElement.first;
785 if (view == null) {
786 throw new IllegalArgumentException("Shared element must not be null");
787 }
788 views.add(sharedElement.first);
George Mount62ab9b72014-05-02 13:51:17 -0700789 }
790 }
791
George Mount413739e2016-06-08 07:13:37 -0700792 ExitTransitionCoordinator exit = new ExitTransitionCoordinator(activity, window,
793 callback, names, names, views, false);
George Mount62ab9b72014-05-02 13:51:17 -0700794 opts.mTransitionReceiver = exit;
795 opts.mSharedElementNames = names;
George Mount413739e2016-06-08 07:13:37 -0700796 opts.mIsReturning = (activity == null);
797 if (activity == null) {
798 opts.mExitCoordinatorIndex = -1;
799 } else {
800 opts.mExitCoordinatorIndex =
801 activity.mActivityTransitionState.addExitTransitionCoordinator(exit);
802 }
803 return exit;
George Mount62ab9b72014-05-02 13:51:17 -0700804 }
805
806 /** @hide */
George Mount413739e2016-06-08 07:13:37 -0700807 static ActivityOptions makeSceneTransitionAnimation(Activity activity,
George Mount62ab9b72014-05-02 13:51:17 -0700808 ExitTransitionCoordinator exitCoordinator, ArrayList<String> sharedElementNames,
809 int resultCode, Intent resultData) {
810 ActivityOptions opts = new ActivityOptions();
811 opts.mAnimationType = ANIM_SCENE_TRANSITION;
812 opts.mSharedElementNames = sharedElementNames;
813 opts.mTransitionReceiver = exitCoordinator;
814 opts.mIsReturning = true;
815 opts.mResultCode = resultCode;
816 opts.mResultData = resultData;
George Mount1fecfb22014-06-18 14:55:55 -0700817 opts.mExitCoordinatorIndex =
818 activity.mActivityTransitionState.addExitTransitionCoordinator(exitCoordinator);
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700819 return opts;
820 }
821
Craig Mautnerbb742462014-07-07 15:28:55 -0700822 /**
823 * If set along with Intent.FLAG_ACTIVITY_NEW_DOCUMENT then the task being launched will not be
824 * presented to the user but will instead be only available through the recents task list.
825 * In addition, the new task wil be affiliated with the launching activity's task.
826 * Affiliated tasks are grouped together in the recents task list.
827 *
828 * <p>This behavior is not supported for activities with {@link
829 * android.R.styleable#AndroidManifestActivity_launchMode launchMode} values of
830 * <code>singleInstance</code> or <code>singleTask</code>.
831 */
Craig Mautner3b2cd1d2014-08-25 14:25:54 -0700832 public static ActivityOptions makeTaskLaunchBehind() {
Craig Mautnerbb742462014-07-07 15:28:55 -0700833 final ActivityOptions opts = new ActivityOptions();
834 opts.mAnimationType = ANIM_LAUNCH_TASK_BEHIND;
835 return opts;
836 }
837
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700838 /**
839 * Create a basic ActivityOptions that has no special animation associated with it.
840 * Other options can still be set.
841 */
842 public static ActivityOptions makeBasic() {
843 final ActivityOptions opts = new ActivityOptions();
844 return opts;
845 }
846
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100847 /**
848 * Create an {@link ActivityOptions} instance that lets the application control the entire
849 * animation using a {@link RemoteAnimationAdapter}.
850 * @hide
851 */
852 @RequiresPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS)
Mathew Inwood4fb17d12018-08-14 14:25:44 +0100853 @UnsupportedAppUsage
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100854 public static ActivityOptions makeRemoteAnimation(
855 RemoteAnimationAdapter remoteAnimationAdapter) {
856 final ActivityOptions opts = new ActivityOptions();
857 opts.mRemoteAnimationAdapter = remoteAnimationAdapter;
858 opts.mAnimationType = ANIM_REMOTE_ANIMATION;
859 return opts;
860 }
861
Craig Mautnerbb742462014-07-07 15:28:55 -0700862 /** @hide */
863 public boolean getLaunchTaskBehind() {
864 return mAnimationType == ANIM_LAUNCH_TASK_BEHIND;
865 }
866
Dianne Hackborn6de01a92012-03-19 19:07:40 -0700867 private ActivityOptions() {
868 }
869
870 /** @hide */
871 public ActivityOptions(Bundle opts) {
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700872 // If the remote side sent us bad parcelables, they won't get the
873 // results they want, which is their loss.
874 opts.setDefusable(true);
875
Dianne Hackborn6de01a92012-03-19 19:07:40 -0700876 mPackageName = opts.getString(KEY_PACKAGE_NAME);
Dianne Hackbornb5a380d2015-05-20 18:18:46 -0700877 try {
878 mUsageTimeReport = opts.getParcelable(KEY_USAGE_TIME_REPORT);
879 } catch (RuntimeException e) {
880 Slog.w(TAG, e);
881 }
Wale Ogunwale5122df02016-01-29 22:33:38 -0800882 mLaunchBounds = opts.getParcelable(KEY_LAUNCH_BOUNDS);
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700883 mAnimationType = opts.getInt(KEY_ANIM_TYPE);
Adam Powell18e905f2013-10-24 14:27:48 -0700884 switch (mAnimationType) {
885 case ANIM_CUSTOM:
886 mCustomEnterResId = opts.getInt(KEY_ANIM_ENTER_RES_ID, 0);
887 mCustomExitResId = opts.getInt(KEY_ANIM_EXIT_RES_ID, 0);
888 mAnimationStartedListener = IRemoteCallback.Stub.asInterface(
889 opts.getBinder(KEY_ANIM_START_LISTENER));
890 break;
891
Winson Chung044d5292014-11-06 11:05:19 -0800892 case ANIM_CUSTOM_IN_PLACE:
893 mCustomInPlaceResId = opts.getInt(KEY_ANIM_IN_PLACE_RES_ID, 0);
894 break;
895
Adam Powell18e905f2013-10-24 14:27:48 -0700896 case ANIM_SCALE_UP:
Chet Haase10e23ab2015-02-11 15:08:38 -0800897 case ANIM_CLIP_REVEAL:
Adam Powell18e905f2013-10-24 14:27:48 -0700898 mStartX = opts.getInt(KEY_ANIM_START_X, 0);
899 mStartY = opts.getInt(KEY_ANIM_START_Y, 0);
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200900 mWidth = opts.getInt(KEY_ANIM_WIDTH, 0);
901 mHeight = opts.getInt(KEY_ANIM_HEIGHT, 0);
Adam Powell18e905f2013-10-24 14:27:48 -0700902 break;
903
904 case ANIM_THUMBNAIL_SCALE_UP:
905 case ANIM_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -0700906 case ANIM_THUMBNAIL_ASPECT_SCALE_UP:
907 case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN:
Winson Chungaa7fa012017-05-24 15:50:06 -0700908 // Unpackage the GraphicBuffer from the parceled thumbnail
909 final GraphicBuffer buffer = opts.getParcelable(KEY_ANIM_THUMBNAIL);
910 if (buffer != null) {
911 mThumbnail = Bitmap.createHardwareBitmap(buffer);
912 }
Adam Powell18e905f2013-10-24 14:27:48 -0700913 mStartX = opts.getInt(KEY_ANIM_START_X, 0);
914 mStartY = opts.getInt(KEY_ANIM_START_Y, 0);
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200915 mWidth = opts.getInt(KEY_ANIM_WIDTH, 0);
916 mHeight = opts.getInt(KEY_ANIM_HEIGHT, 0);
Adam Powell18e905f2013-10-24 14:27:48 -0700917 mAnimationStartedListener = IRemoteCallback.Stub.asInterface(
918 opts.getBinder(KEY_ANIM_START_LISTENER));
919 break;
920
921 case ANIM_SCENE_TRANSITION:
George Mount62ab9b72014-05-02 13:51:17 -0700922 mTransitionReceiver = opts.getParcelable(KEY_TRANSITION_COMPLETE_LISTENER);
923 mIsReturning = opts.getBoolean(KEY_TRANSITION_IS_RETURNING, false);
924 mSharedElementNames = opts.getStringArrayList(KEY_TRANSITION_SHARED_ELEMENTS);
George Mount62ab9b72014-05-02 13:51:17 -0700925 mResultData = opts.getParcelable(KEY_RESULT_DATA);
926 mResultCode = opts.getInt(KEY_RESULT_CODE);
George Mount1fecfb22014-06-18 14:55:55 -0700927 mExitCoordinatorIndex = opts.getInt(KEY_EXIT_COORDINATOR_INDEX);
Adam Powell18e905f2013-10-24 14:27:48 -0700928 break;
Dianne Hackborn6de01a92012-03-19 19:07:40 -0700929 }
Charles He2bf28322017-10-12 22:24:49 +0100930 mLockTaskMode = opts.getBoolean(KEY_LOCK_TASK_MODE, false);
Andrii Kulian16802aa2016-11-02 12:21:33 -0700931 mLaunchDisplayId = opts.getInt(KEY_LAUNCH_DISPLAY_ID, INVALID_DISPLAY);
Wale Ogunwale0568aed2017-09-08 13:29:37 -0700932 mLaunchWindowingMode = opts.getInt(KEY_LAUNCH_WINDOWING_MODE, WINDOWING_MODE_UNDEFINED);
933 mLaunchActivityType = opts.getInt(KEY_LAUNCH_ACTIVITY_TYPE, ACTIVITY_TYPE_UNDEFINED);
Jorim Jaggi2adba072016-03-03 13:43:39 +0100934 mLaunchTaskId = opts.getInt(KEY_LAUNCH_TASK_ID, -1);
Wale Ogunwale3b232392016-05-13 15:37:13 -0700935 mTaskOverlay = opts.getBoolean(KEY_TASK_OVERLAY, false);
Winson Chungcbcadc92017-01-12 15:54:12 -0800936 mTaskOverlayCanResume = opts.getBoolean(KEY_TASK_OVERLAY_CAN_RESUME, false);
Winson Chunge2d72172018-01-25 17:46:20 +0000937 mAvoidMoveToFront = opts.getBoolean(KEY_AVOID_MOVE_TO_FRONT, false);
Matthew Ngbf155872017-10-27 15:24:39 -0700938 mSplitScreenCreateMode = opts.getInt(KEY_SPLIT_SCREEN_CREATE_MODE,
939 SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT);
Winson Chungf7e03e12017-08-22 11:32:16 -0700940 mDisallowEnterPictureInPictureWhileLaunching = opts.getBoolean(
941 KEY_DISALLOW_ENTER_PICTURE_IN_PICTURE_WHILE_LAUNCHING, false);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700942 if (opts.containsKey(KEY_ANIM_SPECS)) {
943 Parcelable[] specs = opts.getParcelableArray(KEY_ANIM_SPECS);
944 mAnimSpecs = new AppTransitionAnimationSpec[specs.length];
945 for (int i = specs.length - 1; i >= 0; i--) {
946 mAnimSpecs[i] = (AppTransitionAnimationSpec) specs[i];
947 }
948 }
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700949 if (opts.containsKey(KEY_ANIMATION_FINISHED_LISTENER)) {
950 mAnimationFinishedListener = IRemoteCallback.Stub.asInterface(
951 opts.getBinder(KEY_ANIMATION_FINISHED_LISTENER));
952 }
Robert Carrfd10cd12016-06-29 16:41:50 -0700953 mRotationAnimationHint = opts.getInt(KEY_ROTATION_ANIMATION_HINT);
Chad Brubaker06068612017-04-06 09:43:47 -0700954 mAppVerificationBundle = opts.getBundle(KEY_INSTANT_APP_VERIFICATION_BUNDLE);
Jorim Jaggi34795e32017-05-12 17:27:46 +0200955 if (opts.containsKey(KEY_SPECS_FUTURE)) {
956 mSpecsFuture = IAppTransitionAnimationSpecsFuture.Stub.asInterface(opts.getBinder(
957 KEY_SPECS_FUTURE));
958 }
Jorim Jaggi33a701a2017-12-01 14:58:18 +0100959 mRemoteAnimationAdapter = opts.getParcelable(KEY_REMOTE_ANIMATION_ADAPTER);
Dianne Hackborn6de01a92012-03-19 19:07:40 -0700960 }
961
Wale Ogunwale7a8fa602015-11-18 15:56:57 -0800962 /**
Wale Ogunwale5122df02016-01-29 22:33:38 -0800963 * Sets the bounds (window size) that the activity should be launched in.
Andrii Kulian8f1701d2016-03-10 21:56:35 -0800964 * Rect position should be provided in pixels and in screen coordinates.
Wale Ogunwale5122df02016-01-29 22:33:38 -0800965 * Set to null explicitly for fullscreen.
966 * <p>
967 * <strong>NOTE:<strong/> This value is ignored on devices that don't have
968 * {@link android.content.pm.PackageManager#FEATURE_FREEFORM_WINDOW_MANAGEMENT} or
969 * {@link android.content.pm.PackageManager#FEATURE_PICTURE_IN_PICTURE} enabled.
Andrii Kulian8f1701d2016-03-10 21:56:35 -0800970 * @param screenSpacePixelRect Launch bounds to use for the activity or null for fullscreen.
Wale Ogunwale7a8fa602015-11-18 15:56:57 -0800971 */
Andrii Kulian8f1701d2016-03-10 21:56:35 -0800972 public ActivityOptions setLaunchBounds(@Nullable Rect screenSpacePixelRect) {
973 mLaunchBounds = screenSpacePixelRect != null ? new Rect(screenSpacePixelRect) : null;
Chong Zhang0fa656b2015-08-31 15:17:21 -0700974 return this;
975 }
976
977 /** @hide */
Dianne Hackborn6de01a92012-03-19 19:07:40 -0700978 public String getPackageName() {
979 return mPackageName;
980 }
981
Wale Ogunwale5122df02016-01-29 22:33:38 -0800982 /**
983 * Returns the bounds that should be used to launch the activity.
984 * @see #setLaunchBounds(Rect)
985 * @return Bounds used to launch the activity.
986 */
987 @Nullable
988 public Rect getLaunchBounds() {
Wale Ogunwale7a8fa602015-11-18 15:56:57 -0800989 return mLaunchBounds;
Chong Zhang0fa656b2015-08-31 15:17:21 -0700990 }
991
992 /** @hide */
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700993 public int getAnimationType() {
994 return mAnimationType;
Dianne Hackborn6de01a92012-03-19 19:07:40 -0700995 }
996
997 /** @hide */
998 public int getCustomEnterResId() {
999 return mCustomEnterResId;
1000 }
1001
1002 /** @hide */
1003 public int getCustomExitResId() {
1004 return mCustomExitResId;
1005 }
1006
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001007 /** @hide */
Winson Chung044d5292014-11-06 11:05:19 -08001008 public int getCustomInPlaceResId() {
1009 return mCustomInPlaceResId;
1010 }
1011
Winson Chungaa7fa012017-05-24 15:50:06 -07001012 /**
1013 * The thumbnail is copied into a hardware bitmap when it is bundled and sent to the system, so
1014 * it should always be backed by a GraphicBuffer on the other end.
1015 *
1016 * @hide
1017 */
1018 public GraphicBuffer getThumbnail() {
Winson Chungf229ae52017-06-02 14:34:52 -07001019 return mThumbnail != null ? mThumbnail.createGraphicBufferHandle() : null;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001020 }
1021
1022 /** @hide */
1023 public int getStartX() {
1024 return mStartX;
1025 }
1026
1027 /** @hide */
1028 public int getStartY() {
1029 return mStartY;
1030 }
1031
1032 /** @hide */
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001033 public int getWidth() {
1034 return mWidth;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001035 }
1036
1037 /** @hide */
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001038 public int getHeight() {
1039 return mHeight;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001040 }
1041
1042 /** @hide */
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001043 public IRemoteCallback getOnAnimationStartListener() {
1044 return mAnimationStartedListener;
1045 }
1046
1047 /** @hide */
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001048 public IRemoteCallback getAnimationFinishedListener() {
1049 return mAnimationFinishedListener;
1050 }
1051
1052 /** @hide */
George Mount1fecfb22014-06-18 14:55:55 -07001053 public int getExitCoordinatorKey() { return mExitCoordinatorIndex; }
George Mounte1803372014-02-26 19:00:52 +00001054
1055 /** @hide */
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001056 public void abort() {
1057 if (mAnimationStartedListener != null) {
1058 try {
1059 mAnimationStartedListener.sendResult(null);
1060 } catch (RemoteException e) {
1061 }
1062 }
1063 }
1064
1065 /** @hide */
George Mount62ab9b72014-05-02 13:51:17 -07001066 public boolean isReturning() {
1067 return mIsReturning;
1068 }
1069
George Mount413739e2016-06-08 07:13:37 -07001070 /**
1071 * Returns whether or not the ActivityOptions was created with
1072 * {@link #startSharedElementAnimation(Window, Pair[])}.
1073 *
1074 * @hide
1075 */
1076 boolean isCrossTask() {
1077 return mExitCoordinatorIndex < 0;
1078 }
1079
George Mount62ab9b72014-05-02 13:51:17 -07001080 /** @hide */
1081 public ArrayList<String> getSharedElementNames() {
1082 return mSharedElementNames;
1083 }
1084
1085 /** @hide */
George Mount62ab9b72014-05-02 13:51:17 -07001086 public ResultReceiver getResultReceiver() { return mTransitionReceiver; }
1087
1088 /** @hide */
1089 public int getResultCode() { return mResultCode; }
1090
1091 /** @hide */
1092 public Intent getResultData() { return mResultData; }
1093
1094 /** @hide */
Dianne Hackbornb5a380d2015-05-20 18:18:46 -07001095 public PendingIntent getUsageTimeReport() {
1096 return mUsageTimeReport;
1097 }
1098
1099 /** @hide */
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001100 public AppTransitionAnimationSpec[] getAnimSpecs() { return mAnimSpecs; }
1101
1102 /** @hide */
Jorim Jaggi34795e32017-05-12 17:27:46 +02001103 public IAppTransitionAnimationSpecsFuture getSpecsFuture() {
1104 return mSpecsFuture;
1105 }
1106
1107 /** @hide */
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001108 public RemoteAnimationAdapter getRemoteAnimationAdapter() {
1109 return mRemoteAnimationAdapter;
1110 }
1111
1112 /** @hide */
Jorim Jaggi04dc5962018-01-29 18:54:13 +01001113 public void setRemoteAnimationAdapter(RemoteAnimationAdapter remoteAnimationAdapter) {
1114 mRemoteAnimationAdapter = remoteAnimationAdapter;
1115 }
1116
1117 /** @hide */
Chong Zhang280d3322015-11-03 17:27:26 -08001118 public static ActivityOptions fromBundle(Bundle bOptions) {
1119 return bOptions != null ? new ActivityOptions(bOptions) : null;
1120 }
1121
1122 /** @hide */
1123 public static void abort(ActivityOptions options) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001124 if (options != null) {
Chong Zhang280d3322015-11-03 17:27:26 -08001125 options.abort();
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001126 }
1127 }
1128
Andrii Kulian16802aa2016-11-02 12:21:33 -07001129 /**
Charles He2bf28322017-10-12 22:24:49 +01001130 * Gets whether the activity is to be launched into LockTask mode.
1131 * @return {@code true} if the activity is to be launched into LockTask mode.
1132 * @see Activity#startLockTask()
1133 * @see android.app.admin.DevicePolicyManager#setLockTaskPackages(ComponentName, String[])
1134 */
1135 public boolean getLockTaskMode() {
1136 return mLockTaskMode;
1137 }
1138
1139 /**
1140 * Sets whether the activity is to be launched into LockTask mode.
1141 *
1142 * Use this option to start an activity in LockTask mode. Note that only apps permitted by
1143 * {@link android.app.admin.DevicePolicyManager} can run in LockTask mode. Therefore, if
1144 * {@link android.app.admin.DevicePolicyManager#isLockTaskPermitted(String)} returns
1145 * {@code false} for the package of the target activity, a {@link SecurityException} will be
Benjamin Franz11f05822018-03-29 15:40:06 +01001146 * thrown during {@link Context#startActivity(Intent, Bundle)}. This method doesn't affect
1147 * activities that are already running — relaunch the activity to run in lock task mode.
Charles He2bf28322017-10-12 22:24:49 +01001148 *
1149 * Defaults to {@code false} if not set.
1150 *
1151 * @param lockTaskMode {@code true} if the activity is to be launched into LockTask mode.
1152 * @return {@code this} {@link ActivityOptions} instance.
1153 * @see Activity#startLockTask()
1154 * @see android.app.admin.DevicePolicyManager#setLockTaskPackages(ComponentName, String[])
1155 */
Benjamin Franzcaffa772018-02-05 16:36:10 +00001156 public ActivityOptions setLockTaskEnabled(boolean lockTaskMode) {
Charles He2bf28322017-10-12 22:24:49 +01001157 mLockTaskMode = lockTaskMode;
1158 return this;
1159 }
1160
1161 /**
Andrii Kulian16802aa2016-11-02 12:21:33 -07001162 * Gets the id of the display where activity should be launched.
1163 * @return The id of the display where activity should be launched,
1164 * {@link android.view.Display#INVALID_DISPLAY} if not set.
Andrii Kulian1981f5f2017-04-07 16:23:12 -07001165 * @see #setLaunchDisplayId(int)
Andrii Kulian16802aa2016-11-02 12:21:33 -07001166 */
1167 public int getLaunchDisplayId() {
1168 return mLaunchDisplayId;
1169 }
1170
1171 /**
1172 * Sets the id of the display where activity should be launched.
Andrii Kulian1981f5f2017-04-07 16:23:12 -07001173 * An app can launch activities on public displays or private displays that are owned by the app
1174 * or where an app already has activities. Otherwise, trying to launch on a private display
1175 * or providing an invalid display id will result in an exception.
1176 * <p>
1177 * Setting launch display id will be ignored on devices that don't have
1178 * {@link android.content.pm.PackageManager#FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS}.
Andrii Kulian16802aa2016-11-02 12:21:33 -07001179 * @param launchDisplayId The id of the display where the activity should be launched.
1180 * @return {@code this} {@link ActivityOptions} instance.
1181 */
1182 public ActivityOptions setLaunchDisplayId(int launchDisplayId) {
1183 mLaunchDisplayId = launchDisplayId;
1184 return this;
1185 }
1186
Filip Gruszczynski90186c62015-10-26 14:07:00 -07001187 /** @hide */
Wale Ogunwale0568aed2017-09-08 13:29:37 -07001188 public int getLaunchWindowingMode() {
1189 return mLaunchWindowingMode;
1190 }
1191
1192 /**
1193 * Sets the windowing mode the activity should launch into. If the input windowing mode is
1194 * {@link android.app.WindowConfiguration#WINDOWING_MODE_SPLIT_SCREEN_SECONDARY} and the device
1195 * isn't currently in split-screen windowing mode, then the activity will be launched in
1196 * {@link android.app.WindowConfiguration#WINDOWING_MODE_FULLSCREEN} windowing mode. For clarity
1197 * on this you can use
1198 * {@link android.app.WindowConfiguration#WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY}
1199 *
1200 * @hide
1201 */
1202 @TestApi
1203 public void setLaunchWindowingMode(int windowingMode) {
1204 mLaunchWindowingMode = windowingMode;
1205 }
1206
1207 /** @hide */
1208 public int getLaunchActivityType() {
1209 return mLaunchActivityType;
Wale Ogunwale854809c2015-12-27 16:18:19 -08001210 }
1211
1212 /** @hide */
Vladislav Kaznacheevacf147e2016-05-05 09:32:27 -07001213 @TestApi
Wale Ogunwale0568aed2017-09-08 13:29:37 -07001214 public void setLaunchActivityType(int activityType) {
1215 mLaunchActivityType = activityType;
Wale Ogunwale854809c2015-12-27 16:18:19 -08001216 }
1217
Jorim Jaggi2adba072016-03-03 13:43:39 +01001218 /**
1219 * Sets the task the activity will be launched in.
1220 * @hide
1221 */
Winson Chung6954fc92017-03-24 16:22:12 -07001222 @TestApi
Jorim Jaggi2adba072016-03-03 13:43:39 +01001223 public void setLaunchTaskId(int taskId) {
1224 mLaunchTaskId = taskId;
1225 }
1226
1227 /**
1228 * @hide
1229 */
1230 public int getLaunchTaskId() {
1231 return mLaunchTaskId;
1232 }
1233
Jorim Jaggic875ae72016-04-26 22:41:06 -07001234 /**
Wale Ogunwale3b232392016-05-13 15:37:13 -07001235 * Set's whether the activity launched with this option should be a task overlay. That is the
Winson Chungcbcadc92017-01-12 15:54:12 -08001236 * activity will always be the top activity of the task. If {@param canResume} is true, then
1237 * the task will also not be moved to the front of the stack.
Jorim Jaggic875ae72016-04-26 22:41:06 -07001238 * @hide
1239 */
Winson Chung6954fc92017-03-24 16:22:12 -07001240 @TestApi
Winson Chungcbcadc92017-01-12 15:54:12 -08001241 public void setTaskOverlay(boolean taskOverlay, boolean canResume) {
Wale Ogunwale3b232392016-05-13 15:37:13 -07001242 mTaskOverlay = taskOverlay;
Winson Chungcbcadc92017-01-12 15:54:12 -08001243 mTaskOverlayCanResume = canResume;
Jorim Jaggic875ae72016-04-26 22:41:06 -07001244 }
1245
1246 /**
1247 * @hide
1248 */
Wale Ogunwale3b232392016-05-13 15:37:13 -07001249 public boolean getTaskOverlay() {
1250 return mTaskOverlay;
Jorim Jaggic875ae72016-04-26 22:41:06 -07001251 }
1252
Winson Chungcbcadc92017-01-12 15:54:12 -08001253 /**
1254 * @hide
1255 */
1256 public boolean canTaskOverlayResume() {
1257 return mTaskOverlayCanResume;
1258 }
1259
Winson Chunge2d72172018-01-25 17:46:20 +00001260 /**
1261 * Sets whether the activity launched should not cause the activity stack it is contained in to
1262 * be moved to the front as a part of launching.
1263 *
1264 * @hide
1265 */
1266 public void setAvoidMoveToFront() {
1267 mAvoidMoveToFront = true;
1268 }
1269
1270 /**
1271 * @return whether the activity launch should prevent moving the associated activity stack to
1272 * the front.
1273 * @hide
1274 */
1275 public boolean getAvoidMoveToFront() {
1276 return mAvoidMoveToFront;
1277 }
1278
Wale Ogunwale854809c2015-12-27 16:18:19 -08001279 /** @hide */
Matthew Ngbf155872017-10-27 15:24:39 -07001280 public int getSplitScreenCreateMode() {
1281 return mSplitScreenCreateMode;
Wale Ogunwale854809c2015-12-27 16:18:19 -08001282 }
Filip Gruszczynski90186c62015-10-26 14:07:00 -07001283
1284 /** @hide */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01001285 @UnsupportedAppUsage
Matthew Ngbf155872017-10-27 15:24:39 -07001286 public void setSplitScreenCreateMode(int splitScreenCreateMode) {
1287 mSplitScreenCreateMode = splitScreenCreateMode;
Filip Gruszczynski90186c62015-10-26 14:07:00 -07001288 }
1289
Winson Chungf7e03e12017-08-22 11:32:16 -07001290 /** @hide */
1291 public void setDisallowEnterPictureInPictureWhileLaunching(boolean disallow) {
1292 mDisallowEnterPictureInPictureWhileLaunching = disallow;
1293 }
1294
1295 /** @hide */
1296 public boolean disallowEnterPictureInPictureWhileLaunching() {
1297 return mDisallowEnterPictureInPictureWhileLaunching;
1298 }
1299
Dianne Hackborn6de01a92012-03-19 19:07:40 -07001300 /**
Dianne Hackbornddc52a82012-05-03 19:40:12 -07001301 * Update the current values in this ActivityOptions from those supplied
1302 * in <var>otherOptions</var>. Any values
Dianne Hackborn6de01a92012-03-19 19:07:40 -07001303 * defined in <var>otherOptions</var> replace those in the base options.
1304 */
Dianne Hackbornddc52a82012-05-03 19:40:12 -07001305 public void update(ActivityOptions otherOptions) {
Dianne Hackborn6de01a92012-03-19 19:07:40 -07001306 if (otherOptions.mPackageName != null) {
1307 mPackageName = otherOptions.mPackageName;
1308 }
Dianne Hackbornb5a380d2015-05-20 18:18:46 -07001309 mUsageTimeReport = otherOptions.mUsageTimeReport;
George Mount62ab9b72014-05-02 13:51:17 -07001310 mTransitionReceiver = null;
1311 mSharedElementNames = null;
George Mount62ab9b72014-05-02 13:51:17 -07001312 mIsReturning = false;
1313 mResultData = null;
1314 mResultCode = 0;
George Mount1fecfb22014-06-18 14:55:55 -07001315 mExitCoordinatorIndex = 0;
George Mount00dde0b2014-07-01 15:27:07 -07001316 mAnimationType = otherOptions.mAnimationType;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001317 switch (otherOptions.mAnimationType) {
1318 case ANIM_CUSTOM:
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001319 mCustomEnterResId = otherOptions.mCustomEnterResId;
1320 mCustomExitResId = otherOptions.mCustomExitResId;
1321 mThumbnail = null;
Adam Powell18e905f2013-10-24 14:27:48 -07001322 if (mAnimationStartedListener != null) {
Dianne Hackborn84375872012-06-01 19:03:50 -07001323 try {
Adam Powell18e905f2013-10-24 14:27:48 -07001324 mAnimationStartedListener.sendResult(null);
Dianne Hackborn84375872012-06-01 19:03:50 -07001325 } catch (RemoteException e) {
1326 }
1327 }
1328 mAnimationStartedListener = otherOptions.mAnimationStartedListener;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001329 break;
Winson Chung044d5292014-11-06 11:05:19 -08001330 case ANIM_CUSTOM_IN_PLACE:
1331 mCustomInPlaceResId = otherOptions.mCustomInPlaceResId;
1332 break;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001333 case ANIM_SCALE_UP:
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001334 mStartX = otherOptions.mStartX;
1335 mStartY = otherOptions.mStartY;
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001336 mWidth = otherOptions.mWidth;
1337 mHeight = otherOptions.mHeight;
Adam Powell18e905f2013-10-24 14:27:48 -07001338 if (mAnimationStartedListener != null) {
Dianne Hackborn84375872012-06-01 19:03:50 -07001339 try {
Adam Powell18e905f2013-10-24 14:27:48 -07001340 mAnimationStartedListener.sendResult(null);
Dianne Hackborn84375872012-06-01 19:03:50 -07001341 } catch (RemoteException e) {
1342 }
1343 }
1344 mAnimationStartedListener = null;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001345 break;
Michael Jurka832cb222012-04-13 09:32:47 -07001346 case ANIM_THUMBNAIL_SCALE_UP:
1347 case ANIM_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001348 case ANIM_THUMBNAIL_ASPECT_SCALE_UP:
1349 case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN:
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001350 mThumbnail = otherOptions.mThumbnail;
1351 mStartX = otherOptions.mStartX;
1352 mStartY = otherOptions.mStartY;
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001353 mWidth = otherOptions.mWidth;
1354 mHeight = otherOptions.mHeight;
Adam Powell18e905f2013-10-24 14:27:48 -07001355 if (mAnimationStartedListener != null) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001356 try {
Adam Powell18e905f2013-10-24 14:27:48 -07001357 mAnimationStartedListener.sendResult(null);
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001358 } catch (RemoteException e) {
1359 }
1360 }
1361 mAnimationStartedListener = otherOptions.mAnimationStartedListener;
Adam Powell18e905f2013-10-24 14:27:48 -07001362 break;
1363 case ANIM_SCENE_TRANSITION:
George Mount62ab9b72014-05-02 13:51:17 -07001364 mTransitionReceiver = otherOptions.mTransitionReceiver;
1365 mSharedElementNames = otherOptions.mSharedElementNames;
George Mount62ab9b72014-05-02 13:51:17 -07001366 mIsReturning = otherOptions.mIsReturning;
Adam Powellcfbe9be2013-11-06 14:58:58 -08001367 mThumbnail = null;
Adam Powell18e905f2013-10-24 14:27:48 -07001368 mAnimationStartedListener = null;
George Mount62ab9b72014-05-02 13:51:17 -07001369 mResultData = otherOptions.mResultData;
1370 mResultCode = otherOptions.mResultCode;
George Mount1fecfb22014-06-18 14:55:55 -07001371 mExitCoordinatorIndex = otherOptions.mExitCoordinatorIndex;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001372 break;
Dianne Hackborn6de01a92012-03-19 19:07:40 -07001373 }
Charles He2bf28322017-10-12 22:24:49 +01001374 mLockTaskMode = otherOptions.mLockTaskMode;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001375 mAnimSpecs = otherOptions.mAnimSpecs;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001376 mAnimationFinishedListener = otherOptions.mAnimationFinishedListener;
Jorim Jaggi34795e32017-05-12 17:27:46 +02001377 mSpecsFuture = otherOptions.mSpecsFuture;
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001378 mRemoteAnimationAdapter = otherOptions.mRemoteAnimationAdapter;
Dianne Hackborn6de01a92012-03-19 19:07:40 -07001379 }
1380
1381 /**
1382 * Returns the created options as a Bundle, which can be passed to
1383 * {@link android.content.Context#startActivity(android.content.Intent, android.os.Bundle)
1384 * Context.startActivity(Intent, Bundle)} and related methods.
1385 * Note that the returned Bundle is still owned by the ActivityOptions
1386 * object; you must not modify it, but can supply it to the startActivity
1387 * methods that take an options Bundle.
1388 */
1389 public Bundle toBundle() {
1390 Bundle b = new Bundle();
1391 if (mPackageName != null) {
1392 b.putString(KEY_PACKAGE_NAME, mPackageName);
1393 }
Wale Ogunwale5122df02016-01-29 22:33:38 -08001394 if (mLaunchBounds != null) {
Wale Ogunwale7a8fa602015-11-18 15:56:57 -08001395 b.putParcelable(KEY_LAUNCH_BOUNDS, mLaunchBounds);
Chong Zhang0fa656b2015-08-31 15:17:21 -07001396 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001397 b.putInt(KEY_ANIM_TYPE, mAnimationType);
Dianne Hackbornb5a380d2015-05-20 18:18:46 -07001398 if (mUsageTimeReport != null) {
1399 b.putParcelable(KEY_USAGE_TIME_REPORT, mUsageTimeReport);
1400 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001401 switch (mAnimationType) {
1402 case ANIM_CUSTOM:
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001403 b.putInt(KEY_ANIM_ENTER_RES_ID, mCustomEnterResId);
1404 b.putInt(KEY_ANIM_EXIT_RES_ID, mCustomExitResId);
Adam Powellcfbe9be2013-11-06 14:58:58 -08001405 b.putBinder(KEY_ANIM_START_LISTENER, mAnimationStartedListener
Dianne Hackborn84375872012-06-01 19:03:50 -07001406 != null ? mAnimationStartedListener.asBinder() : null);
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001407 break;
Winson Chung044d5292014-11-06 11:05:19 -08001408 case ANIM_CUSTOM_IN_PLACE:
1409 b.putInt(KEY_ANIM_IN_PLACE_RES_ID, mCustomInPlaceResId);
1410 break;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001411 case ANIM_SCALE_UP:
Chet Haase10e23ab2015-02-11 15:08:38 -08001412 case ANIM_CLIP_REVEAL:
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001413 b.putInt(KEY_ANIM_START_X, mStartX);
1414 b.putInt(KEY_ANIM_START_Y, mStartY);
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001415 b.putInt(KEY_ANIM_WIDTH, mWidth);
1416 b.putInt(KEY_ANIM_HEIGHT, mHeight);
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001417 break;
Michael Jurka832cb222012-04-13 09:32:47 -07001418 case ANIM_THUMBNAIL_SCALE_UP:
1419 case ANIM_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001420 case ANIM_THUMBNAIL_ASPECT_SCALE_UP:
1421 case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN:
Winson Chungaa7fa012017-05-24 15:50:06 -07001422 // Once we parcel the thumbnail for transfering over to the system, create a copy of
1423 // the bitmap to a hardware bitmap and pass through the GraphicBuffer
Winson Chungf229ae52017-06-02 14:34:52 -07001424 if (mThumbnail != null) {
Winson Chung06b50ab2017-06-16 11:07:29 -07001425 final Bitmap hwBitmap = mThumbnail.copy(Config.HARDWARE, false /* isMutable */);
Winson Chungf229ae52017-06-02 14:34:52 -07001426 if (hwBitmap != null) {
1427 b.putParcelable(KEY_ANIM_THUMBNAIL, hwBitmap.createGraphicBufferHandle());
1428 } else {
1429 Slog.w(TAG, "Failed to copy thumbnail");
1430 }
Winson Chungaa7fa012017-05-24 15:50:06 -07001431 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001432 b.putInt(KEY_ANIM_START_X, mStartX);
1433 b.putInt(KEY_ANIM_START_Y, mStartY);
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001434 b.putInt(KEY_ANIM_WIDTH, mWidth);
1435 b.putInt(KEY_ANIM_HEIGHT, mHeight);
Adam Powellcfbe9be2013-11-06 14:58:58 -08001436 b.putBinder(KEY_ANIM_START_LISTENER, mAnimationStartedListener
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001437 != null ? mAnimationStartedListener.asBinder() : null);
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001438 break;
Adam Powellcfbe9be2013-11-06 14:58:58 -08001439 case ANIM_SCENE_TRANSITION:
George Mount62ab9b72014-05-02 13:51:17 -07001440 if (mTransitionReceiver != null) {
1441 b.putParcelable(KEY_TRANSITION_COMPLETE_LISTENER, mTransitionReceiver);
George Mount0a778ed2013-12-13 13:35:36 -08001442 }
George Mount62ab9b72014-05-02 13:51:17 -07001443 b.putBoolean(KEY_TRANSITION_IS_RETURNING, mIsReturning);
1444 b.putStringArrayList(KEY_TRANSITION_SHARED_ELEMENTS, mSharedElementNames);
George Mount62ab9b72014-05-02 13:51:17 -07001445 b.putParcelable(KEY_RESULT_DATA, mResultData);
1446 b.putInt(KEY_RESULT_CODE, mResultCode);
George Mount1fecfb22014-06-18 14:55:55 -07001447 b.putInt(KEY_EXIT_COORDINATOR_INDEX, mExitCoordinatorIndex);
Adam Powellcfbe9be2013-11-06 14:58:58 -08001448 break;
Dianne Hackborn6de01a92012-03-19 19:07:40 -07001449 }
Charles He2bf28322017-10-12 22:24:49 +01001450 b.putBoolean(KEY_LOCK_TASK_MODE, mLockTaskMode);
Andrii Kulian16802aa2016-11-02 12:21:33 -07001451 b.putInt(KEY_LAUNCH_DISPLAY_ID, mLaunchDisplayId);
Wale Ogunwale0568aed2017-09-08 13:29:37 -07001452 b.putInt(KEY_LAUNCH_WINDOWING_MODE, mLaunchWindowingMode);
1453 b.putInt(KEY_LAUNCH_ACTIVITY_TYPE, mLaunchActivityType);
Jorim Jaggi2adba072016-03-03 13:43:39 +01001454 b.putInt(KEY_LAUNCH_TASK_ID, mLaunchTaskId);
Wale Ogunwale3b232392016-05-13 15:37:13 -07001455 b.putBoolean(KEY_TASK_OVERLAY, mTaskOverlay);
Winson Chungcbcadc92017-01-12 15:54:12 -08001456 b.putBoolean(KEY_TASK_OVERLAY_CAN_RESUME, mTaskOverlayCanResume);
Winson Chunge2d72172018-01-25 17:46:20 +00001457 b.putBoolean(KEY_AVOID_MOVE_TO_FRONT, mAvoidMoveToFront);
Matthew Ngbf155872017-10-27 15:24:39 -07001458 b.putInt(KEY_SPLIT_SCREEN_CREATE_MODE, mSplitScreenCreateMode);
Winson Chungf7e03e12017-08-22 11:32:16 -07001459 b.putBoolean(KEY_DISALLOW_ENTER_PICTURE_IN_PICTURE_WHILE_LAUNCHING,
1460 mDisallowEnterPictureInPictureWhileLaunching);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001461 if (mAnimSpecs != null) {
1462 b.putParcelableArray(KEY_ANIM_SPECS, mAnimSpecs);
1463 }
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001464 if (mAnimationFinishedListener != null) {
1465 b.putBinder(KEY_ANIMATION_FINISHED_LISTENER, mAnimationFinishedListener.asBinder());
1466 }
Jorim Jaggi34795e32017-05-12 17:27:46 +02001467 if (mSpecsFuture != null) {
1468 b.putBinder(KEY_SPECS_FUTURE, mSpecsFuture.asBinder());
1469 }
Robert Carrfd10cd12016-06-29 16:41:50 -07001470 b.putInt(KEY_ROTATION_ANIMATION_HINT, mRotationAnimationHint);
Chad Brubaker06068612017-04-06 09:43:47 -07001471 if (mAppVerificationBundle != null) {
1472 b.putBundle(KEY_INSTANT_APP_VERIFICATION_BUNDLE, mAppVerificationBundle);
1473 }
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001474 if (mRemoteAnimationAdapter != null) {
1475 b.putParcelable(KEY_REMOTE_ANIMATION_ADAPTER, mRemoteAnimationAdapter);
1476 }
Dianne Hackborn6de01a92012-03-19 19:07:40 -07001477 return b;
1478 }
Adam Powellcfbe9be2013-11-06 14:58:58 -08001479
1480 /**
Dianne Hackbornb5a380d2015-05-20 18:18:46 -07001481 * Ask the the system track that time the user spends in the app being launched, and
1482 * report it back once done. The report will be sent to the given receiver, with
Dianne Hackborn67ba2c72015-06-05 14:23:38 -07001483 * the extras {@link #EXTRA_USAGE_TIME_REPORT} and {@link #EXTRA_USAGE_TIME_REPORT_PACKAGES}
Dianne Hackbornb5a380d2015-05-20 18:18:46 -07001484 * filled in.
1485 *
1486 * <p>The time interval tracked is from launching this activity until the user leaves
1487 * that activity's flow. They are considered to stay in the flow as long as
1488 * new activities are being launched or returned to from the original flow,
1489 * even if this crosses package or task boundaries. For example, if the originator
1490 * starts an activity to view an image, and while there the user selects to share,
1491 * which launches their email app in a new task, and they complete the share, the
1492 * time during that entire operation will be included until they finally hit back from
1493 * the original image viewer activity.</p>
1494 *
1495 * <p>The user is considered to complete a flow once they switch to another
1496 * activity that is not part of the tracked flow. This may happen, for example, by
1497 * using the notification shade, launcher, or recents to launch or switch to another
1498 * app. Simply going in to these navigation elements does not break the flow (although
1499 * the launcher and recents stops time tracking of the session); it is the act of
1500 * going somewhere else that completes the tracking.</p>
1501 *
1502 * @param receiver A broadcast receiver that willl receive the report.
1503 */
1504 public void requestUsageTimeReport(PendingIntent receiver) {
1505 mUsageTimeReport = receiver;
1506 }
1507
1508 /**
Adam Powellcfbe9be2013-11-06 14:58:58 -08001509 * Return the filtered options only meant to be seen by the target activity itself
1510 * @hide
1511 */
1512 public ActivityOptions forTargetActivity() {
1513 if (mAnimationType == ANIM_SCENE_TRANSITION) {
1514 final ActivityOptions result = new ActivityOptions();
1515 result.update(this);
1516 return result;
1517 }
1518
1519 return null;
1520 }
George Mount0a778ed2013-12-13 13:35:36 -08001521
Robert Carrfd10cd12016-06-29 16:41:50 -07001522 /**
1523 * Returns the rotation animation set by {@link setRotationAnimationHint} or -1
1524 * if unspecified.
1525 * @hide
1526 */
1527 public int getRotationAnimationHint() {
1528 return mRotationAnimationHint;
1529 }
1530
1531
1532 /**
1533 * Set a rotation animation to be used if launching the activity
1534 * triggers an orientation change, or -1 to clear. See
1535 * {@link android.view.WindowManager.LayoutParams} for rotation
1536 * animation values.
1537 * @hide
1538 */
1539 public void setRotationAnimationHint(int hint) {
1540 mRotationAnimationHint = hint;
1541 }
1542
Chad Brubaker06068612017-04-06 09:43:47 -07001543 /**
1544 * Pop the extra verification bundle for the installer.
1545 * This removes the bundle from the ActivityOptions to make sure the installer bundle
1546 * is only available once.
1547 * @hide
1548 */
1549 public Bundle popAppVerificationBundle() {
1550 Bundle out = mAppVerificationBundle;
1551 mAppVerificationBundle = null;
1552 return out;
1553 }
1554
1555 /**
1556 * Set the {@link Bundle} that is provided to the app installer for additional verification
1557 * if the call to {@link Context#startActivity} results in an app being installed.
1558 *
1559 * This Bundle is not provided to any other app besides the installer.
1560 */
1561 public ActivityOptions setAppVerificationBundle(Bundle bundle) {
1562 mAppVerificationBundle = bundle;
1563 return this;
1564
1565 }
1566
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -08001567 /** @hide */
1568 @Override
1569 public String toString() {
1570 return "ActivityOptions(" + hashCode() + "), mPackageName=" + mPackageName
1571 + ", mAnimationType=" + mAnimationType + ", mStartX=" + mStartX + ", mStartY="
1572 + mStartY + ", mWidth=" + mWidth + ", mHeight=" + mHeight;
1573 }
George Mount413739e2016-06-08 07:13:37 -07001574
Ben Weisse0c37bd2016-10-26 11:18:32 +01001575 private static class HideWindowListener extends TransitionListenerAdapter
George Mount413739e2016-06-08 07:13:37 -07001576 implements ExitTransitionCoordinator.HideSharedElementsCallback {
1577 private final Window mWindow;
1578 private final ExitTransitionCoordinator mExit;
1579 private final boolean mWaitingForTransition;
1580 private boolean mTransitionEnded;
1581 private boolean mSharedElementHidden;
1582 private ArrayList<View> mSharedElements;
1583
1584 public HideWindowListener(Window window, ExitTransitionCoordinator exit) {
1585 mWindow = window;
1586 mExit = exit;
1587 mSharedElements = new ArrayList<>(exit.mSharedElements);
1588 Transition transition = mWindow.getExitTransition();
1589 if (transition != null) {
1590 transition.addListener(this);
1591 mWaitingForTransition = true;
1592 } else {
1593 mWaitingForTransition = false;
1594 }
1595 View decorView = mWindow.getDecorView();
1596 if (decorView != null) {
1597 if (decorView.getTag(com.android.internal.R.id.cross_task_transition) != null) {
1598 throw new IllegalStateException(
1599 "Cannot start a transition while one is running");
1600 }
1601 decorView.setTagInternal(com.android.internal.R.id.cross_task_transition, exit);
1602 }
1603 }
1604
1605 @Override
1606 public void onTransitionEnd(Transition transition) {
1607 mTransitionEnded = true;
1608 hideWhenDone();
1609 transition.removeListener(this);
1610 }
1611
1612 @Override
1613 public void hideSharedElements() {
1614 mSharedElementHidden = true;
1615 hideWhenDone();
1616 }
1617
1618 private void hideWhenDone() {
1619 if (mSharedElementHidden && (!mWaitingForTransition || mTransitionEnded)) {
1620 mExit.resetViews();
1621 int numSharedElements = mSharedElements.size();
1622 for (int i = 0; i < numSharedElements; i++) {
1623 View view = mSharedElements.get(i);
1624 view.requestLayout();
1625 }
1626 View decorView = mWindow.getDecorView();
1627 if (decorView != null) {
1628 decorView.setTagInternal(
1629 com.android.internal.R.id.cross_task_transition, null);
1630 decorView.setVisibility(View.GONE);
1631 }
1632 }
1633 }
1634 }
Dianne Hackborn6de01a92012-03-19 19:07:40 -07001635}