blob: fe018269037551fb6d6b00b3a8104ca4435fba7f [file] [log] [blame]
Craig Mautner164d4bb2012-11-26 13:51:23 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Filip Gruszczynski82861362015-10-16 14:21:09 -070019import static android.view.WindowManagerInternal.AppTransitionListener;
20import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
21import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
22import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
23import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
24import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
25import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
26import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
27import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
28import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
29import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
30import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
31import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
32import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
33import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
34import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
35import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
36import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
37import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
38import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
39import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
40import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
41import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
42
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070043import android.annotation.Nullable;
Craig Mautner164d4bb2012-11-26 13:51:23 -080044import android.content.Context;
Winson Chung2820c452014-04-15 15:34:44 -070045import android.content.res.Configuration;
Craig Mautner164d4bb2012-11-26 13:51:23 -080046import android.graphics.Bitmap;
Winson Chung399f6202014-03-19 10:47:20 -070047import android.graphics.Rect;
Craig Mautner164d4bb2012-11-26 13:51:23 -080048import android.os.Debug;
49import android.os.Handler;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010050import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080051import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010052import android.os.RemoteException;
Craig Mautner164d4bb2012-11-26 13:51:23 -080053import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070054import android.util.SparseArray;
55import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010056import android.view.IAppTransitionAnimationSpecsFuture;
Craig Mautner164d4bb2012-11-26 13:51:23 -080057import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080058import android.view.animation.AlphaAnimation;
59import android.view.animation.Animation;
60import android.view.animation.AnimationSet;
61import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070062import android.view.animation.ClipRectAnimation;
Chet Haase10e23ab2015-02-11 15:08:38 -080063import android.view.animation.ClipRectLRAnimation;
64import android.view.animation.ClipRectTBAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080065import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070066import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080067import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070068import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070069
Craig Mautner164d4bb2012-11-26 13:51:23 -080070import com.android.internal.util.DumpUtils.Dump;
71import com.android.server.AttributeCache;
72import com.android.server.wm.WindowManagerService.H;
73
74import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010075import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010076import java.util.concurrent.ExecutorService;
77import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -080078
Craig Mautner164d4bb2012-11-26 13:51:23 -080079// State management of app transitions. When we are preparing for a
80// transition, mNextAppTransition will be the kind of transition to
81// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
82// mOpeningApps and mClosingApps are the lists of tokens that will be
83// made visible or hidden at the next transition.
84public class AppTransition implements Dump {
85 private static final String TAG = "AppTransition";
Craig Mautner321bdf52012-12-18 09:53:24 -080086 private static final boolean DEBUG_APP_TRANSITIONS =
87 WindowManagerService.DEBUG_APP_TRANSITIONS;
88 private static final boolean DEBUG_ANIM = WindowManagerService.DEBUG_ANIM;
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
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700136 private static final int DEFAULT_APP_TRANSITION_DURATION = 336;
137 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
138 private static final int THUMBNAIL_APP_TRANSITION_ALPHA_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700139 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800140
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800141 private final Context mContext;
142 private final Handler mH;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800143
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800144 private int mNextAppTransition = TRANSIT_UNSET;
145
146 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
147 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
148 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
149 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
150 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700151 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
152 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800153 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800154 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800155 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
156
Winson Chung399f6202014-03-19 10:47:20 -0700157 // These are the possible states for the enter/exit activities during a thumbnail transition
158 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
159 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
160 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
161 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
162
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800163 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800164 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800165 private boolean mNextAppTransitionScaleUp;
166 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100167 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700168 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800169 private int mNextAppTransitionEnter;
170 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800171 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700172
173 // Keyed by task id.
174 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
175 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100176 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
177 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700178 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
179
Winson Chunga4ccb862014-08-22 15:26:27 -0700180 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800181
Winson Chung2820c452014-04-15 15:34:44 -0700182 private Rect mTmpFromClipRect = new Rect();
183 private Rect mTmpToClipRect = new Rect();
184
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700185 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700186
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800187 private final static int APP_STATE_IDLE = 0;
188 private final static int APP_STATE_READY = 1;
189 private final static int APP_STATE_RUNNING = 2;
190 private final static int APP_STATE_TIMEOUT = 3;
191 private int mAppTransitionState = APP_STATE_IDLE;
192
193 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800194 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700195 private final Interpolator mThumbnailFadeInInterpolator;
196 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800197 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700198 private final Interpolator mFastOutLinearInInterpolator;
199 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
200
201 /** Interpolator to be used for animations that respond directly to a touch */
202 private final Interpolator mTouchResponseInterpolator =
203 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
204
205 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800206
Amith Yamasani4befbec2013-07-10 16:18:01 -0700207 private int mCurrentUserId = 0;
208
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100209 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100210 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
211 private final Object mServiceLock;
212 private final WindowSurfacePlacer mWindowSurfacePlacer;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100213
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100214 AppTransition(Context context, Handler h, Object serviceLock,
215 WindowSurfacePlacer windowSurfacePlacer) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800216 mContext = context;
217 mH = h;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100218 mServiceLock = serviceLock;
219 mWindowSurfacePlacer = windowSurfacePlacer;
Chet Haase10e23ab2015-02-11 15:08:38 -0800220 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
221 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700222 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
223 com.android.internal.R.interpolator.fast_out_linear_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800224 mConfigShortAnimTime = context.getResources().getInteger(
225 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800226 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
227 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700228 mThumbnailFadeInInterpolator = new Interpolator() {
229 @Override
230 public float getInterpolation(float input) {
231 // Linear response for first fraction, then complete after that.
232 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
233 return 0f;
234 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700235 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700236 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700237 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700238 }
239 };
240 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800241 @Override
242 public float getInterpolation(float input) {
243 // Linear response for first fraction, then complete after that.
244 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700245 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
246 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800247 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700248 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800249 }
250 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700251 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
252 * mContext.getResources().getDisplayMetrics().density);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800253 }
254
255 boolean isTransitionSet() {
256 return mNextAppTransition != TRANSIT_UNSET;
257 }
258
Craig Mautner164d4bb2012-11-26 13:51:23 -0800259 boolean isTransitionEqual(int transit) {
260 return mNextAppTransition == transit;
261 }
262
263 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800264 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800265 }
266
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700267 private void setAppTransition(int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800268 mNextAppTransition = transit;
269 }
270
271 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800272 return mAppTransitionState == APP_STATE_READY
273 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800274 }
275
Craig Mautnerae446592012-12-06 19:05:05 -0800276 void setReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800277 mAppTransitionState = APP_STATE_READY;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100278 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800279 }
280
281 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800282 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800283 }
284
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800285 void setIdle() {
286 mAppTransitionState = APP_STATE_IDLE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800287 }
288
289 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800290 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800291 }
292
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800293 void setTimeout() {
294 mAppTransitionState = APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800295 }
296
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700297 Bitmap getAppTransitionThumbnailHeader(int taskId) {
298 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800299 if (spec == null) {
300 spec = mDefaultNextAppTransitionAnimationSpec;
301 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700302 return spec != null ? spec.bitmap : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800303 }
304
Winson Chunga4ccb862014-08-22 15:26:27 -0700305 /** Returns whether the next thumbnail transition is aspect scaled up. */
306 boolean isNextThumbnailTransitionAspectScaled() {
307 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
308 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
309 }
310
311 /** Returns whether the next thumbnail transition is scaling up. */
312 boolean isNextThumbnailTransitionScaleUp() {
313 return mNextAppTransitionScaleUp;
314 }
315
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100316 /**
317 * @return true if and only if we are currently fetching app transition specs from the future
318 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
319 */
320 boolean isFetchingAppTransitionsSpecs() {
321 return mNextAppTransitionAnimationsSpecsPending;
322 }
323
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700324 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800325 if (!isRunning()) {
326 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100327 notifyAppTransitionPendingLocked();
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700328 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800329 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700330 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800331 }
332
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100333 void goodToGo(AppWindowAnimator openingAppAnimator, AppWindowAnimator closingAppAnimator) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800334 mNextAppTransition = TRANSIT_UNSET;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800335 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100336 notifyAppTransitionStartingLocked(
337 openingAppAnimator != null ? openingAppAnimator.mAppToken.token : null,
338 closingAppAnimator != null ? closingAppAnimator.mAppToken.token : null,
339 openingAppAnimator != null ? openingAppAnimator.animation : null,
340 closingAppAnimator != null ? closingAppAnimator.animation : null);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800341 }
342
343 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800344 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800345 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700346 mNextAppTransitionAnimationsSpecs.clear();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800347 }
348
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800349 void freeze() {
350 setAppTransition(AppTransition.TRANSIT_UNSET);
351 clear();
352 setReady();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100353 notifyAppTransitionCancelledLocked();
354 }
355
356 void registerListenerLocked(AppTransitionListener listener) {
357 mListeners.add(listener);
358 }
359
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700360 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100361 for (int i = 0; i < mListeners.size(); i++) {
362 mListeners.get(i).onAppTransitionFinishedLocked(token);
363 }
364 }
365
366 private void notifyAppTransitionPendingLocked() {
367 for (int i = 0; i < mListeners.size(); i++) {
368 mListeners.get(i).onAppTransitionPendingLocked();
369 }
370 }
371
372 private void notifyAppTransitionCancelledLocked() {
373 for (int i = 0; i < mListeners.size(); i++) {
374 mListeners.get(i).onAppTransitionCancelledLocked();
375 }
376 }
377
378 private void notifyAppTransitionStartingLocked(IBinder openToken,
379 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
380 for (int i = 0; i < mListeners.size(); i++) {
381 mListeners.get(i).onAppTransitionStartingLocked(openToken, closeToken, openAnimation,
382 closeAnimation);
383 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800384 }
385
Craig Mautner164d4bb2012-11-26 13:51:23 -0800386 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
387 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
388 + (lp != null ? lp.packageName : null)
389 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
390 if (lp != null && lp.windowAnimations != 0) {
391 // If this is a system resource, don't try to load it from the
392 // application resources. It is nice to avoid loading application
393 // resources if we can.
394 String packageName = lp.packageName != null ? lp.packageName : "android";
395 int resId = lp.windowAnimations;
396 if ((resId&0xFF000000) == 0x01000000) {
397 packageName = "android";
398 }
399 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
400 + packageName);
401 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700402 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800403 }
404 return null;
405 }
406
407 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
408 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
409 + packageName + " resId=0x" + Integer.toHexString(resId));
410 if (packageName != null) {
411 if ((resId&0xFF000000) == 0x01000000) {
412 packageName = "android";
413 }
414 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
415 + packageName);
416 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700417 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800418 }
419 return null;
420 }
421
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700422 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800423 int anim = 0;
424 Context context = mContext;
425 if (animAttr >= 0) {
426 AttributeCache.Entry ent = getCachedAnimations(lp);
427 if (ent != null) {
428 context = ent.context;
429 anim = ent.array.getResourceId(animAttr, 0);
430 }
431 }
432 if (anim != 0) {
433 return AnimationUtils.loadAnimation(context, anim);
434 }
435 return null;
436 }
437
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700438 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
439 Context context = mContext;
440 if (resId >= 0) {
441 AttributeCache.Entry ent = getCachedAnimations(lp);
442 if (ent != null) {
443 context = ent.context;
444 }
445 return AnimationUtils.loadAnimation(context, resId);
446 }
447 return null;
448 }
449
450 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800451 int anim = 0;
452 Context context = mContext;
453 if (resId >= 0) {
454 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
455 if (ent != null) {
456 context = ent.context;
457 anim = resId;
458 }
459 }
460 if (anim != 0) {
461 return AnimationUtils.loadAnimation(context, anim);
462 }
463 return null;
464 }
465
Craig Mautner164d4bb2012-11-26 13:51:23 -0800466 /**
467 * Compute the pivot point for an animation that is scaling from a small
468 * rect on screen to a larger rect. The pivot point varies depending on
469 * the distance between the inner and outer edges on both sides. This
470 * function computes the pivot point for one dimension.
471 * @param startPos Offset from left/top edge of outer rectangle to
472 * left/top edge of inner rectangle.
473 * @param finalScale The scaling factor between the size of the outer
474 * and inner rectangles.
475 */
476 private static float computePivot(int startPos, float finalScale) {
477 final float denom = finalScale-1;
478 if (Math.abs(denom) < .0001f) {
479 return startPos;
480 }
481 return -startPos / denom;
482 }
483
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700484 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
485 Rect containingFrame) {
486 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700487 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700488 final int appWidth = containingFrame.width();
489 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800490 if (enter) {
491 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700492 float scaleW = mTmpRect.width() / (float) appWidth;
493 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800494 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700495 computePivot(mTmpRect.left, scaleW),
496 computePivot(mTmpRect.right, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800497 scale.setInterpolator(mDecelerateInterpolator);
498
Craig Mautner164d4bb2012-11-26 13:51:23 -0800499 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700500 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800501
502 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800503 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800504 set.addAnimation(alpha);
505 set.setDetachWallpaper(true);
506 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800507 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
508 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800509 // If we are on top of the wallpaper, we need an animation that
510 // correctly handles the wallpaper staying static behind all of
511 // the animated elements. To do this, will just have the existing
512 // element fade out.
513 a = new AlphaAnimation(1, 0);
514 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800515 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800516 // For normal animations, the exiting element just holds in place.
517 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800518 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800519
520 // Pick the desired duration. If this is an inter-activity transition,
521 // it is the standard duration for that. Otherwise we use the longer
522 // task transition duration.
523 final long duration;
524 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800525 case TRANSIT_ACTIVITY_OPEN:
526 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800527 duration = mConfigShortAnimTime;
528 break;
529 default:
530 duration = DEFAULT_APP_TRANSITION_DURATION;
531 break;
532 }
533 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800534 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800535 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800536 a.initialize(appWidth, appHeight, appWidth, appHeight);
537 return a;
538 }
539
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700540 private void getDefaultNextAppTransitionStartRect(Rect rect) {
541 if (mDefaultNextAppTransitionAnimationSpec == null ||
542 mDefaultNextAppTransitionAnimationSpec.rect == null) {
543 Slog.wtf(TAG, "Starting rect for app requested, but none available", new Throwable());
544 rect.setEmpty();
545 } else {
546 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
547 }
548 }
549
550 void getNextAppTransitionStartRect(int taskId, Rect rect) {
551 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800552 if (spec == null) {
553 spec = mDefaultNextAppTransitionAnimationSpec;
554 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700555 if (spec == null || spec.rect == null) {
556 Slog.wtf(TAG, "Starting rect for task: " + taskId + " requested, but not available",
557 new Throwable());
558 rect.setEmpty();
559 } else {
560 rect.set(spec.rect);
561 }
562 }
563
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800564 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
565 Bitmap bitmap) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700566 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800567 bitmap, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700568 }
569
Craig Mautner80b1f642015-04-22 10:59:09 -0700570 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800571 final Animation anim;
572 if (enter) {
573 // Reveal will expand and move faster in horizontal direction
574
Craig Mautner80b1f642015-04-22 10:59:09 -0700575 final int appWidth = appFrame.width();
576 final int appHeight = appFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700577 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700578 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700579 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700580
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700581 float t = 0f;
582 if (appHeight > 0) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700583 t = (float) mTmpRect.left / appHeight;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700584 }
Filip Gruszczynski82861362015-10-16 14:21:09 -0700585 int translationY = mClipRevealTranslationY + (int)(appHeight / 7f * t);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700586
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700587 int centerX = mTmpRect.centerX();
588 int centerY = mTmpRect.centerY();
589 int halfWidth = mTmpRect.width() / 2;
590 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700591
592 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800593 Animation clipAnimLR = new ClipRectLRAnimation(
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700594 centerX - halfWidth, centerX + halfWidth, 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700595 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
596 clipAnimLR.setDuration((long) (DEFAULT_APP_TRANSITION_DURATION / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700597
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700598 Animation clipAnimTB = new ClipRectTBAnimation(centerY - halfHeight - translationY,
599 centerY + halfHeight/ 2 - translationY, 0, appHeight);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700600 clipAnimTB.setInterpolator(mTouchResponseInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800601 clipAnimTB.setDuration(DEFAULT_APP_TRANSITION_DURATION);
602
Filip Gruszczynski82861362015-10-16 14:21:09 -0700603 // We might be animating entrance of a docked task, so we need the translate to account
604 // for the app frame in which the window will reside. Every other calculation here
605 // is performed as if the window started at 0,0.
606 translationY -= appFrame.top;
607 TranslateAnimation translate = new TranslateAnimation(-appFrame.left, 0, translationY,
608 0);
609 translate.setInterpolator(mLinearOutSlowInInterpolator);
610 translate.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Chet Haase10e23ab2015-02-11 15:08:38 -0800611
612 // Quick fade-in from icon to app window
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700613 final int alphaDuration = DEFAULT_APP_TRANSITION_DURATION / 4;
614 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800615 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700616 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800617
618 AnimationSet set = new AnimationSet(false);
619 set.addAnimation(clipAnimLR);
620 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700621 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800622 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700623 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800624 set.initialize(appWidth, appHeight, appWidth, appHeight);
625 anim = set;
626 } else {
627 final long duration;
628 switch (transit) {
629 case TRANSIT_ACTIVITY_OPEN:
630 case TRANSIT_ACTIVITY_CLOSE:
631 duration = mConfigShortAnimTime;
632 break;
633 default:
634 duration = DEFAULT_APP_TRANSITION_DURATION;
635 break;
636 }
637 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
638 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
639 // If we are on top of the wallpaper, we need an animation that
640 // correctly handles the wallpaper staying static behind all of
641 // the animated elements. To do this, will just have the existing
642 // element fade out.
643 anim = new AlphaAnimation(1, 0);
644 anim.setDetachWallpaper(true);
645 } else {
646 // For normal animations, the exiting element just holds in place.
647 anim = new AlphaAnimation(1, 1);
648 }
649 anim.setInterpolator(mDecelerateInterpolator);
650 anim.setDuration(duration);
651 anim.setFillAfter(true);
652 }
653 return anim;
654 }
655
Winson Chung399f6202014-03-19 10:47:20 -0700656 /**
657 * Prepares the specified animation with a standard duration, interpolator, etc.
658 */
Winson Chung5393dff2014-05-08 14:25:43 -0700659 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
660 int duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700661 if (duration > 0) {
662 a.setDuration(duration);
663 }
Winson Chung5393dff2014-05-08 14:25:43 -0700664 a.setFillAfter(true);
665 a.setInterpolator(interpolator);
666 a.initialize(appWidth, appHeight, appWidth, appHeight);
667 return a;
668 }
669
670 /**
671 * Prepares the specified animation with a standard duration, interpolator, etc.
672 */
Winson Chung399f6202014-03-19 10:47:20 -0700673 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800674 // Pick the desired duration. If this is an inter-activity transition,
675 // it is the standard duration for that. Otherwise we use the longer
676 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700677 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800678 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800679 case TRANSIT_ACTIVITY_OPEN:
680 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800681 duration = mConfigShortAnimTime;
682 break;
683 default:
684 duration = DEFAULT_APP_TRANSITION_DURATION;
685 break;
686 }
Winson Chung5393dff2014-05-08 14:25:43 -0700687 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
688 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800689 }
690
Winson Chung399f6202014-03-19 10:47:20 -0700691 /**
692 * Return the current thumbnail transition state.
693 */
694 int getThumbnailTransitionState(boolean enter) {
695 if (enter) {
696 if (mNextAppTransitionScaleUp) {
697 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
698 } else {
699 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
700 }
701 } else {
702 if (mNextAppTransitionScaleUp) {
703 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
704 } else {
705 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
706 }
707 }
708 }
709
710 /**
711 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700712 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700713 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700714 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, Bitmap thumbnailHeader,
715 final int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700716 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700717 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700718 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700719 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chung399f6202014-03-19 10:47:20 -0700720 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700721 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700722
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700723 float scaleW = appWidth / thumbWidth;
Winson Chunga4ccb862014-08-22 15:26:27 -0700724 float unscaledHeight = thumbHeight * scaleW;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700725 getNextAppTransitionStartRect(taskId, mTmpRect);
726 float unscaledStartY = mTmpRect.top - (unscaledHeight - thumbHeight) / 2f;
Winson Chung399f6202014-03-19 10:47:20 -0700727 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700728 // Animation up from the thumbnail to the full screen
729 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700730 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700731 scale.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700732 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700733 Animation alpha = new AlphaAnimation(1, 0);
Winson Chunga4ccb862014-08-22 15:26:27 -0700734 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
735 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700736 final float toX = appRect.left + appRect.width() / 2 -
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700737 (mTmpRect.left + thumbWidth / 2);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700738 final float toY = appRect.top + mNextAppTransitionInsets.top + -unscaledStartY;
739 Animation translate = new TranslateAnimation(0, toX, 0, toY);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700740 translate.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700741 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700742
743 // This AnimationSet uses the Interpolators assigned above.
744 AnimationSet set = new AnimationSet(false);
745 set.addAnimation(scale);
746 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -0700747 set.addAnimation(translate);
Winson Chung399f6202014-03-19 10:47:20 -0700748 a = set;
749 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700750 // Animation down from the full screen to the thumbnail
751 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700752 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700753 scale.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700754 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
755 Animation alpha = new AlphaAnimation(0f, 1f);
756 alpha.setInterpolator(mThumbnailFadeInInterpolator);
757 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
758 Animation translate = new TranslateAnimation(0, 0, -unscaledStartY +
759 mNextAppTransitionInsets.top, 0);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700760 translate.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700761 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700762
Winson Chunga4ccb862014-08-22 15:26:27 -0700763 // This AnimationSet uses the Interpolators assigned above.
764 AnimationSet set = new AnimationSet(false);
765 set.addAnimation(scale);
766 set.addAnimation(alpha);
767 set.addAnimation(translate);
768 a = set;
769
770 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700771 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700772 mTouchResponseInterpolator);
Winson Chung399f6202014-03-19 10:47:20 -0700773 }
774
775 /**
776 * This alternate animation is created when we are doing a thumbnail transition, for the
777 * activity that is leaving, and the activity that is entering.
778 */
Winson Chunga4ccb862014-08-22 15:26:27 -0700779 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700780 int orientation, int transit, Rect containingFrame, Rect contentInsets,
781 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700782 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700783 final int appWidth = containingFrame.width();
784 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700785 getDefaultNextAppTransitionStartRect(mTmpRect);
786 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700787 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700788 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -0700789 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
790
Winson Chung2820c452014-04-15 15:34:44 -0700791 // Used for the ENTER_SCALE_UP and EXIT_SCALE_DOWN transitions
792 float scale = 1f;
793 int scaledTopDecor = 0;
794
Winson Chung399f6202014-03-19 10:47:20 -0700795 switch (thumbTransitState) {
796 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700797 if (freeform) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700798 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700799 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -0700800 } else {
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700801 mTmpFromClipRect.set(containingFrame);
802 // exclude top screen decor (status bar) region from the source clip.
803 mTmpFromClipRect.top = contentInsets.top;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700804 // App window scaling up to become full screen
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700805 mTmpToClipRect.set(containingFrame);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700806 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
807 // In portrait, we scale the width and clip to the top/left square
808 scale = thumbWidth / appWidth;
809 scaledTopDecor = (int) (scale * contentInsets.top);
810 int unscaledThumbHeight = (int) (thumbHeight / scale);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700811 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700812 } else {
Filip Gruszczynskidd2ff842015-10-25 13:11:04 -0700813 // In landscape, we scale the height and clip to the top/left square. We
814 // only scale the part that is not covered by status bar and the nav bar.
815 scale = thumbHeight / (appHeight - contentInsets.top
816 - contentInsets.bottom);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700817 scaledTopDecor = (int) (scale * contentInsets.top);
818 int unscaledThumbWidth = (int) (thumbWidth / scale);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700819 mTmpFromClipRect.right = mTmpFromClipRect.left + unscaledThumbWidth;
Filip Gruszczynskidd2ff842015-10-25 13:11:04 -0700820 // This removes the navigation bar from the first frame, so it better
821 // matches the thumbnail. We need to do this explicitly in landscape,
822 // because in portrait we already crop vertically.
823 mTmpFromClipRect.bottom = mTmpFromClipRect.bottom - contentInsets.bottom;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700824 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700825
826 mNextAppTransitionInsets.set(contentInsets);
827
828 Animation scaleAnim = new ScaleAnimation(scale, 1, scale, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700829 computePivot(mTmpRect.left, scale),
830 computePivot(mTmpRect.top, scale));
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700831 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
832 Animation translateAnim = new TranslateAnimation(0, 0, -scaledTopDecor, 0);
833
834 AnimationSet set = new AnimationSet(true);
835 set.addAnimation(clipAnim);
836 set.addAnimation(scaleAnim);
837 set.addAnimation(translateAnim);
838 a = set;
Winson Chung2820c452014-04-15 15:34:44 -0700839 }
Winson Chung399f6202014-03-19 10:47:20 -0700840 break;
841 }
842 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700843 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -0700844 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700845 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -0700846 // activity.
847 a = new AlphaAnimation(1, 0);
848 } else {
Winson Chung399f6202014-03-19 10:47:20 -0700849 a = new AlphaAnimation(1, 1);
850 }
851 break;
852 }
853 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700854 // Target app window during the scale down
855 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
856 // Fade in the destination activity if we are animating from a wallpaper
857 // activity.
858 a = new AlphaAnimation(0, 1);
859 } else {
860 a = new AlphaAnimation(1, 1);
861 }
Winson Chung399f6202014-03-19 10:47:20 -0700862 break;
863 }
864 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700865 // App window scaling down from full screen
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700866 if (freeform) {
867 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
868 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -0700869 } else {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700870 mTmpFromClipRect.set(containingFrame);
871 mTmpToClipRect.set(containingFrame);
872 // exclude top screen decor (status bar) region from the destination clip.
873 mTmpToClipRect.top = contentInsets.top;
874 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
875 // In portrait, we scale the width and clip to the top/left square
876 scale = thumbWidth / appWidth;
877 scaledTopDecor = (int) (scale * contentInsets.top);
878 int unscaledThumbHeight = (int) (thumbHeight / scale);
879 mTmpToClipRect.bottom = mTmpToClipRect.top + unscaledThumbHeight;
880 } else {
881 // In landscape, we scale the height and clip to the top/left square. We only
882 // scale the part that is not covered by status bar and the nav bar.
883 scale = thumbHeight / (appHeight - contentInsets.top - contentInsets.bottom);
884 scaledTopDecor = (int) (scale * contentInsets.top);
885 int unscaledThumbWidth = (int) (thumbWidth / scale);
886 mTmpToClipRect.right = mTmpToClipRect.left + unscaledThumbWidth;
887 // This removes the navigation bar from the last frame, so it better matches the
888 // thumbnail. We need to do this explicitly in landscape, because in portrait we
889 // already crop vertically.
890 mTmpToClipRect.bottom = mTmpToClipRect.bottom - contentInsets.bottom;
891 }
892
893 mNextAppTransitionInsets.set(contentInsets);
894
895 Animation scaleAnim = new ScaleAnimation(1, scale, 1, scale,
896 computePivot(mTmpRect.left, scale),
897 computePivot(mTmpRect.top, scale));
898 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
899 Animation translateAnim = new TranslateAnimation(0, 0, 0, -scaledTopDecor);
900
901 AnimationSet set = new AnimationSet(true);
902 set.addAnimation(clipAnim);
903 set.addAnimation(scaleAnim);
904 set.addAnimation(translateAnim);
905
906 a = set;
907 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -0700908 }
Winson Chung399f6202014-03-19 10:47:20 -0700909 break;
910 }
911 default:
912 throw new RuntimeException("Invalid thumbnail transition state");
913 }
914
Winson Chungab79fce2014-11-04 16:15:22 -0800915 int duration = Math.max(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION,
916 THUMBNAIL_APP_TRANSITION_DURATION);
917 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700918 mTouchResponseInterpolator);
Winson Chung399f6202014-03-19 10:47:20 -0700919 }
920
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700921 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
922 @Nullable Rect surfaceInsets, int taskId) {
923 getNextAppTransitionStartRect(taskId, mTmpRect);
924 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
925 true);
926 }
927
928 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
929 @Nullable Rect surfaceInsets, int taskId) {
930 getNextAppTransitionStartRect(taskId, mTmpRect);
931 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
932 false);
933 }
934
935 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
936 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
937 final float sourceWidth = sourceFrame.width();
938 final float sourceHeight = sourceFrame.height();
939 final float destWidth = destFrame.width();
940 final float destHeight = destFrame.height();
941 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
942 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700943 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700944 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700945 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700946 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700947 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
948 // We want the scaling to happen from the center of the surface. In order to achieve that,
949 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700950 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
951 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
952 final ScaleAnimation scale = enter ?
953 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
954 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
955 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
956 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
957 final int destHCenter = destFrame.left + destFrame.width() / 2;
958 final int destVCenter = destFrame.top + destFrame.height() / 2;
959 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
960 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
961 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
962 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700963 set.addAnimation(scale);
964 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700965
966 final IRemoteCallback callback = mAnimationFinishedCallback;
967 if (callback != null) {
968 set.setAnimationListener(new Animation.AnimationListener() {
969 @Override
970 public void onAnimationStart(Animation animation) { }
971
972 @Override
973 public void onAnimationEnd(Animation animation) {
974 mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
975 }
976
977 @Override
978 public void onAnimationRepeat(Animation animation) { }
979 });
980 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700981 return set;
982 }
983
Winson Chung399f6202014-03-19 10:47:20 -0700984 /**
Winson Chunga4ccb862014-08-22 15:26:27 -0700985 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700986 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -0700987 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700988 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
989 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700990 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700991 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700992 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -0700993 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700994 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -0700995 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
996
997 if (mNextAppTransitionScaleUp) {
998 // Animation for the thumbnail zooming from its initial size to the full screen
999 float scaleW = appWidth / thumbWidth;
1000 float scaleH = appHeight / thumbHeight;
1001 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001002 computePivot(mTmpRect.left, 1 / scaleW),
1003 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001004 scale.setInterpolator(mDecelerateInterpolator);
1005
1006 Animation alpha = new AlphaAnimation(1, 0);
1007 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1008
1009 // This AnimationSet uses the Interpolators assigned above.
1010 AnimationSet set = new AnimationSet(false);
1011 set.addAnimation(scale);
1012 set.addAnimation(alpha);
1013 a = set;
1014 } else {
1015 // Animation for the thumbnail zooming down from the full screen to its final size
1016 float scaleW = appWidth / thumbWidth;
1017 float scaleH = appHeight / thumbHeight;
1018 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001019 computePivot(mTmpRect.left, 1 / scaleW),
1020 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001021 }
1022
1023 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1024 }
1025
1026 /**
Winson Chung399f6202014-03-19 10:47:20 -07001027 * This animation is created when we are doing a thumbnail transition, for the activity that is
1028 * leaving, and the activity that is entering.
1029 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001030 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1031 int transit, int taskId) {
1032 final int appWidth = containingFrame.width();
1033 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001034 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001035 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001036 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001037 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001038 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001039 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001040 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1041
1042 switch (thumbTransitState) {
1043 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1044 // Entering app scales up with the thumbnail
1045 float scaleW = thumbWidth / appWidth;
1046 float scaleH = thumbHeight / appHeight;
1047 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001048 computePivot(mTmpRect.left, scaleW),
1049 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001050 break;
1051 }
1052 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1053 // Exiting app while the thumbnail is scaling up should fade or stay in place
1054 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1055 // Fade out while bringing up selected activity. This keeps the
1056 // current activity from showing through a launching wallpaper
1057 // activity.
1058 a = new AlphaAnimation(1, 0);
1059 } else {
1060 // noop animation
1061 a = new AlphaAnimation(1, 1);
1062 }
1063 break;
1064 }
1065 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1066 // Entering the other app, it should just be visible while we scale the thumbnail
1067 // down above it
1068 a = new AlphaAnimation(1, 1);
1069 break;
1070 }
1071 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1072 // Exiting the current app, the app should scale down with the thumbnail
1073 float scaleW = thumbWidth / appWidth;
1074 float scaleH = thumbHeight / appHeight;
1075 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001076 computePivot(mTmpRect.left, scaleW),
1077 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001078
1079 Animation alpha = new AlphaAnimation(1, 0);
1080
1081 AnimationSet set = new AnimationSet(true);
1082 set.addAnimation(scale);
1083 set.addAnimation(alpha);
1084 set.setZAdjustment(Animation.ZORDER_TOP);
1085 a = set;
1086 break;
1087 }
1088 default:
1089 throw new RuntimeException("Invalid thumbnail transition state");
1090 }
1091
1092 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1093 }
1094
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001095 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001096 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1097 final int left = mTmpFromClipRect.left;
1098 final int top = mTmpFromClipRect.top;
1099 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001100 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1101 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001102 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001103 float fromWidth = mTmpFromClipRect.width();
1104 float toWidth = mTmpToClipRect.width();
1105 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001106 // While the window might span the whole display, the actual content will be cropped to the
1107 // system decoration frame, for example when the window is docked. We need to take into
1108 // account the visible height when constructing the animation.
1109 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1110 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001111 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1112 // The final window is larger in both dimensions than current window (e.g. we are
1113 // maximizing), so we can simply unclip the new window and there will be no disappearing
1114 // frame.
1115 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1116 } else {
1117 // The disappearing window has one larger dimension. We need to apply scaling, so the
1118 // first frame of the entry animation matches the old window.
1119 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001120 // We might not be going exactly full screen, but instead be aligned under the status
1121 // bar using cropping. We still need to account for the cropped part, which will also
1122 // be scaled.
1123 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001124 }
1125
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001126 // We animate the translation from the old position of the removed window, to the new
1127 // position of the added window. The latter might not be full screen, for example docked for
1128 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001129 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001130 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001131 set.addAnimation(translate);
1132 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001133 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001134 return set;
1135 }
1136
Jorim Jaggic554b772015-06-04 16:07:57 -07001137 /**
1138 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1139 * frame of the transition doesn't change the visuals on screen, so we can start
1140 * directly with the second one
1141 */
1142 boolean canSkipFirstFrame() {
1143 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1144 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
1145 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1146 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001147
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001148 /**
1149 *
1150 * @param frame These are the bounds of the window when it finishes the animation. This is where
1151 * the animation must usually finish in entrance animation, as the next frame will
1152 * display the window at these coordinates. In case of exit animation, this is
1153 * where the animation must start, as the frame before the animation is displaying
1154 * the window at these bounds.
1155 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1156 * window might be obscured, usually by the system windows (status bar and
1157 * navigation bar) and we use content insets to convey that information. This
1158 * usually affects the animation aspects vertically, as the system decoration is
1159 * at the top and the bottom. For example when we animate from full screen to
1160 * recents, we want to exclude the covered parts, because they won't match the
1161 * thumbnail after the last frame is executed.
1162 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1163 * know about this to make the animation frames match. We currently use
1164 * this for freeform windows, which have larger surfaces to display
1165 * shadows. When we animate them from recents, we want to match the content
1166 * to the recents thumbnail and hence need to account for the surface being
1167 * bigger.
1168 */
Craig Mautner164d4bb2012-11-26 13:51:23 -08001169 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001170 int orientation, Rect frame, Rect insets, @Nullable Rect surfaceInsets,
1171 boolean isVoiceInteraction, boolean freeform, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001172 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001173 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
1174 || transit == TRANSIT_TASK_OPEN
1175 || transit == TRANSIT_TASK_TO_FRONT)) {
1176 a = loadAnimationRes(lp, enter
1177 ? com.android.internal.R.anim.voice_activity_open_enter
1178 : com.android.internal.R.anim.voice_activity_open_exit);
1179 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1180 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001181 + " anim=" + a + " transit=" + appTransitionToString(transit)
1182 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001183 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1184 || transit == TRANSIT_TASK_CLOSE
1185 || transit == TRANSIT_TASK_TO_BACK)) {
1186 a = loadAnimationRes(lp, enter
1187 ? com.android.internal.R.anim.voice_activity_close_enter
1188 : com.android.internal.R.anim.voice_activity_close_exit);
1189 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1190 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001191 + " anim=" + a + " transit=" + appTransitionToString(transit)
1192 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001193 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001194 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001195 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1196 "applyAnimation:"
1197 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1198 + " transit=" + appTransitionToString(transit)
1199 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001200 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1201 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001202 mNextAppTransitionEnter : mNextAppTransitionExit);
1203 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1204 "applyAnimation:"
1205 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001206 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001207 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001208 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1209 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1210 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1211 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001212 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1213 + " transit=" + appTransitionToString(transit)
1214 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001215 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001216 a = createClipRevealAnimationLocked(transit, enter, frame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001217 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1218 "applyAnimation:"
1219 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001220 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001221 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001222 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001223 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001224 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1225 "applyAnimation:"
1226 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001227 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001228 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001229 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1230 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001231 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001232 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001233 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001234 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001235 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1236 String animName = mNextAppTransitionScaleUp ?
1237 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1238 Slog.v(TAG, "applyAnimation:"
1239 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001240 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001241 + " Callers=" + Debug.getCallers(3));
1242 }
1243 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1244 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1245 mNextAppTransitionScaleUp =
1246 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1247 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001248 getThumbnailTransitionState(enter), orientation, transit, frame,
1249 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001250 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1251 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001252 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001253 Slog.v(TAG, "applyAnimation:"
1254 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001255 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001256 + " Callers=" + Debug.getCallers(3));
1257 }
1258 } else {
1259 int animAttr = 0;
1260 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001261 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001262 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001263 ? WindowAnimation_activityOpenEnterAnimation
1264 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001265 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001266 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001267 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001268 ? WindowAnimation_activityCloseEnterAnimation
1269 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001270 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001271 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001272 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001273 ? WindowAnimation_taskOpenEnterAnimation
1274 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001275 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001276 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001277 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001278 ? WindowAnimation_taskCloseEnterAnimation
1279 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001280 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001281 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001282 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001283 ? WindowAnimation_taskToFrontEnterAnimation
1284 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001285 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001286 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001287 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001288 ? WindowAnimation_taskToBackEnterAnimation
1289 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001290 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001291 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001292 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001293 ? WindowAnimation_wallpaperOpenEnterAnimation
1294 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001295 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001296 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001297 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001298 ? WindowAnimation_wallpaperCloseEnterAnimation
1299 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001300 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001301 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001302 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001303 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1304 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001305 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001306 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001307 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001308 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1309 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001310 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001311 case TRANSIT_TASK_OPEN_BEHIND:
1312 animAttr = enter
1313 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001314 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001315 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001316 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001317 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1318 "applyAnimation:"
1319 + " anim=" + a
1320 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001321 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001322 + " Callers=" + Debug.getCallers(3));
1323 }
1324 return a;
1325 }
1326
1327 void postAnimationCallback() {
1328 if (mNextAppTransitionCallback != null) {
1329 mH.sendMessage(mH.obtainMessage(H.DO_ANIMATION_CALLBACK, mNextAppTransitionCallback));
1330 mNextAppTransitionCallback = null;
1331 }
1332 }
1333
1334 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001335 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001336 if (isTransitionSet()) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001337 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001338 mNextAppTransitionPackage = packageName;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001339 mNextAppTransitionAnimationsSpecs.clear();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001340 mNextAppTransitionEnter = enterAnim;
1341 mNextAppTransitionExit = exitAnim;
1342 postAnimationCallback();
1343 mNextAppTransitionCallback = startedCallback;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001344 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001345 } else {
1346 postAnimationCallback();
1347 }
1348 }
1349
1350 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001351 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001352 if (isTransitionSet()) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001353 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001354 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001355 mNextAppTransitionAnimationsSpecs.clear();
1356 putDefaultNextAppTransitionCoordinates(startX, startY, startX + startWidth,
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001357 startY + startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001358 postAnimationCallback();
1359 mNextAppTransitionCallback = null;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001360 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001361 }
1362 }
1363
Chet Haase10e23ab2015-02-11 15:08:38 -08001364 void overridePendingAppTransitionClipReveal(int startX, int startY,
1365 int startWidth, int startHeight) {
1366 if (isTransitionSet()) {
1367 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001368 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001369 postAnimationCallback();
1370 mNextAppTransitionCallback = null;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001371 mAnimationFinishedCallback = null;
Chet Haase10e23ab2015-02-11 15:08:38 -08001372 }
1373 }
1374
Craig Mautner164d4bb2012-11-26 13:51:23 -08001375 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1376 IRemoteCallback startedCallback, boolean scaleUp) {
1377 if (isTransitionSet()) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001378 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1379 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001380 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001381 mNextAppTransitionAnimationsSpecs.clear();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001382 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001383 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001384 postAnimationCallback();
1385 mNextAppTransitionCallback = startedCallback;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001386 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001387 } else {
1388 postAnimationCallback();
1389 }
1390 }
1391
Winson Chunga4ccb862014-08-22 15:26:27 -07001392 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001393 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001394 if (isTransitionSet()) {
1395 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1396 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
1397 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001398 mNextAppTransitionAnimationsSpecs.clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001399 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001400 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1401 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001402 postAnimationCallback();
1403 mNextAppTransitionCallback = startedCallback;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001404 mAnimationFinishedCallback = null;
Winson Chunga4ccb862014-08-22 15:26:27 -07001405 } else {
1406 postAnimationCallback();
1407 }
1408 }
1409
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001410 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001411 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1412 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001413 if (isTransitionSet()) {
1414 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1415 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
1416 mNextAppTransitionPackage = null;
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001417 mDefaultNextAppTransitionAnimationSpec = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001418 mNextAppTransitionAnimationsSpecs.clear();
1419 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001420 if (specs != null) {
1421 for (int i = 0; i < specs.length; i++) {
1422 AppTransitionAnimationSpec spec = specs[i];
1423 if (spec != null) {
1424 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1425 if (i == 0) {
1426 // In full screen mode, the transition code depends on the default spec
1427 // to be set.
1428 Rect rect = spec.rect;
1429 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
1430 rect.width(), rect.height(), null);
1431 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001432 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001433 }
1434 }
1435 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001436 mNextAppTransitionCallback = onAnimationStartedCallback;
1437 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001438 } else {
1439 postAnimationCallback();
1440 }
1441 }
1442
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001443 void overridePendingAppTransitionMultiThumbFuture(
1444 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1445 boolean scaleUp) {
1446 if (isTransitionSet()) {
1447 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1448 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
1449 mNextAppTransitionPackage = null;
1450 mDefaultNextAppTransitionAnimationSpec = null;
1451 mNextAppTransitionAnimationsSpecs.clear();
1452 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1453 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001454 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001455 }
1456 }
1457
Winson Chung044d5292014-11-06 11:05:19 -08001458 void overrideInPlaceAppTransition(String packageName, int anim) {
1459 if (isTransitionSet()) {
1460 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1461 mNextAppTransitionPackage = packageName;
1462 mNextAppTransitionInPlace = anim;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001463 mAnimationFinishedCallback = null;
Winson Chung044d5292014-11-06 11:05:19 -08001464 } else {
1465 postAnimationCallback();
1466 }
1467 }
1468
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001469 /**
1470 * If a future is set for the app transition specs, fetch it in another thread.
1471 */
1472 private void fetchAppTransitionSpecsFromFuture() {
1473 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1474 mNextAppTransitionAnimationsSpecsPending = true;
1475 final IAppTransitionAnimationSpecsFuture future
1476 = mNextAppTransitionAnimationsSpecsFuture;
1477 mNextAppTransitionAnimationsSpecsFuture = null;
1478 mDefaultExecutor.execute(new Runnable() {
1479 @Override
1480 public void run() {
1481 AppTransitionAnimationSpec[] specs = null;
1482 try {
1483 specs = future.get();
1484 } catch (RemoteException e) {
1485 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1486 }
1487 synchronized (mServiceLock) {
1488 mNextAppTransitionAnimationsSpecsPending = false;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001489 overridePendingAppTransitionMultiThumb(specs,
1490 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1491 mNextAppTransitionScaleUp);
1492 mNextAppTransitionFutureCallback = null;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001493 mWindowSurfacePlacer.requestTraversal();
1494 }
1495 }
1496 });
1497 }
1498 }
1499
Craig Mautner164d4bb2012-11-26 13:51:23 -08001500 @Override
1501 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001502 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001503 }
1504
Craig Mautner4b71aa12012-12-27 17:20:01 -08001505 /**
1506 * Returns the human readable name of a window transition.
1507 *
1508 * @param transition The window transition.
1509 * @return The transition symbolic name.
1510 */
1511 public static String appTransitionToString(int transition) {
1512 switch (transition) {
1513 case TRANSIT_UNSET: {
1514 return "TRANSIT_UNSET";
1515 }
1516 case TRANSIT_NONE: {
1517 return "TRANSIT_NONE";
1518 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001519 case TRANSIT_ACTIVITY_OPEN: {
1520 return "TRANSIT_ACTIVITY_OPEN";
1521 }
1522 case TRANSIT_ACTIVITY_CLOSE: {
1523 return "TRANSIT_ACTIVITY_CLOSE";
1524 }
1525 case TRANSIT_TASK_OPEN: {
1526 return "TRANSIT_TASK_OPEN";
1527 }
1528 case TRANSIT_TASK_CLOSE: {
1529 return "TRANSIT_TASK_CLOSE";
1530 }
1531 case TRANSIT_TASK_TO_FRONT: {
1532 return "TRANSIT_TASK_TO_FRONT";
1533 }
1534 case TRANSIT_TASK_TO_BACK: {
1535 return "TRANSIT_TASK_TO_BACK";
1536 }
1537 case TRANSIT_WALLPAPER_CLOSE: {
1538 return "TRANSIT_WALLPAPER_CLOSE";
1539 }
1540 case TRANSIT_WALLPAPER_OPEN: {
1541 return "TRANSIT_WALLPAPER_OPEN";
1542 }
1543 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1544 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1545 }
1546 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1547 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1548 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001549 case TRANSIT_TASK_OPEN_BEHIND: {
1550 return "TRANSIT_TASK_OPEN_BEHIND";
1551 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001552 case TRANSIT_ACTIVITY_RELAUNCH: {
1553 return "TRANSIT_ACTIVITY_RELAUNCH";
1554 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001555 default: {
1556 return "<UNKNOWN>";
1557 }
1558 }
1559 }
1560
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001561 private String appStateToString() {
1562 switch (mAppTransitionState) {
1563 case APP_STATE_IDLE:
1564 return "APP_STATE_IDLE";
1565 case APP_STATE_READY:
1566 return "APP_STATE_READY";
1567 case APP_STATE_RUNNING:
1568 return "APP_STATE_RUNNING";
1569 case APP_STATE_TIMEOUT:
1570 return "APP_STATE_TIMEOUT";
1571 default:
1572 return "unknown state=" + mAppTransitionState;
1573 }
1574 }
1575
1576 private String transitTypeToString() {
1577 switch (mNextAppTransitionType) {
1578 case NEXT_TRANSIT_TYPE_NONE:
1579 return "NEXT_TRANSIT_TYPE_NONE";
1580 case NEXT_TRANSIT_TYPE_CUSTOM:
1581 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001582 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1583 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001584 case NEXT_TRANSIT_TYPE_SCALE_UP:
1585 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1586 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1587 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1588 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1589 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001590 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1591 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1592 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1593 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001594 default:
1595 return "unknown type=" + mNextAppTransitionType;
1596 }
1597 }
1598
Craig Mautner164d4bb2012-11-26 13:51:23 -08001599 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001600 public void dump(PrintWriter pw, String prefix) {
1601 pw.print(prefix); pw.println(this);
1602 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001603 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001604 pw.print(prefix); pw.print("mNextAppTransitionType=");
1605 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001606 }
1607 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001608 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001609 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001610 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001611 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001612 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1613 pw.print(" mNextAppTransitionExit=0x");
1614 pw.println(Integer.toHexString(mNextAppTransitionExit));
1615 break;
Winson Chung044d5292014-11-06 11:05:19 -08001616 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001617 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001618 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001619 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001620 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1621 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001622 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001623 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001624 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001625 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001626 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001627 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001628 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001629 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001630 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001631 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001632 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001633 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001634 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1635 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001636 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001637 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1638 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1639 pw.println(mDefaultNextAppTransitionAnimationSpec);
1640 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1641 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001642 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1643 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001644 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001645 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001646 }
1647 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001648 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1649 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001650 }
1651 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001652
1653 public void setCurrentUser(int newUserId) {
1654 mCurrentUserId = newUserId;
1655 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001656
1657 /**
1658 * @return true if transition is not running and should not be skipped, false if transition is
1659 * already running
1660 */
1661 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent) {
1662 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
1663 + " transit=" + appTransitionToString(transit)
1664 + " " + this
1665 + " alwaysKeepCurrent=" + alwaysKeepCurrent
1666 + " Callers=" + Debug.getCallers(3));
1667 if (!isTransitionSet() || mNextAppTransition == TRANSIT_NONE) {
1668 setAppTransition(transit);
1669 } else if (!alwaysKeepCurrent) {
1670 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
1671 // Opening a new task always supersedes a close for the anim.
1672 setAppTransition(transit);
1673 } else if (transit == TRANSIT_ACTIVITY_OPEN
1674 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
1675 // Opening a new activity always supersedes a close for the anim.
1676 setAppTransition(transit);
1677 }
1678 }
1679 boolean prepared = prepare();
1680 if (isTransitionSet()) {
1681 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
1682 mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
1683 }
1684 return prepared;
1685 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001686}