blob: a1befe9117410899c7b20b9cd9176b90955c067f [file] [log] [blame]
Craig Mautner164d4bb2012-11-26 13:51:23 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Filip Gruszczynski82861362015-10-16 14:21:09 -070019import static android.view.WindowManagerInternal.AppTransitionListener;
20import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
21import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
22import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
23import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
24import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
25import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
26import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
27import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
28import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
29import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
30import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
31import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
32import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
33import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
34import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
35import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
36import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
37import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
38import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
39import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
40import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
41import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080042import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
43import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080044import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
45import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010046import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
47import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
Filip Gruszczynski82861362015-10-16 14:21:09 -070048
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070049import android.annotation.Nullable;
Craig Mautner164d4bb2012-11-26 13:51:23 -080050import android.content.Context;
Winson21700932016-03-24 17:26:23 -070051import android.content.res.Configuration;
Craig Mautner164d4bb2012-11-26 13:51:23 -080052import android.graphics.Bitmap;
Winson Chung399f6202014-03-19 10:47:20 -070053import android.graphics.Rect;
Craig Mautner164d4bb2012-11-26 13:51:23 -080054import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010055import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080056import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010057import android.os.RemoteException;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080058import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080059import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070060import android.util.SparseArray;
61import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010062import android.view.IAppTransitionAnimationSpecsFuture;
Craig Mautner164d4bb2012-11-26 13:51:23 -080063import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080064import android.view.animation.AlphaAnimation;
65import android.view.animation.Animation;
66import android.view.animation.AnimationSet;
67import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070068import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080069import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070070import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080071import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070072import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070073
Craig Mautner164d4bb2012-11-26 13:51:23 -080074import com.android.internal.util.DumpUtils.Dump;
75import com.android.server.AttributeCache;
76import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -080077import com.android.server.wm.animation.ClipRectLRAnimation;
78import com.android.server.wm.animation.ClipRectTBAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080079
80import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010081import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010082import java.util.concurrent.ExecutorService;
83import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -080084
Craig Mautner164d4bb2012-11-26 13:51:23 -080085// State management of app transitions. When we are preparing for a
86// transition, mNextAppTransition will be the kind of transition to
87// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
88// mOpeningApps and mClosingApps are the lists of tokens that will be
89// made visible or hidden at the next transition.
90public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080091 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070092 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080093
Craig Mautner4b71aa12012-12-27 17:20:01 -080094 /** Not set up for a transition. */
95 public static final int TRANSIT_UNSET = -1;
96 /** No animation for transition. */
97 public static final int TRANSIT_NONE = 0;
98 /** 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 -070099 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800100 /** The window in the top-most activity is being closed to reveal the
101 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700102 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800103 /** A window in a new task is being opened on top of an existing one
104 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700105 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800106 /** A window in the top-most activity is being closed to reveal the
107 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700108 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800109 /** A window in an existing task is being displayed on top of an existing one
110 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700111 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800112 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700113 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800114 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
115 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700116 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800117 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
118 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700119 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800120 /** A window in a new activity is being opened on top of an existing one, and both are on top
121 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700122 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800123 /** The window in the top-most activity is being closed to reveal the previous activity, and
124 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700125 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
126 /** A window in a new task is being opened behind an existing one in another activity's task.
127 * The new window will show briefly and then be gone. */
128 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800129 /** A window in a task is being animated in-place. */
130 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700131 /** An activity is being relaunched (e.g. due to configuration change). */
132 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Jorim Jaggi192086e2016-03-11 17:17:03 +0100133 /** A task is being docked from recents. */
134 public static final int TRANSIT_DOCK_TASK_FROM_RECENTS = 19;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800135
Winson Chunga4ccb862014-08-22 15:26:27 -0700136 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700137 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800138 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700139 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800140
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800141 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800142
143 /** Interpolator to be used for animations that respond directly to a touch */
144 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
145 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
146
147 /**
148 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
149 * involved, to make it more understandable.
150 */
151 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700152 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
153 private static final int THUMBNAIL_APP_TRANSITION_ALPHA_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700154 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800155
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800156 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800157 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800158
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800159 private int mNextAppTransition = TRANSIT_UNSET;
160
161 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
162 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
163 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
164 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
165 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700166 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
167 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800168 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800169 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800170 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
171
Winson Chung399f6202014-03-19 10:47:20 -0700172 // These are the possible states for the enter/exit activities during a thumbnail transition
173 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
174 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
175 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
176 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
177
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800178 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800179 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800180 private boolean mNextAppTransitionScaleUp;
181 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100182 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700183 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800184 private int mNextAppTransitionEnter;
185 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800186 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700187
188 // Keyed by task id.
189 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
190 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100191 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
192 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700193 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
194
Winson Chunga4ccb862014-08-22 15:26:27 -0700195 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800196
Winson Chung2820c452014-04-15 15:34:44 -0700197 private Rect mTmpFromClipRect = new Rect();
198 private Rect mTmpToClipRect = new Rect();
199
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700200 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700201
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800202 private final static int APP_STATE_IDLE = 0;
203 private final static int APP_STATE_READY = 1;
204 private final static int APP_STATE_RUNNING = 2;
205 private final static int APP_STATE_TIMEOUT = 3;
206 private int mAppTransitionState = APP_STATE_IDLE;
207
208 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800209 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700210 private final Interpolator mThumbnailFadeInInterpolator;
211 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800212 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700213 private final Interpolator mFastOutLinearInInterpolator;
214 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
215
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700216 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800217
Amith Yamasani4befbec2013-07-10 16:18:01 -0700218 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800219 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700220
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100221 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100222 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100223
Jorim Jaggif97ed922016-02-18 18:57:07 -0800224 private int mLastClipRevealMaxTranslation;
225 private boolean mLastHadClipReveal;
226
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800227 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800228 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800229 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800230 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
231 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700232 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
233 com.android.internal.R.interpolator.fast_out_linear_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800234 mConfigShortAnimTime = context.getResources().getInteger(
235 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800236 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
237 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700238 mThumbnailFadeInInterpolator = new Interpolator() {
239 @Override
240 public float getInterpolation(float input) {
241 // Linear response for first fraction, then complete after that.
242 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
243 return 0f;
244 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700245 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700246 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700247 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700248 }
249 };
250 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800251 @Override
252 public float getInterpolation(float input) {
253 // Linear response for first fraction, then complete after that.
254 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700255 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
256 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800257 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700258 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800259 }
260 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700261 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
262 * mContext.getResources().getDisplayMetrics().density);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800263 }
264
265 boolean isTransitionSet() {
266 return mNextAppTransition != TRANSIT_UNSET;
267 }
268
Craig Mautner164d4bb2012-11-26 13:51:23 -0800269 boolean isTransitionEqual(int transit) {
270 return mNextAppTransition == transit;
271 }
272
273 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800274 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800275 }
276
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700277 private void setAppTransition(int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800278 mNextAppTransition = transit;
279 }
280
281 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800282 return mAppTransitionState == APP_STATE_READY
283 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800284 }
285
Craig Mautnerae446592012-12-06 19:05:05 -0800286 void setReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800287 mAppTransitionState = APP_STATE_READY;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100288 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800289 }
290
291 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800292 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800293 }
294
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800295 void setIdle() {
296 mAppTransitionState = APP_STATE_IDLE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800297 }
298
299 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800300 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800301 }
302
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800303 void setTimeout() {
304 mAppTransitionState = APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800305 }
306
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700307 Bitmap getAppTransitionThumbnailHeader(int taskId) {
308 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800309 if (spec == null) {
310 spec = mDefaultNextAppTransitionAnimationSpec;
311 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700312 return spec != null ? spec.bitmap : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800313 }
314
Winson Chunga4ccb862014-08-22 15:26:27 -0700315 /** Returns whether the next thumbnail transition is aspect scaled up. */
316 boolean isNextThumbnailTransitionAspectScaled() {
317 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
318 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
319 }
320
321 /** Returns whether the next thumbnail transition is scaling up. */
322 boolean isNextThumbnailTransitionScaleUp() {
323 return mNextAppTransitionScaleUp;
324 }
325
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800326 boolean isNextAppTransitionThumbnailUp() {
327 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
328 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
329 }
330
331 boolean isNextAppTransitionThumbnailDown() {
332 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
333 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
334 }
335
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100336 /**
337 * @return true if and only if we are currently fetching app transition specs from the future
338 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
339 */
340 boolean isFetchingAppTransitionsSpecs() {
341 return mNextAppTransitionAnimationsSpecsPending;
342 }
343
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700344 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800345 if (!isRunning()) {
346 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100347 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800348 mLastHadClipReveal = false;
349 mLastClipRevealMaxTranslation = 0;
350 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700351 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800352 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700353 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800354 }
355
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800356 void goodToGo(AppWindowAnimator topOpeningAppAnimator, AppWindowAnimator topClosingAppAnimator,
357 ArraySet<AppWindowToken> openingApps, ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800358 mNextAppTransition = TRANSIT_UNSET;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800359 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100360 notifyAppTransitionStartingLocked(
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800361 topOpeningAppAnimator != null ? topOpeningAppAnimator.mAppToken.token : null,
362 topClosingAppAnimator != null ? topClosingAppAnimator.mAppToken.token : null,
363 topOpeningAppAnimator != null ? topOpeningAppAnimator.animation : null,
364 topClosingAppAnimator != null ? topClosingAppAnimator.animation : null);
365 mService.getDefaultDisplayContentLocked().getDockedDividerController()
366 .notifyAppTransitionStarting(openingApps, closingApps);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800367 }
368
369 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800370 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800371 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700372 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi65193992015-11-23 16:49:59 -0800373 mNextAppTransitionAnimationsSpecsFuture = null;
374 mDefaultNextAppTransitionAnimationSpec = null;
375 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800376 }
377
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800378 void freeze() {
379 setAppTransition(AppTransition.TRANSIT_UNSET);
380 clear();
381 setReady();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100382 notifyAppTransitionCancelledLocked();
383 }
384
385 void registerListenerLocked(AppTransitionListener listener) {
386 mListeners.add(listener);
387 }
388
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700389 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100390 for (int i = 0; i < mListeners.size(); i++) {
391 mListeners.get(i).onAppTransitionFinishedLocked(token);
392 }
393 }
394
395 private void notifyAppTransitionPendingLocked() {
396 for (int i = 0; i < mListeners.size(); i++) {
397 mListeners.get(i).onAppTransitionPendingLocked();
398 }
399 }
400
401 private void notifyAppTransitionCancelledLocked() {
402 for (int i = 0; i < mListeners.size(); i++) {
403 mListeners.get(i).onAppTransitionCancelledLocked();
404 }
405 }
406
407 private void notifyAppTransitionStartingLocked(IBinder openToken,
408 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
409 for (int i = 0; i < mListeners.size(); i++) {
410 mListeners.get(i).onAppTransitionStartingLocked(openToken, closeToken, openAnimation,
411 closeAnimation);
412 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800413 }
414
Craig Mautner164d4bb2012-11-26 13:51:23 -0800415 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
416 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
417 + (lp != null ? lp.packageName : null)
418 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
419 if (lp != null && lp.windowAnimations != 0) {
420 // If this is a system resource, don't try to load it from the
421 // application resources. It is nice to avoid loading application
422 // resources if we can.
423 String packageName = lp.packageName != null ? lp.packageName : "android";
424 int resId = lp.windowAnimations;
425 if ((resId&0xFF000000) == 0x01000000) {
426 packageName = "android";
427 }
428 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
429 + packageName);
430 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700431 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800432 }
433 return null;
434 }
435
436 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
437 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
438 + packageName + " resId=0x" + Integer.toHexString(resId));
439 if (packageName != null) {
440 if ((resId&0xFF000000) == 0x01000000) {
441 packageName = "android";
442 }
443 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
444 + packageName);
445 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700446 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800447 }
448 return null;
449 }
450
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700451 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800452 int anim = 0;
453 Context context = mContext;
454 if (animAttr >= 0) {
455 AttributeCache.Entry ent = getCachedAnimations(lp);
456 if (ent != null) {
457 context = ent.context;
458 anim = ent.array.getResourceId(animAttr, 0);
459 }
460 }
461 if (anim != 0) {
462 return AnimationUtils.loadAnimation(context, anim);
463 }
464 return null;
465 }
466
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700467 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
468 Context context = mContext;
469 if (resId >= 0) {
470 AttributeCache.Entry ent = getCachedAnimations(lp);
471 if (ent != null) {
472 context = ent.context;
473 }
474 return AnimationUtils.loadAnimation(context, resId);
475 }
476 return null;
477 }
478
479 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800480 int anim = 0;
481 Context context = mContext;
482 if (resId >= 0) {
483 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
484 if (ent != null) {
485 context = ent.context;
486 anim = resId;
487 }
488 }
489 if (anim != 0) {
490 return AnimationUtils.loadAnimation(context, anim);
491 }
492 return null;
493 }
494
Craig Mautner164d4bb2012-11-26 13:51:23 -0800495 /**
496 * Compute the pivot point for an animation that is scaling from a small
497 * rect on screen to a larger rect. The pivot point varies depending on
498 * the distance between the inner and outer edges on both sides. This
499 * function computes the pivot point for one dimension.
500 * @param startPos Offset from left/top edge of outer rectangle to
501 * left/top edge of inner rectangle.
502 * @param finalScale The scaling factor between the size of the outer
503 * and inner rectangles.
504 */
505 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800506
507 /*
508 Theorem of intercepting lines:
509
510 + + +-----------------------------------------------+
511 | | | |
512 | | | |
513 | | | |
514 | | | |
515 x | y | | |
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 |
555 |
556 + ++
557 p ++
558
559 scale = (x - y) / x
560 <=> x = -y / (scale - 1)
561 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800562 final float denom = finalScale-1;
563 if (Math.abs(denom) < .0001f) {
564 return startPos;
565 }
566 return -startPos / denom;
567 }
568
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700569 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
570 Rect containingFrame) {
571 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700572 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700573 final int appWidth = containingFrame.width();
574 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800575 if (enter) {
576 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700577 float scaleW = mTmpRect.width() / (float) appWidth;
578 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800579 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700580 computePivot(mTmpRect.left, scaleW),
581 computePivot(mTmpRect.right, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800582 scale.setInterpolator(mDecelerateInterpolator);
583
Craig Mautner164d4bb2012-11-26 13:51:23 -0800584 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700585 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800586
587 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800588 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800589 set.addAnimation(alpha);
590 set.setDetachWallpaper(true);
591 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800592 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
593 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800594 // If we are on top of the wallpaper, we need an animation that
595 // correctly handles the wallpaper staying static behind all of
596 // the animated elements. To do this, will just have the existing
597 // element fade out.
598 a = new AlphaAnimation(1, 0);
599 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800600 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800601 // For normal animations, the exiting element just holds in place.
602 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800603 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800604
605 // Pick the desired duration. If this is an inter-activity transition,
606 // it is the standard duration for that. Otherwise we use the longer
607 // task transition duration.
608 final long duration;
609 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800610 case TRANSIT_ACTIVITY_OPEN:
611 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800612 duration = mConfigShortAnimTime;
613 break;
614 default:
615 duration = DEFAULT_APP_TRANSITION_DURATION;
616 break;
617 }
618 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800619 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800620 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800621 a.initialize(appWidth, appHeight, appWidth, appHeight);
622 return a;
623 }
624
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700625 private void getDefaultNextAppTransitionStartRect(Rect rect) {
626 if (mDefaultNextAppTransitionAnimationSpec == null ||
627 mDefaultNextAppTransitionAnimationSpec.rect == null) {
628 Slog.wtf(TAG, "Starting rect for app requested, but none available", new Throwable());
629 rect.setEmpty();
630 } else {
631 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
632 }
633 }
634
635 void getNextAppTransitionStartRect(int taskId, Rect rect) {
636 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800637 if (spec == null) {
638 spec = mDefaultNextAppTransitionAnimationSpec;
639 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700640 if (spec == null || spec.rect == null) {
641 Slog.wtf(TAG, "Starting rect for task: " + taskId + " requested, but not available",
642 new Throwable());
643 rect.setEmpty();
644 } else {
645 rect.set(spec.rect);
646 }
647 }
648
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800649 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
650 Bitmap bitmap) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700651 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800652 bitmap, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700653 }
654
Jorim Jaggif97ed922016-02-18 18:57:07 -0800655 /**
656 * @return the duration of the last clip reveal animation
657 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800658 long getLastClipRevealTransitionDuration() {
659 return mLastClipRevealTransitionDuration;
660 }
661
662 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800663 * @return the maximum distance the app surface is traveling of the last clip reveal animation
664 */
665 int getLastClipRevealMaxTranslation() {
666 return mLastClipRevealMaxTranslation;
667 }
668
669 /**
670 * @return true if in the last app transition had a clip reveal animation, false otherwise
671 */
672 boolean hadClipRevealAnimation() {
673 return mLastHadClipReveal;
674 }
675
676 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800677 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
678 * the start rect is outside of the target rect, and there is a lot of movement going on.
679 *
680 * @param cutOff whether the start rect was not fully contained by the end rect
681 * @param translationX the total translation the surface moves in x direction
682 * @param translationY the total translation the surfaces moves in y direction
683 * @param displayFrame our display frame
684 *
685 * @return the duration of the clip reveal animation, in milliseconds
686 */
687 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
688 float translationY, Rect displayFrame) {
689 if (!cutOff) {
690 return DEFAULT_APP_TRANSITION_DURATION;
691 }
692 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
693 Math.abs(translationY) / displayFrame.height());
694 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
695 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
696 }
697
698 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
699 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800700 final Animation anim;
701 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700702 final int appWidth = appFrame.width();
703 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800704
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700705 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700706 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700707 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700708
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700709 float t = 0f;
710 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800711 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700712 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800713 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
714 int translationX = 0;
715 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700716 int centerX = mTmpRect.centerX();
717 int centerY = mTmpRect.centerY();
718 int halfWidth = mTmpRect.width() / 2;
719 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800720 int clipStartX = centerX - halfWidth - appFrame.left;
721 int clipStartY = centerY - halfHeight - appFrame.top;
722 boolean cutOff = false;
723
724 // If the starting rectangle is fully or partially outside of the target rectangle, we
725 // need to start the clipping at the edge and then achieve the rest with translation
726 // and extending the clip rect from that edge.
727 if (appFrame.top > centerY - halfHeight) {
728 translationY = (centerY - halfHeight) - appFrame.top;
729 translationYCorrection = 0;
730 clipStartY = 0;
731 cutOff = true;
732 }
733 if (appFrame.left > centerX - halfWidth) {
734 translationX = (centerX - halfWidth) - appFrame.left;
735 clipStartX = 0;
736 cutOff = true;
737 }
738 if (appFrame.right < centerX + halfWidth) {
739 translationX = (centerX + halfWidth) - appFrame.right;
740 clipStartX = appWidth - mTmpRect.width();
741 cutOff = true;
742 }
743 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
744 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700745
746 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800747 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800748 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700749 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800750 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700751
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800752 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
753 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
754 : mLinearOutSlowInInterpolator);
755 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800756
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800757 Animation clipAnimTB = new ClipRectTBAnimation(
758 clipStartY, clipStartY + mTmpRect.height(),
759 0, appHeight,
760 translationYCorrection, 0,
761 mLinearOutSlowInInterpolator);
762 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
763 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800764
765 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800766 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700767 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800768 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700769 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800770
771 AnimationSet set = new AnimationSet(false);
772 set.addAnimation(clipAnimLR);
773 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700774 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800775 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700776 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800777 set.initialize(appWidth, appHeight, appWidth, appHeight);
778 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800779 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800780 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800781
782 // If the start rect was full inside the target rect (cutOff == false), we don't need
783 // to store the translation, because it's only used if cutOff == true.
784 mLastClipRevealMaxTranslation = cutOff
785 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800786 } else {
787 final long duration;
788 switch (transit) {
789 case TRANSIT_ACTIVITY_OPEN:
790 case TRANSIT_ACTIVITY_CLOSE:
791 duration = mConfigShortAnimTime;
792 break;
793 default:
794 duration = DEFAULT_APP_TRANSITION_DURATION;
795 break;
796 }
797 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
798 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
799 // If we are on top of the wallpaper, we need an animation that
800 // correctly handles the wallpaper staying static behind all of
801 // the animated elements. To do this, will just have the existing
802 // element fade out.
803 anim = new AlphaAnimation(1, 0);
804 anim.setDetachWallpaper(true);
805 } else {
806 // For normal animations, the exiting element just holds in place.
807 anim = new AlphaAnimation(1, 1);
808 }
809 anim.setInterpolator(mDecelerateInterpolator);
810 anim.setDuration(duration);
811 anim.setFillAfter(true);
812 }
813 return anim;
814 }
815
Winson Chung399f6202014-03-19 10:47:20 -0700816 /**
817 * Prepares the specified animation with a standard duration, interpolator, etc.
818 */
Winson Chung5393dff2014-05-08 14:25:43 -0700819 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
820 int duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700821 if (duration > 0) {
822 a.setDuration(duration);
823 }
Winson Chung5393dff2014-05-08 14:25:43 -0700824 a.setFillAfter(true);
825 a.setInterpolator(interpolator);
826 a.initialize(appWidth, appHeight, appWidth, appHeight);
827 return a;
828 }
829
830 /**
831 * Prepares the specified animation with a standard duration, interpolator, etc.
832 */
Winson Chung399f6202014-03-19 10:47:20 -0700833 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800834 // Pick the desired duration. If this is an inter-activity transition,
835 // it is the standard duration for that. Otherwise we use the longer
836 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700837 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800838 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800839 case TRANSIT_ACTIVITY_OPEN:
840 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800841 duration = mConfigShortAnimTime;
842 break;
843 default:
844 duration = DEFAULT_APP_TRANSITION_DURATION;
845 break;
846 }
Winson Chung5393dff2014-05-08 14:25:43 -0700847 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
848 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800849 }
850
Winson Chung399f6202014-03-19 10:47:20 -0700851 /**
852 * Return the current thumbnail transition state.
853 */
854 int getThumbnailTransitionState(boolean enter) {
855 if (enter) {
856 if (mNextAppTransitionScaleUp) {
857 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
858 } else {
859 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
860 }
861 } else {
862 if (mNextAppTransitionScaleUp) {
863 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
864 } else {
865 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
866 }
867 }
868 }
869
870 /**
871 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700872 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700873 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700874 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, Bitmap thumbnailHeader,
875 final int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700876 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700877 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700878 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700879 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chung399f6202014-03-19 10:47:20 -0700880 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700881 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700882
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700883 float scaleW = appWidth / thumbWidth;
Winson Chunga4ccb862014-08-22 15:26:27 -0700884 float unscaledHeight = thumbHeight * scaleW;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700885 getNextAppTransitionStartRect(taskId, mTmpRect);
Filip Gruszczynski565a9df2016-01-22 11:10:42 -0800886 final float unscaledStartY = mTmpRect.top - (unscaledHeight - thumbHeight) / 2f;
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800887 final float toY = appRect.top + -unscaledStartY;
Winson Chung399f6202014-03-19 10:47:20 -0700888 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700889 // Animation up from the thumbnail to the full screen
890 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700891 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800892 scale.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700893 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800894 Animation alpha = new AlphaAnimation(1f, 0f);
Winson Chunga4ccb862014-08-22 15:26:27 -0700895 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
896 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700897 final float toX = appRect.left + appRect.width() / 2 -
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700898 (mTmpRect.left + thumbWidth / 2);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700899 Animation translate = new TranslateAnimation(0, toX, 0, toY);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800900 translate.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700901 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700902
903 // This AnimationSet uses the Interpolators assigned above.
904 AnimationSet set = new AnimationSet(false);
905 set.addAnimation(scale);
906 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -0700907 set.addAnimation(translate);
Winson Chung399f6202014-03-19 10:47:20 -0700908 a = set;
909 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700910 // Animation down from the full screen to the thumbnail
911 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700912 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800913 scale.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700914 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
915 Animation alpha = new AlphaAnimation(0f, 1f);
916 alpha.setInterpolator(mThumbnailFadeInInterpolator);
917 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
Filip Gruszczynski565a9df2016-01-22 11:10:42 -0800918 final float toX = appRect.left + appRect.width() / 2 -
919 (mTmpRect.left + thumbWidth / 2);
920 Animation translate = new TranslateAnimation(toX, 0, toY, 0);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800921 translate.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700922 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700923
Winson Chunga4ccb862014-08-22 15:26:27 -0700924 // This AnimationSet uses the Interpolators assigned above.
925 AnimationSet set = new AnimationSet(false);
926 set.addAnimation(scale);
927 set.addAnimation(alpha);
928 set.addAnimation(translate);
929 a = set;
930
931 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700932 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800933 TOUCH_RESPONSE_INTERPOLATOR);
Winson Chung399f6202014-03-19 10:47:20 -0700934 }
935
936 /**
937 * This alternate animation is created when we are doing a thumbnail transition, for the
938 * activity that is leaving, and the activity that is entering.
939 */
Winson Chunga4ccb862014-08-22 15:26:27 -0700940 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700941 int orientation, int transit, Rect containingFrame, Rect contentInsets,
942 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700943 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700944 final int appWidth = containingFrame.width();
945 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700946 getDefaultNextAppTransitionStartRect(mTmpRect);
947 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700948 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700949 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -0700950 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winson21700932016-03-24 17:26:23 -0700951 final int thumbStartX = mTmpRect.left - containingFrame.left;
952 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -0700953
Winson Chung2820c452014-04-15 15:34:44 -0700954 // Used for the ENTER_SCALE_UP and EXIT_SCALE_DOWN transitions
955 float scale = 1f;
956 int scaledTopDecor = 0;
957
Winson Chung399f6202014-03-19 10:47:20 -0700958 switch (thumbTransitState) {
959 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700960 if (freeform) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700961 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700962 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -0700963 } else {
Winson21700932016-03-24 17:26:23 -0700964 AnimationSet set = new AnimationSet(true);
965
966 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700967 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700968 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800969
970 // Containing frame is in screen space, but we need the clip rect in the
971 // app space.
972 mTmpFromClipRect.offsetTo(0, 0);
973 mTmpToClipRect.offsetTo(0, 0);
974
975 // Exclude insets region from the source clip.
976 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700977 mNextAppTransitionInsets.set(contentInsets);
978
Winson21700932016-03-24 17:26:23 -0700979 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
980 // We scale the width and clip to the top/left square
981 scale = thumbWidth / (appWidth - contentInsets.left - contentInsets.right);
982 scaledTopDecor = (int) (scale * contentInsets.top);
983 int unscaledThumbHeight = (int) (thumbHeight / scale);
984 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700985
Winson21700932016-03-24 17:26:23 -0700986 Animation scaleAnim = new ScaleAnimation(scale, 1, scale, 1,
987 computePivot(mTmpRect.left - containingFrame.left, scale),
988 computePivot(mTmpRect.top - containingFrame.top, scale));
989 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
990 Animation translateAnim = new TranslateAnimation(0, 0, -scaledTopDecor, 0);
991
992 set.addAnimation(clipAnim);
993 set.addAnimation(scaleAnim);
994 set.addAnimation(translateAnim);
995
996 } else {
997 // In landscape, we don't scale at all and only crop
998 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
999 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1000
1001 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
1002 Animation translateAnim = new TranslateAnimation(thumbStartX, 0,
1003 thumbStartY - contentInsets.top, 0);
1004
1005 set.addAnimation(clipAnim);
1006 set.addAnimation(translateAnim);
1007 }
1008
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001009 a = set;
Winson21700932016-03-24 17:26:23 -07001010 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001011 }
Winson Chung399f6202014-03-19 10:47:20 -07001012 break;
1013 }
1014 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001015 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001016 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001017 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001018 // activity.
1019 a = new AlphaAnimation(1, 0);
1020 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001021 a = new AlphaAnimation(1, 1);
1022 }
1023 break;
1024 }
1025 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001026 // Target app window during the scale down
1027 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1028 // Fade in the destination activity if we are animating from a wallpaper
1029 // activity.
1030 a = new AlphaAnimation(0, 1);
1031 } else {
1032 a = new AlphaAnimation(1, 1);
1033 }
Winson Chung399f6202014-03-19 10:47:20 -07001034 break;
1035 }
1036 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001037 // App window scaling down from full screen
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001038 if (freeform) {
1039 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1040 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001041 } else {
Winson21700932016-03-24 17:26:23 -07001042 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001043 mTmpFromClipRect.set(containingFrame);
1044 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001045
1046 // Containing frame is in screen space, but we need the clip rect in the
1047 // app space.
1048 mTmpFromClipRect.offsetTo(0, 0);
1049 mTmpToClipRect.offsetTo(0, 0);
1050
1051 // Exclude insets region from the target clip.
1052 mTmpToClipRect.inset(contentInsets);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001053 mNextAppTransitionInsets.set(contentInsets);
1054
Winson21700932016-03-24 17:26:23 -07001055 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
1056 // We scale the width and clip to the top/left square
1057 scale = thumbWidth / (appWidth - contentInsets.left - contentInsets.right);
1058 scaledTopDecor = (int) (scale * contentInsets.top);
1059 int unscaledThumbHeight = (int) (thumbHeight / scale);
1060 mTmpToClipRect.bottom = mTmpToClipRect.top + unscaledThumbHeight;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001061
Winson21700932016-03-24 17:26:23 -07001062 Animation scaleAnim = new ScaleAnimation(1, scale, 1, scale,
1063 computePivot(mTmpRect.left - containingFrame.left, scale),
1064 computePivot(mTmpRect.top - containingFrame.top, scale));
1065 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
1066 Animation translateAnim = new TranslateAnimation(0, 0, 0, -scaledTopDecor);
1067
1068 set.addAnimation(clipAnim);
1069 set.addAnimation(scaleAnim);
1070 set.addAnimation(translateAnim);
1071
1072 } else {
1073 // In landscape, we don't scale at all and only crop
1074 mTmpToClipRect.bottom = mTmpToClipRect.top + thumbHeightI;
1075 mTmpToClipRect.right = mTmpToClipRect.left + thumbWidthI;
1076
1077 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
1078 Animation translateAnim = new TranslateAnimation(0, thumbStartX, 0,
1079 thumbStartY - contentInsets.top);
1080
1081 set.addAnimation(clipAnim);
1082 set.addAnimation(translateAnim);
1083 }
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001084
1085 a = set;
1086 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001087 }
Winson Chung399f6202014-03-19 10:47:20 -07001088 break;
1089 }
1090 default:
1091 throw new RuntimeException("Invalid thumbnail transition state");
1092 }
1093
Winson Chungab79fce2014-11-04 16:15:22 -08001094 int duration = Math.max(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION,
1095 THUMBNAIL_APP_TRANSITION_DURATION);
1096 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001097 TOUCH_RESPONSE_INTERPOLATOR);
Winson Chung399f6202014-03-19 10:47:20 -07001098 }
1099
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001100 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1101 @Nullable Rect surfaceInsets, int taskId) {
1102 getNextAppTransitionStartRect(taskId, mTmpRect);
1103 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1104 true);
1105 }
1106
1107 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1108 @Nullable Rect surfaceInsets, int taskId) {
1109 getNextAppTransitionStartRect(taskId, mTmpRect);
1110 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1111 false);
1112 }
1113
1114 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1115 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1116 final float sourceWidth = sourceFrame.width();
1117 final float sourceHeight = sourceFrame.height();
1118 final float destWidth = destFrame.width();
1119 final float destHeight = destFrame.height();
1120 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1121 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001122 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001123 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001124 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001125 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001126 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1127 // We want the scaling to happen from the center of the surface. In order to achieve that,
1128 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001129 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1130 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1131 final ScaleAnimation scale = enter ?
1132 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1133 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1134 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1135 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1136 final int destHCenter = destFrame.left + destFrame.width() / 2;
1137 final int destVCenter = destFrame.top + destFrame.height() / 2;
1138 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1139 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1140 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1141 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001142 set.addAnimation(scale);
1143 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001144
1145 final IRemoteCallback callback = mAnimationFinishedCallback;
1146 if (callback != null) {
1147 set.setAnimationListener(new Animation.AnimationListener() {
1148 @Override
1149 public void onAnimationStart(Animation animation) { }
1150
1151 @Override
1152 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001153 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001154 }
1155
1156 @Override
1157 public void onAnimationRepeat(Animation animation) { }
1158 });
1159 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001160 return set;
1161 }
1162
Winson Chung399f6202014-03-19 10:47:20 -07001163 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001164 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001165 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001166 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001167 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
1168 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001169 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001170 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001171 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001172 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001173 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001174 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1175
1176 if (mNextAppTransitionScaleUp) {
1177 // Animation for the thumbnail zooming from its initial size to the full screen
1178 float scaleW = appWidth / thumbWidth;
1179 float scaleH = appHeight / thumbHeight;
1180 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001181 computePivot(mTmpRect.left, 1 / scaleW),
1182 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001183 scale.setInterpolator(mDecelerateInterpolator);
1184
1185 Animation alpha = new AlphaAnimation(1, 0);
1186 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1187
1188 // This AnimationSet uses the Interpolators assigned above.
1189 AnimationSet set = new AnimationSet(false);
1190 set.addAnimation(scale);
1191 set.addAnimation(alpha);
1192 a = set;
1193 } else {
1194 // Animation for the thumbnail zooming down from the full screen to its final size
1195 float scaleW = appWidth / thumbWidth;
1196 float scaleH = appHeight / thumbHeight;
1197 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001198 computePivot(mTmpRect.left, 1 / scaleW),
1199 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001200 }
1201
1202 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1203 }
1204
1205 /**
Winson Chung399f6202014-03-19 10:47:20 -07001206 * This animation is created when we are doing a thumbnail transition, for the activity that is
1207 * leaving, and the activity that is entering.
1208 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001209 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1210 int transit, int taskId) {
1211 final int appWidth = containingFrame.width();
1212 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001213 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001214 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001215 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001216 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001217 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001218 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001219 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1220
1221 switch (thumbTransitState) {
1222 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1223 // Entering app scales up with the thumbnail
1224 float scaleW = thumbWidth / appWidth;
1225 float scaleH = thumbHeight / appHeight;
1226 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001227 computePivot(mTmpRect.left, scaleW),
1228 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001229 break;
1230 }
1231 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1232 // Exiting app while the thumbnail is scaling up should fade or stay in place
1233 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1234 // Fade out while bringing up selected activity. This keeps the
1235 // current activity from showing through a launching wallpaper
1236 // activity.
1237 a = new AlphaAnimation(1, 0);
1238 } else {
1239 // noop animation
1240 a = new AlphaAnimation(1, 1);
1241 }
1242 break;
1243 }
1244 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1245 // Entering the other app, it should just be visible while we scale the thumbnail
1246 // down above it
1247 a = new AlphaAnimation(1, 1);
1248 break;
1249 }
1250 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1251 // Exiting the current app, the app should scale down with the thumbnail
1252 float scaleW = thumbWidth / appWidth;
1253 float scaleH = thumbHeight / appHeight;
1254 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001255 computePivot(mTmpRect.left, scaleW),
1256 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001257
1258 Animation alpha = new AlphaAnimation(1, 0);
1259
1260 AnimationSet set = new AnimationSet(true);
1261 set.addAnimation(scale);
1262 set.addAnimation(alpha);
1263 set.setZAdjustment(Animation.ZORDER_TOP);
1264 a = set;
1265 break;
1266 }
1267 default:
1268 throw new RuntimeException("Invalid thumbnail transition state");
1269 }
1270
1271 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1272 }
1273
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001274 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001275 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1276 final int left = mTmpFromClipRect.left;
1277 final int top = mTmpFromClipRect.top;
1278 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001279 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1280 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001281 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001282 float fromWidth = mTmpFromClipRect.width();
1283 float toWidth = mTmpToClipRect.width();
1284 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001285 // While the window might span the whole display, the actual content will be cropped to the
1286 // system decoration frame, for example when the window is docked. We need to take into
1287 // account the visible height when constructing the animation.
1288 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1289 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001290 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1291 // The final window is larger in both dimensions than current window (e.g. we are
1292 // maximizing), so we can simply unclip the new window and there will be no disappearing
1293 // frame.
1294 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1295 } else {
1296 // The disappearing window has one larger dimension. We need to apply scaling, so the
1297 // first frame of the entry animation matches the old window.
1298 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001299 // We might not be going exactly full screen, but instead be aligned under the status
1300 // bar using cropping. We still need to account for the cropped part, which will also
1301 // be scaled.
1302 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001303 }
1304
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001305 // We animate the translation from the old position of the removed window, to the new
1306 // position of the added window. The latter might not be full screen, for example docked for
1307 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001308 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001309 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001310 set.addAnimation(translate);
1311 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001312 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001313 return set;
1314 }
1315
Jorim Jaggic554b772015-06-04 16:07:57 -07001316 /**
1317 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1318 * frame of the transition doesn't change the visuals on screen, so we can start
1319 * directly with the second one
1320 */
1321 boolean canSkipFirstFrame() {
1322 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1323 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
1324 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1325 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001326
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001327 /**
1328 *
1329 * @param frame These are the bounds of the window when it finishes the animation. This is where
1330 * the animation must usually finish in entrance animation, as the next frame will
1331 * display the window at these coordinates. In case of exit animation, this is
1332 * where the animation must start, as the frame before the animation is displaying
1333 * the window at these bounds.
1334 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1335 * window might be obscured, usually by the system windows (status bar and
1336 * navigation bar) and we use content insets to convey that information. This
1337 * usually affects the animation aspects vertically, as the system decoration is
1338 * at the top and the bottom. For example when we animate from full screen to
1339 * recents, we want to exclude the covered parts, because they won't match the
1340 * thumbnail after the last frame is executed.
1341 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1342 * know about this to make the animation frames match. We currently use
1343 * this for freeform windows, which have larger surfaces to display
1344 * shadows. When we animate them from recents, we want to match the content
1345 * to the recents thumbnail and hence need to account for the surface being
1346 * bigger.
1347 */
Craig Mautner164d4bb2012-11-26 13:51:23 -08001348 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001349 int orientation, Rect frame, Rect displayFrame, Rect insets,
1350 @Nullable Rect surfaceInsets, boolean isVoiceInteraction, boolean freeform,
1351 int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001352 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001353 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
1354 || transit == TRANSIT_TASK_OPEN
1355 || transit == TRANSIT_TASK_TO_FRONT)) {
1356 a = loadAnimationRes(lp, enter
1357 ? com.android.internal.R.anim.voice_activity_open_enter
1358 : com.android.internal.R.anim.voice_activity_open_exit);
1359 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1360 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001361 + " anim=" + a + " transit=" + appTransitionToString(transit)
1362 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001363 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1364 || transit == TRANSIT_TASK_CLOSE
1365 || transit == TRANSIT_TASK_TO_BACK)) {
1366 a = loadAnimationRes(lp, enter
1367 ? com.android.internal.R.anim.voice_activity_close_enter
1368 : com.android.internal.R.anim.voice_activity_close_exit);
1369 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1370 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001371 + " anim=" + a + " transit=" + appTransitionToString(transit)
1372 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001373 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001374 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001375 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1376 "applyAnimation:"
1377 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1378 + " transit=" + appTransitionToString(transit)
1379 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001380 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1381 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001382 mNextAppTransitionEnter : mNextAppTransitionExit);
1383 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1384 "applyAnimation:"
1385 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001386 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001387 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001388 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1389 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1390 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1391 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001392 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1393 + " transit=" + appTransitionToString(transit)
1394 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001395 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001396 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001397 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1398 "applyAnimation:"
1399 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001400 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001401 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001402 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001403 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001404 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1405 "applyAnimation:"
1406 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001407 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001408 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001409 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1410 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001411 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001412 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001413 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001414 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001415 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1416 String animName = mNextAppTransitionScaleUp ?
1417 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1418 Slog.v(TAG, "applyAnimation:"
1419 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001420 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001421 + " Callers=" + Debug.getCallers(3));
1422 }
1423 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1424 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1425 mNextAppTransitionScaleUp =
1426 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1427 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001428 getThumbnailTransitionState(enter), orientation, transit, frame,
1429 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001430 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1431 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001432 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001433 Slog.v(TAG, "applyAnimation:"
1434 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001435 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001436 + " Callers=" + Debug.getCallers(3));
1437 }
1438 } else {
1439 int animAttr = 0;
1440 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001441 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001442 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001443 ? WindowAnimation_activityOpenEnterAnimation
1444 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001445 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001446 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001447 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001448 ? WindowAnimation_activityCloseEnterAnimation
1449 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001450 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001451 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001452 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001453 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001454 ? WindowAnimation_taskOpenEnterAnimation
1455 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001456 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001457 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001458 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001459 ? WindowAnimation_taskCloseEnterAnimation
1460 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001461 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001462 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001463 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001464 ? WindowAnimation_taskToFrontEnterAnimation
1465 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001466 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001467 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001468 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001469 ? WindowAnimation_taskToBackEnterAnimation
1470 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001471 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001472 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001473 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001474 ? WindowAnimation_wallpaperOpenEnterAnimation
1475 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001476 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001477 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001478 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001479 ? WindowAnimation_wallpaperCloseEnterAnimation
1480 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001481 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001482 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001483 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001484 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1485 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001486 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001487 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001488 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001489 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1490 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001491 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001492 case TRANSIT_TASK_OPEN_BEHIND:
1493 animAttr = enter
1494 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001495 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001496 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001497 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001498 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1499 "applyAnimation:"
1500 + " anim=" + a
1501 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001502 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001503 + " Callers=" + Debug.getCallers(3));
1504 }
1505 return a;
1506 }
1507
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001508 int getAppStackClipMode() {
1509 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
1510 ? STACK_CLIP_NONE
1511 : STACK_CLIP_AFTER_ANIM;
1512 }
1513
Craig Mautner164d4bb2012-11-26 13:51:23 -08001514 void postAnimationCallback() {
1515 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001516 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1517 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001518 mNextAppTransitionCallback = null;
1519 }
1520 }
1521
1522 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001523 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001524 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001525 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001526 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001527 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001528 mNextAppTransitionEnter = enterAnim;
1529 mNextAppTransitionExit = exitAnim;
1530 postAnimationCallback();
1531 mNextAppTransitionCallback = startedCallback;
1532 } else {
1533 postAnimationCallback();
1534 }
1535 }
1536
1537 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001538 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001539 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001540 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001541 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001542 putDefaultNextAppTransitionCoordinates(startX, startY, startX + startWidth,
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001543 startY + startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001544 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001545 }
1546 }
1547
Chet Haase10e23ab2015-02-11 15:08:38 -08001548 void overridePendingAppTransitionClipReveal(int startX, int startY,
1549 int startWidth, int startHeight) {
1550 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001551 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001552 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001553 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001554 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001555 }
1556 }
1557
Craig Mautner164d4bb2012-11-26 13:51:23 -08001558 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1559 IRemoteCallback startedCallback, boolean scaleUp) {
1560 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001561 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001562 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1563 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001564 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001565 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001566 postAnimationCallback();
1567 mNextAppTransitionCallback = startedCallback;
1568 } else {
1569 postAnimationCallback();
1570 }
1571 }
1572
Winson Chunga4ccb862014-08-22 15:26:27 -07001573 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001574 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001575 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001576 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001577 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1578 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001579 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001580 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1581 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001582 postAnimationCallback();
1583 mNextAppTransitionCallback = startedCallback;
1584 } else {
1585 postAnimationCallback();
1586 }
1587 }
1588
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001589 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001590 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1591 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001592 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001593 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001594 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1595 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001596 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001597 if (specs != null) {
1598 for (int i = 0; i < specs.length; i++) {
1599 AppTransitionAnimationSpec spec = specs[i];
1600 if (spec != null) {
1601 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1602 if (i == 0) {
1603 // In full screen mode, the transition code depends on the default spec
1604 // to be set.
1605 Rect rect = spec.rect;
1606 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Filip Gruszczynskie3264d82015-11-20 17:10:04 -08001607 rect.width(), rect.height(), spec.bitmap);
Jorim Jaggi43102412015-11-11 16:28:37 +01001608 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001609 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001610 }
1611 }
1612 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001613 mNextAppTransitionCallback = onAnimationStartedCallback;
1614 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001615 } else {
1616 postAnimationCallback();
1617 }
1618 }
1619
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001620 void overridePendingAppTransitionMultiThumbFuture(
1621 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1622 boolean scaleUp) {
1623 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001624 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001625 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1626 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001627 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1628 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001629 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001630 }
1631 }
1632
Winson Chung044d5292014-11-06 11:05:19 -08001633 void overrideInPlaceAppTransition(String packageName, int anim) {
1634 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001635 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001636 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1637 mNextAppTransitionPackage = packageName;
1638 mNextAppTransitionInPlace = anim;
1639 } else {
1640 postAnimationCallback();
1641 }
1642 }
1643
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001644 /**
1645 * If a future is set for the app transition specs, fetch it in another thread.
1646 */
1647 private void fetchAppTransitionSpecsFromFuture() {
1648 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1649 mNextAppTransitionAnimationsSpecsPending = true;
1650 final IAppTransitionAnimationSpecsFuture future
1651 = mNextAppTransitionAnimationsSpecsFuture;
1652 mNextAppTransitionAnimationsSpecsFuture = null;
1653 mDefaultExecutor.execute(new Runnable() {
1654 @Override
1655 public void run() {
1656 AppTransitionAnimationSpec[] specs = null;
1657 try {
1658 specs = future.get();
1659 } catch (RemoteException e) {
1660 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1661 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001662 synchronized (mService.mWindowMap) {
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001663 mNextAppTransitionAnimationsSpecsPending = false;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001664 overridePendingAppTransitionMultiThumb(specs,
1665 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1666 mNextAppTransitionScaleUp);
1667 mNextAppTransitionFutureCallback = null;
Filip Gruszczynski96daf322015-11-18 18:01:27 -08001668 if (specs != null) {
1669 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1670 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001671 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001672 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001673 }
1674 });
1675 }
1676 }
1677
Craig Mautner164d4bb2012-11-26 13:51:23 -08001678 @Override
1679 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001680 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001681 }
1682
Craig Mautner4b71aa12012-12-27 17:20:01 -08001683 /**
1684 * Returns the human readable name of a window transition.
1685 *
1686 * @param transition The window transition.
1687 * @return The transition symbolic name.
1688 */
1689 public static String appTransitionToString(int transition) {
1690 switch (transition) {
1691 case TRANSIT_UNSET: {
1692 return "TRANSIT_UNSET";
1693 }
1694 case TRANSIT_NONE: {
1695 return "TRANSIT_NONE";
1696 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001697 case TRANSIT_ACTIVITY_OPEN: {
1698 return "TRANSIT_ACTIVITY_OPEN";
1699 }
1700 case TRANSIT_ACTIVITY_CLOSE: {
1701 return "TRANSIT_ACTIVITY_CLOSE";
1702 }
1703 case TRANSIT_TASK_OPEN: {
1704 return "TRANSIT_TASK_OPEN";
1705 }
1706 case TRANSIT_TASK_CLOSE: {
1707 return "TRANSIT_TASK_CLOSE";
1708 }
1709 case TRANSIT_TASK_TO_FRONT: {
1710 return "TRANSIT_TASK_TO_FRONT";
1711 }
1712 case TRANSIT_TASK_TO_BACK: {
1713 return "TRANSIT_TASK_TO_BACK";
1714 }
1715 case TRANSIT_WALLPAPER_CLOSE: {
1716 return "TRANSIT_WALLPAPER_CLOSE";
1717 }
1718 case TRANSIT_WALLPAPER_OPEN: {
1719 return "TRANSIT_WALLPAPER_OPEN";
1720 }
1721 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1722 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1723 }
1724 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1725 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1726 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001727 case TRANSIT_TASK_OPEN_BEHIND: {
1728 return "TRANSIT_TASK_OPEN_BEHIND";
1729 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001730 case TRANSIT_ACTIVITY_RELAUNCH: {
1731 return "TRANSIT_ACTIVITY_RELAUNCH";
1732 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001733 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1734 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1735 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001736 default: {
1737 return "<UNKNOWN>";
1738 }
1739 }
1740 }
1741
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001742 private String appStateToString() {
1743 switch (mAppTransitionState) {
1744 case APP_STATE_IDLE:
1745 return "APP_STATE_IDLE";
1746 case APP_STATE_READY:
1747 return "APP_STATE_READY";
1748 case APP_STATE_RUNNING:
1749 return "APP_STATE_RUNNING";
1750 case APP_STATE_TIMEOUT:
1751 return "APP_STATE_TIMEOUT";
1752 default:
1753 return "unknown state=" + mAppTransitionState;
1754 }
1755 }
1756
1757 private String transitTypeToString() {
1758 switch (mNextAppTransitionType) {
1759 case NEXT_TRANSIT_TYPE_NONE:
1760 return "NEXT_TRANSIT_TYPE_NONE";
1761 case NEXT_TRANSIT_TYPE_CUSTOM:
1762 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001763 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1764 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001765 case NEXT_TRANSIT_TYPE_SCALE_UP:
1766 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1767 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1768 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1769 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1770 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001771 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1772 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1773 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1774 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001775 default:
1776 return "unknown type=" + mNextAppTransitionType;
1777 }
1778 }
1779
Craig Mautner164d4bb2012-11-26 13:51:23 -08001780 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001781 public void dump(PrintWriter pw, String prefix) {
1782 pw.print(prefix); pw.println(this);
1783 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001784 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001785 pw.print(prefix); pw.print("mNextAppTransitionType=");
1786 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001787 }
1788 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001789 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001790 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001791 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001792 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001793 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1794 pw.print(" mNextAppTransitionExit=0x");
1795 pw.println(Integer.toHexString(mNextAppTransitionExit));
1796 break;
Winson Chung044d5292014-11-06 11:05:19 -08001797 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001798 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001799 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001800 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001801 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1802 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001803 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001804 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001805 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001806 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001807 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001808 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001809 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001810 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001811 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001812 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001813 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001814 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001815 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1816 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001817 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001818 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1819 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1820 pw.println(mDefaultNextAppTransitionAnimationSpec);
1821 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1822 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001823 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1824 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001825 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001826 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001827 }
1828 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001829 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1830 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001831 }
1832 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001833
1834 public void setCurrentUser(int newUserId) {
1835 mCurrentUserId = newUserId;
1836 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001837
1838 /**
1839 * @return true if transition is not running and should not be skipped, false if transition is
1840 * already running
1841 */
1842 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent) {
1843 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
1844 + " transit=" + appTransitionToString(transit)
1845 + " " + this
1846 + " alwaysKeepCurrent=" + alwaysKeepCurrent
1847 + " Callers=" + Debug.getCallers(3));
1848 if (!isTransitionSet() || mNextAppTransition == TRANSIT_NONE) {
1849 setAppTransition(transit);
1850 } else if (!alwaysKeepCurrent) {
1851 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
1852 // Opening a new task always supersedes a close for the anim.
1853 setAppTransition(transit);
1854 } else if (transit == TRANSIT_ACTIVITY_OPEN
1855 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
1856 // Opening a new activity always supersedes a close for the anim.
1857 setAppTransition(transit);
1858 }
1859 }
1860 boolean prepared = prepare();
1861 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001862 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
1863 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001864 }
1865 return prepared;
1866 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001867}