blob: 8e28bbc4474271a68b502cc1fbad56f46bf24d1c [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 */
Jorim Jaggide63d442016-03-14 14:56:56 +0100874 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
875 Bitmap thumbnailHeader, 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
Jorim Jaggide63d442016-03-14 14:56:56 +0100903 float thumbScale = thumbWidth / (appWidth - (contentInsets != null
904 ? contentInsets.left - contentInsets.right : 0));
905
906 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
907 mTmpToClipRect.set(appRect);
908
909 // Containing frame is in screen space, but we need the clip rect in the
910 // app space.
911 mTmpToClipRect.offsetTo(0, 0);
912 mTmpToClipRect.right = (int) (mTmpToClipRect.right * thumbScale);
913 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom * thumbScale);
914
915 if (contentInsets != null) {
916 mTmpToClipRect.inset((int) (-contentInsets.left * thumbScale),
917 (int) (-contentInsets.top * thumbScale),
918 (int) (-contentInsets.right * thumbScale),
919 (int) (-contentInsets.bottom * thumbScale));
920 }
921
922 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
923 clipAnim.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
924 clipAnim.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
925
Winson Chung399f6202014-03-19 10:47:20 -0700926 // This AnimationSet uses the Interpolators assigned above.
927 AnimationSet set = new AnimationSet(false);
928 set.addAnimation(scale);
929 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -0700930 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +0100931 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -0700932 a = set;
933 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700934 // Animation down from the full screen to the thumbnail
935 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700936 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800937 scale.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700938 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
939 Animation alpha = new AlphaAnimation(0f, 1f);
940 alpha.setInterpolator(mThumbnailFadeInInterpolator);
941 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
Filip Gruszczynski565a9df2016-01-22 11:10:42 -0800942 final float toX = appRect.left + appRect.width() / 2 -
943 (mTmpRect.left + thumbWidth / 2);
944 Animation translate = new TranslateAnimation(toX, 0, toY, 0);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800945 translate.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700946 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700947
Winson Chunga4ccb862014-08-22 15:26:27 -0700948 // This AnimationSet uses the Interpolators assigned above.
949 AnimationSet set = new AnimationSet(false);
950 set.addAnimation(scale);
951 set.addAnimation(alpha);
952 set.addAnimation(translate);
953 a = set;
954
955 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700956 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800957 TOUCH_RESPONSE_INTERPOLATOR);
Winson Chung399f6202014-03-19 10:47:20 -0700958 }
959
960 /**
961 * This alternate animation is created when we are doing a thumbnail transition, for the
962 * activity that is leaving, and the activity that is entering.
963 */
Winson Chunga4ccb862014-08-22 15:26:27 -0700964 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700965 int orientation, int transit, Rect containingFrame, Rect contentInsets,
966 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700967 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700968 final int appWidth = containingFrame.width();
969 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700970 getDefaultNextAppTransitionStartRect(mTmpRect);
971 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700972 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700973 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -0700974 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winson21700932016-03-24 17:26:23 -0700975 final int thumbStartX = mTmpRect.left - containingFrame.left;
976 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -0700977
Winson Chung2820c452014-04-15 15:34:44 -0700978 // Used for the ENTER_SCALE_UP and EXIT_SCALE_DOWN transitions
979 float scale = 1f;
980 int scaledTopDecor = 0;
981
Winson Chung399f6202014-03-19 10:47:20 -0700982 switch (thumbTransitState) {
983 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700984 if (freeform) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700985 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700986 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -0700987 } else {
Winson21700932016-03-24 17:26:23 -0700988 AnimationSet set = new AnimationSet(true);
989
990 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700991 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700992 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800993
994 // Containing frame is in screen space, but we need the clip rect in the
995 // app space.
996 mTmpFromClipRect.offsetTo(0, 0);
997 mTmpToClipRect.offsetTo(0, 0);
998
999 // Exclude insets region from the source clip.
1000 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001001 mNextAppTransitionInsets.set(contentInsets);
1002
Winson21700932016-03-24 17:26:23 -07001003 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
1004 // We scale the width and clip to the top/left square
1005 scale = thumbWidth / (appWidth - contentInsets.left - contentInsets.right);
1006 scaledTopDecor = (int) (scale * contentInsets.top);
1007 int unscaledThumbHeight = (int) (thumbHeight / scale);
1008 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001009
Winson21700932016-03-24 17:26:23 -07001010 Animation scaleAnim = new ScaleAnimation(scale, 1, scale, 1,
1011 computePivot(mTmpRect.left - containingFrame.left, scale),
1012 computePivot(mTmpRect.top - containingFrame.top, scale));
1013 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
1014 Animation translateAnim = new TranslateAnimation(0, 0, -scaledTopDecor, 0);
1015
1016 set.addAnimation(clipAnim);
1017 set.addAnimation(scaleAnim);
1018 set.addAnimation(translateAnim);
1019
1020 } else {
1021 // In landscape, we don't scale at all and only crop
1022 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1023 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1024
1025 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
1026 Animation translateAnim = new TranslateAnimation(thumbStartX, 0,
1027 thumbStartY - contentInsets.top, 0);
1028
1029 set.addAnimation(clipAnim);
1030 set.addAnimation(translateAnim);
1031 }
1032
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001033 a = set;
Winson21700932016-03-24 17:26:23 -07001034 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001035 }
Winson Chung399f6202014-03-19 10:47:20 -07001036 break;
1037 }
1038 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001039 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001040 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001041 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001042 // activity.
1043 a = new AlphaAnimation(1, 0);
1044 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001045 a = new AlphaAnimation(1, 1);
1046 }
1047 break;
1048 }
1049 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001050 // Target app window during the scale down
1051 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1052 // Fade in the destination activity if we are animating from a wallpaper
1053 // activity.
1054 a = new AlphaAnimation(0, 1);
1055 } else {
1056 a = new AlphaAnimation(1, 1);
1057 }
Winson Chung399f6202014-03-19 10:47:20 -07001058 break;
1059 }
1060 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001061 // App window scaling down from full screen
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001062 if (freeform) {
1063 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1064 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001065 } else {
Winson21700932016-03-24 17:26:23 -07001066 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001067 mTmpFromClipRect.set(containingFrame);
1068 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001069
1070 // Containing frame is in screen space, but we need the clip rect in the
1071 // app space.
1072 mTmpFromClipRect.offsetTo(0, 0);
1073 mTmpToClipRect.offsetTo(0, 0);
1074
1075 // Exclude insets region from the target clip.
1076 mTmpToClipRect.inset(contentInsets);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001077 mNextAppTransitionInsets.set(contentInsets);
1078
Winson21700932016-03-24 17:26:23 -07001079 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
1080 // We scale the width and clip to the top/left square
1081 scale = thumbWidth / (appWidth - contentInsets.left - contentInsets.right);
1082 scaledTopDecor = (int) (scale * contentInsets.top);
1083 int unscaledThumbHeight = (int) (thumbHeight / scale);
1084 mTmpToClipRect.bottom = mTmpToClipRect.top + unscaledThumbHeight;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001085
Winson21700932016-03-24 17:26:23 -07001086 Animation scaleAnim = new ScaleAnimation(1, scale, 1, scale,
1087 computePivot(mTmpRect.left - containingFrame.left, scale),
1088 computePivot(mTmpRect.top - containingFrame.top, scale));
1089 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
1090 Animation translateAnim = new TranslateAnimation(0, 0, 0, -scaledTopDecor);
1091
1092 set.addAnimation(clipAnim);
1093 set.addAnimation(scaleAnim);
1094 set.addAnimation(translateAnim);
1095
1096 } else {
1097 // In landscape, we don't scale at all and only crop
1098 mTmpToClipRect.bottom = mTmpToClipRect.top + thumbHeightI;
1099 mTmpToClipRect.right = mTmpToClipRect.left + thumbWidthI;
1100
1101 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
1102 Animation translateAnim = new TranslateAnimation(0, thumbStartX, 0,
1103 thumbStartY - contentInsets.top);
1104
1105 set.addAnimation(clipAnim);
1106 set.addAnimation(translateAnim);
1107 }
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001108
1109 a = set;
1110 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001111 }
Winson Chung399f6202014-03-19 10:47:20 -07001112 break;
1113 }
1114 default:
1115 throw new RuntimeException("Invalid thumbnail transition state");
1116 }
1117
Winson Chungab79fce2014-11-04 16:15:22 -08001118 int duration = Math.max(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION,
1119 THUMBNAIL_APP_TRANSITION_DURATION);
1120 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001121 TOUCH_RESPONSE_INTERPOLATOR);
Winson Chung399f6202014-03-19 10:47:20 -07001122 }
1123
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001124 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1125 @Nullable Rect surfaceInsets, int taskId) {
1126 getNextAppTransitionStartRect(taskId, mTmpRect);
1127 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1128 true);
1129 }
1130
1131 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1132 @Nullable Rect surfaceInsets, int taskId) {
1133 getNextAppTransitionStartRect(taskId, mTmpRect);
1134 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1135 false);
1136 }
1137
1138 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1139 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1140 final float sourceWidth = sourceFrame.width();
1141 final float sourceHeight = sourceFrame.height();
1142 final float destWidth = destFrame.width();
1143 final float destHeight = destFrame.height();
1144 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1145 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001146 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001147 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001148 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001149 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001150 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1151 // We want the scaling to happen from the center of the surface. In order to achieve that,
1152 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001153 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1154 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1155 final ScaleAnimation scale = enter ?
1156 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1157 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1158 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1159 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1160 final int destHCenter = destFrame.left + destFrame.width() / 2;
1161 final int destVCenter = destFrame.top + destFrame.height() / 2;
1162 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1163 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1164 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1165 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001166 set.addAnimation(scale);
1167 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001168
1169 final IRemoteCallback callback = mAnimationFinishedCallback;
1170 if (callback != null) {
1171 set.setAnimationListener(new Animation.AnimationListener() {
1172 @Override
1173 public void onAnimationStart(Animation animation) { }
1174
1175 @Override
1176 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001177 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001178 }
1179
1180 @Override
1181 public void onAnimationRepeat(Animation animation) { }
1182 });
1183 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001184 return set;
1185 }
1186
Winson Chung399f6202014-03-19 10:47:20 -07001187 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001188 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001189 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001190 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001191 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
1192 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001193 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001194 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001195 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001196 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001197 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001198 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1199
1200 if (mNextAppTransitionScaleUp) {
1201 // Animation for the thumbnail zooming from its initial size to the full screen
1202 float scaleW = appWidth / thumbWidth;
1203 float scaleH = appHeight / thumbHeight;
1204 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001205 computePivot(mTmpRect.left, 1 / scaleW),
1206 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001207 scale.setInterpolator(mDecelerateInterpolator);
1208
1209 Animation alpha = new AlphaAnimation(1, 0);
1210 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1211
1212 // This AnimationSet uses the Interpolators assigned above.
1213 AnimationSet set = new AnimationSet(false);
1214 set.addAnimation(scale);
1215 set.addAnimation(alpha);
1216 a = set;
1217 } else {
1218 // Animation for the thumbnail zooming down from the full screen to its final size
1219 float scaleW = appWidth / thumbWidth;
1220 float scaleH = appHeight / thumbHeight;
1221 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001222 computePivot(mTmpRect.left, 1 / scaleW),
1223 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001224 }
1225
1226 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1227 }
1228
1229 /**
Winson Chung399f6202014-03-19 10:47:20 -07001230 * This animation is created when we are doing a thumbnail transition, for the activity that is
1231 * leaving, and the activity that is entering.
1232 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001233 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1234 int transit, int taskId) {
1235 final int appWidth = containingFrame.width();
1236 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001237 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001238 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001239 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001240 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001241 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001242 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001243 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1244
1245 switch (thumbTransitState) {
1246 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1247 // Entering app scales up with the thumbnail
1248 float scaleW = thumbWidth / appWidth;
1249 float scaleH = thumbHeight / appHeight;
1250 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001251 computePivot(mTmpRect.left, scaleW),
1252 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001253 break;
1254 }
1255 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1256 // Exiting app while the thumbnail is scaling up should fade or stay in place
1257 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1258 // Fade out while bringing up selected activity. This keeps the
1259 // current activity from showing through a launching wallpaper
1260 // activity.
1261 a = new AlphaAnimation(1, 0);
1262 } else {
1263 // noop animation
1264 a = new AlphaAnimation(1, 1);
1265 }
1266 break;
1267 }
1268 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1269 // Entering the other app, it should just be visible while we scale the thumbnail
1270 // down above it
1271 a = new AlphaAnimation(1, 1);
1272 break;
1273 }
1274 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1275 // Exiting the current app, the app should scale down with the thumbnail
1276 float scaleW = thumbWidth / appWidth;
1277 float scaleH = thumbHeight / appHeight;
1278 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001279 computePivot(mTmpRect.left, scaleW),
1280 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001281
1282 Animation alpha = new AlphaAnimation(1, 0);
1283
1284 AnimationSet set = new AnimationSet(true);
1285 set.addAnimation(scale);
1286 set.addAnimation(alpha);
1287 set.setZAdjustment(Animation.ZORDER_TOP);
1288 a = set;
1289 break;
1290 }
1291 default:
1292 throw new RuntimeException("Invalid thumbnail transition state");
1293 }
1294
1295 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1296 }
1297
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001298 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001299 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1300 final int left = mTmpFromClipRect.left;
1301 final int top = mTmpFromClipRect.top;
1302 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001303 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1304 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001305 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001306 float fromWidth = mTmpFromClipRect.width();
1307 float toWidth = mTmpToClipRect.width();
1308 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001309 // While the window might span the whole display, the actual content will be cropped to the
1310 // system decoration frame, for example when the window is docked. We need to take into
1311 // account the visible height when constructing the animation.
1312 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1313 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001314 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1315 // The final window is larger in both dimensions than current window (e.g. we are
1316 // maximizing), so we can simply unclip the new window and there will be no disappearing
1317 // frame.
1318 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1319 } else {
1320 // The disappearing window has one larger dimension. We need to apply scaling, so the
1321 // first frame of the entry animation matches the old window.
1322 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001323 // We might not be going exactly full screen, but instead be aligned under the status
1324 // bar using cropping. We still need to account for the cropped part, which will also
1325 // be scaled.
1326 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001327 }
1328
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001329 // We animate the translation from the old position of the removed window, to the new
1330 // position of the added window. The latter might not be full screen, for example docked for
1331 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001332 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001333 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001334 set.addAnimation(translate);
1335 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001336 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001337 return set;
1338 }
1339
Jorim Jaggic554b772015-06-04 16:07:57 -07001340 /**
1341 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1342 * frame of the transition doesn't change the visuals on screen, so we can start
1343 * directly with the second one
1344 */
1345 boolean canSkipFirstFrame() {
1346 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1347 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
1348 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1349 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001350
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001351 /**
1352 *
1353 * @param frame These are the bounds of the window when it finishes the animation. This is where
1354 * the animation must usually finish in entrance animation, as the next frame will
1355 * display the window at these coordinates. In case of exit animation, this is
1356 * where the animation must start, as the frame before the animation is displaying
1357 * the window at these bounds.
1358 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1359 * window might be obscured, usually by the system windows (status bar and
1360 * navigation bar) and we use content insets to convey that information. This
1361 * usually affects the animation aspects vertically, as the system decoration is
1362 * at the top and the bottom. For example when we animate from full screen to
1363 * recents, we want to exclude the covered parts, because they won't match the
1364 * thumbnail after the last frame is executed.
1365 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1366 * know about this to make the animation frames match. We currently use
1367 * this for freeform windows, which have larger surfaces to display
1368 * shadows. When we animate them from recents, we want to match the content
1369 * to the recents thumbnail and hence need to account for the surface being
1370 * bigger.
1371 */
Craig Mautner164d4bb2012-11-26 13:51:23 -08001372 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001373 int orientation, Rect frame, Rect displayFrame, Rect insets,
1374 @Nullable Rect surfaceInsets, boolean isVoiceInteraction, boolean freeform,
1375 int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001376 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001377 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
1378 || transit == TRANSIT_TASK_OPEN
1379 || transit == TRANSIT_TASK_TO_FRONT)) {
1380 a = loadAnimationRes(lp, enter
1381 ? com.android.internal.R.anim.voice_activity_open_enter
1382 : com.android.internal.R.anim.voice_activity_open_exit);
1383 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1384 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001385 + " anim=" + a + " transit=" + appTransitionToString(transit)
1386 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001387 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1388 || transit == TRANSIT_TASK_CLOSE
1389 || transit == TRANSIT_TASK_TO_BACK)) {
1390 a = loadAnimationRes(lp, enter
1391 ? com.android.internal.R.anim.voice_activity_close_enter
1392 : com.android.internal.R.anim.voice_activity_close_exit);
1393 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1394 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001395 + " anim=" + a + " transit=" + appTransitionToString(transit)
1396 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001397 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001398 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001399 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1400 "applyAnimation:"
1401 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1402 + " transit=" + appTransitionToString(transit)
1403 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001404 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1405 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001406 mNextAppTransitionEnter : mNextAppTransitionExit);
1407 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1408 "applyAnimation:"
1409 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001410 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001411 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001412 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1413 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1414 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1415 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001416 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1417 + " transit=" + appTransitionToString(transit)
1418 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001419 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001420 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001421 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1422 "applyAnimation:"
1423 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001424 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001425 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001426 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001427 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001428 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1429 "applyAnimation:"
1430 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001431 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001432 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001433 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1434 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001435 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001436 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001437 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001438 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001439 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1440 String animName = mNextAppTransitionScaleUp ?
1441 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1442 Slog.v(TAG, "applyAnimation:"
1443 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001444 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001445 + " Callers=" + Debug.getCallers(3));
1446 }
1447 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1448 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1449 mNextAppTransitionScaleUp =
1450 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1451 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001452 getThumbnailTransitionState(enter), orientation, transit, frame,
1453 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001454 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1455 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001456 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001457 Slog.v(TAG, "applyAnimation:"
1458 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001459 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001460 + " Callers=" + Debug.getCallers(3));
1461 }
1462 } else {
1463 int animAttr = 0;
1464 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001465 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001466 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001467 ? WindowAnimation_activityOpenEnterAnimation
1468 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001469 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001470 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001471 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001472 ? WindowAnimation_activityCloseEnterAnimation
1473 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001474 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001475 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001476 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001477 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001478 ? WindowAnimation_taskOpenEnterAnimation
1479 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001480 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001481 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001482 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001483 ? WindowAnimation_taskCloseEnterAnimation
1484 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001485 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001486 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001487 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001488 ? WindowAnimation_taskToFrontEnterAnimation
1489 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001490 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001491 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001492 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001493 ? WindowAnimation_taskToBackEnterAnimation
1494 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001495 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001496 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001497 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001498 ? WindowAnimation_wallpaperOpenEnterAnimation
1499 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001500 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001501 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001502 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001503 ? WindowAnimation_wallpaperCloseEnterAnimation
1504 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001505 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001506 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001507 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001508 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1509 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001510 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001511 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001512 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001513 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1514 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001515 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001516 case TRANSIT_TASK_OPEN_BEHIND:
1517 animAttr = enter
1518 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001519 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001520 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001521 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001522 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1523 "applyAnimation:"
1524 + " anim=" + a
1525 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001526 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001527 + " Callers=" + Debug.getCallers(3));
1528 }
1529 return a;
1530 }
1531
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001532 int getAppStackClipMode() {
1533 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
1534 ? STACK_CLIP_NONE
1535 : STACK_CLIP_AFTER_ANIM;
1536 }
1537
Craig Mautner164d4bb2012-11-26 13:51:23 -08001538 void postAnimationCallback() {
1539 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001540 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1541 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001542 mNextAppTransitionCallback = null;
1543 }
1544 }
1545
1546 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001547 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001548 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001549 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001550 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001551 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001552 mNextAppTransitionEnter = enterAnim;
1553 mNextAppTransitionExit = exitAnim;
1554 postAnimationCallback();
1555 mNextAppTransitionCallback = startedCallback;
1556 } else {
1557 postAnimationCallback();
1558 }
1559 }
1560
1561 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001562 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001563 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001564 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001565 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001566 putDefaultNextAppTransitionCoordinates(startX, startY, startX + startWidth,
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001567 startY + startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001568 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001569 }
1570 }
1571
Chet Haase10e23ab2015-02-11 15:08:38 -08001572 void overridePendingAppTransitionClipReveal(int startX, int startY,
1573 int startWidth, int startHeight) {
1574 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001575 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001576 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001577 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001578 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001579 }
1580 }
1581
Craig Mautner164d4bb2012-11-26 13:51:23 -08001582 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1583 IRemoteCallback startedCallback, boolean scaleUp) {
1584 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001585 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001586 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1587 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001588 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001589 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001590 postAnimationCallback();
1591 mNextAppTransitionCallback = startedCallback;
1592 } else {
1593 postAnimationCallback();
1594 }
1595 }
1596
Winson Chunga4ccb862014-08-22 15:26:27 -07001597 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001598 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001599 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001600 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001601 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1602 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001603 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001604 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1605 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001606 postAnimationCallback();
1607 mNextAppTransitionCallback = startedCallback;
1608 } else {
1609 postAnimationCallback();
1610 }
1611 }
1612
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001613 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001614 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1615 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001616 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001617 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001618 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1619 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001620 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001621 if (specs != null) {
1622 for (int i = 0; i < specs.length; i++) {
1623 AppTransitionAnimationSpec spec = specs[i];
1624 if (spec != null) {
1625 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1626 if (i == 0) {
1627 // In full screen mode, the transition code depends on the default spec
1628 // to be set.
1629 Rect rect = spec.rect;
1630 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Filip Gruszczynskie3264d82015-11-20 17:10:04 -08001631 rect.width(), rect.height(), spec.bitmap);
Jorim Jaggi43102412015-11-11 16:28:37 +01001632 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001633 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001634 }
1635 }
1636 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001637 mNextAppTransitionCallback = onAnimationStartedCallback;
1638 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001639 } else {
1640 postAnimationCallback();
1641 }
1642 }
1643
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001644 void overridePendingAppTransitionMultiThumbFuture(
1645 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1646 boolean scaleUp) {
1647 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001648 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001649 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1650 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001651 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1652 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001653 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001654 }
1655 }
1656
Winson Chung044d5292014-11-06 11:05:19 -08001657 void overrideInPlaceAppTransition(String packageName, int anim) {
1658 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001659 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001660 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1661 mNextAppTransitionPackage = packageName;
1662 mNextAppTransitionInPlace = anim;
1663 } else {
1664 postAnimationCallback();
1665 }
1666 }
1667
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001668 /**
1669 * If a future is set for the app transition specs, fetch it in another thread.
1670 */
1671 private void fetchAppTransitionSpecsFromFuture() {
1672 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1673 mNextAppTransitionAnimationsSpecsPending = true;
1674 final IAppTransitionAnimationSpecsFuture future
1675 = mNextAppTransitionAnimationsSpecsFuture;
1676 mNextAppTransitionAnimationsSpecsFuture = null;
1677 mDefaultExecutor.execute(new Runnable() {
1678 @Override
1679 public void run() {
1680 AppTransitionAnimationSpec[] specs = null;
1681 try {
1682 specs = future.get();
1683 } catch (RemoteException e) {
1684 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1685 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001686 synchronized (mService.mWindowMap) {
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001687 mNextAppTransitionAnimationsSpecsPending = false;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001688 overridePendingAppTransitionMultiThumb(specs,
1689 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1690 mNextAppTransitionScaleUp);
1691 mNextAppTransitionFutureCallback = null;
Filip Gruszczynski96daf322015-11-18 18:01:27 -08001692 if (specs != null) {
1693 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1694 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001695 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001696 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001697 }
1698 });
1699 }
1700 }
1701
Craig Mautner164d4bb2012-11-26 13:51:23 -08001702 @Override
1703 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001704 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001705 }
1706
Craig Mautner4b71aa12012-12-27 17:20:01 -08001707 /**
1708 * Returns the human readable name of a window transition.
1709 *
1710 * @param transition The window transition.
1711 * @return The transition symbolic name.
1712 */
1713 public static String appTransitionToString(int transition) {
1714 switch (transition) {
1715 case TRANSIT_UNSET: {
1716 return "TRANSIT_UNSET";
1717 }
1718 case TRANSIT_NONE: {
1719 return "TRANSIT_NONE";
1720 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001721 case TRANSIT_ACTIVITY_OPEN: {
1722 return "TRANSIT_ACTIVITY_OPEN";
1723 }
1724 case TRANSIT_ACTIVITY_CLOSE: {
1725 return "TRANSIT_ACTIVITY_CLOSE";
1726 }
1727 case TRANSIT_TASK_OPEN: {
1728 return "TRANSIT_TASK_OPEN";
1729 }
1730 case TRANSIT_TASK_CLOSE: {
1731 return "TRANSIT_TASK_CLOSE";
1732 }
1733 case TRANSIT_TASK_TO_FRONT: {
1734 return "TRANSIT_TASK_TO_FRONT";
1735 }
1736 case TRANSIT_TASK_TO_BACK: {
1737 return "TRANSIT_TASK_TO_BACK";
1738 }
1739 case TRANSIT_WALLPAPER_CLOSE: {
1740 return "TRANSIT_WALLPAPER_CLOSE";
1741 }
1742 case TRANSIT_WALLPAPER_OPEN: {
1743 return "TRANSIT_WALLPAPER_OPEN";
1744 }
1745 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1746 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1747 }
1748 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1749 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1750 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001751 case TRANSIT_TASK_OPEN_BEHIND: {
1752 return "TRANSIT_TASK_OPEN_BEHIND";
1753 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001754 case TRANSIT_ACTIVITY_RELAUNCH: {
1755 return "TRANSIT_ACTIVITY_RELAUNCH";
1756 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001757 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1758 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1759 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001760 default: {
1761 return "<UNKNOWN>";
1762 }
1763 }
1764 }
1765
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001766 private String appStateToString() {
1767 switch (mAppTransitionState) {
1768 case APP_STATE_IDLE:
1769 return "APP_STATE_IDLE";
1770 case APP_STATE_READY:
1771 return "APP_STATE_READY";
1772 case APP_STATE_RUNNING:
1773 return "APP_STATE_RUNNING";
1774 case APP_STATE_TIMEOUT:
1775 return "APP_STATE_TIMEOUT";
1776 default:
1777 return "unknown state=" + mAppTransitionState;
1778 }
1779 }
1780
1781 private String transitTypeToString() {
1782 switch (mNextAppTransitionType) {
1783 case NEXT_TRANSIT_TYPE_NONE:
1784 return "NEXT_TRANSIT_TYPE_NONE";
1785 case NEXT_TRANSIT_TYPE_CUSTOM:
1786 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001787 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1788 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001789 case NEXT_TRANSIT_TYPE_SCALE_UP:
1790 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1791 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1792 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1793 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1794 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001795 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1796 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1797 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1798 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001799 default:
1800 return "unknown type=" + mNextAppTransitionType;
1801 }
1802 }
1803
Craig Mautner164d4bb2012-11-26 13:51:23 -08001804 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001805 public void dump(PrintWriter pw, String prefix) {
1806 pw.print(prefix); pw.println(this);
1807 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001808 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001809 pw.print(prefix); pw.print("mNextAppTransitionType=");
1810 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001811 }
1812 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001813 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001814 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001815 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001816 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001817 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1818 pw.print(" mNextAppTransitionExit=0x");
1819 pw.println(Integer.toHexString(mNextAppTransitionExit));
1820 break;
Winson Chung044d5292014-11-06 11:05:19 -08001821 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001822 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001823 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001824 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001825 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1826 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001827 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001828 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001829 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001830 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001831 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001832 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001833 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001834 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001835 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001836 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001837 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001838 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001839 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1840 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001841 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001842 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1843 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1844 pw.println(mDefaultNextAppTransitionAnimationSpec);
1845 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1846 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001847 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1848 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001849 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001850 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001851 }
1852 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001853 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1854 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001855 }
1856 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001857
1858 public void setCurrentUser(int newUserId) {
1859 mCurrentUserId = newUserId;
1860 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001861
1862 /**
1863 * @return true if transition is not running and should not be skipped, false if transition is
1864 * already running
1865 */
1866 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent) {
1867 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
1868 + " transit=" + appTransitionToString(transit)
1869 + " " + this
1870 + " alwaysKeepCurrent=" + alwaysKeepCurrent
1871 + " Callers=" + Debug.getCallers(3));
1872 if (!isTransitionSet() || mNextAppTransition == TRANSIT_NONE) {
1873 setAppTransition(transit);
1874 } else if (!alwaysKeepCurrent) {
1875 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
1876 // Opening a new task always supersedes a close for the anim.
1877 setAppTransition(transit);
1878 } else if (transit == TRANSIT_ACTIVITY_OPEN
1879 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
1880 // Opening a new activity always supersedes a close for the anim.
1881 setAppTransition(transit);
1882 }
1883 }
1884 boolean prepared = prepare();
1885 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001886 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
1887 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001888 }
1889 return prepared;
1890 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001891}