blob: ba9e6404cf662d7d5210175c5d3b4be5388ba463 [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;
Filip Gruszczynski82861362015-10-16 14:21:09 -070046
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070047import android.annotation.Nullable;
Craig Mautner164d4bb2012-11-26 13:51:23 -080048import android.content.Context;
49import android.graphics.Bitmap;
Winson Chung399f6202014-03-19 10:47:20 -070050import android.graphics.Rect;
Craig Mautner164d4bb2012-11-26 13:51:23 -080051import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010052import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080053import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010054import android.os.RemoteException;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080055import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080056import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070057import android.util.SparseArray;
58import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010059import android.view.IAppTransitionAnimationSpecsFuture;
Craig Mautner164d4bb2012-11-26 13:51:23 -080060import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080061import android.view.animation.AlphaAnimation;
62import android.view.animation.Animation;
63import android.view.animation.AnimationSet;
64import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070065import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080066import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070067import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080068import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070069import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070070
Craig Mautner164d4bb2012-11-26 13:51:23 -080071import com.android.internal.util.DumpUtils.Dump;
72import com.android.server.AttributeCache;
73import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -080074import com.android.server.wm.animation.ClipRectLRAnimation;
75import com.android.server.wm.animation.ClipRectTBAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080076
77import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010078import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010079import java.util.concurrent.ExecutorService;
80import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -080081
Craig Mautner164d4bb2012-11-26 13:51:23 -080082// State management of app transitions. When we are preparing for a
83// transition, mNextAppTransition will be the kind of transition to
84// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
85// mOpeningApps and mClosingApps are the lists of tokens that will be
86// made visible or hidden at the next transition.
87public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080088 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070089 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080090
Craig Mautner4b71aa12012-12-27 17:20:01 -080091 /** Not set up for a transition. */
92 public static final int TRANSIT_UNSET = -1;
93 /** No animation for transition. */
94 public static final int TRANSIT_NONE = 0;
95 /** 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 -070096 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -080097 /** The window in the top-most activity is being closed to reveal the
98 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -070099 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800100 /** A window in a new task is being opened on top of an existing one
101 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700102 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800103 /** A window in the top-most activity is being closed to reveal the
104 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700105 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800106 /** A window in an existing task is being displayed on top of an existing one
107 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700108 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800109 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700110 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800111 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
112 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700113 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800114 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
115 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700116 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800117 /** A window in a new activity is being opened on top of an existing one, and both are on top
118 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700119 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800120 /** The window in the top-most activity is being closed to reveal the previous activity, and
121 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700122 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
123 /** A window in a new task is being opened behind an existing one in another activity's task.
124 * The new window will show briefly and then be gone. */
125 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800126 /** A window in a task is being animated in-place. */
127 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700128 /** An activity is being relaunched (e.g. due to configuration change). */
129 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800130
Winson Chunga4ccb862014-08-22 15:26:27 -0700131 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700132 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800133 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700134 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800135
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800136 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800137
138 /** Interpolator to be used for animations that respond directly to a touch */
139 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
140 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
141
142 /**
143 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
144 * involved, to make it more understandable.
145 */
146 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700147 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
148 private static final int THUMBNAIL_APP_TRANSITION_ALPHA_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700149 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800150
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800151 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800152 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800153
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800154 private int mNextAppTransition = TRANSIT_UNSET;
155
156 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
157 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
158 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
159 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
160 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700161 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
162 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800163 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800164 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800165 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
166
Winson Chung399f6202014-03-19 10:47:20 -0700167 // These are the possible states for the enter/exit activities during a thumbnail transition
168 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
169 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
170 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
171 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
172
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800173 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800174 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800175 private boolean mNextAppTransitionScaleUp;
176 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100177 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700178 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800179 private int mNextAppTransitionEnter;
180 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800181 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700182
183 // Keyed by task id.
184 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
185 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100186 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
187 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700188 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
189
Winson Chunga4ccb862014-08-22 15:26:27 -0700190 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800191
Winson Chung2820c452014-04-15 15:34:44 -0700192 private Rect mTmpFromClipRect = new Rect();
193 private Rect mTmpToClipRect = new Rect();
194
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700195 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700196
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800197 private final static int APP_STATE_IDLE = 0;
198 private final static int APP_STATE_READY = 1;
199 private final static int APP_STATE_RUNNING = 2;
200 private final static int APP_STATE_TIMEOUT = 3;
201 private int mAppTransitionState = APP_STATE_IDLE;
202
203 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800204 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700205 private final Interpolator mThumbnailFadeInInterpolator;
206 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800207 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700208 private final Interpolator mFastOutLinearInInterpolator;
209 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
210
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700211 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800212
Amith Yamasani4befbec2013-07-10 16:18:01 -0700213 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800214 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700215
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100216 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100217 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100218
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800219 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800220 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800221 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800222 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
223 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700224 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
225 com.android.internal.R.interpolator.fast_out_linear_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800226 mConfigShortAnimTime = context.getResources().getInteger(
227 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800228 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
229 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700230 mThumbnailFadeInInterpolator = new Interpolator() {
231 @Override
232 public float getInterpolation(float input) {
233 // Linear response for first fraction, then complete after that.
234 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
235 return 0f;
236 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700237 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700238 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700239 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700240 }
241 };
242 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800243 @Override
244 public float getInterpolation(float input) {
245 // Linear response for first fraction, then complete after that.
246 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700247 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
248 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800249 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700250 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800251 }
252 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700253 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
254 * mContext.getResources().getDisplayMetrics().density);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800255 }
256
257 boolean isTransitionSet() {
258 return mNextAppTransition != TRANSIT_UNSET;
259 }
260
Craig Mautner164d4bb2012-11-26 13:51:23 -0800261 boolean isTransitionEqual(int transit) {
262 return mNextAppTransition == transit;
263 }
264
265 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800266 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800267 }
268
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700269 private void setAppTransition(int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800270 mNextAppTransition = transit;
271 }
272
273 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800274 return mAppTransitionState == APP_STATE_READY
275 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800276 }
277
Craig Mautnerae446592012-12-06 19:05:05 -0800278 void setReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800279 mAppTransitionState = APP_STATE_READY;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100280 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800281 }
282
283 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800284 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800285 }
286
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800287 void setIdle() {
288 mAppTransitionState = APP_STATE_IDLE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800289 }
290
291 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800292 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800293 }
294
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800295 void setTimeout() {
296 mAppTransitionState = APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800297 }
298
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700299 Bitmap getAppTransitionThumbnailHeader(int taskId) {
300 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800301 if (spec == null) {
302 spec = mDefaultNextAppTransitionAnimationSpec;
303 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700304 return spec != null ? spec.bitmap : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800305 }
306
Winson Chunga4ccb862014-08-22 15:26:27 -0700307 /** Returns whether the next thumbnail transition is aspect scaled up. */
308 boolean isNextThumbnailTransitionAspectScaled() {
309 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
310 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
311 }
312
313 /** Returns whether the next thumbnail transition is scaling up. */
314 boolean isNextThumbnailTransitionScaleUp() {
315 return mNextAppTransitionScaleUp;
316 }
317
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800318 boolean isNextAppTransitionThumbnailUp() {
319 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
320 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
321 }
322
323 boolean isNextAppTransitionThumbnailDown() {
324 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
325 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
326 }
327
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100328 /**
329 * @return true if and only if we are currently fetching app transition specs from the future
330 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
331 */
332 boolean isFetchingAppTransitionsSpecs() {
333 return mNextAppTransitionAnimationsSpecsPending;
334 }
335
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700336 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800337 if (!isRunning()) {
338 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100339 notifyAppTransitionPendingLocked();
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700340 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800341 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700342 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800343 }
344
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800345 void goodToGo(AppWindowAnimator topOpeningAppAnimator, AppWindowAnimator topClosingAppAnimator,
346 ArraySet<AppWindowToken> openingApps, ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800347 mNextAppTransition = TRANSIT_UNSET;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800348 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100349 notifyAppTransitionStartingLocked(
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800350 topOpeningAppAnimator != null ? topOpeningAppAnimator.mAppToken.token : null,
351 topClosingAppAnimator != null ? topClosingAppAnimator.mAppToken.token : null,
352 topOpeningAppAnimator != null ? topOpeningAppAnimator.animation : null,
353 topClosingAppAnimator != null ? topClosingAppAnimator.animation : null);
354 mService.getDefaultDisplayContentLocked().getDockedDividerController()
355 .notifyAppTransitionStarting(openingApps, closingApps);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800356 }
357
358 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800359 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800360 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700361 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi65193992015-11-23 16:49:59 -0800362 mNextAppTransitionAnimationsSpecsFuture = null;
363 mDefaultNextAppTransitionAnimationSpec = null;
364 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800365 }
366
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800367 void freeze() {
368 setAppTransition(AppTransition.TRANSIT_UNSET);
369 clear();
370 setReady();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100371 notifyAppTransitionCancelledLocked();
372 }
373
374 void registerListenerLocked(AppTransitionListener listener) {
375 mListeners.add(listener);
376 }
377
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700378 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100379 for (int i = 0; i < mListeners.size(); i++) {
380 mListeners.get(i).onAppTransitionFinishedLocked(token);
381 }
382 }
383
384 private void notifyAppTransitionPendingLocked() {
385 for (int i = 0; i < mListeners.size(); i++) {
386 mListeners.get(i).onAppTransitionPendingLocked();
387 }
388 }
389
390 private void notifyAppTransitionCancelledLocked() {
391 for (int i = 0; i < mListeners.size(); i++) {
392 mListeners.get(i).onAppTransitionCancelledLocked();
393 }
394 }
395
396 private void notifyAppTransitionStartingLocked(IBinder openToken,
397 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
398 for (int i = 0; i < mListeners.size(); i++) {
399 mListeners.get(i).onAppTransitionStartingLocked(openToken, closeToken, openAnimation,
400 closeAnimation);
401 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800402 }
403
Craig Mautner164d4bb2012-11-26 13:51:23 -0800404 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
405 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
406 + (lp != null ? lp.packageName : null)
407 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
408 if (lp != null && lp.windowAnimations != 0) {
409 // If this is a system resource, don't try to load it from the
410 // application resources. It is nice to avoid loading application
411 // resources if we can.
412 String packageName = lp.packageName != null ? lp.packageName : "android";
413 int resId = lp.windowAnimations;
414 if ((resId&0xFF000000) == 0x01000000) {
415 packageName = "android";
416 }
417 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
418 + packageName);
419 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700420 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800421 }
422 return null;
423 }
424
425 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
426 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
427 + packageName + " resId=0x" + Integer.toHexString(resId));
428 if (packageName != null) {
429 if ((resId&0xFF000000) == 0x01000000) {
430 packageName = "android";
431 }
432 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
433 + packageName);
434 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700435 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800436 }
437 return null;
438 }
439
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700440 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800441 int anim = 0;
442 Context context = mContext;
443 if (animAttr >= 0) {
444 AttributeCache.Entry ent = getCachedAnimations(lp);
445 if (ent != null) {
446 context = ent.context;
447 anim = ent.array.getResourceId(animAttr, 0);
448 }
449 }
450 if (anim != 0) {
451 return AnimationUtils.loadAnimation(context, anim);
452 }
453 return null;
454 }
455
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700456 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
457 Context context = mContext;
458 if (resId >= 0) {
459 AttributeCache.Entry ent = getCachedAnimations(lp);
460 if (ent != null) {
461 context = ent.context;
462 }
463 return AnimationUtils.loadAnimation(context, resId);
464 }
465 return null;
466 }
467
468 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800469 int anim = 0;
470 Context context = mContext;
471 if (resId >= 0) {
472 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
473 if (ent != null) {
474 context = ent.context;
475 anim = resId;
476 }
477 }
478 if (anim != 0) {
479 return AnimationUtils.loadAnimation(context, anim);
480 }
481 return null;
482 }
483
Craig Mautner164d4bb2012-11-26 13:51:23 -0800484 /**
485 * Compute the pivot point for an animation that is scaling from a small
486 * rect on screen to a larger rect. The pivot point varies depending on
487 * the distance between the inner and outer edges on both sides. This
488 * function computes the pivot point for one dimension.
489 * @param startPos Offset from left/top edge of outer rectangle to
490 * left/top edge of inner rectangle.
491 * @param finalScale The scaling factor between the size of the outer
492 * and inner rectangles.
493 */
494 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800495
496 /*
497 Theorem of intercepting lines:
498
499 + + +-----------------------------------------------+
500 | | | |
501 | | | |
502 | | | |
503 | | | |
504 x | y | | |
505 | | | |
506 | | | |
507 | | | |
508 | | | |
509 | + | +--------------------+ |
510 | | | | |
511 | | | | |
512 | | | | |
513 | | | | |
514 | | | | |
515 | | | | |
516 | | | | |
517 | | | | |
518 | | | | |
519 | | | | |
520 | | | | |
521 | | | | |
522 | | | | |
523 | | | | |
524 | | | | |
525 | | | | |
526 | | | | |
527 | | +--------------------+ |
528 | | |
529 | | |
530 | | |
531 | | |
532 | | |
533 | | |
534 | | |
535 | +-----------------------------------------------+
536 |
537 |
538 |
539 |
540 |
541 |
542 |
543 |
544 |
545 + ++
546 p ++
547
548 scale = (x - y) / x
549 <=> x = -y / (scale - 1)
550 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800551 final float denom = finalScale-1;
552 if (Math.abs(denom) < .0001f) {
553 return startPos;
554 }
555 return -startPos / denom;
556 }
557
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700558 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
559 Rect containingFrame) {
560 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700561 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700562 final int appWidth = containingFrame.width();
563 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800564 if (enter) {
565 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700566 float scaleW = mTmpRect.width() / (float) appWidth;
567 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800568 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700569 computePivot(mTmpRect.left, scaleW),
570 computePivot(mTmpRect.right, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800571 scale.setInterpolator(mDecelerateInterpolator);
572
Craig Mautner164d4bb2012-11-26 13:51:23 -0800573 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700574 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800575
576 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800577 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800578 set.addAnimation(alpha);
579 set.setDetachWallpaper(true);
580 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800581 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
582 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800583 // If we are on top of the wallpaper, we need an animation that
584 // correctly handles the wallpaper staying static behind all of
585 // the animated elements. To do this, will just have the existing
586 // element fade out.
587 a = new AlphaAnimation(1, 0);
588 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800589 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800590 // For normal animations, the exiting element just holds in place.
591 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800592 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800593
594 // Pick the desired duration. If this is an inter-activity transition,
595 // it is the standard duration for that. Otherwise we use the longer
596 // task transition duration.
597 final long duration;
598 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800599 case TRANSIT_ACTIVITY_OPEN:
600 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800601 duration = mConfigShortAnimTime;
602 break;
603 default:
604 duration = DEFAULT_APP_TRANSITION_DURATION;
605 break;
606 }
607 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800608 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800609 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800610 a.initialize(appWidth, appHeight, appWidth, appHeight);
611 return a;
612 }
613
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700614 private void getDefaultNextAppTransitionStartRect(Rect rect) {
615 if (mDefaultNextAppTransitionAnimationSpec == null ||
616 mDefaultNextAppTransitionAnimationSpec.rect == null) {
617 Slog.wtf(TAG, "Starting rect for app requested, but none available", new Throwable());
618 rect.setEmpty();
619 } else {
620 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
621 }
622 }
623
624 void getNextAppTransitionStartRect(int taskId, Rect rect) {
625 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800626 if (spec == null) {
627 spec = mDefaultNextAppTransitionAnimationSpec;
628 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700629 if (spec == null || spec.rect == null) {
630 Slog.wtf(TAG, "Starting rect for task: " + taskId + " requested, but not available",
631 new Throwable());
632 rect.setEmpty();
633 } else {
634 rect.set(spec.rect);
635 }
636 }
637
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800638 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
639 Bitmap bitmap) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700640 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800641 bitmap, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700642 }
643
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800644 long getLastClipRevealTransitionDuration() {
645 return mLastClipRevealTransitionDuration;
646 }
647
648 /**
649 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
650 * the start rect is outside of the target rect, and there is a lot of movement going on.
651 *
652 * @param cutOff whether the start rect was not fully contained by the end rect
653 * @param translationX the total translation the surface moves in x direction
654 * @param translationY the total translation the surfaces moves in y direction
655 * @param displayFrame our display frame
656 *
657 * @return the duration of the clip reveal animation, in milliseconds
658 */
659 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
660 float translationY, Rect displayFrame) {
661 if (!cutOff) {
662 return DEFAULT_APP_TRANSITION_DURATION;
663 }
664 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
665 Math.abs(translationY) / displayFrame.height());
666 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
667 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
668 }
669
670 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
671 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800672 final Animation anim;
673 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700674 final int appWidth = appFrame.width();
675 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800676
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700677 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700678 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700679 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700680
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700681 float t = 0f;
682 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800683 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700684 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800685 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
686 int translationX = 0;
687 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700688 int centerX = mTmpRect.centerX();
689 int centerY = mTmpRect.centerY();
690 int halfWidth = mTmpRect.width() / 2;
691 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800692 int clipStartX = centerX - halfWidth - appFrame.left;
693 int clipStartY = centerY - halfHeight - appFrame.top;
694 boolean cutOff = false;
695
696 // If the starting rectangle is fully or partially outside of the target rectangle, we
697 // need to start the clipping at the edge and then achieve the rest with translation
698 // and extending the clip rect from that edge.
699 if (appFrame.top > centerY - halfHeight) {
700 translationY = (centerY - halfHeight) - appFrame.top;
701 translationYCorrection = 0;
702 clipStartY = 0;
703 cutOff = true;
704 }
705 if (appFrame.left > centerX - halfWidth) {
706 translationX = (centerX - halfWidth) - appFrame.left;
707 clipStartX = 0;
708 cutOff = true;
709 }
710 if (appFrame.right < centerX + halfWidth) {
711 translationX = (centerX + halfWidth) - appFrame.right;
712 clipStartX = appWidth - mTmpRect.width();
713 cutOff = true;
714 }
715 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
716 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700717
718 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800719 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800720 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700721 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800722 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700723
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800724 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
725 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
726 : mLinearOutSlowInInterpolator);
727 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800728
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800729 Animation clipAnimTB = new ClipRectTBAnimation(
730 clipStartY, clipStartY + mTmpRect.height(),
731 0, appHeight,
732 translationYCorrection, 0,
733 mLinearOutSlowInInterpolator);
734 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
735 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800736
737 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800738 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700739 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800740 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700741 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800742
743 AnimationSet set = new AnimationSet(false);
744 set.addAnimation(clipAnimLR);
745 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700746 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800747 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700748 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800749 set.initialize(appWidth, appHeight, appWidth, appHeight);
750 anim = set;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800751 mLastClipRevealTransitionDuration = duration;
Chet Haase10e23ab2015-02-11 15:08:38 -0800752 } else {
753 final long duration;
754 switch (transit) {
755 case TRANSIT_ACTIVITY_OPEN:
756 case TRANSIT_ACTIVITY_CLOSE:
757 duration = mConfigShortAnimTime;
758 break;
759 default:
760 duration = DEFAULT_APP_TRANSITION_DURATION;
761 break;
762 }
763 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
764 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
765 // If we are on top of the wallpaper, we need an animation that
766 // correctly handles the wallpaper staying static behind all of
767 // the animated elements. To do this, will just have the existing
768 // element fade out.
769 anim = new AlphaAnimation(1, 0);
770 anim.setDetachWallpaper(true);
771 } else {
772 // For normal animations, the exiting element just holds in place.
773 anim = new AlphaAnimation(1, 1);
774 }
775 anim.setInterpolator(mDecelerateInterpolator);
776 anim.setDuration(duration);
777 anim.setFillAfter(true);
778 }
779 return anim;
780 }
781
Winson Chung399f6202014-03-19 10:47:20 -0700782 /**
783 * Prepares the specified animation with a standard duration, interpolator, etc.
784 */
Winson Chung5393dff2014-05-08 14:25:43 -0700785 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
786 int duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700787 if (duration > 0) {
788 a.setDuration(duration);
789 }
Winson Chung5393dff2014-05-08 14:25:43 -0700790 a.setFillAfter(true);
791 a.setInterpolator(interpolator);
792 a.initialize(appWidth, appHeight, appWidth, appHeight);
793 return a;
794 }
795
796 /**
797 * Prepares the specified animation with a standard duration, interpolator, etc.
798 */
Winson Chung399f6202014-03-19 10:47:20 -0700799 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800800 // Pick the desired duration. If this is an inter-activity transition,
801 // it is the standard duration for that. Otherwise we use the longer
802 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700803 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800804 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800805 case TRANSIT_ACTIVITY_OPEN:
806 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800807 duration = mConfigShortAnimTime;
808 break;
809 default:
810 duration = DEFAULT_APP_TRANSITION_DURATION;
811 break;
812 }
Winson Chung5393dff2014-05-08 14:25:43 -0700813 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
814 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800815 }
816
Winson Chung399f6202014-03-19 10:47:20 -0700817 /**
818 * Return the current thumbnail transition state.
819 */
820 int getThumbnailTransitionState(boolean enter) {
821 if (enter) {
822 if (mNextAppTransitionScaleUp) {
823 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
824 } else {
825 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
826 }
827 } else {
828 if (mNextAppTransitionScaleUp) {
829 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
830 } else {
831 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
832 }
833 }
834 }
835
836 /**
837 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700838 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700839 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700840 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, Bitmap thumbnailHeader,
841 final int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700842 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700843 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700844 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700845 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chung399f6202014-03-19 10:47:20 -0700846 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700847 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700848
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700849 float scaleW = appWidth / thumbWidth;
Winson Chunga4ccb862014-08-22 15:26:27 -0700850 float unscaledHeight = thumbHeight * scaleW;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700851 getNextAppTransitionStartRect(taskId, mTmpRect);
Filip Gruszczynski565a9df2016-01-22 11:10:42 -0800852 final float unscaledStartY = mTmpRect.top - (unscaledHeight - thumbHeight) / 2f;
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800853 final float toY = appRect.top + -unscaledStartY;
Winson Chung399f6202014-03-19 10:47:20 -0700854 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700855 // Animation up from the thumbnail to the full screen
856 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700857 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800858 scale.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700859 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800860 Animation alpha = new AlphaAnimation(1f, 0f);
Winson Chunga4ccb862014-08-22 15:26:27 -0700861 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
862 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700863 final float toX = appRect.left + appRect.width() / 2 -
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700864 (mTmpRect.left + thumbWidth / 2);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700865 Animation translate = new TranslateAnimation(0, toX, 0, toY);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800866 translate.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700867 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700868
869 // This AnimationSet uses the Interpolators assigned above.
870 AnimationSet set = new AnimationSet(false);
871 set.addAnimation(scale);
872 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -0700873 set.addAnimation(translate);
Winson Chung399f6202014-03-19 10:47:20 -0700874 a = set;
875 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700876 // Animation down from the full screen to the thumbnail
877 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700878 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800879 scale.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700880 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
881 Animation alpha = new AlphaAnimation(0f, 1f);
882 alpha.setInterpolator(mThumbnailFadeInInterpolator);
883 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
Filip Gruszczynski565a9df2016-01-22 11:10:42 -0800884 final float toX = appRect.left + appRect.width() / 2 -
885 (mTmpRect.left + thumbWidth / 2);
886 Animation translate = new TranslateAnimation(toX, 0, toY, 0);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800887 translate.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
Winson Chunga4ccb862014-08-22 15:26:27 -0700888 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700889
Winson Chunga4ccb862014-08-22 15:26:27 -0700890 // This AnimationSet uses the Interpolators assigned above.
891 AnimationSet set = new AnimationSet(false);
892 set.addAnimation(scale);
893 set.addAnimation(alpha);
894 set.addAnimation(translate);
895 a = set;
896
897 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700898 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800899 TOUCH_RESPONSE_INTERPOLATOR);
Winson Chung399f6202014-03-19 10:47:20 -0700900 }
901
902 /**
903 * This alternate animation is created when we are doing a thumbnail transition, for the
904 * activity that is leaving, and the activity that is entering.
905 */
Winson Chunga4ccb862014-08-22 15:26:27 -0700906 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700907 int orientation, int transit, Rect containingFrame, Rect contentInsets,
908 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700909 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700910 final int appWidth = containingFrame.width();
911 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700912 getDefaultNextAppTransitionStartRect(mTmpRect);
913 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700914 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700915 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -0700916 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
917
Winson Chung2820c452014-04-15 15:34:44 -0700918 // Used for the ENTER_SCALE_UP and EXIT_SCALE_DOWN transitions
919 float scale = 1f;
920 int scaledTopDecor = 0;
921
Winson Chung399f6202014-03-19 10:47:20 -0700922 switch (thumbTransitState) {
923 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700924 if (freeform) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700925 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700926 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -0700927 } else {
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700928 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700929 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800930
931 // Containing frame is in screen space, but we need the clip rect in the
932 // app space.
933 mTmpFromClipRect.offsetTo(0, 0);
934 mTmpToClipRect.offsetTo(0, 0);
935
936 // Exclude insets region from the source clip.
937 mTmpFromClipRect.inset(contentInsets);
938
939 // We scale the width and clip to the top/left square
940 scale = thumbWidth / (appWidth - contentInsets.left - contentInsets.right);
941 scaledTopDecor = (int) (scale * contentInsets.top);
942 int unscaledThumbHeight = (int) (thumbHeight / scale);
943 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700944
945 mNextAppTransitionInsets.set(contentInsets);
946
947 Animation scaleAnim = new ScaleAnimation(scale, 1, scale, 1,
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800948 computePivot(mTmpRect.left - containingFrame.left, scale),
949 computePivot(mTmpRect.top - containingFrame.top, scale));
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700950 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
951 Animation translateAnim = new TranslateAnimation(0, 0, -scaledTopDecor, 0);
952
953 AnimationSet set = new AnimationSet(true);
954 set.addAnimation(clipAnim);
955 set.addAnimation(scaleAnim);
956 set.addAnimation(translateAnim);
957 a = set;
Winson Chung2820c452014-04-15 15:34:44 -0700958 }
Winson Chung399f6202014-03-19 10:47:20 -0700959 break;
960 }
961 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700962 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -0700963 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700964 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -0700965 // activity.
966 a = new AlphaAnimation(1, 0);
967 } else {
Winson Chung399f6202014-03-19 10:47:20 -0700968 a = new AlphaAnimation(1, 1);
969 }
970 break;
971 }
972 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700973 // Target app window during the scale down
974 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
975 // Fade in the destination activity if we are animating from a wallpaper
976 // activity.
977 a = new AlphaAnimation(0, 1);
978 } else {
979 a = new AlphaAnimation(1, 1);
980 }
Winson Chung399f6202014-03-19 10:47:20 -0700981 break;
982 }
983 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700984 // App window scaling down from full screen
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700985 if (freeform) {
986 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
987 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -0700988 } else {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700989 mTmpFromClipRect.set(containingFrame);
990 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800991
992 // Containing frame is in screen space, but we need the clip rect in the
993 // app space.
994 mTmpFromClipRect.offsetTo(0, 0);
995 mTmpToClipRect.offsetTo(0, 0);
996
997 // Exclude insets region from the target clip.
998 mTmpToClipRect.inset(contentInsets);
999
1000 // We scale the width and clip to the top/left square
1001 scale = thumbWidth / (appWidth - contentInsets.left - contentInsets.right);
1002 scaledTopDecor = (int) (scale * contentInsets.top);
1003 int unscaledThumbHeight = (int) (thumbHeight / scale);
1004 mTmpToClipRect.bottom = mTmpToClipRect.top + unscaledThumbHeight;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001005
1006 mNextAppTransitionInsets.set(contentInsets);
1007
1008 Animation scaleAnim = new ScaleAnimation(1, scale, 1, scale,
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001009 computePivot(mTmpRect.left - containingFrame.left, scale),
1010 computePivot(mTmpRect.top - containingFrame.top, scale));
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001011 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
1012 Animation translateAnim = new TranslateAnimation(0, 0, 0, -scaledTopDecor);
1013
1014 AnimationSet set = new AnimationSet(true);
1015 set.addAnimation(clipAnim);
1016 set.addAnimation(scaleAnim);
1017 set.addAnimation(translateAnim);
1018
1019 a = set;
1020 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001021 }
Winson Chung399f6202014-03-19 10:47:20 -07001022 break;
1023 }
1024 default:
1025 throw new RuntimeException("Invalid thumbnail transition state");
1026 }
1027
Winson Chungab79fce2014-11-04 16:15:22 -08001028 int duration = Math.max(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION,
1029 THUMBNAIL_APP_TRANSITION_DURATION);
1030 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001031 TOUCH_RESPONSE_INTERPOLATOR);
Winson Chung399f6202014-03-19 10:47:20 -07001032 }
1033
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001034 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1035 @Nullable Rect surfaceInsets, int taskId) {
1036 getNextAppTransitionStartRect(taskId, mTmpRect);
1037 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1038 true);
1039 }
1040
1041 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1042 @Nullable Rect surfaceInsets, int taskId) {
1043 getNextAppTransitionStartRect(taskId, mTmpRect);
1044 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1045 false);
1046 }
1047
1048 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1049 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1050 final float sourceWidth = sourceFrame.width();
1051 final float sourceHeight = sourceFrame.height();
1052 final float destWidth = destFrame.width();
1053 final float destHeight = destFrame.height();
1054 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1055 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001056 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001057 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001058 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001059 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001060 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1061 // We want the scaling to happen from the center of the surface. In order to achieve that,
1062 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001063 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1064 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1065 final ScaleAnimation scale = enter ?
1066 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1067 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1068 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1069 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1070 final int destHCenter = destFrame.left + destFrame.width() / 2;
1071 final int destVCenter = destFrame.top + destFrame.height() / 2;
1072 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1073 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1074 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1075 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001076 set.addAnimation(scale);
1077 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001078
1079 final IRemoteCallback callback = mAnimationFinishedCallback;
1080 if (callback != null) {
1081 set.setAnimationListener(new Animation.AnimationListener() {
1082 @Override
1083 public void onAnimationStart(Animation animation) { }
1084
1085 @Override
1086 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001087 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001088 }
1089
1090 @Override
1091 public void onAnimationRepeat(Animation animation) { }
1092 });
1093 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001094 return set;
1095 }
1096
Winson Chung399f6202014-03-19 10:47:20 -07001097 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001098 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001099 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001100 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001101 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
1102 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001103 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001104 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001105 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001106 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001107 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001108 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1109
1110 if (mNextAppTransitionScaleUp) {
1111 // Animation for the thumbnail zooming from its initial size to the full screen
1112 float scaleW = appWidth / thumbWidth;
1113 float scaleH = appHeight / thumbHeight;
1114 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001115 computePivot(mTmpRect.left, 1 / scaleW),
1116 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001117 scale.setInterpolator(mDecelerateInterpolator);
1118
1119 Animation alpha = new AlphaAnimation(1, 0);
1120 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1121
1122 // This AnimationSet uses the Interpolators assigned above.
1123 AnimationSet set = new AnimationSet(false);
1124 set.addAnimation(scale);
1125 set.addAnimation(alpha);
1126 a = set;
1127 } else {
1128 // Animation for the thumbnail zooming down from the full screen to its final size
1129 float scaleW = appWidth / thumbWidth;
1130 float scaleH = appHeight / thumbHeight;
1131 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001132 computePivot(mTmpRect.left, 1 / scaleW),
1133 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001134 }
1135
1136 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1137 }
1138
1139 /**
Winson Chung399f6202014-03-19 10:47:20 -07001140 * This animation is created when we are doing a thumbnail transition, for the activity that is
1141 * leaving, and the activity that is entering.
1142 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001143 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1144 int transit, int taskId) {
1145 final int appWidth = containingFrame.width();
1146 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001147 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001148 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001149 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001150 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001151 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001152 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001153 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1154
1155 switch (thumbTransitState) {
1156 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1157 // Entering app scales up with the thumbnail
1158 float scaleW = thumbWidth / appWidth;
1159 float scaleH = thumbHeight / appHeight;
1160 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001161 computePivot(mTmpRect.left, scaleW),
1162 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001163 break;
1164 }
1165 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1166 // Exiting app while the thumbnail is scaling up should fade or stay in place
1167 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1168 // Fade out while bringing up selected activity. This keeps the
1169 // current activity from showing through a launching wallpaper
1170 // activity.
1171 a = new AlphaAnimation(1, 0);
1172 } else {
1173 // noop animation
1174 a = new AlphaAnimation(1, 1);
1175 }
1176 break;
1177 }
1178 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1179 // Entering the other app, it should just be visible while we scale the thumbnail
1180 // down above it
1181 a = new AlphaAnimation(1, 1);
1182 break;
1183 }
1184 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1185 // Exiting the current app, the app should scale down with the thumbnail
1186 float scaleW = thumbWidth / appWidth;
1187 float scaleH = thumbHeight / appHeight;
1188 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001189 computePivot(mTmpRect.left, scaleW),
1190 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001191
1192 Animation alpha = new AlphaAnimation(1, 0);
1193
1194 AnimationSet set = new AnimationSet(true);
1195 set.addAnimation(scale);
1196 set.addAnimation(alpha);
1197 set.setZAdjustment(Animation.ZORDER_TOP);
1198 a = set;
1199 break;
1200 }
1201 default:
1202 throw new RuntimeException("Invalid thumbnail transition state");
1203 }
1204
1205 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1206 }
1207
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001208 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001209 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1210 final int left = mTmpFromClipRect.left;
1211 final int top = mTmpFromClipRect.top;
1212 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001213 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1214 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001215 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001216 float fromWidth = mTmpFromClipRect.width();
1217 float toWidth = mTmpToClipRect.width();
1218 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001219 // While the window might span the whole display, the actual content will be cropped to the
1220 // system decoration frame, for example when the window is docked. We need to take into
1221 // account the visible height when constructing the animation.
1222 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1223 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001224 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1225 // The final window is larger in both dimensions than current window (e.g. we are
1226 // maximizing), so we can simply unclip the new window and there will be no disappearing
1227 // frame.
1228 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1229 } else {
1230 // The disappearing window has one larger dimension. We need to apply scaling, so the
1231 // first frame of the entry animation matches the old window.
1232 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001233 // We might not be going exactly full screen, but instead be aligned under the status
1234 // bar using cropping. We still need to account for the cropped part, which will also
1235 // be scaled.
1236 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001237 }
1238
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001239 // We animate the translation from the old position of the removed window, to the new
1240 // position of the added window. The latter might not be full screen, for example docked for
1241 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001242 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001243 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001244 set.addAnimation(translate);
1245 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001246 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001247 return set;
1248 }
1249
Jorim Jaggic554b772015-06-04 16:07:57 -07001250 /**
1251 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1252 * frame of the transition doesn't change the visuals on screen, so we can start
1253 * directly with the second one
1254 */
1255 boolean canSkipFirstFrame() {
1256 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1257 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
1258 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1259 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001260
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001261 /**
1262 *
1263 * @param frame These are the bounds of the window when it finishes the animation. This is where
1264 * the animation must usually finish in entrance animation, as the next frame will
1265 * display the window at these coordinates. In case of exit animation, this is
1266 * where the animation must start, as the frame before the animation is displaying
1267 * the window at these bounds.
1268 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1269 * window might be obscured, usually by the system windows (status bar and
1270 * navigation bar) and we use content insets to convey that information. This
1271 * usually affects the animation aspects vertically, as the system decoration is
1272 * at the top and the bottom. For example when we animate from full screen to
1273 * recents, we want to exclude the covered parts, because they won't match the
1274 * thumbnail after the last frame is executed.
1275 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1276 * know about this to make the animation frames match. We currently use
1277 * this for freeform windows, which have larger surfaces to display
1278 * shadows. When we animate them from recents, we want to match the content
1279 * to the recents thumbnail and hence need to account for the surface being
1280 * bigger.
1281 */
Craig Mautner164d4bb2012-11-26 13:51:23 -08001282 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001283 int orientation, Rect frame, Rect displayFrame, Rect insets,
1284 @Nullable Rect surfaceInsets, boolean isVoiceInteraction, boolean freeform,
1285 int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001286 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001287 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
1288 || transit == TRANSIT_TASK_OPEN
1289 || transit == TRANSIT_TASK_TO_FRONT)) {
1290 a = loadAnimationRes(lp, enter
1291 ? com.android.internal.R.anim.voice_activity_open_enter
1292 : com.android.internal.R.anim.voice_activity_open_exit);
1293 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1294 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001295 + " anim=" + a + " transit=" + appTransitionToString(transit)
1296 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001297 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1298 || transit == TRANSIT_TASK_CLOSE
1299 || transit == TRANSIT_TASK_TO_BACK)) {
1300 a = loadAnimationRes(lp, enter
1301 ? com.android.internal.R.anim.voice_activity_close_enter
1302 : com.android.internal.R.anim.voice_activity_close_exit);
1303 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1304 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001305 + " anim=" + a + " transit=" + appTransitionToString(transit)
1306 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001307 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001308 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001309 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1310 "applyAnimation:"
1311 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1312 + " transit=" + appTransitionToString(transit)
1313 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001314 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1315 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001316 mNextAppTransitionEnter : mNextAppTransitionExit);
1317 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1318 "applyAnimation:"
1319 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001320 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001321 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001322 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1323 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1324 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1325 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001326 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1327 + " transit=" + appTransitionToString(transit)
1328 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001329 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001330 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001331 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1332 "applyAnimation:"
1333 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001334 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001335 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001336 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001337 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001338 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1339 "applyAnimation:"
1340 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001341 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001342 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001343 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1344 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001345 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001346 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001347 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001348 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001349 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1350 String animName = mNextAppTransitionScaleUp ?
1351 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1352 Slog.v(TAG, "applyAnimation:"
1353 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001354 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001355 + " Callers=" + Debug.getCallers(3));
1356 }
1357 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1358 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1359 mNextAppTransitionScaleUp =
1360 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1361 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001362 getThumbnailTransitionState(enter), orientation, transit, frame,
1363 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001364 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1365 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001366 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001367 Slog.v(TAG, "applyAnimation:"
1368 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001369 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001370 + " Callers=" + Debug.getCallers(3));
1371 }
1372 } else {
1373 int animAttr = 0;
1374 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001375 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001376 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001377 ? WindowAnimation_activityOpenEnterAnimation
1378 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001379 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001380 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001381 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001382 ? WindowAnimation_activityCloseEnterAnimation
1383 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001384 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001385 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001386 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001387 ? WindowAnimation_taskOpenEnterAnimation
1388 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001389 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001390 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001391 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001392 ? WindowAnimation_taskCloseEnterAnimation
1393 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001394 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001395 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001396 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001397 ? WindowAnimation_taskToFrontEnterAnimation
1398 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001399 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001400 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001401 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001402 ? WindowAnimation_taskToBackEnterAnimation
1403 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001404 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001405 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001406 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001407 ? WindowAnimation_wallpaperOpenEnterAnimation
1408 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001409 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001410 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001411 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001412 ? WindowAnimation_wallpaperCloseEnterAnimation
1413 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001414 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001415 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001416 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001417 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1418 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001419 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001420 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001421 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001422 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1423 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001424 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001425 case TRANSIT_TASK_OPEN_BEHIND:
1426 animAttr = enter
1427 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001428 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001429 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001430 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001431 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1432 "applyAnimation:"
1433 + " anim=" + a
1434 + " animAttr=0x" + Integer.toHexString(animAttr)
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));
1437 }
1438 return a;
1439 }
1440
1441 void postAnimationCallback() {
1442 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001443 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1444 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001445 mNextAppTransitionCallback = null;
1446 }
1447 }
1448
1449 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001450 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001451 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001452 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001453 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001454 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001455 mNextAppTransitionEnter = enterAnim;
1456 mNextAppTransitionExit = exitAnim;
1457 postAnimationCallback();
1458 mNextAppTransitionCallback = startedCallback;
1459 } else {
1460 postAnimationCallback();
1461 }
1462 }
1463
1464 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001465 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001466 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001467 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001468 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001469 putDefaultNextAppTransitionCoordinates(startX, startY, startX + startWidth,
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001470 startY + startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001471 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001472 }
1473 }
1474
Chet Haase10e23ab2015-02-11 15:08:38 -08001475 void overridePendingAppTransitionClipReveal(int startX, int startY,
1476 int startWidth, int startHeight) {
1477 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001478 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001479 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001480 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001481 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001482 }
1483 }
1484
Craig Mautner164d4bb2012-11-26 13:51:23 -08001485 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1486 IRemoteCallback startedCallback, boolean scaleUp) {
1487 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001488 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001489 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1490 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001491 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001492 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001493 postAnimationCallback();
1494 mNextAppTransitionCallback = startedCallback;
1495 } else {
1496 postAnimationCallback();
1497 }
1498 }
1499
Winson Chunga4ccb862014-08-22 15:26:27 -07001500 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001501 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001502 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001503 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001504 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1505 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001506 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001507 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1508 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001509 postAnimationCallback();
1510 mNextAppTransitionCallback = startedCallback;
1511 } else {
1512 postAnimationCallback();
1513 }
1514 }
1515
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001516 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001517 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1518 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001519 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001520 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001521 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1522 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001523 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001524 if (specs != null) {
1525 for (int i = 0; i < specs.length; i++) {
1526 AppTransitionAnimationSpec spec = specs[i];
1527 if (spec != null) {
1528 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1529 if (i == 0) {
1530 // In full screen mode, the transition code depends on the default spec
1531 // to be set.
1532 Rect rect = spec.rect;
1533 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Filip Gruszczynskie3264d82015-11-20 17:10:04 -08001534 rect.width(), rect.height(), spec.bitmap);
Jorim Jaggi43102412015-11-11 16:28:37 +01001535 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001536 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001537 }
1538 }
1539 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001540 mNextAppTransitionCallback = onAnimationStartedCallback;
1541 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001542 } else {
1543 postAnimationCallback();
1544 }
1545 }
1546
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001547 void overridePendingAppTransitionMultiThumbFuture(
1548 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1549 boolean scaleUp) {
1550 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001551 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001552 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1553 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001554 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1555 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001556 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001557 }
1558 }
1559
Winson Chung044d5292014-11-06 11:05:19 -08001560 void overrideInPlaceAppTransition(String packageName, int anim) {
1561 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001562 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001563 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1564 mNextAppTransitionPackage = packageName;
1565 mNextAppTransitionInPlace = anim;
1566 } else {
1567 postAnimationCallback();
1568 }
1569 }
1570
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001571 /**
1572 * If a future is set for the app transition specs, fetch it in another thread.
1573 */
1574 private void fetchAppTransitionSpecsFromFuture() {
1575 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1576 mNextAppTransitionAnimationsSpecsPending = true;
1577 final IAppTransitionAnimationSpecsFuture future
1578 = mNextAppTransitionAnimationsSpecsFuture;
1579 mNextAppTransitionAnimationsSpecsFuture = null;
1580 mDefaultExecutor.execute(new Runnable() {
1581 @Override
1582 public void run() {
1583 AppTransitionAnimationSpec[] specs = null;
1584 try {
1585 specs = future.get();
1586 } catch (RemoteException e) {
1587 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1588 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001589 synchronized (mService.mWindowMap) {
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001590 mNextAppTransitionAnimationsSpecsPending = false;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001591 overridePendingAppTransitionMultiThumb(specs,
1592 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1593 mNextAppTransitionScaleUp);
1594 mNextAppTransitionFutureCallback = null;
Filip Gruszczynski96daf322015-11-18 18:01:27 -08001595 if (specs != null) {
1596 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1597 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001598 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001599 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001600 }
1601 });
1602 }
1603 }
1604
Craig Mautner164d4bb2012-11-26 13:51:23 -08001605 @Override
1606 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001607 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001608 }
1609
Craig Mautner4b71aa12012-12-27 17:20:01 -08001610 /**
1611 * Returns the human readable name of a window transition.
1612 *
1613 * @param transition The window transition.
1614 * @return The transition symbolic name.
1615 */
1616 public static String appTransitionToString(int transition) {
1617 switch (transition) {
1618 case TRANSIT_UNSET: {
1619 return "TRANSIT_UNSET";
1620 }
1621 case TRANSIT_NONE: {
1622 return "TRANSIT_NONE";
1623 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001624 case TRANSIT_ACTIVITY_OPEN: {
1625 return "TRANSIT_ACTIVITY_OPEN";
1626 }
1627 case TRANSIT_ACTIVITY_CLOSE: {
1628 return "TRANSIT_ACTIVITY_CLOSE";
1629 }
1630 case TRANSIT_TASK_OPEN: {
1631 return "TRANSIT_TASK_OPEN";
1632 }
1633 case TRANSIT_TASK_CLOSE: {
1634 return "TRANSIT_TASK_CLOSE";
1635 }
1636 case TRANSIT_TASK_TO_FRONT: {
1637 return "TRANSIT_TASK_TO_FRONT";
1638 }
1639 case TRANSIT_TASK_TO_BACK: {
1640 return "TRANSIT_TASK_TO_BACK";
1641 }
1642 case TRANSIT_WALLPAPER_CLOSE: {
1643 return "TRANSIT_WALLPAPER_CLOSE";
1644 }
1645 case TRANSIT_WALLPAPER_OPEN: {
1646 return "TRANSIT_WALLPAPER_OPEN";
1647 }
1648 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1649 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1650 }
1651 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1652 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1653 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001654 case TRANSIT_TASK_OPEN_BEHIND: {
1655 return "TRANSIT_TASK_OPEN_BEHIND";
1656 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001657 case TRANSIT_ACTIVITY_RELAUNCH: {
1658 return "TRANSIT_ACTIVITY_RELAUNCH";
1659 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001660 default: {
1661 return "<UNKNOWN>";
1662 }
1663 }
1664 }
1665
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001666 private String appStateToString() {
1667 switch (mAppTransitionState) {
1668 case APP_STATE_IDLE:
1669 return "APP_STATE_IDLE";
1670 case APP_STATE_READY:
1671 return "APP_STATE_READY";
1672 case APP_STATE_RUNNING:
1673 return "APP_STATE_RUNNING";
1674 case APP_STATE_TIMEOUT:
1675 return "APP_STATE_TIMEOUT";
1676 default:
1677 return "unknown state=" + mAppTransitionState;
1678 }
1679 }
1680
1681 private String transitTypeToString() {
1682 switch (mNextAppTransitionType) {
1683 case NEXT_TRANSIT_TYPE_NONE:
1684 return "NEXT_TRANSIT_TYPE_NONE";
1685 case NEXT_TRANSIT_TYPE_CUSTOM:
1686 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001687 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1688 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001689 case NEXT_TRANSIT_TYPE_SCALE_UP:
1690 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1691 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1692 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1693 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1694 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001695 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1696 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1697 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1698 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001699 default:
1700 return "unknown type=" + mNextAppTransitionType;
1701 }
1702 }
1703
Craig Mautner164d4bb2012-11-26 13:51:23 -08001704 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001705 public void dump(PrintWriter pw, String prefix) {
1706 pw.print(prefix); pw.println(this);
1707 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001708 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001709 pw.print(prefix); pw.print("mNextAppTransitionType=");
1710 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001711 }
1712 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001713 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001714 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001715 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001716 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001717 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1718 pw.print(" mNextAppTransitionExit=0x");
1719 pw.println(Integer.toHexString(mNextAppTransitionExit));
1720 break;
Winson Chung044d5292014-11-06 11:05:19 -08001721 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001722 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001723 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001724 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001725 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1726 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001727 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001728 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001729 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001730 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001731 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001732 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001733 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001734 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001735 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001736 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001737 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001738 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001739 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1740 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001741 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001742 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1743 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1744 pw.println(mDefaultNextAppTransitionAnimationSpec);
1745 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1746 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001747 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1748 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001749 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001750 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001751 }
1752 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001753 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1754 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001755 }
1756 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001757
1758 public void setCurrentUser(int newUserId) {
1759 mCurrentUserId = newUserId;
1760 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001761
1762 /**
1763 * @return true if transition is not running and should not be skipped, false if transition is
1764 * already running
1765 */
1766 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent) {
1767 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
1768 + " transit=" + appTransitionToString(transit)
1769 + " " + this
1770 + " alwaysKeepCurrent=" + alwaysKeepCurrent
1771 + " Callers=" + Debug.getCallers(3));
1772 if (!isTransitionSet() || mNextAppTransition == TRANSIT_NONE) {
1773 setAppTransition(transit);
1774 } else if (!alwaysKeepCurrent) {
1775 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
1776 // Opening a new task always supersedes a close for the anim.
1777 setAppTransition(transit);
1778 } else if (transit == TRANSIT_ACTIVITY_OPEN
1779 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
1780 // Opening a new activity always supersedes a close for the anim.
1781 setAppTransition(transit);
1782 }
1783 }
1784 boolean prepared = prepare();
1785 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001786 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
1787 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001788 }
1789 return prepared;
1790 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001791}