blob: 62fa013e1ee61d1ca02a36eb0e0b3a21dc025d3f [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
Craig Mautner164d4bb2012-11-26 13:51:23 -080075import com.android.internal.util.DumpUtils.Dump;
76import com.android.server.AttributeCache;
77import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -080078import com.android.server.wm.animation.ClipRectLRAnimation;
79import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010080import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080081
82import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010083import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010084import java.util.concurrent.ExecutorService;
85import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -080086
Craig Mautner164d4bb2012-11-26 13:51:23 -080087// State management of app transitions. When we are preparing for a
88// transition, mNextAppTransition will be the kind of transition to
89// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
90// mOpeningApps and mClosingApps are the lists of tokens that will be
91// made visible or hidden at the next transition.
92public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080093 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070094 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080095
Craig Mautner4b71aa12012-12-27 17:20:01 -080096 /** Not set up for a transition. */
97 public static final int TRANSIT_UNSET = -1;
98 /** No animation for transition. */
99 public static final int TRANSIT_NONE = 0;
100 /** 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 -0700101 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800102 /** The window in the top-most activity is being closed to reveal the
103 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700104 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800105 /** A window in a new task is being opened on top of an existing one
106 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700107 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800108 /** A window in the top-most activity is being closed to reveal the
109 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700110 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800111 /** A window in an existing task is being displayed on top of an existing one
112 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700113 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800114 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700115 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800116 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
117 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700118 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800119 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
120 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700121 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800122 /** A window in a new activity is being opened on top of an existing one, and both are on top
123 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700124 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800125 /** The window in the top-most activity is being closed to reveal the previous activity, and
126 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700127 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
128 /** A window in a new task is being opened behind an existing one in another activity's task.
129 * The new window will show briefly and then be gone. */
130 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800131 /** A window in a task is being animated in-place. */
132 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700133 /** An activity is being relaunched (e.g. due to configuration change). */
134 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Jorim Jaggi192086e2016-03-11 17:17:03 +0100135 /** A task is being docked from recents. */
136 public static final int TRANSIT_DOCK_TASK_FROM_RECENTS = 19;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800137
Winson Chunga4ccb862014-08-22 15:26:27 -0700138 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700139 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800140 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700141 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800142
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800143 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800144
145 /** Interpolator to be used for animations that respond directly to a touch */
146 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
147 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
148
Jorim Jaggic69bd222016-03-15 14:38:37 +0100149 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
150 new PathInterpolator(0.85f, 0f, 1f, 1f);
151
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800152 /**
153 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
154 * involved, to make it more understandable.
155 */
156 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700157 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700158 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800159
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800160 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800161 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800162
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800163 private int mNextAppTransition = TRANSIT_UNSET;
164
165 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
166 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
167 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
168 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
169 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700170 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
171 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800172 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800173 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800174 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
175
Winson Chung399f6202014-03-19 10:47:20 -0700176 // These are the possible states for the enter/exit activities during a thumbnail transition
177 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
178 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
179 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
180 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
181
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800182 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800183 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800184 private boolean mNextAppTransitionScaleUp;
185 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100186 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700187 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800188 private int mNextAppTransitionEnter;
189 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800190 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700191
192 // Keyed by task id.
193 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
194 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100195 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
196 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700197 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
198
Winson Chunga4ccb862014-08-22 15:26:27 -0700199 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800200
Winson Chung2820c452014-04-15 15:34:44 -0700201 private Rect mTmpFromClipRect = new Rect();
202 private Rect mTmpToClipRect = new Rect();
203
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700204 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700205
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800206 private final static int APP_STATE_IDLE = 0;
207 private final static int APP_STATE_READY = 1;
208 private final static int APP_STATE_RUNNING = 2;
209 private final static int APP_STATE_TIMEOUT = 3;
210 private int mAppTransitionState = APP_STATE_IDLE;
211
212 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800213 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700214 private final Interpolator mThumbnailFadeInInterpolator;
215 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800216 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700217 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100218 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700219 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
220
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700221 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800222
Amith Yamasani4befbec2013-07-10 16:18:01 -0700223 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800224 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700225
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100226 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100227 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100228
Jorim Jaggif97ed922016-02-18 18:57:07 -0800229 private int mLastClipRevealMaxTranslation;
230 private boolean mLastHadClipReveal;
231
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800232 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800233 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800234 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800235 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
236 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700237 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
238 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100239 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
240 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800241 mConfigShortAnimTime = context.getResources().getInteger(
242 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800243 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
244 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700245 mThumbnailFadeInInterpolator = new Interpolator() {
246 @Override
247 public float getInterpolation(float input) {
248 // Linear response for first fraction, then complete after that.
249 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
250 return 0f;
251 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700252 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700253 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700254 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700255 }
256 };
257 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800258 @Override
259 public float getInterpolation(float input) {
260 // Linear response for first fraction, then complete after that.
261 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700262 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
263 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800264 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700265 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800266 }
267 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700268 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
269 * mContext.getResources().getDisplayMetrics().density);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800270 }
271
272 boolean isTransitionSet() {
273 return mNextAppTransition != TRANSIT_UNSET;
274 }
275
Craig Mautner164d4bb2012-11-26 13:51:23 -0800276 boolean isTransitionEqual(int transit) {
277 return mNextAppTransition == transit;
278 }
279
280 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800281 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800282 }
283
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700284 private void setAppTransition(int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800285 mNextAppTransition = transit;
286 }
287
288 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800289 return mAppTransitionState == APP_STATE_READY
290 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800291 }
292
Craig Mautnerae446592012-12-06 19:05:05 -0800293 void setReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800294 mAppTransitionState = APP_STATE_READY;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100295 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800296 }
297
298 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800299 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800300 }
301
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800302 void setIdle() {
303 mAppTransitionState = APP_STATE_IDLE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800304 }
305
306 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800307 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800308 }
309
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800310 void setTimeout() {
311 mAppTransitionState = APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800312 }
313
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700314 Bitmap getAppTransitionThumbnailHeader(int taskId) {
315 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800316 if (spec == null) {
317 spec = mDefaultNextAppTransitionAnimationSpec;
318 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700319 return spec != null ? spec.bitmap : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800320 }
321
Winson Chunga4ccb862014-08-22 15:26:27 -0700322 /** Returns whether the next thumbnail transition is aspect scaled up. */
323 boolean isNextThumbnailTransitionAspectScaled() {
324 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
325 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
326 }
327
328 /** Returns whether the next thumbnail transition is scaling up. */
329 boolean isNextThumbnailTransitionScaleUp() {
330 return mNextAppTransitionScaleUp;
331 }
332
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800333 boolean isNextAppTransitionThumbnailUp() {
334 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
335 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
336 }
337
338 boolean isNextAppTransitionThumbnailDown() {
339 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
340 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
341 }
342
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100343 /**
344 * @return true if and only if we are currently fetching app transition specs from the future
345 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
346 */
347 boolean isFetchingAppTransitionsSpecs() {
348 return mNextAppTransitionAnimationsSpecsPending;
349 }
350
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700351 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800352 if (!isRunning()) {
353 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100354 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800355 mLastHadClipReveal = false;
356 mLastClipRevealMaxTranslation = 0;
357 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700358 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800359 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700360 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800361 }
362
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800363 void goodToGo(AppWindowAnimator topOpeningAppAnimator, AppWindowAnimator topClosingAppAnimator,
364 ArraySet<AppWindowToken> openingApps, ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800365 mNextAppTransition = TRANSIT_UNSET;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800366 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100367 notifyAppTransitionStartingLocked(
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800368 topOpeningAppAnimator != null ? topOpeningAppAnimator.mAppToken.token : null,
369 topClosingAppAnimator != null ? topClosingAppAnimator.mAppToken.token : null,
370 topOpeningAppAnimator != null ? topOpeningAppAnimator.animation : null,
371 topClosingAppAnimator != null ? topClosingAppAnimator.animation : null);
372 mService.getDefaultDisplayContentLocked().getDockedDividerController()
373 .notifyAppTransitionStarting(openingApps, closingApps);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800374 }
375
376 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800377 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800378 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700379 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi65193992015-11-23 16:49:59 -0800380 mNextAppTransitionAnimationsSpecsFuture = null;
381 mDefaultNextAppTransitionAnimationSpec = null;
382 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800383 }
384
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800385 void freeze() {
386 setAppTransition(AppTransition.TRANSIT_UNSET);
387 clear();
388 setReady();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100389 notifyAppTransitionCancelledLocked();
390 }
391
392 void registerListenerLocked(AppTransitionListener listener) {
393 mListeners.add(listener);
394 }
395
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700396 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100397 for (int i = 0; i < mListeners.size(); i++) {
398 mListeners.get(i).onAppTransitionFinishedLocked(token);
399 }
400 }
401
402 private void notifyAppTransitionPendingLocked() {
403 for (int i = 0; i < mListeners.size(); i++) {
404 mListeners.get(i).onAppTransitionPendingLocked();
405 }
406 }
407
408 private void notifyAppTransitionCancelledLocked() {
409 for (int i = 0; i < mListeners.size(); i++) {
410 mListeners.get(i).onAppTransitionCancelledLocked();
411 }
412 }
413
414 private void notifyAppTransitionStartingLocked(IBinder openToken,
415 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
416 for (int i = 0; i < mListeners.size(); i++) {
417 mListeners.get(i).onAppTransitionStartingLocked(openToken, closeToken, openAnimation,
418 closeAnimation);
419 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800420 }
421
Craig Mautner164d4bb2012-11-26 13:51:23 -0800422 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
423 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
424 + (lp != null ? lp.packageName : null)
425 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
426 if (lp != null && lp.windowAnimations != 0) {
427 // If this is a system resource, don't try to load it from the
428 // application resources. It is nice to avoid loading application
429 // resources if we can.
430 String packageName = lp.packageName != null ? lp.packageName : "android";
431 int resId = lp.windowAnimations;
432 if ((resId&0xFF000000) == 0x01000000) {
433 packageName = "android";
434 }
435 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
436 + packageName);
437 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700438 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800439 }
440 return null;
441 }
442
443 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
444 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
445 + packageName + " resId=0x" + Integer.toHexString(resId));
446 if (packageName != null) {
447 if ((resId&0xFF000000) == 0x01000000) {
448 packageName = "android";
449 }
450 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
451 + packageName);
452 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700453 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800454 }
455 return null;
456 }
457
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700458 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800459 int anim = 0;
460 Context context = mContext;
461 if (animAttr >= 0) {
462 AttributeCache.Entry ent = getCachedAnimations(lp);
463 if (ent != null) {
464 context = ent.context;
465 anim = ent.array.getResourceId(animAttr, 0);
466 }
467 }
468 if (anim != 0) {
469 return AnimationUtils.loadAnimation(context, anim);
470 }
471 return null;
472 }
473
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700474 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
475 Context context = mContext;
476 if (resId >= 0) {
477 AttributeCache.Entry ent = getCachedAnimations(lp);
478 if (ent != null) {
479 context = ent.context;
480 }
481 return AnimationUtils.loadAnimation(context, resId);
482 }
483 return null;
484 }
485
486 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800487 int anim = 0;
488 Context context = mContext;
489 if (resId >= 0) {
490 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
491 if (ent != null) {
492 context = ent.context;
493 anim = resId;
494 }
495 }
496 if (anim != 0) {
497 return AnimationUtils.loadAnimation(context, anim);
498 }
499 return null;
500 }
501
Craig Mautner164d4bb2012-11-26 13:51:23 -0800502 /**
503 * Compute the pivot point for an animation that is scaling from a small
504 * rect on screen to a larger rect. The pivot point varies depending on
505 * the distance between the inner and outer edges on both sides. This
506 * function computes the pivot point for one dimension.
507 * @param startPos Offset from left/top edge of outer rectangle to
508 * left/top edge of inner rectangle.
509 * @param finalScale The scaling factor between the size of the outer
510 * and inner rectangles.
511 */
512 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800513
514 /*
515 Theorem of intercepting lines:
516
517 + + +-----------------------------------------------+
518 | | | |
519 | | | |
520 | | | |
521 | | | |
522 x | y | | |
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 |
563 + ++
564 p ++
565
566 scale = (x - y) / x
567 <=> x = -y / (scale - 1)
568 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800569 final float denom = finalScale-1;
570 if (Math.abs(denom) < .0001f) {
571 return startPos;
572 }
573 return -startPos / denom;
574 }
575
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700576 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
577 Rect containingFrame) {
578 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700579 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700580 final int appWidth = containingFrame.width();
581 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800582 if (enter) {
583 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700584 float scaleW = mTmpRect.width() / (float) appWidth;
585 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800586 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700587 computePivot(mTmpRect.left, scaleW),
588 computePivot(mTmpRect.right, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800589 scale.setInterpolator(mDecelerateInterpolator);
590
Craig Mautner164d4bb2012-11-26 13:51:23 -0800591 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700592 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800593
594 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800595 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800596 set.addAnimation(alpha);
597 set.setDetachWallpaper(true);
598 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800599 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
600 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800601 // If we are on top of the wallpaper, we need an animation that
602 // correctly handles the wallpaper staying static behind all of
603 // the animated elements. To do this, will just have the existing
604 // element fade out.
605 a = new AlphaAnimation(1, 0);
606 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800607 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800608 // For normal animations, the exiting element just holds in place.
609 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800610 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800611
612 // Pick the desired duration. If this is an inter-activity transition,
613 // it is the standard duration for that. Otherwise we use the longer
614 // task transition duration.
615 final long duration;
616 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800617 case TRANSIT_ACTIVITY_OPEN:
618 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800619 duration = mConfigShortAnimTime;
620 break;
621 default:
622 duration = DEFAULT_APP_TRANSITION_DURATION;
623 break;
624 }
625 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800626 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800627 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800628 a.initialize(appWidth, appHeight, appWidth, appHeight);
629 return a;
630 }
631
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700632 private void getDefaultNextAppTransitionStartRect(Rect rect) {
633 if (mDefaultNextAppTransitionAnimationSpec == null ||
634 mDefaultNextAppTransitionAnimationSpec.rect == null) {
635 Slog.wtf(TAG, "Starting rect for app requested, but none available", new Throwable());
636 rect.setEmpty();
637 } else {
638 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
639 }
640 }
641
642 void getNextAppTransitionStartRect(int taskId, Rect rect) {
643 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800644 if (spec == null) {
645 spec = mDefaultNextAppTransitionAnimationSpec;
646 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700647 if (spec == null || spec.rect == null) {
648 Slog.wtf(TAG, "Starting rect for task: " + taskId + " requested, but not available",
649 new Throwable());
650 rect.setEmpty();
651 } else {
652 rect.set(spec.rect);
653 }
654 }
655
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800656 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
657 Bitmap bitmap) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700658 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800659 bitmap, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700660 }
661
Jorim Jaggif97ed922016-02-18 18:57:07 -0800662 /**
663 * @return the duration of the last clip reveal animation
664 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800665 long getLastClipRevealTransitionDuration() {
666 return mLastClipRevealTransitionDuration;
667 }
668
669 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800670 * @return the maximum distance the app surface is traveling of the last clip reveal animation
671 */
672 int getLastClipRevealMaxTranslation() {
673 return mLastClipRevealMaxTranslation;
674 }
675
676 /**
677 * @return true if in the last app transition had a clip reveal animation, false otherwise
678 */
679 boolean hadClipRevealAnimation() {
680 return mLastHadClipReveal;
681 }
682
683 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800684 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
685 * the start rect is outside of the target rect, and there is a lot of movement going on.
686 *
687 * @param cutOff whether the start rect was not fully contained by the end rect
688 * @param translationX the total translation the surface moves in x direction
689 * @param translationY the total translation the surfaces moves in y direction
690 * @param displayFrame our display frame
691 *
692 * @return the duration of the clip reveal animation, in milliseconds
693 */
694 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
695 float translationY, Rect displayFrame) {
696 if (!cutOff) {
697 return DEFAULT_APP_TRANSITION_DURATION;
698 }
699 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
700 Math.abs(translationY) / displayFrame.height());
701 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
702 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
703 }
704
705 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
706 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800707 final Animation anim;
708 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700709 final int appWidth = appFrame.width();
710 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800711
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700712 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700713 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700714 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700715
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700716 float t = 0f;
717 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800718 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700719 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800720 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
721 int translationX = 0;
722 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700723 int centerX = mTmpRect.centerX();
724 int centerY = mTmpRect.centerY();
725 int halfWidth = mTmpRect.width() / 2;
726 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800727 int clipStartX = centerX - halfWidth - appFrame.left;
728 int clipStartY = centerY - halfHeight - appFrame.top;
729 boolean cutOff = false;
730
731 // If the starting rectangle is fully or partially outside of the target rectangle, we
732 // need to start the clipping at the edge and then achieve the rest with translation
733 // and extending the clip rect from that edge.
734 if (appFrame.top > centerY - halfHeight) {
735 translationY = (centerY - halfHeight) - appFrame.top;
736 translationYCorrection = 0;
737 clipStartY = 0;
738 cutOff = true;
739 }
740 if (appFrame.left > centerX - halfWidth) {
741 translationX = (centerX - halfWidth) - appFrame.left;
742 clipStartX = 0;
743 cutOff = true;
744 }
745 if (appFrame.right < centerX + halfWidth) {
746 translationX = (centerX + halfWidth) - appFrame.right;
747 clipStartX = appWidth - mTmpRect.width();
748 cutOff = true;
749 }
750 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
751 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700752
753 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800754 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800755 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700756 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800757 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700758
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800759 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
760 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
761 : mLinearOutSlowInInterpolator);
762 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800763
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800764 Animation clipAnimTB = new ClipRectTBAnimation(
765 clipStartY, clipStartY + mTmpRect.height(),
766 0, appHeight,
767 translationYCorrection, 0,
768 mLinearOutSlowInInterpolator);
769 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
770 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800771
772 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800773 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700774 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800775 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700776 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800777
778 AnimationSet set = new AnimationSet(false);
779 set.addAnimation(clipAnimLR);
780 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700781 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800782 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700783 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800784 set.initialize(appWidth, appHeight, appWidth, appHeight);
785 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800786 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800787 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800788
789 // If the start rect was full inside the target rect (cutOff == false), we don't need
790 // to store the translation, because it's only used if cutOff == true.
791 mLastClipRevealMaxTranslation = cutOff
792 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800793 } else {
794 final long duration;
795 switch (transit) {
796 case TRANSIT_ACTIVITY_OPEN:
797 case TRANSIT_ACTIVITY_CLOSE:
798 duration = mConfigShortAnimTime;
799 break;
800 default:
801 duration = DEFAULT_APP_TRANSITION_DURATION;
802 break;
803 }
804 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
805 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
806 // If we are on top of the wallpaper, we need an animation that
807 // correctly handles the wallpaper staying static behind all of
808 // the animated elements. To do this, will just have the existing
809 // element fade out.
810 anim = new AlphaAnimation(1, 0);
811 anim.setDetachWallpaper(true);
812 } else {
813 // For normal animations, the exiting element just holds in place.
814 anim = new AlphaAnimation(1, 1);
815 }
816 anim.setInterpolator(mDecelerateInterpolator);
817 anim.setDuration(duration);
818 anim.setFillAfter(true);
819 }
820 return anim;
821 }
822
Winson Chung399f6202014-03-19 10:47:20 -0700823 /**
824 * Prepares the specified animation with a standard duration, interpolator, etc.
825 */
Winson Chung5393dff2014-05-08 14:25:43 -0700826 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100827 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700828 if (duration > 0) {
829 a.setDuration(duration);
830 }
Winson Chung5393dff2014-05-08 14:25:43 -0700831 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100832 if (interpolator != null) {
833 a.setInterpolator(interpolator);
834 }
Winson Chung5393dff2014-05-08 14:25:43 -0700835 a.initialize(appWidth, appHeight, appWidth, appHeight);
836 return a;
837 }
838
839 /**
840 * Prepares the specified animation with a standard duration, interpolator, etc.
841 */
Winson Chung399f6202014-03-19 10:47:20 -0700842 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800843 // Pick the desired duration. If this is an inter-activity transition,
844 // it is the standard duration for that. Otherwise we use the longer
845 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700846 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800847 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800848 case TRANSIT_ACTIVITY_OPEN:
849 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800850 duration = mConfigShortAnimTime;
851 break;
852 default:
853 duration = DEFAULT_APP_TRANSITION_DURATION;
854 break;
855 }
Winson Chung5393dff2014-05-08 14:25:43 -0700856 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
857 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800858 }
859
Winson Chung399f6202014-03-19 10:47:20 -0700860 /**
861 * Return the current thumbnail transition state.
862 */
863 int getThumbnailTransitionState(boolean enter) {
864 if (enter) {
865 if (mNextAppTransitionScaleUp) {
866 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
867 } else {
868 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
869 }
870 } else {
871 if (mNextAppTransitionScaleUp) {
872 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
873 } else {
874 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
875 }
876 }
877 }
878
879 /**
880 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700881 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700882 */
Jorim Jaggide63d442016-03-14 14:56:56 +0100883 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
884 Bitmap thumbnailHeader, final int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700885 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700886 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700887 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700888 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700889 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700890
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700891 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700892 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi8448f332016-03-14 17:50:37 +0100893 final float toY = mTmpRect.height() / 2 * (scaleW - 1f) + appRect.top;
894 final float fromY = mTmpRect.top;
895 final float toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
896 final float fromX = mTmpRect.left;
897 final float pivotX = mTmpRect.width() / 2;
898 final float pivotY = mTmpRect.height() / 2;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100899 final long duration = getAspectScaleDuration();
900 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -0700901 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700902 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +0100903 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100904 scale.setInterpolator(interpolator);
905 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800906 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100907 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
908 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
909 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
910 ? duration / 2
911 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100912 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
913 translate.setInterpolator(interpolator);
914 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -0700915
Jorim Jaggide63d442016-03-14 14:56:56 +0100916 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
917 mTmpToClipRect.set(appRect);
918
919 // Containing frame is in screen space, but we need the clip rect in the
920 // app space.
921 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100922 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
923 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +0100924
925 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +0100926 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
927 (int) (-contentInsets.top * scaleW),
928 (int) (-contentInsets.right * scaleW),
929 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +0100930 }
931
932 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100933 clipAnim.setInterpolator(interpolator);
934 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +0100935
Winson Chung399f6202014-03-19 10:47:20 -0700936 // This AnimationSet uses the Interpolators assigned above.
937 AnimationSet set = new AnimationSet(false);
938 set.addAnimation(scale);
939 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -0700940 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +0100941 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -0700942 a = set;
943 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700944 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +0100945 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100946 scale.setInterpolator(interpolator);
947 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -0700948 Animation alpha = new AlphaAnimation(0f, 1f);
949 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100950 alpha.setDuration(duration);
951 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
952 translate.setInterpolator(interpolator);
953 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -0700954
Winson Chunga4ccb862014-08-22 15:26:27 -0700955 // This AnimationSet uses the Interpolators assigned above.
956 AnimationSet set = new AnimationSet(false);
957 set.addAnimation(scale);
958 set.addAnimation(alpha);
959 set.addAnimation(translate);
960 a = set;
961
962 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700963 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +0100964 null);
Winson Chung399f6202014-03-19 10:47:20 -0700965 }
966
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100967 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
968
969 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +0100970 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100971 return new TranslateAnimation(fromX, toX, fromY, toY);
972 } else {
973 final Path path = createCurvedPath(fromX, toX, fromY, toY);
974 return new CurvedTranslateAnimation(path);
975 }
976 }
977
978 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
979 final Path path = new Path();
980 path.moveTo(fromX, fromY);
981 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
982 return path;
983 }
984
985 private long getAspectScaleDuration() {
986 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +0100987 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100988 } else {
989 return THUMBNAIL_APP_TRANSITION_DURATION;
990 }
991 }
992
993 private Interpolator getAspectScaleInterpolator() {
994 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
995 return mFastOutSlowInInterpolator;
996 } else {
997 return TOUCH_RESPONSE_INTERPOLATOR;
998 }
999 }
1000
Winson Chung399f6202014-03-19 10:47:20 -07001001 /**
1002 * This alternate animation is created when we are doing a thumbnail transition, for the
1003 * activity that is leaving, and the activity that is entering.
1004 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001005 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001006 int orientation, int transit, Rect containingFrame, Rect contentInsets,
1007 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001008 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001009 final int appWidth = containingFrame.width();
1010 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001011 getDefaultNextAppTransitionStartRect(mTmpRect);
1012 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001013 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001014 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001015 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winson21700932016-03-24 17:26:23 -07001016 final int thumbStartX = mTmpRect.left - containingFrame.left;
1017 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001018
1019 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001020 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1021 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1022 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1023 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001024 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001025 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001026 } else if (freeform) {
1027 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1028 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001029 } else {
Winson21700932016-03-24 17:26:23 -07001030 AnimationSet set = new AnimationSet(true);
1031
1032 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001033 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001034 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001035
1036 // Containing frame is in screen space, but we need the clip rect in the
1037 // app space.
1038 mTmpFromClipRect.offsetTo(0, 0);
1039 mTmpToClipRect.offsetTo(0, 0);
1040
1041 // Exclude insets region from the source clip.
1042 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001043 mNextAppTransitionInsets.set(contentInsets);
1044
Winson21700932016-03-24 17:26:23 -07001045 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
1046 // We scale the width and clip to the top/left square
Jorim Jaggic69bd222016-03-15 14:38:37 +01001047 // We scale the width and clip to the top/left square
1048 float scale = thumbWidth /
1049 (appWidth - contentInsets.left - contentInsets.right);
1050 int unscaledThumbHeight = (int) (thumbHeight / scale);
1051 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1052
1053 mNextAppTransitionInsets.set(contentInsets);
1054
Jorim Jaggi8448f332016-03-14 17:50:37 +01001055 Animation scaleAnim = new ScaleAnimation(
1056 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1057 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001058 containingFrame.width() / 2f,
1059 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001060 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001061 final float x = containingFrame.width() / 2f
1062 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001063 final float targetY = (mTmpRect.top - containingFrame.top);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001064 final float y = containingFrame.height() / 2f
1065 - containingFrame.height() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001066 final float startX = targetX - x;
1067 final float startY = targetY - y;
1068 Animation clipAnim = scaleUp
1069 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1070 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1071 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001072 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1073 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1074
Winson21700932016-03-24 17:26:23 -07001075 set.addAnimation(clipAnim);
1076 set.addAnimation(scaleAnim);
1077 set.addAnimation(translateAnim);
1078
1079 } else {
1080 // In landscape, we don't scale at all and only crop
1081 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1082 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1083
Jorim Jaggi8448f332016-03-14 17:50:37 +01001084 Animation clipAnim = scaleUp
1085 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1086 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1087 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001088 ? createCurvedMotion(thumbStartX, 0,
1089 thumbStartY - contentInsets.top, 0)
1090 : createCurvedMotion(0, thumbStartX, 0,
1091 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001092
1093 set.addAnimation(clipAnim);
1094 set.addAnimation(translateAnim);
1095 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001096 a = set;
Winson21700932016-03-24 17:26:23 -07001097 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001098 }
Winson Chung399f6202014-03-19 10:47:20 -07001099 break;
1100 }
1101 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001102 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001103 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001104 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001105 // activity.
1106 a = new AlphaAnimation(1, 0);
1107 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001108 a = new AlphaAnimation(1, 1);
1109 }
1110 break;
1111 }
1112 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001113 // Target app window during the scale down
1114 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1115 // Fade in the destination activity if we are animating from a wallpaper
1116 // activity.
1117 a = new AlphaAnimation(0, 1);
1118 } else {
1119 a = new AlphaAnimation(1, 1);
1120 }
Winson Chung399f6202014-03-19 10:47:20 -07001121 break;
1122 }
Winson Chung399f6202014-03-19 10:47:20 -07001123 default:
1124 throw new RuntimeException("Invalid thumbnail transition state");
1125 }
1126
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001127 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1128 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001129 }
1130
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001131 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1132 @Nullable Rect surfaceInsets, int taskId) {
1133 getNextAppTransitionStartRect(taskId, mTmpRect);
1134 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1135 true);
1136 }
1137
1138 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1139 @Nullable Rect surfaceInsets, int taskId) {
1140 getNextAppTransitionStartRect(taskId, mTmpRect);
1141 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1142 false);
1143 }
1144
1145 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1146 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1147 final float sourceWidth = sourceFrame.width();
1148 final float sourceHeight = sourceFrame.height();
1149 final float destWidth = destFrame.width();
1150 final float destHeight = destFrame.height();
1151 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1152 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001153 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001154 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001155 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001156 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001157 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1158 // We want the scaling to happen from the center of the surface. In order to achieve that,
1159 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001160 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1161 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1162 final ScaleAnimation scale = enter ?
1163 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1164 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1165 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1166 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1167 final int destHCenter = destFrame.left + destFrame.width() / 2;
1168 final int destVCenter = destFrame.top + destFrame.height() / 2;
1169 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1170 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1171 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1172 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001173 set.addAnimation(scale);
1174 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001175
1176 final IRemoteCallback callback = mAnimationFinishedCallback;
1177 if (callback != null) {
1178 set.setAnimationListener(new Animation.AnimationListener() {
1179 @Override
1180 public void onAnimationStart(Animation animation) { }
1181
1182 @Override
1183 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001184 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001185 }
1186
1187 @Override
1188 public void onAnimationRepeat(Animation animation) { }
1189 });
1190 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001191 return set;
1192 }
1193
Winson Chung399f6202014-03-19 10:47:20 -07001194 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001195 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001196 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001197 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001198 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
1199 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001200 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001201 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001202 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001203 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001204 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001205 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1206
1207 if (mNextAppTransitionScaleUp) {
1208 // Animation for the thumbnail zooming from its initial size to the full screen
1209 float scaleW = appWidth / thumbWidth;
1210 float scaleH = appHeight / thumbHeight;
1211 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001212 computePivot(mTmpRect.left, 1 / scaleW),
1213 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001214 scale.setInterpolator(mDecelerateInterpolator);
1215
1216 Animation alpha = new AlphaAnimation(1, 0);
1217 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1218
1219 // This AnimationSet uses the Interpolators assigned above.
1220 AnimationSet set = new AnimationSet(false);
1221 set.addAnimation(scale);
1222 set.addAnimation(alpha);
1223 a = set;
1224 } else {
1225 // Animation for the thumbnail zooming down from the full screen to its final size
1226 float scaleW = appWidth / thumbWidth;
1227 float scaleH = appHeight / thumbHeight;
1228 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001229 computePivot(mTmpRect.left, 1 / scaleW),
1230 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001231 }
1232
1233 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1234 }
1235
1236 /**
Winson Chung399f6202014-03-19 10:47:20 -07001237 * This animation is created when we are doing a thumbnail transition, for the activity that is
1238 * leaving, and the activity that is entering.
1239 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001240 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1241 int transit, int taskId) {
1242 final int appWidth = containingFrame.width();
1243 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001244 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001245 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001246 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001247 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001248 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001249 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001250 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1251
1252 switch (thumbTransitState) {
1253 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1254 // Entering app scales up with the thumbnail
1255 float scaleW = thumbWidth / appWidth;
1256 float scaleH = thumbHeight / appHeight;
1257 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001258 computePivot(mTmpRect.left, scaleW),
1259 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001260 break;
1261 }
1262 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1263 // Exiting app while the thumbnail is scaling up should fade or stay in place
1264 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1265 // Fade out while bringing up selected activity. This keeps the
1266 // current activity from showing through a launching wallpaper
1267 // activity.
1268 a = new AlphaAnimation(1, 0);
1269 } else {
1270 // noop animation
1271 a = new AlphaAnimation(1, 1);
1272 }
1273 break;
1274 }
1275 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1276 // Entering the other app, it should just be visible while we scale the thumbnail
1277 // down above it
1278 a = new AlphaAnimation(1, 1);
1279 break;
1280 }
1281 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1282 // Exiting the current app, the app should scale down with the thumbnail
1283 float scaleW = thumbWidth / appWidth;
1284 float scaleH = thumbHeight / appHeight;
1285 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001286 computePivot(mTmpRect.left, scaleW),
1287 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001288
1289 Animation alpha = new AlphaAnimation(1, 0);
1290
1291 AnimationSet set = new AnimationSet(true);
1292 set.addAnimation(scale);
1293 set.addAnimation(alpha);
1294 set.setZAdjustment(Animation.ZORDER_TOP);
1295 a = set;
1296 break;
1297 }
1298 default:
1299 throw new RuntimeException("Invalid thumbnail transition state");
1300 }
1301
1302 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1303 }
1304
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001305 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001306 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1307 final int left = mTmpFromClipRect.left;
1308 final int top = mTmpFromClipRect.top;
1309 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001310 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1311 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001312 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001313 float fromWidth = mTmpFromClipRect.width();
1314 float toWidth = mTmpToClipRect.width();
1315 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001316 // While the window might span the whole display, the actual content will be cropped to the
1317 // system decoration frame, for example when the window is docked. We need to take into
1318 // account the visible height when constructing the animation.
1319 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1320 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001321 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1322 // The final window is larger in both dimensions than current window (e.g. we are
1323 // maximizing), so we can simply unclip the new window and there will be no disappearing
1324 // frame.
1325 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1326 } else {
1327 // The disappearing window has one larger dimension. We need to apply scaling, so the
1328 // first frame of the entry animation matches the old window.
1329 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001330 // We might not be going exactly full screen, but instead be aligned under the status
1331 // bar using cropping. We still need to account for the cropped part, which will also
1332 // be scaled.
1333 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001334 }
1335
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001336 // We animate the translation from the old position of the removed window, to the new
1337 // position of the added window. The latter might not be full screen, for example docked for
1338 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001339 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001340 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001341 set.addAnimation(translate);
1342 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001343 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001344 return set;
1345 }
1346
Jorim Jaggic554b772015-06-04 16:07:57 -07001347 /**
1348 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1349 * frame of the transition doesn't change the visuals on screen, so we can start
1350 * directly with the second one
1351 */
1352 boolean canSkipFirstFrame() {
1353 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1354 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
1355 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1356 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001357
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001358 /**
1359 *
1360 * @param frame These are the bounds of the window when it finishes the animation. This is where
1361 * the animation must usually finish in entrance animation, as the next frame will
1362 * display the window at these coordinates. In case of exit animation, this is
1363 * where the animation must start, as the frame before the animation is displaying
1364 * the window at these bounds.
1365 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1366 * window might be obscured, usually by the system windows (status bar and
1367 * navigation bar) and we use content insets to convey that information. This
1368 * usually affects the animation aspects vertically, as the system decoration is
1369 * at the top and the bottom. For example when we animate from full screen to
1370 * recents, we want to exclude the covered parts, because they won't match the
1371 * thumbnail after the last frame is executed.
1372 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1373 * know about this to make the animation frames match. We currently use
1374 * this for freeform windows, which have larger surfaces to display
1375 * shadows. When we animate them from recents, we want to match the content
1376 * to the recents thumbnail and hence need to account for the surface being
1377 * bigger.
1378 */
Craig Mautner164d4bb2012-11-26 13:51:23 -08001379 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001380 int orientation, Rect frame, Rect displayFrame, Rect insets,
1381 @Nullable Rect surfaceInsets, boolean isVoiceInteraction, boolean freeform,
1382 int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001383 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001384 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
1385 || transit == TRANSIT_TASK_OPEN
1386 || transit == TRANSIT_TASK_TO_FRONT)) {
1387 a = loadAnimationRes(lp, enter
1388 ? com.android.internal.R.anim.voice_activity_open_enter
1389 : com.android.internal.R.anim.voice_activity_open_exit);
1390 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1391 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001392 + " anim=" + a + " transit=" + appTransitionToString(transit)
1393 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001394 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1395 || transit == TRANSIT_TASK_CLOSE
1396 || transit == TRANSIT_TASK_TO_BACK)) {
1397 a = loadAnimationRes(lp, enter
1398 ? com.android.internal.R.anim.voice_activity_close_enter
1399 : com.android.internal.R.anim.voice_activity_close_exit);
1400 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1401 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001402 + " anim=" + a + " transit=" + appTransitionToString(transit)
1403 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001404 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001405 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001406 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1407 "applyAnimation:"
1408 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1409 + " transit=" + appTransitionToString(transit)
1410 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001411 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1412 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001413 mNextAppTransitionEnter : mNextAppTransitionExit);
1414 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1415 "applyAnimation:"
1416 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001417 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001418 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001419 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1420 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1421 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1422 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001423 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1424 + " transit=" + appTransitionToString(transit)
1425 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001426 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001427 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001428 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1429 "applyAnimation:"
1430 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001431 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001432 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001433 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001434 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001435 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1436 "applyAnimation:"
1437 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001438 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001439 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001440 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1441 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001442 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001443 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001444 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001445 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001446 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1447 String animName = mNextAppTransitionScaleUp ?
1448 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1449 Slog.v(TAG, "applyAnimation:"
1450 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001451 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001452 + " Callers=" + Debug.getCallers(3));
1453 }
1454 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1455 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1456 mNextAppTransitionScaleUp =
1457 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1458 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001459 getThumbnailTransitionState(enter), orientation, transit, frame,
1460 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001461 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1462 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001463 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001464 Slog.v(TAG, "applyAnimation:"
1465 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001466 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001467 + " Callers=" + Debug.getCallers(3));
1468 }
1469 } else {
1470 int animAttr = 0;
1471 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001472 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001473 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001474 ? WindowAnimation_activityOpenEnterAnimation
1475 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001476 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001477 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001478 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001479 ? WindowAnimation_activityCloseEnterAnimation
1480 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001481 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001482 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001483 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001484 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001485 ? WindowAnimation_taskOpenEnterAnimation
1486 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001487 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001488 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001489 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001490 ? WindowAnimation_taskCloseEnterAnimation
1491 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001492 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001493 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001494 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001495 ? WindowAnimation_taskToFrontEnterAnimation
1496 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001497 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001498 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001499 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001500 ? WindowAnimation_taskToBackEnterAnimation
1501 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001502 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001503 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001504 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001505 ? WindowAnimation_wallpaperOpenEnterAnimation
1506 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001507 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001508 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001509 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001510 ? WindowAnimation_wallpaperCloseEnterAnimation
1511 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001512 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001513 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001514 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001515 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1516 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001517 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001518 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001519 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001520 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1521 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001522 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001523 case TRANSIT_TASK_OPEN_BEHIND:
1524 animAttr = enter
1525 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001526 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001527 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001528 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001529 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1530 "applyAnimation:"
1531 + " anim=" + a
1532 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001533 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001534 + " Callers=" + Debug.getCallers(3));
1535 }
1536 return a;
1537 }
1538
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001539 int getAppStackClipMode() {
1540 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001541 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001542 ? STACK_CLIP_NONE
1543 : STACK_CLIP_AFTER_ANIM;
1544 }
1545
Craig Mautner164d4bb2012-11-26 13:51:23 -08001546 void postAnimationCallback() {
1547 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001548 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1549 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001550 mNextAppTransitionCallback = null;
1551 }
1552 }
1553
1554 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001555 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001556 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001557 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001558 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001559 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001560 mNextAppTransitionEnter = enterAnim;
1561 mNextAppTransitionExit = exitAnim;
1562 postAnimationCallback();
1563 mNextAppTransitionCallback = startedCallback;
1564 } else {
1565 postAnimationCallback();
1566 }
1567 }
1568
1569 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001570 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001571 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001572 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001573 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001574 putDefaultNextAppTransitionCoordinates(startX, startY, startX + startWidth,
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001575 startY + startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001576 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001577 }
1578 }
1579
Chet Haase10e23ab2015-02-11 15:08:38 -08001580 void overridePendingAppTransitionClipReveal(int startX, int startY,
1581 int startWidth, int startHeight) {
1582 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001583 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001584 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001585 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001586 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001587 }
1588 }
1589
Craig Mautner164d4bb2012-11-26 13:51:23 -08001590 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1591 IRemoteCallback startedCallback, boolean scaleUp) {
1592 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001593 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001594 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1595 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001596 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001597 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001598 postAnimationCallback();
1599 mNextAppTransitionCallback = startedCallback;
1600 } else {
1601 postAnimationCallback();
1602 }
1603 }
1604
Winson Chunga4ccb862014-08-22 15:26:27 -07001605 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001606 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001607 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001608 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001609 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1610 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001611 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001612 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1613 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001614 postAnimationCallback();
1615 mNextAppTransitionCallback = startedCallback;
1616 } else {
1617 postAnimationCallback();
1618 }
1619 }
1620
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001621 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001622 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1623 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001624 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001625 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001626 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1627 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001628 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001629 if (specs != null) {
1630 for (int i = 0; i < specs.length; i++) {
1631 AppTransitionAnimationSpec spec = specs[i];
1632 if (spec != null) {
1633 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1634 if (i == 0) {
1635 // In full screen mode, the transition code depends on the default spec
1636 // to be set.
1637 Rect rect = spec.rect;
1638 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Filip Gruszczynskie3264d82015-11-20 17:10:04 -08001639 rect.width(), rect.height(), spec.bitmap);
Jorim Jaggi43102412015-11-11 16:28:37 +01001640 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001641 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001642 }
1643 }
1644 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001645 mNextAppTransitionCallback = onAnimationStartedCallback;
1646 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001647 } else {
1648 postAnimationCallback();
1649 }
1650 }
1651
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001652 void overridePendingAppTransitionMultiThumbFuture(
1653 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1654 boolean scaleUp) {
1655 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001656 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001657 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1658 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001659 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1660 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001661 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001662 }
1663 }
1664
Winson Chung044d5292014-11-06 11:05:19 -08001665 void overrideInPlaceAppTransition(String packageName, int anim) {
1666 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001667 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001668 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1669 mNextAppTransitionPackage = packageName;
1670 mNextAppTransitionInPlace = anim;
1671 } else {
1672 postAnimationCallback();
1673 }
1674 }
1675
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001676 /**
1677 * If a future is set for the app transition specs, fetch it in another thread.
1678 */
1679 private void fetchAppTransitionSpecsFromFuture() {
1680 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1681 mNextAppTransitionAnimationsSpecsPending = true;
1682 final IAppTransitionAnimationSpecsFuture future
1683 = mNextAppTransitionAnimationsSpecsFuture;
1684 mNextAppTransitionAnimationsSpecsFuture = null;
1685 mDefaultExecutor.execute(new Runnable() {
1686 @Override
1687 public void run() {
1688 AppTransitionAnimationSpec[] specs = null;
1689 try {
1690 specs = future.get();
1691 } catch (RemoteException e) {
1692 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1693 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001694 synchronized (mService.mWindowMap) {
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001695 mNextAppTransitionAnimationsSpecsPending = false;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001696 overridePendingAppTransitionMultiThumb(specs,
1697 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1698 mNextAppTransitionScaleUp);
1699 mNextAppTransitionFutureCallback = null;
Filip Gruszczynski96daf322015-11-18 18:01:27 -08001700 if (specs != null) {
1701 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1702 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001703 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001704 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001705 }
1706 });
1707 }
1708 }
1709
Craig Mautner164d4bb2012-11-26 13:51:23 -08001710 @Override
1711 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001712 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001713 }
1714
Craig Mautner4b71aa12012-12-27 17:20:01 -08001715 /**
1716 * Returns the human readable name of a window transition.
1717 *
1718 * @param transition The window transition.
1719 * @return The transition symbolic name.
1720 */
1721 public static String appTransitionToString(int transition) {
1722 switch (transition) {
1723 case TRANSIT_UNSET: {
1724 return "TRANSIT_UNSET";
1725 }
1726 case TRANSIT_NONE: {
1727 return "TRANSIT_NONE";
1728 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001729 case TRANSIT_ACTIVITY_OPEN: {
1730 return "TRANSIT_ACTIVITY_OPEN";
1731 }
1732 case TRANSIT_ACTIVITY_CLOSE: {
1733 return "TRANSIT_ACTIVITY_CLOSE";
1734 }
1735 case TRANSIT_TASK_OPEN: {
1736 return "TRANSIT_TASK_OPEN";
1737 }
1738 case TRANSIT_TASK_CLOSE: {
1739 return "TRANSIT_TASK_CLOSE";
1740 }
1741 case TRANSIT_TASK_TO_FRONT: {
1742 return "TRANSIT_TASK_TO_FRONT";
1743 }
1744 case TRANSIT_TASK_TO_BACK: {
1745 return "TRANSIT_TASK_TO_BACK";
1746 }
1747 case TRANSIT_WALLPAPER_CLOSE: {
1748 return "TRANSIT_WALLPAPER_CLOSE";
1749 }
1750 case TRANSIT_WALLPAPER_OPEN: {
1751 return "TRANSIT_WALLPAPER_OPEN";
1752 }
1753 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1754 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1755 }
1756 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1757 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1758 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001759 case TRANSIT_TASK_OPEN_BEHIND: {
1760 return "TRANSIT_TASK_OPEN_BEHIND";
1761 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001762 case TRANSIT_ACTIVITY_RELAUNCH: {
1763 return "TRANSIT_ACTIVITY_RELAUNCH";
1764 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001765 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1766 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1767 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001768 default: {
1769 return "<UNKNOWN>";
1770 }
1771 }
1772 }
1773
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001774 private String appStateToString() {
1775 switch (mAppTransitionState) {
1776 case APP_STATE_IDLE:
1777 return "APP_STATE_IDLE";
1778 case APP_STATE_READY:
1779 return "APP_STATE_READY";
1780 case APP_STATE_RUNNING:
1781 return "APP_STATE_RUNNING";
1782 case APP_STATE_TIMEOUT:
1783 return "APP_STATE_TIMEOUT";
1784 default:
1785 return "unknown state=" + mAppTransitionState;
1786 }
1787 }
1788
1789 private String transitTypeToString() {
1790 switch (mNextAppTransitionType) {
1791 case NEXT_TRANSIT_TYPE_NONE:
1792 return "NEXT_TRANSIT_TYPE_NONE";
1793 case NEXT_TRANSIT_TYPE_CUSTOM:
1794 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001795 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1796 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001797 case NEXT_TRANSIT_TYPE_SCALE_UP:
1798 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1799 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1800 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1801 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1802 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001803 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1804 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1805 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1806 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001807 default:
1808 return "unknown type=" + mNextAppTransitionType;
1809 }
1810 }
1811
Craig Mautner164d4bb2012-11-26 13:51:23 -08001812 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001813 public void dump(PrintWriter pw, String prefix) {
1814 pw.print(prefix); pw.println(this);
1815 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001816 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001817 pw.print(prefix); pw.print("mNextAppTransitionType=");
1818 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001819 }
1820 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001821 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001822 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001823 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001824 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001825 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1826 pw.print(" mNextAppTransitionExit=0x");
1827 pw.println(Integer.toHexString(mNextAppTransitionExit));
1828 break;
Winson Chung044d5292014-11-06 11:05:19 -08001829 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001830 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001831 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001832 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001833 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1834 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001835 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001836 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001837 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001838 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001839 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001840 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001841 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001842 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001843 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001844 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001845 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001846 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001847 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1848 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001849 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001850 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1851 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1852 pw.println(mDefaultNextAppTransitionAnimationSpec);
1853 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1854 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001855 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1856 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001857 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001858 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001859 }
1860 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001861 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1862 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001863 }
1864 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001865
1866 public void setCurrentUser(int newUserId) {
1867 mCurrentUserId = newUserId;
1868 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001869
1870 /**
1871 * @return true if transition is not running and should not be skipped, false if transition is
1872 * already running
1873 */
1874 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent) {
1875 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
1876 + " transit=" + appTransitionToString(transit)
1877 + " " + this
1878 + " alwaysKeepCurrent=" + alwaysKeepCurrent
1879 + " Callers=" + Debug.getCallers(3));
1880 if (!isTransitionSet() || mNextAppTransition == TRANSIT_NONE) {
1881 setAppTransition(transit);
1882 } else if (!alwaysKeepCurrent) {
1883 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
1884 // Opening a new task always supersedes a close for the anim.
1885 setAppTransition(transit);
1886 } else if (transit == TRANSIT_ACTIVITY_OPEN
1887 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
1888 // Opening a new activity always supersedes a close for the anim.
1889 setAppTransition(transit);
1890 }
1891 }
1892 boolean prepared = prepare();
1893 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001894 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
1895 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001896 }
1897 return prepared;
1898 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001899}