blob: 5dc1fffdabbb40e4be6760b06ada88610ee850cb [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();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700880 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700881
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700882 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700883 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi8448f332016-03-14 17:50:37 +0100884 final float toY = mTmpRect.height() / 2 * (scaleW - 1f) + appRect.top;
885 final float fromY = mTmpRect.top;
886 final float toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
887 final float fromX = mTmpRect.left;
888 final float pivotX = mTmpRect.width() / 2;
889 final float pivotY = mTmpRect.height() / 2;
Winson Chung399f6202014-03-19 10:47:20 -0700890 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700891 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +0100892 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800893 scale.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700894 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800895 Animation alpha = new AlphaAnimation(1f, 0f);
Winson Chunga4ccb862014-08-22 15:26:27 -0700896 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
897 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
Jorim Jaggi8448f332016-03-14 17:50:37 +0100898 Animation translate = new TranslateAnimation(fromX, toX, fromY, toY);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800899 translate.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700900 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700901
Jorim Jaggide63d442016-03-14 14:56:56 +0100902 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
903 mTmpToClipRect.set(appRect);
904
905 // Containing frame is in screen space, but we need the clip rect in the
906 // app space.
907 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggi8448f332016-03-14 17:50:37 +0100908 mTmpToClipRect.right = (int) (mTmpToClipRect.right * scaleW);
909 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom * scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +0100910
911 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +0100912 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
913 (int) (-contentInsets.top * scaleW),
914 (int) (-contentInsets.right * scaleW),
915 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +0100916 }
917
918 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
919 clipAnim.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
920 clipAnim.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
921
Winson Chung399f6202014-03-19 10:47:20 -0700922 // This AnimationSet uses the Interpolators assigned above.
923 AnimationSet set = new AnimationSet(false);
924 set.addAnimation(scale);
925 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -0700926 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +0100927 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -0700928 a = set;
929 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700930 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +0100931 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800932 scale.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700933 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
934 Animation alpha = new AlphaAnimation(0f, 1f);
935 alpha.setInterpolator(mThumbnailFadeInInterpolator);
936 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
Jorim Jaggi8448f332016-03-14 17:50:37 +0100937 Animation translate = new TranslateAnimation(toX, fromX, toY, fromY);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800938 translate.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700939 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700940
Winson Chunga4ccb862014-08-22 15:26:27 -0700941 // This AnimationSet uses the Interpolators assigned above.
942 AnimationSet set = new AnimationSet(false);
943 set.addAnimation(scale);
944 set.addAnimation(alpha);
945 set.addAnimation(translate);
946 a = set;
947
948 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700949 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800950 TOUCH_RESPONSE_INTERPOLATOR);
Winson Chung399f6202014-03-19 10:47:20 -0700951 }
952
953 /**
954 * This alternate animation is created when we are doing a thumbnail transition, for the
955 * activity that is leaving, and the activity that is entering.
956 */
Winson Chunga4ccb862014-08-22 15:26:27 -0700957 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700958 int orientation, int transit, Rect containingFrame, Rect contentInsets,
959 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700960 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700961 final int appWidth = containingFrame.width();
962 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700963 getDefaultNextAppTransitionStartRect(mTmpRect);
964 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700965 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700966 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -0700967 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winson21700932016-03-24 17:26:23 -0700968 final int thumbStartX = mTmpRect.left - containingFrame.left;
969 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -0700970
Winson Chung2820c452014-04-15 15:34:44 -0700971 // Used for the ENTER_SCALE_UP and EXIT_SCALE_DOWN transitions
972 float scale = 1f;
973 int scaledTopDecor = 0;
974
Winson Chung399f6202014-03-19 10:47:20 -0700975 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +0100976 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
977 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
978 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
979 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700980 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700981 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +0100982 } else if (freeform) {
983 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
984 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -0700985 } else {
Winson21700932016-03-24 17:26:23 -0700986 AnimationSet set = new AnimationSet(true);
987
988 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700989 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700990 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800991
992 // Containing frame is in screen space, but we need the clip rect in the
993 // app space.
994 mTmpFromClipRect.offsetTo(0, 0);
995 mTmpToClipRect.offsetTo(0, 0);
996
997 // Exclude insets region from the source clip.
998 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700999 mNextAppTransitionInsets.set(contentInsets);
1000
Winson21700932016-03-24 17:26:23 -07001001 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
1002 // We scale the width and clip to the top/left square
Jorim Jaggi8448f332016-03-14 17:50:37 +01001003 Animation scaleAnim = new ScaleAnimation(
1004 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1005 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1006 containingFrame.width() / 2,
1007 containingFrame.height() / 2 + contentInsets.top);
1008 final float targetX = (mTmpRect.left - containingFrame.left);
1009 final float x = containingFrame.width() / 2
1010 - containingFrame.width() / 2 * scale;
1011 final float targetY = (mTmpRect.top - containingFrame.top);
1012 final float y = containingFrame.height() / 2
1013 - containingFrame.height() / 2 * scale;
1014 final float startX = targetX - x;
1015 final float startY = targetY - y;
1016 Animation clipAnim = scaleUp
1017 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1018 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1019 Animation translateAnim = scaleUp
1020 ? new TranslateAnimation(startX, 0, startY - scaledTopDecor, 0)
1021 : new TranslateAnimation(0, startX, 0, startY - scaledTopDecor);
Winson21700932016-03-24 17:26:23 -07001022 set.addAnimation(clipAnim);
1023 set.addAnimation(scaleAnim);
1024 set.addAnimation(translateAnim);
1025
1026 } else {
1027 // In landscape, we don't scale at all and only crop
1028 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1029 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1030
Jorim Jaggi8448f332016-03-14 17:50:37 +01001031 Animation clipAnim = scaleUp
1032 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1033 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1034 Animation translateAnim = scaleUp
1035 ? new TranslateAnimation(thumbStartX, 0, thumbStartY - contentInsets.top, 0)
1036 : new TranslateAnimation(0, thumbStartX, 0, thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001037
1038 set.addAnimation(clipAnim);
1039 set.addAnimation(translateAnim);
1040 }
Jorim Jaggi8448f332016-03-14 17:50:37 +01001041 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001042 a = set;
Winson21700932016-03-24 17:26:23 -07001043 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001044 }
Winson Chung399f6202014-03-19 10:47:20 -07001045 break;
1046 }
1047 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001048 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001049 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001050 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001051 // activity.
1052 a = new AlphaAnimation(1, 0);
1053 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001054 a = new AlphaAnimation(1, 1);
1055 }
1056 break;
1057 }
1058 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001059 // Target app window during the scale down
1060 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1061 // Fade in the destination activity if we are animating from a wallpaper
1062 // activity.
1063 a = new AlphaAnimation(0, 1);
1064 } else {
1065 a = new AlphaAnimation(1, 1);
1066 }
Winson Chung399f6202014-03-19 10:47:20 -07001067 break;
1068 }
Winson Chung399f6202014-03-19 10:47:20 -07001069 default:
1070 throw new RuntimeException("Invalid thumbnail transition state");
1071 }
1072
Winson Chungab79fce2014-11-04 16:15:22 -08001073 int duration = Math.max(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION,
1074 THUMBNAIL_APP_TRANSITION_DURATION);
1075 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001076 TOUCH_RESPONSE_INTERPOLATOR);
Winson Chung399f6202014-03-19 10:47:20 -07001077 }
1078
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001079 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1080 @Nullable Rect surfaceInsets, int taskId) {
1081 getNextAppTransitionStartRect(taskId, mTmpRect);
1082 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1083 true);
1084 }
1085
1086 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1087 @Nullable Rect surfaceInsets, int taskId) {
1088 getNextAppTransitionStartRect(taskId, mTmpRect);
1089 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1090 false);
1091 }
1092
1093 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1094 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1095 final float sourceWidth = sourceFrame.width();
1096 final float sourceHeight = sourceFrame.height();
1097 final float destWidth = destFrame.width();
1098 final float destHeight = destFrame.height();
1099 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1100 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001101 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001102 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001103 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001104 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001105 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1106 // We want the scaling to happen from the center of the surface. In order to achieve that,
1107 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001108 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1109 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1110 final ScaleAnimation scale = enter ?
1111 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1112 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1113 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1114 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1115 final int destHCenter = destFrame.left + destFrame.width() / 2;
1116 final int destVCenter = destFrame.top + destFrame.height() / 2;
1117 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1118 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1119 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1120 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001121 set.addAnimation(scale);
1122 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001123
1124 final IRemoteCallback callback = mAnimationFinishedCallback;
1125 if (callback != null) {
1126 set.setAnimationListener(new Animation.AnimationListener() {
1127 @Override
1128 public void onAnimationStart(Animation animation) { }
1129
1130 @Override
1131 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001132 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001133 }
1134
1135 @Override
1136 public void onAnimationRepeat(Animation animation) { }
1137 });
1138 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001139 return set;
1140 }
1141
Winson Chung399f6202014-03-19 10:47:20 -07001142 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001143 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001144 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001145 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001146 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
1147 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001148 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001149 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001150 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001151 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001152 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001153 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1154
1155 if (mNextAppTransitionScaleUp) {
1156 // Animation for the thumbnail zooming from its initial size to the full screen
1157 float scaleW = appWidth / thumbWidth;
1158 float scaleH = appHeight / thumbHeight;
1159 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001160 computePivot(mTmpRect.left, 1 / scaleW),
1161 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001162 scale.setInterpolator(mDecelerateInterpolator);
1163
1164 Animation alpha = new AlphaAnimation(1, 0);
1165 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1166
1167 // This AnimationSet uses the Interpolators assigned above.
1168 AnimationSet set = new AnimationSet(false);
1169 set.addAnimation(scale);
1170 set.addAnimation(alpha);
1171 a = set;
1172 } else {
1173 // Animation for the thumbnail zooming down from the full screen to its final size
1174 float scaleW = appWidth / thumbWidth;
1175 float scaleH = appHeight / thumbHeight;
1176 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001177 computePivot(mTmpRect.left, 1 / scaleW),
1178 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001179 }
1180
1181 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1182 }
1183
1184 /**
Winson Chung399f6202014-03-19 10:47:20 -07001185 * This animation is created when we are doing a thumbnail transition, for the activity that is
1186 * leaving, and the activity that is entering.
1187 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001188 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1189 int transit, int taskId) {
1190 final int appWidth = containingFrame.width();
1191 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001192 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -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 != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001196 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001197 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001198 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1199
1200 switch (thumbTransitState) {
1201 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1202 // Entering app scales up with the thumbnail
1203 float scaleW = thumbWidth / appWidth;
1204 float scaleH = thumbHeight / appHeight;
1205 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001206 computePivot(mTmpRect.left, scaleW),
1207 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001208 break;
1209 }
1210 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1211 // Exiting app while the thumbnail is scaling up should fade or stay in place
1212 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1213 // Fade out while bringing up selected activity. This keeps the
1214 // current activity from showing through a launching wallpaper
1215 // activity.
1216 a = new AlphaAnimation(1, 0);
1217 } else {
1218 // noop animation
1219 a = new AlphaAnimation(1, 1);
1220 }
1221 break;
1222 }
1223 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1224 // Entering the other app, it should just be visible while we scale the thumbnail
1225 // down above it
1226 a = new AlphaAnimation(1, 1);
1227 break;
1228 }
1229 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1230 // Exiting the current app, the app should scale down with the thumbnail
1231 float scaleW = thumbWidth / appWidth;
1232 float scaleH = thumbHeight / appHeight;
1233 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001234 computePivot(mTmpRect.left, scaleW),
1235 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001236
1237 Animation alpha = new AlphaAnimation(1, 0);
1238
1239 AnimationSet set = new AnimationSet(true);
1240 set.addAnimation(scale);
1241 set.addAnimation(alpha);
1242 set.setZAdjustment(Animation.ZORDER_TOP);
1243 a = set;
1244 break;
1245 }
1246 default:
1247 throw new RuntimeException("Invalid thumbnail transition state");
1248 }
1249
1250 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1251 }
1252
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001253 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001254 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1255 final int left = mTmpFromClipRect.left;
1256 final int top = mTmpFromClipRect.top;
1257 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001258 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1259 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001260 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001261 float fromWidth = mTmpFromClipRect.width();
1262 float toWidth = mTmpToClipRect.width();
1263 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001264 // While the window might span the whole display, the actual content will be cropped to the
1265 // system decoration frame, for example when the window is docked. We need to take into
1266 // account the visible height when constructing the animation.
1267 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1268 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001269 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1270 // The final window is larger in both dimensions than current window (e.g. we are
1271 // maximizing), so we can simply unclip the new window and there will be no disappearing
1272 // frame.
1273 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1274 } else {
1275 // The disappearing window has one larger dimension. We need to apply scaling, so the
1276 // first frame of the entry animation matches the old window.
1277 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001278 // We might not be going exactly full screen, but instead be aligned under the status
1279 // bar using cropping. We still need to account for the cropped part, which will also
1280 // be scaled.
1281 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001282 }
1283
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001284 // We animate the translation from the old position of the removed window, to the new
1285 // position of the added window. The latter might not be full screen, for example docked for
1286 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001287 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001288 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001289 set.addAnimation(translate);
1290 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001291 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001292 return set;
1293 }
1294
Jorim Jaggic554b772015-06-04 16:07:57 -07001295 /**
1296 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1297 * frame of the transition doesn't change the visuals on screen, so we can start
1298 * directly with the second one
1299 */
1300 boolean canSkipFirstFrame() {
1301 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1302 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
1303 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1304 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001305
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001306 /**
1307 *
1308 * @param frame These are the bounds of the window when it finishes the animation. This is where
1309 * the animation must usually finish in entrance animation, as the next frame will
1310 * display the window at these coordinates. In case of exit animation, this is
1311 * where the animation must start, as the frame before the animation is displaying
1312 * the window at these bounds.
1313 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1314 * window might be obscured, usually by the system windows (status bar and
1315 * navigation bar) and we use content insets to convey that information. This
1316 * usually affects the animation aspects vertically, as the system decoration is
1317 * at the top and the bottom. For example when we animate from full screen to
1318 * recents, we want to exclude the covered parts, because they won't match the
1319 * thumbnail after the last frame is executed.
1320 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1321 * know about this to make the animation frames match. We currently use
1322 * this for freeform windows, which have larger surfaces to display
1323 * shadows. When we animate them from recents, we want to match the content
1324 * to the recents thumbnail and hence need to account for the surface being
1325 * bigger.
1326 */
Craig Mautner164d4bb2012-11-26 13:51:23 -08001327 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001328 int orientation, Rect frame, Rect displayFrame, Rect insets,
1329 @Nullable Rect surfaceInsets, boolean isVoiceInteraction, boolean freeform,
1330 int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001331 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001332 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
1333 || transit == TRANSIT_TASK_OPEN
1334 || transit == TRANSIT_TASK_TO_FRONT)) {
1335 a = loadAnimationRes(lp, enter
1336 ? com.android.internal.R.anim.voice_activity_open_enter
1337 : com.android.internal.R.anim.voice_activity_open_exit);
1338 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1339 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001340 + " anim=" + a + " transit=" + appTransitionToString(transit)
1341 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001342 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1343 || transit == TRANSIT_TASK_CLOSE
1344 || transit == TRANSIT_TASK_TO_BACK)) {
1345 a = loadAnimationRes(lp, enter
1346 ? com.android.internal.R.anim.voice_activity_close_enter
1347 : com.android.internal.R.anim.voice_activity_close_exit);
1348 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1349 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001350 + " anim=" + a + " transit=" + appTransitionToString(transit)
1351 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001352 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001353 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001354 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1355 "applyAnimation:"
1356 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1357 + " transit=" + appTransitionToString(transit)
1358 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001359 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1360 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001361 mNextAppTransitionEnter : mNextAppTransitionExit);
1362 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1363 "applyAnimation:"
1364 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001365 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001366 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001367 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1368 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1369 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1370 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001371 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1372 + " transit=" + appTransitionToString(transit)
1373 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001374 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001375 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001376 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1377 "applyAnimation:"
1378 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001379 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001380 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001381 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001382 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001383 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1384 "applyAnimation:"
1385 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001386 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001387 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001388 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1389 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001390 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001391 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001392 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001393 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001394 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1395 String animName = mNextAppTransitionScaleUp ?
1396 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1397 Slog.v(TAG, "applyAnimation:"
1398 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001399 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001400 + " Callers=" + Debug.getCallers(3));
1401 }
1402 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1403 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1404 mNextAppTransitionScaleUp =
1405 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1406 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001407 getThumbnailTransitionState(enter), orientation, transit, frame,
1408 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001409 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1410 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001411 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001412 Slog.v(TAG, "applyAnimation:"
1413 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001414 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001415 + " Callers=" + Debug.getCallers(3));
1416 }
1417 } else {
1418 int animAttr = 0;
1419 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001420 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001421 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001422 ? WindowAnimation_activityOpenEnterAnimation
1423 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001424 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001425 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001426 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001427 ? WindowAnimation_activityCloseEnterAnimation
1428 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001429 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001430 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001431 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001432 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001433 ? WindowAnimation_taskOpenEnterAnimation
1434 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001435 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001436 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001437 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001438 ? WindowAnimation_taskCloseEnterAnimation
1439 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001440 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001441 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001442 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001443 ? WindowAnimation_taskToFrontEnterAnimation
1444 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001445 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001446 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001447 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001448 ? WindowAnimation_taskToBackEnterAnimation
1449 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001450 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001451 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001452 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001453 ? WindowAnimation_wallpaperOpenEnterAnimation
1454 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001455 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001456 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001457 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001458 ? WindowAnimation_wallpaperCloseEnterAnimation
1459 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001460 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001461 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001462 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001463 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1464 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001465 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001466 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001467 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001468 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1469 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001470 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001471 case TRANSIT_TASK_OPEN_BEHIND:
1472 animAttr = enter
1473 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001474 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001475 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001476 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001477 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1478 "applyAnimation:"
1479 + " anim=" + a
1480 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001481 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001482 + " Callers=" + Debug.getCallers(3));
1483 }
1484 return a;
1485 }
1486
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001487 int getAppStackClipMode() {
1488 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
1489 ? STACK_CLIP_NONE
1490 : STACK_CLIP_AFTER_ANIM;
1491 }
1492
Craig Mautner164d4bb2012-11-26 13:51:23 -08001493 void postAnimationCallback() {
1494 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001495 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1496 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001497 mNextAppTransitionCallback = null;
1498 }
1499 }
1500
1501 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001502 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001503 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001504 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001505 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001506 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001507 mNextAppTransitionEnter = enterAnim;
1508 mNextAppTransitionExit = exitAnim;
1509 postAnimationCallback();
1510 mNextAppTransitionCallback = startedCallback;
1511 } else {
1512 postAnimationCallback();
1513 }
1514 }
1515
1516 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001517 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001518 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001519 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001520 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001521 putDefaultNextAppTransitionCoordinates(startX, startY, startX + startWidth,
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001522 startY + startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001523 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001524 }
1525 }
1526
Chet Haase10e23ab2015-02-11 15:08:38 -08001527 void overridePendingAppTransitionClipReveal(int startX, int startY,
1528 int startWidth, int startHeight) {
1529 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001530 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001531 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001532 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001533 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001534 }
1535 }
1536
Craig Mautner164d4bb2012-11-26 13:51:23 -08001537 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1538 IRemoteCallback startedCallback, boolean scaleUp) {
1539 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001540 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001541 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1542 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001543 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001544 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001545 postAnimationCallback();
1546 mNextAppTransitionCallback = startedCallback;
1547 } else {
1548 postAnimationCallback();
1549 }
1550 }
1551
Winson Chunga4ccb862014-08-22 15:26:27 -07001552 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001553 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001554 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001555 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001556 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1557 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001558 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001559 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1560 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001561 postAnimationCallback();
1562 mNextAppTransitionCallback = startedCallback;
1563 } else {
1564 postAnimationCallback();
1565 }
1566 }
1567
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001568 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001569 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1570 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001571 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001572 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001573 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1574 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001575 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001576 if (specs != null) {
1577 for (int i = 0; i < specs.length; i++) {
1578 AppTransitionAnimationSpec spec = specs[i];
1579 if (spec != null) {
1580 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1581 if (i == 0) {
1582 // In full screen mode, the transition code depends on the default spec
1583 // to be set.
1584 Rect rect = spec.rect;
1585 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Filip Gruszczynskie3264d82015-11-20 17:10:04 -08001586 rect.width(), rect.height(), spec.bitmap);
Jorim Jaggi43102412015-11-11 16:28:37 +01001587 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001588 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001589 }
1590 }
1591 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001592 mNextAppTransitionCallback = onAnimationStartedCallback;
1593 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001594 } else {
1595 postAnimationCallback();
1596 }
1597 }
1598
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001599 void overridePendingAppTransitionMultiThumbFuture(
1600 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1601 boolean scaleUp) {
1602 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001603 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001604 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1605 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001606 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1607 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001608 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001609 }
1610 }
1611
Winson Chung044d5292014-11-06 11:05:19 -08001612 void overrideInPlaceAppTransition(String packageName, int anim) {
1613 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001614 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001615 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1616 mNextAppTransitionPackage = packageName;
1617 mNextAppTransitionInPlace = anim;
1618 } else {
1619 postAnimationCallback();
1620 }
1621 }
1622
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001623 /**
1624 * If a future is set for the app transition specs, fetch it in another thread.
1625 */
1626 private void fetchAppTransitionSpecsFromFuture() {
1627 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1628 mNextAppTransitionAnimationsSpecsPending = true;
1629 final IAppTransitionAnimationSpecsFuture future
1630 = mNextAppTransitionAnimationsSpecsFuture;
1631 mNextAppTransitionAnimationsSpecsFuture = null;
1632 mDefaultExecutor.execute(new Runnable() {
1633 @Override
1634 public void run() {
1635 AppTransitionAnimationSpec[] specs = null;
1636 try {
1637 specs = future.get();
1638 } catch (RemoteException e) {
1639 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1640 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001641 synchronized (mService.mWindowMap) {
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001642 mNextAppTransitionAnimationsSpecsPending = false;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001643 overridePendingAppTransitionMultiThumb(specs,
1644 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1645 mNextAppTransitionScaleUp);
1646 mNextAppTransitionFutureCallback = null;
Filip Gruszczynski96daf322015-11-18 18:01:27 -08001647 if (specs != null) {
1648 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1649 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001650 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001651 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001652 }
1653 });
1654 }
1655 }
1656
Craig Mautner164d4bb2012-11-26 13:51:23 -08001657 @Override
1658 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001659 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001660 }
1661
Craig Mautner4b71aa12012-12-27 17:20:01 -08001662 /**
1663 * Returns the human readable name of a window transition.
1664 *
1665 * @param transition The window transition.
1666 * @return The transition symbolic name.
1667 */
1668 public static String appTransitionToString(int transition) {
1669 switch (transition) {
1670 case TRANSIT_UNSET: {
1671 return "TRANSIT_UNSET";
1672 }
1673 case TRANSIT_NONE: {
1674 return "TRANSIT_NONE";
1675 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001676 case TRANSIT_ACTIVITY_OPEN: {
1677 return "TRANSIT_ACTIVITY_OPEN";
1678 }
1679 case TRANSIT_ACTIVITY_CLOSE: {
1680 return "TRANSIT_ACTIVITY_CLOSE";
1681 }
1682 case TRANSIT_TASK_OPEN: {
1683 return "TRANSIT_TASK_OPEN";
1684 }
1685 case TRANSIT_TASK_CLOSE: {
1686 return "TRANSIT_TASK_CLOSE";
1687 }
1688 case TRANSIT_TASK_TO_FRONT: {
1689 return "TRANSIT_TASK_TO_FRONT";
1690 }
1691 case TRANSIT_TASK_TO_BACK: {
1692 return "TRANSIT_TASK_TO_BACK";
1693 }
1694 case TRANSIT_WALLPAPER_CLOSE: {
1695 return "TRANSIT_WALLPAPER_CLOSE";
1696 }
1697 case TRANSIT_WALLPAPER_OPEN: {
1698 return "TRANSIT_WALLPAPER_OPEN";
1699 }
1700 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1701 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1702 }
1703 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1704 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1705 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001706 case TRANSIT_TASK_OPEN_BEHIND: {
1707 return "TRANSIT_TASK_OPEN_BEHIND";
1708 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001709 case TRANSIT_ACTIVITY_RELAUNCH: {
1710 return "TRANSIT_ACTIVITY_RELAUNCH";
1711 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001712 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1713 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1714 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001715 default: {
1716 return "<UNKNOWN>";
1717 }
1718 }
1719 }
1720
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001721 private String appStateToString() {
1722 switch (mAppTransitionState) {
1723 case APP_STATE_IDLE:
1724 return "APP_STATE_IDLE";
1725 case APP_STATE_READY:
1726 return "APP_STATE_READY";
1727 case APP_STATE_RUNNING:
1728 return "APP_STATE_RUNNING";
1729 case APP_STATE_TIMEOUT:
1730 return "APP_STATE_TIMEOUT";
1731 default:
1732 return "unknown state=" + mAppTransitionState;
1733 }
1734 }
1735
1736 private String transitTypeToString() {
1737 switch (mNextAppTransitionType) {
1738 case NEXT_TRANSIT_TYPE_NONE:
1739 return "NEXT_TRANSIT_TYPE_NONE";
1740 case NEXT_TRANSIT_TYPE_CUSTOM:
1741 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001742 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1743 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001744 case NEXT_TRANSIT_TYPE_SCALE_UP:
1745 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1746 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1747 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1748 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1749 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001750 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1751 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1752 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1753 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001754 default:
1755 return "unknown type=" + mNextAppTransitionType;
1756 }
1757 }
1758
Craig Mautner164d4bb2012-11-26 13:51:23 -08001759 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001760 public void dump(PrintWriter pw, String prefix) {
1761 pw.print(prefix); pw.println(this);
1762 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001763 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001764 pw.print(prefix); pw.print("mNextAppTransitionType=");
1765 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001766 }
1767 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001768 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001769 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001770 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001771 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001772 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1773 pw.print(" mNextAppTransitionExit=0x");
1774 pw.println(Integer.toHexString(mNextAppTransitionExit));
1775 break;
Winson Chung044d5292014-11-06 11:05:19 -08001776 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001777 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001778 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001779 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001780 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1781 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001782 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001783 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001784 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001785 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001786 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001787 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001788 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001789 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001790 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001791 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001792 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001793 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001794 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1795 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001796 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001797 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1798 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1799 pw.println(mDefaultNextAppTransitionAnimationSpec);
1800 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1801 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001802 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1803 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001804 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001805 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001806 }
1807 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001808 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1809 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001810 }
1811 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001812
1813 public void setCurrentUser(int newUserId) {
1814 mCurrentUserId = newUserId;
1815 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001816
1817 /**
1818 * @return true if transition is not running and should not be skipped, false if transition is
1819 * already running
1820 */
1821 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent) {
1822 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
1823 + " transit=" + appTransitionToString(transit)
1824 + " " + this
1825 + " alwaysKeepCurrent=" + alwaysKeepCurrent
1826 + " Callers=" + Debug.getCallers(3));
1827 if (!isTransitionSet() || mNextAppTransition == TRANSIT_NONE) {
1828 setAppTransition(transit);
1829 } else if (!alwaysKeepCurrent) {
1830 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
1831 // Opening a new task always supersedes a close for the anim.
1832 setAppTransition(transit);
1833 } else if (transit == TRANSIT_ACTIVITY_OPEN
1834 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
1835 // Opening a new activity always supersedes a close for the anim.
1836 setAppTransition(transit);
1837 }
1838 }
1839 boolean prepared = prepare();
1840 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001841 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
1842 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001843 }
1844 return prepared;
1845 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001846}