blob: d4e17a89c97b963766c57dc08ff9a24b7d474057 [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 /**
Benjamin Miller55714562018-07-05 10:24:28 +0000963 * Sets the bounds (window size and position) 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.
Benjamin Miller55714562018-07-05 10:24:28 +0000965 * Set to {@code null} to explicitly launch fullscreen.
Wale Ogunwale5122df02016-01-29 22:33:38 -0800966 * <p>
Benjamin Miller55714562018-07-05 10:24:28 +0000967 * <strong>NOTE:</strong> This value is ignored on devices that don't have
Wale Ogunwale5122df02016-01-29 22:33:38 -0800968 * {@link android.content.pm.PackageManager#FEATURE_FREEFORM_WINDOW_MANAGEMENT} or
969 * {@link android.content.pm.PackageManager#FEATURE_PICTURE_IN_PICTURE} enabled.
Benjamin Miller55714562018-07-05 10:24:28 +0000970 * @param screenSpacePixelRect launch bounds or {@code null} for fullscreen
971 * @return {@code this} {@link ActivityOptions} instance
Wale Ogunwale7a8fa602015-11-18 15:56:57 -0800972 */
Andrii Kulian8f1701d2016-03-10 21:56:35 -0800973 public ActivityOptions setLaunchBounds(@Nullable Rect screenSpacePixelRect) {
974 mLaunchBounds = screenSpacePixelRect != null ? new Rect(screenSpacePixelRect) : null;
Chong Zhang0fa656b2015-08-31 15:17:21 -0700975 return this;
976 }
977
978 /** @hide */
Dianne Hackborn6de01a92012-03-19 19:07:40 -0700979 public String getPackageName() {
980 return mPackageName;
981 }
982
Wale Ogunwale5122df02016-01-29 22:33:38 -0800983 /**
984 * Returns the bounds that should be used to launch the activity.
985 * @see #setLaunchBounds(Rect)
986 * @return Bounds used to launch the activity.
987 */
988 @Nullable
989 public Rect getLaunchBounds() {
Wale Ogunwale7a8fa602015-11-18 15:56:57 -0800990 return mLaunchBounds;
Chong Zhang0fa656b2015-08-31 15:17:21 -0700991 }
992
993 /** @hide */
Dianne Hackborn8078d8c2012-03-20 11:11:26 -0700994 public int getAnimationType() {
995 return mAnimationType;
Dianne Hackborn6de01a92012-03-19 19:07:40 -0700996 }
997
998 /** @hide */
999 public int getCustomEnterResId() {
1000 return mCustomEnterResId;
1001 }
1002
1003 /** @hide */
1004 public int getCustomExitResId() {
1005 return mCustomExitResId;
1006 }
1007
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001008 /** @hide */
Winson Chung044d5292014-11-06 11:05:19 -08001009 public int getCustomInPlaceResId() {
1010 return mCustomInPlaceResId;
1011 }
1012
Winson Chungaa7fa012017-05-24 15:50:06 -07001013 /**
1014 * The thumbnail is copied into a hardware bitmap when it is bundled and sent to the system, so
1015 * it should always be backed by a GraphicBuffer on the other end.
1016 *
1017 * @hide
1018 */
1019 public GraphicBuffer getThumbnail() {
Winson Chungf229ae52017-06-02 14:34:52 -07001020 return mThumbnail != null ? mThumbnail.createGraphicBufferHandle() : null;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001021 }
1022
1023 /** @hide */
1024 public int getStartX() {
1025 return mStartX;
1026 }
1027
1028 /** @hide */
1029 public int getStartY() {
1030 return mStartY;
1031 }
1032
1033 /** @hide */
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001034 public int getWidth() {
1035 return mWidth;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001036 }
1037
1038 /** @hide */
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001039 public int getHeight() {
1040 return mHeight;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001041 }
1042
1043 /** @hide */
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001044 public IRemoteCallback getOnAnimationStartListener() {
1045 return mAnimationStartedListener;
1046 }
1047
1048 /** @hide */
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001049 public IRemoteCallback getAnimationFinishedListener() {
1050 return mAnimationFinishedListener;
1051 }
1052
1053 /** @hide */
George Mount1fecfb22014-06-18 14:55:55 -07001054 public int getExitCoordinatorKey() { return mExitCoordinatorIndex; }
George Mounte1803372014-02-26 19:00:52 +00001055
1056 /** @hide */
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001057 public void abort() {
1058 if (mAnimationStartedListener != null) {
1059 try {
1060 mAnimationStartedListener.sendResult(null);
1061 } catch (RemoteException e) {
1062 }
1063 }
1064 }
1065
1066 /** @hide */
George Mount62ab9b72014-05-02 13:51:17 -07001067 public boolean isReturning() {
1068 return mIsReturning;
1069 }
1070
George Mount413739e2016-06-08 07:13:37 -07001071 /**
1072 * Returns whether or not the ActivityOptions was created with
1073 * {@link #startSharedElementAnimation(Window, Pair[])}.
1074 *
1075 * @hide
1076 */
1077 boolean isCrossTask() {
1078 return mExitCoordinatorIndex < 0;
1079 }
1080
George Mount62ab9b72014-05-02 13:51:17 -07001081 /** @hide */
1082 public ArrayList<String> getSharedElementNames() {
1083 return mSharedElementNames;
1084 }
1085
1086 /** @hide */
George Mount62ab9b72014-05-02 13:51:17 -07001087 public ResultReceiver getResultReceiver() { return mTransitionReceiver; }
1088
1089 /** @hide */
1090 public int getResultCode() { return mResultCode; }
1091
1092 /** @hide */
1093 public Intent getResultData() { return mResultData; }
1094
1095 /** @hide */
Dianne Hackbornb5a380d2015-05-20 18:18:46 -07001096 public PendingIntent getUsageTimeReport() {
1097 return mUsageTimeReport;
1098 }
1099
1100 /** @hide */
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001101 public AppTransitionAnimationSpec[] getAnimSpecs() { return mAnimSpecs; }
1102
1103 /** @hide */
Jorim Jaggi34795e32017-05-12 17:27:46 +02001104 public IAppTransitionAnimationSpecsFuture getSpecsFuture() {
1105 return mSpecsFuture;
1106 }
1107
1108 /** @hide */
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001109 public RemoteAnimationAdapter getRemoteAnimationAdapter() {
1110 return mRemoteAnimationAdapter;
1111 }
1112
1113 /** @hide */
Jorim Jaggi04dc5962018-01-29 18:54:13 +01001114 public void setRemoteAnimationAdapter(RemoteAnimationAdapter remoteAnimationAdapter) {
1115 mRemoteAnimationAdapter = remoteAnimationAdapter;
1116 }
1117
1118 /** @hide */
Chong Zhang280d3322015-11-03 17:27:26 -08001119 public static ActivityOptions fromBundle(Bundle bOptions) {
1120 return bOptions != null ? new ActivityOptions(bOptions) : null;
1121 }
1122
1123 /** @hide */
1124 public static void abort(ActivityOptions options) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001125 if (options != null) {
Chong Zhang280d3322015-11-03 17:27:26 -08001126 options.abort();
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001127 }
1128 }
1129
Andrii Kulian16802aa2016-11-02 12:21:33 -07001130 /**
Charles He2bf28322017-10-12 22:24:49 +01001131 * Gets whether the activity is to be launched into LockTask mode.
1132 * @return {@code true} if the activity is to be launched into LockTask mode.
1133 * @see Activity#startLockTask()
1134 * @see android.app.admin.DevicePolicyManager#setLockTaskPackages(ComponentName, String[])
1135 */
1136 public boolean getLockTaskMode() {
1137 return mLockTaskMode;
1138 }
1139
1140 /**
1141 * Sets whether the activity is to be launched into LockTask mode.
1142 *
1143 * Use this option to start an activity in LockTask mode. Note that only apps permitted by
1144 * {@link android.app.admin.DevicePolicyManager} can run in LockTask mode. Therefore, if
1145 * {@link android.app.admin.DevicePolicyManager#isLockTaskPermitted(String)} returns
1146 * {@code false} for the package of the target activity, a {@link SecurityException} will be
Benjamin Franz11f05822018-03-29 15:40:06 +01001147 * thrown during {@link Context#startActivity(Intent, Bundle)}. This method doesn't affect
1148 * activities that are already running — relaunch the activity to run in lock task mode.
Charles He2bf28322017-10-12 22:24:49 +01001149 *
1150 * Defaults to {@code false} if not set.
1151 *
1152 * @param lockTaskMode {@code true} if the activity is to be launched into LockTask mode.
1153 * @return {@code this} {@link ActivityOptions} instance.
1154 * @see Activity#startLockTask()
1155 * @see android.app.admin.DevicePolicyManager#setLockTaskPackages(ComponentName, String[])
1156 */
Benjamin Franzcaffa772018-02-05 16:36:10 +00001157 public ActivityOptions setLockTaskEnabled(boolean lockTaskMode) {
Charles He2bf28322017-10-12 22:24:49 +01001158 mLockTaskMode = lockTaskMode;
1159 return this;
1160 }
1161
1162 /**
Andrii Kulian16802aa2016-11-02 12:21:33 -07001163 * Gets the id of the display where activity should be launched.
1164 * @return The id of the display where activity should be launched,
1165 * {@link android.view.Display#INVALID_DISPLAY} if not set.
Andrii Kulian1981f5f2017-04-07 16:23:12 -07001166 * @see #setLaunchDisplayId(int)
Andrii Kulian16802aa2016-11-02 12:21:33 -07001167 */
1168 public int getLaunchDisplayId() {
1169 return mLaunchDisplayId;
1170 }
1171
1172 /**
1173 * Sets the id of the display where activity should be launched.
Andrii Kulian1981f5f2017-04-07 16:23:12 -07001174 * An app can launch activities on public displays or private displays that are owned by the app
1175 * or where an app already has activities. Otherwise, trying to launch on a private display
1176 * or providing an invalid display id will result in an exception.
1177 * <p>
1178 * Setting launch display id will be ignored on devices that don't have
1179 * {@link android.content.pm.PackageManager#FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS}.
Andrii Kulian16802aa2016-11-02 12:21:33 -07001180 * @param launchDisplayId The id of the display where the activity should be launched.
1181 * @return {@code this} {@link ActivityOptions} instance.
1182 */
1183 public ActivityOptions setLaunchDisplayId(int launchDisplayId) {
1184 mLaunchDisplayId = launchDisplayId;
1185 return this;
1186 }
1187
Filip Gruszczynski90186c62015-10-26 14:07:00 -07001188 /** @hide */
Wale Ogunwale0568aed2017-09-08 13:29:37 -07001189 public int getLaunchWindowingMode() {
1190 return mLaunchWindowingMode;
1191 }
1192
1193 /**
1194 * Sets the windowing mode the activity should launch into. If the input windowing mode is
1195 * {@link android.app.WindowConfiguration#WINDOWING_MODE_SPLIT_SCREEN_SECONDARY} and the device
1196 * isn't currently in split-screen windowing mode, then the activity will be launched in
1197 * {@link android.app.WindowConfiguration#WINDOWING_MODE_FULLSCREEN} windowing mode. For clarity
1198 * on this you can use
1199 * {@link android.app.WindowConfiguration#WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY}
1200 *
1201 * @hide
1202 */
1203 @TestApi
1204 public void setLaunchWindowingMode(int windowingMode) {
1205 mLaunchWindowingMode = windowingMode;
1206 }
1207
1208 /** @hide */
1209 public int getLaunchActivityType() {
1210 return mLaunchActivityType;
Wale Ogunwale854809c2015-12-27 16:18:19 -08001211 }
1212
1213 /** @hide */
Vladislav Kaznacheevacf147e2016-05-05 09:32:27 -07001214 @TestApi
Wale Ogunwale0568aed2017-09-08 13:29:37 -07001215 public void setLaunchActivityType(int activityType) {
1216 mLaunchActivityType = activityType;
Wale Ogunwale854809c2015-12-27 16:18:19 -08001217 }
1218
Jorim Jaggi2adba072016-03-03 13:43:39 +01001219 /**
1220 * Sets the task the activity will be launched in.
1221 * @hide
1222 */
Winson Chung6954fc92017-03-24 16:22:12 -07001223 @TestApi
Jorim Jaggi2adba072016-03-03 13:43:39 +01001224 public void setLaunchTaskId(int taskId) {
1225 mLaunchTaskId = taskId;
1226 }
1227
1228 /**
1229 * @hide
1230 */
1231 public int getLaunchTaskId() {
1232 return mLaunchTaskId;
1233 }
1234
Jorim Jaggic875ae72016-04-26 22:41:06 -07001235 /**
Wale Ogunwale3b232392016-05-13 15:37:13 -07001236 * Set's whether the activity launched with this option should be a task overlay. That is the
Winson Chungcbcadc92017-01-12 15:54:12 -08001237 * activity will always be the top activity of the task. If {@param canResume} is true, then
1238 * the task will also not be moved to the front of the stack.
Jorim Jaggic875ae72016-04-26 22:41:06 -07001239 * @hide
1240 */
Winson Chung6954fc92017-03-24 16:22:12 -07001241 @TestApi
Winson Chungcbcadc92017-01-12 15:54:12 -08001242 public void setTaskOverlay(boolean taskOverlay, boolean canResume) {
Wale Ogunwale3b232392016-05-13 15:37:13 -07001243 mTaskOverlay = taskOverlay;
Winson Chungcbcadc92017-01-12 15:54:12 -08001244 mTaskOverlayCanResume = canResume;
Jorim Jaggic875ae72016-04-26 22:41:06 -07001245 }
1246
1247 /**
1248 * @hide
1249 */
Wale Ogunwale3b232392016-05-13 15:37:13 -07001250 public boolean getTaskOverlay() {
1251 return mTaskOverlay;
Jorim Jaggic875ae72016-04-26 22:41:06 -07001252 }
1253
Winson Chungcbcadc92017-01-12 15:54:12 -08001254 /**
1255 * @hide
1256 */
1257 public boolean canTaskOverlayResume() {
1258 return mTaskOverlayCanResume;
1259 }
1260
Winson Chunge2d72172018-01-25 17:46:20 +00001261 /**
1262 * Sets whether the activity launched should not cause the activity stack it is contained in to
1263 * be moved to the front as a part of launching.
1264 *
1265 * @hide
1266 */
1267 public void setAvoidMoveToFront() {
1268 mAvoidMoveToFront = true;
1269 }
1270
1271 /**
1272 * @return whether the activity launch should prevent moving the associated activity stack to
1273 * the front.
1274 * @hide
1275 */
1276 public boolean getAvoidMoveToFront() {
1277 return mAvoidMoveToFront;
1278 }
1279
Wale Ogunwale854809c2015-12-27 16:18:19 -08001280 /** @hide */
Matthew Ngbf155872017-10-27 15:24:39 -07001281 public int getSplitScreenCreateMode() {
1282 return mSplitScreenCreateMode;
Wale Ogunwale854809c2015-12-27 16:18:19 -08001283 }
Filip Gruszczynski90186c62015-10-26 14:07:00 -07001284
1285 /** @hide */
Mathew Inwood4fb17d12018-08-14 14:25:44 +01001286 @UnsupportedAppUsage
Matthew Ngbf155872017-10-27 15:24:39 -07001287 public void setSplitScreenCreateMode(int splitScreenCreateMode) {
1288 mSplitScreenCreateMode = splitScreenCreateMode;
Filip Gruszczynski90186c62015-10-26 14:07:00 -07001289 }
1290
Winson Chungf7e03e12017-08-22 11:32:16 -07001291 /** @hide */
1292 public void setDisallowEnterPictureInPictureWhileLaunching(boolean disallow) {
1293 mDisallowEnterPictureInPictureWhileLaunching = disallow;
1294 }
1295
1296 /** @hide */
1297 public boolean disallowEnterPictureInPictureWhileLaunching() {
1298 return mDisallowEnterPictureInPictureWhileLaunching;
1299 }
1300
Dianne Hackborn6de01a92012-03-19 19:07:40 -07001301 /**
Dianne Hackbornddc52a82012-05-03 19:40:12 -07001302 * Update the current values in this ActivityOptions from those supplied
1303 * in <var>otherOptions</var>. Any values
Dianne Hackborn6de01a92012-03-19 19:07:40 -07001304 * defined in <var>otherOptions</var> replace those in the base options.
1305 */
Dianne Hackbornddc52a82012-05-03 19:40:12 -07001306 public void update(ActivityOptions otherOptions) {
Dianne Hackborn6de01a92012-03-19 19:07:40 -07001307 if (otherOptions.mPackageName != null) {
1308 mPackageName = otherOptions.mPackageName;
1309 }
Dianne Hackbornb5a380d2015-05-20 18:18:46 -07001310 mUsageTimeReport = otherOptions.mUsageTimeReport;
George Mount62ab9b72014-05-02 13:51:17 -07001311 mTransitionReceiver = null;
1312 mSharedElementNames = null;
George Mount62ab9b72014-05-02 13:51:17 -07001313 mIsReturning = false;
1314 mResultData = null;
1315 mResultCode = 0;
George Mount1fecfb22014-06-18 14:55:55 -07001316 mExitCoordinatorIndex = 0;
George Mount00dde0b2014-07-01 15:27:07 -07001317 mAnimationType = otherOptions.mAnimationType;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001318 switch (otherOptions.mAnimationType) {
1319 case ANIM_CUSTOM:
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001320 mCustomEnterResId = otherOptions.mCustomEnterResId;
1321 mCustomExitResId = otherOptions.mCustomExitResId;
1322 mThumbnail = null;
Adam Powell18e905f2013-10-24 14:27:48 -07001323 if (mAnimationStartedListener != null) {
Dianne Hackborn84375872012-06-01 19:03:50 -07001324 try {
Adam Powell18e905f2013-10-24 14:27:48 -07001325 mAnimationStartedListener.sendResult(null);
Dianne Hackborn84375872012-06-01 19:03:50 -07001326 } catch (RemoteException e) {
1327 }
1328 }
1329 mAnimationStartedListener = otherOptions.mAnimationStartedListener;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001330 break;
Winson Chung044d5292014-11-06 11:05:19 -08001331 case ANIM_CUSTOM_IN_PLACE:
1332 mCustomInPlaceResId = otherOptions.mCustomInPlaceResId;
1333 break;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001334 case ANIM_SCALE_UP:
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001335 mStartX = otherOptions.mStartX;
1336 mStartY = otherOptions.mStartY;
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001337 mWidth = otherOptions.mWidth;
1338 mHeight = otherOptions.mHeight;
Adam Powell18e905f2013-10-24 14:27:48 -07001339 if (mAnimationStartedListener != null) {
Dianne Hackborn84375872012-06-01 19:03:50 -07001340 try {
Adam Powell18e905f2013-10-24 14:27:48 -07001341 mAnimationStartedListener.sendResult(null);
Dianne Hackborn84375872012-06-01 19:03:50 -07001342 } catch (RemoteException e) {
1343 }
1344 }
1345 mAnimationStartedListener = null;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001346 break;
Michael Jurka832cb222012-04-13 09:32:47 -07001347 case ANIM_THUMBNAIL_SCALE_UP:
1348 case ANIM_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001349 case ANIM_THUMBNAIL_ASPECT_SCALE_UP:
1350 case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN:
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001351 mThumbnail = otherOptions.mThumbnail;
1352 mStartX = otherOptions.mStartX;
1353 mStartY = otherOptions.mStartY;
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001354 mWidth = otherOptions.mWidth;
1355 mHeight = otherOptions.mHeight;
Adam Powell18e905f2013-10-24 14:27:48 -07001356 if (mAnimationStartedListener != null) {
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001357 try {
Adam Powell18e905f2013-10-24 14:27:48 -07001358 mAnimationStartedListener.sendResult(null);
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001359 } catch (RemoteException e) {
1360 }
1361 }
1362 mAnimationStartedListener = otherOptions.mAnimationStartedListener;
Adam Powell18e905f2013-10-24 14:27:48 -07001363 break;
1364 case ANIM_SCENE_TRANSITION:
George Mount62ab9b72014-05-02 13:51:17 -07001365 mTransitionReceiver = otherOptions.mTransitionReceiver;
1366 mSharedElementNames = otherOptions.mSharedElementNames;
George Mount62ab9b72014-05-02 13:51:17 -07001367 mIsReturning = otherOptions.mIsReturning;
Adam Powellcfbe9be2013-11-06 14:58:58 -08001368 mThumbnail = null;
Adam Powell18e905f2013-10-24 14:27:48 -07001369 mAnimationStartedListener = null;
George Mount62ab9b72014-05-02 13:51:17 -07001370 mResultData = otherOptions.mResultData;
1371 mResultCode = otherOptions.mResultCode;
George Mount1fecfb22014-06-18 14:55:55 -07001372 mExitCoordinatorIndex = otherOptions.mExitCoordinatorIndex;
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001373 break;
Dianne Hackborn6de01a92012-03-19 19:07:40 -07001374 }
Charles He2bf28322017-10-12 22:24:49 +01001375 mLockTaskMode = otherOptions.mLockTaskMode;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001376 mAnimSpecs = otherOptions.mAnimSpecs;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001377 mAnimationFinishedListener = otherOptions.mAnimationFinishedListener;
Jorim Jaggi34795e32017-05-12 17:27:46 +02001378 mSpecsFuture = otherOptions.mSpecsFuture;
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001379 mRemoteAnimationAdapter = otherOptions.mRemoteAnimationAdapter;
Dianne Hackborn6de01a92012-03-19 19:07:40 -07001380 }
1381
1382 /**
1383 * Returns the created options as a Bundle, which can be passed to
1384 * {@link android.content.Context#startActivity(android.content.Intent, android.os.Bundle)
1385 * Context.startActivity(Intent, Bundle)} and related methods.
1386 * Note that the returned Bundle is still owned by the ActivityOptions
1387 * object; you must not modify it, but can supply it to the startActivity
1388 * methods that take an options Bundle.
1389 */
1390 public Bundle toBundle() {
1391 Bundle b = new Bundle();
1392 if (mPackageName != null) {
1393 b.putString(KEY_PACKAGE_NAME, mPackageName);
1394 }
Wale Ogunwale5122df02016-01-29 22:33:38 -08001395 if (mLaunchBounds != null) {
Wale Ogunwale7a8fa602015-11-18 15:56:57 -08001396 b.putParcelable(KEY_LAUNCH_BOUNDS, mLaunchBounds);
Chong Zhang0fa656b2015-08-31 15:17:21 -07001397 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001398 b.putInt(KEY_ANIM_TYPE, mAnimationType);
Dianne Hackbornb5a380d2015-05-20 18:18:46 -07001399 if (mUsageTimeReport != null) {
1400 b.putParcelable(KEY_USAGE_TIME_REPORT, mUsageTimeReport);
1401 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001402 switch (mAnimationType) {
1403 case ANIM_CUSTOM:
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001404 b.putInt(KEY_ANIM_ENTER_RES_ID, mCustomEnterResId);
1405 b.putInt(KEY_ANIM_EXIT_RES_ID, mCustomExitResId);
Adam Powellcfbe9be2013-11-06 14:58:58 -08001406 b.putBinder(KEY_ANIM_START_LISTENER, mAnimationStartedListener
Dianne Hackborn84375872012-06-01 19:03:50 -07001407 != null ? mAnimationStartedListener.asBinder() : null);
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001408 break;
Winson Chung044d5292014-11-06 11:05:19 -08001409 case ANIM_CUSTOM_IN_PLACE:
1410 b.putInt(KEY_ANIM_IN_PLACE_RES_ID, mCustomInPlaceResId);
1411 break;
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001412 case ANIM_SCALE_UP:
Chet Haase10e23ab2015-02-11 15:08:38 -08001413 case ANIM_CLIP_REVEAL:
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001414 b.putInt(KEY_ANIM_START_X, mStartX);
1415 b.putInt(KEY_ANIM_START_Y, mStartY);
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001416 b.putInt(KEY_ANIM_WIDTH, mWidth);
1417 b.putInt(KEY_ANIM_HEIGHT, mHeight);
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001418 break;
Michael Jurka832cb222012-04-13 09:32:47 -07001419 case ANIM_THUMBNAIL_SCALE_UP:
1420 case ANIM_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001421 case ANIM_THUMBNAIL_ASPECT_SCALE_UP:
1422 case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN:
Winson Chungaa7fa012017-05-24 15:50:06 -07001423 // Once we parcel the thumbnail for transfering over to the system, create a copy of
1424 // the bitmap to a hardware bitmap and pass through the GraphicBuffer
Winson Chungf229ae52017-06-02 14:34:52 -07001425 if (mThumbnail != null) {
Winson Chung06b50ab2017-06-16 11:07:29 -07001426 final Bitmap hwBitmap = mThumbnail.copy(Config.HARDWARE, false /* isMutable */);
Winson Chungf229ae52017-06-02 14:34:52 -07001427 if (hwBitmap != null) {
1428 b.putParcelable(KEY_ANIM_THUMBNAIL, hwBitmap.createGraphicBufferHandle());
1429 } else {
1430 Slog.w(TAG, "Failed to copy thumbnail");
1431 }
Winson Chungaa7fa012017-05-24 15:50:06 -07001432 }
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001433 b.putInt(KEY_ANIM_START_X, mStartX);
1434 b.putInt(KEY_ANIM_START_Y, mStartY);
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001435 b.putInt(KEY_ANIM_WIDTH, mWidth);
1436 b.putInt(KEY_ANIM_HEIGHT, mHeight);
Adam Powellcfbe9be2013-11-06 14:58:58 -08001437 b.putBinder(KEY_ANIM_START_LISTENER, mAnimationStartedListener
Dianne Hackborn8078d8c2012-03-20 11:11:26 -07001438 != null ? mAnimationStartedListener.asBinder() : null);
Dianne Hackborneabfb3a2012-04-16 16:28:22 -07001439 break;
Adam Powellcfbe9be2013-11-06 14:58:58 -08001440 case ANIM_SCENE_TRANSITION:
George Mount62ab9b72014-05-02 13:51:17 -07001441 if (mTransitionReceiver != null) {
1442 b.putParcelable(KEY_TRANSITION_COMPLETE_LISTENER, mTransitionReceiver);
George Mount0a778ed2013-12-13 13:35:36 -08001443 }
George Mount62ab9b72014-05-02 13:51:17 -07001444 b.putBoolean(KEY_TRANSITION_IS_RETURNING, mIsReturning);
1445 b.putStringArrayList(KEY_TRANSITION_SHARED_ELEMENTS, mSharedElementNames);
George Mount62ab9b72014-05-02 13:51:17 -07001446 b.putParcelable(KEY_RESULT_DATA, mResultData);
1447 b.putInt(KEY_RESULT_CODE, mResultCode);
George Mount1fecfb22014-06-18 14:55:55 -07001448 b.putInt(KEY_EXIT_COORDINATOR_INDEX, mExitCoordinatorIndex);
Adam Powellcfbe9be2013-11-06 14:58:58 -08001449 break;
Dianne Hackborn6de01a92012-03-19 19:07:40 -07001450 }
Charles He2bf28322017-10-12 22:24:49 +01001451 b.putBoolean(KEY_LOCK_TASK_MODE, mLockTaskMode);
Andrii Kulian16802aa2016-11-02 12:21:33 -07001452 b.putInt(KEY_LAUNCH_DISPLAY_ID, mLaunchDisplayId);
Wale Ogunwale0568aed2017-09-08 13:29:37 -07001453 b.putInt(KEY_LAUNCH_WINDOWING_MODE, mLaunchWindowingMode);
1454 b.putInt(KEY_LAUNCH_ACTIVITY_TYPE, mLaunchActivityType);
Jorim Jaggi2adba072016-03-03 13:43:39 +01001455 b.putInt(KEY_LAUNCH_TASK_ID, mLaunchTaskId);
Wale Ogunwale3b232392016-05-13 15:37:13 -07001456 b.putBoolean(KEY_TASK_OVERLAY, mTaskOverlay);
Winson Chungcbcadc92017-01-12 15:54:12 -08001457 b.putBoolean(KEY_TASK_OVERLAY_CAN_RESUME, mTaskOverlayCanResume);
Winson Chunge2d72172018-01-25 17:46:20 +00001458 b.putBoolean(KEY_AVOID_MOVE_TO_FRONT, mAvoidMoveToFront);
Matthew Ngbf155872017-10-27 15:24:39 -07001459 b.putInt(KEY_SPLIT_SCREEN_CREATE_MODE, mSplitScreenCreateMode);
Winson Chungf7e03e12017-08-22 11:32:16 -07001460 b.putBoolean(KEY_DISALLOW_ENTER_PICTURE_IN_PICTURE_WHILE_LAUNCHING,
1461 mDisallowEnterPictureInPictureWhileLaunching);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001462 if (mAnimSpecs != null) {
1463 b.putParcelableArray(KEY_ANIM_SPECS, mAnimSpecs);
1464 }
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001465 if (mAnimationFinishedListener != null) {
1466 b.putBinder(KEY_ANIMATION_FINISHED_LISTENER, mAnimationFinishedListener.asBinder());
1467 }
Jorim Jaggi34795e32017-05-12 17:27:46 +02001468 if (mSpecsFuture != null) {
1469 b.putBinder(KEY_SPECS_FUTURE, mSpecsFuture.asBinder());
1470 }
Robert Carrfd10cd12016-06-29 16:41:50 -07001471 b.putInt(KEY_ROTATION_ANIMATION_HINT, mRotationAnimationHint);
Chad Brubaker06068612017-04-06 09:43:47 -07001472 if (mAppVerificationBundle != null) {
1473 b.putBundle(KEY_INSTANT_APP_VERIFICATION_BUNDLE, mAppVerificationBundle);
1474 }
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001475 if (mRemoteAnimationAdapter != null) {
1476 b.putParcelable(KEY_REMOTE_ANIMATION_ADAPTER, mRemoteAnimationAdapter);
1477 }
Dianne Hackborn6de01a92012-03-19 19:07:40 -07001478 return b;
1479 }
Adam Powellcfbe9be2013-11-06 14:58:58 -08001480
1481 /**
koprivaa1a78482018-10-09 10:09:23 -07001482 * Ask the system track that time the user spends in the app being launched, and
Dianne Hackbornb5a380d2015-05-20 18:18:46 -07001483 * report it back once done. The report will be sent to the given receiver, with
Dianne Hackborn67ba2c72015-06-05 14:23:38 -07001484 * the extras {@link #EXTRA_USAGE_TIME_REPORT} and {@link #EXTRA_USAGE_TIME_REPORT_PACKAGES}
Dianne Hackbornb5a380d2015-05-20 18:18:46 -07001485 * filled in.
1486 *
1487 * <p>The time interval tracked is from launching this activity until the user leaves
1488 * that activity's flow. They are considered to stay in the flow as long as
1489 * new activities are being launched or returned to from the original flow,
1490 * even if this crosses package or task boundaries. For example, if the originator
1491 * starts an activity to view an image, and while there the user selects to share,
1492 * which launches their email app in a new task, and they complete the share, the
1493 * time during that entire operation will be included until they finally hit back from
1494 * the original image viewer activity.</p>
1495 *
1496 * <p>The user is considered to complete a flow once they switch to another
1497 * activity that is not part of the tracked flow. This may happen, for example, by
1498 * using the notification shade, launcher, or recents to launch or switch to another
1499 * app. Simply going in to these navigation elements does not break the flow (although
1500 * the launcher and recents stops time tracking of the session); it is the act of
1501 * going somewhere else that completes the tracking.</p>
1502 *
1503 * @param receiver A broadcast receiver that willl receive the report.
1504 */
1505 public void requestUsageTimeReport(PendingIntent receiver) {
1506 mUsageTimeReport = receiver;
1507 }
1508
1509 /**
Adam Powellcfbe9be2013-11-06 14:58:58 -08001510 * Return the filtered options only meant to be seen by the target activity itself
1511 * @hide
1512 */
1513 public ActivityOptions forTargetActivity() {
1514 if (mAnimationType == ANIM_SCENE_TRANSITION) {
1515 final ActivityOptions result = new ActivityOptions();
1516 result.update(this);
1517 return result;
1518 }
1519
1520 return null;
1521 }
George Mount0a778ed2013-12-13 13:35:36 -08001522
Robert Carrfd10cd12016-06-29 16:41:50 -07001523 /**
1524 * Returns the rotation animation set by {@link setRotationAnimationHint} or -1
1525 * if unspecified.
1526 * @hide
1527 */
1528 public int getRotationAnimationHint() {
1529 return mRotationAnimationHint;
1530 }
1531
1532
1533 /**
1534 * Set a rotation animation to be used if launching the activity
1535 * triggers an orientation change, or -1 to clear. See
1536 * {@link android.view.WindowManager.LayoutParams} for rotation
1537 * animation values.
1538 * @hide
1539 */
1540 public void setRotationAnimationHint(int hint) {
1541 mRotationAnimationHint = hint;
1542 }
1543
Chad Brubaker06068612017-04-06 09:43:47 -07001544 /**
1545 * Pop the extra verification bundle for the installer.
1546 * This removes the bundle from the ActivityOptions to make sure the installer bundle
1547 * is only available once.
1548 * @hide
1549 */
1550 public Bundle popAppVerificationBundle() {
1551 Bundle out = mAppVerificationBundle;
1552 mAppVerificationBundle = null;
1553 return out;
1554 }
1555
1556 /**
1557 * Set the {@link Bundle} that is provided to the app installer for additional verification
1558 * if the call to {@link Context#startActivity} results in an app being installed.
1559 *
1560 * This Bundle is not provided to any other app besides the installer.
1561 */
1562 public ActivityOptions setAppVerificationBundle(Bundle bundle) {
1563 mAppVerificationBundle = bundle;
1564 return this;
1565
1566 }
1567
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -08001568 /** @hide */
1569 @Override
1570 public String toString() {
1571 return "ActivityOptions(" + hashCode() + "), mPackageName=" + mPackageName
1572 + ", mAnimationType=" + mAnimationType + ", mStartX=" + mStartX + ", mStartY="
1573 + mStartY + ", mWidth=" + mWidth + ", mHeight=" + mHeight;
1574 }
George Mount413739e2016-06-08 07:13:37 -07001575
Ben Weisse0c37bd2016-10-26 11:18:32 +01001576 private static class HideWindowListener extends TransitionListenerAdapter
George Mount413739e2016-06-08 07:13:37 -07001577 implements ExitTransitionCoordinator.HideSharedElementsCallback {
1578 private final Window mWindow;
1579 private final ExitTransitionCoordinator mExit;
1580 private final boolean mWaitingForTransition;
1581 private boolean mTransitionEnded;
1582 private boolean mSharedElementHidden;
1583 private ArrayList<View> mSharedElements;
1584
1585 public HideWindowListener(Window window, ExitTransitionCoordinator exit) {
1586 mWindow = window;
1587 mExit = exit;
1588 mSharedElements = new ArrayList<>(exit.mSharedElements);
1589 Transition transition = mWindow.getExitTransition();
1590 if (transition != null) {
1591 transition.addListener(this);
1592 mWaitingForTransition = true;
1593 } else {
1594 mWaitingForTransition = false;
1595 }
1596 View decorView = mWindow.getDecorView();
1597 if (decorView != null) {
1598 if (decorView.getTag(com.android.internal.R.id.cross_task_transition) != null) {
1599 throw new IllegalStateException(
1600 "Cannot start a transition while one is running");
1601 }
1602 decorView.setTagInternal(com.android.internal.R.id.cross_task_transition, exit);
1603 }
1604 }
1605
1606 @Override
1607 public void onTransitionEnd(Transition transition) {
1608 mTransitionEnded = true;
1609 hideWhenDone();
1610 transition.removeListener(this);
1611 }
1612
1613 @Override
1614 public void hideSharedElements() {
1615 mSharedElementHidden = true;
1616 hideWhenDone();
1617 }
1618
1619 private void hideWhenDone() {
1620 if (mSharedElementHidden && (!mWaitingForTransition || mTransitionEnded)) {
1621 mExit.resetViews();
1622 int numSharedElements = mSharedElements.size();
1623 for (int i = 0; i < numSharedElements; i++) {
1624 View view = mSharedElements.get(i);
1625 view.requestLayout();
1626 }
1627 View decorView = mWindow.getDecorView();
1628 if (decorView != null) {
1629 decorView.setTagInternal(
1630 com.android.internal.R.id.cross_task_transition, null);
1631 decorView.setVisibility(View.GONE);
1632 }
1633 }
1634 }
1635 }
Dianne Hackborn6de01a92012-03-19 19:07:40 -07001636}