blob: bea300add980e7570a22e29a0f96e8311b17e897 [file] [log] [blame]
Craig Mautner164d4bb2012-11-26 13:51:23 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Filip Gruszczynski82861362015-10-16 14:21:09 -070019import static android.view.WindowManagerInternal.AppTransitionListener;
20import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
21import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
22import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
23import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
24import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
25import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
26import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
27import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
28import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
29import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
30import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
31import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
32import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
33import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
34import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
35import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
36import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
37import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
38import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
39import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
40import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
41import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080042import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
43import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080044import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
45import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010046import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
47import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
Filip Gruszczynski82861362015-10-16 14:21:09 -070048
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070049import android.annotation.Nullable;
Craig Mautner164d4bb2012-11-26 13:51:23 -080050import android.content.Context;
51import android.graphics.Bitmap;
Winson Chung399f6202014-03-19 10:47:20 -070052import android.graphics.Rect;
Craig Mautner164d4bb2012-11-26 13:51:23 -080053import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010054import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080055import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010056import android.os.RemoteException;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080057import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080058import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070059import android.util.SparseArray;
60import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010061import android.view.IAppTransitionAnimationSpecsFuture;
Craig Mautner164d4bb2012-11-26 13:51:23 -080062import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080063import android.view.animation.AlphaAnimation;
64import android.view.animation.Animation;
65import android.view.animation.AnimationSet;
66import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070067import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080068import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070069import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080070import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070071import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070072
Craig Mautner164d4bb2012-11-26 13:51:23 -080073import com.android.internal.util.DumpUtils.Dump;
74import com.android.server.AttributeCache;
75import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -080076import com.android.server.wm.animation.ClipRectLRAnimation;
77import com.android.server.wm.animation.ClipRectTBAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080078
79import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010080import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010081import java.util.concurrent.ExecutorService;
82import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -080083
Craig Mautner164d4bb2012-11-26 13:51:23 -080084// State management of app transitions. When we are preparing for a
85// transition, mNextAppTransition will be the kind of transition to
86// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
87// mOpeningApps and mClosingApps are the lists of tokens that will be
88// made visible or hidden at the next transition.
89public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080090 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070091 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080092
Craig Mautner4b71aa12012-12-27 17:20:01 -080093 /** Not set up for a transition. */
94 public static final int TRANSIT_UNSET = -1;
95 /** No animation for transition. */
96 public static final int TRANSIT_NONE = 0;
97 /** 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 -070098 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -080099 /** The window in the top-most activity is being closed to reveal the
100 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700101 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800102 /** A window in a new task is being opened on top of an existing one
103 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700104 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800105 /** A window in the top-most activity is being closed to reveal the
106 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700107 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800108 /** A window in an existing task is being displayed on top of an existing one
109 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700110 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800111 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700112 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800113 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
114 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700115 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800116 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
117 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700118 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800119 /** A window in a new activity is being opened on top of an existing one, and both are on top
120 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700121 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800122 /** The window in the top-most activity is being closed to reveal the previous activity, and
123 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700124 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
125 /** A window in a new task is being opened behind an existing one in another activity's task.
126 * The new window will show briefly and then be gone. */
127 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800128 /** A window in a task is being animated in-place. */
129 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700130 /** An activity is being relaunched (e.g. due to configuration change). */
131 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800132
Winson Chunga4ccb862014-08-22 15:26:27 -0700133 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700134 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800135 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700136 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800137
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800138 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800139
140 /** Interpolator to be used for animations that respond directly to a touch */
141 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
142 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
143
144 /**
145 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
146 * involved, to make it more understandable.
147 */
148 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700149 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
150 private static final int THUMBNAIL_APP_TRANSITION_ALPHA_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700151 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800152
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800153 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800154 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800155
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800156 private int mNextAppTransition = TRANSIT_UNSET;
157
158 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
159 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
160 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
161 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
162 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700163 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
164 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800165 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800166 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800167 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
168
Winson Chung399f6202014-03-19 10:47:20 -0700169 // These are the possible states for the enter/exit activities during a thumbnail transition
170 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
171 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
172 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
173 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
174
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800175 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800176 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800177 private boolean mNextAppTransitionScaleUp;
178 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100179 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700180 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800181 private int mNextAppTransitionEnter;
182 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800183 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700184
185 // Keyed by task id.
186 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
187 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100188 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
189 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700190 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
191
Winson Chunga4ccb862014-08-22 15:26:27 -0700192 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800193
Winson Chung2820c452014-04-15 15:34:44 -0700194 private Rect mTmpFromClipRect = new Rect();
195 private Rect mTmpToClipRect = new Rect();
196
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700197 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700198
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800199 private final static int APP_STATE_IDLE = 0;
200 private final static int APP_STATE_READY = 1;
201 private final static int APP_STATE_RUNNING = 2;
202 private final static int APP_STATE_TIMEOUT = 3;
203 private int mAppTransitionState = APP_STATE_IDLE;
204
205 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800206 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700207 private final Interpolator mThumbnailFadeInInterpolator;
208 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800209 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700210 private final Interpolator mFastOutLinearInInterpolator;
211 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
212
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700213 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800214
Amith Yamasani4befbec2013-07-10 16:18:01 -0700215 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800216 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700217
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100218 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100219 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100220
Jorim Jaggif97ed922016-02-18 18:57:07 -0800221 private int mLastClipRevealMaxTranslation;
222 private boolean mLastHadClipReveal;
223
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800224 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800225 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800226 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800227 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
228 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700229 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
230 com.android.internal.R.interpolator.fast_out_linear_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800231 mConfigShortAnimTime = context.getResources().getInteger(
232 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800233 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
234 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700235 mThumbnailFadeInInterpolator = new Interpolator() {
236 @Override
237 public float getInterpolation(float input) {
238 // Linear response for first fraction, then complete after that.
239 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
240 return 0f;
241 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700242 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700243 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700244 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700245 }
246 };
247 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800248 @Override
249 public float getInterpolation(float input) {
250 // Linear response for first fraction, then complete after that.
251 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700252 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
253 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800254 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700255 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800256 }
257 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700258 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
259 * mContext.getResources().getDisplayMetrics().density);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800260 }
261
262 boolean isTransitionSet() {
263 return mNextAppTransition != TRANSIT_UNSET;
264 }
265
Craig Mautner164d4bb2012-11-26 13:51:23 -0800266 boolean isTransitionEqual(int transit) {
267 return mNextAppTransition == transit;
268 }
269
270 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800271 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800272 }
273
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700274 private void setAppTransition(int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800275 mNextAppTransition = transit;
276 }
277
278 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800279 return mAppTransitionState == APP_STATE_READY
280 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800281 }
282
Craig Mautnerae446592012-12-06 19:05:05 -0800283 void setReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800284 mAppTransitionState = APP_STATE_READY;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100285 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800286 }
287
288 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800289 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800290 }
291
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800292 void setIdle() {
293 mAppTransitionState = APP_STATE_IDLE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800294 }
295
296 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800297 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800298 }
299
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800300 void setTimeout() {
301 mAppTransitionState = APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800302 }
303
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700304 Bitmap getAppTransitionThumbnailHeader(int taskId) {
305 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800306 if (spec == null) {
307 spec = mDefaultNextAppTransitionAnimationSpec;
308 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700309 return spec != null ? spec.bitmap : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800310 }
311
Winson Chunga4ccb862014-08-22 15:26:27 -0700312 /** Returns whether the next thumbnail transition is aspect scaled up. */
313 boolean isNextThumbnailTransitionAspectScaled() {
314 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
315 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
316 }
317
318 /** Returns whether the next thumbnail transition is scaling up. */
319 boolean isNextThumbnailTransitionScaleUp() {
320 return mNextAppTransitionScaleUp;
321 }
322
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800323 boolean isNextAppTransitionThumbnailUp() {
324 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
325 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
326 }
327
328 boolean isNextAppTransitionThumbnailDown() {
329 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
330 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
331 }
332
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100333 /**
334 * @return true if and only if we are currently fetching app transition specs from the future
335 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
336 */
337 boolean isFetchingAppTransitionsSpecs() {
338 return mNextAppTransitionAnimationsSpecsPending;
339 }
340
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700341 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800342 if (!isRunning()) {
343 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100344 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800345 mLastHadClipReveal = false;
346 mLastClipRevealMaxTranslation = 0;
347 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700348 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800349 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700350 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800351 }
352
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800353 void goodToGo(AppWindowAnimator topOpeningAppAnimator, AppWindowAnimator topClosingAppAnimator,
354 ArraySet<AppWindowToken> openingApps, ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800355 mNextAppTransition = TRANSIT_UNSET;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800356 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100357 notifyAppTransitionStartingLocked(
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800358 topOpeningAppAnimator != null ? topOpeningAppAnimator.mAppToken.token : null,
359 topClosingAppAnimator != null ? topClosingAppAnimator.mAppToken.token : null,
360 topOpeningAppAnimator != null ? topOpeningAppAnimator.animation : null,
361 topClosingAppAnimator != null ? topClosingAppAnimator.animation : null);
362 mService.getDefaultDisplayContentLocked().getDockedDividerController()
363 .notifyAppTransitionStarting(openingApps, closingApps);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800364 }
365
366 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800367 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800368 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700369 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi65193992015-11-23 16:49:59 -0800370 mNextAppTransitionAnimationsSpecsFuture = null;
371 mDefaultNextAppTransitionAnimationSpec = null;
372 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800373 }
374
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800375 void freeze() {
376 setAppTransition(AppTransition.TRANSIT_UNSET);
377 clear();
378 setReady();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100379 notifyAppTransitionCancelledLocked();
380 }
381
382 void registerListenerLocked(AppTransitionListener listener) {
383 mListeners.add(listener);
384 }
385
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700386 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100387 for (int i = 0; i < mListeners.size(); i++) {
388 mListeners.get(i).onAppTransitionFinishedLocked(token);
389 }
390 }
391
392 private void notifyAppTransitionPendingLocked() {
393 for (int i = 0; i < mListeners.size(); i++) {
394 mListeners.get(i).onAppTransitionPendingLocked();
395 }
396 }
397
398 private void notifyAppTransitionCancelledLocked() {
399 for (int i = 0; i < mListeners.size(); i++) {
400 mListeners.get(i).onAppTransitionCancelledLocked();
401 }
402 }
403
404 private void notifyAppTransitionStartingLocked(IBinder openToken,
405 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
406 for (int i = 0; i < mListeners.size(); i++) {
407 mListeners.get(i).onAppTransitionStartingLocked(openToken, closeToken, openAnimation,
408 closeAnimation);
409 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800410 }
411
Craig Mautner164d4bb2012-11-26 13:51:23 -0800412 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
413 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
414 + (lp != null ? lp.packageName : null)
415 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
416 if (lp != null && lp.windowAnimations != 0) {
417 // If this is a system resource, don't try to load it from the
418 // application resources. It is nice to avoid loading application
419 // resources if we can.
420 String packageName = lp.packageName != null ? lp.packageName : "android";
421 int resId = lp.windowAnimations;
422 if ((resId&0xFF000000) == 0x01000000) {
423 packageName = "android";
424 }
425 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
426 + packageName);
427 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700428 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800429 }
430 return null;
431 }
432
433 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
434 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
435 + packageName + " resId=0x" + Integer.toHexString(resId));
436 if (packageName != null) {
437 if ((resId&0xFF000000) == 0x01000000) {
438 packageName = "android";
439 }
440 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
441 + packageName);
442 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700443 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800444 }
445 return null;
446 }
447
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700448 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800449 int anim = 0;
450 Context context = mContext;
451 if (animAttr >= 0) {
452 AttributeCache.Entry ent = getCachedAnimations(lp);
453 if (ent != null) {
454 context = ent.context;
455 anim = ent.array.getResourceId(animAttr, 0);
456 }
457 }
458 if (anim != 0) {
459 return AnimationUtils.loadAnimation(context, anim);
460 }
461 return null;
462 }
463
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700464 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
465 Context context = mContext;
466 if (resId >= 0) {
467 AttributeCache.Entry ent = getCachedAnimations(lp);
468 if (ent != null) {
469 context = ent.context;
470 }
471 return AnimationUtils.loadAnimation(context, resId);
472 }
473 return null;
474 }
475
476 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800477 int anim = 0;
478 Context context = mContext;
479 if (resId >= 0) {
480 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
481 if (ent != null) {
482 context = ent.context;
483 anim = resId;
484 }
485 }
486 if (anim != 0) {
487 return AnimationUtils.loadAnimation(context, anim);
488 }
489 return null;
490 }
491
Craig Mautner164d4bb2012-11-26 13:51:23 -0800492 /**
493 * Compute the pivot point for an animation that is scaling from a small
494 * rect on screen to a larger rect. The pivot point varies depending on
495 * the distance between the inner and outer edges on both sides. This
496 * function computes the pivot point for one dimension.
497 * @param startPos Offset from left/top edge of outer rectangle to
498 * left/top edge of inner rectangle.
499 * @param finalScale The scaling factor between the size of the outer
500 * and inner rectangles.
501 */
502 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800503
504 /*
505 Theorem of intercepting lines:
506
507 + + +-----------------------------------------------+
508 | | | |
509 | | | |
510 | | | |
511 | | | |
512 x | y | | |
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 + ++
554 p ++
555
556 scale = (x - y) / x
557 <=> x = -y / (scale - 1)
558 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800559 final float denom = finalScale-1;
560 if (Math.abs(denom) < .0001f) {
561 return startPos;
562 }
563 return -startPos / denom;
564 }
565
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700566 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
567 Rect containingFrame) {
568 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700569 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700570 final int appWidth = containingFrame.width();
571 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800572 if (enter) {
573 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700574 float scaleW = mTmpRect.width() / (float) appWidth;
575 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800576 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700577 computePivot(mTmpRect.left, scaleW),
578 computePivot(mTmpRect.right, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800579 scale.setInterpolator(mDecelerateInterpolator);
580
Craig Mautner164d4bb2012-11-26 13:51:23 -0800581 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700582 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800583
584 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800585 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800586 set.addAnimation(alpha);
587 set.setDetachWallpaper(true);
588 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800589 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
590 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800591 // If we are on top of the wallpaper, we need an animation that
592 // correctly handles the wallpaper staying static behind all of
593 // the animated elements. To do this, will just have the existing
594 // element fade out.
595 a = new AlphaAnimation(1, 0);
596 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800597 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800598 // For normal animations, the exiting element just holds in place.
599 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800600 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800601
602 // Pick the desired duration. If this is an inter-activity transition,
603 // it is the standard duration for that. Otherwise we use the longer
604 // task transition duration.
605 final long duration;
606 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800607 case TRANSIT_ACTIVITY_OPEN:
608 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800609 duration = mConfigShortAnimTime;
610 break;
611 default:
612 duration = DEFAULT_APP_TRANSITION_DURATION;
613 break;
614 }
615 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800616 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800617 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800618 a.initialize(appWidth, appHeight, appWidth, appHeight);
619 return a;
620 }
621
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700622 private void getDefaultNextAppTransitionStartRect(Rect rect) {
623 if (mDefaultNextAppTransitionAnimationSpec == null ||
624 mDefaultNextAppTransitionAnimationSpec.rect == null) {
625 Slog.wtf(TAG, "Starting rect for app requested, but none available", new Throwable());
626 rect.setEmpty();
627 } else {
628 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
629 }
630 }
631
632 void getNextAppTransitionStartRect(int taskId, Rect rect) {
633 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800634 if (spec == null) {
635 spec = mDefaultNextAppTransitionAnimationSpec;
636 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700637 if (spec == null || spec.rect == null) {
638 Slog.wtf(TAG, "Starting rect for task: " + taskId + " requested, but not available",
639 new Throwable());
640 rect.setEmpty();
641 } else {
642 rect.set(spec.rect);
643 }
644 }
645
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800646 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
647 Bitmap bitmap) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700648 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800649 bitmap, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700650 }
651
Jorim Jaggif97ed922016-02-18 18:57:07 -0800652 /**
653 * @return the duration of the last clip reveal animation
654 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800655 long getLastClipRevealTransitionDuration() {
656 return mLastClipRevealTransitionDuration;
657 }
658
659 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800660 * @return the maximum distance the app surface is traveling of the last clip reveal animation
661 */
662 int getLastClipRevealMaxTranslation() {
663 return mLastClipRevealMaxTranslation;
664 }
665
666 /**
667 * @return true if in the last app transition had a clip reveal animation, false otherwise
668 */
669 boolean hadClipRevealAnimation() {
670 return mLastHadClipReveal;
671 }
672
673 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800674 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
675 * the start rect is outside of the target rect, and there is a lot of movement going on.
676 *
677 * @param cutOff whether the start rect was not fully contained by the end rect
678 * @param translationX the total translation the surface moves in x direction
679 * @param translationY the total translation the surfaces moves in y direction
680 * @param displayFrame our display frame
681 *
682 * @return the duration of the clip reveal animation, in milliseconds
683 */
684 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
685 float translationY, Rect displayFrame) {
686 if (!cutOff) {
687 return DEFAULT_APP_TRANSITION_DURATION;
688 }
689 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
690 Math.abs(translationY) / displayFrame.height());
691 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
692 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
693 }
694
695 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
696 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800697 final Animation anim;
698 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700699 final int appWidth = appFrame.width();
700 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800701
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700702 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700703 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700704 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700705
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700706 float t = 0f;
707 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800708 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700709 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800710 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
711 int translationX = 0;
712 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700713 int centerX = mTmpRect.centerX();
714 int centerY = mTmpRect.centerY();
715 int halfWidth = mTmpRect.width() / 2;
716 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800717 int clipStartX = centerX - halfWidth - appFrame.left;
718 int clipStartY = centerY - halfHeight - appFrame.top;
719 boolean cutOff = false;
720
721 // If the starting rectangle is fully or partially outside of the target rectangle, we
722 // need to start the clipping at the edge and then achieve the rest with translation
723 // and extending the clip rect from that edge.
724 if (appFrame.top > centerY - halfHeight) {
725 translationY = (centerY - halfHeight) - appFrame.top;
726 translationYCorrection = 0;
727 clipStartY = 0;
728 cutOff = true;
729 }
730 if (appFrame.left > centerX - halfWidth) {
731 translationX = (centerX - halfWidth) - appFrame.left;
732 clipStartX = 0;
733 cutOff = true;
734 }
735 if (appFrame.right < centerX + halfWidth) {
736 translationX = (centerX + halfWidth) - appFrame.right;
737 clipStartX = appWidth - mTmpRect.width();
738 cutOff = true;
739 }
740 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
741 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700742
743 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800744 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800745 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700746 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800747 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700748
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800749 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
750 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
751 : mLinearOutSlowInInterpolator);
752 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800753
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800754 Animation clipAnimTB = new ClipRectTBAnimation(
755 clipStartY, clipStartY + mTmpRect.height(),
756 0, appHeight,
757 translationYCorrection, 0,
758 mLinearOutSlowInInterpolator);
759 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
760 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800761
762 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800763 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700764 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800765 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700766 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800767
768 AnimationSet set = new AnimationSet(false);
769 set.addAnimation(clipAnimLR);
770 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700771 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800772 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700773 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800774 set.initialize(appWidth, appHeight, appWidth, appHeight);
775 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800776 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800777 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800778
779 // If the start rect was full inside the target rect (cutOff == false), we don't need
780 // to store the translation, because it's only used if cutOff == true.
781 mLastClipRevealMaxTranslation = cutOff
782 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800783 } else {
784 final long duration;
785 switch (transit) {
786 case TRANSIT_ACTIVITY_OPEN:
787 case TRANSIT_ACTIVITY_CLOSE:
788 duration = mConfigShortAnimTime;
789 break;
790 default:
791 duration = DEFAULT_APP_TRANSITION_DURATION;
792 break;
793 }
794 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
795 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
796 // If we are on top of the wallpaper, we need an animation that
797 // correctly handles the wallpaper staying static behind all of
798 // the animated elements. To do this, will just have the existing
799 // element fade out.
800 anim = new AlphaAnimation(1, 0);
801 anim.setDetachWallpaper(true);
802 } else {
803 // For normal animations, the exiting element just holds in place.
804 anim = new AlphaAnimation(1, 1);
805 }
806 anim.setInterpolator(mDecelerateInterpolator);
807 anim.setDuration(duration);
808 anim.setFillAfter(true);
809 }
810 return anim;
811 }
812
Winson Chung399f6202014-03-19 10:47:20 -0700813 /**
814 * Prepares the specified animation with a standard duration, interpolator, etc.
815 */
Winson Chung5393dff2014-05-08 14:25:43 -0700816 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
817 int duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700818 if (duration > 0) {
819 a.setDuration(duration);
820 }
Winson Chung5393dff2014-05-08 14:25:43 -0700821 a.setFillAfter(true);
822 a.setInterpolator(interpolator);
823 a.initialize(appWidth, appHeight, appWidth, appHeight);
824 return a;
825 }
826
827 /**
828 * Prepares the specified animation with a standard duration, interpolator, etc.
829 */
Winson Chung399f6202014-03-19 10:47:20 -0700830 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800831 // Pick the desired duration. If this is an inter-activity transition,
832 // it is the standard duration for that. Otherwise we use the longer
833 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700834 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800835 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800836 case TRANSIT_ACTIVITY_OPEN:
837 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800838 duration = mConfigShortAnimTime;
839 break;
840 default:
841 duration = DEFAULT_APP_TRANSITION_DURATION;
842 break;
843 }
Winson Chung5393dff2014-05-08 14:25:43 -0700844 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
845 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800846 }
847
Winson Chung399f6202014-03-19 10:47:20 -0700848 /**
849 * Return the current thumbnail transition state.
850 */
851 int getThumbnailTransitionState(boolean enter) {
852 if (enter) {
853 if (mNextAppTransitionScaleUp) {
854 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
855 } else {
856 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
857 }
858 } else {
859 if (mNextAppTransitionScaleUp) {
860 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
861 } else {
862 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
863 }
864 }
865 }
866
867 /**
868 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700869 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700870 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700871 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, Bitmap thumbnailHeader,
872 final int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700873 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700874 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700875 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700876 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chung399f6202014-03-19 10:47:20 -0700877 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700878 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700879
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700880 float scaleW = appWidth / thumbWidth;
Winson Chunga4ccb862014-08-22 15:26:27 -0700881 float unscaledHeight = thumbHeight * scaleW;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700882 getNextAppTransitionStartRect(taskId, mTmpRect);
Filip Gruszczynski565a9df2016-01-22 11:10:42 -0800883 final float unscaledStartY = mTmpRect.top - (unscaledHeight - thumbHeight) / 2f;
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800884 final float toY = appRect.top + -unscaledStartY;
Winson Chung399f6202014-03-19 10:47:20 -0700885 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700886 // Animation up from the thumbnail to the full screen
887 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700888 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800889 scale.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700890 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800891 Animation alpha = new AlphaAnimation(1f, 0f);
Winson Chunga4ccb862014-08-22 15:26:27 -0700892 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
893 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700894 final float toX = appRect.left + appRect.width() / 2 -
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700895 (mTmpRect.left + thumbWidth / 2);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700896 Animation translate = new TranslateAnimation(0, toX, 0, toY);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800897 translate.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700898 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700899
900 // This AnimationSet uses the Interpolators assigned above.
901 AnimationSet set = new AnimationSet(false);
902 set.addAnimation(scale);
903 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -0700904 set.addAnimation(translate);
Winson Chung399f6202014-03-19 10:47:20 -0700905 a = set;
906 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700907 // Animation down from the full screen to the thumbnail
908 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700909 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800910 scale.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700911 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
912 Animation alpha = new AlphaAnimation(0f, 1f);
913 alpha.setInterpolator(mThumbnailFadeInInterpolator);
914 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
Filip Gruszczynski565a9df2016-01-22 11:10:42 -0800915 final float toX = appRect.left + appRect.width() / 2 -
916 (mTmpRect.left + thumbWidth / 2);
917 Animation translate = new TranslateAnimation(toX, 0, toY, 0);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800918 translate.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700919 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700920
Winson Chunga4ccb862014-08-22 15:26:27 -0700921 // This AnimationSet uses the Interpolators assigned above.
922 AnimationSet set = new AnimationSet(false);
923 set.addAnimation(scale);
924 set.addAnimation(alpha);
925 set.addAnimation(translate);
926 a = set;
927
928 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700929 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800930 TOUCH_RESPONSE_INTERPOLATOR);
Winson Chung399f6202014-03-19 10:47:20 -0700931 }
932
933 /**
934 * This alternate animation is created when we are doing a thumbnail transition, for the
935 * activity that is leaving, and the activity that is entering.
936 */
Winson Chunga4ccb862014-08-22 15:26:27 -0700937 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700938 int orientation, int transit, Rect containingFrame, Rect contentInsets,
939 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700940 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700941 final int appWidth = containingFrame.width();
942 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700943 getDefaultNextAppTransitionStartRect(mTmpRect);
944 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700945 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700946 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -0700947 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
948
Winson Chung2820c452014-04-15 15:34:44 -0700949 // Used for the ENTER_SCALE_UP and EXIT_SCALE_DOWN transitions
950 float scale = 1f;
951 int scaledTopDecor = 0;
952
Winson Chung399f6202014-03-19 10:47:20 -0700953 switch (thumbTransitState) {
954 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700955 if (freeform) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700956 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700957 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -0700958 } else {
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700959 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700960 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800961
962 // Containing frame is in screen space, but we need the clip rect in the
963 // app space.
964 mTmpFromClipRect.offsetTo(0, 0);
965 mTmpToClipRect.offsetTo(0, 0);
966
967 // Exclude insets region from the source clip.
968 mTmpFromClipRect.inset(contentInsets);
969
970 // We scale the width and clip to the top/left square
971 scale = thumbWidth / (appWidth - contentInsets.left - contentInsets.right);
972 scaledTopDecor = (int) (scale * contentInsets.top);
973 int unscaledThumbHeight = (int) (thumbHeight / scale);
974 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700975
976 mNextAppTransitionInsets.set(contentInsets);
977
978 Animation scaleAnim = new ScaleAnimation(scale, 1, scale, 1,
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800979 computePivot(mTmpRect.left - containingFrame.left, scale),
980 computePivot(mTmpRect.top - containingFrame.top, scale));
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700981 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
982 Animation translateAnim = new TranslateAnimation(0, 0, -scaledTopDecor, 0);
983
984 AnimationSet set = new AnimationSet(true);
985 set.addAnimation(clipAnim);
986 set.addAnimation(scaleAnim);
987 set.addAnimation(translateAnim);
988 a = set;
Winson Chung2820c452014-04-15 15:34:44 -0700989 }
Winson Chung399f6202014-03-19 10:47:20 -0700990 break;
991 }
992 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700993 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -0700994 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700995 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -0700996 // activity.
997 a = new AlphaAnimation(1, 0);
998 } else {
Winson Chung399f6202014-03-19 10:47:20 -0700999 a = new AlphaAnimation(1, 1);
1000 }
1001 break;
1002 }
1003 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001004 // Target app window during the scale down
1005 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1006 // Fade in the destination activity if we are animating from a wallpaper
1007 // activity.
1008 a = new AlphaAnimation(0, 1);
1009 } else {
1010 a = new AlphaAnimation(1, 1);
1011 }
Winson Chung399f6202014-03-19 10:47:20 -07001012 break;
1013 }
1014 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001015 // App window scaling down from full screen
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001016 if (freeform) {
1017 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1018 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001019 } else {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001020 mTmpFromClipRect.set(containingFrame);
1021 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001022
1023 // Containing frame is in screen space, but we need the clip rect in the
1024 // app space.
1025 mTmpFromClipRect.offsetTo(0, 0);
1026 mTmpToClipRect.offsetTo(0, 0);
1027
1028 // Exclude insets region from the target clip.
1029 mTmpToClipRect.inset(contentInsets);
1030
1031 // We scale the width and clip to the top/left square
1032 scale = thumbWidth / (appWidth - contentInsets.left - contentInsets.right);
1033 scaledTopDecor = (int) (scale * contentInsets.top);
1034 int unscaledThumbHeight = (int) (thumbHeight / scale);
1035 mTmpToClipRect.bottom = mTmpToClipRect.top + unscaledThumbHeight;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001036
1037 mNextAppTransitionInsets.set(contentInsets);
1038
1039 Animation scaleAnim = new ScaleAnimation(1, scale, 1, scale,
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001040 computePivot(mTmpRect.left - containingFrame.left, scale),
1041 computePivot(mTmpRect.top - containingFrame.top, scale));
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001042 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
1043 Animation translateAnim = new TranslateAnimation(0, 0, 0, -scaledTopDecor);
1044
1045 AnimationSet set = new AnimationSet(true);
1046 set.addAnimation(clipAnim);
1047 set.addAnimation(scaleAnim);
1048 set.addAnimation(translateAnim);
1049
1050 a = set;
1051 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001052 }
Winson Chung399f6202014-03-19 10:47:20 -07001053 break;
1054 }
1055 default:
1056 throw new RuntimeException("Invalid thumbnail transition state");
1057 }
1058
Winson Chungab79fce2014-11-04 16:15:22 -08001059 int duration = Math.max(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION,
1060 THUMBNAIL_APP_TRANSITION_DURATION);
1061 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001062 TOUCH_RESPONSE_INTERPOLATOR);
Winson Chung399f6202014-03-19 10:47:20 -07001063 }
1064
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001065 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1066 @Nullable Rect surfaceInsets, int taskId) {
1067 getNextAppTransitionStartRect(taskId, mTmpRect);
1068 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1069 true);
1070 }
1071
1072 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1073 @Nullable Rect surfaceInsets, int taskId) {
1074 getNextAppTransitionStartRect(taskId, mTmpRect);
1075 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1076 false);
1077 }
1078
1079 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1080 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1081 final float sourceWidth = sourceFrame.width();
1082 final float sourceHeight = sourceFrame.height();
1083 final float destWidth = destFrame.width();
1084 final float destHeight = destFrame.height();
1085 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1086 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001087 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001088 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001089 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001090 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001091 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1092 // We want the scaling to happen from the center of the surface. In order to achieve that,
1093 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001094 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1095 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1096 final ScaleAnimation scale = enter ?
1097 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1098 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1099 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1100 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1101 final int destHCenter = destFrame.left + destFrame.width() / 2;
1102 final int destVCenter = destFrame.top + destFrame.height() / 2;
1103 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1104 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1105 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1106 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001107 set.addAnimation(scale);
1108 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001109
1110 final IRemoteCallback callback = mAnimationFinishedCallback;
1111 if (callback != null) {
1112 set.setAnimationListener(new Animation.AnimationListener() {
1113 @Override
1114 public void onAnimationStart(Animation animation) { }
1115
1116 @Override
1117 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001118 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001119 }
1120
1121 @Override
1122 public void onAnimationRepeat(Animation animation) { }
1123 });
1124 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001125 return set;
1126 }
1127
Winson Chung399f6202014-03-19 10:47:20 -07001128 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001129 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001130 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001131 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001132 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
1133 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001134 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001135 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001136 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001137 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001138 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001139 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1140
1141 if (mNextAppTransitionScaleUp) {
1142 // Animation for the thumbnail zooming from its initial size to the full screen
1143 float scaleW = appWidth / thumbWidth;
1144 float scaleH = appHeight / thumbHeight;
1145 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001146 computePivot(mTmpRect.left, 1 / scaleW),
1147 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001148 scale.setInterpolator(mDecelerateInterpolator);
1149
1150 Animation alpha = new AlphaAnimation(1, 0);
1151 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1152
1153 // This AnimationSet uses the Interpolators assigned above.
1154 AnimationSet set = new AnimationSet(false);
1155 set.addAnimation(scale);
1156 set.addAnimation(alpha);
1157 a = set;
1158 } else {
1159 // Animation for the thumbnail zooming down from the full screen to its final size
1160 float scaleW = appWidth / thumbWidth;
1161 float scaleH = appHeight / thumbHeight;
1162 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001163 computePivot(mTmpRect.left, 1 / scaleW),
1164 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001165 }
1166
1167 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1168 }
1169
1170 /**
Winson Chung399f6202014-03-19 10:47:20 -07001171 * This animation is created when we are doing a thumbnail transition, for the activity that is
1172 * leaving, and the activity that is entering.
1173 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001174 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1175 int transit, int taskId) {
1176 final int appWidth = containingFrame.width();
1177 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001178 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001179 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001180 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001181 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001182 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001183 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001184 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1185
1186 switch (thumbTransitState) {
1187 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1188 // Entering app scales up with the thumbnail
1189 float scaleW = thumbWidth / appWidth;
1190 float scaleH = thumbHeight / appHeight;
1191 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001192 computePivot(mTmpRect.left, scaleW),
1193 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001194 break;
1195 }
1196 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1197 // Exiting app while the thumbnail is scaling up should fade or stay in place
1198 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1199 // Fade out while bringing up selected activity. This keeps the
1200 // current activity from showing through a launching wallpaper
1201 // activity.
1202 a = new AlphaAnimation(1, 0);
1203 } else {
1204 // noop animation
1205 a = new AlphaAnimation(1, 1);
1206 }
1207 break;
1208 }
1209 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1210 // Entering the other app, it should just be visible while we scale the thumbnail
1211 // down above it
1212 a = new AlphaAnimation(1, 1);
1213 break;
1214 }
1215 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1216 // Exiting the current app, the app should scale down with the thumbnail
1217 float scaleW = thumbWidth / appWidth;
1218 float scaleH = thumbHeight / appHeight;
1219 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001220 computePivot(mTmpRect.left, scaleW),
1221 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001222
1223 Animation alpha = new AlphaAnimation(1, 0);
1224
1225 AnimationSet set = new AnimationSet(true);
1226 set.addAnimation(scale);
1227 set.addAnimation(alpha);
1228 set.setZAdjustment(Animation.ZORDER_TOP);
1229 a = set;
1230 break;
1231 }
1232 default:
1233 throw new RuntimeException("Invalid thumbnail transition state");
1234 }
1235
1236 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1237 }
1238
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001239 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001240 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1241 final int left = mTmpFromClipRect.left;
1242 final int top = mTmpFromClipRect.top;
1243 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001244 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1245 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001246 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001247 float fromWidth = mTmpFromClipRect.width();
1248 float toWidth = mTmpToClipRect.width();
1249 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001250 // While the window might span the whole display, the actual content will be cropped to the
1251 // system decoration frame, for example when the window is docked. We need to take into
1252 // account the visible height when constructing the animation.
1253 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1254 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001255 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1256 // The final window is larger in both dimensions than current window (e.g. we are
1257 // maximizing), so we can simply unclip the new window and there will be no disappearing
1258 // frame.
1259 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1260 } else {
1261 // The disappearing window has one larger dimension. We need to apply scaling, so the
1262 // first frame of the entry animation matches the old window.
1263 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001264 // We might not be going exactly full screen, but instead be aligned under the status
1265 // bar using cropping. We still need to account for the cropped part, which will also
1266 // be scaled.
1267 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001268 }
1269
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001270 // We animate the translation from the old position of the removed window, to the new
1271 // position of the added window. The latter might not be full screen, for example docked for
1272 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001273 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001274 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001275 set.addAnimation(translate);
1276 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001277 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001278 return set;
1279 }
1280
Jorim Jaggic554b772015-06-04 16:07:57 -07001281 /**
1282 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1283 * frame of the transition doesn't change the visuals on screen, so we can start
1284 * directly with the second one
1285 */
1286 boolean canSkipFirstFrame() {
1287 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1288 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
1289 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1290 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001291
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001292 /**
1293 *
1294 * @param frame These are the bounds of the window when it finishes the animation. This is where
1295 * the animation must usually finish in entrance animation, as the next frame will
1296 * display the window at these coordinates. In case of exit animation, this is
1297 * where the animation must start, as the frame before the animation is displaying
1298 * the window at these bounds.
1299 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1300 * window might be obscured, usually by the system windows (status bar and
1301 * navigation bar) and we use content insets to convey that information. This
1302 * usually affects the animation aspects vertically, as the system decoration is
1303 * at the top and the bottom. For example when we animate from full screen to
1304 * recents, we want to exclude the covered parts, because they won't match the
1305 * thumbnail after the last frame is executed.
1306 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1307 * know about this to make the animation frames match. We currently use
1308 * this for freeform windows, which have larger surfaces to display
1309 * shadows. When we animate them from recents, we want to match the content
1310 * to the recents thumbnail and hence need to account for the surface being
1311 * bigger.
1312 */
Craig Mautner164d4bb2012-11-26 13:51:23 -08001313 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001314 int orientation, Rect frame, Rect displayFrame, Rect insets,
1315 @Nullable Rect surfaceInsets, boolean isVoiceInteraction, boolean freeform,
1316 int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001317 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001318 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
1319 || transit == TRANSIT_TASK_OPEN
1320 || transit == TRANSIT_TASK_TO_FRONT)) {
1321 a = loadAnimationRes(lp, enter
1322 ? com.android.internal.R.anim.voice_activity_open_enter
1323 : com.android.internal.R.anim.voice_activity_open_exit);
1324 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1325 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001326 + " anim=" + a + " transit=" + appTransitionToString(transit)
1327 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001328 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1329 || transit == TRANSIT_TASK_CLOSE
1330 || transit == TRANSIT_TASK_TO_BACK)) {
1331 a = loadAnimationRes(lp, enter
1332 ? com.android.internal.R.anim.voice_activity_close_enter
1333 : com.android.internal.R.anim.voice_activity_close_exit);
1334 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1335 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001336 + " anim=" + a + " transit=" + appTransitionToString(transit)
1337 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001338 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001339 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001340 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1341 "applyAnimation:"
1342 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1343 + " transit=" + appTransitionToString(transit)
1344 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001345 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1346 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001347 mNextAppTransitionEnter : mNextAppTransitionExit);
1348 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1349 "applyAnimation:"
1350 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001351 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001352 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001353 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1354 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1355 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1356 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001357 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1358 + " transit=" + appTransitionToString(transit)
1359 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001360 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001361 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001362 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1363 "applyAnimation:"
1364 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001365 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001366 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001367 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001368 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001369 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1370 "applyAnimation:"
1371 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001372 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001373 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001374 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1375 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001376 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001377 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001378 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001379 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001380 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1381 String animName = mNextAppTransitionScaleUp ?
1382 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1383 Slog.v(TAG, "applyAnimation:"
1384 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001385 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001386 + " Callers=" + Debug.getCallers(3));
1387 }
1388 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1389 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1390 mNextAppTransitionScaleUp =
1391 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1392 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001393 getThumbnailTransitionState(enter), orientation, transit, frame,
1394 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001395 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1396 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001397 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001398 Slog.v(TAG, "applyAnimation:"
1399 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001400 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001401 + " Callers=" + Debug.getCallers(3));
1402 }
1403 } else {
1404 int animAttr = 0;
1405 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001406 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001407 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001408 ? WindowAnimation_activityOpenEnterAnimation
1409 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001410 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001411 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001412 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001413 ? WindowAnimation_activityCloseEnterAnimation
1414 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001415 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001416 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001417 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001418 ? WindowAnimation_taskOpenEnterAnimation
1419 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001420 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001421 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001422 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001423 ? WindowAnimation_taskCloseEnterAnimation
1424 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001425 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001426 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001427 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001428 ? WindowAnimation_taskToFrontEnterAnimation
1429 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001430 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001431 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001432 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001433 ? WindowAnimation_taskToBackEnterAnimation
1434 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001435 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001436 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001437 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001438 ? WindowAnimation_wallpaperOpenEnterAnimation
1439 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001440 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001441 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001442 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001443 ? WindowAnimation_wallpaperCloseEnterAnimation
1444 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001445 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001446 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001447 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001448 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1449 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001450 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001451 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001452 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001453 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1454 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001455 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001456 case TRANSIT_TASK_OPEN_BEHIND:
1457 animAttr = enter
1458 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001459 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001460 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001461 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001462 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1463 "applyAnimation:"
1464 + " anim=" + a
1465 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001466 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001467 + " Callers=" + Debug.getCallers(3));
1468 }
1469 return a;
1470 }
1471
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001472 int getAppStackClipMode() {
1473 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
1474 ? STACK_CLIP_NONE
1475 : STACK_CLIP_AFTER_ANIM;
1476 }
1477
Craig Mautner164d4bb2012-11-26 13:51:23 -08001478 void postAnimationCallback() {
1479 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001480 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1481 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001482 mNextAppTransitionCallback = null;
1483 }
1484 }
1485
1486 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001487 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001488 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001489 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001490 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001491 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001492 mNextAppTransitionEnter = enterAnim;
1493 mNextAppTransitionExit = exitAnim;
1494 postAnimationCallback();
1495 mNextAppTransitionCallback = startedCallback;
1496 } else {
1497 postAnimationCallback();
1498 }
1499 }
1500
1501 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001502 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001503 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001504 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001505 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001506 putDefaultNextAppTransitionCoordinates(startX, startY, startX + startWidth,
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001507 startY + startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001508 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001509 }
1510 }
1511
Chet Haase10e23ab2015-02-11 15:08:38 -08001512 void overridePendingAppTransitionClipReveal(int startX, int startY,
1513 int startWidth, int startHeight) {
1514 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001515 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001516 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001517 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001518 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001519 }
1520 }
1521
Craig Mautner164d4bb2012-11-26 13:51:23 -08001522 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1523 IRemoteCallback startedCallback, boolean scaleUp) {
1524 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001525 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001526 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1527 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001528 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001529 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001530 postAnimationCallback();
1531 mNextAppTransitionCallback = startedCallback;
1532 } else {
1533 postAnimationCallback();
1534 }
1535 }
1536
Winson Chunga4ccb862014-08-22 15:26:27 -07001537 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001538 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001539 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001540 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001541 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1542 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001543 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001544 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1545 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001546 postAnimationCallback();
1547 mNextAppTransitionCallback = startedCallback;
1548 } else {
1549 postAnimationCallback();
1550 }
1551 }
1552
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001553 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001554 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1555 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001556 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001557 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001558 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1559 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001560 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001561 if (specs != null) {
1562 for (int i = 0; i < specs.length; i++) {
1563 AppTransitionAnimationSpec spec = specs[i];
1564 if (spec != null) {
1565 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1566 if (i == 0) {
1567 // In full screen mode, the transition code depends on the default spec
1568 // to be set.
1569 Rect rect = spec.rect;
1570 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Filip Gruszczynskie3264d82015-11-20 17:10:04 -08001571 rect.width(), rect.height(), spec.bitmap);
Jorim Jaggi43102412015-11-11 16:28:37 +01001572 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001573 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001574 }
1575 }
1576 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001577 mNextAppTransitionCallback = onAnimationStartedCallback;
1578 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001579 } else {
1580 postAnimationCallback();
1581 }
1582 }
1583
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001584 void overridePendingAppTransitionMultiThumbFuture(
1585 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1586 boolean scaleUp) {
1587 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001588 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001589 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1590 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001591 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1592 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001593 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001594 }
1595 }
1596
Winson Chung044d5292014-11-06 11:05:19 -08001597 void overrideInPlaceAppTransition(String packageName, int anim) {
1598 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001599 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001600 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1601 mNextAppTransitionPackage = packageName;
1602 mNextAppTransitionInPlace = anim;
1603 } else {
1604 postAnimationCallback();
1605 }
1606 }
1607
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001608 /**
1609 * If a future is set for the app transition specs, fetch it in another thread.
1610 */
1611 private void fetchAppTransitionSpecsFromFuture() {
1612 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1613 mNextAppTransitionAnimationsSpecsPending = true;
1614 final IAppTransitionAnimationSpecsFuture future
1615 = mNextAppTransitionAnimationsSpecsFuture;
1616 mNextAppTransitionAnimationsSpecsFuture = null;
1617 mDefaultExecutor.execute(new Runnable() {
1618 @Override
1619 public void run() {
1620 AppTransitionAnimationSpec[] specs = null;
1621 try {
1622 specs = future.get();
1623 } catch (RemoteException e) {
1624 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1625 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001626 synchronized (mService.mWindowMap) {
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001627 mNextAppTransitionAnimationsSpecsPending = false;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001628 overridePendingAppTransitionMultiThumb(specs,
1629 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1630 mNextAppTransitionScaleUp);
1631 mNextAppTransitionFutureCallback = null;
Filip Gruszczynski96daf322015-11-18 18:01:27 -08001632 if (specs != null) {
1633 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1634 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001635 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001636 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001637 }
1638 });
1639 }
1640 }
1641
Craig Mautner164d4bb2012-11-26 13:51:23 -08001642 @Override
1643 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001644 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001645 }
1646
Craig Mautner4b71aa12012-12-27 17:20:01 -08001647 /**
1648 * Returns the human readable name of a window transition.
1649 *
1650 * @param transition The window transition.
1651 * @return The transition symbolic name.
1652 */
1653 public static String appTransitionToString(int transition) {
1654 switch (transition) {
1655 case TRANSIT_UNSET: {
1656 return "TRANSIT_UNSET";
1657 }
1658 case TRANSIT_NONE: {
1659 return "TRANSIT_NONE";
1660 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001661 case TRANSIT_ACTIVITY_OPEN: {
1662 return "TRANSIT_ACTIVITY_OPEN";
1663 }
1664 case TRANSIT_ACTIVITY_CLOSE: {
1665 return "TRANSIT_ACTIVITY_CLOSE";
1666 }
1667 case TRANSIT_TASK_OPEN: {
1668 return "TRANSIT_TASK_OPEN";
1669 }
1670 case TRANSIT_TASK_CLOSE: {
1671 return "TRANSIT_TASK_CLOSE";
1672 }
1673 case TRANSIT_TASK_TO_FRONT: {
1674 return "TRANSIT_TASK_TO_FRONT";
1675 }
1676 case TRANSIT_TASK_TO_BACK: {
1677 return "TRANSIT_TASK_TO_BACK";
1678 }
1679 case TRANSIT_WALLPAPER_CLOSE: {
1680 return "TRANSIT_WALLPAPER_CLOSE";
1681 }
1682 case TRANSIT_WALLPAPER_OPEN: {
1683 return "TRANSIT_WALLPAPER_OPEN";
1684 }
1685 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1686 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1687 }
1688 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1689 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1690 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001691 case TRANSIT_TASK_OPEN_BEHIND: {
1692 return "TRANSIT_TASK_OPEN_BEHIND";
1693 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001694 case TRANSIT_ACTIVITY_RELAUNCH: {
1695 return "TRANSIT_ACTIVITY_RELAUNCH";
1696 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001697 default: {
1698 return "<UNKNOWN>";
1699 }
1700 }
1701 }
1702
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001703 private String appStateToString() {
1704 switch (mAppTransitionState) {
1705 case APP_STATE_IDLE:
1706 return "APP_STATE_IDLE";
1707 case APP_STATE_READY:
1708 return "APP_STATE_READY";
1709 case APP_STATE_RUNNING:
1710 return "APP_STATE_RUNNING";
1711 case APP_STATE_TIMEOUT:
1712 return "APP_STATE_TIMEOUT";
1713 default:
1714 return "unknown state=" + mAppTransitionState;
1715 }
1716 }
1717
1718 private String transitTypeToString() {
1719 switch (mNextAppTransitionType) {
1720 case NEXT_TRANSIT_TYPE_NONE:
1721 return "NEXT_TRANSIT_TYPE_NONE";
1722 case NEXT_TRANSIT_TYPE_CUSTOM:
1723 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001724 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1725 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001726 case NEXT_TRANSIT_TYPE_SCALE_UP:
1727 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1728 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1729 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1730 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1731 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001732 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1733 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1734 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1735 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001736 default:
1737 return "unknown type=" + mNextAppTransitionType;
1738 }
1739 }
1740
Craig Mautner164d4bb2012-11-26 13:51:23 -08001741 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001742 public void dump(PrintWriter pw, String prefix) {
1743 pw.print(prefix); pw.println(this);
1744 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001745 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001746 pw.print(prefix); pw.print("mNextAppTransitionType=");
1747 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001748 }
1749 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001750 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001751 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001752 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001753 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001754 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1755 pw.print(" mNextAppTransitionExit=0x");
1756 pw.println(Integer.toHexString(mNextAppTransitionExit));
1757 break;
Winson Chung044d5292014-11-06 11:05:19 -08001758 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001759 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001760 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001761 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001762 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1763 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001764 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001765 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001766 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001767 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001768 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001769 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001770 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001771 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001772 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001773 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001774 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001775 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001776 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1777 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001778 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001779 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1780 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1781 pw.println(mDefaultNextAppTransitionAnimationSpec);
1782 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1783 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001784 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1785 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001786 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001787 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001788 }
1789 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001790 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1791 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001792 }
1793 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001794
1795 public void setCurrentUser(int newUserId) {
1796 mCurrentUserId = newUserId;
1797 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001798
1799 /**
1800 * @return true if transition is not running and should not be skipped, false if transition is
1801 * already running
1802 */
1803 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent) {
1804 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
1805 + " transit=" + appTransitionToString(transit)
1806 + " " + this
1807 + " alwaysKeepCurrent=" + alwaysKeepCurrent
1808 + " Callers=" + Debug.getCallers(3));
1809 if (!isTransitionSet() || mNextAppTransition == TRANSIT_NONE) {
1810 setAppTransition(transit);
1811 } else if (!alwaysKeepCurrent) {
1812 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
1813 // Opening a new task always supersedes a close for the anim.
1814 setAppTransition(transit);
1815 } else if (transit == TRANSIT_ACTIVITY_OPEN
1816 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
1817 // Opening a new activity always supersedes a close for the anim.
1818 setAppTransition(transit);
1819 }
1820 }
1821 boolean prepared = prepare();
1822 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001823 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
1824 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001825 }
1826 return prepared;
1827 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001828}