blob: 11b01ccb9c684349d762f6555ab97498335702b3 [file] [log] [blame]
Craig Mautner164d4bb2012-11-26 13:51:23 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Filip Gruszczynski82861362015-10-16 14:21:09 -070019import static android.view.WindowManagerInternal.AppTransitionListener;
20import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
21import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
22import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
23import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
24import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
25import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
26import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
27import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
28import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
29import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
30import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
31import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
32import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
33import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
34import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
35import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
36import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
37import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
38import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
39import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
40import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
41import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080042import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
43import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080044import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
45import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010046import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
47import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
Filip Gruszczynski82861362015-10-16 14:21:09 -070048
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070049import android.annotation.Nullable;
Craig Mautner164d4bb2012-11-26 13:51:23 -080050import android.content.Context;
Winson21700932016-03-24 17:26:23 -070051import android.content.res.Configuration;
Craig Mautner164d4bb2012-11-26 13:51:23 -080052import android.graphics.Bitmap;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010053import android.graphics.Path;
Winson Chung399f6202014-03-19 10:47:20 -070054import android.graphics.Rect;
Craig Mautner164d4bb2012-11-26 13:51:23 -080055import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010056import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080057import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010058import android.os.RemoteException;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080059import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080060import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070061import android.util.SparseArray;
62import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010063import android.view.IAppTransitionAnimationSpecsFuture;
Craig Mautner164d4bb2012-11-26 13:51:23 -080064import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080065import android.view.animation.AlphaAnimation;
66import android.view.animation.Animation;
67import android.view.animation.AnimationSet;
68import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070069import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080070import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070071import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080072import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070073import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070074
Craig Mautner164d4bb2012-11-26 13:51:23 -080075import com.android.internal.util.DumpUtils.Dump;
76import com.android.server.AttributeCache;
77import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -080078import com.android.server.wm.animation.ClipRectLRAnimation;
79import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010080import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080081
82import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010083import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010084import java.util.concurrent.ExecutorService;
85import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -080086
Craig Mautner164d4bb2012-11-26 13:51:23 -080087// State management of app transitions. When we are preparing for a
88// transition, mNextAppTransition will be the kind of transition to
89// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
90// mOpeningApps and mClosingApps are the lists of tokens that will be
91// made visible or hidden at the next transition.
92public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080093 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070094 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080095
Craig Mautner4b71aa12012-12-27 17:20:01 -080096 /** Not set up for a transition. */
97 public static final int TRANSIT_UNSET = -1;
98 /** No animation for transition. */
99 public static final int TRANSIT_NONE = 0;
100 /** A window in a new activity is being opened on top of an existing one in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700101 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800102 /** The window in the top-most activity is being closed to reveal the
103 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700104 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800105 /** A window in a new task is being opened on top of an existing one
106 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700107 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800108 /** A window in the top-most activity is being closed to reveal the
109 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700110 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800111 /** A window in an existing task is being displayed on top of an existing one
112 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700113 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800114 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700115 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800116 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
117 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700118 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800119 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
120 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700121 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800122 /** A window in a new activity is being opened on top of an existing one, and both are on top
123 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700124 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800125 /** The window in the top-most activity is being closed to reveal the previous activity, and
126 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700127 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
128 /** A window in a new task is being opened behind an existing one in another activity's task.
129 * The new window will show briefly and then be gone. */
130 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800131 /** A window in a task is being animated in-place. */
132 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700133 /** An activity is being relaunched (e.g. due to configuration change). */
134 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Jorim Jaggi192086e2016-03-11 17:17:03 +0100135 /** A task is being docked from recents. */
136 public static final int TRANSIT_DOCK_TASK_FROM_RECENTS = 19;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800137
Winson Chunga4ccb862014-08-22 15:26:27 -0700138 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700139 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800140 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700141 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800142
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800143 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800144
145 /** Interpolator to be used for animations that respond directly to a touch */
146 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
147 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
148
Jorim Jaggic69bd222016-03-15 14:38:37 +0100149 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
150 new PathInterpolator(0.85f, 0f, 1f, 1f);
151
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800152 /**
153 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
154 * involved, to make it more understandable.
155 */
156 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700157 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700158 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800159
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800160 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800161 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800162
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800163 private int mNextAppTransition = TRANSIT_UNSET;
164
165 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
166 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
167 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
168 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
169 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700170 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
171 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800172 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800173 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800174 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
175
Winson Chung399f6202014-03-19 10:47:20 -0700176 // These are the possible states for the enter/exit activities during a thumbnail transition
177 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
178 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
179 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
180 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
181
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800182 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800183 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800184 private boolean mNextAppTransitionScaleUp;
185 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100186 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700187 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800188 private int mNextAppTransitionEnter;
189 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800190 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700191
192 // Keyed by task id.
193 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
194 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100195 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
196 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700197 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
198
Winson Chunga4ccb862014-08-22 15:26:27 -0700199 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800200
Winson Chung2820c452014-04-15 15:34:44 -0700201 private Rect mTmpFromClipRect = new Rect();
202 private Rect mTmpToClipRect = new Rect();
203
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700204 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700205
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800206 private final static int APP_STATE_IDLE = 0;
207 private final static int APP_STATE_READY = 1;
208 private final static int APP_STATE_RUNNING = 2;
209 private final static int APP_STATE_TIMEOUT = 3;
210 private int mAppTransitionState = APP_STATE_IDLE;
211
212 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800213 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700214 private final Interpolator mThumbnailFadeInInterpolator;
215 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800216 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700217 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100218 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700219 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
220
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700221 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800222
Amith Yamasani4befbec2013-07-10 16:18:01 -0700223 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800224 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700225
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100226 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100227 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100228
Jorim Jaggif97ed922016-02-18 18:57:07 -0800229 private int mLastClipRevealMaxTranslation;
230 private boolean mLastHadClipReveal;
231
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800232 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800233 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800234 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800235 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
236 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700237 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
238 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100239 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
240 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800241 mConfigShortAnimTime = context.getResources().getInteger(
242 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800243 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
244 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700245 mThumbnailFadeInInterpolator = new Interpolator() {
246 @Override
247 public float getInterpolation(float input) {
248 // Linear response for first fraction, then complete after that.
249 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
250 return 0f;
251 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700252 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700253 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700254 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700255 }
256 };
257 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800258 @Override
259 public float getInterpolation(float input) {
260 // Linear response for first fraction, then complete after that.
261 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700262 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
263 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800264 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700265 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800266 }
267 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700268 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
269 * mContext.getResources().getDisplayMetrics().density);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800270 }
271
272 boolean isTransitionSet() {
273 return mNextAppTransition != TRANSIT_UNSET;
274 }
275
Craig Mautner164d4bb2012-11-26 13:51:23 -0800276 boolean isTransitionEqual(int transit) {
277 return mNextAppTransition == transit;
278 }
279
280 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800281 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800282 }
283
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700284 private void setAppTransition(int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800285 mNextAppTransition = transit;
286 }
287
288 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800289 return mAppTransitionState == APP_STATE_READY
290 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800291 }
292
Craig Mautnerae446592012-12-06 19:05:05 -0800293 void setReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800294 mAppTransitionState = APP_STATE_READY;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100295 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800296 }
297
298 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800299 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800300 }
301
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800302 void setIdle() {
303 mAppTransitionState = APP_STATE_IDLE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800304 }
305
306 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800307 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800308 }
309
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800310 void setTimeout() {
311 mAppTransitionState = APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800312 }
313
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700314 Bitmap getAppTransitionThumbnailHeader(int taskId) {
315 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800316 if (spec == null) {
317 spec = mDefaultNextAppTransitionAnimationSpec;
318 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700319 return spec != null ? spec.bitmap : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800320 }
321
Winson Chunga4ccb862014-08-22 15:26:27 -0700322 /** Returns whether the next thumbnail transition is aspect scaled up. */
323 boolean isNextThumbnailTransitionAspectScaled() {
324 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
325 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
326 }
327
328 /** Returns whether the next thumbnail transition is scaling up. */
329 boolean isNextThumbnailTransitionScaleUp() {
330 return mNextAppTransitionScaleUp;
331 }
332
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800333 boolean isNextAppTransitionThumbnailUp() {
334 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
335 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
336 }
337
338 boolean isNextAppTransitionThumbnailDown() {
339 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
340 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
341 }
342
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100343 /**
344 * @return true if and only if we are currently fetching app transition specs from the future
345 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
346 */
347 boolean isFetchingAppTransitionsSpecs() {
348 return mNextAppTransitionAnimationsSpecsPending;
349 }
350
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700351 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800352 if (!isRunning()) {
353 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100354 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800355 mLastHadClipReveal = false;
356 mLastClipRevealMaxTranslation = 0;
357 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700358 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800359 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700360 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800361 }
362
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800363 void goodToGo(AppWindowAnimator topOpeningAppAnimator, AppWindowAnimator topClosingAppAnimator,
364 ArraySet<AppWindowToken> openingApps, ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800365 mNextAppTransition = TRANSIT_UNSET;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800366 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100367 notifyAppTransitionStartingLocked(
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800368 topOpeningAppAnimator != null ? topOpeningAppAnimator.mAppToken.token : null,
369 topClosingAppAnimator != null ? topClosingAppAnimator.mAppToken.token : null,
370 topOpeningAppAnimator != null ? topOpeningAppAnimator.animation : null,
371 topClosingAppAnimator != null ? topClosingAppAnimator.animation : null);
372 mService.getDefaultDisplayContentLocked().getDockedDividerController()
373 .notifyAppTransitionStarting(openingApps, closingApps);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800374 }
375
376 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800377 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800378 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700379 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi65193992015-11-23 16:49:59 -0800380 mNextAppTransitionAnimationsSpecsFuture = null;
381 mDefaultNextAppTransitionAnimationSpec = null;
382 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800383 }
384
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800385 void freeze() {
386 setAppTransition(AppTransition.TRANSIT_UNSET);
387 clear();
388 setReady();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100389 notifyAppTransitionCancelledLocked();
390 }
391
392 void registerListenerLocked(AppTransitionListener listener) {
393 mListeners.add(listener);
394 }
395
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700396 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100397 for (int i = 0; i < mListeners.size(); i++) {
398 mListeners.get(i).onAppTransitionFinishedLocked(token);
399 }
400 }
401
402 private void notifyAppTransitionPendingLocked() {
403 for (int i = 0; i < mListeners.size(); i++) {
404 mListeners.get(i).onAppTransitionPendingLocked();
405 }
406 }
407
408 private void notifyAppTransitionCancelledLocked() {
409 for (int i = 0; i < mListeners.size(); i++) {
410 mListeners.get(i).onAppTransitionCancelledLocked();
411 }
412 }
413
414 private void notifyAppTransitionStartingLocked(IBinder openToken,
415 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
416 for (int i = 0; i < mListeners.size(); i++) {
417 mListeners.get(i).onAppTransitionStartingLocked(openToken, closeToken, openAnimation,
418 closeAnimation);
419 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800420 }
421
Craig Mautner164d4bb2012-11-26 13:51:23 -0800422 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
423 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
424 + (lp != null ? lp.packageName : null)
425 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
426 if (lp != null && lp.windowAnimations != 0) {
427 // If this is a system resource, don't try to load it from the
428 // application resources. It is nice to avoid loading application
429 // resources if we can.
430 String packageName = lp.packageName != null ? lp.packageName : "android";
431 int resId = lp.windowAnimations;
432 if ((resId&0xFF000000) == 0x01000000) {
433 packageName = "android";
434 }
435 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
436 + packageName);
437 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700438 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800439 }
440 return null;
441 }
442
443 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
444 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
445 + packageName + " resId=0x" + Integer.toHexString(resId));
446 if (packageName != null) {
447 if ((resId&0xFF000000) == 0x01000000) {
448 packageName = "android";
449 }
450 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
451 + packageName);
452 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700453 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800454 }
455 return null;
456 }
457
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700458 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800459 int anim = 0;
460 Context context = mContext;
461 if (animAttr >= 0) {
462 AttributeCache.Entry ent = getCachedAnimations(lp);
463 if (ent != null) {
464 context = ent.context;
465 anim = ent.array.getResourceId(animAttr, 0);
466 }
467 }
468 if (anim != 0) {
469 return AnimationUtils.loadAnimation(context, anim);
470 }
471 return null;
472 }
473
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700474 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
475 Context context = mContext;
476 if (resId >= 0) {
477 AttributeCache.Entry ent = getCachedAnimations(lp);
478 if (ent != null) {
479 context = ent.context;
480 }
481 return AnimationUtils.loadAnimation(context, resId);
482 }
483 return null;
484 }
485
486 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800487 int anim = 0;
488 Context context = mContext;
489 if (resId >= 0) {
490 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
491 if (ent != null) {
492 context = ent.context;
493 anim = resId;
494 }
495 }
496 if (anim != 0) {
497 return AnimationUtils.loadAnimation(context, anim);
498 }
499 return null;
500 }
501
Craig Mautner164d4bb2012-11-26 13:51:23 -0800502 /**
503 * Compute the pivot point for an animation that is scaling from a small
504 * rect on screen to a larger rect. The pivot point varies depending on
505 * the distance between the inner and outer edges on both sides. This
506 * function computes the pivot point for one dimension.
507 * @param startPos Offset from left/top edge of outer rectangle to
508 * left/top edge of inner rectangle.
509 * @param finalScale The scaling factor between the size of the outer
510 * and inner rectangles.
511 */
512 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800513
514 /*
515 Theorem of intercepting lines:
516
517 + + +-----------------------------------------------+
518 | | | |
519 | | | |
520 | | | |
521 | | | |
522 x | y | | |
523 | | | |
524 | | | |
525 | | | |
526 | | | |
527 | + | +--------------------+ |
528 | | | | |
529 | | | | |
530 | | | | |
531 | | | | |
532 | | | | |
533 | | | | |
534 | | | | |
535 | | | | |
536 | | | | |
537 | | | | |
538 | | | | |
539 | | | | |
540 | | | | |
541 | | | | |
542 | | | | |
543 | | | | |
544 | | | | |
545 | | +--------------------+ |
546 | | |
547 | | |
548 | | |
549 | | |
550 | | |
551 | | |
552 | | |
553 | +-----------------------------------------------+
554 |
555 |
556 |
557 |
558 |
559 |
560 |
561 |
562 |
563 + ++
564 p ++
565
566 scale = (x - y) / x
567 <=> x = -y / (scale - 1)
568 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800569 final float denom = finalScale-1;
570 if (Math.abs(denom) < .0001f) {
571 return startPos;
572 }
573 return -startPos / denom;
574 }
575
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700576 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
577 Rect containingFrame) {
578 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700579 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700580 final int appWidth = containingFrame.width();
581 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800582 if (enter) {
583 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700584 float scaleW = mTmpRect.width() / (float) appWidth;
585 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800586 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700587 computePivot(mTmpRect.left, scaleW),
588 computePivot(mTmpRect.right, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800589 scale.setInterpolator(mDecelerateInterpolator);
590
Craig Mautner164d4bb2012-11-26 13:51:23 -0800591 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700592 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800593
594 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800595 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800596 set.addAnimation(alpha);
597 set.setDetachWallpaper(true);
598 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800599 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
600 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800601 // If we are on top of the wallpaper, we need an animation that
602 // correctly handles the wallpaper staying static behind all of
603 // the animated elements. To do this, will just have the existing
604 // element fade out.
605 a = new AlphaAnimation(1, 0);
606 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800607 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800608 // For normal animations, the exiting element just holds in place.
609 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800610 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800611
612 // Pick the desired duration. If this is an inter-activity transition,
613 // it is the standard duration for that. Otherwise we use the longer
614 // task transition duration.
615 final long duration;
616 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800617 case TRANSIT_ACTIVITY_OPEN:
618 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800619 duration = mConfigShortAnimTime;
620 break;
621 default:
622 duration = DEFAULT_APP_TRANSITION_DURATION;
623 break;
624 }
625 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800626 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800627 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800628 a.initialize(appWidth, appHeight, appWidth, appHeight);
629 return a;
630 }
631
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700632 private void getDefaultNextAppTransitionStartRect(Rect rect) {
633 if (mDefaultNextAppTransitionAnimationSpec == null ||
634 mDefaultNextAppTransitionAnimationSpec.rect == null) {
635 Slog.wtf(TAG, "Starting rect for app requested, but none available", new Throwable());
636 rect.setEmpty();
637 } else {
638 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
639 }
640 }
641
642 void getNextAppTransitionStartRect(int taskId, Rect rect) {
643 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800644 if (spec == null) {
645 spec = mDefaultNextAppTransitionAnimationSpec;
646 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700647 if (spec == null || spec.rect == null) {
648 Slog.wtf(TAG, "Starting rect for task: " + taskId + " requested, but not available",
649 new Throwable());
650 rect.setEmpty();
651 } else {
652 rect.set(spec.rect);
653 }
654 }
655
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800656 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
657 Bitmap bitmap) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700658 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800659 bitmap, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700660 }
661
Jorim Jaggif97ed922016-02-18 18:57:07 -0800662 /**
663 * @return the duration of the last clip reveal animation
664 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800665 long getLastClipRevealTransitionDuration() {
666 return mLastClipRevealTransitionDuration;
667 }
668
669 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800670 * @return the maximum distance the app surface is traveling of the last clip reveal animation
671 */
672 int getLastClipRevealMaxTranslation() {
673 return mLastClipRevealMaxTranslation;
674 }
675
676 /**
677 * @return true if in the last app transition had a clip reveal animation, false otherwise
678 */
679 boolean hadClipRevealAnimation() {
680 return mLastHadClipReveal;
681 }
682
683 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800684 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
685 * the start rect is outside of the target rect, and there is a lot of movement going on.
686 *
687 * @param cutOff whether the start rect was not fully contained by the end rect
688 * @param translationX the total translation the surface moves in x direction
689 * @param translationY the total translation the surfaces moves in y direction
690 * @param displayFrame our display frame
691 *
692 * @return the duration of the clip reveal animation, in milliseconds
693 */
694 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
695 float translationY, Rect displayFrame) {
696 if (!cutOff) {
697 return DEFAULT_APP_TRANSITION_DURATION;
698 }
699 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
700 Math.abs(translationY) / displayFrame.height());
701 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
702 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
703 }
704
705 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
706 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800707 final Animation anim;
708 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700709 final int appWidth = appFrame.width();
710 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800711
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700712 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700713 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700714 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700715
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700716 float t = 0f;
717 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800718 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700719 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800720 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
721 int translationX = 0;
722 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700723 int centerX = mTmpRect.centerX();
724 int centerY = mTmpRect.centerY();
725 int halfWidth = mTmpRect.width() / 2;
726 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800727 int clipStartX = centerX - halfWidth - appFrame.left;
728 int clipStartY = centerY - halfHeight - appFrame.top;
729 boolean cutOff = false;
730
731 // If the starting rectangle is fully or partially outside of the target rectangle, we
732 // need to start the clipping at the edge and then achieve the rest with translation
733 // and extending the clip rect from that edge.
734 if (appFrame.top > centerY - halfHeight) {
735 translationY = (centerY - halfHeight) - appFrame.top;
736 translationYCorrection = 0;
737 clipStartY = 0;
738 cutOff = true;
739 }
740 if (appFrame.left > centerX - halfWidth) {
741 translationX = (centerX - halfWidth) - appFrame.left;
742 clipStartX = 0;
743 cutOff = true;
744 }
745 if (appFrame.right < centerX + halfWidth) {
746 translationX = (centerX + halfWidth) - appFrame.right;
747 clipStartX = appWidth - mTmpRect.width();
748 cutOff = true;
749 }
750 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
751 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700752
753 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800754 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800755 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700756 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800757 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700758
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800759 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
760 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
761 : mLinearOutSlowInInterpolator);
762 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800763
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800764 Animation clipAnimTB = new ClipRectTBAnimation(
765 clipStartY, clipStartY + mTmpRect.height(),
766 0, appHeight,
767 translationYCorrection, 0,
768 mLinearOutSlowInInterpolator);
769 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
770 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800771
772 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800773 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700774 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800775 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700776 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800777
778 AnimationSet set = new AnimationSet(false);
779 set.addAnimation(clipAnimLR);
780 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700781 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800782 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700783 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800784 set.initialize(appWidth, appHeight, appWidth, appHeight);
785 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800786 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800787 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800788
789 // If the start rect was full inside the target rect (cutOff == false), we don't need
790 // to store the translation, because it's only used if cutOff == true.
791 mLastClipRevealMaxTranslation = cutOff
792 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800793 } else {
794 final long duration;
795 switch (transit) {
796 case TRANSIT_ACTIVITY_OPEN:
797 case TRANSIT_ACTIVITY_CLOSE:
798 duration = mConfigShortAnimTime;
799 break;
800 default:
801 duration = DEFAULT_APP_TRANSITION_DURATION;
802 break;
803 }
804 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
805 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
806 // If we are on top of the wallpaper, we need an animation that
807 // correctly handles the wallpaper staying static behind all of
808 // the animated elements. To do this, will just have the existing
809 // element fade out.
810 anim = new AlphaAnimation(1, 0);
811 anim.setDetachWallpaper(true);
812 } else {
813 // For normal animations, the exiting element just holds in place.
814 anim = new AlphaAnimation(1, 1);
815 }
816 anim.setInterpolator(mDecelerateInterpolator);
817 anim.setDuration(duration);
818 anim.setFillAfter(true);
819 }
820 return anim;
821 }
822
Winson Chung399f6202014-03-19 10:47:20 -0700823 /**
824 * Prepares the specified animation with a standard duration, interpolator, etc.
825 */
Winson Chung5393dff2014-05-08 14:25:43 -0700826 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100827 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700828 if (duration > 0) {
829 a.setDuration(duration);
830 }
Winson Chung5393dff2014-05-08 14:25:43 -0700831 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100832 if (interpolator != null) {
833 a.setInterpolator(interpolator);
834 }
Winson Chung5393dff2014-05-08 14:25:43 -0700835 a.initialize(appWidth, appHeight, appWidth, appHeight);
836 return a;
837 }
838
839 /**
840 * Prepares the specified animation with a standard duration, interpolator, etc.
841 */
Winson Chung399f6202014-03-19 10:47:20 -0700842 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800843 // Pick the desired duration. If this is an inter-activity transition,
844 // it is the standard duration for that. Otherwise we use the longer
845 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700846 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800847 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800848 case TRANSIT_ACTIVITY_OPEN:
849 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800850 duration = mConfigShortAnimTime;
851 break;
852 default:
853 duration = DEFAULT_APP_TRANSITION_DURATION;
854 break;
855 }
Winson Chung5393dff2014-05-08 14:25:43 -0700856 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
857 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800858 }
859
Winson Chung399f6202014-03-19 10:47:20 -0700860 /**
861 * Return the current thumbnail transition state.
862 */
863 int getThumbnailTransitionState(boolean enter) {
864 if (enter) {
865 if (mNextAppTransitionScaleUp) {
866 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
867 } else {
868 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
869 }
870 } else {
871 if (mNextAppTransitionScaleUp) {
872 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
873 } else {
874 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
875 }
876 }
877 }
878
879 /**
880 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700881 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700882 */
Jorim Jaggide63d442016-03-14 14:56:56 +0100883 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winsonb2024762016-04-05 17:32:30 -0700884 Bitmap thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -0700885 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700886 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700887 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700888 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700889 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700890
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700891 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700892 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -0700893 final float fromX;
894 final float fromY;
895 final float toX;
896 final float toY;
897 final float pivotX;
898 final float pivotY;
Winsonb2024762016-04-05 17:32:30 -0700899 if (isTvUiMode(uiMode) || orientation == Configuration.ORIENTATION_PORTRAIT) {
Jorim Jaggi09072002016-03-25 16:48:42 -0700900 fromX = mTmpRect.left;
901 fromY = mTmpRect.top;
902
903 // For the curved translate animation to work, the pivot points needs to be at the
904 // same absolute position as the one from the real surface.
905 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
906 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
907 pivotX = mTmpRect.width() / 2;
908 pivotY = appRect.height() / 2 / scaleW;
909 } else {
910 pivotX = 0;
911 pivotY = 0;
912 fromX = mTmpRect.left;
913 fromY = mTmpRect.top;
914 toX = appRect.left;
915 toY = appRect.top;
916 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100917 final long duration = getAspectScaleDuration();
918 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -0700919 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700920 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +0100921 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100922 scale.setInterpolator(interpolator);
923 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800924 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100925 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
926 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
927 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
928 ? duration / 2
929 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100930 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
931 translate.setInterpolator(interpolator);
932 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -0700933
Jorim Jaggide63d442016-03-14 14:56:56 +0100934 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
935 mTmpToClipRect.set(appRect);
936
937 // Containing frame is in screen space, but we need the clip rect in the
938 // app space.
939 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100940 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
941 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +0100942
943 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +0100944 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
945 (int) (-contentInsets.top * scaleW),
946 (int) (-contentInsets.right * scaleW),
947 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +0100948 }
949
950 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100951 clipAnim.setInterpolator(interpolator);
952 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +0100953
Winson Chung399f6202014-03-19 10:47:20 -0700954 // This AnimationSet uses the Interpolators assigned above.
955 AnimationSet set = new AnimationSet(false);
956 set.addAnimation(scale);
957 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -0700958 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +0100959 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -0700960 a = set;
961 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700962 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +0100963 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100964 scale.setInterpolator(interpolator);
965 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -0700966 Animation alpha = new AlphaAnimation(0f, 1f);
967 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100968 alpha.setDuration(duration);
969 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
970 translate.setInterpolator(interpolator);
971 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -0700972
Winson Chunga4ccb862014-08-22 15:26:27 -0700973 // This AnimationSet uses the Interpolators assigned above.
974 AnimationSet set = new AnimationSet(false);
975 set.addAnimation(scale);
976 set.addAnimation(alpha);
977 set.addAnimation(translate);
978 a = set;
979
980 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700981 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +0100982 null);
Winson Chung399f6202014-03-19 10:47:20 -0700983 }
984
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100985 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
986
987 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +0100988 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100989 return new TranslateAnimation(fromX, toX, fromY, toY);
990 } else {
991 final Path path = createCurvedPath(fromX, toX, fromY, toY);
992 return new CurvedTranslateAnimation(path);
993 }
994 }
995
996 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
997 final Path path = new Path();
998 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -0700999
1000 if (fromY > toY) {
1001 // If the object needs to go up, move it in horizontal direction first, then vertical.
1002 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1003 } else {
1004 // If the object needs to go down, move it in vertical direction first, then horizontal.
1005 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1006 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001007 return path;
1008 }
1009
1010 private long getAspectScaleDuration() {
1011 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001012 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001013 } else {
1014 return THUMBNAIL_APP_TRANSITION_DURATION;
1015 }
1016 }
1017
1018 private Interpolator getAspectScaleInterpolator() {
1019 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1020 return mFastOutSlowInInterpolator;
1021 } else {
1022 return TOUCH_RESPONSE_INTERPOLATOR;
1023 }
1024 }
1025
Winson Chung399f6202014-03-19 10:47:20 -07001026 /**
1027 * This alternate animation is created when we are doing a thumbnail transition, for the
1028 * activity that is leaving, and the activity that is entering.
1029 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001030 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001031 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001032 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001033 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001034 final int appWidth = containingFrame.width();
1035 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001036 getDefaultNextAppTransitionStartRect(mTmpRect);
1037 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001038 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001039 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001040 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winson21700932016-03-24 17:26:23 -07001041 final int thumbStartX = mTmpRect.left - containingFrame.left;
1042 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001043
1044 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001045 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1046 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1047 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1048 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001049 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001050 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001051 } else if (freeform) {
1052 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1053 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001054 } else {
Winson21700932016-03-24 17:26:23 -07001055 AnimationSet set = new AnimationSet(true);
1056
1057 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001058 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001059 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001060
1061 // Containing frame is in screen space, but we need the clip rect in the
1062 // app space.
1063 mTmpFromClipRect.offsetTo(0, 0);
1064 mTmpToClipRect.offsetTo(0, 0);
1065
1066 // Exclude insets region from the source clip.
1067 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001068 mNextAppTransitionInsets.set(contentInsets);
1069
Winsonb2024762016-04-05 17:32:30 -07001070 if (isTvUiMode(uiMode) || orientation == Configuration.ORIENTATION_PORTRAIT) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001071 // We scale the width and clip to the top/left square
1072 float scale = thumbWidth /
1073 (appWidth - contentInsets.left - contentInsets.right);
1074 int unscaledThumbHeight = (int) (thumbHeight / scale);
1075 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1076
1077 mNextAppTransitionInsets.set(contentInsets);
1078
Jorim Jaggi8448f332016-03-14 17:50:37 +01001079 Animation scaleAnim = new ScaleAnimation(
1080 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1081 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001082 containingFrame.width() / 2f,
1083 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001084 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001085 final float x = containingFrame.width() / 2f
1086 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001087 final float targetY = (mTmpRect.top - containingFrame.top);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001088 final float y = containingFrame.height() / 2f
1089 - containingFrame.height() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001090 final float startX = targetX - x;
1091 final float startY = targetY - y;
1092 Animation clipAnim = scaleUp
1093 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1094 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1095 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001096 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1097 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1098
Winson21700932016-03-24 17:26:23 -07001099 set.addAnimation(clipAnim);
1100 set.addAnimation(scaleAnim);
1101 set.addAnimation(translateAnim);
1102
1103 } else {
1104 // In landscape, we don't scale at all and only crop
1105 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1106 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1107
Jorim Jaggi8448f332016-03-14 17:50:37 +01001108 Animation clipAnim = scaleUp
1109 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1110 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1111 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001112 ? createCurvedMotion(thumbStartX, 0,
1113 thumbStartY - contentInsets.top, 0)
1114 : createCurvedMotion(0, thumbStartX, 0,
1115 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001116
1117 set.addAnimation(clipAnim);
1118 set.addAnimation(translateAnim);
1119 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001120 a = set;
Winson21700932016-03-24 17:26:23 -07001121 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001122 }
Winson Chung399f6202014-03-19 10:47:20 -07001123 break;
1124 }
1125 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001126 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001127 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001128 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001129 // activity.
1130 a = new AlphaAnimation(1, 0);
1131 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001132 a = new AlphaAnimation(1, 1);
1133 }
1134 break;
1135 }
1136 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001137 // Target app window during the scale down
1138 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1139 // Fade in the destination activity if we are animating from a wallpaper
1140 // activity.
1141 a = new AlphaAnimation(0, 1);
1142 } else {
1143 a = new AlphaAnimation(1, 1);
1144 }
Winson Chung399f6202014-03-19 10:47:20 -07001145 break;
1146 }
Winson Chung399f6202014-03-19 10:47:20 -07001147 default:
1148 throw new RuntimeException("Invalid thumbnail transition state");
1149 }
1150
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001151 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1152 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001153 }
1154
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001155 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1156 @Nullable Rect surfaceInsets, int taskId) {
1157 getNextAppTransitionStartRect(taskId, mTmpRect);
1158 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1159 true);
1160 }
1161
1162 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1163 @Nullable Rect surfaceInsets, int taskId) {
1164 getNextAppTransitionStartRect(taskId, mTmpRect);
1165 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1166 false);
1167 }
1168
1169 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1170 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1171 final float sourceWidth = sourceFrame.width();
1172 final float sourceHeight = sourceFrame.height();
1173 final float destWidth = destFrame.width();
1174 final float destHeight = destFrame.height();
1175 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1176 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001177 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001178 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001179 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001180 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001181 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1182 // We want the scaling to happen from the center of the surface. In order to achieve that,
1183 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001184 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1185 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1186 final ScaleAnimation scale = enter ?
1187 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1188 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1189 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1190 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1191 final int destHCenter = destFrame.left + destFrame.width() / 2;
1192 final int destVCenter = destFrame.top + destFrame.height() / 2;
1193 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1194 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1195 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1196 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001197 set.addAnimation(scale);
1198 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001199
1200 final IRemoteCallback callback = mAnimationFinishedCallback;
1201 if (callback != null) {
1202 set.setAnimationListener(new Animation.AnimationListener() {
1203 @Override
1204 public void onAnimationStart(Animation animation) { }
1205
1206 @Override
1207 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001208 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001209 }
1210
1211 @Override
1212 public void onAnimationRepeat(Animation animation) { }
1213 });
1214 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001215 return set;
1216 }
1217
Winson Chung399f6202014-03-19 10:47:20 -07001218 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001219 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001220 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001221 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001222 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
1223 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001224 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001225 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001226 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001227 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001228 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001229 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1230
1231 if (mNextAppTransitionScaleUp) {
1232 // Animation for the thumbnail zooming from its initial size to the full screen
1233 float scaleW = appWidth / thumbWidth;
1234 float scaleH = appHeight / thumbHeight;
1235 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001236 computePivot(mTmpRect.left, 1 / scaleW),
1237 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001238 scale.setInterpolator(mDecelerateInterpolator);
1239
1240 Animation alpha = new AlphaAnimation(1, 0);
1241 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1242
1243 // This AnimationSet uses the Interpolators assigned above.
1244 AnimationSet set = new AnimationSet(false);
1245 set.addAnimation(scale);
1246 set.addAnimation(alpha);
1247 a = set;
1248 } else {
1249 // Animation for the thumbnail zooming down from the full screen to its final size
1250 float scaleW = appWidth / thumbWidth;
1251 float scaleH = appHeight / thumbHeight;
1252 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001253 computePivot(mTmpRect.left, 1 / scaleW),
1254 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001255 }
1256
1257 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1258 }
1259
1260 /**
Winson Chung399f6202014-03-19 10:47:20 -07001261 * This animation is created when we are doing a thumbnail transition, for the activity that is
1262 * leaving, and the activity that is entering.
1263 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001264 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1265 int transit, int taskId) {
1266 final int appWidth = containingFrame.width();
1267 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001268 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001269 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001270 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001271 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001272 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001273 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001274 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1275
1276 switch (thumbTransitState) {
1277 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1278 // Entering app scales up with the thumbnail
1279 float scaleW = thumbWidth / appWidth;
1280 float scaleH = thumbHeight / appHeight;
1281 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001282 computePivot(mTmpRect.left, scaleW),
1283 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001284 break;
1285 }
1286 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1287 // Exiting app while the thumbnail is scaling up should fade or stay in place
1288 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1289 // Fade out while bringing up selected activity. This keeps the
1290 // current activity from showing through a launching wallpaper
1291 // activity.
1292 a = new AlphaAnimation(1, 0);
1293 } else {
1294 // noop animation
1295 a = new AlphaAnimation(1, 1);
1296 }
1297 break;
1298 }
1299 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1300 // Entering the other app, it should just be visible while we scale the thumbnail
1301 // down above it
1302 a = new AlphaAnimation(1, 1);
1303 break;
1304 }
1305 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1306 // Exiting the current app, the app should scale down with the thumbnail
1307 float scaleW = thumbWidth / appWidth;
1308 float scaleH = thumbHeight / appHeight;
1309 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001310 computePivot(mTmpRect.left, scaleW),
1311 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001312
1313 Animation alpha = new AlphaAnimation(1, 0);
1314
1315 AnimationSet set = new AnimationSet(true);
1316 set.addAnimation(scale);
1317 set.addAnimation(alpha);
1318 set.setZAdjustment(Animation.ZORDER_TOP);
1319 a = set;
1320 break;
1321 }
1322 default:
1323 throw new RuntimeException("Invalid thumbnail transition state");
1324 }
1325
1326 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1327 }
1328
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001329 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001330 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1331 final int left = mTmpFromClipRect.left;
1332 final int top = mTmpFromClipRect.top;
1333 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001334 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1335 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001336 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001337 float fromWidth = mTmpFromClipRect.width();
1338 float toWidth = mTmpToClipRect.width();
1339 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001340 // While the window might span the whole display, the actual content will be cropped to the
1341 // system decoration frame, for example when the window is docked. We need to take into
1342 // account the visible height when constructing the animation.
1343 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1344 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001345 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1346 // The final window is larger in both dimensions than current window (e.g. we are
1347 // maximizing), so we can simply unclip the new window and there will be no disappearing
1348 // frame.
1349 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1350 } else {
1351 // The disappearing window has one larger dimension. We need to apply scaling, so the
1352 // first frame of the entry animation matches the old window.
1353 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001354 // We might not be going exactly full screen, but instead be aligned under the status
1355 // bar using cropping. We still need to account for the cropped part, which will also
1356 // be scaled.
1357 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001358 }
1359
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001360 // We animate the translation from the old position of the removed window, to the new
1361 // position of the added window. The latter might not be full screen, for example docked for
1362 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001363 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001364 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001365 set.addAnimation(translate);
1366 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001367 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001368 return set;
1369 }
1370
Jorim Jaggic554b772015-06-04 16:07:57 -07001371 /**
1372 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1373 * frame of the transition doesn't change the visuals on screen, so we can start
1374 * directly with the second one
1375 */
1376 boolean canSkipFirstFrame() {
1377 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1378 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
1379 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1380 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001381
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001382 /**
1383 *
1384 * @param frame These are the bounds of the window when it finishes the animation. This is where
1385 * the animation must usually finish in entrance animation, as the next frame will
1386 * display the window at these coordinates. In case of exit animation, this is
1387 * where the animation must start, as the frame before the animation is displaying
1388 * the window at these bounds.
1389 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1390 * window might be obscured, usually by the system windows (status bar and
1391 * navigation bar) and we use content insets to convey that information. This
1392 * usually affects the animation aspects vertically, as the system decoration is
1393 * at the top and the bottom. For example when we animate from full screen to
1394 * recents, we want to exclude the covered parts, because they won't match the
1395 * thumbnail after the last frame is executed.
1396 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1397 * know about this to make the animation frames match. We currently use
1398 * this for freeform windows, which have larger surfaces to display
1399 * shadows. When we animate them from recents, we want to match the content
1400 * to the recents thumbnail and hence need to account for the surface being
1401 * bigger.
1402 */
Winsonb2024762016-04-05 17:32:30 -07001403 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001404 int orientation, Rect frame, Rect displayFrame, Rect insets,
1405 @Nullable Rect surfaceInsets, boolean isVoiceInteraction, boolean freeform,
1406 int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001407 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001408 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
1409 || transit == TRANSIT_TASK_OPEN
1410 || transit == TRANSIT_TASK_TO_FRONT)) {
1411 a = loadAnimationRes(lp, enter
1412 ? com.android.internal.R.anim.voice_activity_open_enter
1413 : com.android.internal.R.anim.voice_activity_open_exit);
1414 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1415 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001416 + " anim=" + a + " transit=" + appTransitionToString(transit)
1417 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001418 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1419 || transit == TRANSIT_TASK_CLOSE
1420 || transit == TRANSIT_TASK_TO_BACK)) {
1421 a = loadAnimationRes(lp, enter
1422 ? com.android.internal.R.anim.voice_activity_close_enter
1423 : com.android.internal.R.anim.voice_activity_close_exit);
1424 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1425 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001426 + " anim=" + a + " transit=" + appTransitionToString(transit)
1427 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001428 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001429 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001430 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1431 "applyAnimation:"
1432 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1433 + " transit=" + appTransitionToString(transit)
1434 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001435 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1436 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001437 mNextAppTransitionEnter : mNextAppTransitionExit);
1438 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1439 "applyAnimation:"
1440 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001441 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001442 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001443 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1444 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1445 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1446 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001447 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1448 + " transit=" + appTransitionToString(transit)
1449 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001450 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001451 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001452 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1453 "applyAnimation:"
1454 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001455 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001456 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001457 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001458 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001459 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1460 "applyAnimation:"
1461 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001462 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001463 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001464 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1465 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001466 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001467 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001468 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001469 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001470 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1471 String animName = mNextAppTransitionScaleUp ?
1472 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1473 Slog.v(TAG, "applyAnimation:"
1474 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001475 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001476 + " Callers=" + Debug.getCallers(3));
1477 }
1478 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1479 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1480 mNextAppTransitionScaleUp =
1481 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1482 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001483 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001484 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001485 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1486 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001487 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001488 Slog.v(TAG, "applyAnimation:"
1489 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001490 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001491 + " Callers=" + Debug.getCallers(3));
1492 }
1493 } else {
1494 int animAttr = 0;
1495 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001496 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001497 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001498 ? WindowAnimation_activityOpenEnterAnimation
1499 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001500 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001501 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001502 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001503 ? WindowAnimation_activityCloseEnterAnimation
1504 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001505 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001506 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001507 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001508 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001509 ? WindowAnimation_taskOpenEnterAnimation
1510 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001511 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001512 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001513 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001514 ? WindowAnimation_taskCloseEnterAnimation
1515 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001516 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001517 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001518 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001519 ? WindowAnimation_taskToFrontEnterAnimation
1520 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001521 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001522 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001523 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001524 ? WindowAnimation_taskToBackEnterAnimation
1525 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001526 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001527 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001528 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001529 ? WindowAnimation_wallpaperOpenEnterAnimation
1530 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001531 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001532 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001533 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001534 ? WindowAnimation_wallpaperCloseEnterAnimation
1535 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001536 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001537 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001538 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001539 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1540 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001541 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001542 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001543 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001544 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1545 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001546 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001547 case TRANSIT_TASK_OPEN_BEHIND:
1548 animAttr = enter
1549 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001550 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001551 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001552 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001553 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1554 "applyAnimation:"
1555 + " anim=" + a
1556 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001557 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001558 + " Callers=" + Debug.getCallers(3));
1559 }
1560 return a;
1561 }
1562
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001563 int getAppStackClipMode() {
1564 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001565 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001566 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001567 ? STACK_CLIP_NONE
1568 : STACK_CLIP_AFTER_ANIM;
1569 }
1570
Craig Mautner164d4bb2012-11-26 13:51:23 -08001571 void postAnimationCallback() {
1572 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001573 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1574 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001575 mNextAppTransitionCallback = null;
1576 }
1577 }
1578
1579 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001580 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001581 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001582 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001583 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001584 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001585 mNextAppTransitionEnter = enterAnim;
1586 mNextAppTransitionExit = exitAnim;
1587 postAnimationCallback();
1588 mNextAppTransitionCallback = startedCallback;
1589 } else {
1590 postAnimationCallback();
1591 }
1592 }
1593
1594 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001595 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001596 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001597 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001598 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001599 putDefaultNextAppTransitionCoordinates(startX, startY, startX + startWidth,
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001600 startY + startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001601 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001602 }
1603 }
1604
Chet Haase10e23ab2015-02-11 15:08:38 -08001605 void overridePendingAppTransitionClipReveal(int startX, int startY,
1606 int startWidth, int startHeight) {
1607 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001608 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001609 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001610 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001611 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001612 }
1613 }
1614
Craig Mautner164d4bb2012-11-26 13:51:23 -08001615 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1616 IRemoteCallback startedCallback, boolean scaleUp) {
1617 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001618 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001619 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1620 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001621 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001622 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001623 postAnimationCallback();
1624 mNextAppTransitionCallback = startedCallback;
1625 } else {
1626 postAnimationCallback();
1627 }
1628 }
1629
Winson Chunga4ccb862014-08-22 15:26:27 -07001630 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001631 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001632 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001633 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001634 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1635 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001636 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001637 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1638 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001639 postAnimationCallback();
1640 mNextAppTransitionCallback = startedCallback;
1641 } else {
1642 postAnimationCallback();
1643 }
1644 }
1645
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001646 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001647 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1648 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001649 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001650 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001651 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1652 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001653 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001654 if (specs != null) {
1655 for (int i = 0; i < specs.length; i++) {
1656 AppTransitionAnimationSpec spec = specs[i];
1657 if (spec != null) {
1658 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1659 if (i == 0) {
1660 // In full screen mode, the transition code depends on the default spec
1661 // to be set.
1662 Rect rect = spec.rect;
1663 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Filip Gruszczynskie3264d82015-11-20 17:10:04 -08001664 rect.width(), rect.height(), spec.bitmap);
Jorim Jaggi43102412015-11-11 16:28:37 +01001665 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001666 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001667 }
1668 }
1669 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001670 mNextAppTransitionCallback = onAnimationStartedCallback;
1671 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001672 } else {
1673 postAnimationCallback();
1674 }
1675 }
1676
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001677 void overridePendingAppTransitionMultiThumbFuture(
1678 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1679 boolean scaleUp) {
1680 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001681 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001682 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1683 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001684 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1685 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001686 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001687 }
1688 }
1689
Winson Chung044d5292014-11-06 11:05:19 -08001690 void overrideInPlaceAppTransition(String packageName, int anim) {
1691 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001692 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001693 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1694 mNextAppTransitionPackage = packageName;
1695 mNextAppTransitionInPlace = anim;
1696 } else {
1697 postAnimationCallback();
1698 }
1699 }
1700
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001701 /**
1702 * If a future is set for the app transition specs, fetch it in another thread.
1703 */
1704 private void fetchAppTransitionSpecsFromFuture() {
1705 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1706 mNextAppTransitionAnimationsSpecsPending = true;
1707 final IAppTransitionAnimationSpecsFuture future
1708 = mNextAppTransitionAnimationsSpecsFuture;
1709 mNextAppTransitionAnimationsSpecsFuture = null;
1710 mDefaultExecutor.execute(new Runnable() {
1711 @Override
1712 public void run() {
1713 AppTransitionAnimationSpec[] specs = null;
1714 try {
1715 specs = future.get();
1716 } catch (RemoteException e) {
1717 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1718 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001719 synchronized (mService.mWindowMap) {
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001720 mNextAppTransitionAnimationsSpecsPending = false;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001721 overridePendingAppTransitionMultiThumb(specs,
1722 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1723 mNextAppTransitionScaleUp);
1724 mNextAppTransitionFutureCallback = null;
Filip Gruszczynski96daf322015-11-18 18:01:27 -08001725 if (specs != null) {
1726 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1727 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001728 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001729 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001730 }
1731 });
1732 }
1733 }
1734
Craig Mautner164d4bb2012-11-26 13:51:23 -08001735 @Override
1736 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001737 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001738 }
1739
Craig Mautner4b71aa12012-12-27 17:20:01 -08001740 /**
1741 * Returns the human readable name of a window transition.
1742 *
1743 * @param transition The window transition.
1744 * @return The transition symbolic name.
1745 */
1746 public static String appTransitionToString(int transition) {
1747 switch (transition) {
1748 case TRANSIT_UNSET: {
1749 return "TRANSIT_UNSET";
1750 }
1751 case TRANSIT_NONE: {
1752 return "TRANSIT_NONE";
1753 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001754 case TRANSIT_ACTIVITY_OPEN: {
1755 return "TRANSIT_ACTIVITY_OPEN";
1756 }
1757 case TRANSIT_ACTIVITY_CLOSE: {
1758 return "TRANSIT_ACTIVITY_CLOSE";
1759 }
1760 case TRANSIT_TASK_OPEN: {
1761 return "TRANSIT_TASK_OPEN";
1762 }
1763 case TRANSIT_TASK_CLOSE: {
1764 return "TRANSIT_TASK_CLOSE";
1765 }
1766 case TRANSIT_TASK_TO_FRONT: {
1767 return "TRANSIT_TASK_TO_FRONT";
1768 }
1769 case TRANSIT_TASK_TO_BACK: {
1770 return "TRANSIT_TASK_TO_BACK";
1771 }
1772 case TRANSIT_WALLPAPER_CLOSE: {
1773 return "TRANSIT_WALLPAPER_CLOSE";
1774 }
1775 case TRANSIT_WALLPAPER_OPEN: {
1776 return "TRANSIT_WALLPAPER_OPEN";
1777 }
1778 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1779 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1780 }
1781 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1782 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1783 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001784 case TRANSIT_TASK_OPEN_BEHIND: {
1785 return "TRANSIT_TASK_OPEN_BEHIND";
1786 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001787 case TRANSIT_ACTIVITY_RELAUNCH: {
1788 return "TRANSIT_ACTIVITY_RELAUNCH";
1789 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001790 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1791 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1792 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001793 default: {
1794 return "<UNKNOWN>";
1795 }
1796 }
1797 }
1798
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001799 private String appStateToString() {
1800 switch (mAppTransitionState) {
1801 case APP_STATE_IDLE:
1802 return "APP_STATE_IDLE";
1803 case APP_STATE_READY:
1804 return "APP_STATE_READY";
1805 case APP_STATE_RUNNING:
1806 return "APP_STATE_RUNNING";
1807 case APP_STATE_TIMEOUT:
1808 return "APP_STATE_TIMEOUT";
1809 default:
1810 return "unknown state=" + mAppTransitionState;
1811 }
1812 }
1813
1814 private String transitTypeToString() {
1815 switch (mNextAppTransitionType) {
1816 case NEXT_TRANSIT_TYPE_NONE:
1817 return "NEXT_TRANSIT_TYPE_NONE";
1818 case NEXT_TRANSIT_TYPE_CUSTOM:
1819 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001820 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1821 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001822 case NEXT_TRANSIT_TYPE_SCALE_UP:
1823 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1824 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1825 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1826 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1827 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001828 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1829 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1830 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1831 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001832 default:
1833 return "unknown type=" + mNextAppTransitionType;
1834 }
1835 }
1836
Craig Mautner164d4bb2012-11-26 13:51:23 -08001837 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001838 public void dump(PrintWriter pw, String prefix) {
1839 pw.print(prefix); pw.println(this);
1840 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001841 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001842 pw.print(prefix); pw.print("mNextAppTransitionType=");
1843 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001844 }
1845 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001846 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001847 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001848 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001849 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001850 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1851 pw.print(" mNextAppTransitionExit=0x");
1852 pw.println(Integer.toHexString(mNextAppTransitionExit));
1853 break;
Winson Chung044d5292014-11-06 11:05:19 -08001854 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001855 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001856 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001857 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001858 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1859 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001860 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001861 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001862 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001863 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001864 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001865 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001866 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001867 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001868 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001869 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001870 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001871 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001872 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1873 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001874 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001875 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1876 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1877 pw.println(mDefaultNextAppTransitionAnimationSpec);
1878 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1879 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001880 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1881 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001882 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001883 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001884 }
1885 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001886 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1887 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001888 }
1889 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001890
1891 public void setCurrentUser(int newUserId) {
1892 mCurrentUserId = newUserId;
1893 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001894
1895 /**
1896 * @return true if transition is not running and should not be skipped, false if transition is
1897 * already running
1898 */
1899 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent) {
1900 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
1901 + " transit=" + appTransitionToString(transit)
1902 + " " + this
1903 + " alwaysKeepCurrent=" + alwaysKeepCurrent
1904 + " Callers=" + Debug.getCallers(3));
1905 if (!isTransitionSet() || mNextAppTransition == TRANSIT_NONE) {
1906 setAppTransition(transit);
1907 } else if (!alwaysKeepCurrent) {
1908 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
1909 // Opening a new task always supersedes a close for the anim.
1910 setAppTransition(transit);
1911 } else if (transit == TRANSIT_ACTIVITY_OPEN
1912 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
1913 // Opening a new activity always supersedes a close for the anim.
1914 setAppTransition(transit);
1915 }
1916 }
1917 boolean prepared = prepare();
1918 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001919 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
1920 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001921 }
1922 return prepared;
1923 }
Winsonb2024762016-04-05 17:32:30 -07001924
1925 /**
1926 * @return whether the specified {@param uiMode} is the TV mode.
1927 */
1928 private boolean isTvUiMode(int uiMode) {
1929 return (uiMode & Configuration.UI_MODE_TYPE_TELEVISION) > 0;
1930 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001931}