blob: 1a8b1f7efd6a04a038bd291b3155fac1ff49e7e3 [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;
Winson21700932016-03-24 17:26:23 -070049import android.content.res.Configuration;
Craig Mautner164d4bb2012-11-26 13:51:23 -080050import android.graphics.Bitmap;
Winson Chung399f6202014-03-19 10:47:20 -070051import android.graphics.Rect;
Craig Mautner164d4bb2012-11-26 13:51:23 -080052import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010053import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080054import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010055import android.os.RemoteException;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080056import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080057import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070058import android.util.SparseArray;
59import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010060import android.view.IAppTransitionAnimationSpecsFuture;
Craig Mautner164d4bb2012-11-26 13:51:23 -080061import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080062import android.view.animation.AlphaAnimation;
63import android.view.animation.Animation;
64import android.view.animation.AnimationSet;
65import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070066import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080067import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070068import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080069import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070070import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070071
Craig Mautner164d4bb2012-11-26 13:51:23 -080072import com.android.internal.util.DumpUtils.Dump;
73import com.android.server.AttributeCache;
74import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -080075import com.android.server.wm.animation.ClipRectLRAnimation;
76import com.android.server.wm.animation.ClipRectTBAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080077
78import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010079import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010080import java.util.concurrent.ExecutorService;
81import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -080082
Craig Mautner164d4bb2012-11-26 13:51:23 -080083// State management of app transitions. When we are preparing for a
84// transition, mNextAppTransition will be the kind of transition to
85// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
86// mOpeningApps and mClosingApps are the lists of tokens that will be
87// made visible or hidden at the next transition.
88public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080089 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070090 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080091
Craig Mautner4b71aa12012-12-27 17:20:01 -080092 /** Not set up for a transition. */
93 public static final int TRANSIT_UNSET = -1;
94 /** No animation for transition. */
95 public static final int TRANSIT_NONE = 0;
96 /** 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 -070097 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -080098 /** The window in the top-most activity is being closed to reveal the
99 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700100 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800101 /** A window in a new task is being opened on top of an existing one
102 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700103 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800104 /** A window in the top-most activity is being closed to reveal the
105 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700106 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800107 /** A window in an existing task is being displayed on top of an existing one
108 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700109 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800110 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700111 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800112 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
113 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700114 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800115 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
116 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700117 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800118 /** A window in a new activity is being opened on top of an existing one, and both are on top
119 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700120 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800121 /** The window in the top-most activity is being closed to reveal the previous activity, and
122 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700123 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
124 /** A window in a new task is being opened behind an existing one in another activity's task.
125 * The new window will show briefly and then be gone. */
126 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800127 /** A window in a task is being animated in-place. */
128 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700129 /** An activity is being relaunched (e.g. due to configuration change). */
130 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800131
Winson Chunga4ccb862014-08-22 15:26:27 -0700132 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700133 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800134 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700135 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800136
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800137 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800138
139 /** Interpolator to be used for animations that respond directly to a touch */
140 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
141 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
142
143 /**
144 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
145 * involved, to make it more understandable.
146 */
147 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700148 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
149 private static final int THUMBNAIL_APP_TRANSITION_ALPHA_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700150 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800151
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800152 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800153 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800154
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800155 private int mNextAppTransition = TRANSIT_UNSET;
156
157 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
158 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
159 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
160 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
161 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700162 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
163 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800164 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800165 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800166 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
167
Winson Chung399f6202014-03-19 10:47:20 -0700168 // These are the possible states for the enter/exit activities during a thumbnail transition
169 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
170 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
171 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
172 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
173
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800174 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800175 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800176 private boolean mNextAppTransitionScaleUp;
177 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100178 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700179 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800180 private int mNextAppTransitionEnter;
181 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800182 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700183
184 // Keyed by task id.
185 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
186 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100187 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
188 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700189 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
190
Winson Chunga4ccb862014-08-22 15:26:27 -0700191 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800192
Winson Chung2820c452014-04-15 15:34:44 -0700193 private Rect mTmpFromClipRect = new Rect();
194 private Rect mTmpToClipRect = new Rect();
195
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700196 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700197
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800198 private final static int APP_STATE_IDLE = 0;
199 private final static int APP_STATE_READY = 1;
200 private final static int APP_STATE_RUNNING = 2;
201 private final static int APP_STATE_TIMEOUT = 3;
202 private int mAppTransitionState = APP_STATE_IDLE;
203
204 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800205 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700206 private final Interpolator mThumbnailFadeInInterpolator;
207 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800208 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700209 private final Interpolator mFastOutLinearInInterpolator;
210 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
211
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700212 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800213
Amith Yamasani4befbec2013-07-10 16:18:01 -0700214 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800215 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700216
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100217 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100218 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100219
Jorim Jaggif97ed922016-02-18 18:57:07 -0800220 private int mLastClipRevealMaxTranslation;
221 private boolean mLastHadClipReveal;
222
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800223 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800224 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800225 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800226 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
227 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700228 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
229 com.android.internal.R.interpolator.fast_out_linear_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800230 mConfigShortAnimTime = context.getResources().getInteger(
231 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800232 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
233 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700234 mThumbnailFadeInInterpolator = new Interpolator() {
235 @Override
236 public float getInterpolation(float input) {
237 // Linear response for first fraction, then complete after that.
238 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
239 return 0f;
240 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700241 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700242 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700243 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700244 }
245 };
246 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800247 @Override
248 public float getInterpolation(float input) {
249 // Linear response for first fraction, then complete after that.
250 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700251 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
252 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800253 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700254 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800255 }
256 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700257 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
258 * mContext.getResources().getDisplayMetrics().density);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800259 }
260
261 boolean isTransitionSet() {
262 return mNextAppTransition != TRANSIT_UNSET;
263 }
264
Craig Mautner164d4bb2012-11-26 13:51:23 -0800265 boolean isTransitionEqual(int transit) {
266 return mNextAppTransition == transit;
267 }
268
269 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800270 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800271 }
272
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700273 private void setAppTransition(int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800274 mNextAppTransition = transit;
275 }
276
277 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800278 return mAppTransitionState == APP_STATE_READY
279 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800280 }
281
Craig Mautnerae446592012-12-06 19:05:05 -0800282 void setReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800283 mAppTransitionState = APP_STATE_READY;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100284 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800285 }
286
287 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800288 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800289 }
290
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800291 void setIdle() {
292 mAppTransitionState = APP_STATE_IDLE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800293 }
294
295 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800296 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800297 }
298
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800299 void setTimeout() {
300 mAppTransitionState = APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800301 }
302
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700303 Bitmap getAppTransitionThumbnailHeader(int taskId) {
304 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800305 if (spec == null) {
306 spec = mDefaultNextAppTransitionAnimationSpec;
307 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700308 return spec != null ? spec.bitmap : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800309 }
310
Winson Chunga4ccb862014-08-22 15:26:27 -0700311 /** Returns whether the next thumbnail transition is aspect scaled up. */
312 boolean isNextThumbnailTransitionAspectScaled() {
313 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
314 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
315 }
316
317 /** Returns whether the next thumbnail transition is scaling up. */
318 boolean isNextThumbnailTransitionScaleUp() {
319 return mNextAppTransitionScaleUp;
320 }
321
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800322 boolean isNextAppTransitionThumbnailUp() {
323 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
324 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
325 }
326
327 boolean isNextAppTransitionThumbnailDown() {
328 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
329 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
330 }
331
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100332 /**
333 * @return true if and only if we are currently fetching app transition specs from the future
334 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
335 */
336 boolean isFetchingAppTransitionsSpecs() {
337 return mNextAppTransitionAnimationsSpecsPending;
338 }
339
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700340 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800341 if (!isRunning()) {
342 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100343 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800344 mLastHadClipReveal = false;
345 mLastClipRevealMaxTranslation = 0;
346 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700347 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800348 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700349 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800350 }
351
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800352 void goodToGo(AppWindowAnimator topOpeningAppAnimator, AppWindowAnimator topClosingAppAnimator,
353 ArraySet<AppWindowToken> openingApps, ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800354 mNextAppTransition = TRANSIT_UNSET;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800355 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100356 notifyAppTransitionStartingLocked(
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800357 topOpeningAppAnimator != null ? topOpeningAppAnimator.mAppToken.token : null,
358 topClosingAppAnimator != null ? topClosingAppAnimator.mAppToken.token : null,
359 topOpeningAppAnimator != null ? topOpeningAppAnimator.animation : null,
360 topClosingAppAnimator != null ? topClosingAppAnimator.animation : null);
361 mService.getDefaultDisplayContentLocked().getDockedDividerController()
362 .notifyAppTransitionStarting(openingApps, closingApps);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800363 }
364
365 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800366 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800367 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700368 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi65193992015-11-23 16:49:59 -0800369 mNextAppTransitionAnimationsSpecsFuture = null;
370 mDefaultNextAppTransitionAnimationSpec = null;
371 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800372 }
373
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800374 void freeze() {
375 setAppTransition(AppTransition.TRANSIT_UNSET);
376 clear();
377 setReady();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100378 notifyAppTransitionCancelledLocked();
379 }
380
381 void registerListenerLocked(AppTransitionListener listener) {
382 mListeners.add(listener);
383 }
384
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700385 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100386 for (int i = 0; i < mListeners.size(); i++) {
387 mListeners.get(i).onAppTransitionFinishedLocked(token);
388 }
389 }
390
391 private void notifyAppTransitionPendingLocked() {
392 for (int i = 0; i < mListeners.size(); i++) {
393 mListeners.get(i).onAppTransitionPendingLocked();
394 }
395 }
396
397 private void notifyAppTransitionCancelledLocked() {
398 for (int i = 0; i < mListeners.size(); i++) {
399 mListeners.get(i).onAppTransitionCancelledLocked();
400 }
401 }
402
403 private void notifyAppTransitionStartingLocked(IBinder openToken,
404 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
405 for (int i = 0; i < mListeners.size(); i++) {
406 mListeners.get(i).onAppTransitionStartingLocked(openToken, closeToken, openAnimation,
407 closeAnimation);
408 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800409 }
410
Craig Mautner164d4bb2012-11-26 13:51:23 -0800411 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
412 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
413 + (lp != null ? lp.packageName : null)
414 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
415 if (lp != null && lp.windowAnimations != 0) {
416 // If this is a system resource, don't try to load it from the
417 // application resources. It is nice to avoid loading application
418 // resources if we can.
419 String packageName = lp.packageName != null ? lp.packageName : "android";
420 int resId = lp.windowAnimations;
421 if ((resId&0xFF000000) == 0x01000000) {
422 packageName = "android";
423 }
424 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
425 + packageName);
426 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700427 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800428 }
429 return null;
430 }
431
432 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
433 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
434 + packageName + " resId=0x" + Integer.toHexString(resId));
435 if (packageName != null) {
436 if ((resId&0xFF000000) == 0x01000000) {
437 packageName = "android";
438 }
439 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
440 + packageName);
441 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700442 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800443 }
444 return null;
445 }
446
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700447 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800448 int anim = 0;
449 Context context = mContext;
450 if (animAttr >= 0) {
451 AttributeCache.Entry ent = getCachedAnimations(lp);
452 if (ent != null) {
453 context = ent.context;
454 anim = ent.array.getResourceId(animAttr, 0);
455 }
456 }
457 if (anim != 0) {
458 return AnimationUtils.loadAnimation(context, anim);
459 }
460 return null;
461 }
462
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700463 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
464 Context context = mContext;
465 if (resId >= 0) {
466 AttributeCache.Entry ent = getCachedAnimations(lp);
467 if (ent != null) {
468 context = ent.context;
469 }
470 return AnimationUtils.loadAnimation(context, resId);
471 }
472 return null;
473 }
474
475 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800476 int anim = 0;
477 Context context = mContext;
478 if (resId >= 0) {
479 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
480 if (ent != null) {
481 context = ent.context;
482 anim = resId;
483 }
484 }
485 if (anim != 0) {
486 return AnimationUtils.loadAnimation(context, anim);
487 }
488 return null;
489 }
490
Craig Mautner164d4bb2012-11-26 13:51:23 -0800491 /**
492 * Compute the pivot point for an animation that is scaling from a small
493 * rect on screen to a larger rect. The pivot point varies depending on
494 * the distance between the inner and outer edges on both sides. This
495 * function computes the pivot point for one dimension.
496 * @param startPos Offset from left/top edge of outer rectangle to
497 * left/top edge of inner rectangle.
498 * @param finalScale The scaling factor between the size of the outer
499 * and inner rectangles.
500 */
501 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800502
503 /*
504 Theorem of intercepting lines:
505
506 + + +-----------------------------------------------+
507 | | | |
508 | | | |
509 | | | |
510 | | | |
511 x | y | | |
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 + ++
553 p ++
554
555 scale = (x - y) / x
556 <=> x = -y / (scale - 1)
557 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800558 final float denom = finalScale-1;
559 if (Math.abs(denom) < .0001f) {
560 return startPos;
561 }
562 return -startPos / denom;
563 }
564
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700565 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
566 Rect containingFrame) {
567 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700568 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700569 final int appWidth = containingFrame.width();
570 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800571 if (enter) {
572 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700573 float scaleW = mTmpRect.width() / (float) appWidth;
574 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800575 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700576 computePivot(mTmpRect.left, scaleW),
577 computePivot(mTmpRect.right, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800578 scale.setInterpolator(mDecelerateInterpolator);
579
Craig Mautner164d4bb2012-11-26 13:51:23 -0800580 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700581 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800582
583 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800584 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800585 set.addAnimation(alpha);
586 set.setDetachWallpaper(true);
587 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800588 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
589 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800590 // If we are on top of the wallpaper, we need an animation that
591 // correctly handles the wallpaper staying static behind all of
592 // the animated elements. To do this, will just have the existing
593 // element fade out.
594 a = new AlphaAnimation(1, 0);
595 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800596 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800597 // For normal animations, the exiting element just holds in place.
598 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800599 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800600
601 // Pick the desired duration. If this is an inter-activity transition,
602 // it is the standard duration for that. Otherwise we use the longer
603 // task transition duration.
604 final long duration;
605 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800606 case TRANSIT_ACTIVITY_OPEN:
607 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800608 duration = mConfigShortAnimTime;
609 break;
610 default:
611 duration = DEFAULT_APP_TRANSITION_DURATION;
612 break;
613 }
614 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800615 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800616 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800617 a.initialize(appWidth, appHeight, appWidth, appHeight);
618 return a;
619 }
620
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700621 private void getDefaultNextAppTransitionStartRect(Rect rect) {
622 if (mDefaultNextAppTransitionAnimationSpec == null ||
623 mDefaultNextAppTransitionAnimationSpec.rect == null) {
624 Slog.wtf(TAG, "Starting rect for app requested, but none available", new Throwable());
625 rect.setEmpty();
626 } else {
627 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
628 }
629 }
630
631 void getNextAppTransitionStartRect(int taskId, Rect rect) {
632 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800633 if (spec == null) {
634 spec = mDefaultNextAppTransitionAnimationSpec;
635 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700636 if (spec == null || spec.rect == null) {
637 Slog.wtf(TAG, "Starting rect for task: " + taskId + " requested, but not available",
638 new Throwable());
639 rect.setEmpty();
640 } else {
641 rect.set(spec.rect);
642 }
643 }
644
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800645 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
646 Bitmap bitmap) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700647 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800648 bitmap, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700649 }
650
Jorim Jaggif97ed922016-02-18 18:57:07 -0800651 /**
652 * @return the duration of the last clip reveal animation
653 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800654 long getLastClipRevealTransitionDuration() {
655 return mLastClipRevealTransitionDuration;
656 }
657
658 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800659 * @return the maximum distance the app surface is traveling of the last clip reveal animation
660 */
661 int getLastClipRevealMaxTranslation() {
662 return mLastClipRevealMaxTranslation;
663 }
664
665 /**
666 * @return true if in the last app transition had a clip reveal animation, false otherwise
667 */
668 boolean hadClipRevealAnimation() {
669 return mLastHadClipReveal;
670 }
671
672 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800673 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
674 * the start rect is outside of the target rect, and there is a lot of movement going on.
675 *
676 * @param cutOff whether the start rect was not fully contained by the end rect
677 * @param translationX the total translation the surface moves in x direction
678 * @param translationY the total translation the surfaces moves in y direction
679 * @param displayFrame our display frame
680 *
681 * @return the duration of the clip reveal animation, in milliseconds
682 */
683 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
684 float translationY, Rect displayFrame) {
685 if (!cutOff) {
686 return DEFAULT_APP_TRANSITION_DURATION;
687 }
688 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
689 Math.abs(translationY) / displayFrame.height());
690 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
691 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
692 }
693
694 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
695 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800696 final Animation anim;
697 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700698 final int appWidth = appFrame.width();
699 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800700
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700701 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700702 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700703 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700704
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700705 float t = 0f;
706 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800707 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700708 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800709 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
710 int translationX = 0;
711 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700712 int centerX = mTmpRect.centerX();
713 int centerY = mTmpRect.centerY();
714 int halfWidth = mTmpRect.width() / 2;
715 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800716 int clipStartX = centerX - halfWidth - appFrame.left;
717 int clipStartY = centerY - halfHeight - appFrame.top;
718 boolean cutOff = false;
719
720 // If the starting rectangle is fully or partially outside of the target rectangle, we
721 // need to start the clipping at the edge and then achieve the rest with translation
722 // and extending the clip rect from that edge.
723 if (appFrame.top > centerY - halfHeight) {
724 translationY = (centerY - halfHeight) - appFrame.top;
725 translationYCorrection = 0;
726 clipStartY = 0;
727 cutOff = true;
728 }
729 if (appFrame.left > centerX - halfWidth) {
730 translationX = (centerX - halfWidth) - appFrame.left;
731 clipStartX = 0;
732 cutOff = true;
733 }
734 if (appFrame.right < centerX + halfWidth) {
735 translationX = (centerX + halfWidth) - appFrame.right;
736 clipStartX = appWidth - mTmpRect.width();
737 cutOff = true;
738 }
739 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
740 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700741
742 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800743 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800744 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700745 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800746 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700747
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800748 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
749 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
750 : mLinearOutSlowInInterpolator);
751 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800752
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800753 Animation clipAnimTB = new ClipRectTBAnimation(
754 clipStartY, clipStartY + mTmpRect.height(),
755 0, appHeight,
756 translationYCorrection, 0,
757 mLinearOutSlowInInterpolator);
758 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
759 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800760
761 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800762 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700763 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800764 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700765 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800766
767 AnimationSet set = new AnimationSet(false);
768 set.addAnimation(clipAnimLR);
769 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700770 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800771 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700772 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800773 set.initialize(appWidth, appHeight, appWidth, appHeight);
774 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800775 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800776 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800777
778 // If the start rect was full inside the target rect (cutOff == false), we don't need
779 // to store the translation, because it's only used if cutOff == true.
780 mLastClipRevealMaxTranslation = cutOff
781 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800782 } else {
783 final long duration;
784 switch (transit) {
785 case TRANSIT_ACTIVITY_OPEN:
786 case TRANSIT_ACTIVITY_CLOSE:
787 duration = mConfigShortAnimTime;
788 break;
789 default:
790 duration = DEFAULT_APP_TRANSITION_DURATION;
791 break;
792 }
793 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
794 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
795 // If we are on top of the wallpaper, we need an animation that
796 // correctly handles the wallpaper staying static behind all of
797 // the animated elements. To do this, will just have the existing
798 // element fade out.
799 anim = new AlphaAnimation(1, 0);
800 anim.setDetachWallpaper(true);
801 } else {
802 // For normal animations, the exiting element just holds in place.
803 anim = new AlphaAnimation(1, 1);
804 }
805 anim.setInterpolator(mDecelerateInterpolator);
806 anim.setDuration(duration);
807 anim.setFillAfter(true);
808 }
809 return anim;
810 }
811
Winson Chung399f6202014-03-19 10:47:20 -0700812 /**
813 * Prepares the specified animation with a standard duration, interpolator, etc.
814 */
Winson Chung5393dff2014-05-08 14:25:43 -0700815 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
816 int duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700817 if (duration > 0) {
818 a.setDuration(duration);
819 }
Winson Chung5393dff2014-05-08 14:25:43 -0700820 a.setFillAfter(true);
821 a.setInterpolator(interpolator);
822 a.initialize(appWidth, appHeight, appWidth, appHeight);
823 return a;
824 }
825
826 /**
827 * Prepares the specified animation with a standard duration, interpolator, etc.
828 */
Winson Chung399f6202014-03-19 10:47:20 -0700829 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800830 // Pick the desired duration. If this is an inter-activity transition,
831 // it is the standard duration for that. Otherwise we use the longer
832 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700833 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800834 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800835 case TRANSIT_ACTIVITY_OPEN:
836 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800837 duration = mConfigShortAnimTime;
838 break;
839 default:
840 duration = DEFAULT_APP_TRANSITION_DURATION;
841 break;
842 }
Winson Chung5393dff2014-05-08 14:25:43 -0700843 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
844 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800845 }
846
Winson Chung399f6202014-03-19 10:47:20 -0700847 /**
848 * Return the current thumbnail transition state.
849 */
850 int getThumbnailTransitionState(boolean enter) {
851 if (enter) {
852 if (mNextAppTransitionScaleUp) {
853 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
854 } else {
855 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
856 }
857 } else {
858 if (mNextAppTransitionScaleUp) {
859 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
860 } else {
861 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
862 }
863 }
864 }
865
866 /**
867 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700868 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700869 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700870 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, Bitmap thumbnailHeader,
871 final int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700872 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700873 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700874 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700875 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chung399f6202014-03-19 10:47:20 -0700876 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700877 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700878
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700879 float scaleW = appWidth / thumbWidth;
Winson Chunga4ccb862014-08-22 15:26:27 -0700880 float unscaledHeight = thumbHeight * scaleW;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700881 getNextAppTransitionStartRect(taskId, mTmpRect);
Filip Gruszczynski565a9df2016-01-22 11:10:42 -0800882 final float unscaledStartY = mTmpRect.top - (unscaledHeight - thumbHeight) / 2f;
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800883 final float toY = appRect.top + -unscaledStartY;
Winson Chung399f6202014-03-19 10:47:20 -0700884 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700885 // Animation up from the thumbnail to the full screen
886 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700887 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800888 scale.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700889 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800890 Animation alpha = new AlphaAnimation(1f, 0f);
Winson Chunga4ccb862014-08-22 15:26:27 -0700891 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
892 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700893 final float toX = appRect.left + appRect.width() / 2 -
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700894 (mTmpRect.left + thumbWidth / 2);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700895 Animation translate = new TranslateAnimation(0, toX, 0, toY);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800896 translate.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700897 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700898
899 // This AnimationSet uses the Interpolators assigned above.
900 AnimationSet set = new AnimationSet(false);
901 set.addAnimation(scale);
902 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -0700903 set.addAnimation(translate);
Winson Chung399f6202014-03-19 10:47:20 -0700904 a = set;
905 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700906 // Animation down from the full screen to the thumbnail
907 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700908 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800909 scale.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700910 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
911 Animation alpha = new AlphaAnimation(0f, 1f);
912 alpha.setInterpolator(mThumbnailFadeInInterpolator);
913 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
Filip Gruszczynski565a9df2016-01-22 11:10:42 -0800914 final float toX = appRect.left + appRect.width() / 2 -
915 (mTmpRect.left + thumbWidth / 2);
916 Animation translate = new TranslateAnimation(toX, 0, toY, 0);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800917 translate.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700918 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700919
Winson Chunga4ccb862014-08-22 15:26:27 -0700920 // This AnimationSet uses the Interpolators assigned above.
921 AnimationSet set = new AnimationSet(false);
922 set.addAnimation(scale);
923 set.addAnimation(alpha);
924 set.addAnimation(translate);
925 a = set;
926
927 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700928 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800929 TOUCH_RESPONSE_INTERPOLATOR);
Winson Chung399f6202014-03-19 10:47:20 -0700930 }
931
932 /**
933 * This alternate animation is created when we are doing a thumbnail transition, for the
934 * activity that is leaving, and the activity that is entering.
935 */
Winson Chunga4ccb862014-08-22 15:26:27 -0700936 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700937 int orientation, int transit, Rect containingFrame, Rect contentInsets,
938 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700939 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700940 final int appWidth = containingFrame.width();
941 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700942 getDefaultNextAppTransitionStartRect(mTmpRect);
943 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700944 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700945 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -0700946 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winson21700932016-03-24 17:26:23 -0700947 final int thumbStartX = mTmpRect.left - containingFrame.left;
948 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -0700949
Winson Chung2820c452014-04-15 15:34:44 -0700950 // Used for the ENTER_SCALE_UP and EXIT_SCALE_DOWN transitions
951 float scale = 1f;
952 int scaledTopDecor = 0;
953
Winson Chung399f6202014-03-19 10:47:20 -0700954 switch (thumbTransitState) {
955 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700956 if (freeform) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700957 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700958 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -0700959 } else {
Winson21700932016-03-24 17:26:23 -0700960 AnimationSet set = new AnimationSet(true);
961
962 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700963 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700964 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800965
966 // Containing frame is in screen space, but we need the clip rect in the
967 // app space.
968 mTmpFromClipRect.offsetTo(0, 0);
969 mTmpToClipRect.offsetTo(0, 0);
970
971 // Exclude insets region from the source clip.
972 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700973 mNextAppTransitionInsets.set(contentInsets);
974
Winson21700932016-03-24 17:26:23 -0700975 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
976 // We scale the width and clip to the top/left square
977 scale = thumbWidth / (appWidth - contentInsets.left - contentInsets.right);
978 scaledTopDecor = (int) (scale * contentInsets.top);
979 int unscaledThumbHeight = (int) (thumbHeight / scale);
980 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700981
Winson21700932016-03-24 17:26:23 -0700982 Animation scaleAnim = new ScaleAnimation(scale, 1, scale, 1,
983 computePivot(mTmpRect.left - containingFrame.left, scale),
984 computePivot(mTmpRect.top - containingFrame.top, scale));
985 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
986 Animation translateAnim = new TranslateAnimation(0, 0, -scaledTopDecor, 0);
987
988 set.addAnimation(clipAnim);
989 set.addAnimation(scaleAnim);
990 set.addAnimation(translateAnim);
991
992 } else {
993 // In landscape, we don't scale at all and only crop
994 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
995 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
996
997 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
998 Animation translateAnim = new TranslateAnimation(thumbStartX, 0,
999 thumbStartY - contentInsets.top, 0);
1000
1001 set.addAnimation(clipAnim);
1002 set.addAnimation(translateAnim);
1003 }
1004
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001005 a = set;
Winson21700932016-03-24 17:26:23 -07001006 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001007 }
Winson Chung399f6202014-03-19 10:47:20 -07001008 break;
1009 }
1010 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001011 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001012 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001013 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001014 // activity.
1015 a = new AlphaAnimation(1, 0);
1016 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001017 a = new AlphaAnimation(1, 1);
1018 }
1019 break;
1020 }
1021 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001022 // Target app window during the scale down
1023 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1024 // Fade in the destination activity if we are animating from a wallpaper
1025 // activity.
1026 a = new AlphaAnimation(0, 1);
1027 } else {
1028 a = new AlphaAnimation(1, 1);
1029 }
Winson Chung399f6202014-03-19 10:47:20 -07001030 break;
1031 }
1032 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001033 // App window scaling down from full screen
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001034 if (freeform) {
1035 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1036 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001037 } else {
Winson21700932016-03-24 17:26:23 -07001038 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001039 mTmpFromClipRect.set(containingFrame);
1040 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001041
1042 // Containing frame is in screen space, but we need the clip rect in the
1043 // app space.
1044 mTmpFromClipRect.offsetTo(0, 0);
1045 mTmpToClipRect.offsetTo(0, 0);
1046
1047 // Exclude insets region from the target clip.
1048 mTmpToClipRect.inset(contentInsets);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001049 mNextAppTransitionInsets.set(contentInsets);
1050
Winson21700932016-03-24 17:26:23 -07001051 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
1052 // We scale the width and clip to the top/left square
1053 scale = thumbWidth / (appWidth - contentInsets.left - contentInsets.right);
1054 scaledTopDecor = (int) (scale * contentInsets.top);
1055 int unscaledThumbHeight = (int) (thumbHeight / scale);
1056 mTmpToClipRect.bottom = mTmpToClipRect.top + unscaledThumbHeight;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001057
Winson21700932016-03-24 17:26:23 -07001058 Animation scaleAnim = new ScaleAnimation(1, scale, 1, scale,
1059 computePivot(mTmpRect.left - containingFrame.left, scale),
1060 computePivot(mTmpRect.top - containingFrame.top, scale));
1061 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
1062 Animation translateAnim = new TranslateAnimation(0, 0, 0, -scaledTopDecor);
1063
1064 set.addAnimation(clipAnim);
1065 set.addAnimation(scaleAnim);
1066 set.addAnimation(translateAnim);
1067
1068 } else {
1069 // In landscape, we don't scale at all and only crop
1070 mTmpToClipRect.bottom = mTmpToClipRect.top + thumbHeightI;
1071 mTmpToClipRect.right = mTmpToClipRect.left + thumbWidthI;
1072
1073 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
1074 Animation translateAnim = new TranslateAnimation(0, thumbStartX, 0,
1075 thumbStartY - contentInsets.top);
1076
1077 set.addAnimation(clipAnim);
1078 set.addAnimation(translateAnim);
1079 }
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001080
1081 a = set;
1082 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001083 }
Winson Chung399f6202014-03-19 10:47:20 -07001084 break;
1085 }
1086 default:
1087 throw new RuntimeException("Invalid thumbnail transition state");
1088 }
1089
Winson Chungab79fce2014-11-04 16:15:22 -08001090 int duration = Math.max(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION,
1091 THUMBNAIL_APP_TRANSITION_DURATION);
1092 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001093 TOUCH_RESPONSE_INTERPOLATOR);
Winson Chung399f6202014-03-19 10:47:20 -07001094 }
1095
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001096 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1097 @Nullable Rect surfaceInsets, int taskId) {
1098 getNextAppTransitionStartRect(taskId, mTmpRect);
1099 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1100 true);
1101 }
1102
1103 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1104 @Nullable Rect surfaceInsets, int taskId) {
1105 getNextAppTransitionStartRect(taskId, mTmpRect);
1106 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1107 false);
1108 }
1109
1110 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1111 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1112 final float sourceWidth = sourceFrame.width();
1113 final float sourceHeight = sourceFrame.height();
1114 final float destWidth = destFrame.width();
1115 final float destHeight = destFrame.height();
1116 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1117 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001118 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001119 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001120 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001121 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001122 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1123 // We want the scaling to happen from the center of the surface. In order to achieve that,
1124 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001125 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1126 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1127 final ScaleAnimation scale = enter ?
1128 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1129 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1130 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1131 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1132 final int destHCenter = destFrame.left + destFrame.width() / 2;
1133 final int destVCenter = destFrame.top + destFrame.height() / 2;
1134 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1135 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1136 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1137 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001138 set.addAnimation(scale);
1139 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001140
1141 final IRemoteCallback callback = mAnimationFinishedCallback;
1142 if (callback != null) {
1143 set.setAnimationListener(new Animation.AnimationListener() {
1144 @Override
1145 public void onAnimationStart(Animation animation) { }
1146
1147 @Override
1148 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001149 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001150 }
1151
1152 @Override
1153 public void onAnimationRepeat(Animation animation) { }
1154 });
1155 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001156 return set;
1157 }
1158
Winson Chung399f6202014-03-19 10:47:20 -07001159 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001160 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001161 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001162 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001163 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
1164 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001165 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001166 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001167 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001168 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001169 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001170 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1171
1172 if (mNextAppTransitionScaleUp) {
1173 // Animation for the thumbnail zooming from its initial size to the full screen
1174 float scaleW = appWidth / thumbWidth;
1175 float scaleH = appHeight / thumbHeight;
1176 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001177 computePivot(mTmpRect.left, 1 / scaleW),
1178 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001179 scale.setInterpolator(mDecelerateInterpolator);
1180
1181 Animation alpha = new AlphaAnimation(1, 0);
1182 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1183
1184 // This AnimationSet uses the Interpolators assigned above.
1185 AnimationSet set = new AnimationSet(false);
1186 set.addAnimation(scale);
1187 set.addAnimation(alpha);
1188 a = set;
1189 } else {
1190 // Animation for the thumbnail zooming down from the full screen to its final size
1191 float scaleW = appWidth / thumbWidth;
1192 float scaleH = appHeight / thumbHeight;
1193 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001194 computePivot(mTmpRect.left, 1 / scaleW),
1195 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001196 }
1197
1198 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1199 }
1200
1201 /**
Winson Chung399f6202014-03-19 10:47:20 -07001202 * This animation is created when we are doing a thumbnail transition, for the activity that is
1203 * leaving, and the activity that is entering.
1204 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001205 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1206 int transit, int taskId) {
1207 final int appWidth = containingFrame.width();
1208 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001209 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001210 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001211 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001212 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001213 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001214 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001215 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1216
1217 switch (thumbTransitState) {
1218 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1219 // Entering app scales up with the thumbnail
1220 float scaleW = thumbWidth / appWidth;
1221 float scaleH = thumbHeight / appHeight;
1222 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001223 computePivot(mTmpRect.left, scaleW),
1224 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001225 break;
1226 }
1227 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1228 // Exiting app while the thumbnail is scaling up should fade or stay in place
1229 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1230 // Fade out while bringing up selected activity. This keeps the
1231 // current activity from showing through a launching wallpaper
1232 // activity.
1233 a = new AlphaAnimation(1, 0);
1234 } else {
1235 // noop animation
1236 a = new AlphaAnimation(1, 1);
1237 }
1238 break;
1239 }
1240 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1241 // Entering the other app, it should just be visible while we scale the thumbnail
1242 // down above it
1243 a = new AlphaAnimation(1, 1);
1244 break;
1245 }
1246 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1247 // Exiting the current app, the app should scale down with the thumbnail
1248 float scaleW = thumbWidth / appWidth;
1249 float scaleH = thumbHeight / appHeight;
1250 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001251 computePivot(mTmpRect.left, scaleW),
1252 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001253
1254 Animation alpha = new AlphaAnimation(1, 0);
1255
1256 AnimationSet set = new AnimationSet(true);
1257 set.addAnimation(scale);
1258 set.addAnimation(alpha);
1259 set.setZAdjustment(Animation.ZORDER_TOP);
1260 a = set;
1261 break;
1262 }
1263 default:
1264 throw new RuntimeException("Invalid thumbnail transition state");
1265 }
1266
1267 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1268 }
1269
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001270 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001271 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1272 final int left = mTmpFromClipRect.left;
1273 final int top = mTmpFromClipRect.top;
1274 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001275 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1276 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001277 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001278 float fromWidth = mTmpFromClipRect.width();
1279 float toWidth = mTmpToClipRect.width();
1280 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001281 // While the window might span the whole display, the actual content will be cropped to the
1282 // system decoration frame, for example when the window is docked. We need to take into
1283 // account the visible height when constructing the animation.
1284 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1285 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001286 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1287 // The final window is larger in both dimensions than current window (e.g. we are
1288 // maximizing), so we can simply unclip the new window and there will be no disappearing
1289 // frame.
1290 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1291 } else {
1292 // The disappearing window has one larger dimension. We need to apply scaling, so the
1293 // first frame of the entry animation matches the old window.
1294 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001295 // We might not be going exactly full screen, but instead be aligned under the status
1296 // bar using cropping. We still need to account for the cropped part, which will also
1297 // be scaled.
1298 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001299 }
1300
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001301 // We animate the translation from the old position of the removed window, to the new
1302 // position of the added window. The latter might not be full screen, for example docked for
1303 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001304 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001305 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001306 set.addAnimation(translate);
1307 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001308 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001309 return set;
1310 }
1311
Jorim Jaggic554b772015-06-04 16:07:57 -07001312 /**
1313 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1314 * frame of the transition doesn't change the visuals on screen, so we can start
1315 * directly with the second one
1316 */
1317 boolean canSkipFirstFrame() {
1318 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1319 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
1320 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1321 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001322
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001323 /**
1324 *
1325 * @param frame These are the bounds of the window when it finishes the animation. This is where
1326 * the animation must usually finish in entrance animation, as the next frame will
1327 * display the window at these coordinates. In case of exit animation, this is
1328 * where the animation must start, as the frame before the animation is displaying
1329 * the window at these bounds.
1330 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1331 * window might be obscured, usually by the system windows (status bar and
1332 * navigation bar) and we use content insets to convey that information. This
1333 * usually affects the animation aspects vertically, as the system decoration is
1334 * at the top and the bottom. For example when we animate from full screen to
1335 * recents, we want to exclude the covered parts, because they won't match the
1336 * thumbnail after the last frame is executed.
1337 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1338 * know about this to make the animation frames match. We currently use
1339 * this for freeform windows, which have larger surfaces to display
1340 * shadows. When we animate them from recents, we want to match the content
1341 * to the recents thumbnail and hence need to account for the surface being
1342 * bigger.
1343 */
Craig Mautner164d4bb2012-11-26 13:51:23 -08001344 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001345 int orientation, Rect frame, Rect displayFrame, Rect insets,
1346 @Nullable Rect surfaceInsets, boolean isVoiceInteraction, boolean freeform,
1347 int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001348 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001349 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
1350 || transit == TRANSIT_TASK_OPEN
1351 || transit == TRANSIT_TASK_TO_FRONT)) {
1352 a = loadAnimationRes(lp, enter
1353 ? com.android.internal.R.anim.voice_activity_open_enter
1354 : com.android.internal.R.anim.voice_activity_open_exit);
1355 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1356 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001357 + " anim=" + a + " transit=" + appTransitionToString(transit)
1358 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001359 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1360 || transit == TRANSIT_TASK_CLOSE
1361 || transit == TRANSIT_TASK_TO_BACK)) {
1362 a = loadAnimationRes(lp, enter
1363 ? com.android.internal.R.anim.voice_activity_close_enter
1364 : com.android.internal.R.anim.voice_activity_close_exit);
1365 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1366 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001367 + " anim=" + a + " transit=" + appTransitionToString(transit)
1368 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001369 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001370 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001371 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1372 "applyAnimation:"
1373 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1374 + " transit=" + appTransitionToString(transit)
1375 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001376 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1377 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001378 mNextAppTransitionEnter : mNextAppTransitionExit);
1379 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1380 "applyAnimation:"
1381 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001382 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001383 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001384 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1385 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1386 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1387 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001388 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1389 + " transit=" + appTransitionToString(transit)
1390 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001391 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001392 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001393 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1394 "applyAnimation:"
1395 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001396 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001397 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001398 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001399 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001400 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1401 "applyAnimation:"
1402 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001403 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001404 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001405 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1406 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001407 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001408 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001409 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001410 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001411 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1412 String animName = mNextAppTransitionScaleUp ?
1413 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1414 Slog.v(TAG, "applyAnimation:"
1415 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001416 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001417 + " Callers=" + Debug.getCallers(3));
1418 }
1419 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1420 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1421 mNextAppTransitionScaleUp =
1422 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1423 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001424 getThumbnailTransitionState(enter), orientation, transit, frame,
1425 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001426 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1427 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001428 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001429 Slog.v(TAG, "applyAnimation:"
1430 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001431 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001432 + " Callers=" + Debug.getCallers(3));
1433 }
1434 } else {
1435 int animAttr = 0;
1436 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001437 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001438 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001439 ? WindowAnimation_activityOpenEnterAnimation
1440 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001441 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001442 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001443 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001444 ? WindowAnimation_activityCloseEnterAnimation
1445 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001446 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001447 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001448 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001449 ? WindowAnimation_taskOpenEnterAnimation
1450 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001451 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001452 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001453 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001454 ? WindowAnimation_taskCloseEnterAnimation
1455 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001456 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001457 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001458 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001459 ? WindowAnimation_taskToFrontEnterAnimation
1460 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001461 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001462 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001463 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001464 ? WindowAnimation_taskToBackEnterAnimation
1465 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001466 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001467 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001468 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001469 ? WindowAnimation_wallpaperOpenEnterAnimation
1470 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001471 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001472 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001473 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001474 ? WindowAnimation_wallpaperCloseEnterAnimation
1475 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001476 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001477 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001478 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001479 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1480 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001481 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001482 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001483 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001484 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1485 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001486 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001487 case TRANSIT_TASK_OPEN_BEHIND:
1488 animAttr = enter
1489 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001490 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001491 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001492 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001493 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1494 "applyAnimation:"
1495 + " anim=" + a
1496 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001497 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001498 + " Callers=" + Debug.getCallers(3));
1499 }
1500 return a;
1501 }
1502
1503 void postAnimationCallback() {
1504 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001505 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1506 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001507 mNextAppTransitionCallback = null;
1508 }
1509 }
1510
1511 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001512 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001513 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001514 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001515 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001516 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001517 mNextAppTransitionEnter = enterAnim;
1518 mNextAppTransitionExit = exitAnim;
1519 postAnimationCallback();
1520 mNextAppTransitionCallback = startedCallback;
1521 } else {
1522 postAnimationCallback();
1523 }
1524 }
1525
1526 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001527 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001528 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001529 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001530 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001531 putDefaultNextAppTransitionCoordinates(startX, startY, startX + startWidth,
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001532 startY + startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001533 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001534 }
1535 }
1536
Chet Haase10e23ab2015-02-11 15:08:38 -08001537 void overridePendingAppTransitionClipReveal(int startX, int startY,
1538 int startWidth, int startHeight) {
1539 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001540 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001541 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001542 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001543 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001544 }
1545 }
1546
Craig Mautner164d4bb2012-11-26 13:51:23 -08001547 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1548 IRemoteCallback startedCallback, boolean scaleUp) {
1549 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001550 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001551 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1552 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001553 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001554 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001555 postAnimationCallback();
1556 mNextAppTransitionCallback = startedCallback;
1557 } else {
1558 postAnimationCallback();
1559 }
1560 }
1561
Winson Chunga4ccb862014-08-22 15:26:27 -07001562 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001563 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001564 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001565 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001566 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1567 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001568 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001569 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1570 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001571 postAnimationCallback();
1572 mNextAppTransitionCallback = startedCallback;
1573 } else {
1574 postAnimationCallback();
1575 }
1576 }
1577
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001578 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001579 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1580 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001581 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001582 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001583 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1584 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001585 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001586 if (specs != null) {
1587 for (int i = 0; i < specs.length; i++) {
1588 AppTransitionAnimationSpec spec = specs[i];
1589 if (spec != null) {
1590 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1591 if (i == 0) {
1592 // In full screen mode, the transition code depends on the default spec
1593 // to be set.
1594 Rect rect = spec.rect;
1595 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Filip Gruszczynskie3264d82015-11-20 17:10:04 -08001596 rect.width(), rect.height(), spec.bitmap);
Jorim Jaggi43102412015-11-11 16:28:37 +01001597 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001598 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001599 }
1600 }
1601 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001602 mNextAppTransitionCallback = onAnimationStartedCallback;
1603 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001604 } else {
1605 postAnimationCallback();
1606 }
1607 }
1608
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001609 void overridePendingAppTransitionMultiThumbFuture(
1610 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1611 boolean scaleUp) {
1612 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001613 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001614 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1615 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001616 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1617 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001618 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001619 }
1620 }
1621
Winson Chung044d5292014-11-06 11:05:19 -08001622 void overrideInPlaceAppTransition(String packageName, int anim) {
1623 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001624 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001625 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1626 mNextAppTransitionPackage = packageName;
1627 mNextAppTransitionInPlace = anim;
1628 } else {
1629 postAnimationCallback();
1630 }
1631 }
1632
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001633 /**
1634 * If a future is set for the app transition specs, fetch it in another thread.
1635 */
1636 private void fetchAppTransitionSpecsFromFuture() {
1637 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1638 mNextAppTransitionAnimationsSpecsPending = true;
1639 final IAppTransitionAnimationSpecsFuture future
1640 = mNextAppTransitionAnimationsSpecsFuture;
1641 mNextAppTransitionAnimationsSpecsFuture = null;
1642 mDefaultExecutor.execute(new Runnable() {
1643 @Override
1644 public void run() {
1645 AppTransitionAnimationSpec[] specs = null;
1646 try {
1647 specs = future.get();
1648 } catch (RemoteException e) {
1649 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1650 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001651 synchronized (mService.mWindowMap) {
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001652 mNextAppTransitionAnimationsSpecsPending = false;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001653 overridePendingAppTransitionMultiThumb(specs,
1654 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1655 mNextAppTransitionScaleUp);
1656 mNextAppTransitionFutureCallback = null;
Filip Gruszczynski96daf322015-11-18 18:01:27 -08001657 if (specs != null) {
1658 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1659 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001660 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001661 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001662 }
1663 });
1664 }
1665 }
1666
Craig Mautner164d4bb2012-11-26 13:51:23 -08001667 @Override
1668 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001669 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001670 }
1671
Craig Mautner4b71aa12012-12-27 17:20:01 -08001672 /**
1673 * Returns the human readable name of a window transition.
1674 *
1675 * @param transition The window transition.
1676 * @return The transition symbolic name.
1677 */
1678 public static String appTransitionToString(int transition) {
1679 switch (transition) {
1680 case TRANSIT_UNSET: {
1681 return "TRANSIT_UNSET";
1682 }
1683 case TRANSIT_NONE: {
1684 return "TRANSIT_NONE";
1685 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001686 case TRANSIT_ACTIVITY_OPEN: {
1687 return "TRANSIT_ACTIVITY_OPEN";
1688 }
1689 case TRANSIT_ACTIVITY_CLOSE: {
1690 return "TRANSIT_ACTIVITY_CLOSE";
1691 }
1692 case TRANSIT_TASK_OPEN: {
1693 return "TRANSIT_TASK_OPEN";
1694 }
1695 case TRANSIT_TASK_CLOSE: {
1696 return "TRANSIT_TASK_CLOSE";
1697 }
1698 case TRANSIT_TASK_TO_FRONT: {
1699 return "TRANSIT_TASK_TO_FRONT";
1700 }
1701 case TRANSIT_TASK_TO_BACK: {
1702 return "TRANSIT_TASK_TO_BACK";
1703 }
1704 case TRANSIT_WALLPAPER_CLOSE: {
1705 return "TRANSIT_WALLPAPER_CLOSE";
1706 }
1707 case TRANSIT_WALLPAPER_OPEN: {
1708 return "TRANSIT_WALLPAPER_OPEN";
1709 }
1710 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1711 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1712 }
1713 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1714 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1715 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001716 case TRANSIT_TASK_OPEN_BEHIND: {
1717 return "TRANSIT_TASK_OPEN_BEHIND";
1718 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001719 case TRANSIT_ACTIVITY_RELAUNCH: {
1720 return "TRANSIT_ACTIVITY_RELAUNCH";
1721 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001722 default: {
1723 return "<UNKNOWN>";
1724 }
1725 }
1726 }
1727
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001728 private String appStateToString() {
1729 switch (mAppTransitionState) {
1730 case APP_STATE_IDLE:
1731 return "APP_STATE_IDLE";
1732 case APP_STATE_READY:
1733 return "APP_STATE_READY";
1734 case APP_STATE_RUNNING:
1735 return "APP_STATE_RUNNING";
1736 case APP_STATE_TIMEOUT:
1737 return "APP_STATE_TIMEOUT";
1738 default:
1739 return "unknown state=" + mAppTransitionState;
1740 }
1741 }
1742
1743 private String transitTypeToString() {
1744 switch (mNextAppTransitionType) {
1745 case NEXT_TRANSIT_TYPE_NONE:
1746 return "NEXT_TRANSIT_TYPE_NONE";
1747 case NEXT_TRANSIT_TYPE_CUSTOM:
1748 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001749 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1750 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001751 case NEXT_TRANSIT_TYPE_SCALE_UP:
1752 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1753 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1754 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1755 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1756 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001757 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1758 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1759 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1760 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001761 default:
1762 return "unknown type=" + mNextAppTransitionType;
1763 }
1764 }
1765
Craig Mautner164d4bb2012-11-26 13:51:23 -08001766 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001767 public void dump(PrintWriter pw, String prefix) {
1768 pw.print(prefix); pw.println(this);
1769 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001770 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001771 pw.print(prefix); pw.print("mNextAppTransitionType=");
1772 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001773 }
1774 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001775 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001776 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001777 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001778 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001779 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1780 pw.print(" mNextAppTransitionExit=0x");
1781 pw.println(Integer.toHexString(mNextAppTransitionExit));
1782 break;
Winson Chung044d5292014-11-06 11:05:19 -08001783 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001784 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001785 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001786 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001787 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1788 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001789 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001790 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001791 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001792 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001793 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001794 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001795 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001796 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001797 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001798 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001799 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001800 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001801 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1802 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001803 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001804 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1805 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1806 pw.println(mDefaultNextAppTransitionAnimationSpec);
1807 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1808 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001809 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1810 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001811 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001812 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001813 }
1814 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001815 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1816 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001817 }
1818 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001819
1820 public void setCurrentUser(int newUserId) {
1821 mCurrentUserId = newUserId;
1822 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001823
1824 /**
1825 * @return true if transition is not running and should not be skipped, false if transition is
1826 * already running
1827 */
1828 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent) {
1829 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
1830 + " transit=" + appTransitionToString(transit)
1831 + " " + this
1832 + " alwaysKeepCurrent=" + alwaysKeepCurrent
1833 + " Callers=" + Debug.getCallers(3));
1834 if (!isTransitionSet() || mNextAppTransition == TRANSIT_NONE) {
1835 setAppTransition(transit);
1836 } else if (!alwaysKeepCurrent) {
1837 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
1838 // Opening a new task always supersedes a close for the anim.
1839 setAppTransition(transit);
1840 } else if (transit == TRANSIT_ACTIVITY_OPEN
1841 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
1842 // Opening a new activity always supersedes a close for the anim.
1843 setAppTransition(transit);
1844 }
1845 }
1846 boolean prepared = prepare();
1847 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001848 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
1849 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001850 }
1851 return prepared;
1852 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001853}