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 | /** |
Wale Ogunwale | 5122df0 | 2016-01-29 22:33:38 -0800 | [diff] [blame] | 963 | * Sets the bounds (window size) 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. |
Wale Ogunwale | 5122df0 | 2016-01-29 22:33:38 -0800 | [diff] [blame] | 965 | * Set to null explicitly for fullscreen. |
| 966 | * <p> |
| 967 | * <strong>NOTE:<strong/> This value is ignored on devices that don't have |
| 968 | * {@link android.content.pm.PackageManager#FEATURE_FREEFORM_WINDOW_MANAGEMENT} or |
| 969 | * {@link android.content.pm.PackageManager#FEATURE_PICTURE_IN_PICTURE} enabled. |
Andrii Kulian | 8f1701d | 2016-03-10 21:56:35 -0800 | [diff] [blame] | 970 | * @param screenSpacePixelRect Launch bounds to use for the activity or null for fullscreen. |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 971 | */ |
Andrii Kulian | 8f1701d | 2016-03-10 21:56:35 -0800 | [diff] [blame] | 972 | public ActivityOptions setLaunchBounds(@Nullable Rect screenSpacePixelRect) { |
| 973 | mLaunchBounds = screenSpacePixelRect != null ? new Rect(screenSpacePixelRect) : null; |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 974 | return this; |
| 975 | } |
| 976 | |
| 977 | /** @hide */ |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 978 | public String getPackageName() { |
| 979 | return mPackageName; |
| 980 | } |
| 981 | |
Wale Ogunwale | 5122df0 | 2016-01-29 22:33:38 -0800 | [diff] [blame] | 982 | /** |
| 983 | * Returns the bounds that should be used to launch the activity. |
| 984 | * @see #setLaunchBounds(Rect) |
| 985 | * @return Bounds used to launch the activity. |
| 986 | */ |
| 987 | @Nullable |
| 988 | public Rect getLaunchBounds() { |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 989 | return mLaunchBounds; |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | /** @hide */ |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 993 | public int getAnimationType() { |
| 994 | return mAnimationType; |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | /** @hide */ |
| 998 | public int getCustomEnterResId() { |
| 999 | return mCustomEnterResId; |
| 1000 | } |
| 1001 | |
| 1002 | /** @hide */ |
| 1003 | public int getCustomExitResId() { |
| 1004 | return mCustomExitResId; |
| 1005 | } |
| 1006 | |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1007 | /** @hide */ |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 1008 | public int getCustomInPlaceResId() { |
| 1009 | return mCustomInPlaceResId; |
| 1010 | } |
| 1011 | |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 1012 | /** |
| 1013 | * The thumbnail is copied into a hardware bitmap when it is bundled and sent to the system, so |
| 1014 | * it should always be backed by a GraphicBuffer on the other end. |
| 1015 | * |
| 1016 | * @hide |
| 1017 | */ |
| 1018 | public GraphicBuffer getThumbnail() { |
Winson Chung | f229ae5 | 2017-06-02 14:34:52 -0700 | [diff] [blame] | 1019 | return mThumbnail != null ? mThumbnail.createGraphicBufferHandle() : null; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | /** @hide */ |
| 1023 | public int getStartX() { |
| 1024 | return mStartX; |
| 1025 | } |
| 1026 | |
| 1027 | /** @hide */ |
| 1028 | public int getStartY() { |
| 1029 | return mStartY; |
| 1030 | } |
| 1031 | |
| 1032 | /** @hide */ |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 1033 | public int getWidth() { |
| 1034 | return mWidth; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | /** @hide */ |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 1038 | public int getHeight() { |
| 1039 | return mHeight; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | /** @hide */ |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1043 | public IRemoteCallback getOnAnimationStartListener() { |
| 1044 | return mAnimationStartedListener; |
| 1045 | } |
| 1046 | |
| 1047 | /** @hide */ |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 1048 | public IRemoteCallback getAnimationFinishedListener() { |
| 1049 | return mAnimationFinishedListener; |
| 1050 | } |
| 1051 | |
| 1052 | /** @hide */ |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 1053 | public int getExitCoordinatorKey() { return mExitCoordinatorIndex; } |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 1054 | |
| 1055 | /** @hide */ |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1056 | public void abort() { |
| 1057 | if (mAnimationStartedListener != null) { |
| 1058 | try { |
| 1059 | mAnimationStartedListener.sendResult(null); |
| 1060 | } catch (RemoteException e) { |
| 1061 | } |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | /** @hide */ |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1066 | public boolean isReturning() { |
| 1067 | return mIsReturning; |
| 1068 | } |
| 1069 | |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 1070 | /** |
| 1071 | * Returns whether or not the ActivityOptions was created with |
| 1072 | * {@link #startSharedElementAnimation(Window, Pair[])}. |
| 1073 | * |
| 1074 | * @hide |
| 1075 | */ |
| 1076 | boolean isCrossTask() { |
| 1077 | return mExitCoordinatorIndex < 0; |
| 1078 | } |
| 1079 | |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1080 | /** @hide */ |
| 1081 | public ArrayList<String> getSharedElementNames() { |
| 1082 | return mSharedElementNames; |
| 1083 | } |
| 1084 | |
| 1085 | /** @hide */ |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1086 | public ResultReceiver getResultReceiver() { return mTransitionReceiver; } |
| 1087 | |
| 1088 | /** @hide */ |
| 1089 | public int getResultCode() { return mResultCode; } |
| 1090 | |
| 1091 | /** @hide */ |
| 1092 | public Intent getResultData() { return mResultData; } |
| 1093 | |
| 1094 | /** @hide */ |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 1095 | public PendingIntent getUsageTimeReport() { |
| 1096 | return mUsageTimeReport; |
| 1097 | } |
| 1098 | |
| 1099 | /** @hide */ |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 1100 | public AppTransitionAnimationSpec[] getAnimSpecs() { return mAnimSpecs; } |
| 1101 | |
| 1102 | /** @hide */ |
Jorim Jaggi | 34795e3 | 2017-05-12 17:27:46 +0200 | [diff] [blame] | 1103 | public IAppTransitionAnimationSpecsFuture getSpecsFuture() { |
| 1104 | return mSpecsFuture; |
| 1105 | } |
| 1106 | |
| 1107 | /** @hide */ |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 1108 | public RemoteAnimationAdapter getRemoteAnimationAdapter() { |
| 1109 | return mRemoteAnimationAdapter; |
| 1110 | } |
| 1111 | |
| 1112 | /** @hide */ |
Jorim Jaggi | 04dc596 | 2018-01-29 18:54:13 +0100 | [diff] [blame] | 1113 | public void setRemoteAnimationAdapter(RemoteAnimationAdapter remoteAnimationAdapter) { |
| 1114 | mRemoteAnimationAdapter = remoteAnimationAdapter; |
| 1115 | } |
| 1116 | |
| 1117 | /** @hide */ |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 1118 | public static ActivityOptions fromBundle(Bundle bOptions) { |
| 1119 | return bOptions != null ? new ActivityOptions(bOptions) : null; |
| 1120 | } |
| 1121 | |
| 1122 | /** @hide */ |
| 1123 | public static void abort(ActivityOptions options) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1124 | if (options != null) { |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 1125 | options.abort(); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1126 | } |
| 1127 | } |
| 1128 | |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 1129 | /** |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 1130 | * Gets whether the activity is to be launched into LockTask mode. |
| 1131 | * @return {@code true} if the activity is to be launched into LockTask mode. |
| 1132 | * @see Activity#startLockTask() |
| 1133 | * @see android.app.admin.DevicePolicyManager#setLockTaskPackages(ComponentName, String[]) |
| 1134 | */ |
| 1135 | public boolean getLockTaskMode() { |
| 1136 | return mLockTaskMode; |
| 1137 | } |
| 1138 | |
| 1139 | /** |
| 1140 | * Sets whether the activity is to be launched into LockTask mode. |
| 1141 | * |
| 1142 | * Use this option to start an activity in LockTask mode. Note that only apps permitted by |
| 1143 | * {@link android.app.admin.DevicePolicyManager} can run in LockTask mode. Therefore, if |
| 1144 | * {@link android.app.admin.DevicePolicyManager#isLockTaskPermitted(String)} returns |
| 1145 | * {@code false} for the package of the target activity, a {@link SecurityException} will be |
Benjamin Franz | 11f0582 | 2018-03-29 15:40:06 +0100 | [diff] [blame] | 1146 | * thrown during {@link Context#startActivity(Intent, Bundle)}. This method doesn't affect |
| 1147 | * activities that are already running — relaunch the activity to run in lock task mode. |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 1148 | * |
| 1149 | * Defaults to {@code false} if not set. |
| 1150 | * |
| 1151 | * @param lockTaskMode {@code true} if the activity is to be launched into LockTask mode. |
| 1152 | * @return {@code this} {@link ActivityOptions} instance. |
| 1153 | * @see Activity#startLockTask() |
| 1154 | * @see android.app.admin.DevicePolicyManager#setLockTaskPackages(ComponentName, String[]) |
| 1155 | */ |
Benjamin Franz | caffa77 | 2018-02-05 16:36:10 +0000 | [diff] [blame] | 1156 | public ActivityOptions setLockTaskEnabled(boolean lockTaskMode) { |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 1157 | mLockTaskMode = lockTaskMode; |
| 1158 | return this; |
| 1159 | } |
| 1160 | |
| 1161 | /** |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 1162 | * Gets the id of the display where activity should be launched. |
| 1163 | * @return The id of the display where activity should be launched, |
| 1164 | * {@link android.view.Display#INVALID_DISPLAY} if not set. |
Andrii Kulian | 1981f5f | 2017-04-07 16:23:12 -0700 | [diff] [blame] | 1165 | * @see #setLaunchDisplayId(int) |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 1166 | */ |
| 1167 | public int getLaunchDisplayId() { |
| 1168 | return mLaunchDisplayId; |
| 1169 | } |
| 1170 | |
| 1171 | /** |
| 1172 | * Sets the id of the display where activity should be launched. |
Andrii Kulian | 1981f5f | 2017-04-07 16:23:12 -0700 | [diff] [blame] | 1173 | * An app can launch activities on public displays or private displays that are owned by the app |
| 1174 | * or where an app already has activities. Otherwise, trying to launch on a private display |
| 1175 | * or providing an invalid display id will result in an exception. |
| 1176 | * <p> |
| 1177 | * Setting launch display id will be ignored on devices that don't have |
| 1178 | * {@link android.content.pm.PackageManager#FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS}. |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 1179 | * @param launchDisplayId The id of the display where the activity should be launched. |
| 1180 | * @return {@code this} {@link ActivityOptions} instance. |
| 1181 | */ |
| 1182 | public ActivityOptions setLaunchDisplayId(int launchDisplayId) { |
| 1183 | mLaunchDisplayId = launchDisplayId; |
| 1184 | return this; |
| 1185 | } |
| 1186 | |
Filip Gruszczynski | 90186c6 | 2015-10-26 14:07:00 -0700 | [diff] [blame] | 1187 | /** @hide */ |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 1188 | public int getLaunchWindowingMode() { |
| 1189 | return mLaunchWindowingMode; |
| 1190 | } |
| 1191 | |
| 1192 | /** |
| 1193 | * Sets the windowing mode the activity should launch into. If the input windowing mode is |
| 1194 | * {@link android.app.WindowConfiguration#WINDOWING_MODE_SPLIT_SCREEN_SECONDARY} and the device |
| 1195 | * isn't currently in split-screen windowing mode, then the activity will be launched in |
| 1196 | * {@link android.app.WindowConfiguration#WINDOWING_MODE_FULLSCREEN} windowing mode. For clarity |
| 1197 | * on this you can use |
| 1198 | * {@link android.app.WindowConfiguration#WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY} |
| 1199 | * |
| 1200 | * @hide |
| 1201 | */ |
| 1202 | @TestApi |
| 1203 | public void setLaunchWindowingMode(int windowingMode) { |
| 1204 | mLaunchWindowingMode = windowingMode; |
| 1205 | } |
| 1206 | |
| 1207 | /** @hide */ |
| 1208 | public int getLaunchActivityType() { |
| 1209 | return mLaunchActivityType; |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | /** @hide */ |
Vladislav Kaznacheev | acf147e | 2016-05-05 09:32:27 -0700 | [diff] [blame] | 1213 | @TestApi |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 1214 | public void setLaunchActivityType(int activityType) { |
| 1215 | mLaunchActivityType = activityType; |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 1216 | } |
| 1217 | |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 1218 | /** |
| 1219 | * Sets the task the activity will be launched in. |
| 1220 | * @hide |
| 1221 | */ |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 1222 | @TestApi |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 1223 | public void setLaunchTaskId(int taskId) { |
| 1224 | mLaunchTaskId = taskId; |
| 1225 | } |
| 1226 | |
| 1227 | /** |
| 1228 | * @hide |
| 1229 | */ |
| 1230 | public int getLaunchTaskId() { |
| 1231 | return mLaunchTaskId; |
| 1232 | } |
| 1233 | |
Jorim Jaggi | c875ae7 | 2016-04-26 22:41:06 -0700 | [diff] [blame] | 1234 | /** |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 1235 | * 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] | 1236 | * activity will always be the top activity of the task. If {@param canResume} is true, then |
| 1237 | * the task will also not be moved to the front of the stack. |
Jorim Jaggi | c875ae7 | 2016-04-26 22:41:06 -0700 | [diff] [blame] | 1238 | * @hide |
| 1239 | */ |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 1240 | @TestApi |
Winson Chung | cbcadc9 | 2017-01-12 15:54:12 -0800 | [diff] [blame] | 1241 | public void setTaskOverlay(boolean taskOverlay, boolean canResume) { |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 1242 | mTaskOverlay = taskOverlay; |
Winson Chung | cbcadc9 | 2017-01-12 15:54:12 -0800 | [diff] [blame] | 1243 | mTaskOverlayCanResume = canResume; |
Jorim Jaggi | c875ae7 | 2016-04-26 22:41:06 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | /** |
| 1247 | * @hide |
| 1248 | */ |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 1249 | public boolean getTaskOverlay() { |
| 1250 | return mTaskOverlay; |
Jorim Jaggi | c875ae7 | 2016-04-26 22:41:06 -0700 | [diff] [blame] | 1251 | } |
| 1252 | |
Winson Chung | cbcadc9 | 2017-01-12 15:54:12 -0800 | [diff] [blame] | 1253 | /** |
| 1254 | * @hide |
| 1255 | */ |
| 1256 | public boolean canTaskOverlayResume() { |
| 1257 | return mTaskOverlayCanResume; |
| 1258 | } |
| 1259 | |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 1260 | /** |
| 1261 | * Sets whether the activity launched should not cause the activity stack it is contained in to |
| 1262 | * be moved to the front as a part of launching. |
| 1263 | * |
| 1264 | * @hide |
| 1265 | */ |
| 1266 | public void setAvoidMoveToFront() { |
| 1267 | mAvoidMoveToFront = true; |
| 1268 | } |
| 1269 | |
| 1270 | /** |
| 1271 | * @return whether the activity launch should prevent moving the associated activity stack to |
| 1272 | * the front. |
| 1273 | * @hide |
| 1274 | */ |
| 1275 | public boolean getAvoidMoveToFront() { |
| 1276 | return mAvoidMoveToFront; |
| 1277 | } |
| 1278 | |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 1279 | /** @hide */ |
Matthew Ng | bf15587 | 2017-10-27 15:24:39 -0700 | [diff] [blame] | 1280 | public int getSplitScreenCreateMode() { |
| 1281 | return mSplitScreenCreateMode; |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 1282 | } |
Filip Gruszczynski | 90186c6 | 2015-10-26 14:07:00 -0700 | [diff] [blame] | 1283 | |
| 1284 | /** @hide */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 1285 | @UnsupportedAppUsage |
Matthew Ng | bf15587 | 2017-10-27 15:24:39 -0700 | [diff] [blame] | 1286 | public void setSplitScreenCreateMode(int splitScreenCreateMode) { |
| 1287 | mSplitScreenCreateMode = splitScreenCreateMode; |
Filip Gruszczynski | 90186c6 | 2015-10-26 14:07:00 -0700 | [diff] [blame] | 1288 | } |
| 1289 | |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 1290 | /** @hide */ |
| 1291 | public void setDisallowEnterPictureInPictureWhileLaunching(boolean disallow) { |
| 1292 | mDisallowEnterPictureInPictureWhileLaunching = disallow; |
| 1293 | } |
| 1294 | |
| 1295 | /** @hide */ |
| 1296 | public boolean disallowEnterPictureInPictureWhileLaunching() { |
| 1297 | return mDisallowEnterPictureInPictureWhileLaunching; |
| 1298 | } |
| 1299 | |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 1300 | /** |
Dianne Hackborn | ddc52a8 | 2012-05-03 19:40:12 -0700 | [diff] [blame] | 1301 | * Update the current values in this ActivityOptions from those supplied |
| 1302 | * in <var>otherOptions</var>. Any values |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 1303 | * defined in <var>otherOptions</var> replace those in the base options. |
| 1304 | */ |
Dianne Hackborn | ddc52a8 | 2012-05-03 19:40:12 -0700 | [diff] [blame] | 1305 | public void update(ActivityOptions otherOptions) { |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 1306 | if (otherOptions.mPackageName != null) { |
| 1307 | mPackageName = otherOptions.mPackageName; |
| 1308 | } |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 1309 | mUsageTimeReport = otherOptions.mUsageTimeReport; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1310 | mTransitionReceiver = null; |
| 1311 | mSharedElementNames = null; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1312 | mIsReturning = false; |
| 1313 | mResultData = null; |
| 1314 | mResultCode = 0; |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 1315 | mExitCoordinatorIndex = 0; |
George Mount | 00dde0b | 2014-07-01 15:27:07 -0700 | [diff] [blame] | 1316 | mAnimationType = otherOptions.mAnimationType; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1317 | switch (otherOptions.mAnimationType) { |
| 1318 | case ANIM_CUSTOM: |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1319 | mCustomEnterResId = otherOptions.mCustomEnterResId; |
| 1320 | mCustomExitResId = otherOptions.mCustomExitResId; |
| 1321 | mThumbnail = null; |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 1322 | if (mAnimationStartedListener != null) { |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1323 | try { |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 1324 | mAnimationStartedListener.sendResult(null); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1325 | } catch (RemoteException e) { |
| 1326 | } |
| 1327 | } |
| 1328 | mAnimationStartedListener = otherOptions.mAnimationStartedListener; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1329 | break; |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 1330 | case ANIM_CUSTOM_IN_PLACE: |
| 1331 | mCustomInPlaceResId = otherOptions.mCustomInPlaceResId; |
| 1332 | break; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 1333 | case ANIM_SCALE_UP: |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 1334 | mStartX = otherOptions.mStartX; |
| 1335 | mStartY = otherOptions.mStartY; |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 1336 | mWidth = otherOptions.mWidth; |
| 1337 | mHeight = otherOptions.mHeight; |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 1338 | if (mAnimationStartedListener != null) { |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1339 | try { |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 1340 | mAnimationStartedListener.sendResult(null); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1341 | } catch (RemoteException e) { |
| 1342 | } |
| 1343 | } |
| 1344 | mAnimationStartedListener = null; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 1345 | break; |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 1346 | case ANIM_THUMBNAIL_SCALE_UP: |
| 1347 | case ANIM_THUMBNAIL_SCALE_DOWN: |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1348 | case ANIM_THUMBNAIL_ASPECT_SCALE_UP: |
| 1349 | case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN: |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1350 | mThumbnail = otherOptions.mThumbnail; |
| 1351 | mStartX = otherOptions.mStartX; |
| 1352 | mStartY = otherOptions.mStartY; |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 1353 | mWidth = otherOptions.mWidth; |
| 1354 | mHeight = otherOptions.mHeight; |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 1355 | if (mAnimationStartedListener != null) { |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1356 | try { |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 1357 | mAnimationStartedListener.sendResult(null); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1358 | } catch (RemoteException e) { |
| 1359 | } |
| 1360 | } |
| 1361 | mAnimationStartedListener = otherOptions.mAnimationStartedListener; |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 1362 | break; |
| 1363 | case ANIM_SCENE_TRANSITION: |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1364 | mTransitionReceiver = otherOptions.mTransitionReceiver; |
| 1365 | mSharedElementNames = otherOptions.mSharedElementNames; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1366 | mIsReturning = otherOptions.mIsReturning; |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1367 | mThumbnail = null; |
Adam Powell | 18e905f | 2013-10-24 14:27:48 -0700 | [diff] [blame] | 1368 | mAnimationStartedListener = null; |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1369 | mResultData = otherOptions.mResultData; |
| 1370 | mResultCode = otherOptions.mResultCode; |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 1371 | mExitCoordinatorIndex = otherOptions.mExitCoordinatorIndex; |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1372 | break; |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 1373 | } |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 1374 | mLockTaskMode = otherOptions.mLockTaskMode; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 1375 | mAnimSpecs = otherOptions.mAnimSpecs; |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 1376 | mAnimationFinishedListener = otherOptions.mAnimationFinishedListener; |
Jorim Jaggi | 34795e3 | 2017-05-12 17:27:46 +0200 | [diff] [blame] | 1377 | mSpecsFuture = otherOptions.mSpecsFuture; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 1378 | mRemoteAnimationAdapter = otherOptions.mRemoteAnimationAdapter; |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | /** |
| 1382 | * Returns the created options as a Bundle, which can be passed to |
| 1383 | * {@link android.content.Context#startActivity(android.content.Intent, android.os.Bundle) |
| 1384 | * Context.startActivity(Intent, Bundle)} and related methods. |
| 1385 | * Note that the returned Bundle is still owned by the ActivityOptions |
| 1386 | * object; you must not modify it, but can supply it to the startActivity |
| 1387 | * methods that take an options Bundle. |
| 1388 | */ |
| 1389 | public Bundle toBundle() { |
| 1390 | Bundle b = new Bundle(); |
| 1391 | if (mPackageName != null) { |
| 1392 | b.putString(KEY_PACKAGE_NAME, mPackageName); |
| 1393 | } |
Wale Ogunwale | 5122df0 | 2016-01-29 22:33:38 -0800 | [diff] [blame] | 1394 | if (mLaunchBounds != null) { |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 1395 | b.putParcelable(KEY_LAUNCH_BOUNDS, mLaunchBounds); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 1396 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1397 | b.putInt(KEY_ANIM_TYPE, mAnimationType); |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 1398 | if (mUsageTimeReport != null) { |
| 1399 | b.putParcelable(KEY_USAGE_TIME_REPORT, mUsageTimeReport); |
| 1400 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1401 | switch (mAnimationType) { |
| 1402 | case ANIM_CUSTOM: |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1403 | b.putInt(KEY_ANIM_ENTER_RES_ID, mCustomEnterResId); |
| 1404 | b.putInt(KEY_ANIM_EXIT_RES_ID, mCustomExitResId); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1405 | b.putBinder(KEY_ANIM_START_LISTENER, mAnimationStartedListener |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1406 | != null ? mAnimationStartedListener.asBinder() : null); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1407 | break; |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 1408 | case ANIM_CUSTOM_IN_PLACE: |
| 1409 | b.putInt(KEY_ANIM_IN_PLACE_RES_ID, mCustomInPlaceResId); |
| 1410 | break; |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 1411 | case ANIM_SCALE_UP: |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 1412 | case ANIM_CLIP_REVEAL: |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 1413 | b.putInt(KEY_ANIM_START_X, mStartX); |
| 1414 | b.putInt(KEY_ANIM_START_Y, mStartY); |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 1415 | b.putInt(KEY_ANIM_WIDTH, mWidth); |
| 1416 | b.putInt(KEY_ANIM_HEIGHT, mHeight); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 1417 | break; |
Michael Jurka | 832cb22 | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 1418 | case ANIM_THUMBNAIL_SCALE_UP: |
| 1419 | case ANIM_THUMBNAIL_SCALE_DOWN: |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1420 | case ANIM_THUMBNAIL_ASPECT_SCALE_UP: |
| 1421 | case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN: |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 1422 | // Once we parcel the thumbnail for transfering over to the system, create a copy of |
| 1423 | // the bitmap to a hardware bitmap and pass through the GraphicBuffer |
Winson Chung | f229ae5 | 2017-06-02 14:34:52 -0700 | [diff] [blame] | 1424 | if (mThumbnail != null) { |
Winson Chung | 06b50ab | 2017-06-16 11:07:29 -0700 | [diff] [blame] | 1425 | final Bitmap hwBitmap = mThumbnail.copy(Config.HARDWARE, false /* isMutable */); |
Winson Chung | f229ae5 | 2017-06-02 14:34:52 -0700 | [diff] [blame] | 1426 | if (hwBitmap != null) { |
| 1427 | b.putParcelable(KEY_ANIM_THUMBNAIL, hwBitmap.createGraphicBufferHandle()); |
| 1428 | } else { |
| 1429 | Slog.w(TAG, "Failed to copy thumbnail"); |
| 1430 | } |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 1431 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1432 | b.putInt(KEY_ANIM_START_X, mStartX); |
| 1433 | b.putInt(KEY_ANIM_START_Y, mStartY); |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 1434 | b.putInt(KEY_ANIM_WIDTH, mWidth); |
| 1435 | b.putInt(KEY_ANIM_HEIGHT, mHeight); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1436 | b.putBinder(KEY_ANIM_START_LISTENER, mAnimationStartedListener |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1437 | != null ? mAnimationStartedListener.asBinder() : null); |
Dianne Hackborn | eabfb3a | 2012-04-16 16:28:22 -0700 | [diff] [blame] | 1438 | break; |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1439 | case ANIM_SCENE_TRANSITION: |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1440 | if (mTransitionReceiver != null) { |
| 1441 | b.putParcelable(KEY_TRANSITION_COMPLETE_LISTENER, mTransitionReceiver); |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 1442 | } |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1443 | b.putBoolean(KEY_TRANSITION_IS_RETURNING, mIsReturning); |
| 1444 | b.putStringArrayList(KEY_TRANSITION_SHARED_ELEMENTS, mSharedElementNames); |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 1445 | b.putParcelable(KEY_RESULT_DATA, mResultData); |
| 1446 | b.putInt(KEY_RESULT_CODE, mResultCode); |
George Mount | 1fecfb2 | 2014-06-18 14:55:55 -0700 | [diff] [blame] | 1447 | b.putInt(KEY_EXIT_COORDINATOR_INDEX, mExitCoordinatorIndex); |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1448 | break; |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 1449 | } |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 1450 | b.putBoolean(KEY_LOCK_TASK_MODE, mLockTaskMode); |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 1451 | b.putInt(KEY_LAUNCH_DISPLAY_ID, mLaunchDisplayId); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 1452 | b.putInt(KEY_LAUNCH_WINDOWING_MODE, mLaunchWindowingMode); |
| 1453 | b.putInt(KEY_LAUNCH_ACTIVITY_TYPE, mLaunchActivityType); |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 1454 | b.putInt(KEY_LAUNCH_TASK_ID, mLaunchTaskId); |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 1455 | b.putBoolean(KEY_TASK_OVERLAY, mTaskOverlay); |
Winson Chung | cbcadc9 | 2017-01-12 15:54:12 -0800 | [diff] [blame] | 1456 | b.putBoolean(KEY_TASK_OVERLAY_CAN_RESUME, mTaskOverlayCanResume); |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 1457 | b.putBoolean(KEY_AVOID_MOVE_TO_FRONT, mAvoidMoveToFront); |
Matthew Ng | bf15587 | 2017-10-27 15:24:39 -0700 | [diff] [blame] | 1458 | b.putInt(KEY_SPLIT_SCREEN_CREATE_MODE, mSplitScreenCreateMode); |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 1459 | b.putBoolean(KEY_DISALLOW_ENTER_PICTURE_IN_PICTURE_WHILE_LAUNCHING, |
| 1460 | mDisallowEnterPictureInPictureWhileLaunching); |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 1461 | if (mAnimSpecs != null) { |
| 1462 | b.putParcelableArray(KEY_ANIM_SPECS, mAnimSpecs); |
| 1463 | } |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 1464 | if (mAnimationFinishedListener != null) { |
| 1465 | b.putBinder(KEY_ANIMATION_FINISHED_LISTENER, mAnimationFinishedListener.asBinder()); |
| 1466 | } |
Jorim Jaggi | 34795e3 | 2017-05-12 17:27:46 +0200 | [diff] [blame] | 1467 | if (mSpecsFuture != null) { |
| 1468 | b.putBinder(KEY_SPECS_FUTURE, mSpecsFuture.asBinder()); |
| 1469 | } |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 1470 | b.putInt(KEY_ROTATION_ANIMATION_HINT, mRotationAnimationHint); |
Chad Brubaker | 0606861 | 2017-04-06 09:43:47 -0700 | [diff] [blame] | 1471 | if (mAppVerificationBundle != null) { |
| 1472 | b.putBundle(KEY_INSTANT_APP_VERIFICATION_BUNDLE, mAppVerificationBundle); |
| 1473 | } |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 1474 | if (mRemoteAnimationAdapter != null) { |
| 1475 | b.putParcelable(KEY_REMOTE_ANIMATION_ADAPTER, mRemoteAnimationAdapter); |
| 1476 | } |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 1477 | return b; |
| 1478 | } |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1479 | |
| 1480 | /** |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 1481 | * Ask the the system track that time the user spends in the app being launched, and |
| 1482 | * report it back once done. The report will be sent to the given receiver, with |
Dianne Hackborn | 67ba2c7 | 2015-06-05 14:23:38 -0700 | [diff] [blame] | 1483 | * 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] | 1484 | * filled in. |
| 1485 | * |
| 1486 | * <p>The time interval tracked is from launching this activity until the user leaves |
| 1487 | * that activity's flow. They are considered to stay in the flow as long as |
| 1488 | * new activities are being launched or returned to from the original flow, |
| 1489 | * even if this crosses package or task boundaries. For example, if the originator |
| 1490 | * starts an activity to view an image, and while there the user selects to share, |
| 1491 | * which launches their email app in a new task, and they complete the share, the |
| 1492 | * time during that entire operation will be included until they finally hit back from |
| 1493 | * the original image viewer activity.</p> |
| 1494 | * |
| 1495 | * <p>The user is considered to complete a flow once they switch to another |
| 1496 | * activity that is not part of the tracked flow. This may happen, for example, by |
| 1497 | * using the notification shade, launcher, or recents to launch or switch to another |
| 1498 | * app. Simply going in to these navigation elements does not break the flow (although |
| 1499 | * the launcher and recents stops time tracking of the session); it is the act of |
| 1500 | * going somewhere else that completes the tracking.</p> |
| 1501 | * |
| 1502 | * @param receiver A broadcast receiver that willl receive the report. |
| 1503 | */ |
| 1504 | public void requestUsageTimeReport(PendingIntent receiver) { |
| 1505 | mUsageTimeReport = receiver; |
| 1506 | } |
| 1507 | |
| 1508 | /** |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1509 | * Return the filtered options only meant to be seen by the target activity itself |
| 1510 | * @hide |
| 1511 | */ |
| 1512 | public ActivityOptions forTargetActivity() { |
| 1513 | if (mAnimationType == ANIM_SCENE_TRANSITION) { |
| 1514 | final ActivityOptions result = new ActivityOptions(); |
| 1515 | result.update(this); |
| 1516 | return result; |
| 1517 | } |
| 1518 | |
| 1519 | return null; |
| 1520 | } |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 1521 | |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 1522 | /** |
| 1523 | * Returns the rotation animation set by {@link setRotationAnimationHint} or -1 |
| 1524 | * if unspecified. |
| 1525 | * @hide |
| 1526 | */ |
| 1527 | public int getRotationAnimationHint() { |
| 1528 | return mRotationAnimationHint; |
| 1529 | } |
| 1530 | |
| 1531 | |
| 1532 | /** |
| 1533 | * Set a rotation animation to be used if launching the activity |
| 1534 | * triggers an orientation change, or -1 to clear. See |
| 1535 | * {@link android.view.WindowManager.LayoutParams} for rotation |
| 1536 | * animation values. |
| 1537 | * @hide |
| 1538 | */ |
| 1539 | public void setRotationAnimationHint(int hint) { |
| 1540 | mRotationAnimationHint = hint; |
| 1541 | } |
| 1542 | |
Chad Brubaker | 0606861 | 2017-04-06 09:43:47 -0700 | [diff] [blame] | 1543 | /** |
| 1544 | * Pop the extra verification bundle for the installer. |
| 1545 | * This removes the bundle from the ActivityOptions to make sure the installer bundle |
| 1546 | * is only available once. |
| 1547 | * @hide |
| 1548 | */ |
| 1549 | public Bundle popAppVerificationBundle() { |
| 1550 | Bundle out = mAppVerificationBundle; |
| 1551 | mAppVerificationBundle = null; |
| 1552 | return out; |
| 1553 | } |
| 1554 | |
| 1555 | /** |
| 1556 | * Set the {@link Bundle} that is provided to the app installer for additional verification |
| 1557 | * if the call to {@link Context#startActivity} results in an app being installed. |
| 1558 | * |
| 1559 | * This Bundle is not provided to any other app besides the installer. |
| 1560 | */ |
| 1561 | public ActivityOptions setAppVerificationBundle(Bundle bundle) { |
| 1562 | mAppVerificationBundle = bundle; |
| 1563 | return this; |
| 1564 | |
| 1565 | } |
| 1566 | |
Filip Gruszczynski | 198dcbf | 2016-01-18 10:02:00 -0800 | [diff] [blame] | 1567 | /** @hide */ |
| 1568 | @Override |
| 1569 | public String toString() { |
| 1570 | return "ActivityOptions(" + hashCode() + "), mPackageName=" + mPackageName |
| 1571 | + ", mAnimationType=" + mAnimationType + ", mStartX=" + mStartX + ", mStartY=" |
| 1572 | + mStartY + ", mWidth=" + mWidth + ", mHeight=" + mHeight; |
| 1573 | } |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 1574 | |
Ben Weiss | e0c37bd | 2016-10-26 11:18:32 +0100 | [diff] [blame] | 1575 | private static class HideWindowListener extends TransitionListenerAdapter |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 1576 | implements ExitTransitionCoordinator.HideSharedElementsCallback { |
| 1577 | private final Window mWindow; |
| 1578 | private final ExitTransitionCoordinator mExit; |
| 1579 | private final boolean mWaitingForTransition; |
| 1580 | private boolean mTransitionEnded; |
| 1581 | private boolean mSharedElementHidden; |
| 1582 | private ArrayList<View> mSharedElements; |
| 1583 | |
| 1584 | public HideWindowListener(Window window, ExitTransitionCoordinator exit) { |
| 1585 | mWindow = window; |
| 1586 | mExit = exit; |
| 1587 | mSharedElements = new ArrayList<>(exit.mSharedElements); |
| 1588 | Transition transition = mWindow.getExitTransition(); |
| 1589 | if (transition != null) { |
| 1590 | transition.addListener(this); |
| 1591 | mWaitingForTransition = true; |
| 1592 | } else { |
| 1593 | mWaitingForTransition = false; |
| 1594 | } |
| 1595 | View decorView = mWindow.getDecorView(); |
| 1596 | if (decorView != null) { |
| 1597 | if (decorView.getTag(com.android.internal.R.id.cross_task_transition) != null) { |
| 1598 | throw new IllegalStateException( |
| 1599 | "Cannot start a transition while one is running"); |
| 1600 | } |
| 1601 | decorView.setTagInternal(com.android.internal.R.id.cross_task_transition, exit); |
| 1602 | } |
| 1603 | } |
| 1604 | |
| 1605 | @Override |
| 1606 | public void onTransitionEnd(Transition transition) { |
| 1607 | mTransitionEnded = true; |
| 1608 | hideWhenDone(); |
| 1609 | transition.removeListener(this); |
| 1610 | } |
| 1611 | |
| 1612 | @Override |
| 1613 | public void hideSharedElements() { |
| 1614 | mSharedElementHidden = true; |
| 1615 | hideWhenDone(); |
| 1616 | } |
| 1617 | |
| 1618 | private void hideWhenDone() { |
| 1619 | if (mSharedElementHidden && (!mWaitingForTransition || mTransitionEnded)) { |
| 1620 | mExit.resetViews(); |
| 1621 | int numSharedElements = mSharedElements.size(); |
| 1622 | for (int i = 0; i < numSharedElements; i++) { |
| 1623 | View view = mSharedElements.get(i); |
| 1624 | view.requestLayout(); |
| 1625 | } |
| 1626 | View decorView = mWindow.getDecorView(); |
| 1627 | if (decorView != null) { |
| 1628 | decorView.setTagInternal( |
| 1629 | com.android.internal.R.id.cross_task_transition, null); |
| 1630 | decorView.setVisibility(View.GONE); |
| 1631 | } |
| 1632 | } |
| 1633 | } |
| 1634 | } |
Dianne Hackborn | 6de01a9 | 2012-03-19 19:07:40 -0700 | [diff] [blame] | 1635 | } |