blob: 15a26913865887d16d23a9a933376972c238d7db [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,
Jorim Jaggi09072002016-03-25 16:48:42 -0700884 Bitmap thumbnailHeader, final int taskId, int orientation) {
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 Jaggi09072002016-03-25 16:48:42 -0700893 final float fromX;
894 final float fromY;
895 final float toX;
896 final float toY;
897 final float pivotX;
898 final float pivotY;
899 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
900 fromX = mTmpRect.left;
901 fromY = mTmpRect.top;
902
903 // For the curved translate animation to work, the pivot points needs to be at the
904 // same absolute position as the one from the real surface.
905 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
906 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
907 pivotX = mTmpRect.width() / 2;
908 pivotY = appRect.height() / 2 / scaleW;
909 } else {
910 pivotX = 0;
911 pivotY = 0;
912 fromX = mTmpRect.left;
913 fromY = mTmpRect.top;
914 toX = appRect.left;
915 toY = appRect.top;
916 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100917 final long duration = getAspectScaleDuration();
918 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -0700919 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700920 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +0100921 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100922 scale.setInterpolator(interpolator);
923 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800924 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100925 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
926 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
927 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
928 ? duration / 2
929 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100930 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
931 translate.setInterpolator(interpolator);
932 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -0700933
Jorim Jaggide63d442016-03-14 14:56:56 +0100934 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
935 mTmpToClipRect.set(appRect);
936
937 // Containing frame is in screen space, but we need the clip rect in the
938 // app space.
939 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100940 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
941 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +0100942
943 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +0100944 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
945 (int) (-contentInsets.top * scaleW),
946 (int) (-contentInsets.right * scaleW),
947 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +0100948 }
949
950 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100951 clipAnim.setInterpolator(interpolator);
952 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +0100953
Winson Chung399f6202014-03-19 10:47:20 -0700954 // This AnimationSet uses the Interpolators assigned above.
955 AnimationSet set = new AnimationSet(false);
956 set.addAnimation(scale);
957 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -0700958 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +0100959 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -0700960 a = set;
961 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700962 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +0100963 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100964 scale.setInterpolator(interpolator);
965 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -0700966 Animation alpha = new AlphaAnimation(0f, 1f);
967 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100968 alpha.setDuration(duration);
969 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
970 translate.setInterpolator(interpolator);
971 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -0700972
Winson Chunga4ccb862014-08-22 15:26:27 -0700973 // This AnimationSet uses the Interpolators assigned above.
974 AnimationSet set = new AnimationSet(false);
975 set.addAnimation(scale);
976 set.addAnimation(alpha);
977 set.addAnimation(translate);
978 a = set;
979
980 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700981 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +0100982 null);
Winson Chung399f6202014-03-19 10:47:20 -0700983 }
984
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100985 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
986
987 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +0100988 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100989 return new TranslateAnimation(fromX, toX, fromY, toY);
990 } else {
991 final Path path = createCurvedPath(fromX, toX, fromY, toY);
992 return new CurvedTranslateAnimation(path);
993 }
994 }
995
996 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
997 final Path path = new Path();
998 path.moveTo(fromX, fromY);
999 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1000 return path;
1001 }
1002
1003 private long getAspectScaleDuration() {
1004 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001005 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001006 } else {
1007 return THUMBNAIL_APP_TRANSITION_DURATION;
1008 }
1009 }
1010
1011 private Interpolator getAspectScaleInterpolator() {
1012 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1013 return mFastOutSlowInInterpolator;
1014 } else {
1015 return TOUCH_RESPONSE_INTERPOLATOR;
1016 }
1017 }
1018
Winson Chung399f6202014-03-19 10:47:20 -07001019 /**
1020 * This alternate animation is created when we are doing a thumbnail transition, for the
1021 * activity that is leaving, and the activity that is entering.
1022 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001023 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001024 int orientation, int transit, Rect containingFrame, Rect contentInsets,
1025 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001026 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001027 final int appWidth = containingFrame.width();
1028 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001029 getDefaultNextAppTransitionStartRect(mTmpRect);
1030 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001031 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001032 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001033 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winson21700932016-03-24 17:26:23 -07001034 final int thumbStartX = mTmpRect.left - containingFrame.left;
1035 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001036
1037 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001038 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1039 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1040 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1041 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001042 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001043 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001044 } else if (freeform) {
1045 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1046 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001047 } else {
Winson21700932016-03-24 17:26:23 -07001048 AnimationSet set = new AnimationSet(true);
1049
1050 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001051 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001052 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001053
1054 // Containing frame is in screen space, but we need the clip rect in the
1055 // app space.
1056 mTmpFromClipRect.offsetTo(0, 0);
1057 mTmpToClipRect.offsetTo(0, 0);
1058
1059 // Exclude insets region from the source clip.
1060 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001061 mNextAppTransitionInsets.set(contentInsets);
1062
Winson21700932016-03-24 17:26:23 -07001063 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
1064 // We scale the width and clip to the top/left square
Jorim Jaggic69bd222016-03-15 14:38:37 +01001065 // We scale the width and clip to the top/left square
1066 float scale = thumbWidth /
1067 (appWidth - contentInsets.left - contentInsets.right);
1068 int unscaledThumbHeight = (int) (thumbHeight / scale);
1069 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1070
1071 mNextAppTransitionInsets.set(contentInsets);
1072
Jorim Jaggi8448f332016-03-14 17:50:37 +01001073 Animation scaleAnim = new ScaleAnimation(
1074 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1075 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001076 containingFrame.width() / 2f,
1077 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001078 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001079 final float x = containingFrame.width() / 2f
1080 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001081 final float targetY = (mTmpRect.top - containingFrame.top);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001082 final float y = containingFrame.height() / 2f
1083 - containingFrame.height() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001084 final float startX = targetX - x;
1085 final float startY = targetY - y;
1086 Animation clipAnim = scaleUp
1087 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1088 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1089 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001090 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1091 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1092
Winson21700932016-03-24 17:26:23 -07001093 set.addAnimation(clipAnim);
1094 set.addAnimation(scaleAnim);
1095 set.addAnimation(translateAnim);
1096
1097 } else {
1098 // In landscape, we don't scale at all and only crop
1099 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1100 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1101
Jorim Jaggi8448f332016-03-14 17:50:37 +01001102 Animation clipAnim = scaleUp
1103 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1104 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1105 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001106 ? createCurvedMotion(thumbStartX, 0,
1107 thumbStartY - contentInsets.top, 0)
1108 : createCurvedMotion(0, thumbStartX, 0,
1109 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001110
1111 set.addAnimation(clipAnim);
1112 set.addAnimation(translateAnim);
1113 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001114 a = set;
Winson21700932016-03-24 17:26:23 -07001115 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001116 }
Winson Chung399f6202014-03-19 10:47:20 -07001117 break;
1118 }
1119 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001120 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001121 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001122 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001123 // activity.
1124 a = new AlphaAnimation(1, 0);
1125 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001126 a = new AlphaAnimation(1, 1);
1127 }
1128 break;
1129 }
1130 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001131 // Target app window during the scale down
1132 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1133 // Fade in the destination activity if we are animating from a wallpaper
1134 // activity.
1135 a = new AlphaAnimation(0, 1);
1136 } else {
1137 a = new AlphaAnimation(1, 1);
1138 }
Winson Chung399f6202014-03-19 10:47:20 -07001139 break;
1140 }
Winson Chung399f6202014-03-19 10:47:20 -07001141 default:
1142 throw new RuntimeException("Invalid thumbnail transition state");
1143 }
1144
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001145 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1146 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001147 }
1148
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001149 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1150 @Nullable Rect surfaceInsets, int taskId) {
1151 getNextAppTransitionStartRect(taskId, mTmpRect);
1152 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1153 true);
1154 }
1155
1156 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1157 @Nullable Rect surfaceInsets, int taskId) {
1158 getNextAppTransitionStartRect(taskId, mTmpRect);
1159 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1160 false);
1161 }
1162
1163 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1164 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1165 final float sourceWidth = sourceFrame.width();
1166 final float sourceHeight = sourceFrame.height();
1167 final float destWidth = destFrame.width();
1168 final float destHeight = destFrame.height();
1169 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1170 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001171 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001172 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001173 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001174 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001175 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1176 // We want the scaling to happen from the center of the surface. In order to achieve that,
1177 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001178 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1179 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1180 final ScaleAnimation scale = enter ?
1181 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1182 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1183 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1184 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1185 final int destHCenter = destFrame.left + destFrame.width() / 2;
1186 final int destVCenter = destFrame.top + destFrame.height() / 2;
1187 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1188 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1189 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1190 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001191 set.addAnimation(scale);
1192 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001193
1194 final IRemoteCallback callback = mAnimationFinishedCallback;
1195 if (callback != null) {
1196 set.setAnimationListener(new Animation.AnimationListener() {
1197 @Override
1198 public void onAnimationStart(Animation animation) { }
1199
1200 @Override
1201 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001202 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001203 }
1204
1205 @Override
1206 public void onAnimationRepeat(Animation animation) { }
1207 });
1208 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001209 return set;
1210 }
1211
Winson Chung399f6202014-03-19 10:47:20 -07001212 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001213 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001214 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001215 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001216 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
1217 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001218 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001219 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001220 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001221 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001222 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001223 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1224
1225 if (mNextAppTransitionScaleUp) {
1226 // Animation for the thumbnail zooming from its initial size to the full screen
1227 float scaleW = appWidth / thumbWidth;
1228 float scaleH = appHeight / thumbHeight;
1229 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001230 computePivot(mTmpRect.left, 1 / scaleW),
1231 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001232 scale.setInterpolator(mDecelerateInterpolator);
1233
1234 Animation alpha = new AlphaAnimation(1, 0);
1235 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1236
1237 // This AnimationSet uses the Interpolators assigned above.
1238 AnimationSet set = new AnimationSet(false);
1239 set.addAnimation(scale);
1240 set.addAnimation(alpha);
1241 a = set;
1242 } else {
1243 // Animation for the thumbnail zooming down from the full screen to its final size
1244 float scaleW = appWidth / thumbWidth;
1245 float scaleH = appHeight / thumbHeight;
1246 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001247 computePivot(mTmpRect.left, 1 / scaleW),
1248 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001249 }
1250
1251 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1252 }
1253
1254 /**
Winson Chung399f6202014-03-19 10:47:20 -07001255 * This animation is created when we are doing a thumbnail transition, for the activity that is
1256 * leaving, and the activity that is entering.
1257 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001258 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1259 int transit, int taskId) {
1260 final int appWidth = containingFrame.width();
1261 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001262 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001263 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001264 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001265 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001266 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001267 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001268 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1269
1270 switch (thumbTransitState) {
1271 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1272 // Entering app scales up with the thumbnail
1273 float scaleW = thumbWidth / appWidth;
1274 float scaleH = thumbHeight / appHeight;
1275 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001276 computePivot(mTmpRect.left, scaleW),
1277 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001278 break;
1279 }
1280 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1281 // Exiting app while the thumbnail is scaling up should fade or stay in place
1282 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1283 // Fade out while bringing up selected activity. This keeps the
1284 // current activity from showing through a launching wallpaper
1285 // activity.
1286 a = new AlphaAnimation(1, 0);
1287 } else {
1288 // noop animation
1289 a = new AlphaAnimation(1, 1);
1290 }
1291 break;
1292 }
1293 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1294 // Entering the other app, it should just be visible while we scale the thumbnail
1295 // down above it
1296 a = new AlphaAnimation(1, 1);
1297 break;
1298 }
1299 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1300 // Exiting the current app, the app should scale down with the thumbnail
1301 float scaleW = thumbWidth / appWidth;
1302 float scaleH = thumbHeight / appHeight;
1303 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001304 computePivot(mTmpRect.left, scaleW),
1305 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001306
1307 Animation alpha = new AlphaAnimation(1, 0);
1308
1309 AnimationSet set = new AnimationSet(true);
1310 set.addAnimation(scale);
1311 set.addAnimation(alpha);
1312 set.setZAdjustment(Animation.ZORDER_TOP);
1313 a = set;
1314 break;
1315 }
1316 default:
1317 throw new RuntimeException("Invalid thumbnail transition state");
1318 }
1319
1320 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1321 }
1322
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001323 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001324 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1325 final int left = mTmpFromClipRect.left;
1326 final int top = mTmpFromClipRect.top;
1327 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001328 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1329 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001330 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001331 float fromWidth = mTmpFromClipRect.width();
1332 float toWidth = mTmpToClipRect.width();
1333 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001334 // While the window might span the whole display, the actual content will be cropped to the
1335 // system decoration frame, for example when the window is docked. We need to take into
1336 // account the visible height when constructing the animation.
1337 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1338 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001339 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1340 // The final window is larger in both dimensions than current window (e.g. we are
1341 // maximizing), so we can simply unclip the new window and there will be no disappearing
1342 // frame.
1343 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1344 } else {
1345 // The disappearing window has one larger dimension. We need to apply scaling, so the
1346 // first frame of the entry animation matches the old window.
1347 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001348 // We might not be going exactly full screen, but instead be aligned under the status
1349 // bar using cropping. We still need to account for the cropped part, which will also
1350 // be scaled.
1351 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001352 }
1353
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001354 // We animate the translation from the old position of the removed window, to the new
1355 // position of the added window. The latter might not be full screen, for example docked for
1356 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001357 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001358 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001359 set.addAnimation(translate);
1360 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001361 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001362 return set;
1363 }
1364
Jorim Jaggic554b772015-06-04 16:07:57 -07001365 /**
1366 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1367 * frame of the transition doesn't change the visuals on screen, so we can start
1368 * directly with the second one
1369 */
1370 boolean canSkipFirstFrame() {
1371 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1372 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
1373 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1374 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001375
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001376 /**
1377 *
1378 * @param frame These are the bounds of the window when it finishes the animation. This is where
1379 * the animation must usually finish in entrance animation, as the next frame will
1380 * display the window at these coordinates. In case of exit animation, this is
1381 * where the animation must start, as the frame before the animation is displaying
1382 * the window at these bounds.
1383 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1384 * window might be obscured, usually by the system windows (status bar and
1385 * navigation bar) and we use content insets to convey that information. This
1386 * usually affects the animation aspects vertically, as the system decoration is
1387 * at the top and the bottom. For example when we animate from full screen to
1388 * recents, we want to exclude the covered parts, because they won't match the
1389 * thumbnail after the last frame is executed.
1390 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1391 * know about this to make the animation frames match. We currently use
1392 * this for freeform windows, which have larger surfaces to display
1393 * shadows. When we animate them from recents, we want to match the content
1394 * to the recents thumbnail and hence need to account for the surface being
1395 * bigger.
1396 */
Craig Mautner164d4bb2012-11-26 13:51:23 -08001397 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001398 int orientation, Rect frame, Rect displayFrame, Rect insets,
1399 @Nullable Rect surfaceInsets, boolean isVoiceInteraction, boolean freeform,
1400 int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001401 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001402 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
1403 || transit == TRANSIT_TASK_OPEN
1404 || transit == TRANSIT_TASK_TO_FRONT)) {
1405 a = loadAnimationRes(lp, enter
1406 ? com.android.internal.R.anim.voice_activity_open_enter
1407 : com.android.internal.R.anim.voice_activity_open_exit);
1408 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1409 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001410 + " anim=" + a + " transit=" + appTransitionToString(transit)
1411 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001412 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1413 || transit == TRANSIT_TASK_CLOSE
1414 || transit == TRANSIT_TASK_TO_BACK)) {
1415 a = loadAnimationRes(lp, enter
1416 ? com.android.internal.R.anim.voice_activity_close_enter
1417 : com.android.internal.R.anim.voice_activity_close_exit);
1418 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1419 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001420 + " anim=" + a + " transit=" + appTransitionToString(transit)
1421 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001422 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001423 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001424 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1425 "applyAnimation:"
1426 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1427 + " transit=" + appTransitionToString(transit)
1428 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001429 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1430 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001431 mNextAppTransitionEnter : mNextAppTransitionExit);
1432 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1433 "applyAnimation:"
1434 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001435 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001436 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001437 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1438 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1439 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1440 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001441 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1442 + " transit=" + appTransitionToString(transit)
1443 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001444 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001445 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001446 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1447 "applyAnimation:"
1448 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001449 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001450 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001451 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001452 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001453 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1454 "applyAnimation:"
1455 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001456 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001457 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001458 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1459 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001460 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001461 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001462 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001463 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001464 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1465 String animName = mNextAppTransitionScaleUp ?
1466 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1467 Slog.v(TAG, "applyAnimation:"
1468 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001469 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001470 + " Callers=" + Debug.getCallers(3));
1471 }
1472 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1473 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1474 mNextAppTransitionScaleUp =
1475 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1476 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001477 getThumbnailTransitionState(enter), orientation, transit, frame,
1478 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001479 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1480 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001481 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001482 Slog.v(TAG, "applyAnimation:"
1483 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001484 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001485 + " Callers=" + Debug.getCallers(3));
1486 }
1487 } else {
1488 int animAttr = 0;
1489 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001490 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001491 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001492 ? WindowAnimation_activityOpenEnterAnimation
1493 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001494 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001495 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001496 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001497 ? WindowAnimation_activityCloseEnterAnimation
1498 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001499 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001500 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001501 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001502 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001503 ? WindowAnimation_taskOpenEnterAnimation
1504 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001505 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001506 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001507 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001508 ? WindowAnimation_taskCloseEnterAnimation
1509 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001510 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001511 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001512 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001513 ? WindowAnimation_taskToFrontEnterAnimation
1514 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001515 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001516 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001517 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001518 ? WindowAnimation_taskToBackEnterAnimation
1519 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001520 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001521 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001522 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001523 ? WindowAnimation_wallpaperOpenEnterAnimation
1524 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001525 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001526 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001527 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001528 ? WindowAnimation_wallpaperCloseEnterAnimation
1529 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001530 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001531 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001532 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001533 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1534 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001535 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001536 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001537 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001538 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1539 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001540 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001541 case TRANSIT_TASK_OPEN_BEHIND:
1542 animAttr = enter
1543 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001544 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001545 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001546 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001547 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1548 "applyAnimation:"
1549 + " anim=" + a
1550 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001551 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001552 + " Callers=" + Debug.getCallers(3));
1553 }
1554 return a;
1555 }
1556
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001557 int getAppStackClipMode() {
1558 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001559 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001560 ? STACK_CLIP_NONE
1561 : STACK_CLIP_AFTER_ANIM;
1562 }
1563
Craig Mautner164d4bb2012-11-26 13:51:23 -08001564 void postAnimationCallback() {
1565 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001566 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1567 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001568 mNextAppTransitionCallback = null;
1569 }
1570 }
1571
1572 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001573 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001574 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001575 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001576 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001577 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001578 mNextAppTransitionEnter = enterAnim;
1579 mNextAppTransitionExit = exitAnim;
1580 postAnimationCallback();
1581 mNextAppTransitionCallback = startedCallback;
1582 } else {
1583 postAnimationCallback();
1584 }
1585 }
1586
1587 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001588 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001589 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001590 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001591 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001592 putDefaultNextAppTransitionCoordinates(startX, startY, startX + startWidth,
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001593 startY + startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001594 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001595 }
1596 }
1597
Chet Haase10e23ab2015-02-11 15:08:38 -08001598 void overridePendingAppTransitionClipReveal(int startX, int startY,
1599 int startWidth, int startHeight) {
1600 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001601 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001602 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001603 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001604 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001605 }
1606 }
1607
Craig Mautner164d4bb2012-11-26 13:51:23 -08001608 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1609 IRemoteCallback startedCallback, boolean scaleUp) {
1610 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001611 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001612 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1613 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001614 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001615 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001616 postAnimationCallback();
1617 mNextAppTransitionCallback = startedCallback;
1618 } else {
1619 postAnimationCallback();
1620 }
1621 }
1622
Winson Chunga4ccb862014-08-22 15:26:27 -07001623 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001624 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001625 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001626 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001627 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1628 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001629 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001630 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1631 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001632 postAnimationCallback();
1633 mNextAppTransitionCallback = startedCallback;
1634 } else {
1635 postAnimationCallback();
1636 }
1637 }
1638
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001639 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001640 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1641 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001642 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001643 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001644 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1645 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001646 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001647 if (specs != null) {
1648 for (int i = 0; i < specs.length; i++) {
1649 AppTransitionAnimationSpec spec = specs[i];
1650 if (spec != null) {
1651 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1652 if (i == 0) {
1653 // In full screen mode, the transition code depends on the default spec
1654 // to be set.
1655 Rect rect = spec.rect;
1656 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Filip Gruszczynskie3264d82015-11-20 17:10:04 -08001657 rect.width(), rect.height(), spec.bitmap);
Jorim Jaggi43102412015-11-11 16:28:37 +01001658 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001659 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001660 }
1661 }
1662 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001663 mNextAppTransitionCallback = onAnimationStartedCallback;
1664 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001665 } else {
1666 postAnimationCallback();
1667 }
1668 }
1669
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001670 void overridePendingAppTransitionMultiThumbFuture(
1671 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1672 boolean scaleUp) {
1673 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001674 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001675 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1676 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001677 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1678 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001679 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001680 }
1681 }
1682
Winson Chung044d5292014-11-06 11:05:19 -08001683 void overrideInPlaceAppTransition(String packageName, int anim) {
1684 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001685 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001686 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1687 mNextAppTransitionPackage = packageName;
1688 mNextAppTransitionInPlace = anim;
1689 } else {
1690 postAnimationCallback();
1691 }
1692 }
1693
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001694 /**
1695 * If a future is set for the app transition specs, fetch it in another thread.
1696 */
1697 private void fetchAppTransitionSpecsFromFuture() {
1698 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1699 mNextAppTransitionAnimationsSpecsPending = true;
1700 final IAppTransitionAnimationSpecsFuture future
1701 = mNextAppTransitionAnimationsSpecsFuture;
1702 mNextAppTransitionAnimationsSpecsFuture = null;
1703 mDefaultExecutor.execute(new Runnable() {
1704 @Override
1705 public void run() {
1706 AppTransitionAnimationSpec[] specs = null;
1707 try {
1708 specs = future.get();
1709 } catch (RemoteException e) {
1710 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1711 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001712 synchronized (mService.mWindowMap) {
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001713 mNextAppTransitionAnimationsSpecsPending = false;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001714 overridePendingAppTransitionMultiThumb(specs,
1715 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1716 mNextAppTransitionScaleUp);
1717 mNextAppTransitionFutureCallback = null;
Filip Gruszczynski96daf322015-11-18 18:01:27 -08001718 if (specs != null) {
1719 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1720 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001721 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001722 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001723 }
1724 });
1725 }
1726 }
1727
Craig Mautner164d4bb2012-11-26 13:51:23 -08001728 @Override
1729 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001730 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001731 }
1732
Craig Mautner4b71aa12012-12-27 17:20:01 -08001733 /**
1734 * Returns the human readable name of a window transition.
1735 *
1736 * @param transition The window transition.
1737 * @return The transition symbolic name.
1738 */
1739 public static String appTransitionToString(int transition) {
1740 switch (transition) {
1741 case TRANSIT_UNSET: {
1742 return "TRANSIT_UNSET";
1743 }
1744 case TRANSIT_NONE: {
1745 return "TRANSIT_NONE";
1746 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001747 case TRANSIT_ACTIVITY_OPEN: {
1748 return "TRANSIT_ACTIVITY_OPEN";
1749 }
1750 case TRANSIT_ACTIVITY_CLOSE: {
1751 return "TRANSIT_ACTIVITY_CLOSE";
1752 }
1753 case TRANSIT_TASK_OPEN: {
1754 return "TRANSIT_TASK_OPEN";
1755 }
1756 case TRANSIT_TASK_CLOSE: {
1757 return "TRANSIT_TASK_CLOSE";
1758 }
1759 case TRANSIT_TASK_TO_FRONT: {
1760 return "TRANSIT_TASK_TO_FRONT";
1761 }
1762 case TRANSIT_TASK_TO_BACK: {
1763 return "TRANSIT_TASK_TO_BACK";
1764 }
1765 case TRANSIT_WALLPAPER_CLOSE: {
1766 return "TRANSIT_WALLPAPER_CLOSE";
1767 }
1768 case TRANSIT_WALLPAPER_OPEN: {
1769 return "TRANSIT_WALLPAPER_OPEN";
1770 }
1771 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1772 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1773 }
1774 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1775 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1776 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001777 case TRANSIT_TASK_OPEN_BEHIND: {
1778 return "TRANSIT_TASK_OPEN_BEHIND";
1779 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001780 case TRANSIT_ACTIVITY_RELAUNCH: {
1781 return "TRANSIT_ACTIVITY_RELAUNCH";
1782 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001783 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1784 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1785 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001786 default: {
1787 return "<UNKNOWN>";
1788 }
1789 }
1790 }
1791
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001792 private String appStateToString() {
1793 switch (mAppTransitionState) {
1794 case APP_STATE_IDLE:
1795 return "APP_STATE_IDLE";
1796 case APP_STATE_READY:
1797 return "APP_STATE_READY";
1798 case APP_STATE_RUNNING:
1799 return "APP_STATE_RUNNING";
1800 case APP_STATE_TIMEOUT:
1801 return "APP_STATE_TIMEOUT";
1802 default:
1803 return "unknown state=" + mAppTransitionState;
1804 }
1805 }
1806
1807 private String transitTypeToString() {
1808 switch (mNextAppTransitionType) {
1809 case NEXT_TRANSIT_TYPE_NONE:
1810 return "NEXT_TRANSIT_TYPE_NONE";
1811 case NEXT_TRANSIT_TYPE_CUSTOM:
1812 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001813 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1814 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001815 case NEXT_TRANSIT_TYPE_SCALE_UP:
1816 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1817 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1818 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1819 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1820 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001821 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1822 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1823 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1824 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001825 default:
1826 return "unknown type=" + mNextAppTransitionType;
1827 }
1828 }
1829
Craig Mautner164d4bb2012-11-26 13:51:23 -08001830 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001831 public void dump(PrintWriter pw, String prefix) {
1832 pw.print(prefix); pw.println(this);
1833 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001834 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001835 pw.print(prefix); pw.print("mNextAppTransitionType=");
1836 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001837 }
1838 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001839 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001840 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001841 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001842 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001843 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1844 pw.print(" mNextAppTransitionExit=0x");
1845 pw.println(Integer.toHexString(mNextAppTransitionExit));
1846 break;
Winson Chung044d5292014-11-06 11:05:19 -08001847 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001848 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001849 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001850 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001851 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1852 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001853 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001854 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001855 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001856 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001857 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001858 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001859 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001860 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001861 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001862 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001863 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001864 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001865 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1866 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001867 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001868 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1869 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1870 pw.println(mDefaultNextAppTransitionAnimationSpec);
1871 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1872 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001873 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1874 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001875 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001876 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001877 }
1878 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001879 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1880 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001881 }
1882 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001883
1884 public void setCurrentUser(int newUserId) {
1885 mCurrentUserId = newUserId;
1886 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001887
1888 /**
1889 * @return true if transition is not running and should not be skipped, false if transition is
1890 * already running
1891 */
1892 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent) {
1893 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
1894 + " transit=" + appTransitionToString(transit)
1895 + " " + this
1896 + " alwaysKeepCurrent=" + alwaysKeepCurrent
1897 + " Callers=" + Debug.getCallers(3));
1898 if (!isTransitionSet() || mNextAppTransition == TRANSIT_NONE) {
1899 setAppTransition(transit);
1900 } else if (!alwaysKeepCurrent) {
1901 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
1902 // Opening a new task always supersedes a close for the anim.
1903 setAppTransition(transit);
1904 } else if (transit == TRANSIT_ACTIVITY_OPEN
1905 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
1906 // Opening a new activity always supersedes a close for the anim.
1907 setAppTransition(transit);
1908 }
1909 }
1910 boolean prepared = prepare();
1911 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001912 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
1913 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001914 }
1915 return prepared;
1916 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001917}