blob: eb0ca232462b92253e3d3f84642e77a2a77266a8 [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;
42
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070043import android.annotation.Nullable;
Craig Mautner164d4bb2012-11-26 13:51:23 -080044import android.content.Context;
Winson Chung2820c452014-04-15 15:34:44 -070045import android.content.res.Configuration;
Craig Mautner164d4bb2012-11-26 13:51:23 -080046import android.graphics.Bitmap;
Winson Chung399f6202014-03-19 10:47:20 -070047import android.graphics.Rect;
Craig Mautner164d4bb2012-11-26 13:51:23 -080048import android.os.Debug;
49import android.os.Handler;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010050import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080051import android.os.IRemoteCallback;
52import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070053import android.util.SparseArray;
54import android.view.AppTransitionAnimationSpec;
Craig Mautner164d4bb2012-11-26 13:51:23 -080055import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080056import android.view.animation.AlphaAnimation;
57import android.view.animation.Animation;
58import android.view.animation.AnimationSet;
59import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070060import android.view.animation.ClipRectAnimation;
Chet Haase10e23ab2015-02-11 15:08:38 -080061import android.view.animation.ClipRectLRAnimation;
62import android.view.animation.ClipRectTBAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080063import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070064import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080065import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070066import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070067
Craig Mautner164d4bb2012-11-26 13:51:23 -080068import com.android.internal.util.DumpUtils.Dump;
69import com.android.server.AttributeCache;
70import com.android.server.wm.WindowManagerService.H;
71
72import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010073import java.util.ArrayList;
Craig Mautner164d4bb2012-11-26 13:51:23 -080074
Craig Mautner164d4bb2012-11-26 13:51:23 -080075// State management of app transitions. When we are preparing for a
76// transition, mNextAppTransition will be the kind of transition to
77// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
78// mOpeningApps and mClosingApps are the lists of tokens that will be
79// made visible or hidden at the next transition.
80public class AppTransition implements Dump {
81 private static final String TAG = "AppTransition";
Craig Mautner321bdf52012-12-18 09:53:24 -080082 private static final boolean DEBUG_APP_TRANSITIONS =
83 WindowManagerService.DEBUG_APP_TRANSITIONS;
84 private static final boolean DEBUG_ANIM = WindowManagerService.DEBUG_ANIM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070085 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080086
Craig Mautner4b71aa12012-12-27 17:20:01 -080087 /** Not set up for a transition. */
88 public static final int TRANSIT_UNSET = -1;
89 /** No animation for transition. */
90 public static final int TRANSIT_NONE = 0;
91 /** 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 -070092 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -080093 /** The window in the top-most activity is being closed to reveal the
94 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -070095 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -080096 /** A window in a new task is being opened on top of an existing one
97 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -070098 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -080099 /** A window in the top-most activity is being closed to reveal the
100 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700101 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800102 /** A window in an existing task is being displayed on top of an existing one
103 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700104 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800105 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700106 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800107 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
108 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700109 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800110 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
111 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700112 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800113 /** A window in a new activity is being opened on top of an existing one, and both are on top
114 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700115 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800116 /** The window in the top-most activity is being closed to reveal the previous activity, and
117 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700118 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
119 /** A window in a new task is being opened behind an existing one in another activity's task.
120 * The new window will show briefly and then be gone. */
121 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800122 /** A window in a task is being animated in-place. */
123 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700124 /** An activity is being relaunched (e.g. due to configuration change). */
125 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800126
Winson Chunga4ccb862014-08-22 15:26:27 -0700127 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700128 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800129 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700130 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800131
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700132 private static final int DEFAULT_APP_TRANSITION_DURATION = 336;
133 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
134 private static final int THUMBNAIL_APP_TRANSITION_ALPHA_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700135 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800136
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800137 private final Context mContext;
138 private final Handler mH;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800139
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800140 private int mNextAppTransition = TRANSIT_UNSET;
141
142 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
143 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
144 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
145 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
146 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700147 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
148 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800149 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800150 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800151 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
152
Winson Chung399f6202014-03-19 10:47:20 -0700153 // These are the possible states for the enter/exit activities during a thumbnail transition
154 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
155 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
156 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
157 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
158
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800159 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800160 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800161 private boolean mNextAppTransitionScaleUp;
162 private IRemoteCallback mNextAppTransitionCallback;
163 private int mNextAppTransitionEnter;
164 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800165 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700166
167 // Keyed by task id.
168 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
169 = new SparseArray<>();
170 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
171
Winson Chunga4ccb862014-08-22 15:26:27 -0700172 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800173
Winson Chung2820c452014-04-15 15:34:44 -0700174 private Rect mTmpFromClipRect = new Rect();
175 private Rect mTmpToClipRect = new Rect();
176
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700177 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700178
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800179 private final static int APP_STATE_IDLE = 0;
180 private final static int APP_STATE_READY = 1;
181 private final static int APP_STATE_RUNNING = 2;
182 private final static int APP_STATE_TIMEOUT = 3;
183 private int mAppTransitionState = APP_STATE_IDLE;
184
185 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800186 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700187 private final Interpolator mThumbnailFadeInInterpolator;
188 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800189 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700190 private final Interpolator mFastOutLinearInInterpolator;
191 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
192
193 /** Interpolator to be used for animations that respond directly to a touch */
194 private final Interpolator mTouchResponseInterpolator =
195 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
196
197 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800198
Amith Yamasani4befbec2013-07-10 16:18:01 -0700199 private int mCurrentUserId = 0;
200
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100201 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
202
Craig Mautner164d4bb2012-11-26 13:51:23 -0800203 AppTransition(Context context, Handler h) {
204 mContext = context;
205 mH = h;
Chet Haase10e23ab2015-02-11 15:08:38 -0800206 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
207 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700208 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
209 com.android.internal.R.interpolator.fast_out_linear_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800210 mConfigShortAnimTime = context.getResources().getInteger(
211 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800212 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
213 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700214 mThumbnailFadeInInterpolator = new Interpolator() {
215 @Override
216 public float getInterpolation(float input) {
217 // Linear response for first fraction, then complete after that.
218 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
219 return 0f;
220 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700221 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700222 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700223 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700224 }
225 };
226 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800227 @Override
228 public float getInterpolation(float input) {
229 // Linear response for first fraction, then complete after that.
230 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700231 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
232 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800233 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700234 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800235 }
236 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700237 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
238 * mContext.getResources().getDisplayMetrics().density);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800239 }
240
241 boolean isTransitionSet() {
242 return mNextAppTransition != TRANSIT_UNSET;
243 }
244
Craig Mautner164d4bb2012-11-26 13:51:23 -0800245 boolean isTransitionEqual(int transit) {
246 return mNextAppTransition == transit;
247 }
248
249 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800250 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800251 }
252
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700253 private void setAppTransition(int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800254 mNextAppTransition = transit;
255 }
256
257 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800258 return mAppTransitionState == APP_STATE_READY
259 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800260 }
261
Craig Mautnerae446592012-12-06 19:05:05 -0800262 void setReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800263 mAppTransitionState = APP_STATE_READY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800264 }
265
266 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800267 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800268 }
269
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800270 void setIdle() {
271 mAppTransitionState = APP_STATE_IDLE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800272 }
273
274 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800275 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800276 }
277
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800278 void setTimeout() {
279 mAppTransitionState = APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800280 }
281
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700282 Bitmap getAppTransitionThumbnailHeader(int taskId) {
283 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
284 return spec != null ? spec.bitmap : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800285 }
286
Winson Chunga4ccb862014-08-22 15:26:27 -0700287 /** Returns whether the next thumbnail transition is aspect scaled up. */
288 boolean isNextThumbnailTransitionAspectScaled() {
289 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
290 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
291 }
292
293 /** Returns whether the next thumbnail transition is scaling up. */
294 boolean isNextThumbnailTransitionScaleUp() {
295 return mNextAppTransitionScaleUp;
296 }
297
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700298 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800299 if (!isRunning()) {
300 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100301 notifyAppTransitionPendingLocked();
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700302 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800303 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700304 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800305 }
306
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100307 void goodToGo(AppWindowAnimator openingAppAnimator, AppWindowAnimator closingAppAnimator) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800308 mNextAppTransition = TRANSIT_UNSET;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800309 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100310 notifyAppTransitionStartingLocked(
311 openingAppAnimator != null ? openingAppAnimator.mAppToken.token : null,
312 closingAppAnimator != null ? closingAppAnimator.mAppToken.token : null,
313 openingAppAnimator != null ? openingAppAnimator.animation : null,
314 closingAppAnimator != null ? closingAppAnimator.animation : null);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800315 }
316
317 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800318 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800319 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700320 mNextAppTransitionAnimationsSpecs.clear();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800321 }
322
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800323 void freeze() {
324 setAppTransition(AppTransition.TRANSIT_UNSET);
325 clear();
326 setReady();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100327 notifyAppTransitionCancelledLocked();
328 }
329
330 void registerListenerLocked(AppTransitionListener listener) {
331 mListeners.add(listener);
332 }
333
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700334 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100335 for (int i = 0; i < mListeners.size(); i++) {
336 mListeners.get(i).onAppTransitionFinishedLocked(token);
337 }
338 }
339
340 private void notifyAppTransitionPendingLocked() {
341 for (int i = 0; i < mListeners.size(); i++) {
342 mListeners.get(i).onAppTransitionPendingLocked();
343 }
344 }
345
346 private void notifyAppTransitionCancelledLocked() {
347 for (int i = 0; i < mListeners.size(); i++) {
348 mListeners.get(i).onAppTransitionCancelledLocked();
349 }
350 }
351
352 private void notifyAppTransitionStartingLocked(IBinder openToken,
353 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
354 for (int i = 0; i < mListeners.size(); i++) {
355 mListeners.get(i).onAppTransitionStartingLocked(openToken, closeToken, openAnimation,
356 closeAnimation);
357 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800358 }
359
Craig Mautner164d4bb2012-11-26 13:51:23 -0800360 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
361 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
362 + (lp != null ? lp.packageName : null)
363 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
364 if (lp != null && lp.windowAnimations != 0) {
365 // If this is a system resource, don't try to load it from the
366 // application resources. It is nice to avoid loading application
367 // resources if we can.
368 String packageName = lp.packageName != null ? lp.packageName : "android";
369 int resId = lp.windowAnimations;
370 if ((resId&0xFF000000) == 0x01000000) {
371 packageName = "android";
372 }
373 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
374 + packageName);
375 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700376 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800377 }
378 return null;
379 }
380
381 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
382 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
383 + packageName + " resId=0x" + Integer.toHexString(resId));
384 if (packageName != null) {
385 if ((resId&0xFF000000) == 0x01000000) {
386 packageName = "android";
387 }
388 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
389 + packageName);
390 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700391 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800392 }
393 return null;
394 }
395
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700396 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800397 int anim = 0;
398 Context context = mContext;
399 if (animAttr >= 0) {
400 AttributeCache.Entry ent = getCachedAnimations(lp);
401 if (ent != null) {
402 context = ent.context;
403 anim = ent.array.getResourceId(animAttr, 0);
404 }
405 }
406 if (anim != 0) {
407 return AnimationUtils.loadAnimation(context, anim);
408 }
409 return null;
410 }
411
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700412 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
413 Context context = mContext;
414 if (resId >= 0) {
415 AttributeCache.Entry ent = getCachedAnimations(lp);
416 if (ent != null) {
417 context = ent.context;
418 }
419 return AnimationUtils.loadAnimation(context, resId);
420 }
421 return null;
422 }
423
424 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800425 int anim = 0;
426 Context context = mContext;
427 if (resId >= 0) {
428 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
429 if (ent != null) {
430 context = ent.context;
431 anim = resId;
432 }
433 }
434 if (anim != 0) {
435 return AnimationUtils.loadAnimation(context, anim);
436 }
437 return null;
438 }
439
Craig Mautner164d4bb2012-11-26 13:51:23 -0800440 /**
441 * Compute the pivot point for an animation that is scaling from a small
442 * rect on screen to a larger rect. The pivot point varies depending on
443 * the distance between the inner and outer edges on both sides. This
444 * function computes the pivot point for one dimension.
445 * @param startPos Offset from left/top edge of outer rectangle to
446 * left/top edge of inner rectangle.
447 * @param finalScale The scaling factor between the size of the outer
448 * and inner rectangles.
449 */
450 private static float computePivot(int startPos, float finalScale) {
451 final float denom = finalScale-1;
452 if (Math.abs(denom) < .0001f) {
453 return startPos;
454 }
455 return -startPos / denom;
456 }
457
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700458 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
459 Rect containingFrame) {
460 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700461 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700462 final int appWidth = containingFrame.width();
463 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800464 if (enter) {
465 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700466 float scaleW = mTmpRect.width() / (float) appWidth;
467 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800468 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700469 computePivot(mTmpRect.left, scaleW),
470 computePivot(mTmpRect.right, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800471 scale.setInterpolator(mDecelerateInterpolator);
472
Craig Mautner164d4bb2012-11-26 13:51:23 -0800473 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700474 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800475
476 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800477 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800478 set.addAnimation(alpha);
479 set.setDetachWallpaper(true);
480 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800481 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
482 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800483 // If we are on top of the wallpaper, we need an animation that
484 // correctly handles the wallpaper staying static behind all of
485 // the animated elements. To do this, will just have the existing
486 // element fade out.
487 a = new AlphaAnimation(1, 0);
488 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800489 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800490 // For normal animations, the exiting element just holds in place.
491 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800492 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800493
494 // Pick the desired duration. If this is an inter-activity transition,
495 // it is the standard duration for that. Otherwise we use the longer
496 // task transition duration.
497 final long duration;
498 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800499 case TRANSIT_ACTIVITY_OPEN:
500 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800501 duration = mConfigShortAnimTime;
502 break;
503 default:
504 duration = DEFAULT_APP_TRANSITION_DURATION;
505 break;
506 }
507 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800508 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800509 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800510 a.initialize(appWidth, appHeight, appWidth, appHeight);
511 return a;
512 }
513
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700514 private void getDefaultNextAppTransitionStartRect(Rect rect) {
515 if (mDefaultNextAppTransitionAnimationSpec == null ||
516 mDefaultNextAppTransitionAnimationSpec.rect == null) {
517 Slog.wtf(TAG, "Starting rect for app requested, but none available", new Throwable());
518 rect.setEmpty();
519 } else {
520 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
521 }
522 }
523
524 void getNextAppTransitionStartRect(int taskId, Rect rect) {
525 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
526 if (spec == null || spec.rect == null) {
527 Slog.wtf(TAG, "Starting rect for task: " + taskId + " requested, but not available",
528 new Throwable());
529 rect.setEmpty();
530 } else {
531 rect.set(spec.rect);
532 }
533 }
534
535 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height) {
536 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
537 null /* bitmap */, new Rect(left, top, left + width, top + height));
538 }
539
Craig Mautner80b1f642015-04-22 10:59:09 -0700540 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800541 final Animation anim;
542 if (enter) {
543 // Reveal will expand and move faster in horizontal direction
544
Craig Mautner80b1f642015-04-22 10:59:09 -0700545 final int appWidth = appFrame.width();
546 final int appHeight = appFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700547 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700548 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700549 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700550
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700551 float t = 0f;
552 if (appHeight > 0) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700553 t = (float) mTmpRect.left / appHeight;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700554 }
Filip Gruszczynski82861362015-10-16 14:21:09 -0700555 int translationY = mClipRevealTranslationY + (int)(appHeight / 7f * t);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700556
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700557 int centerX = mTmpRect.centerX();
558 int centerY = mTmpRect.centerY();
559 int halfWidth = mTmpRect.width() / 2;
560 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700561
562 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800563 Animation clipAnimLR = new ClipRectLRAnimation(
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700564 centerX - halfWidth, centerX + halfWidth, 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700565 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
566 clipAnimLR.setDuration((long) (DEFAULT_APP_TRANSITION_DURATION / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700567
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700568 Animation clipAnimTB = new ClipRectTBAnimation(centerY - halfHeight - translationY,
569 centerY + halfHeight/ 2 - translationY, 0, appHeight);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700570 clipAnimTB.setInterpolator(mTouchResponseInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800571 clipAnimTB.setDuration(DEFAULT_APP_TRANSITION_DURATION);
572
Filip Gruszczynski82861362015-10-16 14:21:09 -0700573 // We might be animating entrance of a docked task, so we need the translate to account
574 // for the app frame in which the window will reside. Every other calculation here
575 // is performed as if the window started at 0,0.
576 translationY -= appFrame.top;
577 TranslateAnimation translate = new TranslateAnimation(-appFrame.left, 0, translationY,
578 0);
579 translate.setInterpolator(mLinearOutSlowInInterpolator);
580 translate.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Chet Haase10e23ab2015-02-11 15:08:38 -0800581
582 // Quick fade-in from icon to app window
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700583 final int alphaDuration = DEFAULT_APP_TRANSITION_DURATION / 4;
584 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800585 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700586 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800587
588 AnimationSet set = new AnimationSet(false);
589 set.addAnimation(clipAnimLR);
590 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700591 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800592 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700593 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800594 set.initialize(appWidth, appHeight, appWidth, appHeight);
595 anim = set;
596 } else {
597 final long duration;
598 switch (transit) {
599 case TRANSIT_ACTIVITY_OPEN:
600 case TRANSIT_ACTIVITY_CLOSE:
601 duration = mConfigShortAnimTime;
602 break;
603 default:
604 duration = DEFAULT_APP_TRANSITION_DURATION;
605 break;
606 }
607 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
608 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
609 // If we are on top of the wallpaper, we need an animation that
610 // correctly handles the wallpaper staying static behind all of
611 // the animated elements. To do this, will just have the existing
612 // element fade out.
613 anim = new AlphaAnimation(1, 0);
614 anim.setDetachWallpaper(true);
615 } else {
616 // For normal animations, the exiting element just holds in place.
617 anim = new AlphaAnimation(1, 1);
618 }
619 anim.setInterpolator(mDecelerateInterpolator);
620 anim.setDuration(duration);
621 anim.setFillAfter(true);
622 }
623 return anim;
624 }
625
Winson Chung399f6202014-03-19 10:47:20 -0700626 /**
627 * Prepares the specified animation with a standard duration, interpolator, etc.
628 */
Winson Chung5393dff2014-05-08 14:25:43 -0700629 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
630 int duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700631 if (duration > 0) {
632 a.setDuration(duration);
633 }
Winson Chung5393dff2014-05-08 14:25:43 -0700634 a.setFillAfter(true);
635 a.setInterpolator(interpolator);
636 a.initialize(appWidth, appHeight, appWidth, appHeight);
637 return a;
638 }
639
640 /**
641 * Prepares the specified animation with a standard duration, interpolator, etc.
642 */
Winson Chung399f6202014-03-19 10:47:20 -0700643 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800644 // Pick the desired duration. If this is an inter-activity transition,
645 // it is the standard duration for that. Otherwise we use the longer
646 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700647 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800648 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800649 case TRANSIT_ACTIVITY_OPEN:
650 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800651 duration = mConfigShortAnimTime;
652 break;
653 default:
654 duration = DEFAULT_APP_TRANSITION_DURATION;
655 break;
656 }
Winson Chung5393dff2014-05-08 14:25:43 -0700657 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
658 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800659 }
660
Winson Chung399f6202014-03-19 10:47:20 -0700661 /**
662 * Return the current thumbnail transition state.
663 */
664 int getThumbnailTransitionState(boolean enter) {
665 if (enter) {
666 if (mNextAppTransitionScaleUp) {
667 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
668 } else {
669 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
670 }
671 } else {
672 if (mNextAppTransitionScaleUp) {
673 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
674 } else {
675 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
676 }
677 }
678 }
679
680 /**
681 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700682 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700683 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700684 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, Bitmap thumbnailHeader,
685 final int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700686 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700687 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700688 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700689 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chung399f6202014-03-19 10:47:20 -0700690 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700691 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700692
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700693 float scaleW = appWidth / thumbWidth;
Winson Chunga4ccb862014-08-22 15:26:27 -0700694 float unscaledHeight = thumbHeight * scaleW;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700695 getNextAppTransitionStartRect(taskId, mTmpRect);
696 float unscaledStartY = mTmpRect.top - (unscaledHeight - thumbHeight) / 2f;
Winson Chung399f6202014-03-19 10:47:20 -0700697 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700698 // Animation up from the thumbnail to the full screen
699 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700700 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700701 scale.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700702 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700703 Animation alpha = new AlphaAnimation(1, 0);
Winson Chunga4ccb862014-08-22 15:26:27 -0700704 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
705 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700706 final float toX = appRect.left + appRect.width() / 2 -
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700707 (mTmpRect.left + thumbWidth / 2);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700708 final float toY = appRect.top + mNextAppTransitionInsets.top + -unscaledStartY;
709 Animation translate = new TranslateAnimation(0, toX, 0, toY);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700710 translate.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700711 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700712
713 // This AnimationSet uses the Interpolators assigned above.
714 AnimationSet set = new AnimationSet(false);
715 set.addAnimation(scale);
716 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -0700717 set.addAnimation(translate);
Winson Chung399f6202014-03-19 10:47:20 -0700718 a = set;
719 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700720 // Animation down from the full screen to the thumbnail
721 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700722 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700723 scale.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700724 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
725 Animation alpha = new AlphaAnimation(0f, 1f);
726 alpha.setInterpolator(mThumbnailFadeInInterpolator);
727 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
728 Animation translate = new TranslateAnimation(0, 0, -unscaledStartY +
729 mNextAppTransitionInsets.top, 0);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700730 translate.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700731 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700732
Winson Chunga4ccb862014-08-22 15:26:27 -0700733 // This AnimationSet uses the Interpolators assigned above.
734 AnimationSet set = new AnimationSet(false);
735 set.addAnimation(scale);
736 set.addAnimation(alpha);
737 set.addAnimation(translate);
738 a = set;
739
740 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700741 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700742 mTouchResponseInterpolator);
Winson Chung399f6202014-03-19 10:47:20 -0700743 }
744
745 /**
746 * This alternate animation is created when we are doing a thumbnail transition, for the
747 * activity that is leaving, and the activity that is entering.
748 */
Winson Chunga4ccb862014-08-22 15:26:27 -0700749 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700750 int orientation, int transit, Rect containingFrame, Rect contentInsets,
751 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700752 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700753 final int appWidth = containingFrame.width();
754 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700755 getDefaultNextAppTransitionStartRect(mTmpRect);
756 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700757 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700758 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -0700759 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
760
Winson Chung2820c452014-04-15 15:34:44 -0700761 // Used for the ENTER_SCALE_UP and EXIT_SCALE_DOWN transitions
762 float scale = 1f;
763 int scaledTopDecor = 0;
764
Winson Chung399f6202014-03-19 10:47:20 -0700765 switch (thumbTransitState) {
766 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700767 if (freeform) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700768 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700769 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -0700770 } else {
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700771 mTmpFromClipRect.set(containingFrame);
772 // exclude top screen decor (status bar) region from the source clip.
773 mTmpFromClipRect.top = contentInsets.top;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700774 // App window scaling up to become full screen
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700775 mTmpToClipRect.set(containingFrame);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700776 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
777 // In portrait, we scale the width and clip to the top/left square
778 scale = thumbWidth / appWidth;
779 scaledTopDecor = (int) (scale * contentInsets.top);
780 int unscaledThumbHeight = (int) (thumbHeight / scale);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700781 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700782 } else {
Filip Gruszczynskidd2ff842015-10-25 13:11:04 -0700783 // In landscape, we scale the height and clip to the top/left square. We
784 // only scale the part that is not covered by status bar and the nav bar.
785 scale = thumbHeight / (appHeight - contentInsets.top
786 - contentInsets.bottom);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700787 scaledTopDecor = (int) (scale * contentInsets.top);
788 int unscaledThumbWidth = (int) (thumbWidth / scale);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700789 mTmpFromClipRect.right = mTmpFromClipRect.left + unscaledThumbWidth;
Filip Gruszczynskidd2ff842015-10-25 13:11:04 -0700790 // This removes the navigation bar from the first frame, so it better
791 // matches the thumbnail. We need to do this explicitly in landscape,
792 // because in portrait we already crop vertically.
793 mTmpFromClipRect.bottom = mTmpFromClipRect.bottom - contentInsets.bottom;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700794 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700795
796 mNextAppTransitionInsets.set(contentInsets);
797
798 Animation scaleAnim = new ScaleAnimation(scale, 1, scale, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700799 computePivot(mTmpRect.left, scale),
800 computePivot(mTmpRect.top, scale));
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700801 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
802 Animation translateAnim = new TranslateAnimation(0, 0, -scaledTopDecor, 0);
803
804 AnimationSet set = new AnimationSet(true);
805 set.addAnimation(clipAnim);
806 set.addAnimation(scaleAnim);
807 set.addAnimation(translateAnim);
808 a = set;
Winson Chung2820c452014-04-15 15:34:44 -0700809 }
Winson Chung399f6202014-03-19 10:47:20 -0700810 break;
811 }
812 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700813 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -0700814 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700815 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -0700816 // activity.
817 a = new AlphaAnimation(1, 0);
818 } else {
Winson Chung399f6202014-03-19 10:47:20 -0700819 a = new AlphaAnimation(1, 1);
820 }
821 break;
822 }
823 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700824 // Target app window during the scale down
825 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
826 // Fade in the destination activity if we are animating from a wallpaper
827 // activity.
828 a = new AlphaAnimation(0, 1);
829 } else {
830 a = new AlphaAnimation(1, 1);
831 }
Winson Chung399f6202014-03-19 10:47:20 -0700832 break;
833 }
834 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700835 // App window scaling down from full screen
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700836 if (freeform) {
837 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
838 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -0700839 } else {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700840 mTmpFromClipRect.set(containingFrame);
841 mTmpToClipRect.set(containingFrame);
842 // exclude top screen decor (status bar) region from the destination clip.
843 mTmpToClipRect.top = contentInsets.top;
844 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
845 // In portrait, we scale the width and clip to the top/left square
846 scale = thumbWidth / appWidth;
847 scaledTopDecor = (int) (scale * contentInsets.top);
848 int unscaledThumbHeight = (int) (thumbHeight / scale);
849 mTmpToClipRect.bottom = mTmpToClipRect.top + unscaledThumbHeight;
850 } else {
851 // In landscape, we scale the height and clip to the top/left square. We only
852 // scale the part that is not covered by status bar and the nav bar.
853 scale = thumbHeight / (appHeight - contentInsets.top - contentInsets.bottom);
854 scaledTopDecor = (int) (scale * contentInsets.top);
855 int unscaledThumbWidth = (int) (thumbWidth / scale);
856 mTmpToClipRect.right = mTmpToClipRect.left + unscaledThumbWidth;
857 // This removes the navigation bar from the last frame, so it better matches the
858 // thumbnail. We need to do this explicitly in landscape, because in portrait we
859 // already crop vertically.
860 mTmpToClipRect.bottom = mTmpToClipRect.bottom - contentInsets.bottom;
861 }
862
863 mNextAppTransitionInsets.set(contentInsets);
864
865 Animation scaleAnim = new ScaleAnimation(1, scale, 1, scale,
866 computePivot(mTmpRect.left, scale),
867 computePivot(mTmpRect.top, scale));
868 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
869 Animation translateAnim = new TranslateAnimation(0, 0, 0, -scaledTopDecor);
870
871 AnimationSet set = new AnimationSet(true);
872 set.addAnimation(clipAnim);
873 set.addAnimation(scaleAnim);
874 set.addAnimation(translateAnim);
875
876 a = set;
877 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -0700878 }
Winson Chung399f6202014-03-19 10:47:20 -0700879 break;
880 }
881 default:
882 throw new RuntimeException("Invalid thumbnail transition state");
883 }
884
Winson Chungab79fce2014-11-04 16:15:22 -0800885 int duration = Math.max(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION,
886 THUMBNAIL_APP_TRANSITION_DURATION);
887 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700888 mTouchResponseInterpolator);
Winson Chung399f6202014-03-19 10:47:20 -0700889 }
890
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700891 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
892 @Nullable Rect surfaceInsets, int taskId) {
893 getNextAppTransitionStartRect(taskId, mTmpRect);
894 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
895 true);
896 }
897
898 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
899 @Nullable Rect surfaceInsets, int taskId) {
900 getNextAppTransitionStartRect(taskId, mTmpRect);
901 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
902 false);
903 }
904
905 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
906 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
907 final float sourceWidth = sourceFrame.width();
908 final float sourceHeight = sourceFrame.height();
909 final float destWidth = destFrame.width();
910 final float destHeight = destFrame.height();
911 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
912 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700913 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700914 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700915 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700916 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700917 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
918 // We want the scaling to happen from the center of the surface. In order to achieve that,
919 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700920 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
921 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
922 final ScaleAnimation scale = enter ?
923 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
924 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
925 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
926 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
927 final int destHCenter = destFrame.left + destFrame.width() / 2;
928 final int destVCenter = destFrame.top + destFrame.height() / 2;
929 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
930 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
931 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
932 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700933 set.addAnimation(scale);
934 set.addAnimation(translation);
935 return set;
936 }
937
Winson Chung399f6202014-03-19 10:47:20 -0700938 /**
Winson Chunga4ccb862014-08-22 15:26:27 -0700939 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700940 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -0700941 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700942 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
943 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700944 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700945 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700946 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -0700947 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700948 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -0700949 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
950
951 if (mNextAppTransitionScaleUp) {
952 // Animation for the thumbnail zooming from its initial size to the full screen
953 float scaleW = appWidth / thumbWidth;
954 float scaleH = appHeight / thumbHeight;
955 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700956 computePivot(mTmpRect.left, 1 / scaleW),
957 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -0700958 scale.setInterpolator(mDecelerateInterpolator);
959
960 Animation alpha = new AlphaAnimation(1, 0);
961 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
962
963 // This AnimationSet uses the Interpolators assigned above.
964 AnimationSet set = new AnimationSet(false);
965 set.addAnimation(scale);
966 set.addAnimation(alpha);
967 a = set;
968 } else {
969 // Animation for the thumbnail zooming down from the full screen to its final size
970 float scaleW = appWidth / thumbWidth;
971 float scaleH = appHeight / thumbHeight;
972 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700973 computePivot(mTmpRect.left, 1 / scaleW),
974 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -0700975 }
976
977 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
978 }
979
980 /**
Winson Chung399f6202014-03-19 10:47:20 -0700981 * This animation is created when we are doing a thumbnail transition, for the activity that is
982 * leaving, and the activity that is entering.
983 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700984 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
985 int transit, int taskId) {
986 final int appWidth = containingFrame.width();
987 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700988 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -0700989 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700990 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700991 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -0700992 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700993 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -0700994 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
995
996 switch (thumbTransitState) {
997 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
998 // Entering app scales up with the thumbnail
999 float scaleW = thumbWidth / appWidth;
1000 float scaleH = thumbHeight / appHeight;
1001 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001002 computePivot(mTmpRect.left, scaleW),
1003 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001004 break;
1005 }
1006 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1007 // Exiting app while the thumbnail is scaling up should fade or stay in place
1008 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1009 // Fade out while bringing up selected activity. This keeps the
1010 // current activity from showing through a launching wallpaper
1011 // activity.
1012 a = new AlphaAnimation(1, 0);
1013 } else {
1014 // noop animation
1015 a = new AlphaAnimation(1, 1);
1016 }
1017 break;
1018 }
1019 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1020 // Entering the other app, it should just be visible while we scale the thumbnail
1021 // down above it
1022 a = new AlphaAnimation(1, 1);
1023 break;
1024 }
1025 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1026 // Exiting the current app, the app should scale down with the thumbnail
1027 float scaleW = thumbWidth / appWidth;
1028 float scaleH = thumbHeight / appHeight;
1029 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001030 computePivot(mTmpRect.left, scaleW),
1031 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001032
1033 Animation alpha = new AlphaAnimation(1, 0);
1034
1035 AnimationSet set = new AnimationSet(true);
1036 set.addAnimation(scale);
1037 set.addAnimation(alpha);
1038 set.setZAdjustment(Animation.ZORDER_TOP);
1039 a = set;
1040 break;
1041 }
1042 default:
1043 throw new RuntimeException("Invalid thumbnail transition state");
1044 }
1045
1046 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1047 }
1048
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001049 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001050 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1051 final int left = mTmpFromClipRect.left;
1052 final int top = mTmpFromClipRect.top;
1053 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001054 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1055 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001056 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001057 float fromWidth = mTmpFromClipRect.width();
1058 float toWidth = mTmpToClipRect.width();
1059 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001060 // While the window might span the whole display, the actual content will be cropped to the
1061 // system decoration frame, for example when the window is docked. We need to take into
1062 // account the visible height when constructing the animation.
1063 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1064 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001065 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1066 // The final window is larger in both dimensions than current window (e.g. we are
1067 // maximizing), so we can simply unclip the new window and there will be no disappearing
1068 // frame.
1069 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1070 } else {
1071 // The disappearing window has one larger dimension. We need to apply scaling, so the
1072 // first frame of the entry animation matches the old window.
1073 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001074 // We might not be going exactly full screen, but instead be aligned under the status
1075 // bar using cropping. We still need to account for the cropped part, which will also
1076 // be scaled.
1077 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001078 }
1079
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001080 // We animate the translation from the old position of the removed window, to the new
1081 // position of the added window. The latter might not be full screen, for example docked for
1082 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001083 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001084 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001085 set.addAnimation(translate);
1086 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001087 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001088 return set;
1089 }
1090
Jorim Jaggic554b772015-06-04 16:07:57 -07001091 /**
1092 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1093 * frame of the transition doesn't change the visuals on screen, so we can start
1094 * directly with the second one
1095 */
1096 boolean canSkipFirstFrame() {
1097 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1098 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
1099 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1100 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001101
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001102 /**
1103 *
1104 * @param frame These are the bounds of the window when it finishes the animation. This is where
1105 * the animation must usually finish in entrance animation, as the next frame will
1106 * display the window at these coordinates. In case of exit animation, this is
1107 * where the animation must start, as the frame before the animation is displaying
1108 * the window at these bounds.
1109 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1110 * window might be obscured, usually by the system windows (status bar and
1111 * navigation bar) and we use content insets to convey that information. This
1112 * usually affects the animation aspects vertically, as the system decoration is
1113 * at the top and the bottom. For example when we animate from full screen to
1114 * recents, we want to exclude the covered parts, because they won't match the
1115 * thumbnail after the last frame is executed.
1116 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1117 * know about this to make the animation frames match. We currently use
1118 * this for freeform windows, which have larger surfaces to display
1119 * shadows. When we animate them from recents, we want to match the content
1120 * to the recents thumbnail and hence need to account for the surface being
1121 * bigger.
1122 */
Craig Mautner164d4bb2012-11-26 13:51:23 -08001123 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001124 int orientation, Rect frame, Rect insets, @Nullable Rect surfaceInsets,
1125 boolean isVoiceInteraction, boolean freeform, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001126 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001127 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
1128 || transit == TRANSIT_TASK_OPEN
1129 || transit == TRANSIT_TASK_TO_FRONT)) {
1130 a = loadAnimationRes(lp, enter
1131 ? com.android.internal.R.anim.voice_activity_open_enter
1132 : com.android.internal.R.anim.voice_activity_open_exit);
1133 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1134 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001135 + " anim=" + a + " transit=" + appTransitionToString(transit)
1136 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001137 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1138 || transit == TRANSIT_TASK_CLOSE
1139 || transit == TRANSIT_TASK_TO_BACK)) {
1140 a = loadAnimationRes(lp, enter
1141 ? com.android.internal.R.anim.voice_activity_close_enter
1142 : com.android.internal.R.anim.voice_activity_close_exit);
1143 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1144 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001145 + " anim=" + a + " transit=" + appTransitionToString(transit)
1146 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001147 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001148 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001149 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1150 "applyAnimation:"
1151 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1152 + " transit=" + appTransitionToString(transit)
1153 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001154 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1155 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001156 mNextAppTransitionEnter : mNextAppTransitionExit);
1157 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1158 "applyAnimation:"
1159 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001160 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001161 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001162 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1163 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1164 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1165 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001166 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1167 + " transit=" + appTransitionToString(transit)
1168 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001169 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001170 a = createClipRevealAnimationLocked(transit, enter, frame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001171 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1172 "applyAnimation:"
1173 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001174 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001175 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001176 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001177 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001178 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1179 "applyAnimation:"
1180 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001181 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001182 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001183 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1184 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001185 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001186 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001187 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001188 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001189 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1190 String animName = mNextAppTransitionScaleUp ?
1191 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1192 Slog.v(TAG, "applyAnimation:"
1193 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001194 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001195 + " Callers=" + Debug.getCallers(3));
1196 }
1197 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1198 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1199 mNextAppTransitionScaleUp =
1200 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1201 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001202 getThumbnailTransitionState(enter), orientation, transit, frame,
1203 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001204 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1205 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001206 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001207 Slog.v(TAG, "applyAnimation:"
1208 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001209 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001210 + " Callers=" + Debug.getCallers(3));
1211 }
1212 } else {
1213 int animAttr = 0;
1214 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001215 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001216 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001217 ? WindowAnimation_activityOpenEnterAnimation
1218 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001219 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001220 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001221 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001222 ? WindowAnimation_activityCloseEnterAnimation
1223 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001224 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001225 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001226 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001227 ? WindowAnimation_taskOpenEnterAnimation
1228 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001229 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001230 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001231 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001232 ? WindowAnimation_taskCloseEnterAnimation
1233 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001234 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001235 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001236 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001237 ? WindowAnimation_taskToFrontEnterAnimation
1238 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001239 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001240 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001241 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001242 ? WindowAnimation_taskToBackEnterAnimation
1243 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001244 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001245 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001246 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001247 ? WindowAnimation_wallpaperOpenEnterAnimation
1248 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001249 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001250 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001251 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001252 ? WindowAnimation_wallpaperCloseEnterAnimation
1253 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001254 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001255 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001256 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001257 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1258 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001259 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001260 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001261 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001262 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1263 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001264 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001265 case TRANSIT_TASK_OPEN_BEHIND:
1266 animAttr = enter
1267 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001268 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001269 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001270 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001271 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1272 "applyAnimation:"
1273 + " anim=" + a
1274 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001275 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001276 + " Callers=" + Debug.getCallers(3));
1277 }
1278 return a;
1279 }
1280
1281 void postAnimationCallback() {
1282 if (mNextAppTransitionCallback != null) {
1283 mH.sendMessage(mH.obtainMessage(H.DO_ANIMATION_CALLBACK, mNextAppTransitionCallback));
1284 mNextAppTransitionCallback = null;
1285 }
1286 }
1287
1288 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001289 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001290 if (isTransitionSet()) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001291 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001292 mNextAppTransitionPackage = packageName;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001293 mNextAppTransitionAnimationsSpecs.clear();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001294 mNextAppTransitionEnter = enterAnim;
1295 mNextAppTransitionExit = exitAnim;
1296 postAnimationCallback();
1297 mNextAppTransitionCallback = startedCallback;
1298 } else {
1299 postAnimationCallback();
1300 }
1301 }
1302
1303 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001304 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001305 if (isTransitionSet()) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001306 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001307 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001308 mNextAppTransitionAnimationsSpecs.clear();
1309 putDefaultNextAppTransitionCoordinates(startX, startY, startX + startWidth,
1310 startY + startHeight);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001311 postAnimationCallback();
1312 mNextAppTransitionCallback = null;
1313 }
1314 }
1315
Chet Haase10e23ab2015-02-11 15:08:38 -08001316 void overridePendingAppTransitionClipReveal(int startX, int startY,
1317 int startWidth, int startHeight) {
1318 if (isTransitionSet()) {
1319 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001320 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight);
Chet Haase10e23ab2015-02-11 15:08:38 -08001321 postAnimationCallback();
1322 mNextAppTransitionCallback = null;
1323 }
1324 }
1325
Craig Mautner164d4bb2012-11-26 13:51:23 -08001326 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1327 IRemoteCallback startedCallback, boolean scaleUp) {
1328 if (isTransitionSet()) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001329 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1330 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001331 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001332 mNextAppTransitionAnimationsSpecs.clear();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001333 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001334 putDefaultNextAppTransitionCoordinates(startX, startY, 0 ,0);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001335 postAnimationCallback();
1336 mNextAppTransitionCallback = startedCallback;
1337 } else {
1338 postAnimationCallback();
1339 }
1340 }
1341
Winson Chunga4ccb862014-08-22 15:26:27 -07001342 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001343 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001344 if (isTransitionSet()) {
1345 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1346 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
1347 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001348 mNextAppTransitionAnimationsSpecs.clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001349 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001350 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight);
Winson Chunga4ccb862014-08-22 15:26:27 -07001351 postAnimationCallback();
1352 mNextAppTransitionCallback = startedCallback;
1353 } else {
1354 postAnimationCallback();
1355 }
1356 }
1357
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001358 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
1359 IRemoteCallback callback, boolean scaleUp) {
1360 if (isTransitionSet()) {
1361 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1362 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
1363 mNextAppTransitionPackage = null;
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001364 mDefaultNextAppTransitionAnimationSpec = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001365 mNextAppTransitionAnimationsSpecs.clear();
1366 mNextAppTransitionScaleUp = scaleUp;
1367 for (int i = 0; i < specs.length; i++) {
1368 AppTransitionAnimationSpec spec = specs[i];
1369 if (spec != null) {
1370 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001371 if (i == 0) {
1372 // In full screen mode, the transition code depends on the default spec to
1373 // be set.
1374 Rect rect = spec.rect;
1375 putDefaultNextAppTransitionCoordinates(rect.left, rect.top, rect.width(),
1376 rect.height());
1377 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001378 }
1379 }
1380 postAnimationCallback();
1381 mNextAppTransitionCallback = callback;
1382 } else {
1383 postAnimationCallback();
1384 }
1385 }
1386
Winson Chung044d5292014-11-06 11:05:19 -08001387 void overrideInPlaceAppTransition(String packageName, int anim) {
1388 if (isTransitionSet()) {
1389 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1390 mNextAppTransitionPackage = packageName;
1391 mNextAppTransitionInPlace = anim;
1392 } else {
1393 postAnimationCallback();
1394 }
1395 }
1396
Craig Mautner164d4bb2012-11-26 13:51:23 -08001397 @Override
1398 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001399 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001400 }
1401
Craig Mautner4b71aa12012-12-27 17:20:01 -08001402 /**
1403 * Returns the human readable name of a window transition.
1404 *
1405 * @param transition The window transition.
1406 * @return The transition symbolic name.
1407 */
1408 public static String appTransitionToString(int transition) {
1409 switch (transition) {
1410 case TRANSIT_UNSET: {
1411 return "TRANSIT_UNSET";
1412 }
1413 case TRANSIT_NONE: {
1414 return "TRANSIT_NONE";
1415 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001416 case TRANSIT_ACTIVITY_OPEN: {
1417 return "TRANSIT_ACTIVITY_OPEN";
1418 }
1419 case TRANSIT_ACTIVITY_CLOSE: {
1420 return "TRANSIT_ACTIVITY_CLOSE";
1421 }
1422 case TRANSIT_TASK_OPEN: {
1423 return "TRANSIT_TASK_OPEN";
1424 }
1425 case TRANSIT_TASK_CLOSE: {
1426 return "TRANSIT_TASK_CLOSE";
1427 }
1428 case TRANSIT_TASK_TO_FRONT: {
1429 return "TRANSIT_TASK_TO_FRONT";
1430 }
1431 case TRANSIT_TASK_TO_BACK: {
1432 return "TRANSIT_TASK_TO_BACK";
1433 }
1434 case TRANSIT_WALLPAPER_CLOSE: {
1435 return "TRANSIT_WALLPAPER_CLOSE";
1436 }
1437 case TRANSIT_WALLPAPER_OPEN: {
1438 return "TRANSIT_WALLPAPER_OPEN";
1439 }
1440 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1441 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1442 }
1443 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1444 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1445 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001446 case TRANSIT_TASK_OPEN_BEHIND: {
1447 return "TRANSIT_TASK_OPEN_BEHIND";
1448 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001449 case TRANSIT_ACTIVITY_RELAUNCH: {
1450 return "TRANSIT_ACTIVITY_RELAUNCH";
1451 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001452 default: {
1453 return "<UNKNOWN>";
1454 }
1455 }
1456 }
1457
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001458 private String appStateToString() {
1459 switch (mAppTransitionState) {
1460 case APP_STATE_IDLE:
1461 return "APP_STATE_IDLE";
1462 case APP_STATE_READY:
1463 return "APP_STATE_READY";
1464 case APP_STATE_RUNNING:
1465 return "APP_STATE_RUNNING";
1466 case APP_STATE_TIMEOUT:
1467 return "APP_STATE_TIMEOUT";
1468 default:
1469 return "unknown state=" + mAppTransitionState;
1470 }
1471 }
1472
1473 private String transitTypeToString() {
1474 switch (mNextAppTransitionType) {
1475 case NEXT_TRANSIT_TYPE_NONE:
1476 return "NEXT_TRANSIT_TYPE_NONE";
1477 case NEXT_TRANSIT_TYPE_CUSTOM:
1478 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001479 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1480 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001481 case NEXT_TRANSIT_TYPE_SCALE_UP:
1482 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1483 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1484 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1485 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1486 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001487 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1488 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1489 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1490 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001491 default:
1492 return "unknown type=" + mNextAppTransitionType;
1493 }
1494 }
1495
Craig Mautner164d4bb2012-11-26 13:51:23 -08001496 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001497 public void dump(PrintWriter pw, String prefix) {
1498 pw.print(prefix); pw.println(this);
1499 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001500 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001501 pw.print(prefix); pw.print("mNextAppTransitionType=");
1502 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001503 }
1504 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001505 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001506 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001507 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001508 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001509 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1510 pw.print(" mNextAppTransitionExit=0x");
1511 pw.println(Integer.toHexString(mNextAppTransitionExit));
1512 break;
Winson Chung044d5292014-11-06 11:05:19 -08001513 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001514 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001515 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001516 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001517 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1518 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001519 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001520 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001521 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001522 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001523 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001524 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001525 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001526 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001527 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001528 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001529 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001530 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001531 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1532 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001533 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001534 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1535 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1536 pw.println(mDefaultNextAppTransitionAnimationSpec);
1537 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1538 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001539 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1540 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001541 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001542 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001543 }
1544 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001545 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1546 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001547 }
1548 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001549
1550 public void setCurrentUser(int newUserId) {
1551 mCurrentUserId = newUserId;
1552 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001553
1554 /**
1555 * @return true if transition is not running and should not be skipped, false if transition is
1556 * already running
1557 */
1558 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent) {
1559 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
1560 + " transit=" + appTransitionToString(transit)
1561 + " " + this
1562 + " alwaysKeepCurrent=" + alwaysKeepCurrent
1563 + " Callers=" + Debug.getCallers(3));
1564 if (!isTransitionSet() || mNextAppTransition == TRANSIT_NONE) {
1565 setAppTransition(transit);
1566 } else if (!alwaysKeepCurrent) {
1567 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
1568 // Opening a new task always supersedes a close for the anim.
1569 setAppTransition(transit);
1570 } else if (transit == TRANSIT_ACTIVITY_OPEN
1571 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
1572 // Opening a new activity always supersedes a close for the anim.
1573 setAppTransition(transit);
1574 }
1575 }
1576 boolean prepared = prepare();
1577 if (isTransitionSet()) {
1578 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
1579 mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
1580 }
1581 return prepared;
1582 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001583}