Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.app; |
| 18 | |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 19 | import static android.Manifest.permission.CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS; |
Matthew Ng | bf15587 | 2017-10-27 15:24:39 -0700 | [diff] [blame] | 20 | import static android.app.ActivityManager.SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 21 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
| 22 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 23 | import static android.view.Display.INVALID_DISPLAY; |
Filip Gruszczynski | 90186c6 | 2015-10-26 14:07:00 -0700 | [diff] [blame] | 24 | |
Wale Ogunwale | 5122df0 | 2016-01-29 22:33:38 -0800 | [diff] [blame] | 25 | import android.annotation.Nullable; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 26 | import android.annotation.RequiresPermission; |
Vladislav Kaznacheev | acf147e | 2016-05-05 09:32:27 -0700 | [diff] [blame] | 27 | import android.annotation.TestApi; |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 28 | import android.annotation.UnsupportedAppUsage; |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 29 | import android.content.ComponentName; |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 30 | import android.content.Context; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 31 | import android.content.Intent; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 32 | import android.graphics.Bitmap; |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 33 | import android.graphics.Bitmap.Config; |
| 34 | import android.graphics.GraphicBuffer; |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 35 | import android.graphics.Rect; |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 36 | import android.os.Bundle; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 37 | import android.os.Handler; |
| 38 | import android.os.IRemoteCallback; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 39 | import android.os.Parcelable; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 40 | import android.os.RemoteException; |
George Mount | cb4b7d9 | 2014-02-25 10:47:55 -0800 | [diff] [blame] | 41 | import android.os.ResultReceiver; |
Tony Mak | 089c35e | 2017-12-18 20:34:14 +0000 | [diff] [blame] | 42 | import android.os.UserHandle; |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 43 | import android.transition.Transition; |
Ben Weiss | e0c37bd | 2016-10-26 11:18:32 +0100 | [diff] [blame] | 44 | import android.transition.TransitionListenerAdapter; |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 45 | import android.transition.TransitionManager; |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 46 | import android.util.Pair; |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 47 | import android.util.Slog; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 48 | import android.view.AppTransitionAnimationSpec; |
Jorim Jaggi | 34795e3 | 2017-05-12 17:27:46 +0200 | [diff] [blame] | 49 | import android.view.IAppTransitionAnimationSpecsFuture; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 50 | import android.view.RemoteAnimationAdapter; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 51 | import android.view.View; |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 52 | import android.view.ViewGroup; |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 53 | import android.view.Window; |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 54 | |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 55 | import java.util.ArrayList; |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 56 | |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 57 | /** |
| 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 | */ |
| 62 | public class ActivityOptions { |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 63 | private static final String TAG = "ActivityOptions"; |
| 64 | |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 65 | /** |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 66 | * A long in the extras delivered by {@link #requestUsageTimeReport} that contains |
Dianne Hackborn | 67ba2c7 | 2015-06-05 14:23:38 -0700 | [diff] [blame] | 67 | * the total time (in ms) the user spent in the app flow. |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 68 | */ |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 69 | public static final String EXTRA_USAGE_TIME_REPORT = "android.activity.usage_time"; |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 70 | |
| 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 Hackborn | 67ba2c7 | 2015-06-05 14:23:38 -0700 | [diff] [blame] | 76 | public static final String EXTRA_USAGE_TIME_REPORT_PACKAGES = "android.usage_time_packages"; |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 77 | |
| 78 | /** |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 79 | * The package name that created the options. |
| 80 | * @hide |
| 81 | */ |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 82 | public static final String KEY_PACKAGE_NAME = "android:activity.packageName"; |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 85 | * 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 Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 88 | * {@link android.content.pm.PackageManager#FEATURE_FREEFORM_WINDOW_MANAGEMENT} or |
| 89 | * {@link android.content.pm.PackageManager#FEATURE_PICTURE_IN_PICTURE} enabled. |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 90 | * @hide |
| 91 | */ |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 92 | public static final String KEY_LAUNCH_BOUNDS = "android:activity.launchBounds"; |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 93 | |
| 94 | /** |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 95 | * Type of animation that arguments specify. |
| 96 | * @hide |
| 97 | */ |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 98 | public static final String KEY_ANIM_TYPE = "android:activity.animType"; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 99 | |
| 100 | /** |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 101 | * Custom enter animation resource ID. |
| 102 | * @hide |
| 103 | */ |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 104 | public static final String KEY_ANIM_ENTER_RES_ID = "android:activity.animEnterRes"; |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 105 | |
| 106 | /** |
| 107 | * Custom exit animation resource ID. |
| 108 | * @hide |
| 109 | */ |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 110 | public static final String KEY_ANIM_EXIT_RES_ID = "android:activity.animExitRes"; |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 111 | |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 112 | /** |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 113 | * Custom in-place animation resource ID. |
| 114 | * @hide |
| 115 | */ |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 116 | public static final String KEY_ANIM_IN_PLACE_RES_ID = "android:activity.animInPlaceRes"; |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 117 | |
| 118 | /** |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 119 | * Bitmap for thumbnail animation. |
| 120 | * @hide |
| 121 | */ |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 122 | public static final String KEY_ANIM_THUMBNAIL = "android:activity.animThumbnail"; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 123 | |
| 124 | /** |
| 125 | * Start X position of thumbnail animation. |
| 126 | * @hide |
| 127 | */ |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 128 | public static final String KEY_ANIM_START_X = "android:activity.animStartX"; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 129 | |
| 130 | /** |
| 131 | * Start Y position of thumbnail animation. |
| 132 | * @hide |
| 133 | */ |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 134 | public static final String KEY_ANIM_START_Y = "android:activity.animStartY"; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 135 | |
| 136 | /** |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 137 | * Initial width of the animation. |
| 138 | * @hide |
| 139 | */ |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 140 | public static final String KEY_ANIM_WIDTH = "android:activity.animWidth"; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 141 | |
| 142 | /** |
| 143 | * Initial height of the animation. |
| 144 | * @hide |
| 145 | */ |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 146 | public static final String KEY_ANIM_HEIGHT = "android:activity.animHeight"; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 147 | |
| 148 | /** |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 149 | * Callback for when animation is started. |
| 150 | * @hide |
| 151 | */ |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 152 | public static final String KEY_ANIM_START_LISTENER = "android:activity.animStartListener"; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 153 | |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 154 | /** |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 155 | * 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 Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 162 | * 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 He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 167 | * Whether the activity should be launched into LockTask mode. |
Benjamin Franz | caffa77 | 2018-02-05 16:36:10 +0000 | [diff] [blame] | 168 | * @see #setLockTaskEnabled(boolean) |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 169 | */ |
| 170 | private static final String KEY_LOCK_TASK_MODE = "android:activity.lockTaskMode"; |
| 171 | |
| 172 | /** |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 173 | * The display id the activity should be launched into. |
Andrii Kulian | 1981f5f | 2017-04-07 16:23:12 -0700 | [diff] [blame] | 174 | * @see #setLaunchDisplayId(int) |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 175 | * @hide |
| 176 | */ |
| 177 | private static final String KEY_LAUNCH_DISPLAY_ID = "android.activity.launchDisplayId"; |
| 178 | |
| 179 | /** |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 180 | * The windowing mode the activity should be launched into. |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 181 | * @hide |
| 182 | */ |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 183 | 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 Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 190 | |
| 191 | /** |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 192 | * 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 Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 198 | * See {@link #setTaskOverlay}. |
Jorim Jaggi | c875ae7 | 2016-04-26 22:41:06 -0700 | [diff] [blame] | 199 | * @hide |
| 200 | */ |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 201 | private static final String KEY_TASK_OVERLAY = "android.activity.taskOverlay"; |
Jorim Jaggi | c875ae7 | 2016-04-26 22:41:06 -0700 | [diff] [blame] | 202 | |
| 203 | /** |
Winson Chung | cbcadc9 | 2017-01-12 15:54:12 -0800 | [diff] [blame] | 204 | * See {@link #setTaskOverlay}. |
| 205 | * @hide |
| 206 | */ |
| 207 | private static final String KEY_TASK_OVERLAY_CAN_RESUME = |
| 208 | "android.activity.taskOverlayCanResume"; |
| 209 | |
| 210 | /** |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 211 | * See {@link #setAvoidMoveToFront()}. |
| 212 | * @hide |
| 213 | */ |
| 214 | private static final String KEY_AVOID_MOVE_TO_FRONT = "android.activity.avoidMoveToFront"; |
| 215 | |
| 216 | /** |
Matthew Ng | bf15587 | 2017-10-27 15:24:39 -0700 | [diff] [blame] | 217 | * Where the split-screen-primary stack should be positioned. |
Filip Gruszczynski | 90186c6 | 2015-10-26 14:07:00 -0700 | [diff] [blame] | 218 | * @hide |
| 219 | */ |
Matthew Ng | bf15587 | 2017-10-27 15:24:39 -0700 | [diff] [blame] | 220 | private static final String KEY_SPLIT_SCREEN_CREATE_MODE = |
| 221 | "android:activity.splitScreenCreateMode"; |
Filip Gruszczynski | 90186c6 | 2015-10-26 14:07:00 -0700 | [diff] [blame] | 222 | |
| 223 | /** |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 224 | * 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 Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 232 | * 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 Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 237 | = "android:activity.transitionCompleteListener"; |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 238 | |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 239 | 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 Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 247 | |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 248 | private static final String KEY_USAGE_TIME_REPORT = "android:activity.usageTimeReport"; |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 249 | private static final String KEY_ROTATION_ANIMATION_HINT = "android:activity.rotationAnimationHint"; |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 250 | |
Chad Brubaker | 0606861 | 2017-04-06 09:43:47 -0700 | [diff] [blame] | 251 | private static final String KEY_INSTANT_APP_VERIFICATION_BUNDLE |
| 252 | = "android:instantapps.installerbundle"; |
Jorim Jaggi | 34795e3 | 2017-05-12 17:27:46 +0200 | [diff] [blame] | 253 | private static final String KEY_SPECS_FUTURE = "android:activity.specsFuture"; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 254 | private static final String KEY_REMOTE_ANIMATION_ADAPTER |
| 255 | = "android:activity.remoteAnimationAdapter"; |
Chad Brubaker | 0606861 | 2017-04-06 09:43:47 -0700 | [diff] [blame] | 256 | |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 257 | /** @hide */ |
| 258 | public static final int ANIM_NONE = 0; |
| 259 | /** @hide */ |
| 260 | public static final int ANIM_CUSTOM = 1; |
| 261 | /** @hide */ |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 262 | public static final int ANIM_SCALE_UP = 2; |
| 263 | /** @hide */ |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 264 | public static final int ANIM_THUMBNAIL_SCALE_UP = 3; |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 265 | /** @hide */ |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 266 | public static final int ANIM_THUMBNAIL_SCALE_DOWN = 4; |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 267 | /** @hide */ |
| 268 | public static final int ANIM_SCENE_TRANSITION = 5; |
George Mount | 0b6f3e1 | 2014-06-20 07:35:23 -0700 | [diff] [blame] | 269 | /** @hide */ |
| 270 | public static final int ANIM_DEFAULT = 6; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 271 | /** @hide */ |
| 272 | public static final int ANIM_LAUNCH_TASK_BEHIND = 7; |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 273 | /** @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 Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 277 | /** @hide */ |
| 278 | public static final int ANIM_CUSTOM_IN_PLACE = 10; |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 279 | /** @hide */ |
| 280 | public static final int ANIM_CLIP_REVEAL = 11; |
Tony Mak | 089c35e | 2017-12-18 20:34:14 +0000 | [diff] [blame] | 281 | /** @hide */ |
| 282 | public static final int ANIM_OPEN_CROSS_PROFILE_APPS = 12; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 283 | /** @hide */ |
| 284 | public static final int ANIM_REMOTE_ANIMATION = 13; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 285 | |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 286 | private String mPackageName; |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 287 | private Rect mLaunchBounds; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 288 | private int mAnimationType = ANIM_NONE; |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 289 | private int mCustomEnterResId; |
| 290 | private int mCustomExitResId; |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 291 | private int mCustomInPlaceResId; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 292 | private Bitmap mThumbnail; |
| 293 | private int mStartX; |
| 294 | private int mStartY; |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 295 | private int mWidth; |
| 296 | private int mHeight; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 297 | private IRemoteCallback mAnimationStartedListener; |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 298 | private IRemoteCallback mAnimationFinishedListener; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 299 | private ResultReceiver mTransitionReceiver; |
| 300 | private boolean mIsReturning; |
| 301 | private ArrayList<String> mSharedElementNames; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 302 | private Intent mResultData; |
| 303 | private int mResultCode; |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 304 | private int mExitCoordinatorIndex; |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 305 | private PendingIntent mUsageTimeReport; |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 306 | private boolean mLockTaskMode = false; |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 307 | private int mLaunchDisplayId = INVALID_DISPLAY; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 308 | @WindowConfiguration.WindowingMode |
| 309 | private int mLaunchWindowingMode = WINDOWING_MODE_UNDEFINED; |
| 310 | @WindowConfiguration.ActivityType |
| 311 | private int mLaunchActivityType = ACTIVITY_TYPE_UNDEFINED; |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 312 | private int mLaunchTaskId = -1; |
Matthew Ng | bf15587 | 2017-10-27 15:24:39 -0700 | [diff] [blame] | 313 | private int mSplitScreenCreateMode = SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT; |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 314 | private boolean mDisallowEnterPictureInPictureWhileLaunching; |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 315 | private boolean mTaskOverlay; |
Winson Chung | cbcadc9 | 2017-01-12 15:54:12 -0800 | [diff] [blame] | 316 | private boolean mTaskOverlayCanResume; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 317 | private boolean mAvoidMoveToFront; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 318 | private AppTransitionAnimationSpec mAnimSpecs[]; |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 319 | private int mRotationAnimationHint = -1; |
Chad Brubaker | 0606861 | 2017-04-06 09:43:47 -0700 | [diff] [blame] | 320 | private Bundle mAppVerificationBundle; |
Jorim Jaggi | 34795e3 | 2017-05-12 17:27:46 +0200 | [diff] [blame] | 321 | private IAppTransitionAnimationSpecsFuture mSpecsFuture; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 322 | private RemoteAnimationAdapter mRemoteAnimationAdapter; |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 323 | |
| 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 Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 339 | 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 Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 361 | @UnsupportedAppUsage |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 362 | public static ActivityOptions makeCustomAnimation(Context context, |
| 363 | int enterResId, int exitResId, Handler handler, OnAnimationStartedListener listener) { |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 364 | ActivityOptions opts = new ActivityOptions(); |
| 365 | opts.mPackageName = context.getPackageName(); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 366 | opts.mAnimationType = ANIM_CUSTOM; |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 367 | opts.mCustomEnterResId = enterResId; |
| 368 | opts.mCustomExitResId = exitResId; |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 369 | opts.setOnAnimationStartedListener(handler, listener); |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 370 | return opts; |
| 371 | } |
| 372 | |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 373 | /** |
| 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 Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 397 | private void setOnAnimationStartedListener(final Handler handler, |
| 398 | final OnAnimationStartedListener listener) { |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 399 | if (listener != null) { |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 400 | mAnimationStartedListener = new IRemoteCallback.Stub() { |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 401 | @Override |
| 402 | public void sendResult(Bundle data) throws RemoteException { |
| 403 | handler.post(new Runnable() { |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 404 | @Override public void run() { |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 405 | listener.onAnimationStarted(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 406 | } |
| 407 | }); |
| 408 | } |
| 409 | }; |
| 410 | } |
| 411 | } |
| 412 | |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 413 | /** |
| 414 | * Callback for use with {@link ActivityOptions#makeThumbnailScaleUpAnimation} |
| 415 | * to find out when the given animation has started running. |
Dianne Hackborn | 9944ecd | 2012-04-10 15:54:19 -0700 | [diff] [blame] | 416 | * @hide |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 417 | */ |
| 418 | public interface OnAnimationStartedListener { |
| 419 | void onAnimationStarted(); |
| 420 | } |
| 421 | |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 422 | 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 Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 448 | /** |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 449 | * 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 Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 453 | * <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 Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 458 | * @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 Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 462 | * @param width The initial width of the new activity. |
| 463 | * @param height The initial height of the new activity. |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 464 | * @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 Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 468 | int startX, int startY, int width, int height) { |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 469 | 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 Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 476 | opts.mWidth = width; |
| 477 | opts.mHeight = height; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 478 | return opts; |
| 479 | } |
| 480 | |
| 481 | /** |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 482 | * 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 Mak | 089c35e | 2017-12-18 20:34:14 +0000 | [diff] [blame] | 509 | * 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 Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 522 | * 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 Hackborn | d367ca8 | 2012-05-07 15:49:39 -0700 | [diff] [blame] | 526 | * <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 Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 531 | * @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 Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 535 | * @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 Hackborn | 9944ecd | 2012-04-10 15:54:19 -0700 | [diff] [blame] | 537 | * @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 Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 554 | * @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 Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 556 | * @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 Jaggi | 34795e3 | 2017-05-12 17:27:46 +0200 | [diff] [blame] | 562 | private static ActivityOptions makeThumbnailScaleUpAnimation(View source, |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 563 | Bitmap thumbnail, int startX, int startY, OnAnimationStartedListener listener) { |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 564 | return makeThumbnailAnimation(source, thumbnail, startX, startY, listener, true); |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 567 | private static ActivityOptions makeThumbnailAnimation(View source, |
Michael Jurka | 21385cd | 2012-05-03 10:57:31 -0700 | [diff] [blame] | 568 | Bitmap thumbnail, int startX, int startY, OnAnimationStartedListener listener, |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 569 | boolean scaleUp) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 570 | ActivityOptions opts = new ActivityOptions(); |
| 571 | opts.mPackageName = source.getContext().getPackageName(); |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 572 | opts.mAnimationType = scaleUp ? ANIM_THUMBNAIL_SCALE_UP : ANIM_THUMBNAIL_SCALE_DOWN; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 573 | 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 Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 578 | opts.setOnAnimationStartedListener(source.getHandler(), listener); |
| 579 | return opts; |
| 580 | } |
| 581 | |
| 582 | /** |
Jorim Jaggi | 34795e3 | 2017-05-12 17:27:46 +0200 | [diff] [blame] | 583 | * Create an ActivityOptions specifying an animation where a list of activity windows and |
| 584 | * thumbnails are aspect scaled to/from a new location. |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 585 | * @hide |
| 586 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 587 | @UnsupportedAppUsage |
Jorim Jaggi | 34795e3 | 2017-05-12 17:27:46 +0200 | [diff] [blame] | 588 | 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 Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 599 | } |
| 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 Chung | e494c38 | 2014-12-17 10:12:54 -0800 | [diff] [blame] | 611 | * @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 Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 613 | * @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 Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 621 | Bitmap thumbnail, int startX, int startY, int targetWidth, int targetHeight, |
Winson Chung | e494c38 | 2014-12-17 10:12:54 -0800 | [diff] [blame] | 622 | Handler handler, OnAnimationStartedListener listener) { |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 623 | return makeAspectScaledThumbnailAnimation(source, thumbnail, startX, startY, |
Winson Chung | e494c38 | 2014-12-17 10:12:54 -0800 | [diff] [blame] | 624 | targetWidth, targetHeight, handler, listener, false); |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | private static ActivityOptions makeAspectScaledThumbnailAnimation(View source, Bitmap thumbnail, |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 628 | int startX, int startY, int targetWidth, int targetHeight, |
Winson Chung | e494c38 | 2014-12-17 10:12:54 -0800 | [diff] [blame] | 629 | Handler handler, OnAnimationStartedListener listener, boolean scaleUp) { |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 630 | 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 Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 639 | opts.mWidth = targetWidth; |
| 640 | opts.mHeight = targetHeight; |
Winson Chung | e494c38 | 2014-12-17 10:12:54 -0800 | [diff] [blame] | 641 | opts.setOnAnimationStartedListener(handler, listener); |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 642 | return opts; |
| 643 | } |
| 644 | |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 645 | /** @hide */ |
| 646 | public static ActivityOptions makeThumbnailAspectScaleDownAnimation(View source, |
| 647 | AppTransitionAnimationSpec[] specs, Handler handler, |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 648 | OnAnimationStartedListener onAnimationStartedListener, |
| 649 | OnAnimationFinishedListener onAnimationFinishedListener) { |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 650 | ActivityOptions opts = new ActivityOptions(); |
| 651 | opts.mPackageName = source.getContext().getPackageName(); |
| 652 | opts.mAnimationType = ANIM_THUMBNAIL_ASPECT_SCALE_DOWN; |
| 653 | opts.mAnimSpecs = specs; |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 654 | opts.setOnAnimationStartedListener(handler, onAnimationStartedListener); |
| 655 | opts.setOnAnimationFinishedListener(handler, onAnimationFinishedListener); |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 656 | return opts; |
| 657 | } |
| 658 | |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 659 | /** |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 660 | * 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 Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 662 | * 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 Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 665 | * |
George Mount | 9826f63 | 2014-09-11 08:50:09 -0700 | [diff] [blame] | 666 | * <p>This requires {@link android.view.Window#FEATURE_ACTIVITY_TRANSITIONS} to be |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 667 | * 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 Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 669 | * @param activity The Activity whose window contains the shared elements. |
George Mount | 0b6f3e1 | 2014-06-20 07:35:23 -0700 | [diff] [blame] | 670 | * @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 Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 673 | * @return Returns a new ActivityOptions object that you can use to |
| 674 | * supply these options as the options Bundle when starting an activity. |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 675 | * @see android.transition.Transition#setEpicenterCallback( |
| 676 | * android.transition.Transition.EpicenterCallback) |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 677 | */ |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 678 | public static ActivityOptions makeSceneTransitionAnimation(Activity activity, |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 679 | View sharedElement, String sharedElementName) { |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 680 | return makeSceneTransitionAnimation(activity, Pair.create(sharedElement, sharedElementName)); |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 681 | } |
| 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 Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 686 | * Activity. The position of the first element in sharedElements |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 687 | * 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 Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 689 | * |
George Mount | 9826f63 | 2014-09-11 08:50:09 -0700 | [diff] [blame] | 690 | * <p>This requires {@link android.view.Window#FEATURE_ACTIVITY_TRANSITIONS} to be |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 691 | * 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 Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 693 | * @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 Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 697 | * @return Returns a new ActivityOptions object that you can use to |
| 698 | * supply these options as the options Bundle when starting an activity. |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 699 | * @see android.transition.Transition#setEpicenterCallback( |
| 700 | * android.transition.Transition.EpicenterCallback) |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 701 | */ |
George Mount | d98f4ba | 2016-03-14 14:29:24 -0700 | [diff] [blame] | 702 | @SafeVarargs |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 703 | public static ActivityOptions makeSceneTransitionAnimation(Activity activity, |
| 704 | Pair<View, String>... sharedElements) { |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 705 | ActivityOptions opts = new ActivityOptions(); |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 706 | 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 Talvala | 563df3b | 2016-06-06 22:04:54 +0000 | [diff] [blame] | 728 | return opts; |
George Mount | 04073dc | 2016-05-27 11:02:13 -0700 | [diff] [blame] | 729 | } |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 730 | 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 Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 771 | opts.mAnimationType = ANIM_SCENE_TRANSITION; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 772 | |
| 773 | ArrayList<String> names = new ArrayList<String>(); |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 774 | ArrayList<View> views = new ArrayList<View>(); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 775 | |
| 776 | if (sharedElements != null) { |
| 777 | for (int i = 0; i < sharedElements.length; i++) { |
| 778 | Pair<View, String> sharedElement = sharedElements[i]; |
George Mount | d5f9d73 | 2014-06-05 15:43:06 -0700 | [diff] [blame] | 779 | String sharedElementName = sharedElement.second; |
| 780 | if (sharedElementName == null) { |
| 781 | throw new IllegalArgumentException("Shared element name must not be null"); |
| 782 | } |
George Mount | d5f9d73 | 2014-06-05 15:43:06 -0700 | [diff] [blame] | 783 | names.add(sharedElementName); |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 784 | 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 Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 789 | } |
| 790 | } |
| 791 | |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 792 | ExitTransitionCoordinator exit = new ExitTransitionCoordinator(activity, window, |
| 793 | callback, names, names, views, false); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 794 | opts.mTransitionReceiver = exit; |
| 795 | opts.mSharedElementNames = names; |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 796 | 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 Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | /** @hide */ |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 807 | static ActivityOptions makeSceneTransitionAnimation(Activity activity, |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 808 | 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 Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 817 | opts.mExitCoordinatorIndex = |
| 818 | activity.mActivityTransitionState.addExitTransitionCoordinator(exitCoordinator); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 819 | return opts; |
| 820 | } |
| 821 | |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 822 | /** |
| 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 Mautner | 3b2cd1d | 2014-08-25 14:25:54 -0700 | [diff] [blame] | 832 | public static ActivityOptions makeTaskLaunchBehind() { |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 833 | final ActivityOptions opts = new ActivityOptions(); |
| 834 | opts.mAnimationType = ANIM_LAUNCH_TASK_BEHIND; |
| 835 | return opts; |
| 836 | } |
| 837 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 838 | /** |
| 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 Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 847 | /** |
| 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 Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 853 | @UnsupportedAppUsage |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 854 | 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 Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 862 | /** @hide */ |
| 863 | public boolean getLaunchTaskBehind() { |
| 864 | return mAnimationType == ANIM_LAUNCH_TASK_BEHIND; |
| 865 | } |
| 866 | |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 867 | private ActivityOptions() { |
| 868 | } |
| 869 | |
| 870 | /** @hide */ |
| 871 | public ActivityOptions(Bundle opts) { |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 872 | // 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 Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 876 | mPackageName = opts.getString(KEY_PACKAGE_NAME); |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 877 | try { |
| 878 | mUsageTimeReport = opts.getParcelable(KEY_USAGE_TIME_REPORT); |
| 879 | } catch (RuntimeException e) { |
| 880 | Slog.w(TAG, e); |
| 881 | } |
Wale Ogunwale | 5122df0 | 2016-01-29 22:33:38 -0800 | [diff] [blame] | 882 | mLaunchBounds = opts.getParcelable(KEY_LAUNCH_BOUNDS); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 883 | mAnimationType = opts.getInt(KEY_ANIM_TYPE); |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 884 | 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 Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 892 | case ANIM_CUSTOM_IN_PLACE: |
| 893 | mCustomInPlaceResId = opts.getInt(KEY_ANIM_IN_PLACE_RES_ID, 0); |
| 894 | break; |
| 895 | |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 896 | case ANIM_SCALE_UP: |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 897 | case ANIM_CLIP_REVEAL: |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 898 | mStartX = opts.getInt(KEY_ANIM_START_X, 0); |
| 899 | mStartY = opts.getInt(KEY_ANIM_START_Y, 0); |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 900 | mWidth = opts.getInt(KEY_ANIM_WIDTH, 0); |
| 901 | mHeight = opts.getInt(KEY_ANIM_HEIGHT, 0); |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 902 | break; |
| 903 | |
| 904 | case ANIM_THUMBNAIL_SCALE_UP: |
| 905 | case ANIM_THUMBNAIL_SCALE_DOWN: |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 906 | case ANIM_THUMBNAIL_ASPECT_SCALE_UP: |
| 907 | case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN: |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 908 | // 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 Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 913 | mStartX = opts.getInt(KEY_ANIM_START_X, 0); |
| 914 | mStartY = opts.getInt(KEY_ANIM_START_Y, 0); |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 915 | mWidth = opts.getInt(KEY_ANIM_WIDTH, 0); |
| 916 | mHeight = opts.getInt(KEY_ANIM_HEIGHT, 0); |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 917 | mAnimationStartedListener = IRemoteCallback.Stub.asInterface( |
| 918 | opts.getBinder(KEY_ANIM_START_LISTENER)); |
| 919 | break; |
| 920 | |
| 921 | case ANIM_SCENE_TRANSITION: |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 922 | 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 Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 925 | mResultData = opts.getParcelable(KEY_RESULT_DATA); |
| 926 | mResultCode = opts.getInt(KEY_RESULT_CODE); |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 927 | mExitCoordinatorIndex = opts.getInt(KEY_EXIT_COORDINATOR_INDEX); |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 928 | break; |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 929 | } |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 930 | mLockTaskMode = opts.getBoolean(KEY_LOCK_TASK_MODE, false); |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 931 | mLaunchDisplayId = opts.getInt(KEY_LAUNCH_DISPLAY_ID, INVALID_DISPLAY); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 932 | mLaunchWindowingMode = opts.getInt(KEY_LAUNCH_WINDOWING_MODE, WINDOWING_MODE_UNDEFINED); |
| 933 | mLaunchActivityType = opts.getInt(KEY_LAUNCH_ACTIVITY_TYPE, ACTIVITY_TYPE_UNDEFINED); |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 934 | mLaunchTaskId = opts.getInt(KEY_LAUNCH_TASK_ID, -1); |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 935 | mTaskOverlay = opts.getBoolean(KEY_TASK_OVERLAY, false); |
Winson Chung | cbcadc9 | 2017-01-12 15:54:12 -0800 | [diff] [blame] | 936 | mTaskOverlayCanResume = opts.getBoolean(KEY_TASK_OVERLAY_CAN_RESUME, false); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 937 | mAvoidMoveToFront = opts.getBoolean(KEY_AVOID_MOVE_TO_FRONT, false); |
Matthew Ng | bf15587 | 2017-10-27 15:24:39 -0700 | [diff] [blame] | 938 | mSplitScreenCreateMode = opts.getInt(KEY_SPLIT_SCREEN_CREATE_MODE, |
| 939 | SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT); |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 940 | mDisallowEnterPictureInPictureWhileLaunching = opts.getBoolean( |
| 941 | KEY_DISALLOW_ENTER_PICTURE_IN_PICTURE_WHILE_LAUNCHING, false); |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 942 | 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 Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 949 | if (opts.containsKey(KEY_ANIMATION_FINISHED_LISTENER)) { |
| 950 | mAnimationFinishedListener = IRemoteCallback.Stub.asInterface( |
| 951 | opts.getBinder(KEY_ANIMATION_FINISHED_LISTENER)); |
| 952 | } |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 953 | mRotationAnimationHint = opts.getInt(KEY_ROTATION_ANIMATION_HINT); |
Chad Brubaker | 0606861 | 2017-04-06 09:43:47 -0700 | [diff] [blame] | 954 | mAppVerificationBundle = opts.getBundle(KEY_INSTANT_APP_VERIFICATION_BUNDLE); |
Jorim Jaggi | 34795e3 | 2017-05-12 17:27:46 +0200 | [diff] [blame] | 955 | if (opts.containsKey(KEY_SPECS_FUTURE)) { |
| 956 | mSpecsFuture = IAppTransitionAnimationSpecsFuture.Stub.asInterface(opts.getBinder( |
| 957 | KEY_SPECS_FUTURE)); |
| 958 | } |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 959 | mRemoteAnimationAdapter = opts.getParcelable(KEY_REMOTE_ANIMATION_ADAPTER); |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 960 | } |
| 961 | |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 962 | /** |
Benjamin Miller | 5571456 | 2018-07-05 10:24:28 +0000 | [diff] [blame] | 963 | * Sets the bounds (window size and position) that the activity should be launched in. |
Andrii Kulian | 8f1701d | 2016-03-10 21:56:35 -0800 | [diff] [blame] | 964 | * Rect position should be provided in pixels and in screen coordinates. |
Benjamin Miller | 5571456 | 2018-07-05 10:24:28 +0000 | [diff] [blame] | 965 | * Set to {@code null} to explicitly launch fullscreen. |
Wale Ogunwale | 5122df0 | 2016-01-29 22:33:38 -0800 | [diff] [blame] | 966 | * <p> |
Benjamin Miller | 5571456 | 2018-07-05 10:24:28 +0000 | [diff] [blame] | 967 | * <strong>NOTE:</strong> This value is ignored on devices that don't have |
Wale Ogunwale | 5122df0 | 2016-01-29 22:33:38 -0800 | [diff] [blame] | 968 | * {@link android.content.pm.PackageManager#FEATURE_FREEFORM_WINDOW_MANAGEMENT} or |
| 969 | * {@link android.content.pm.PackageManager#FEATURE_PICTURE_IN_PICTURE} enabled. |
Benjamin Miller | 5571456 | 2018-07-05 10:24:28 +0000 | [diff] [blame] | 970 | * @param screenSpacePixelRect launch bounds or {@code null} for fullscreen |
| 971 | * @return {@code this} {@link ActivityOptions} instance |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 972 | */ |
Andrii Kulian | 8f1701d | 2016-03-10 21:56:35 -0800 | [diff] [blame] | 973 | public ActivityOptions setLaunchBounds(@Nullable Rect screenSpacePixelRect) { |
| 974 | mLaunchBounds = screenSpacePixelRect != null ? new Rect(screenSpacePixelRect) : null; |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 975 | return this; |
| 976 | } |
| 977 | |
| 978 | /** @hide */ |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 979 | public String getPackageName() { |
| 980 | return mPackageName; |
| 981 | } |
| 982 | |
Wale Ogunwale | 5122df0 | 2016-01-29 22:33:38 -0800 | [diff] [blame] | 983 | /** |
| 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 Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 990 | return mLaunchBounds; |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | /** @hide */ |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 994 | public int getAnimationType() { |
| 995 | return mAnimationType; |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | /** @hide */ |
| 999 | public int getCustomEnterResId() { |
| 1000 | return mCustomEnterResId; |
| 1001 | } |
| 1002 | |
| 1003 | /** @hide */ |
| 1004 | public int getCustomExitResId() { |
| 1005 | return mCustomExitResId; |
| 1006 | } |
| 1007 | |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1008 | /** @hide */ |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 1009 | public int getCustomInPlaceResId() { |
| 1010 | return mCustomInPlaceResId; |
| 1011 | } |
| 1012 | |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 1013 | /** |
| 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 Chung | f229ae5 | 2017-06-02 14:34:52 -0700 | [diff] [blame] | 1020 | return mThumbnail != null ? mThumbnail.createGraphicBufferHandle() : null; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1021 | } |
| 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 Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 1034 | public int getWidth() { |
| 1035 | return mWidth; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | /** @hide */ |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 1039 | public int getHeight() { |
| 1040 | return mHeight; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | /** @hide */ |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1044 | public IRemoteCallback getOnAnimationStartListener() { |
| 1045 | return mAnimationStartedListener; |
| 1046 | } |
| 1047 | |
| 1048 | /** @hide */ |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 1049 | public IRemoteCallback getAnimationFinishedListener() { |
| 1050 | return mAnimationFinishedListener; |
| 1051 | } |
| 1052 | |
| 1053 | /** @hide */ |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 1054 | public int getExitCoordinatorKey() { return mExitCoordinatorIndex; } |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 1055 | |
| 1056 | /** @hide */ |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1057 | public void abort() { |
| 1058 | if (mAnimationStartedListener != null) { |
| 1059 | try { |
| 1060 | mAnimationStartedListener.sendResult(null); |
| 1061 | } catch (RemoteException e) { |
| 1062 | } |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | /** @hide */ |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1067 | public boolean isReturning() { |
| 1068 | return mIsReturning; |
| 1069 | } |
| 1070 | |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 1071 | /** |
| 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 Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1081 | /** @hide */ |
| 1082 | public ArrayList<String> getSharedElementNames() { |
| 1083 | return mSharedElementNames; |
| 1084 | } |
| 1085 | |
| 1086 | /** @hide */ |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1087 | 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 Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 1096 | public PendingIntent getUsageTimeReport() { |
| 1097 | return mUsageTimeReport; |
| 1098 | } |
| 1099 | |
| 1100 | /** @hide */ |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 1101 | public AppTransitionAnimationSpec[] getAnimSpecs() { return mAnimSpecs; } |
| 1102 | |
| 1103 | /** @hide */ |
Jorim Jaggi | 34795e3 | 2017-05-12 17:27:46 +0200 | [diff] [blame] | 1104 | public IAppTransitionAnimationSpecsFuture getSpecsFuture() { |
| 1105 | return mSpecsFuture; |
| 1106 | } |
| 1107 | |
| 1108 | /** @hide */ |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 1109 | public RemoteAnimationAdapter getRemoteAnimationAdapter() { |
| 1110 | return mRemoteAnimationAdapter; |
| 1111 | } |
| 1112 | |
| 1113 | /** @hide */ |
Jorim Jaggi | 04dc596 | 2018-01-29 18:54:13 +0100 | [diff] [blame] | 1114 | public void setRemoteAnimationAdapter(RemoteAnimationAdapter remoteAnimationAdapter) { |
| 1115 | mRemoteAnimationAdapter = remoteAnimationAdapter; |
| 1116 | } |
| 1117 | |
| 1118 | /** @hide */ |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 1119 | 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 Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1125 | if (options != null) { |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 1126 | options.abort(); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1127 | } |
| 1128 | } |
| 1129 | |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 1130 | /** |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 1131 | * 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 Franz | 11f0582 | 2018-03-29 15:40:06 +0100 | [diff] [blame] | 1147 | * 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 He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 1149 | * |
| 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 Franz | caffa77 | 2018-02-05 16:36:10 +0000 | [diff] [blame] | 1157 | public ActivityOptions setLockTaskEnabled(boolean lockTaskMode) { |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 1158 | mLockTaskMode = lockTaskMode; |
| 1159 | return this; |
| 1160 | } |
| 1161 | |
| 1162 | /** |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 1163 | * 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 Kulian | 1981f5f | 2017-04-07 16:23:12 -0700 | [diff] [blame] | 1166 | * @see #setLaunchDisplayId(int) |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 1167 | */ |
| 1168 | public int getLaunchDisplayId() { |
| 1169 | return mLaunchDisplayId; |
| 1170 | } |
| 1171 | |
| 1172 | /** |
| 1173 | * Sets the id of the display where activity should be launched. |
Andrii Kulian | 1981f5f | 2017-04-07 16:23:12 -0700 | [diff] [blame] | 1174 | * 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 Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 1180 | * @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 Gruszczynski | 90186c6 | 2015-10-26 14:07:00 -0700 | [diff] [blame] | 1188 | /** @hide */ |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 1189 | 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 Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | /** @hide */ |
Vladislav Kaznacheev | acf147e | 2016-05-05 09:32:27 -0700 | [diff] [blame] | 1214 | @TestApi |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 1215 | public void setLaunchActivityType(int activityType) { |
| 1216 | mLaunchActivityType = activityType; |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 1217 | } |
| 1218 | |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 1219 | /** |
| 1220 | * Sets the task the activity will be launched in. |
| 1221 | * @hide |
| 1222 | */ |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 1223 | @TestApi |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 1224 | public void setLaunchTaskId(int taskId) { |
| 1225 | mLaunchTaskId = taskId; |
| 1226 | } |
| 1227 | |
| 1228 | /** |
| 1229 | * @hide |
| 1230 | */ |
| 1231 | public int getLaunchTaskId() { |
| 1232 | return mLaunchTaskId; |
| 1233 | } |
| 1234 | |
Jorim Jaggi | c875ae7 | 2016-04-26 22:41:06 -0700 | [diff] [blame] | 1235 | /** |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 1236 | * Set's whether the activity launched with this option should be a task overlay. That is the |
Winson Chung | cbcadc9 | 2017-01-12 15:54:12 -0800 | [diff] [blame] | 1237 | * 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 Jaggi | c875ae7 | 2016-04-26 22:41:06 -0700 | [diff] [blame] | 1239 | * @hide |
| 1240 | */ |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 1241 | @TestApi |
Winson Chung | cbcadc9 | 2017-01-12 15:54:12 -0800 | [diff] [blame] | 1242 | public void setTaskOverlay(boolean taskOverlay, boolean canResume) { |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 1243 | mTaskOverlay = taskOverlay; |
Winson Chung | cbcadc9 | 2017-01-12 15:54:12 -0800 | [diff] [blame] | 1244 | mTaskOverlayCanResume = canResume; |
Jorim Jaggi | c875ae7 | 2016-04-26 22:41:06 -0700 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | /** |
| 1248 | * @hide |
| 1249 | */ |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 1250 | public boolean getTaskOverlay() { |
| 1251 | return mTaskOverlay; |
Jorim Jaggi | c875ae7 | 2016-04-26 22:41:06 -0700 | [diff] [blame] | 1252 | } |
| 1253 | |
Winson Chung | cbcadc9 | 2017-01-12 15:54:12 -0800 | [diff] [blame] | 1254 | /** |
| 1255 | * @hide |
| 1256 | */ |
| 1257 | public boolean canTaskOverlayResume() { |
| 1258 | return mTaskOverlayCanResume; |
| 1259 | } |
| 1260 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 1261 | /** |
| 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 Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 1280 | /** @hide */ |
Matthew Ng | bf15587 | 2017-10-27 15:24:39 -0700 | [diff] [blame] | 1281 | public int getSplitScreenCreateMode() { |
| 1282 | return mSplitScreenCreateMode; |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 1283 | } |
Filip Gruszczynski | 90186c6 | 2015-10-26 14:07:00 -0700 | [diff] [blame] | 1284 | |
| 1285 | /** @hide */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1286 | @UnsupportedAppUsage |
Matthew Ng | bf15587 | 2017-10-27 15:24:39 -0700 | [diff] [blame] | 1287 | public void setSplitScreenCreateMode(int splitScreenCreateMode) { |
| 1288 | mSplitScreenCreateMode = splitScreenCreateMode; |
Filip Gruszczynski | 90186c6 | 2015-10-26 14:07:00 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 1291 | /** @hide */ |
| 1292 | public void setDisallowEnterPictureInPictureWhileLaunching(boolean disallow) { |
| 1293 | mDisallowEnterPictureInPictureWhileLaunching = disallow; |
| 1294 | } |
| 1295 | |
| 1296 | /** @hide */ |
| 1297 | public boolean disallowEnterPictureInPictureWhileLaunching() { |
| 1298 | return mDisallowEnterPictureInPictureWhileLaunching; |
| 1299 | } |
| 1300 | |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 1301 | /** |
Dianne Hackborn | ddc52a8 | 2012-05-03 19:40:12 -0700 | [diff] [blame] | 1302 | * Update the current values in this ActivityOptions from those supplied |
| 1303 | * in <var>otherOptions</var>. Any values |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 1304 | * defined in <var>otherOptions</var> replace those in the base options. |
| 1305 | */ |
Dianne Hackborn | ddc52a8 | 2012-05-03 19:40:12 -0700 | [diff] [blame] | 1306 | public void update(ActivityOptions otherOptions) { |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 1307 | if (otherOptions.mPackageName != null) { |
| 1308 | mPackageName = otherOptions.mPackageName; |
| 1309 | } |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 1310 | mUsageTimeReport = otherOptions.mUsageTimeReport; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1311 | mTransitionReceiver = null; |
| 1312 | mSharedElementNames = null; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1313 | mIsReturning = false; |
| 1314 | mResultData = null; |
| 1315 | mResultCode = 0; |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 1316 | mExitCoordinatorIndex = 0; |
George Mount | 00dde0b | 2014-07-01 15:27:07 -0700 | [diff] [blame] | 1317 | mAnimationType = otherOptions.mAnimationType; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1318 | switch (otherOptions.mAnimationType) { |
| 1319 | case ANIM_CUSTOM: |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1320 | mCustomEnterResId = otherOptions.mCustomEnterResId; |
| 1321 | mCustomExitResId = otherOptions.mCustomExitResId; |
| 1322 | mThumbnail = null; |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 1323 | if (mAnimationStartedListener != null) { |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1324 | try { |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 1325 | mAnimationStartedListener.sendResult(null); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1326 | } catch (RemoteException e) { |
| 1327 | } |
| 1328 | } |
| 1329 | mAnimationStartedListener = otherOptions.mAnimationStartedListener; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1330 | break; |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 1331 | case ANIM_CUSTOM_IN_PLACE: |
| 1332 | mCustomInPlaceResId = otherOptions.mCustomInPlaceResId; |
| 1333 | break; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 1334 | case ANIM_SCALE_UP: |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 1335 | mStartX = otherOptions.mStartX; |
| 1336 | mStartY = otherOptions.mStartY; |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 1337 | mWidth = otherOptions.mWidth; |
| 1338 | mHeight = otherOptions.mHeight; |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 1339 | if (mAnimationStartedListener != null) { |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1340 | try { |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 1341 | mAnimationStartedListener.sendResult(null); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1342 | } catch (RemoteException e) { |
| 1343 | } |
| 1344 | } |
| 1345 | mAnimationStartedListener = null; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 1346 | break; |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 1347 | case ANIM_THUMBNAIL_SCALE_UP: |
| 1348 | case ANIM_THUMBNAIL_SCALE_DOWN: |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1349 | case ANIM_THUMBNAIL_ASPECT_SCALE_UP: |
| 1350 | case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN: |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1351 | mThumbnail = otherOptions.mThumbnail; |
| 1352 | mStartX = otherOptions.mStartX; |
| 1353 | mStartY = otherOptions.mStartY; |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 1354 | mWidth = otherOptions.mWidth; |
| 1355 | mHeight = otherOptions.mHeight; |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 1356 | if (mAnimationStartedListener != null) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1357 | try { |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 1358 | mAnimationStartedListener.sendResult(null); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1359 | } catch (RemoteException e) { |
| 1360 | } |
| 1361 | } |
| 1362 | mAnimationStartedListener = otherOptions.mAnimationStartedListener; |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 1363 | break; |
| 1364 | case ANIM_SCENE_TRANSITION: |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1365 | mTransitionReceiver = otherOptions.mTransitionReceiver; |
| 1366 | mSharedElementNames = otherOptions.mSharedElementNames; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1367 | mIsReturning = otherOptions.mIsReturning; |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1368 | mThumbnail = null; |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 1369 | mAnimationStartedListener = null; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1370 | mResultData = otherOptions.mResultData; |
| 1371 | mResultCode = otherOptions.mResultCode; |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 1372 | mExitCoordinatorIndex = otherOptions.mExitCoordinatorIndex; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1373 | break; |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 1374 | } |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 1375 | mLockTaskMode = otherOptions.mLockTaskMode; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 1376 | mAnimSpecs = otherOptions.mAnimSpecs; |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 1377 | mAnimationFinishedListener = otherOptions.mAnimationFinishedListener; |
Jorim Jaggi | 34795e3 | 2017-05-12 17:27:46 +0200 | [diff] [blame] | 1378 | mSpecsFuture = otherOptions.mSpecsFuture; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 1379 | mRemoteAnimationAdapter = otherOptions.mRemoteAnimationAdapter; |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 1380 | } |
| 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 Ogunwale | 5122df0 | 2016-01-29 22:33:38 -0800 | [diff] [blame] | 1395 | if (mLaunchBounds != null) { |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 1396 | b.putParcelable(KEY_LAUNCH_BOUNDS, mLaunchBounds); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 1397 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1398 | b.putInt(KEY_ANIM_TYPE, mAnimationType); |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 1399 | if (mUsageTimeReport != null) { |
| 1400 | b.putParcelable(KEY_USAGE_TIME_REPORT, mUsageTimeReport); |
| 1401 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1402 | switch (mAnimationType) { |
| 1403 | case ANIM_CUSTOM: |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1404 | b.putInt(KEY_ANIM_ENTER_RES_ID, mCustomEnterResId); |
| 1405 | b.putInt(KEY_ANIM_EXIT_RES_ID, mCustomExitResId); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1406 | b.putBinder(KEY_ANIM_START_LISTENER, mAnimationStartedListener |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1407 | != null ? mAnimationStartedListener.asBinder() : null); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1408 | break; |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 1409 | case ANIM_CUSTOM_IN_PLACE: |
| 1410 | b.putInt(KEY_ANIM_IN_PLACE_RES_ID, mCustomInPlaceResId); |
| 1411 | break; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 1412 | case ANIM_SCALE_UP: |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 1413 | case ANIM_CLIP_REVEAL: |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 1414 | b.putInt(KEY_ANIM_START_X, mStartX); |
| 1415 | b.putInt(KEY_ANIM_START_Y, mStartY); |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 1416 | b.putInt(KEY_ANIM_WIDTH, mWidth); |
| 1417 | b.putInt(KEY_ANIM_HEIGHT, mHeight); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 1418 | break; |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 1419 | case ANIM_THUMBNAIL_SCALE_UP: |
| 1420 | case ANIM_THUMBNAIL_SCALE_DOWN: |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1421 | case ANIM_THUMBNAIL_ASPECT_SCALE_UP: |
| 1422 | case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN: |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 1423 | // 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 Chung | f229ae5 | 2017-06-02 14:34:52 -0700 | [diff] [blame] | 1425 | if (mThumbnail != null) { |
Winson Chung | 06b50ab | 2017-06-16 11:07:29 -0700 | [diff] [blame] | 1426 | final Bitmap hwBitmap = mThumbnail.copy(Config.HARDWARE, false /* isMutable */); |
Winson Chung | f229ae5 | 2017-06-02 14:34:52 -0700 | [diff] [blame] | 1427 | if (hwBitmap != null) { |
| 1428 | b.putParcelable(KEY_ANIM_THUMBNAIL, hwBitmap.createGraphicBufferHandle()); |
| 1429 | } else { |
| 1430 | Slog.w(TAG, "Failed to copy thumbnail"); |
| 1431 | } |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 1432 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1433 | b.putInt(KEY_ANIM_START_X, mStartX); |
| 1434 | b.putInt(KEY_ANIM_START_Y, mStartY); |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 1435 | b.putInt(KEY_ANIM_WIDTH, mWidth); |
| 1436 | b.putInt(KEY_ANIM_HEIGHT, mHeight); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1437 | b.putBinder(KEY_ANIM_START_LISTENER, mAnimationStartedListener |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1438 | != null ? mAnimationStartedListener.asBinder() : null); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 1439 | break; |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1440 | case ANIM_SCENE_TRANSITION: |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1441 | if (mTransitionReceiver != null) { |
| 1442 | b.putParcelable(KEY_TRANSITION_COMPLETE_LISTENER, mTransitionReceiver); |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 1443 | } |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1444 | b.putBoolean(KEY_TRANSITION_IS_RETURNING, mIsReturning); |
| 1445 | b.putStringArrayList(KEY_TRANSITION_SHARED_ELEMENTS, mSharedElementNames); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1446 | b.putParcelable(KEY_RESULT_DATA, mResultData); |
| 1447 | b.putInt(KEY_RESULT_CODE, mResultCode); |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 1448 | b.putInt(KEY_EXIT_COORDINATOR_INDEX, mExitCoordinatorIndex); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1449 | break; |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 1450 | } |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 1451 | b.putBoolean(KEY_LOCK_TASK_MODE, mLockTaskMode); |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 1452 | b.putInt(KEY_LAUNCH_DISPLAY_ID, mLaunchDisplayId); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 1453 | b.putInt(KEY_LAUNCH_WINDOWING_MODE, mLaunchWindowingMode); |
| 1454 | b.putInt(KEY_LAUNCH_ACTIVITY_TYPE, mLaunchActivityType); |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 1455 | b.putInt(KEY_LAUNCH_TASK_ID, mLaunchTaskId); |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 1456 | b.putBoolean(KEY_TASK_OVERLAY, mTaskOverlay); |
Winson Chung | cbcadc9 | 2017-01-12 15:54:12 -0800 | [diff] [blame] | 1457 | b.putBoolean(KEY_TASK_OVERLAY_CAN_RESUME, mTaskOverlayCanResume); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 1458 | b.putBoolean(KEY_AVOID_MOVE_TO_FRONT, mAvoidMoveToFront); |
Matthew Ng | bf15587 | 2017-10-27 15:24:39 -0700 | [diff] [blame] | 1459 | b.putInt(KEY_SPLIT_SCREEN_CREATE_MODE, mSplitScreenCreateMode); |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 1460 | b.putBoolean(KEY_DISALLOW_ENTER_PICTURE_IN_PICTURE_WHILE_LAUNCHING, |
| 1461 | mDisallowEnterPictureInPictureWhileLaunching); |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 1462 | if (mAnimSpecs != null) { |
| 1463 | b.putParcelableArray(KEY_ANIM_SPECS, mAnimSpecs); |
| 1464 | } |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 1465 | if (mAnimationFinishedListener != null) { |
| 1466 | b.putBinder(KEY_ANIMATION_FINISHED_LISTENER, mAnimationFinishedListener.asBinder()); |
| 1467 | } |
Jorim Jaggi | 34795e3 | 2017-05-12 17:27:46 +0200 | [diff] [blame] | 1468 | if (mSpecsFuture != null) { |
| 1469 | b.putBinder(KEY_SPECS_FUTURE, mSpecsFuture.asBinder()); |
| 1470 | } |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 1471 | b.putInt(KEY_ROTATION_ANIMATION_HINT, mRotationAnimationHint); |
Chad Brubaker | 0606861 | 2017-04-06 09:43:47 -0700 | [diff] [blame] | 1472 | if (mAppVerificationBundle != null) { |
| 1473 | b.putBundle(KEY_INSTANT_APP_VERIFICATION_BUNDLE, mAppVerificationBundle); |
| 1474 | } |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 1475 | if (mRemoteAnimationAdapter != null) { |
| 1476 | b.putParcelable(KEY_REMOTE_ANIMATION_ADAPTER, mRemoteAnimationAdapter); |
| 1477 | } |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 1478 | return b; |
| 1479 | } |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1480 | |
| 1481 | /** |
kopriva | a1a7848 | 2018-10-09 10:09:23 -0700 | [diff] [blame] | 1482 | * Ask the system track that time the user spends in the app being launched, and |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 1483 | * report it back once done. The report will be sent to the given receiver, with |
Dianne Hackborn | 67ba2c7 | 2015-06-05 14:23:38 -0700 | [diff] [blame] | 1484 | * the extras {@link #EXTRA_USAGE_TIME_REPORT} and {@link #EXTRA_USAGE_TIME_REPORT_PACKAGES} |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 1485 | * 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 Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1510 | * 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 Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 1522 | |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 1523 | /** |
| 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 Brubaker | 0606861 | 2017-04-06 09:43:47 -0700 | [diff] [blame] | 1544 | /** |
| 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 Gruszczynski | 198dcbf | 2016-01-18 10:02:00 -0800 | [diff] [blame] | 1568 | /** @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 Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 1575 | |
Ben Weiss | e0c37bd | 2016-10-26 11:18:32 +0100 | [diff] [blame] | 1576 | private static class HideWindowListener extends TransitionListenerAdapter |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 1577 | 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 Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 1636 | } |