blob: 5cb709936bd1aebe5d13bddd3902d2e4e81ee5ac [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;
Filip Gruszczynski82861362015-10-16 14:21:09 -070046
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070047import android.annotation.Nullable;
Craig Mautner164d4bb2012-11-26 13:51:23 -080048import android.content.Context;
49import android.graphics.Bitmap;
Winson Chung399f6202014-03-19 10:47:20 -070050import android.graphics.Rect;
Craig Mautner164d4bb2012-11-26 13:51:23 -080051import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010052import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080053import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010054import android.os.RemoteException;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080055import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080056import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070057import android.util.SparseArray;
58import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010059import android.view.IAppTransitionAnimationSpecsFuture;
Craig Mautner164d4bb2012-11-26 13:51:23 -080060import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080061import android.view.animation.AlphaAnimation;
62import android.view.animation.Animation;
63import android.view.animation.AnimationSet;
64import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070065import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080066import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070067import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080068import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070069import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070070
Craig Mautner164d4bb2012-11-26 13:51:23 -080071import com.android.internal.util.DumpUtils.Dump;
72import com.android.server.AttributeCache;
73import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -080074import com.android.server.wm.animation.ClipRectLRAnimation;
75import com.android.server.wm.animation.ClipRectTBAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080076
77import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010078import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010079import java.util.concurrent.ExecutorService;
80import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -080081
Craig Mautner164d4bb2012-11-26 13:51:23 -080082// State management of app transitions. When we are preparing for a
83// transition, mNextAppTransition will be the kind of transition to
84// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
85// mOpeningApps and mClosingApps are the lists of tokens that will be
86// made visible or hidden at the next transition.
87public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080088 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070089 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080090
Craig Mautner4b71aa12012-12-27 17:20:01 -080091 /** Not set up for a transition. */
92 public static final int TRANSIT_UNSET = -1;
93 /** No animation for transition. */
94 public static final int TRANSIT_NONE = 0;
95 /** 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 -070096 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -080097 /** The window in the top-most activity is being closed to reveal the
98 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -070099 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800100 /** A window in a new task is being opened on top of an existing one
101 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700102 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800103 /** A window in the top-most activity is being closed to reveal the
104 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700105 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800106 /** A window in an existing task is being displayed on top of an existing one
107 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700108 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800109 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700110 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800111 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
112 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700113 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800114 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
115 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700116 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800117 /** A window in a new activity is being opened on top of an existing one, and both are on top
118 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700119 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800120 /** The window in the top-most activity is being closed to reveal the previous activity, and
121 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700122 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
123 /** A window in a new task is being opened behind an existing one in another activity's task.
124 * The new window will show briefly and then be gone. */
125 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800126 /** A window in a task is being animated in-place. */
127 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700128 /** An activity is being relaunched (e.g. due to configuration change). */
129 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800130
Winson Chunga4ccb862014-08-22 15:26:27 -0700131 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700132 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800133 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700134 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800135
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800136 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800137
138 /** Interpolator to be used for animations that respond directly to a touch */
139 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
140 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
141
142 /**
143 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
144 * involved, to make it more understandable.
145 */
146 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700147 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
148 private static final int THUMBNAIL_APP_TRANSITION_ALPHA_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700149 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800150
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800151 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800152 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800153
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800154 private int mNextAppTransition = TRANSIT_UNSET;
155
156 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
157 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
158 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
159 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
160 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700161 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
162 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800163 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800164 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800165 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
166
Winson Chung399f6202014-03-19 10:47:20 -0700167 // These are the possible states for the enter/exit activities during a thumbnail transition
168 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
169 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
170 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
171 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
172
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800173 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800174 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800175 private boolean mNextAppTransitionScaleUp;
176 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100177 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700178 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800179 private int mNextAppTransitionEnter;
180 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800181 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700182
183 // Keyed by task id.
184 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
185 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100186 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
187 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700188 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
189
Winson Chunga4ccb862014-08-22 15:26:27 -0700190 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800191
Winson Chung2820c452014-04-15 15:34:44 -0700192 private Rect mTmpFromClipRect = new Rect();
193 private Rect mTmpToClipRect = new Rect();
194
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700195 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700196
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800197 private final static int APP_STATE_IDLE = 0;
198 private final static int APP_STATE_READY = 1;
199 private final static int APP_STATE_RUNNING = 2;
200 private final static int APP_STATE_TIMEOUT = 3;
201 private int mAppTransitionState = APP_STATE_IDLE;
202
203 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800204 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700205 private final Interpolator mThumbnailFadeInInterpolator;
206 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800207 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700208 private final Interpolator mFastOutLinearInInterpolator;
209 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
210
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700211 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800212
Amith Yamasani4befbec2013-07-10 16:18:01 -0700213 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800214 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700215
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100216 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100217 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100218
Jorim Jaggif97ed922016-02-18 18:57:07 -0800219 private int mLastClipRevealMaxTranslation;
220 private boolean mLastHadClipReveal;
221
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800222 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800223 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800224 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800225 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
226 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700227 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
228 com.android.internal.R.interpolator.fast_out_linear_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800229 mConfigShortAnimTime = context.getResources().getInteger(
230 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800231 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
232 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700233 mThumbnailFadeInInterpolator = new Interpolator() {
234 @Override
235 public float getInterpolation(float input) {
236 // Linear response for first fraction, then complete after that.
237 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
238 return 0f;
239 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700240 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700241 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700242 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700243 }
244 };
245 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800246 @Override
247 public float getInterpolation(float input) {
248 // Linear response for first fraction, then complete after that.
249 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700250 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
251 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800252 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700253 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800254 }
255 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700256 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
257 * mContext.getResources().getDisplayMetrics().density);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800258 }
259
260 boolean isTransitionSet() {
261 return mNextAppTransition != TRANSIT_UNSET;
262 }
263
Craig Mautner164d4bb2012-11-26 13:51:23 -0800264 boolean isTransitionEqual(int transit) {
265 return mNextAppTransition == transit;
266 }
267
268 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800269 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800270 }
271
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700272 private void setAppTransition(int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800273 mNextAppTransition = transit;
274 }
275
276 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800277 return mAppTransitionState == APP_STATE_READY
278 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800279 }
280
Craig Mautnerae446592012-12-06 19:05:05 -0800281 void setReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800282 mAppTransitionState = APP_STATE_READY;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100283 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800284 }
285
286 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800287 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800288 }
289
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800290 void setIdle() {
291 mAppTransitionState = APP_STATE_IDLE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800292 }
293
294 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800295 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800296 }
297
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800298 void setTimeout() {
299 mAppTransitionState = APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800300 }
301
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700302 Bitmap getAppTransitionThumbnailHeader(int taskId) {
303 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800304 if (spec == null) {
305 spec = mDefaultNextAppTransitionAnimationSpec;
306 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700307 return spec != null ? spec.bitmap : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800308 }
309
Winson Chunga4ccb862014-08-22 15:26:27 -0700310 /** Returns whether the next thumbnail transition is aspect scaled up. */
311 boolean isNextThumbnailTransitionAspectScaled() {
312 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
313 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
314 }
315
316 /** Returns whether the next thumbnail transition is scaling up. */
317 boolean isNextThumbnailTransitionScaleUp() {
318 return mNextAppTransitionScaleUp;
319 }
320
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800321 boolean isNextAppTransitionThumbnailUp() {
322 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
323 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
324 }
325
326 boolean isNextAppTransitionThumbnailDown() {
327 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
328 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
329 }
330
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100331 /**
332 * @return true if and only if we are currently fetching app transition specs from the future
333 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
334 */
335 boolean isFetchingAppTransitionsSpecs() {
336 return mNextAppTransitionAnimationsSpecsPending;
337 }
338
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700339 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800340 if (!isRunning()) {
341 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100342 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800343 mLastHadClipReveal = false;
344 mLastClipRevealMaxTranslation = 0;
345 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700346 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800347 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700348 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800349 }
350
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800351 void goodToGo(AppWindowAnimator topOpeningAppAnimator, AppWindowAnimator topClosingAppAnimator,
352 ArraySet<AppWindowToken> openingApps, ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800353 mNextAppTransition = TRANSIT_UNSET;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800354 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100355 notifyAppTransitionStartingLocked(
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800356 topOpeningAppAnimator != null ? topOpeningAppAnimator.mAppToken.token : null,
357 topClosingAppAnimator != null ? topClosingAppAnimator.mAppToken.token : null,
358 topOpeningAppAnimator != null ? topOpeningAppAnimator.animation : null,
359 topClosingAppAnimator != null ? topClosingAppAnimator.animation : null);
360 mService.getDefaultDisplayContentLocked().getDockedDividerController()
361 .notifyAppTransitionStarting(openingApps, closingApps);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800362 }
363
364 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800365 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800366 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700367 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi65193992015-11-23 16:49:59 -0800368 mNextAppTransitionAnimationsSpecsFuture = null;
369 mDefaultNextAppTransitionAnimationSpec = null;
370 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800371 }
372
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800373 void freeze() {
374 setAppTransition(AppTransition.TRANSIT_UNSET);
375 clear();
376 setReady();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100377 notifyAppTransitionCancelledLocked();
378 }
379
380 void registerListenerLocked(AppTransitionListener listener) {
381 mListeners.add(listener);
382 }
383
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700384 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100385 for (int i = 0; i < mListeners.size(); i++) {
386 mListeners.get(i).onAppTransitionFinishedLocked(token);
387 }
388 }
389
390 private void notifyAppTransitionPendingLocked() {
391 for (int i = 0; i < mListeners.size(); i++) {
392 mListeners.get(i).onAppTransitionPendingLocked();
393 }
394 }
395
396 private void notifyAppTransitionCancelledLocked() {
397 for (int i = 0; i < mListeners.size(); i++) {
398 mListeners.get(i).onAppTransitionCancelledLocked();
399 }
400 }
401
402 private void notifyAppTransitionStartingLocked(IBinder openToken,
403 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
404 for (int i = 0; i < mListeners.size(); i++) {
405 mListeners.get(i).onAppTransitionStartingLocked(openToken, closeToken, openAnimation,
406 closeAnimation);
407 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800408 }
409
Craig Mautner164d4bb2012-11-26 13:51:23 -0800410 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
411 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
412 + (lp != null ? lp.packageName : null)
413 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
414 if (lp != null && lp.windowAnimations != 0) {
415 // If this is a system resource, don't try to load it from the
416 // application resources. It is nice to avoid loading application
417 // resources if we can.
418 String packageName = lp.packageName != null ? lp.packageName : "android";
419 int resId = lp.windowAnimations;
420 if ((resId&0xFF000000) == 0x01000000) {
421 packageName = "android";
422 }
423 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
424 + packageName);
425 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700426 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800427 }
428 return null;
429 }
430
431 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
432 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
433 + packageName + " resId=0x" + Integer.toHexString(resId));
434 if (packageName != null) {
435 if ((resId&0xFF000000) == 0x01000000) {
436 packageName = "android";
437 }
438 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
439 + packageName);
440 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700441 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800442 }
443 return null;
444 }
445
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700446 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800447 int anim = 0;
448 Context context = mContext;
449 if (animAttr >= 0) {
450 AttributeCache.Entry ent = getCachedAnimations(lp);
451 if (ent != null) {
452 context = ent.context;
453 anim = ent.array.getResourceId(animAttr, 0);
454 }
455 }
456 if (anim != 0) {
457 return AnimationUtils.loadAnimation(context, anim);
458 }
459 return null;
460 }
461
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700462 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
463 Context context = mContext;
464 if (resId >= 0) {
465 AttributeCache.Entry ent = getCachedAnimations(lp);
466 if (ent != null) {
467 context = ent.context;
468 }
469 return AnimationUtils.loadAnimation(context, resId);
470 }
471 return null;
472 }
473
474 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800475 int anim = 0;
476 Context context = mContext;
477 if (resId >= 0) {
478 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
479 if (ent != null) {
480 context = ent.context;
481 anim = resId;
482 }
483 }
484 if (anim != 0) {
485 return AnimationUtils.loadAnimation(context, anim);
486 }
487 return null;
488 }
489
Craig Mautner164d4bb2012-11-26 13:51:23 -0800490 /**
491 * Compute the pivot point for an animation that is scaling from a small
492 * rect on screen to a larger rect. The pivot point varies depending on
493 * the distance between the inner and outer edges on both sides. This
494 * function computes the pivot point for one dimension.
495 * @param startPos Offset from left/top edge of outer rectangle to
496 * left/top edge of inner rectangle.
497 * @param finalScale The scaling factor between the size of the outer
498 * and inner rectangles.
499 */
500 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800501
502 /*
503 Theorem of intercepting lines:
504
505 + + +-----------------------------------------------+
506 | | | |
507 | | | |
508 | | | |
509 | | | |
510 x | y | | |
511 | | | |
512 | | | |
513 | | | |
514 | | | |
515 | + | +--------------------+ |
516 | | | | |
517 | | | | |
518 | | | | |
519 | | | | |
520 | | | | |
521 | | | | |
522 | | | | |
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 p ++
553
554 scale = (x - y) / x
555 <=> x = -y / (scale - 1)
556 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800557 final float denom = finalScale-1;
558 if (Math.abs(denom) < .0001f) {
559 return startPos;
560 }
561 return -startPos / denom;
562 }
563
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700564 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
565 Rect containingFrame) {
566 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700567 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700568 final int appWidth = containingFrame.width();
569 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800570 if (enter) {
571 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700572 float scaleW = mTmpRect.width() / (float) appWidth;
573 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800574 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700575 computePivot(mTmpRect.left, scaleW),
576 computePivot(mTmpRect.right, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800577 scale.setInterpolator(mDecelerateInterpolator);
578
Craig Mautner164d4bb2012-11-26 13:51:23 -0800579 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700580 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800581
582 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800583 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800584 set.addAnimation(alpha);
585 set.setDetachWallpaper(true);
586 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800587 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
588 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800589 // If we are on top of the wallpaper, we need an animation that
590 // correctly handles the wallpaper staying static behind all of
591 // the animated elements. To do this, will just have the existing
592 // element fade out.
593 a = new AlphaAnimation(1, 0);
594 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800595 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800596 // For normal animations, the exiting element just holds in place.
597 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800598 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800599
600 // Pick the desired duration. If this is an inter-activity transition,
601 // it is the standard duration for that. Otherwise we use the longer
602 // task transition duration.
603 final long duration;
604 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800605 case TRANSIT_ACTIVITY_OPEN:
606 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800607 duration = mConfigShortAnimTime;
608 break;
609 default:
610 duration = DEFAULT_APP_TRANSITION_DURATION;
611 break;
612 }
613 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800614 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800615 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800616 a.initialize(appWidth, appHeight, appWidth, appHeight);
617 return a;
618 }
619
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700620 private void getDefaultNextAppTransitionStartRect(Rect rect) {
621 if (mDefaultNextAppTransitionAnimationSpec == null ||
622 mDefaultNextAppTransitionAnimationSpec.rect == null) {
623 Slog.wtf(TAG, "Starting rect for app requested, but none available", new Throwable());
624 rect.setEmpty();
625 } else {
626 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
627 }
628 }
629
630 void getNextAppTransitionStartRect(int taskId, Rect rect) {
631 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800632 if (spec == null) {
633 spec = mDefaultNextAppTransitionAnimationSpec;
634 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700635 if (spec == null || spec.rect == null) {
636 Slog.wtf(TAG, "Starting rect for task: " + taskId + " requested, but not available",
637 new Throwable());
638 rect.setEmpty();
639 } else {
640 rect.set(spec.rect);
641 }
642 }
643
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800644 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
645 Bitmap bitmap) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700646 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800647 bitmap, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700648 }
649
Jorim Jaggif97ed922016-02-18 18:57:07 -0800650 /**
651 * @return the duration of the last clip reveal animation
652 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800653 long getLastClipRevealTransitionDuration() {
654 return mLastClipRevealTransitionDuration;
655 }
656
657 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800658 * @return the maximum distance the app surface is traveling of the last clip reveal animation
659 */
660 int getLastClipRevealMaxTranslation() {
661 return mLastClipRevealMaxTranslation;
662 }
663
664 /**
665 * @return true if in the last app transition had a clip reveal animation, false otherwise
666 */
667 boolean hadClipRevealAnimation() {
668 return mLastHadClipReveal;
669 }
670
671 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800672 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
673 * the start rect is outside of the target rect, and there is a lot of movement going on.
674 *
675 * @param cutOff whether the start rect was not fully contained by the end rect
676 * @param translationX the total translation the surface moves in x direction
677 * @param translationY the total translation the surfaces moves in y direction
678 * @param displayFrame our display frame
679 *
680 * @return the duration of the clip reveal animation, in milliseconds
681 */
682 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
683 float translationY, Rect displayFrame) {
684 if (!cutOff) {
685 return DEFAULT_APP_TRANSITION_DURATION;
686 }
687 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
688 Math.abs(translationY) / displayFrame.height());
689 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
690 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
691 }
692
693 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
694 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800695 final Animation anim;
696 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700697 final int appWidth = appFrame.width();
698 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800699
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700700 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700701 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700702 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700703
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700704 float t = 0f;
705 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800706 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700707 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800708 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
709 int translationX = 0;
710 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700711 int centerX = mTmpRect.centerX();
712 int centerY = mTmpRect.centerY();
713 int halfWidth = mTmpRect.width() / 2;
714 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800715 int clipStartX = centerX - halfWidth - appFrame.left;
716 int clipStartY = centerY - halfHeight - appFrame.top;
717 boolean cutOff = false;
718
719 // If the starting rectangle is fully or partially outside of the target rectangle, we
720 // need to start the clipping at the edge and then achieve the rest with translation
721 // and extending the clip rect from that edge.
722 if (appFrame.top > centerY - halfHeight) {
723 translationY = (centerY - halfHeight) - appFrame.top;
724 translationYCorrection = 0;
725 clipStartY = 0;
726 cutOff = true;
727 }
728 if (appFrame.left > centerX - halfWidth) {
729 translationX = (centerX - halfWidth) - appFrame.left;
730 clipStartX = 0;
731 cutOff = true;
732 }
733 if (appFrame.right < centerX + halfWidth) {
734 translationX = (centerX + halfWidth) - appFrame.right;
735 clipStartX = appWidth - mTmpRect.width();
736 cutOff = true;
737 }
738 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
739 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700740
741 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800742 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800743 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700744 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800745 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700746
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800747 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
748 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
749 : mLinearOutSlowInInterpolator);
750 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800751
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800752 Animation clipAnimTB = new ClipRectTBAnimation(
753 clipStartY, clipStartY + mTmpRect.height(),
754 0, appHeight,
755 translationYCorrection, 0,
756 mLinearOutSlowInInterpolator);
757 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
758 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800759
760 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800761 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700762 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800763 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700764 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800765
766 AnimationSet set = new AnimationSet(false);
767 set.addAnimation(clipAnimLR);
768 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700769 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800770 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700771 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800772 set.initialize(appWidth, appHeight, appWidth, appHeight);
773 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800774 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800775 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800776
777 // If the start rect was full inside the target rect (cutOff == false), we don't need
778 // to store the translation, because it's only used if cutOff == true.
779 mLastClipRevealMaxTranslation = cutOff
780 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800781 } else {
782 final long duration;
783 switch (transit) {
784 case TRANSIT_ACTIVITY_OPEN:
785 case TRANSIT_ACTIVITY_CLOSE:
786 duration = mConfigShortAnimTime;
787 break;
788 default:
789 duration = DEFAULT_APP_TRANSITION_DURATION;
790 break;
791 }
792 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
793 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
794 // If we are on top of the wallpaper, we need an animation that
795 // correctly handles the wallpaper staying static behind all of
796 // the animated elements. To do this, will just have the existing
797 // element fade out.
798 anim = new AlphaAnimation(1, 0);
799 anim.setDetachWallpaper(true);
800 } else {
801 // For normal animations, the exiting element just holds in place.
802 anim = new AlphaAnimation(1, 1);
803 }
804 anim.setInterpolator(mDecelerateInterpolator);
805 anim.setDuration(duration);
806 anim.setFillAfter(true);
807 }
808 return anim;
809 }
810
Winson Chung399f6202014-03-19 10:47:20 -0700811 /**
812 * Prepares the specified animation with a standard duration, interpolator, etc.
813 */
Winson Chung5393dff2014-05-08 14:25:43 -0700814 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
815 int duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700816 if (duration > 0) {
817 a.setDuration(duration);
818 }
Winson Chung5393dff2014-05-08 14:25:43 -0700819 a.setFillAfter(true);
820 a.setInterpolator(interpolator);
821 a.initialize(appWidth, appHeight, appWidth, appHeight);
822 return a;
823 }
824
825 /**
826 * Prepares the specified animation with a standard duration, interpolator, etc.
827 */
Winson Chung399f6202014-03-19 10:47:20 -0700828 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800829 // Pick the desired duration. If this is an inter-activity transition,
830 // it is the standard duration for that. Otherwise we use the longer
831 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700832 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800833 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800834 case TRANSIT_ACTIVITY_OPEN:
835 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800836 duration = mConfigShortAnimTime;
837 break;
838 default:
839 duration = DEFAULT_APP_TRANSITION_DURATION;
840 break;
841 }
Winson Chung5393dff2014-05-08 14:25:43 -0700842 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
843 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800844 }
845
Winson Chung399f6202014-03-19 10:47:20 -0700846 /**
847 * Return the current thumbnail transition state.
848 */
849 int getThumbnailTransitionState(boolean enter) {
850 if (enter) {
851 if (mNextAppTransitionScaleUp) {
852 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
853 } else {
854 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
855 }
856 } else {
857 if (mNextAppTransitionScaleUp) {
858 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
859 } else {
860 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
861 }
862 }
863 }
864
865 /**
866 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700867 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700868 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700869 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, Bitmap thumbnailHeader,
870 final int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700871 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700872 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700873 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700874 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chung399f6202014-03-19 10:47:20 -0700875 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700876 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700877
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700878 float scaleW = appWidth / thumbWidth;
Winson Chunga4ccb862014-08-22 15:26:27 -0700879 float unscaledHeight = thumbHeight * scaleW;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700880 getNextAppTransitionStartRect(taskId, mTmpRect);
Filip Gruszczynski565a9df2016-01-22 11:10:42 -0800881 final float unscaledStartY = mTmpRect.top - (unscaledHeight - thumbHeight) / 2f;
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800882 final float toY = appRect.top + -unscaledStartY;
Winson Chung399f6202014-03-19 10:47:20 -0700883 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700884 // Animation up from the thumbnail to the full screen
885 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700886 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800887 scale.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700888 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800889 Animation alpha = new AlphaAnimation(1f, 0f);
Winson Chunga4ccb862014-08-22 15:26:27 -0700890 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
891 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700892 final float toX = appRect.left + appRect.width() / 2 -
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700893 (mTmpRect.left + thumbWidth / 2);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700894 Animation translate = new TranslateAnimation(0, toX, 0, toY);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800895 translate.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700896 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700897
898 // This AnimationSet uses the Interpolators assigned above.
899 AnimationSet set = new AnimationSet(false);
900 set.addAnimation(scale);
901 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -0700902 set.addAnimation(translate);
Winson Chung399f6202014-03-19 10:47:20 -0700903 a = set;
904 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700905 // Animation down from the full screen to the thumbnail
906 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700907 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800908 scale.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700909 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
910 Animation alpha = new AlphaAnimation(0f, 1f);
911 alpha.setInterpolator(mThumbnailFadeInInterpolator);
912 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
Filip Gruszczynski565a9df2016-01-22 11:10:42 -0800913 final float toX = appRect.left + appRect.width() / 2 -
914 (mTmpRect.left + thumbWidth / 2);
915 Animation translate = new TranslateAnimation(toX, 0, toY, 0);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800916 translate.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700917 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700918
Winson Chunga4ccb862014-08-22 15:26:27 -0700919 // This AnimationSet uses the Interpolators assigned above.
920 AnimationSet set = new AnimationSet(false);
921 set.addAnimation(scale);
922 set.addAnimation(alpha);
923 set.addAnimation(translate);
924 a = set;
925
926 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700927 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800928 TOUCH_RESPONSE_INTERPOLATOR);
Winson Chung399f6202014-03-19 10:47:20 -0700929 }
930
931 /**
932 * This alternate animation is created when we are doing a thumbnail transition, for the
933 * activity that is leaving, and the activity that is entering.
934 */
Winson Chunga4ccb862014-08-22 15:26:27 -0700935 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700936 int orientation, int transit, Rect containingFrame, Rect contentInsets,
937 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700938 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700939 final int appWidth = containingFrame.width();
940 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700941 getDefaultNextAppTransitionStartRect(mTmpRect);
942 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700943 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700944 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -0700945 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
946
Winson Chung2820c452014-04-15 15:34:44 -0700947 // Used for the ENTER_SCALE_UP and EXIT_SCALE_DOWN transitions
948 float scale = 1f;
949 int scaledTopDecor = 0;
950
Winson Chung399f6202014-03-19 10:47:20 -0700951 switch (thumbTransitState) {
952 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700953 if (freeform) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700954 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700955 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -0700956 } else {
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700957 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700958 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800959
960 // Containing frame is in screen space, but we need the clip rect in the
961 // app space.
962 mTmpFromClipRect.offsetTo(0, 0);
963 mTmpToClipRect.offsetTo(0, 0);
964
965 // Exclude insets region from the source clip.
966 mTmpFromClipRect.inset(contentInsets);
967
968 // We scale the width and clip to the top/left square
969 scale = thumbWidth / (appWidth - contentInsets.left - contentInsets.right);
970 scaledTopDecor = (int) (scale * contentInsets.top);
971 int unscaledThumbHeight = (int) (thumbHeight / scale);
972 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700973
974 mNextAppTransitionInsets.set(contentInsets);
975
976 Animation scaleAnim = new ScaleAnimation(scale, 1, scale, 1,
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800977 computePivot(mTmpRect.left - containingFrame.left, scale),
978 computePivot(mTmpRect.top - containingFrame.top, scale));
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700979 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
980 Animation translateAnim = new TranslateAnimation(0, 0, -scaledTopDecor, 0);
981
982 AnimationSet set = new AnimationSet(true);
983 set.addAnimation(clipAnim);
984 set.addAnimation(scaleAnim);
985 set.addAnimation(translateAnim);
986 a = set;
Winson Chung2820c452014-04-15 15:34:44 -0700987 }
Winson Chung399f6202014-03-19 10:47:20 -0700988 break;
989 }
990 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700991 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -0700992 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700993 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -0700994 // activity.
995 a = new AlphaAnimation(1, 0);
996 } else {
Winson Chung399f6202014-03-19 10:47:20 -0700997 a = new AlphaAnimation(1, 1);
998 }
999 break;
1000 }
1001 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001002 // Target app window during the scale down
1003 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1004 // Fade in the destination activity if we are animating from a wallpaper
1005 // activity.
1006 a = new AlphaAnimation(0, 1);
1007 } else {
1008 a = new AlphaAnimation(1, 1);
1009 }
Winson Chung399f6202014-03-19 10:47:20 -07001010 break;
1011 }
1012 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001013 // App window scaling down from full screen
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001014 if (freeform) {
1015 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1016 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001017 } else {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001018 mTmpFromClipRect.set(containingFrame);
1019 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001020
1021 // Containing frame is in screen space, but we need the clip rect in the
1022 // app space.
1023 mTmpFromClipRect.offsetTo(0, 0);
1024 mTmpToClipRect.offsetTo(0, 0);
1025
1026 // Exclude insets region from the target clip.
1027 mTmpToClipRect.inset(contentInsets);
1028
1029 // We scale the width and clip to the top/left square
1030 scale = thumbWidth / (appWidth - contentInsets.left - contentInsets.right);
1031 scaledTopDecor = (int) (scale * contentInsets.top);
1032 int unscaledThumbHeight = (int) (thumbHeight / scale);
1033 mTmpToClipRect.bottom = mTmpToClipRect.top + unscaledThumbHeight;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001034
1035 mNextAppTransitionInsets.set(contentInsets);
1036
1037 Animation scaleAnim = new ScaleAnimation(1, scale, 1, scale,
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001038 computePivot(mTmpRect.left - containingFrame.left, scale),
1039 computePivot(mTmpRect.top - containingFrame.top, scale));
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001040 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
1041 Animation translateAnim = new TranslateAnimation(0, 0, 0, -scaledTopDecor);
1042
1043 AnimationSet set = new AnimationSet(true);
1044 set.addAnimation(clipAnim);
1045 set.addAnimation(scaleAnim);
1046 set.addAnimation(translateAnim);
1047
1048 a = set;
1049 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001050 }
Winson Chung399f6202014-03-19 10:47:20 -07001051 break;
1052 }
1053 default:
1054 throw new RuntimeException("Invalid thumbnail transition state");
1055 }
1056
Winson Chungab79fce2014-11-04 16:15:22 -08001057 int duration = Math.max(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION,
1058 THUMBNAIL_APP_TRANSITION_DURATION);
1059 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001060 TOUCH_RESPONSE_INTERPOLATOR);
Winson Chung399f6202014-03-19 10:47:20 -07001061 }
1062
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001063 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1064 @Nullable Rect surfaceInsets, int taskId) {
1065 getNextAppTransitionStartRect(taskId, mTmpRect);
1066 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1067 true);
1068 }
1069
1070 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1071 @Nullable Rect surfaceInsets, int taskId) {
1072 getNextAppTransitionStartRect(taskId, mTmpRect);
1073 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1074 false);
1075 }
1076
1077 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1078 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1079 final float sourceWidth = sourceFrame.width();
1080 final float sourceHeight = sourceFrame.height();
1081 final float destWidth = destFrame.width();
1082 final float destHeight = destFrame.height();
1083 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1084 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001085 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001086 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001087 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001088 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001089 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1090 // We want the scaling to happen from the center of the surface. In order to achieve that,
1091 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001092 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1093 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1094 final ScaleAnimation scale = enter ?
1095 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1096 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1097 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1098 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1099 final int destHCenter = destFrame.left + destFrame.width() / 2;
1100 final int destVCenter = destFrame.top + destFrame.height() / 2;
1101 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1102 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1103 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1104 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001105 set.addAnimation(scale);
1106 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001107
1108 final IRemoteCallback callback = mAnimationFinishedCallback;
1109 if (callback != null) {
1110 set.setAnimationListener(new Animation.AnimationListener() {
1111 @Override
1112 public void onAnimationStart(Animation animation) { }
1113
1114 @Override
1115 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001116 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001117 }
1118
1119 @Override
1120 public void onAnimationRepeat(Animation animation) { }
1121 });
1122 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001123 return set;
1124 }
1125
Winson Chung399f6202014-03-19 10:47:20 -07001126 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001127 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001128 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001129 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001130 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
1131 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001132 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001133 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001134 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001135 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001136 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001137 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1138
1139 if (mNextAppTransitionScaleUp) {
1140 // Animation for the thumbnail zooming from its initial size to the full screen
1141 float scaleW = appWidth / thumbWidth;
1142 float scaleH = appHeight / thumbHeight;
1143 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001144 computePivot(mTmpRect.left, 1 / scaleW),
1145 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001146 scale.setInterpolator(mDecelerateInterpolator);
1147
1148 Animation alpha = new AlphaAnimation(1, 0);
1149 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1150
1151 // This AnimationSet uses the Interpolators assigned above.
1152 AnimationSet set = new AnimationSet(false);
1153 set.addAnimation(scale);
1154 set.addAnimation(alpha);
1155 a = set;
1156 } else {
1157 // Animation for the thumbnail zooming down from the full screen to its final size
1158 float scaleW = appWidth / thumbWidth;
1159 float scaleH = appHeight / thumbHeight;
1160 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001161 computePivot(mTmpRect.left, 1 / scaleW),
1162 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001163 }
1164
1165 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1166 }
1167
1168 /**
Winson Chung399f6202014-03-19 10:47:20 -07001169 * This animation is created when we are doing a thumbnail transition, for the activity that is
1170 * leaving, and the activity that is entering.
1171 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001172 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1173 int transit, int taskId) {
1174 final int appWidth = containingFrame.width();
1175 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001176 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001177 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001178 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001179 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001180 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001181 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001182 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1183
1184 switch (thumbTransitState) {
1185 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1186 // Entering app scales up with the thumbnail
1187 float scaleW = thumbWidth / appWidth;
1188 float scaleH = thumbHeight / appHeight;
1189 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001190 computePivot(mTmpRect.left, scaleW),
1191 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001192 break;
1193 }
1194 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1195 // Exiting app while the thumbnail is scaling up should fade or stay in place
1196 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1197 // Fade out while bringing up selected activity. This keeps the
1198 // current activity from showing through a launching wallpaper
1199 // activity.
1200 a = new AlphaAnimation(1, 0);
1201 } else {
1202 // noop animation
1203 a = new AlphaAnimation(1, 1);
1204 }
1205 break;
1206 }
1207 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1208 // Entering the other app, it should just be visible while we scale the thumbnail
1209 // down above it
1210 a = new AlphaAnimation(1, 1);
1211 break;
1212 }
1213 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1214 // Exiting the current app, the app should scale down with the thumbnail
1215 float scaleW = thumbWidth / appWidth;
1216 float scaleH = thumbHeight / appHeight;
1217 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001218 computePivot(mTmpRect.left, scaleW),
1219 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001220
1221 Animation alpha = new AlphaAnimation(1, 0);
1222
1223 AnimationSet set = new AnimationSet(true);
1224 set.addAnimation(scale);
1225 set.addAnimation(alpha);
1226 set.setZAdjustment(Animation.ZORDER_TOP);
1227 a = set;
1228 break;
1229 }
1230 default:
1231 throw new RuntimeException("Invalid thumbnail transition state");
1232 }
1233
1234 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1235 }
1236
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001237 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001238 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1239 final int left = mTmpFromClipRect.left;
1240 final int top = mTmpFromClipRect.top;
1241 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001242 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1243 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001244 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001245 float fromWidth = mTmpFromClipRect.width();
1246 float toWidth = mTmpToClipRect.width();
1247 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001248 // While the window might span the whole display, the actual content will be cropped to the
1249 // system decoration frame, for example when the window is docked. We need to take into
1250 // account the visible height when constructing the animation.
1251 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1252 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001253 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1254 // The final window is larger in both dimensions than current window (e.g. we are
1255 // maximizing), so we can simply unclip the new window and there will be no disappearing
1256 // frame.
1257 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1258 } else {
1259 // The disappearing window has one larger dimension. We need to apply scaling, so the
1260 // first frame of the entry animation matches the old window.
1261 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001262 // We might not be going exactly full screen, but instead be aligned under the status
1263 // bar using cropping. We still need to account for the cropped part, which will also
1264 // be scaled.
1265 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001266 }
1267
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001268 // We animate the translation from the old position of the removed window, to the new
1269 // position of the added window. The latter might not be full screen, for example docked for
1270 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001271 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001272 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001273 set.addAnimation(translate);
1274 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001275 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001276 return set;
1277 }
1278
Jorim Jaggic554b772015-06-04 16:07:57 -07001279 /**
1280 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1281 * frame of the transition doesn't change the visuals on screen, so we can start
1282 * directly with the second one
1283 */
1284 boolean canSkipFirstFrame() {
1285 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1286 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
1287 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1288 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001289
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001290 /**
1291 *
1292 * @param frame These are the bounds of the window when it finishes the animation. This is where
1293 * the animation must usually finish in entrance animation, as the next frame will
1294 * display the window at these coordinates. In case of exit animation, this is
1295 * where the animation must start, as the frame before the animation is displaying
1296 * the window at these bounds.
1297 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1298 * window might be obscured, usually by the system windows (status bar and
1299 * navigation bar) and we use content insets to convey that information. This
1300 * usually affects the animation aspects vertically, as the system decoration is
1301 * at the top and the bottom. For example when we animate from full screen to
1302 * recents, we want to exclude the covered parts, because they won't match the
1303 * thumbnail after the last frame is executed.
1304 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1305 * know about this to make the animation frames match. We currently use
1306 * this for freeform windows, which have larger surfaces to display
1307 * shadows. When we animate them from recents, we want to match the content
1308 * to the recents thumbnail and hence need to account for the surface being
1309 * bigger.
1310 */
Craig Mautner164d4bb2012-11-26 13:51:23 -08001311 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001312 int orientation, Rect frame, Rect displayFrame, Rect insets,
1313 @Nullable Rect surfaceInsets, boolean isVoiceInteraction, boolean freeform,
1314 int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001315 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001316 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
1317 || transit == TRANSIT_TASK_OPEN
1318 || transit == TRANSIT_TASK_TO_FRONT)) {
1319 a = loadAnimationRes(lp, enter
1320 ? com.android.internal.R.anim.voice_activity_open_enter
1321 : com.android.internal.R.anim.voice_activity_open_exit);
1322 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1323 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001324 + " anim=" + a + " transit=" + appTransitionToString(transit)
1325 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001326 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1327 || transit == TRANSIT_TASK_CLOSE
1328 || transit == TRANSIT_TASK_TO_BACK)) {
1329 a = loadAnimationRes(lp, enter
1330 ? com.android.internal.R.anim.voice_activity_close_enter
1331 : com.android.internal.R.anim.voice_activity_close_exit);
1332 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1333 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001334 + " anim=" + a + " transit=" + appTransitionToString(transit)
1335 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001336 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001337 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001338 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1339 "applyAnimation:"
1340 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1341 + " transit=" + appTransitionToString(transit)
1342 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001343 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1344 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001345 mNextAppTransitionEnter : mNextAppTransitionExit);
1346 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1347 "applyAnimation:"
1348 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001349 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001350 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001351 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1352 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1353 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1354 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001355 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1356 + " transit=" + appTransitionToString(transit)
1357 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001358 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001359 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001360 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1361 "applyAnimation:"
1362 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001363 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001364 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001365 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001366 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001367 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1368 "applyAnimation:"
1369 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001370 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001371 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001372 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1373 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001374 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001375 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001376 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001377 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001378 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1379 String animName = mNextAppTransitionScaleUp ?
1380 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1381 Slog.v(TAG, "applyAnimation:"
1382 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001383 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001384 + " Callers=" + Debug.getCallers(3));
1385 }
1386 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1387 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1388 mNextAppTransitionScaleUp =
1389 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1390 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001391 getThumbnailTransitionState(enter), orientation, transit, frame,
1392 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001393 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1394 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001395 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001396 Slog.v(TAG, "applyAnimation:"
1397 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001398 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001399 + " Callers=" + Debug.getCallers(3));
1400 }
1401 } else {
1402 int animAttr = 0;
1403 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001404 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001405 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001406 ? WindowAnimation_activityOpenEnterAnimation
1407 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001408 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001409 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001410 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001411 ? WindowAnimation_activityCloseEnterAnimation
1412 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001413 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001414 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001415 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001416 ? WindowAnimation_taskOpenEnterAnimation
1417 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001418 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001419 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001420 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001421 ? WindowAnimation_taskCloseEnterAnimation
1422 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001423 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001424 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001425 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001426 ? WindowAnimation_taskToFrontEnterAnimation
1427 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001428 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001429 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001430 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001431 ? WindowAnimation_taskToBackEnterAnimation
1432 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001433 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001434 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001435 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001436 ? WindowAnimation_wallpaperOpenEnterAnimation
1437 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001438 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001439 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001440 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001441 ? WindowAnimation_wallpaperCloseEnterAnimation
1442 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001443 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001444 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001445 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001446 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1447 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001448 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001449 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001450 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001451 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1452 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001453 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001454 case TRANSIT_TASK_OPEN_BEHIND:
1455 animAttr = enter
1456 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001457 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001458 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001459 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001460 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1461 "applyAnimation:"
1462 + " anim=" + a
1463 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001464 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001465 + " Callers=" + Debug.getCallers(3));
1466 }
1467 return a;
1468 }
1469
1470 void postAnimationCallback() {
1471 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001472 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1473 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001474 mNextAppTransitionCallback = null;
1475 }
1476 }
1477
1478 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001479 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001480 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001481 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001482 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001483 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001484 mNextAppTransitionEnter = enterAnim;
1485 mNextAppTransitionExit = exitAnim;
1486 postAnimationCallback();
1487 mNextAppTransitionCallback = startedCallback;
1488 } else {
1489 postAnimationCallback();
1490 }
1491 }
1492
1493 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001494 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001495 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001496 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001497 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001498 putDefaultNextAppTransitionCoordinates(startX, startY, startX + startWidth,
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001499 startY + startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001500 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001501 }
1502 }
1503
Chet Haase10e23ab2015-02-11 15:08:38 -08001504 void overridePendingAppTransitionClipReveal(int startX, int startY,
1505 int startWidth, int startHeight) {
1506 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001507 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001508 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001509 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001510 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001511 }
1512 }
1513
Craig Mautner164d4bb2012-11-26 13:51:23 -08001514 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1515 IRemoteCallback startedCallback, boolean scaleUp) {
1516 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001517 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001518 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1519 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001520 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001521 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001522 postAnimationCallback();
1523 mNextAppTransitionCallback = startedCallback;
1524 } else {
1525 postAnimationCallback();
1526 }
1527 }
1528
Winson Chunga4ccb862014-08-22 15:26:27 -07001529 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001530 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001531 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001532 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001533 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1534 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001535 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001536 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1537 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001538 postAnimationCallback();
1539 mNextAppTransitionCallback = startedCallback;
1540 } else {
1541 postAnimationCallback();
1542 }
1543 }
1544
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001545 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001546 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1547 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001548 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001549 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001550 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1551 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001552 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001553 if (specs != null) {
1554 for (int i = 0; i < specs.length; i++) {
1555 AppTransitionAnimationSpec spec = specs[i];
1556 if (spec != null) {
1557 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1558 if (i == 0) {
1559 // In full screen mode, the transition code depends on the default spec
1560 // to be set.
1561 Rect rect = spec.rect;
1562 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Filip Gruszczynskie3264d82015-11-20 17:10:04 -08001563 rect.width(), rect.height(), spec.bitmap);
Jorim Jaggi43102412015-11-11 16:28:37 +01001564 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001565 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001566 }
1567 }
1568 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001569 mNextAppTransitionCallback = onAnimationStartedCallback;
1570 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001571 } else {
1572 postAnimationCallback();
1573 }
1574 }
1575
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001576 void overridePendingAppTransitionMultiThumbFuture(
1577 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1578 boolean scaleUp) {
1579 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001580 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001581 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1582 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001583 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1584 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001585 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001586 }
1587 }
1588
Winson Chung044d5292014-11-06 11:05:19 -08001589 void overrideInPlaceAppTransition(String packageName, int anim) {
1590 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001591 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001592 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1593 mNextAppTransitionPackage = packageName;
1594 mNextAppTransitionInPlace = anim;
1595 } else {
1596 postAnimationCallback();
1597 }
1598 }
1599
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001600 /**
1601 * If a future is set for the app transition specs, fetch it in another thread.
1602 */
1603 private void fetchAppTransitionSpecsFromFuture() {
1604 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1605 mNextAppTransitionAnimationsSpecsPending = true;
1606 final IAppTransitionAnimationSpecsFuture future
1607 = mNextAppTransitionAnimationsSpecsFuture;
1608 mNextAppTransitionAnimationsSpecsFuture = null;
1609 mDefaultExecutor.execute(new Runnable() {
1610 @Override
1611 public void run() {
1612 AppTransitionAnimationSpec[] specs = null;
1613 try {
1614 specs = future.get();
1615 } catch (RemoteException e) {
1616 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1617 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001618 synchronized (mService.mWindowMap) {
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001619 mNextAppTransitionAnimationsSpecsPending = false;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001620 overridePendingAppTransitionMultiThumb(specs,
1621 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1622 mNextAppTransitionScaleUp);
1623 mNextAppTransitionFutureCallback = null;
Filip Gruszczynski96daf322015-11-18 18:01:27 -08001624 if (specs != null) {
1625 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1626 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001627 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001628 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001629 }
1630 });
1631 }
1632 }
1633
Craig Mautner164d4bb2012-11-26 13:51:23 -08001634 @Override
1635 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001636 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001637 }
1638
Craig Mautner4b71aa12012-12-27 17:20:01 -08001639 /**
1640 * Returns the human readable name of a window transition.
1641 *
1642 * @param transition The window transition.
1643 * @return The transition symbolic name.
1644 */
1645 public static String appTransitionToString(int transition) {
1646 switch (transition) {
1647 case TRANSIT_UNSET: {
1648 return "TRANSIT_UNSET";
1649 }
1650 case TRANSIT_NONE: {
1651 return "TRANSIT_NONE";
1652 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001653 case TRANSIT_ACTIVITY_OPEN: {
1654 return "TRANSIT_ACTIVITY_OPEN";
1655 }
1656 case TRANSIT_ACTIVITY_CLOSE: {
1657 return "TRANSIT_ACTIVITY_CLOSE";
1658 }
1659 case TRANSIT_TASK_OPEN: {
1660 return "TRANSIT_TASK_OPEN";
1661 }
1662 case TRANSIT_TASK_CLOSE: {
1663 return "TRANSIT_TASK_CLOSE";
1664 }
1665 case TRANSIT_TASK_TO_FRONT: {
1666 return "TRANSIT_TASK_TO_FRONT";
1667 }
1668 case TRANSIT_TASK_TO_BACK: {
1669 return "TRANSIT_TASK_TO_BACK";
1670 }
1671 case TRANSIT_WALLPAPER_CLOSE: {
1672 return "TRANSIT_WALLPAPER_CLOSE";
1673 }
1674 case TRANSIT_WALLPAPER_OPEN: {
1675 return "TRANSIT_WALLPAPER_OPEN";
1676 }
1677 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1678 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1679 }
1680 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1681 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1682 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001683 case TRANSIT_TASK_OPEN_BEHIND: {
1684 return "TRANSIT_TASK_OPEN_BEHIND";
1685 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001686 case TRANSIT_ACTIVITY_RELAUNCH: {
1687 return "TRANSIT_ACTIVITY_RELAUNCH";
1688 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001689 default: {
1690 return "<UNKNOWN>";
1691 }
1692 }
1693 }
1694
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001695 private String appStateToString() {
1696 switch (mAppTransitionState) {
1697 case APP_STATE_IDLE:
1698 return "APP_STATE_IDLE";
1699 case APP_STATE_READY:
1700 return "APP_STATE_READY";
1701 case APP_STATE_RUNNING:
1702 return "APP_STATE_RUNNING";
1703 case APP_STATE_TIMEOUT:
1704 return "APP_STATE_TIMEOUT";
1705 default:
1706 return "unknown state=" + mAppTransitionState;
1707 }
1708 }
1709
1710 private String transitTypeToString() {
1711 switch (mNextAppTransitionType) {
1712 case NEXT_TRANSIT_TYPE_NONE:
1713 return "NEXT_TRANSIT_TYPE_NONE";
1714 case NEXT_TRANSIT_TYPE_CUSTOM:
1715 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001716 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1717 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001718 case NEXT_TRANSIT_TYPE_SCALE_UP:
1719 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1720 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1721 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1722 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1723 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001724 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1725 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1726 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1727 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001728 default:
1729 return "unknown type=" + mNextAppTransitionType;
1730 }
1731 }
1732
Craig Mautner164d4bb2012-11-26 13:51:23 -08001733 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001734 public void dump(PrintWriter pw, String prefix) {
1735 pw.print(prefix); pw.println(this);
1736 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001737 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001738 pw.print(prefix); pw.print("mNextAppTransitionType=");
1739 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001740 }
1741 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001742 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001743 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001744 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001745 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001746 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1747 pw.print(" mNextAppTransitionExit=0x");
1748 pw.println(Integer.toHexString(mNextAppTransitionExit));
1749 break;
Winson Chung044d5292014-11-06 11:05:19 -08001750 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001751 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001752 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001753 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001754 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1755 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001756 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001757 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001758 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001759 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001760 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001761 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001762 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001763 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001764 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001765 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001766 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001767 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001768 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1769 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001770 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001771 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1772 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1773 pw.println(mDefaultNextAppTransitionAnimationSpec);
1774 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1775 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001776 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1777 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001778 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001779 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001780 }
1781 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001782 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1783 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001784 }
1785 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001786
1787 public void setCurrentUser(int newUserId) {
1788 mCurrentUserId = newUserId;
1789 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001790
1791 /**
1792 * @return true if transition is not running and should not be skipped, false if transition is
1793 * already running
1794 */
1795 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent) {
1796 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
1797 + " transit=" + appTransitionToString(transit)
1798 + " " + this
1799 + " alwaysKeepCurrent=" + alwaysKeepCurrent
1800 + " Callers=" + Debug.getCallers(3));
1801 if (!isTransitionSet() || mNextAppTransition == TRANSIT_NONE) {
1802 setAppTransition(transit);
1803 } else if (!alwaysKeepCurrent) {
1804 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
1805 // Opening a new task always supersedes a close for the anim.
1806 setAppTransition(transit);
1807 } else if (transit == TRANSIT_ACTIVITY_OPEN
1808 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
1809 // Opening a new activity always supersedes a close for the anim.
1810 setAppTransition(transit);
1811 }
1812 }
1813 boolean prepared = prepare();
1814 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001815 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
1816 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001817 }
1818 return prepared;
1819 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001820}