blob: 9536cb7a732374da30d95b5508a0a8f8aa256dcd [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;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010053import android.graphics.Path;
Winson Chung399f6202014-03-19 10:47:20 -070054import android.graphics.Rect;
Craig Mautner164d4bb2012-11-26 13:51:23 -080055import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010056import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080057import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010058import android.os.RemoteException;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080059import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080060import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070061import android.util.SparseArray;
62import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010063import android.view.IAppTransitionAnimationSpecsFuture;
Craig Mautner164d4bb2012-11-26 13:51:23 -080064import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080065import android.view.animation.AlphaAnimation;
66import android.view.animation.Animation;
67import android.view.animation.AnimationSet;
68import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070069import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080070import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070071import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080072import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070073import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070074
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010075import com.android.internal.R;
Craig Mautner164d4bb2012-11-26 13:51:23 -080076import com.android.internal.util.DumpUtils.Dump;
77import com.android.server.AttributeCache;
78import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -080079import com.android.server.wm.animation.ClipRectLRAnimation;
80import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010081import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080082
83import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010084import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010085import java.util.concurrent.ExecutorService;
86import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -080087
Craig Mautner164d4bb2012-11-26 13:51:23 -080088// State management of app transitions. When we are preparing for a
89// transition, mNextAppTransition will be the kind of transition to
90// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
91// mOpeningApps and mClosingApps are the lists of tokens that will be
92// made visible or hidden at the next transition.
93public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080094 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070095 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080096
Craig Mautner4b71aa12012-12-27 17:20:01 -080097 /** Not set up for a transition. */
98 public static final int TRANSIT_UNSET = -1;
99 /** No animation for transition. */
100 public static final int TRANSIT_NONE = 0;
101 /** 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 -0700102 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800103 /** The window in the top-most activity is being closed to reveal the
104 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700105 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800106 /** A window in a new task is being opened on top of an existing one
107 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700108 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800109 /** A window in the top-most activity is being closed to reveal the
110 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700111 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800112 /** A window in an existing task is being displayed on top of an existing one
113 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700114 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800115 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700116 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800117 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
118 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700119 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800120 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
121 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700122 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800123 /** A window in a new activity is being opened on top of an existing one, and both are on top
124 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700125 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800126 /** The window in the top-most activity is being closed to reveal the previous activity, and
127 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700128 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
129 /** A window in a new task is being opened behind an existing one in another activity's task.
130 * The new window will show briefly and then be gone. */
131 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800132 /** A window in a task is being animated in-place. */
133 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700134 /** An activity is being relaunched (e.g. due to configuration change). */
135 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Jorim Jaggi192086e2016-03-11 17:17:03 +0100136 /** A task is being docked from recents. */
137 public static final int TRANSIT_DOCK_TASK_FROM_RECENTS = 19;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800138
Winson Chunga4ccb862014-08-22 15:26:27 -0700139 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700140 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800141 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700142 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800143
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800144 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800145
146 /** Interpolator to be used for animations that respond directly to a touch */
147 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
148 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
149
150 /**
151 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
152 * involved, to make it more understandable.
153 */
154 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700155 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700156 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800157
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800158 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800159 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800160
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800161 private int mNextAppTransition = TRANSIT_UNSET;
162
163 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
164 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
165 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
166 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
167 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700168 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
169 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800170 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800171 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800172 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
173
Winson Chung399f6202014-03-19 10:47:20 -0700174 // These are the possible states for the enter/exit activities during a thumbnail transition
175 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
176 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
177 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
178 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
179
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800180 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800181 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800182 private boolean mNextAppTransitionScaleUp;
183 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100184 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700185 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800186 private int mNextAppTransitionEnter;
187 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800188 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700189
190 // Keyed by task id.
191 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
192 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100193 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
194 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700195 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
196
Winson Chunga4ccb862014-08-22 15:26:27 -0700197 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800198
Winson Chung2820c452014-04-15 15:34:44 -0700199 private Rect mTmpFromClipRect = new Rect();
200 private Rect mTmpToClipRect = new Rect();
201
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700202 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700203
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800204 private final static int APP_STATE_IDLE = 0;
205 private final static int APP_STATE_READY = 1;
206 private final static int APP_STATE_RUNNING = 2;
207 private final static int APP_STATE_TIMEOUT = 3;
208 private int mAppTransitionState = APP_STATE_IDLE;
209
210 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800211 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700212 private final Interpolator mThumbnailFadeInInterpolator;
213 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800214 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700215 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100216 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700217 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
218
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700219 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800220
Amith Yamasani4befbec2013-07-10 16:18:01 -0700221 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800222 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700223
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100224 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100225 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100226
Jorim Jaggif97ed922016-02-18 18:57:07 -0800227 private int mLastClipRevealMaxTranslation;
228 private boolean mLastHadClipReveal;
229
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800230 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800231 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800232 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800233 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
234 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700235 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
236 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100237 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
238 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800239 mConfigShortAnimTime = context.getResources().getInteger(
240 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800241 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
242 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700243 mThumbnailFadeInInterpolator = new Interpolator() {
244 @Override
245 public float getInterpolation(float input) {
246 // Linear response for first fraction, then complete after that.
247 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
248 return 0f;
249 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700250 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700251 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700252 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700253 }
254 };
255 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800256 @Override
257 public float getInterpolation(float input) {
258 // Linear response for first fraction, then complete after that.
259 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700260 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
261 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800262 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700263 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800264 }
265 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700266 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
267 * mContext.getResources().getDisplayMetrics().density);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800268 }
269
270 boolean isTransitionSet() {
271 return mNextAppTransition != TRANSIT_UNSET;
272 }
273
Craig Mautner164d4bb2012-11-26 13:51:23 -0800274 boolean isTransitionEqual(int transit) {
275 return mNextAppTransition == transit;
276 }
277
278 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800279 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800280 }
281
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700282 private void setAppTransition(int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800283 mNextAppTransition = transit;
284 }
285
286 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800287 return mAppTransitionState == APP_STATE_READY
288 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800289 }
290
Craig Mautnerae446592012-12-06 19:05:05 -0800291 void setReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800292 mAppTransitionState = APP_STATE_READY;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100293 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800294 }
295
296 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800297 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800298 }
299
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800300 void setIdle() {
301 mAppTransitionState = APP_STATE_IDLE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800302 }
303
304 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800305 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800306 }
307
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800308 void setTimeout() {
309 mAppTransitionState = APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800310 }
311
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700312 Bitmap getAppTransitionThumbnailHeader(int taskId) {
313 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800314 if (spec == null) {
315 spec = mDefaultNextAppTransitionAnimationSpec;
316 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700317 return spec != null ? spec.bitmap : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800318 }
319
Winson Chunga4ccb862014-08-22 15:26:27 -0700320 /** Returns whether the next thumbnail transition is aspect scaled up. */
321 boolean isNextThumbnailTransitionAspectScaled() {
322 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
323 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
324 }
325
326 /** Returns whether the next thumbnail transition is scaling up. */
327 boolean isNextThumbnailTransitionScaleUp() {
328 return mNextAppTransitionScaleUp;
329 }
330
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800331 boolean isNextAppTransitionThumbnailUp() {
332 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
333 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
334 }
335
336 boolean isNextAppTransitionThumbnailDown() {
337 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
338 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
339 }
340
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100341 /**
342 * @return true if and only if we are currently fetching app transition specs from the future
343 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
344 */
345 boolean isFetchingAppTransitionsSpecs() {
346 return mNextAppTransitionAnimationsSpecsPending;
347 }
348
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700349 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800350 if (!isRunning()) {
351 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100352 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800353 mLastHadClipReveal = false;
354 mLastClipRevealMaxTranslation = 0;
355 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700356 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800357 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700358 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800359 }
360
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800361 void goodToGo(AppWindowAnimator topOpeningAppAnimator, AppWindowAnimator topClosingAppAnimator,
362 ArraySet<AppWindowToken> openingApps, ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800363 mNextAppTransition = TRANSIT_UNSET;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800364 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100365 notifyAppTransitionStartingLocked(
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800366 topOpeningAppAnimator != null ? topOpeningAppAnimator.mAppToken.token : null,
367 topClosingAppAnimator != null ? topClosingAppAnimator.mAppToken.token : null,
368 topOpeningAppAnimator != null ? topOpeningAppAnimator.animation : null,
369 topClosingAppAnimator != null ? topClosingAppAnimator.animation : null);
370 mService.getDefaultDisplayContentLocked().getDockedDividerController()
371 .notifyAppTransitionStarting(openingApps, closingApps);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800372 }
373
374 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800375 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800376 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700377 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi65193992015-11-23 16:49:59 -0800378 mNextAppTransitionAnimationsSpecsFuture = null;
379 mDefaultNextAppTransitionAnimationSpec = null;
380 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800381 }
382
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800383 void freeze() {
384 setAppTransition(AppTransition.TRANSIT_UNSET);
385 clear();
386 setReady();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100387 notifyAppTransitionCancelledLocked();
388 }
389
390 void registerListenerLocked(AppTransitionListener listener) {
391 mListeners.add(listener);
392 }
393
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700394 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100395 for (int i = 0; i < mListeners.size(); i++) {
396 mListeners.get(i).onAppTransitionFinishedLocked(token);
397 }
398 }
399
400 private void notifyAppTransitionPendingLocked() {
401 for (int i = 0; i < mListeners.size(); i++) {
402 mListeners.get(i).onAppTransitionPendingLocked();
403 }
404 }
405
406 private void notifyAppTransitionCancelledLocked() {
407 for (int i = 0; i < mListeners.size(); i++) {
408 mListeners.get(i).onAppTransitionCancelledLocked();
409 }
410 }
411
412 private void notifyAppTransitionStartingLocked(IBinder openToken,
413 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
414 for (int i = 0; i < mListeners.size(); i++) {
415 mListeners.get(i).onAppTransitionStartingLocked(openToken, closeToken, openAnimation,
416 closeAnimation);
417 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800418 }
419
Craig Mautner164d4bb2012-11-26 13:51:23 -0800420 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
421 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
422 + (lp != null ? lp.packageName : null)
423 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
424 if (lp != null && lp.windowAnimations != 0) {
425 // If this is a system resource, don't try to load it from the
426 // application resources. It is nice to avoid loading application
427 // resources if we can.
428 String packageName = lp.packageName != null ? lp.packageName : "android";
429 int resId = lp.windowAnimations;
430 if ((resId&0xFF000000) == 0x01000000) {
431 packageName = "android";
432 }
433 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
434 + packageName);
435 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700436 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800437 }
438 return null;
439 }
440
441 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
442 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
443 + packageName + " resId=0x" + Integer.toHexString(resId));
444 if (packageName != null) {
445 if ((resId&0xFF000000) == 0x01000000) {
446 packageName = "android";
447 }
448 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
449 + packageName);
450 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700451 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800452 }
453 return null;
454 }
455
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700456 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800457 int anim = 0;
458 Context context = mContext;
459 if (animAttr >= 0) {
460 AttributeCache.Entry ent = getCachedAnimations(lp);
461 if (ent != null) {
462 context = ent.context;
463 anim = ent.array.getResourceId(animAttr, 0);
464 }
465 }
466 if (anim != 0) {
467 return AnimationUtils.loadAnimation(context, anim);
468 }
469 return null;
470 }
471
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700472 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
473 Context context = mContext;
474 if (resId >= 0) {
475 AttributeCache.Entry ent = getCachedAnimations(lp);
476 if (ent != null) {
477 context = ent.context;
478 }
479 return AnimationUtils.loadAnimation(context, resId);
480 }
481 return null;
482 }
483
484 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800485 int anim = 0;
486 Context context = mContext;
487 if (resId >= 0) {
488 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
489 if (ent != null) {
490 context = ent.context;
491 anim = resId;
492 }
493 }
494 if (anim != 0) {
495 return AnimationUtils.loadAnimation(context, anim);
496 }
497 return null;
498 }
499
Craig Mautner164d4bb2012-11-26 13:51:23 -0800500 /**
501 * Compute the pivot point for an animation that is scaling from a small
502 * rect on screen to a larger rect. The pivot point varies depending on
503 * the distance between the inner and outer edges on both sides. This
504 * function computes the pivot point for one dimension.
505 * @param startPos Offset from left/top edge of outer rectangle to
506 * left/top edge of inner rectangle.
507 * @param finalScale The scaling factor between the size of the outer
508 * and inner rectangles.
509 */
510 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800511
512 /*
513 Theorem of intercepting lines:
514
515 + + +-----------------------------------------------+
516 | | | |
517 | | | |
518 | | | |
519 | | | |
520 x | y | | |
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 |
558 |
559 |
560 |
561 + ++
562 p ++
563
564 scale = (x - y) / x
565 <=> x = -y / (scale - 1)
566 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800567 final float denom = finalScale-1;
568 if (Math.abs(denom) < .0001f) {
569 return startPos;
570 }
571 return -startPos / denom;
572 }
573
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700574 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
575 Rect containingFrame) {
576 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700577 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700578 final int appWidth = containingFrame.width();
579 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800580 if (enter) {
581 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700582 float scaleW = mTmpRect.width() / (float) appWidth;
583 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800584 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700585 computePivot(mTmpRect.left, scaleW),
586 computePivot(mTmpRect.right, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800587 scale.setInterpolator(mDecelerateInterpolator);
588
Craig Mautner164d4bb2012-11-26 13:51:23 -0800589 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700590 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800591
592 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800593 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800594 set.addAnimation(alpha);
595 set.setDetachWallpaper(true);
596 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800597 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
598 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800599 // If we are on top of the wallpaper, we need an animation that
600 // correctly handles the wallpaper staying static behind all of
601 // the animated elements. To do this, will just have the existing
602 // element fade out.
603 a = new AlphaAnimation(1, 0);
604 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800605 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800606 // For normal animations, the exiting element just holds in place.
607 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800608 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800609
610 // Pick the desired duration. If this is an inter-activity transition,
611 // it is the standard duration for that. Otherwise we use the longer
612 // task transition duration.
613 final long duration;
614 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800615 case TRANSIT_ACTIVITY_OPEN:
616 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800617 duration = mConfigShortAnimTime;
618 break;
619 default:
620 duration = DEFAULT_APP_TRANSITION_DURATION;
621 break;
622 }
623 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800624 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800625 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800626 a.initialize(appWidth, appHeight, appWidth, appHeight);
627 return a;
628 }
629
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700630 private void getDefaultNextAppTransitionStartRect(Rect rect) {
631 if (mDefaultNextAppTransitionAnimationSpec == null ||
632 mDefaultNextAppTransitionAnimationSpec.rect == null) {
633 Slog.wtf(TAG, "Starting rect for app requested, but none available", new Throwable());
634 rect.setEmpty();
635 } else {
636 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
637 }
638 }
639
640 void getNextAppTransitionStartRect(int taskId, Rect rect) {
641 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800642 if (spec == null) {
643 spec = mDefaultNextAppTransitionAnimationSpec;
644 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700645 if (spec == null || spec.rect == null) {
646 Slog.wtf(TAG, "Starting rect for task: " + taskId + " requested, but not available",
647 new Throwable());
648 rect.setEmpty();
649 } else {
650 rect.set(spec.rect);
651 }
652 }
653
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800654 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
655 Bitmap bitmap) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700656 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800657 bitmap, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700658 }
659
Jorim Jaggif97ed922016-02-18 18:57:07 -0800660 /**
661 * @return the duration of the last clip reveal animation
662 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800663 long getLastClipRevealTransitionDuration() {
664 return mLastClipRevealTransitionDuration;
665 }
666
667 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800668 * @return the maximum distance the app surface is traveling of the last clip reveal animation
669 */
670 int getLastClipRevealMaxTranslation() {
671 return mLastClipRevealMaxTranslation;
672 }
673
674 /**
675 * @return true if in the last app transition had a clip reveal animation, false otherwise
676 */
677 boolean hadClipRevealAnimation() {
678 return mLastHadClipReveal;
679 }
680
681 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800682 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
683 * the start rect is outside of the target rect, and there is a lot of movement going on.
684 *
685 * @param cutOff whether the start rect was not fully contained by the end rect
686 * @param translationX the total translation the surface moves in x direction
687 * @param translationY the total translation the surfaces moves in y direction
688 * @param displayFrame our display frame
689 *
690 * @return the duration of the clip reveal animation, in milliseconds
691 */
692 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
693 float translationY, Rect displayFrame) {
694 if (!cutOff) {
695 return DEFAULT_APP_TRANSITION_DURATION;
696 }
697 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
698 Math.abs(translationY) / displayFrame.height());
699 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
700 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
701 }
702
703 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
704 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800705 final Animation anim;
706 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700707 final int appWidth = appFrame.width();
708 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800709
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700710 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700711 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700712 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700713
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700714 float t = 0f;
715 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800716 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700717 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800718 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
719 int translationX = 0;
720 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700721 int centerX = mTmpRect.centerX();
722 int centerY = mTmpRect.centerY();
723 int halfWidth = mTmpRect.width() / 2;
724 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800725 int clipStartX = centerX - halfWidth - appFrame.left;
726 int clipStartY = centerY - halfHeight - appFrame.top;
727 boolean cutOff = false;
728
729 // If the starting rectangle is fully or partially outside of the target rectangle, we
730 // need to start the clipping at the edge and then achieve the rest with translation
731 // and extending the clip rect from that edge.
732 if (appFrame.top > centerY - halfHeight) {
733 translationY = (centerY - halfHeight) - appFrame.top;
734 translationYCorrection = 0;
735 clipStartY = 0;
736 cutOff = true;
737 }
738 if (appFrame.left > centerX - halfWidth) {
739 translationX = (centerX - halfWidth) - appFrame.left;
740 clipStartX = 0;
741 cutOff = true;
742 }
743 if (appFrame.right < centerX + halfWidth) {
744 translationX = (centerX + halfWidth) - appFrame.right;
745 clipStartX = appWidth - mTmpRect.width();
746 cutOff = true;
747 }
748 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
749 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700750
751 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800752 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800753 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700754 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800755 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700756
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800757 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
758 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
759 : mLinearOutSlowInInterpolator);
760 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800761
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800762 Animation clipAnimTB = new ClipRectTBAnimation(
763 clipStartY, clipStartY + mTmpRect.height(),
764 0, appHeight,
765 translationYCorrection, 0,
766 mLinearOutSlowInInterpolator);
767 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
768 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800769
770 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800771 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700772 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800773 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700774 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800775
776 AnimationSet set = new AnimationSet(false);
777 set.addAnimation(clipAnimLR);
778 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700779 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800780 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700781 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800782 set.initialize(appWidth, appHeight, appWidth, appHeight);
783 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800784 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800785 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800786
787 // If the start rect was full inside the target rect (cutOff == false), we don't need
788 // to store the translation, because it's only used if cutOff == true.
789 mLastClipRevealMaxTranslation = cutOff
790 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800791 } else {
792 final long duration;
793 switch (transit) {
794 case TRANSIT_ACTIVITY_OPEN:
795 case TRANSIT_ACTIVITY_CLOSE:
796 duration = mConfigShortAnimTime;
797 break;
798 default:
799 duration = DEFAULT_APP_TRANSITION_DURATION;
800 break;
801 }
802 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
803 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
804 // If we are on top of the wallpaper, we need an animation that
805 // correctly handles the wallpaper staying static behind all of
806 // the animated elements. To do this, will just have the existing
807 // element fade out.
808 anim = new AlphaAnimation(1, 0);
809 anim.setDetachWallpaper(true);
810 } else {
811 // For normal animations, the exiting element just holds in place.
812 anim = new AlphaAnimation(1, 1);
813 }
814 anim.setInterpolator(mDecelerateInterpolator);
815 anim.setDuration(duration);
816 anim.setFillAfter(true);
817 }
818 return anim;
819 }
820
Winson Chung399f6202014-03-19 10:47:20 -0700821 /**
822 * Prepares the specified animation with a standard duration, interpolator, etc.
823 */
Winson Chung5393dff2014-05-08 14:25:43 -0700824 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100825 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700826 if (duration > 0) {
827 a.setDuration(duration);
828 }
Winson Chung5393dff2014-05-08 14:25:43 -0700829 a.setFillAfter(true);
830 a.setInterpolator(interpolator);
831 a.initialize(appWidth, appHeight, appWidth, appHeight);
832 return a;
833 }
834
835 /**
836 * Prepares the specified animation with a standard duration, interpolator, etc.
837 */
Winson Chung399f6202014-03-19 10:47:20 -0700838 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800839 // Pick the desired duration. If this is an inter-activity transition,
840 // it is the standard duration for that. Otherwise we use the longer
841 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700842 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800843 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800844 case TRANSIT_ACTIVITY_OPEN:
845 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800846 duration = mConfigShortAnimTime;
847 break;
848 default:
849 duration = DEFAULT_APP_TRANSITION_DURATION;
850 break;
851 }
Winson Chung5393dff2014-05-08 14:25:43 -0700852 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
853 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800854 }
855
Winson Chung399f6202014-03-19 10:47:20 -0700856 /**
857 * Return the current thumbnail transition state.
858 */
859 int getThumbnailTransitionState(boolean enter) {
860 if (enter) {
861 if (mNextAppTransitionScaleUp) {
862 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
863 } else {
864 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
865 }
866 } else {
867 if (mNextAppTransitionScaleUp) {
868 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
869 } else {
870 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
871 }
872 }
873 }
874
875 /**
876 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700877 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700878 */
Jorim Jaggide63d442016-03-14 14:56:56 +0100879 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
880 Bitmap thumbnailHeader, final int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700881 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700882 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700883 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700884 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700885 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700886
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700887 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700888 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi8448f332016-03-14 17:50:37 +0100889 final float toY = mTmpRect.height() / 2 * (scaleW - 1f) + appRect.top;
890 final float fromY = mTmpRect.top;
891 final float toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
892 final float fromX = mTmpRect.left;
893 final float pivotX = mTmpRect.width() / 2;
894 final float pivotY = mTmpRect.height() / 2;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100895 final long duration = getAspectScaleDuration();
896 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -0700897 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700898 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +0100899 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100900 scale.setInterpolator(interpolator);
901 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800902 Animation alpha = new AlphaAnimation(1f, 0f);
Winson Chunga4ccb862014-08-22 15:26:27 -0700903 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100904 alpha.setDuration(duration);
905 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
906 translate.setInterpolator(interpolator);
907 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -0700908
Jorim Jaggide63d442016-03-14 14:56:56 +0100909 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
910 mTmpToClipRect.set(appRect);
911
912 // Containing frame is in screen space, but we need the clip rect in the
913 // app space.
914 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggi8448f332016-03-14 17:50:37 +0100915 mTmpToClipRect.right = (int) (mTmpToClipRect.right * scaleW);
916 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom * scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +0100917
918 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +0100919 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
920 (int) (-contentInsets.top * scaleW),
921 (int) (-contentInsets.right * scaleW),
922 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +0100923 }
924
925 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100926 clipAnim.setInterpolator(interpolator);
927 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +0100928
Winson Chung399f6202014-03-19 10:47:20 -0700929 // This AnimationSet uses the Interpolators assigned above.
930 AnimationSet set = new AnimationSet(false);
931 set.addAnimation(scale);
932 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -0700933 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +0100934 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -0700935 a = set;
936 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700937 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +0100938 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100939 scale.setInterpolator(interpolator);
940 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -0700941 Animation alpha = new AlphaAnimation(0f, 1f);
942 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100943 alpha.setDuration(duration);
944 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
945 translate.setInterpolator(interpolator);
946 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -0700947
Winson Chunga4ccb862014-08-22 15:26:27 -0700948 // This AnimationSet uses the Interpolators assigned above.
949 AnimationSet set = new AnimationSet(false);
950 set.addAnimation(scale);
951 set.addAnimation(alpha);
952 set.addAnimation(translate);
953 a = set;
954
955 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700956 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800957 TOUCH_RESPONSE_INTERPOLATOR);
Winson Chung399f6202014-03-19 10:47:20 -0700958 }
959
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100960 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
961
962 // Almost no x-change - use linear animation
963 if (Math.abs(toX - fromX) < 1f) {
964 return new TranslateAnimation(fromX, toX, fromY, toY);
965 } else {
966 final Path path = createCurvedPath(fromX, toX, fromY, toY);
967 return new CurvedTranslateAnimation(path);
968 }
969 }
970
971 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
972 final Path path = new Path();
973 path.moveTo(fromX, fromY);
974 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
975 return path;
976 }
977
978 private long getAspectScaleDuration() {
979 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
980 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1f);
981 } else {
982 return THUMBNAIL_APP_TRANSITION_DURATION;
983 }
984 }
985
986 private Interpolator getAspectScaleInterpolator() {
987 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
988 return mFastOutSlowInInterpolator;
989 } else {
990 return TOUCH_RESPONSE_INTERPOLATOR;
991 }
992 }
993
Winson Chung399f6202014-03-19 10:47:20 -0700994 /**
995 * This alternate animation is created when we are doing a thumbnail transition, for the
996 * activity that is leaving, and the activity that is entering.
997 */
Winson Chunga4ccb862014-08-22 15:26:27 -0700998 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700999 int orientation, int transit, Rect containingFrame, Rect contentInsets,
1000 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001001 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001002 final int appWidth = containingFrame.width();
1003 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001004 getDefaultNextAppTransitionStartRect(mTmpRect);
1005 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001006 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001007 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001008 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winson21700932016-03-24 17:26:23 -07001009 final int thumbStartX = mTmpRect.left - containingFrame.left;
1010 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001011
Winson Chung2820c452014-04-15 15:34:44 -07001012 // Used for the ENTER_SCALE_UP and EXIT_SCALE_DOWN transitions
1013 float scale = 1f;
1014 int scaledTopDecor = 0;
1015
Winson Chung399f6202014-03-19 10:47:20 -07001016 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001017 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1018 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1019 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1020 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001021 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001022 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001023 } else if (freeform) {
1024 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1025 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001026 } else {
Winson21700932016-03-24 17:26:23 -07001027 AnimationSet set = new AnimationSet(true);
1028
1029 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001030 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001031 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001032
1033 // Containing frame is in screen space, but we need the clip rect in the
1034 // app space.
1035 mTmpFromClipRect.offsetTo(0, 0);
1036 mTmpToClipRect.offsetTo(0, 0);
1037
1038 // Exclude insets region from the source clip.
1039 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001040 mNextAppTransitionInsets.set(contentInsets);
1041
Winson21700932016-03-24 17:26:23 -07001042 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
1043 // We scale the width and clip to the top/left square
Jorim Jaggi8448f332016-03-14 17:50:37 +01001044 Animation scaleAnim = new ScaleAnimation(
1045 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1046 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1047 containingFrame.width() / 2,
1048 containingFrame.height() / 2 + contentInsets.top);
1049 final float targetX = (mTmpRect.left - containingFrame.left);
1050 final float x = containingFrame.width() / 2
1051 - containingFrame.width() / 2 * scale;
1052 final float targetY = (mTmpRect.top - containingFrame.top);
1053 final float y = containingFrame.height() / 2
1054 - containingFrame.height() / 2 * scale;
1055 final float startX = targetX - x;
1056 final float startY = targetY - y;
1057 Animation clipAnim = scaleUp
1058 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1059 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1060 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001061 ? createCurvedMotion(startX, 0, startY - scaledTopDecor, 0)
1062 : createCurvedMotion(0, startX, 0, startY - scaledTopDecor);
Winson21700932016-03-24 17:26:23 -07001063 set.addAnimation(clipAnim);
1064 set.addAnimation(scaleAnim);
1065 set.addAnimation(translateAnim);
1066
1067 } else {
1068 // In landscape, we don't scale at all and only crop
1069 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1070 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1071
Jorim Jaggi8448f332016-03-14 17:50:37 +01001072 Animation clipAnim = scaleUp
1073 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1074 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1075 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001076 ? createCurvedMotion(thumbStartX, 0,
1077 thumbStartY - contentInsets.top, 0)
1078 : createCurvedMotion(0, thumbStartX, 0,
1079 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001080
1081 set.addAnimation(clipAnim);
1082 set.addAnimation(translateAnim);
1083 }
Jorim Jaggi8448f332016-03-14 17:50:37 +01001084 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001085 a = set;
Winson21700932016-03-24 17:26:23 -07001086 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001087 }
Winson Chung399f6202014-03-19 10:47:20 -07001088 break;
1089 }
1090 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001091 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001092 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001093 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001094 // activity.
1095 a = new AlphaAnimation(1, 0);
1096 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001097 a = new AlphaAnimation(1, 1);
1098 }
1099 break;
1100 }
1101 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001102 // Target app window during the scale down
1103 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1104 // Fade in the destination activity if we are animating from a wallpaper
1105 // activity.
1106 a = new AlphaAnimation(0, 1);
1107 } else {
1108 a = new AlphaAnimation(1, 1);
1109 }
Winson Chung399f6202014-03-19 10:47:20 -07001110 break;
1111 }
Winson Chung399f6202014-03-19 10:47:20 -07001112 default:
1113 throw new RuntimeException("Invalid thumbnail transition state");
1114 }
1115
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001116 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1117 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001118 }
1119
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001120 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1121 @Nullable Rect surfaceInsets, int taskId) {
1122 getNextAppTransitionStartRect(taskId, mTmpRect);
1123 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1124 true);
1125 }
1126
1127 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1128 @Nullable Rect surfaceInsets, int taskId) {
1129 getNextAppTransitionStartRect(taskId, mTmpRect);
1130 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1131 false);
1132 }
1133
1134 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1135 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1136 final float sourceWidth = sourceFrame.width();
1137 final float sourceHeight = sourceFrame.height();
1138 final float destWidth = destFrame.width();
1139 final float destHeight = destFrame.height();
1140 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1141 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001142 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001143 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001144 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001145 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001146 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1147 // We want the scaling to happen from the center of the surface. In order to achieve that,
1148 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001149 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1150 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1151 final ScaleAnimation scale = enter ?
1152 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1153 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1154 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1155 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1156 final int destHCenter = destFrame.left + destFrame.width() / 2;
1157 final int destVCenter = destFrame.top + destFrame.height() / 2;
1158 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1159 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1160 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1161 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001162 set.addAnimation(scale);
1163 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001164
1165 final IRemoteCallback callback = mAnimationFinishedCallback;
1166 if (callback != null) {
1167 set.setAnimationListener(new Animation.AnimationListener() {
1168 @Override
1169 public void onAnimationStart(Animation animation) { }
1170
1171 @Override
1172 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001173 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001174 }
1175
1176 @Override
1177 public void onAnimationRepeat(Animation animation) { }
1178 });
1179 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001180 return set;
1181 }
1182
Winson Chung399f6202014-03-19 10:47:20 -07001183 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001184 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001185 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001186 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001187 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
1188 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001189 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001190 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001191 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001192 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001193 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001194 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1195
1196 if (mNextAppTransitionScaleUp) {
1197 // Animation for the thumbnail zooming from its initial size to the full screen
1198 float scaleW = appWidth / thumbWidth;
1199 float scaleH = appHeight / thumbHeight;
1200 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001201 computePivot(mTmpRect.left, 1 / scaleW),
1202 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001203 scale.setInterpolator(mDecelerateInterpolator);
1204
1205 Animation alpha = new AlphaAnimation(1, 0);
1206 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1207
1208 // This AnimationSet uses the Interpolators assigned above.
1209 AnimationSet set = new AnimationSet(false);
1210 set.addAnimation(scale);
1211 set.addAnimation(alpha);
1212 a = set;
1213 } else {
1214 // Animation for the thumbnail zooming down from the full screen to its final size
1215 float scaleW = appWidth / thumbWidth;
1216 float scaleH = appHeight / thumbHeight;
1217 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001218 computePivot(mTmpRect.left, 1 / scaleW),
1219 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001220 }
1221
1222 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1223 }
1224
1225 /**
Winson Chung399f6202014-03-19 10:47:20 -07001226 * This animation is created when we are doing a thumbnail transition, for the activity that is
1227 * leaving, and the activity that is entering.
1228 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001229 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1230 int transit, int taskId) {
1231 final int appWidth = containingFrame.width();
1232 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001233 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001234 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001235 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001236 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001237 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001238 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001239 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1240
1241 switch (thumbTransitState) {
1242 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1243 // Entering app scales up with the thumbnail
1244 float scaleW = thumbWidth / appWidth;
1245 float scaleH = thumbHeight / appHeight;
1246 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001247 computePivot(mTmpRect.left, scaleW),
1248 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001249 break;
1250 }
1251 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1252 // Exiting app while the thumbnail is scaling up should fade or stay in place
1253 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1254 // Fade out while bringing up selected activity. This keeps the
1255 // current activity from showing through a launching wallpaper
1256 // activity.
1257 a = new AlphaAnimation(1, 0);
1258 } else {
1259 // noop animation
1260 a = new AlphaAnimation(1, 1);
1261 }
1262 break;
1263 }
1264 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1265 // Entering the other app, it should just be visible while we scale the thumbnail
1266 // down above it
1267 a = new AlphaAnimation(1, 1);
1268 break;
1269 }
1270 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1271 // Exiting the current app, the app should scale down with the thumbnail
1272 float scaleW = thumbWidth / appWidth;
1273 float scaleH = thumbHeight / appHeight;
1274 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001275 computePivot(mTmpRect.left, scaleW),
1276 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001277
1278 Animation alpha = new AlphaAnimation(1, 0);
1279
1280 AnimationSet set = new AnimationSet(true);
1281 set.addAnimation(scale);
1282 set.addAnimation(alpha);
1283 set.setZAdjustment(Animation.ZORDER_TOP);
1284 a = set;
1285 break;
1286 }
1287 default:
1288 throw new RuntimeException("Invalid thumbnail transition state");
1289 }
1290
1291 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1292 }
1293
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001294 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001295 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1296 final int left = mTmpFromClipRect.left;
1297 final int top = mTmpFromClipRect.top;
1298 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001299 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1300 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001301 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001302 float fromWidth = mTmpFromClipRect.width();
1303 float toWidth = mTmpToClipRect.width();
1304 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001305 // While the window might span the whole display, the actual content will be cropped to the
1306 // system decoration frame, for example when the window is docked. We need to take into
1307 // account the visible height when constructing the animation.
1308 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1309 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001310 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1311 // The final window is larger in both dimensions than current window (e.g. we are
1312 // maximizing), so we can simply unclip the new window and there will be no disappearing
1313 // frame.
1314 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1315 } else {
1316 // The disappearing window has one larger dimension. We need to apply scaling, so the
1317 // first frame of the entry animation matches the old window.
1318 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001319 // We might not be going exactly full screen, but instead be aligned under the status
1320 // bar using cropping. We still need to account for the cropped part, which will also
1321 // be scaled.
1322 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001323 }
1324
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001325 // We animate the translation from the old position of the removed window, to the new
1326 // position of the added window. The latter might not be full screen, for example docked for
1327 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001328 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001329 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001330 set.addAnimation(translate);
1331 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001332 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001333 return set;
1334 }
1335
Jorim Jaggic554b772015-06-04 16:07:57 -07001336 /**
1337 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1338 * frame of the transition doesn't change the visuals on screen, so we can start
1339 * directly with the second one
1340 */
1341 boolean canSkipFirstFrame() {
1342 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1343 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
1344 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1345 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001346
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001347 /**
1348 *
1349 * @param frame These are the bounds of the window when it finishes the animation. This is where
1350 * the animation must usually finish in entrance animation, as the next frame will
1351 * display the window at these coordinates. In case of exit animation, this is
1352 * where the animation must start, as the frame before the animation is displaying
1353 * the window at these bounds.
1354 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1355 * window might be obscured, usually by the system windows (status bar and
1356 * navigation bar) and we use content insets to convey that information. This
1357 * usually affects the animation aspects vertically, as the system decoration is
1358 * at the top and the bottom. For example when we animate from full screen to
1359 * recents, we want to exclude the covered parts, because they won't match the
1360 * thumbnail after the last frame is executed.
1361 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1362 * know about this to make the animation frames match. We currently use
1363 * this for freeform windows, which have larger surfaces to display
1364 * shadows. When we animate them from recents, we want to match the content
1365 * to the recents thumbnail and hence need to account for the surface being
1366 * bigger.
1367 */
Craig Mautner164d4bb2012-11-26 13:51:23 -08001368 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001369 int orientation, Rect frame, Rect displayFrame, Rect insets,
1370 @Nullable Rect surfaceInsets, boolean isVoiceInteraction, boolean freeform,
1371 int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001372 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001373 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
1374 || transit == TRANSIT_TASK_OPEN
1375 || transit == TRANSIT_TASK_TO_FRONT)) {
1376 a = loadAnimationRes(lp, enter
1377 ? com.android.internal.R.anim.voice_activity_open_enter
1378 : com.android.internal.R.anim.voice_activity_open_exit);
1379 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1380 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001381 + " anim=" + a + " transit=" + appTransitionToString(transit)
1382 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001383 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1384 || transit == TRANSIT_TASK_CLOSE
1385 || transit == TRANSIT_TASK_TO_BACK)) {
1386 a = loadAnimationRes(lp, enter
1387 ? com.android.internal.R.anim.voice_activity_close_enter
1388 : com.android.internal.R.anim.voice_activity_close_exit);
1389 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1390 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001391 + " anim=" + a + " transit=" + appTransitionToString(transit)
1392 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001393 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001394 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001395 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1396 "applyAnimation:"
1397 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1398 + " transit=" + appTransitionToString(transit)
1399 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001400 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1401 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001402 mNextAppTransitionEnter : mNextAppTransitionExit);
1403 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1404 "applyAnimation:"
1405 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001406 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001407 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001408 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1409 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1410 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1411 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001412 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1413 + " transit=" + appTransitionToString(transit)
1414 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001415 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001416 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001417 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1418 "applyAnimation:"
1419 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001420 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001421 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001422 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001423 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001424 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1425 "applyAnimation:"
1426 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001427 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001428 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001429 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1430 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001431 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001432 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001433 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001434 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001435 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1436 String animName = mNextAppTransitionScaleUp ?
1437 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1438 Slog.v(TAG, "applyAnimation:"
1439 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001440 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001441 + " Callers=" + Debug.getCallers(3));
1442 }
1443 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1444 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1445 mNextAppTransitionScaleUp =
1446 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1447 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001448 getThumbnailTransitionState(enter), orientation, transit, frame,
1449 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001450 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1451 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001452 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001453 Slog.v(TAG, "applyAnimation:"
1454 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001455 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001456 + " Callers=" + Debug.getCallers(3));
1457 }
1458 } else {
1459 int animAttr = 0;
1460 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001461 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001462 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001463 ? WindowAnimation_activityOpenEnterAnimation
1464 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001465 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001466 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001467 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001468 ? WindowAnimation_activityCloseEnterAnimation
1469 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001470 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001471 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001472 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001473 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001474 ? WindowAnimation_taskOpenEnterAnimation
1475 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001476 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001477 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001478 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001479 ? WindowAnimation_taskCloseEnterAnimation
1480 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001481 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001482 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001483 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001484 ? WindowAnimation_taskToFrontEnterAnimation
1485 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001486 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001487 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001488 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001489 ? WindowAnimation_taskToBackEnterAnimation
1490 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001491 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001492 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001493 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001494 ? WindowAnimation_wallpaperOpenEnterAnimation
1495 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001496 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001497 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001498 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001499 ? WindowAnimation_wallpaperCloseEnterAnimation
1500 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001501 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001502 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001503 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001504 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1505 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001506 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001507 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001508 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001509 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1510 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001511 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001512 case TRANSIT_TASK_OPEN_BEHIND:
1513 animAttr = enter
1514 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001515 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001516 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001517 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001518 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1519 "applyAnimation:"
1520 + " anim=" + a
1521 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001522 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001523 + " Callers=" + Debug.getCallers(3));
1524 }
1525 return a;
1526 }
1527
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001528 int getAppStackClipMode() {
1529 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
1530 ? STACK_CLIP_NONE
1531 : STACK_CLIP_AFTER_ANIM;
1532 }
1533
Craig Mautner164d4bb2012-11-26 13:51:23 -08001534 void postAnimationCallback() {
1535 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001536 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1537 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001538 mNextAppTransitionCallback = null;
1539 }
1540 }
1541
1542 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001543 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001544 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001545 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001546 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001547 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001548 mNextAppTransitionEnter = enterAnim;
1549 mNextAppTransitionExit = exitAnim;
1550 postAnimationCallback();
1551 mNextAppTransitionCallback = startedCallback;
1552 } else {
1553 postAnimationCallback();
1554 }
1555 }
1556
1557 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001558 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001559 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001560 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001561 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001562 putDefaultNextAppTransitionCoordinates(startX, startY, startX + startWidth,
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001563 startY + startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001564 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001565 }
1566 }
1567
Chet Haase10e23ab2015-02-11 15:08:38 -08001568 void overridePendingAppTransitionClipReveal(int startX, int startY,
1569 int startWidth, int startHeight) {
1570 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001571 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001572 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001573 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001574 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001575 }
1576 }
1577
Craig Mautner164d4bb2012-11-26 13:51:23 -08001578 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1579 IRemoteCallback startedCallback, boolean scaleUp) {
1580 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001581 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001582 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1583 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001584 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001585 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001586 postAnimationCallback();
1587 mNextAppTransitionCallback = startedCallback;
1588 } else {
1589 postAnimationCallback();
1590 }
1591 }
1592
Winson Chunga4ccb862014-08-22 15:26:27 -07001593 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001594 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001595 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001596 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001597 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1598 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001599 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001600 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1601 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001602 postAnimationCallback();
1603 mNextAppTransitionCallback = startedCallback;
1604 } else {
1605 postAnimationCallback();
1606 }
1607 }
1608
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001609 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001610 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1611 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001612 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001613 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001614 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1615 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001616 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001617 if (specs != null) {
1618 for (int i = 0; i < specs.length; i++) {
1619 AppTransitionAnimationSpec spec = specs[i];
1620 if (spec != null) {
1621 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1622 if (i == 0) {
1623 // In full screen mode, the transition code depends on the default spec
1624 // to be set.
1625 Rect rect = spec.rect;
1626 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Filip Gruszczynskie3264d82015-11-20 17:10:04 -08001627 rect.width(), rect.height(), spec.bitmap);
Jorim Jaggi43102412015-11-11 16:28:37 +01001628 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001629 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001630 }
1631 }
1632 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001633 mNextAppTransitionCallback = onAnimationStartedCallback;
1634 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001635 } else {
1636 postAnimationCallback();
1637 }
1638 }
1639
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001640 void overridePendingAppTransitionMultiThumbFuture(
1641 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1642 boolean scaleUp) {
1643 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001644 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001645 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1646 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001647 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1648 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001649 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001650 }
1651 }
1652
Winson Chung044d5292014-11-06 11:05:19 -08001653 void overrideInPlaceAppTransition(String packageName, int anim) {
1654 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001655 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001656 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1657 mNextAppTransitionPackage = packageName;
1658 mNextAppTransitionInPlace = anim;
1659 } else {
1660 postAnimationCallback();
1661 }
1662 }
1663
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001664 /**
1665 * If a future is set for the app transition specs, fetch it in another thread.
1666 */
1667 private void fetchAppTransitionSpecsFromFuture() {
1668 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1669 mNextAppTransitionAnimationsSpecsPending = true;
1670 final IAppTransitionAnimationSpecsFuture future
1671 = mNextAppTransitionAnimationsSpecsFuture;
1672 mNextAppTransitionAnimationsSpecsFuture = null;
1673 mDefaultExecutor.execute(new Runnable() {
1674 @Override
1675 public void run() {
1676 AppTransitionAnimationSpec[] specs = null;
1677 try {
1678 specs = future.get();
1679 } catch (RemoteException e) {
1680 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1681 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001682 synchronized (mService.mWindowMap) {
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001683 mNextAppTransitionAnimationsSpecsPending = false;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001684 overridePendingAppTransitionMultiThumb(specs,
1685 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1686 mNextAppTransitionScaleUp);
1687 mNextAppTransitionFutureCallback = null;
Filip Gruszczynski96daf322015-11-18 18:01:27 -08001688 if (specs != null) {
1689 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1690 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001691 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001692 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001693 }
1694 });
1695 }
1696 }
1697
Craig Mautner164d4bb2012-11-26 13:51:23 -08001698 @Override
1699 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001700 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001701 }
1702
Craig Mautner4b71aa12012-12-27 17:20:01 -08001703 /**
1704 * Returns the human readable name of a window transition.
1705 *
1706 * @param transition The window transition.
1707 * @return The transition symbolic name.
1708 */
1709 public static String appTransitionToString(int transition) {
1710 switch (transition) {
1711 case TRANSIT_UNSET: {
1712 return "TRANSIT_UNSET";
1713 }
1714 case TRANSIT_NONE: {
1715 return "TRANSIT_NONE";
1716 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001717 case TRANSIT_ACTIVITY_OPEN: {
1718 return "TRANSIT_ACTIVITY_OPEN";
1719 }
1720 case TRANSIT_ACTIVITY_CLOSE: {
1721 return "TRANSIT_ACTIVITY_CLOSE";
1722 }
1723 case TRANSIT_TASK_OPEN: {
1724 return "TRANSIT_TASK_OPEN";
1725 }
1726 case TRANSIT_TASK_CLOSE: {
1727 return "TRANSIT_TASK_CLOSE";
1728 }
1729 case TRANSIT_TASK_TO_FRONT: {
1730 return "TRANSIT_TASK_TO_FRONT";
1731 }
1732 case TRANSIT_TASK_TO_BACK: {
1733 return "TRANSIT_TASK_TO_BACK";
1734 }
1735 case TRANSIT_WALLPAPER_CLOSE: {
1736 return "TRANSIT_WALLPAPER_CLOSE";
1737 }
1738 case TRANSIT_WALLPAPER_OPEN: {
1739 return "TRANSIT_WALLPAPER_OPEN";
1740 }
1741 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1742 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1743 }
1744 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1745 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1746 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001747 case TRANSIT_TASK_OPEN_BEHIND: {
1748 return "TRANSIT_TASK_OPEN_BEHIND";
1749 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001750 case TRANSIT_ACTIVITY_RELAUNCH: {
1751 return "TRANSIT_ACTIVITY_RELAUNCH";
1752 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001753 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1754 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1755 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001756 default: {
1757 return "<UNKNOWN>";
1758 }
1759 }
1760 }
1761
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001762 private String appStateToString() {
1763 switch (mAppTransitionState) {
1764 case APP_STATE_IDLE:
1765 return "APP_STATE_IDLE";
1766 case APP_STATE_READY:
1767 return "APP_STATE_READY";
1768 case APP_STATE_RUNNING:
1769 return "APP_STATE_RUNNING";
1770 case APP_STATE_TIMEOUT:
1771 return "APP_STATE_TIMEOUT";
1772 default:
1773 return "unknown state=" + mAppTransitionState;
1774 }
1775 }
1776
1777 private String transitTypeToString() {
1778 switch (mNextAppTransitionType) {
1779 case NEXT_TRANSIT_TYPE_NONE:
1780 return "NEXT_TRANSIT_TYPE_NONE";
1781 case NEXT_TRANSIT_TYPE_CUSTOM:
1782 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001783 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1784 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001785 case NEXT_TRANSIT_TYPE_SCALE_UP:
1786 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1787 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1788 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1789 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1790 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001791 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1792 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1793 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1794 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001795 default:
1796 return "unknown type=" + mNextAppTransitionType;
1797 }
1798 }
1799
Craig Mautner164d4bb2012-11-26 13:51:23 -08001800 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001801 public void dump(PrintWriter pw, String prefix) {
1802 pw.print(prefix); pw.println(this);
1803 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001804 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001805 pw.print(prefix); pw.print("mNextAppTransitionType=");
1806 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001807 }
1808 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001809 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001810 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001811 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001812 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001813 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1814 pw.print(" mNextAppTransitionExit=0x");
1815 pw.println(Integer.toHexString(mNextAppTransitionExit));
1816 break;
Winson Chung044d5292014-11-06 11:05:19 -08001817 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001818 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001819 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001820 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001821 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1822 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001823 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001824 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001825 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001826 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001827 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001828 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001829 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001830 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001831 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001832 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001833 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001834 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001835 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1836 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001837 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001838 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1839 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1840 pw.println(mDefaultNextAppTransitionAnimationSpec);
1841 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1842 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001843 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1844 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001845 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001846 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001847 }
1848 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001849 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1850 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001851 }
1852 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001853
1854 public void setCurrentUser(int newUserId) {
1855 mCurrentUserId = newUserId;
1856 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001857
1858 /**
1859 * @return true if transition is not running and should not be skipped, false if transition is
1860 * already running
1861 */
1862 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent) {
1863 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
1864 + " transit=" + appTransitionToString(transit)
1865 + " " + this
1866 + " alwaysKeepCurrent=" + alwaysKeepCurrent
1867 + " Callers=" + Debug.getCallers(3));
1868 if (!isTransitionSet() || mNextAppTransition == TRANSIT_NONE) {
1869 setAppTransition(transit);
1870 } else if (!alwaysKeepCurrent) {
1871 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
1872 // Opening a new task always supersedes a close for the anim.
1873 setAppTransition(transit);
1874 } else if (transit == TRANSIT_ACTIVITY_OPEN
1875 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
1876 // Opening a new activity always supersedes a close for the anim.
1877 setAppTransition(transit);
1878 }
1879 }
1880 boolean prepared = prepare();
1881 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001882 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
1883 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001884 }
1885 return prepared;
1886 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001887}