blob: 943c9ed39262fefe43ce507ef73cdf2da8f1d51c [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;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800142 private final WindowManagerService mService;
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();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100211
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800212 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800213 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800214 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800215 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
216 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700217 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
218 com.android.internal.R.interpolator.fast_out_linear_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800219 mConfigShortAnimTime = context.getResources().getInteger(
220 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800221 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
222 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700223 mThumbnailFadeInInterpolator = new Interpolator() {
224 @Override
225 public float getInterpolation(float input) {
226 // Linear response for first fraction, then complete after that.
227 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
228 return 0f;
229 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700230 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700231 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700232 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700233 }
234 };
235 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800236 @Override
237 public float getInterpolation(float input) {
238 // Linear response for first fraction, then complete after that.
239 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700240 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
241 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800242 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700243 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800244 }
245 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700246 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
247 * mContext.getResources().getDisplayMetrics().density);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800248 }
249
250 boolean isTransitionSet() {
251 return mNextAppTransition != TRANSIT_UNSET;
252 }
253
Craig Mautner164d4bb2012-11-26 13:51:23 -0800254 boolean isTransitionEqual(int transit) {
255 return mNextAppTransition == transit;
256 }
257
258 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800259 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800260 }
261
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700262 private void setAppTransition(int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800263 mNextAppTransition = transit;
264 }
265
266 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800267 return mAppTransitionState == APP_STATE_READY
268 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800269 }
270
Craig Mautnerae446592012-12-06 19:05:05 -0800271 void setReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800272 mAppTransitionState = APP_STATE_READY;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100273 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800274 }
275
276 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800277 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800278 }
279
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800280 void setIdle() {
281 mAppTransitionState = APP_STATE_IDLE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800282 }
283
284 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800285 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800286 }
287
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800288 void setTimeout() {
289 mAppTransitionState = APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800290 }
291
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700292 Bitmap getAppTransitionThumbnailHeader(int taskId) {
293 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800294 if (spec == null) {
295 spec = mDefaultNextAppTransitionAnimationSpec;
296 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700297 return spec != null ? spec.bitmap : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800298 }
299
Winson Chunga4ccb862014-08-22 15:26:27 -0700300 /** Returns whether the next thumbnail transition is aspect scaled up. */
301 boolean isNextThumbnailTransitionAspectScaled() {
302 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
303 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
304 }
305
306 /** Returns whether the next thumbnail transition is scaling up. */
307 boolean isNextThumbnailTransitionScaleUp() {
308 return mNextAppTransitionScaleUp;
309 }
310
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100311 /**
312 * @return true if and only if we are currently fetching app transition specs from the future
313 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
314 */
315 boolean isFetchingAppTransitionsSpecs() {
316 return mNextAppTransitionAnimationsSpecsPending;
317 }
318
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700319 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800320 if (!isRunning()) {
321 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100322 notifyAppTransitionPendingLocked();
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700323 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800324 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700325 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800326 }
327
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100328 void goodToGo(AppWindowAnimator openingAppAnimator, AppWindowAnimator closingAppAnimator) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800329 mNextAppTransition = TRANSIT_UNSET;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800330 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100331 notifyAppTransitionStartingLocked(
332 openingAppAnimator != null ? openingAppAnimator.mAppToken.token : null,
333 closingAppAnimator != null ? closingAppAnimator.mAppToken.token : null,
334 openingAppAnimator != null ? openingAppAnimator.animation : null,
335 closingAppAnimator != null ? closingAppAnimator.animation : null);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800336 }
337
338 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800339 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800340 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700341 mNextAppTransitionAnimationsSpecs.clear();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800342 }
343
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800344 void freeze() {
345 setAppTransition(AppTransition.TRANSIT_UNSET);
346 clear();
347 setReady();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100348 notifyAppTransitionCancelledLocked();
349 }
350
351 void registerListenerLocked(AppTransitionListener listener) {
352 mListeners.add(listener);
353 }
354
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700355 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100356 for (int i = 0; i < mListeners.size(); i++) {
357 mListeners.get(i).onAppTransitionFinishedLocked(token);
358 }
359 }
360
361 private void notifyAppTransitionPendingLocked() {
362 for (int i = 0; i < mListeners.size(); i++) {
363 mListeners.get(i).onAppTransitionPendingLocked();
364 }
365 }
366
367 private void notifyAppTransitionCancelledLocked() {
368 for (int i = 0; i < mListeners.size(); i++) {
369 mListeners.get(i).onAppTransitionCancelledLocked();
370 }
371 }
372
373 private void notifyAppTransitionStartingLocked(IBinder openToken,
374 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
375 for (int i = 0; i < mListeners.size(); i++) {
376 mListeners.get(i).onAppTransitionStartingLocked(openToken, closeToken, openAnimation,
377 closeAnimation);
378 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800379 }
380
Craig Mautner164d4bb2012-11-26 13:51:23 -0800381 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
382 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
383 + (lp != null ? lp.packageName : null)
384 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
385 if (lp != null && lp.windowAnimations != 0) {
386 // If this is a system resource, don't try to load it from the
387 // application resources. It is nice to avoid loading application
388 // resources if we can.
389 String packageName = lp.packageName != null ? lp.packageName : "android";
390 int resId = lp.windowAnimations;
391 if ((resId&0xFF000000) == 0x01000000) {
392 packageName = "android";
393 }
394 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
395 + packageName);
396 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700397 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800398 }
399 return null;
400 }
401
402 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
403 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
404 + packageName + " resId=0x" + Integer.toHexString(resId));
405 if (packageName != null) {
406 if ((resId&0xFF000000) == 0x01000000) {
407 packageName = "android";
408 }
409 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
410 + packageName);
411 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700412 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800413 }
414 return null;
415 }
416
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700417 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800418 int anim = 0;
419 Context context = mContext;
420 if (animAttr >= 0) {
421 AttributeCache.Entry ent = getCachedAnimations(lp);
422 if (ent != null) {
423 context = ent.context;
424 anim = ent.array.getResourceId(animAttr, 0);
425 }
426 }
427 if (anim != 0) {
428 return AnimationUtils.loadAnimation(context, anim);
429 }
430 return null;
431 }
432
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700433 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
434 Context context = mContext;
435 if (resId >= 0) {
436 AttributeCache.Entry ent = getCachedAnimations(lp);
437 if (ent != null) {
438 context = ent.context;
439 }
440 return AnimationUtils.loadAnimation(context, resId);
441 }
442 return null;
443 }
444
445 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800446 int anim = 0;
447 Context context = mContext;
448 if (resId >= 0) {
449 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
450 if (ent != null) {
451 context = ent.context;
452 anim = resId;
453 }
454 }
455 if (anim != 0) {
456 return AnimationUtils.loadAnimation(context, anim);
457 }
458 return null;
459 }
460
Craig Mautner164d4bb2012-11-26 13:51:23 -0800461 /**
462 * Compute the pivot point for an animation that is scaling from a small
463 * rect on screen to a larger rect. The pivot point varies depending on
464 * the distance between the inner and outer edges on both sides. This
465 * function computes the pivot point for one dimension.
466 * @param startPos Offset from left/top edge of outer rectangle to
467 * left/top edge of inner rectangle.
468 * @param finalScale The scaling factor between the size of the outer
469 * and inner rectangles.
470 */
471 private static float computePivot(int startPos, float finalScale) {
472 final float denom = finalScale-1;
473 if (Math.abs(denom) < .0001f) {
474 return startPos;
475 }
476 return -startPos / denom;
477 }
478
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700479 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
480 Rect containingFrame) {
481 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700482 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700483 final int appWidth = containingFrame.width();
484 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800485 if (enter) {
486 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700487 float scaleW = mTmpRect.width() / (float) appWidth;
488 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800489 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700490 computePivot(mTmpRect.left, scaleW),
491 computePivot(mTmpRect.right, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800492 scale.setInterpolator(mDecelerateInterpolator);
493
Craig Mautner164d4bb2012-11-26 13:51:23 -0800494 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700495 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800496
497 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800498 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800499 set.addAnimation(alpha);
500 set.setDetachWallpaper(true);
501 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800502 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
503 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800504 // If we are on top of the wallpaper, we need an animation that
505 // correctly handles the wallpaper staying static behind all of
506 // the animated elements. To do this, will just have the existing
507 // element fade out.
508 a = new AlphaAnimation(1, 0);
509 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800510 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800511 // For normal animations, the exiting element just holds in place.
512 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800513 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800514
515 // Pick the desired duration. If this is an inter-activity transition,
516 // it is the standard duration for that. Otherwise we use the longer
517 // task transition duration.
518 final long duration;
519 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800520 case TRANSIT_ACTIVITY_OPEN:
521 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800522 duration = mConfigShortAnimTime;
523 break;
524 default:
525 duration = DEFAULT_APP_TRANSITION_DURATION;
526 break;
527 }
528 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800529 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800530 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800531 a.initialize(appWidth, appHeight, appWidth, appHeight);
532 return a;
533 }
534
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700535 private void getDefaultNextAppTransitionStartRect(Rect rect) {
536 if (mDefaultNextAppTransitionAnimationSpec == null ||
537 mDefaultNextAppTransitionAnimationSpec.rect == null) {
538 Slog.wtf(TAG, "Starting rect for app requested, but none available", new Throwable());
539 rect.setEmpty();
540 } else {
541 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
542 }
543 }
544
545 void getNextAppTransitionStartRect(int taskId, Rect rect) {
546 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800547 if (spec == null) {
548 spec = mDefaultNextAppTransitionAnimationSpec;
549 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700550 if (spec == null || spec.rect == null) {
551 Slog.wtf(TAG, "Starting rect for task: " + taskId + " requested, but not available",
552 new Throwable());
553 rect.setEmpty();
554 } else {
555 rect.set(spec.rect);
556 }
557 }
558
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800559 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
560 Bitmap bitmap) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700561 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800562 bitmap, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700563 }
564
Craig Mautner80b1f642015-04-22 10:59:09 -0700565 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800566 final Animation anim;
567 if (enter) {
568 // Reveal will expand and move faster in horizontal direction
569
Craig Mautner80b1f642015-04-22 10:59:09 -0700570 final int appWidth = appFrame.width();
571 final int appHeight = appFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700572 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700573 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700574 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700575
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700576 float t = 0f;
577 if (appHeight > 0) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700578 t = (float) mTmpRect.left / appHeight;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700579 }
Filip Gruszczynski82861362015-10-16 14:21:09 -0700580 int translationY = mClipRevealTranslationY + (int)(appHeight / 7f * t);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700581
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700582 int centerX = mTmpRect.centerX();
583 int centerY = mTmpRect.centerY();
584 int halfWidth = mTmpRect.width() / 2;
585 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700586
587 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800588 Animation clipAnimLR = new ClipRectLRAnimation(
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700589 centerX - halfWidth, centerX + halfWidth, 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700590 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
591 clipAnimLR.setDuration((long) (DEFAULT_APP_TRANSITION_DURATION / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700592
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700593 Animation clipAnimTB = new ClipRectTBAnimation(centerY - halfHeight - translationY,
594 centerY + halfHeight/ 2 - translationY, 0, appHeight);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700595 clipAnimTB.setInterpolator(mTouchResponseInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800596 clipAnimTB.setDuration(DEFAULT_APP_TRANSITION_DURATION);
597
Filip Gruszczynski82861362015-10-16 14:21:09 -0700598 // We might be animating entrance of a docked task, so we need the translate to account
599 // for the app frame in which the window will reside. Every other calculation here
600 // is performed as if the window started at 0,0.
601 translationY -= appFrame.top;
602 TranslateAnimation translate = new TranslateAnimation(-appFrame.left, 0, translationY,
603 0);
604 translate.setInterpolator(mLinearOutSlowInInterpolator);
605 translate.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Chet Haase10e23ab2015-02-11 15:08:38 -0800606
607 // Quick fade-in from icon to app window
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700608 final int alphaDuration = DEFAULT_APP_TRANSITION_DURATION / 4;
609 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800610 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700611 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800612
613 AnimationSet set = new AnimationSet(false);
614 set.addAnimation(clipAnimLR);
615 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700616 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800617 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700618 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800619 set.initialize(appWidth, appHeight, appWidth, appHeight);
620 anim = set;
621 } else {
622 final long duration;
623 switch (transit) {
624 case TRANSIT_ACTIVITY_OPEN:
625 case TRANSIT_ACTIVITY_CLOSE:
626 duration = mConfigShortAnimTime;
627 break;
628 default:
629 duration = DEFAULT_APP_TRANSITION_DURATION;
630 break;
631 }
632 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
633 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
634 // If we are on top of the wallpaper, we need an animation that
635 // correctly handles the wallpaper staying static behind all of
636 // the animated elements. To do this, will just have the existing
637 // element fade out.
638 anim = new AlphaAnimation(1, 0);
639 anim.setDetachWallpaper(true);
640 } else {
641 // For normal animations, the exiting element just holds in place.
642 anim = new AlphaAnimation(1, 1);
643 }
644 anim.setInterpolator(mDecelerateInterpolator);
645 anim.setDuration(duration);
646 anim.setFillAfter(true);
647 }
648 return anim;
649 }
650
Winson Chung399f6202014-03-19 10:47:20 -0700651 /**
652 * Prepares the specified animation with a standard duration, interpolator, etc.
653 */
Winson Chung5393dff2014-05-08 14:25:43 -0700654 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
655 int duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700656 if (duration > 0) {
657 a.setDuration(duration);
658 }
Winson Chung5393dff2014-05-08 14:25:43 -0700659 a.setFillAfter(true);
660 a.setInterpolator(interpolator);
661 a.initialize(appWidth, appHeight, appWidth, appHeight);
662 return a;
663 }
664
665 /**
666 * Prepares the specified animation with a standard duration, interpolator, etc.
667 */
Winson Chung399f6202014-03-19 10:47:20 -0700668 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800669 // Pick the desired duration. If this is an inter-activity transition,
670 // it is the standard duration for that. Otherwise we use the longer
671 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700672 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800673 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800674 case TRANSIT_ACTIVITY_OPEN:
675 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800676 duration = mConfigShortAnimTime;
677 break;
678 default:
679 duration = DEFAULT_APP_TRANSITION_DURATION;
680 break;
681 }
Winson Chung5393dff2014-05-08 14:25:43 -0700682 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
683 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800684 }
685
Winson Chung399f6202014-03-19 10:47:20 -0700686 /**
687 * Return the current thumbnail transition state.
688 */
689 int getThumbnailTransitionState(boolean enter) {
690 if (enter) {
691 if (mNextAppTransitionScaleUp) {
692 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
693 } else {
694 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
695 }
696 } else {
697 if (mNextAppTransitionScaleUp) {
698 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
699 } else {
700 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
701 }
702 }
703 }
704
705 /**
706 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700707 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700708 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700709 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, Bitmap thumbnailHeader,
710 final int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700711 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700712 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700713 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700714 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chung399f6202014-03-19 10:47:20 -0700715 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700716 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700717
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700718 float scaleW = appWidth / thumbWidth;
Winson Chunga4ccb862014-08-22 15:26:27 -0700719 float unscaledHeight = thumbHeight * scaleW;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700720 getNextAppTransitionStartRect(taskId, mTmpRect);
721 float unscaledStartY = mTmpRect.top - (unscaledHeight - thumbHeight) / 2f;
Winson Chung399f6202014-03-19 10:47:20 -0700722 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700723 // Animation up from the thumbnail to the full screen
724 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700725 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700726 scale.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700727 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700728 Animation alpha = new AlphaAnimation(1, 0);
Winson Chunga4ccb862014-08-22 15:26:27 -0700729 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
730 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700731 final float toX = appRect.left + appRect.width() / 2 -
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700732 (mTmpRect.left + thumbWidth / 2);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700733 final float toY = appRect.top + mNextAppTransitionInsets.top + -unscaledStartY;
734 Animation translate = new TranslateAnimation(0, toX, 0, toY);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700735 translate.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700736 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700737
738 // This AnimationSet uses the Interpolators assigned above.
739 AnimationSet set = new AnimationSet(false);
740 set.addAnimation(scale);
741 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -0700742 set.addAnimation(translate);
Winson Chung399f6202014-03-19 10:47:20 -0700743 a = set;
744 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700745 // Animation down from the full screen to the thumbnail
746 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700747 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700748 scale.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700749 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
750 Animation alpha = new AlphaAnimation(0f, 1f);
751 alpha.setInterpolator(mThumbnailFadeInInterpolator);
752 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
753 Animation translate = new TranslateAnimation(0, 0, -unscaledStartY +
754 mNextAppTransitionInsets.top, 0);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700755 translate.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700756 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700757
Winson Chunga4ccb862014-08-22 15:26:27 -0700758 // This AnimationSet uses the Interpolators assigned above.
759 AnimationSet set = new AnimationSet(false);
760 set.addAnimation(scale);
761 set.addAnimation(alpha);
762 set.addAnimation(translate);
763 a = set;
764
765 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700766 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700767 mTouchResponseInterpolator);
Winson Chung399f6202014-03-19 10:47:20 -0700768 }
769
770 /**
771 * This alternate animation is created when we are doing a thumbnail transition, for the
772 * activity that is leaving, and the activity that is entering.
773 */
Winson Chunga4ccb862014-08-22 15:26:27 -0700774 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700775 int orientation, int transit, Rect containingFrame, Rect contentInsets,
776 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700777 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700778 final int appWidth = containingFrame.width();
779 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700780 getDefaultNextAppTransitionStartRect(mTmpRect);
781 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700782 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700783 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -0700784 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
785
Winson Chung2820c452014-04-15 15:34:44 -0700786 // Used for the ENTER_SCALE_UP and EXIT_SCALE_DOWN transitions
787 float scale = 1f;
788 int scaledTopDecor = 0;
789
Winson Chung399f6202014-03-19 10:47:20 -0700790 switch (thumbTransitState) {
791 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700792 if (freeform) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700793 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700794 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -0700795 } else {
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700796 mTmpFromClipRect.set(containingFrame);
797 // exclude top screen decor (status bar) region from the source clip.
798 mTmpFromClipRect.top = contentInsets.top;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700799 // App window scaling up to become full screen
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700800 mTmpToClipRect.set(containingFrame);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700801 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
802 // In portrait, we scale the width and clip to the top/left square
803 scale = thumbWidth / appWidth;
804 scaledTopDecor = (int) (scale * contentInsets.top);
805 int unscaledThumbHeight = (int) (thumbHeight / scale);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700806 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700807 } else {
Filip Gruszczynskidd2ff842015-10-25 13:11:04 -0700808 // In landscape, we scale the height and clip to the top/left square. We
809 // only scale the part that is not covered by status bar and the nav bar.
810 scale = thumbHeight / (appHeight - contentInsets.top
811 - contentInsets.bottom);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700812 scaledTopDecor = (int) (scale * contentInsets.top);
813 int unscaledThumbWidth = (int) (thumbWidth / scale);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700814 mTmpFromClipRect.right = mTmpFromClipRect.left + unscaledThumbWidth;
Filip Gruszczynskidd2ff842015-10-25 13:11:04 -0700815 // This removes the navigation bar from the first frame, so it better
816 // matches the thumbnail. We need to do this explicitly in landscape,
817 // because in portrait we already crop vertically.
818 mTmpFromClipRect.bottom = mTmpFromClipRect.bottom - contentInsets.bottom;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700819 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700820
821 mNextAppTransitionInsets.set(contentInsets);
822
823 Animation scaleAnim = new ScaleAnimation(scale, 1, scale, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700824 computePivot(mTmpRect.left, scale),
825 computePivot(mTmpRect.top, scale));
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700826 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
827 Animation translateAnim = new TranslateAnimation(0, 0, -scaledTopDecor, 0);
828
829 AnimationSet set = new AnimationSet(true);
830 set.addAnimation(clipAnim);
831 set.addAnimation(scaleAnim);
832 set.addAnimation(translateAnim);
833 a = set;
Winson Chung2820c452014-04-15 15:34:44 -0700834 }
Winson Chung399f6202014-03-19 10:47:20 -0700835 break;
836 }
837 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700838 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -0700839 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700840 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -0700841 // activity.
842 a = new AlphaAnimation(1, 0);
843 } else {
Winson Chung399f6202014-03-19 10:47:20 -0700844 a = new AlphaAnimation(1, 1);
845 }
846 break;
847 }
848 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700849 // Target app window during the scale down
850 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
851 // Fade in the destination activity if we are animating from a wallpaper
852 // activity.
853 a = new AlphaAnimation(0, 1);
854 } else {
855 a = new AlphaAnimation(1, 1);
856 }
Winson Chung399f6202014-03-19 10:47:20 -0700857 break;
858 }
859 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700860 // App window scaling down from full screen
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700861 if (freeform) {
862 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
863 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -0700864 } else {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700865 mTmpFromClipRect.set(containingFrame);
866 mTmpToClipRect.set(containingFrame);
867 // exclude top screen decor (status bar) region from the destination clip.
868 mTmpToClipRect.top = contentInsets.top;
869 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
870 // In portrait, we scale the width and clip to the top/left square
871 scale = thumbWidth / appWidth;
872 scaledTopDecor = (int) (scale * contentInsets.top);
873 int unscaledThumbHeight = (int) (thumbHeight / scale);
874 mTmpToClipRect.bottom = mTmpToClipRect.top + unscaledThumbHeight;
875 } else {
876 // In landscape, we scale the height and clip to the top/left square. We only
877 // scale the part that is not covered by status bar and the nav bar.
878 scale = thumbHeight / (appHeight - contentInsets.top - contentInsets.bottom);
879 scaledTopDecor = (int) (scale * contentInsets.top);
880 int unscaledThumbWidth = (int) (thumbWidth / scale);
881 mTmpToClipRect.right = mTmpToClipRect.left + unscaledThumbWidth;
882 // This removes the navigation bar from the last frame, so it better matches the
883 // thumbnail. We need to do this explicitly in landscape, because in portrait we
884 // already crop vertically.
885 mTmpToClipRect.bottom = mTmpToClipRect.bottom - contentInsets.bottom;
886 }
887
888 mNextAppTransitionInsets.set(contentInsets);
889
890 Animation scaleAnim = new ScaleAnimation(1, scale, 1, scale,
891 computePivot(mTmpRect.left, scale),
892 computePivot(mTmpRect.top, scale));
893 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
894 Animation translateAnim = new TranslateAnimation(0, 0, 0, -scaledTopDecor);
895
896 AnimationSet set = new AnimationSet(true);
897 set.addAnimation(clipAnim);
898 set.addAnimation(scaleAnim);
899 set.addAnimation(translateAnim);
900
901 a = set;
902 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -0700903 }
Winson Chung399f6202014-03-19 10:47:20 -0700904 break;
905 }
906 default:
907 throw new RuntimeException("Invalid thumbnail transition state");
908 }
909
Winson Chungab79fce2014-11-04 16:15:22 -0800910 int duration = Math.max(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION,
911 THUMBNAIL_APP_TRANSITION_DURATION);
912 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700913 mTouchResponseInterpolator);
Winson Chung399f6202014-03-19 10:47:20 -0700914 }
915
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700916 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
917 @Nullable Rect surfaceInsets, int taskId) {
918 getNextAppTransitionStartRect(taskId, mTmpRect);
919 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
920 true);
921 }
922
923 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
924 @Nullable Rect surfaceInsets, int taskId) {
925 getNextAppTransitionStartRect(taskId, mTmpRect);
926 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
927 false);
928 }
929
930 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
931 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
932 final float sourceWidth = sourceFrame.width();
933 final float sourceHeight = sourceFrame.height();
934 final float destWidth = destFrame.width();
935 final float destHeight = destFrame.height();
936 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
937 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700938 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700939 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700940 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700941 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700942 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
943 // We want the scaling to happen from the center of the surface. In order to achieve that,
944 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700945 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
946 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
947 final ScaleAnimation scale = enter ?
948 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
949 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
950 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
951 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
952 final int destHCenter = destFrame.left + destFrame.width() / 2;
953 final int destVCenter = destFrame.top + destFrame.height() / 2;
954 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
955 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
956 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
957 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700958 set.addAnimation(scale);
959 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700960
961 final IRemoteCallback callback = mAnimationFinishedCallback;
962 if (callback != null) {
963 set.setAnimationListener(new Animation.AnimationListener() {
964 @Override
965 public void onAnimationStart(Animation animation) { }
966
967 @Override
968 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800969 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700970 }
971
972 @Override
973 public void onAnimationRepeat(Animation animation) { }
974 });
975 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700976 return set;
977 }
978
Winson Chung399f6202014-03-19 10:47:20 -0700979 /**
Winson Chunga4ccb862014-08-22 15:26:27 -0700980 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700981 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -0700982 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700983 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
984 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700985 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700986 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700987 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -0700988 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700989 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -0700990 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
991
992 if (mNextAppTransitionScaleUp) {
993 // Animation for the thumbnail zooming from its initial size to the full screen
994 float scaleW = appWidth / thumbWidth;
995 float scaleH = appHeight / thumbHeight;
996 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700997 computePivot(mTmpRect.left, 1 / scaleW),
998 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -0700999 scale.setInterpolator(mDecelerateInterpolator);
1000
1001 Animation alpha = new AlphaAnimation(1, 0);
1002 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1003
1004 // This AnimationSet uses the Interpolators assigned above.
1005 AnimationSet set = new AnimationSet(false);
1006 set.addAnimation(scale);
1007 set.addAnimation(alpha);
1008 a = set;
1009 } else {
1010 // Animation for the thumbnail zooming down from the full screen to its final size
1011 float scaleW = appWidth / thumbWidth;
1012 float scaleH = appHeight / thumbHeight;
1013 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001014 computePivot(mTmpRect.left, 1 / scaleW),
1015 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001016 }
1017
1018 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1019 }
1020
1021 /**
Winson Chung399f6202014-03-19 10:47:20 -07001022 * This animation is created when we are doing a thumbnail transition, for the activity that is
1023 * leaving, and the activity that is entering.
1024 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001025 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1026 int transit, int taskId) {
1027 final int appWidth = containingFrame.width();
1028 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001029 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001030 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001031 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001032 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001033 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001034 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001035 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1036
1037 switch (thumbTransitState) {
1038 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1039 // Entering app scales up with the thumbnail
1040 float scaleW = thumbWidth / appWidth;
1041 float scaleH = thumbHeight / appHeight;
1042 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001043 computePivot(mTmpRect.left, scaleW),
1044 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001045 break;
1046 }
1047 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1048 // Exiting app while the thumbnail is scaling up should fade or stay in place
1049 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1050 // Fade out while bringing up selected activity. This keeps the
1051 // current activity from showing through a launching wallpaper
1052 // activity.
1053 a = new AlphaAnimation(1, 0);
1054 } else {
1055 // noop animation
1056 a = new AlphaAnimation(1, 1);
1057 }
1058 break;
1059 }
1060 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1061 // Entering the other app, it should just be visible while we scale the thumbnail
1062 // down above it
1063 a = new AlphaAnimation(1, 1);
1064 break;
1065 }
1066 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1067 // Exiting the current app, the app should scale down with the thumbnail
1068 float scaleW = thumbWidth / appWidth;
1069 float scaleH = thumbHeight / appHeight;
1070 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001071 computePivot(mTmpRect.left, scaleW),
1072 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001073
1074 Animation alpha = new AlphaAnimation(1, 0);
1075
1076 AnimationSet set = new AnimationSet(true);
1077 set.addAnimation(scale);
1078 set.addAnimation(alpha);
1079 set.setZAdjustment(Animation.ZORDER_TOP);
1080 a = set;
1081 break;
1082 }
1083 default:
1084 throw new RuntimeException("Invalid thumbnail transition state");
1085 }
1086
1087 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1088 }
1089
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001090 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001091 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1092 final int left = mTmpFromClipRect.left;
1093 final int top = mTmpFromClipRect.top;
1094 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001095 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1096 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001097 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001098 float fromWidth = mTmpFromClipRect.width();
1099 float toWidth = mTmpToClipRect.width();
1100 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001101 // While the window might span the whole display, the actual content will be cropped to the
1102 // system decoration frame, for example when the window is docked. We need to take into
1103 // account the visible height when constructing the animation.
1104 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1105 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001106 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1107 // The final window is larger in both dimensions than current window (e.g. we are
1108 // maximizing), so we can simply unclip the new window and there will be no disappearing
1109 // frame.
1110 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1111 } else {
1112 // The disappearing window has one larger dimension. We need to apply scaling, so the
1113 // first frame of the entry animation matches the old window.
1114 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001115 // We might not be going exactly full screen, but instead be aligned under the status
1116 // bar using cropping. We still need to account for the cropped part, which will also
1117 // be scaled.
1118 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001119 }
1120
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001121 // We animate the translation from the old position of the removed window, to the new
1122 // position of the added window. The latter might not be full screen, for example docked for
1123 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001124 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001125 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001126 set.addAnimation(translate);
1127 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001128 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001129 return set;
1130 }
1131
Jorim Jaggic554b772015-06-04 16:07:57 -07001132 /**
1133 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1134 * frame of the transition doesn't change the visuals on screen, so we can start
1135 * directly with the second one
1136 */
1137 boolean canSkipFirstFrame() {
1138 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1139 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
1140 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1141 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001142
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001143 /**
1144 *
1145 * @param frame These are the bounds of the window when it finishes the animation. This is where
1146 * the animation must usually finish in entrance animation, as the next frame will
1147 * display the window at these coordinates. In case of exit animation, this is
1148 * where the animation must start, as the frame before the animation is displaying
1149 * the window at these bounds.
1150 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1151 * window might be obscured, usually by the system windows (status bar and
1152 * navigation bar) and we use content insets to convey that information. This
1153 * usually affects the animation aspects vertically, as the system decoration is
1154 * at the top and the bottom. For example when we animate from full screen to
1155 * recents, we want to exclude the covered parts, because they won't match the
1156 * thumbnail after the last frame is executed.
1157 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1158 * know about this to make the animation frames match. We currently use
1159 * this for freeform windows, which have larger surfaces to display
1160 * shadows. When we animate them from recents, we want to match the content
1161 * to the recents thumbnail and hence need to account for the surface being
1162 * bigger.
1163 */
Craig Mautner164d4bb2012-11-26 13:51:23 -08001164 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001165 int orientation, Rect frame, Rect insets, @Nullable Rect surfaceInsets,
1166 boolean isVoiceInteraction, boolean freeform, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001167 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001168 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
1169 || transit == TRANSIT_TASK_OPEN
1170 || transit == TRANSIT_TASK_TO_FRONT)) {
1171 a = loadAnimationRes(lp, enter
1172 ? com.android.internal.R.anim.voice_activity_open_enter
1173 : com.android.internal.R.anim.voice_activity_open_exit);
1174 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1175 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001176 + " anim=" + a + " transit=" + appTransitionToString(transit)
1177 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001178 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1179 || transit == TRANSIT_TASK_CLOSE
1180 || transit == TRANSIT_TASK_TO_BACK)) {
1181 a = loadAnimationRes(lp, enter
1182 ? com.android.internal.R.anim.voice_activity_close_enter
1183 : com.android.internal.R.anim.voice_activity_close_exit);
1184 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1185 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001186 + " anim=" + a + " transit=" + appTransitionToString(transit)
1187 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001188 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001189 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001190 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1191 "applyAnimation:"
1192 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1193 + " transit=" + appTransitionToString(transit)
1194 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001195 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1196 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001197 mNextAppTransitionEnter : mNextAppTransitionExit);
1198 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1199 "applyAnimation:"
1200 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001201 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001202 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001203 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1204 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1205 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1206 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001207 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1208 + " transit=" + appTransitionToString(transit)
1209 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001210 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001211 a = createClipRevealAnimationLocked(transit, enter, frame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001212 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1213 "applyAnimation:"
1214 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001215 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001216 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001217 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001218 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001219 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1220 "applyAnimation:"
1221 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001222 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001223 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001224 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1225 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001226 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001227 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001228 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001229 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001230 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1231 String animName = mNextAppTransitionScaleUp ?
1232 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1233 Slog.v(TAG, "applyAnimation:"
1234 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001235 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001236 + " Callers=" + Debug.getCallers(3));
1237 }
1238 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1239 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1240 mNextAppTransitionScaleUp =
1241 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1242 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001243 getThumbnailTransitionState(enter), orientation, transit, frame,
1244 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001245 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1246 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001247 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001248 Slog.v(TAG, "applyAnimation:"
1249 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001250 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001251 + " Callers=" + Debug.getCallers(3));
1252 }
1253 } else {
1254 int animAttr = 0;
1255 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001256 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001257 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001258 ? WindowAnimation_activityOpenEnterAnimation
1259 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001260 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001261 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001262 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001263 ? WindowAnimation_activityCloseEnterAnimation
1264 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001265 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001266 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001267 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001268 ? WindowAnimation_taskOpenEnterAnimation
1269 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001270 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001271 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001272 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001273 ? WindowAnimation_taskCloseEnterAnimation
1274 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001275 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001276 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001277 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001278 ? WindowAnimation_taskToFrontEnterAnimation
1279 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001280 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001281 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001282 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001283 ? WindowAnimation_taskToBackEnterAnimation
1284 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001285 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001286 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001287 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001288 ? WindowAnimation_wallpaperOpenEnterAnimation
1289 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001290 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001291 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001292 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001293 ? WindowAnimation_wallpaperCloseEnterAnimation
1294 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001295 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001296 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001297 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001298 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1299 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001300 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001301 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001302 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001303 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1304 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001305 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001306 case TRANSIT_TASK_OPEN_BEHIND:
1307 animAttr = enter
1308 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001309 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001310 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001311 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001312 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1313 "applyAnimation:"
1314 + " anim=" + a
1315 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001316 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001317 + " Callers=" + Debug.getCallers(3));
1318 }
1319 return a;
1320 }
1321
1322 void postAnimationCallback() {
1323 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001324 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1325 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001326 mNextAppTransitionCallback = null;
1327 }
1328 }
1329
Filip Gruszczynskif74359d2015-11-11 10:12:04 -08001330 private void clearAppTransitionState() {
1331 mNextAppTransitionPackage = null;
1332 mNextAppTransitionAnimationsSpecs.clear();
1333 mDefaultNextAppTransitionAnimationSpec = null;
1334 mAnimationFinishedCallback = null;
1335 }
1336
Craig Mautner164d4bb2012-11-26 13:51:23 -08001337 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001338 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001339 if (isTransitionSet()) {
Filip Gruszczynskif74359d2015-11-11 10:12:04 -08001340 clearAppTransitionState();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001341 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001342 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001343 mNextAppTransitionEnter = enterAnim;
1344 mNextAppTransitionExit = exitAnim;
1345 postAnimationCallback();
1346 mNextAppTransitionCallback = startedCallback;
1347 } else {
1348 postAnimationCallback();
1349 }
1350 }
1351
1352 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001353 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001354 if (isTransitionSet()) {
Filip Gruszczynskif74359d2015-11-11 10:12:04 -08001355 clearAppTransitionState();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001356 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001357 putDefaultNextAppTransitionCoordinates(startX, startY, startX + startWidth,
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001358 startY + startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001359 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001360 }
1361 }
1362
Chet Haase10e23ab2015-02-11 15:08:38 -08001363 void overridePendingAppTransitionClipReveal(int startX, int startY,
1364 int startWidth, int startHeight) {
1365 if (isTransitionSet()) {
Filip Gruszczynskif74359d2015-11-11 10:12:04 -08001366 clearAppTransitionState();
Chet Haase10e23ab2015-02-11 15:08:38 -08001367 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();
Chet Haase10e23ab2015-02-11 15:08:38 -08001370 }
1371 }
1372
Craig Mautner164d4bb2012-11-26 13:51:23 -08001373 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1374 IRemoteCallback startedCallback, boolean scaleUp) {
1375 if (isTransitionSet()) {
Filip Gruszczynskif74359d2015-11-11 10:12:04 -08001376 clearAppTransitionState();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001377 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1378 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001379 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001380 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001381 postAnimationCallback();
1382 mNextAppTransitionCallback = startedCallback;
1383 } else {
1384 postAnimationCallback();
1385 }
1386 }
1387
Winson Chunga4ccb862014-08-22 15:26:27 -07001388 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001389 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001390 if (isTransitionSet()) {
Filip Gruszczynskif74359d2015-11-11 10:12:04 -08001391 clearAppTransitionState();
Winson Chunga4ccb862014-08-22 15:26:27 -07001392 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1393 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001394 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001395 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1396 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001397 postAnimationCallback();
1398 mNextAppTransitionCallback = startedCallback;
1399 } else {
1400 postAnimationCallback();
1401 }
1402 }
1403
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001404 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001405 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1406 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001407 if (isTransitionSet()) {
Filip Gruszczynskif74359d2015-11-11 10:12:04 -08001408 clearAppTransitionState();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001409 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1410 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001411 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001412 if (specs != null) {
1413 for (int i = 0; i < specs.length; i++) {
1414 AppTransitionAnimationSpec spec = specs[i];
1415 if (spec != null) {
1416 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1417 if (i == 0) {
1418 // In full screen mode, the transition code depends on the default spec
1419 // to be set.
1420 Rect rect = spec.rect;
1421 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
1422 rect.width(), rect.height(), null);
1423 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001424 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001425 }
1426 }
1427 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001428 mNextAppTransitionCallback = onAnimationStartedCallback;
1429 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001430 } else {
1431 postAnimationCallback();
1432 }
1433 }
1434
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001435 void overridePendingAppTransitionMultiThumbFuture(
1436 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1437 boolean scaleUp) {
1438 if (isTransitionSet()) {
Filip Gruszczynskif74359d2015-11-11 10:12:04 -08001439 clearAppTransitionState();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001440 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1441 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001442 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1443 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001444 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001445 }
1446 }
1447
Winson Chung044d5292014-11-06 11:05:19 -08001448 void overrideInPlaceAppTransition(String packageName, int anim) {
1449 if (isTransitionSet()) {
Filip Gruszczynskif74359d2015-11-11 10:12:04 -08001450 clearAppTransitionState();
Winson Chung044d5292014-11-06 11:05:19 -08001451 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1452 mNextAppTransitionPackage = packageName;
1453 mNextAppTransitionInPlace = anim;
1454 } else {
1455 postAnimationCallback();
1456 }
1457 }
1458
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001459 /**
1460 * If a future is set for the app transition specs, fetch it in another thread.
1461 */
1462 private void fetchAppTransitionSpecsFromFuture() {
1463 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1464 mNextAppTransitionAnimationsSpecsPending = true;
1465 final IAppTransitionAnimationSpecsFuture future
1466 = mNextAppTransitionAnimationsSpecsFuture;
1467 mNextAppTransitionAnimationsSpecsFuture = null;
1468 mDefaultExecutor.execute(new Runnable() {
1469 @Override
1470 public void run() {
1471 AppTransitionAnimationSpec[] specs = null;
1472 try {
1473 specs = future.get();
1474 } catch (RemoteException e) {
1475 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1476 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001477 synchronized (mService.mWindowMap) {
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001478 mNextAppTransitionAnimationsSpecsPending = false;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001479 overridePendingAppTransitionMultiThumb(specs,
1480 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1481 mNextAppTransitionScaleUp);
1482 mNextAppTransitionFutureCallback = null;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001483 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001484 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001485 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001486 }
1487 });
1488 }
1489 }
1490
Craig Mautner164d4bb2012-11-26 13:51:23 -08001491 @Override
1492 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001493 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001494 }
1495
Craig Mautner4b71aa12012-12-27 17:20:01 -08001496 /**
1497 * Returns the human readable name of a window transition.
1498 *
1499 * @param transition The window transition.
1500 * @return The transition symbolic name.
1501 */
1502 public static String appTransitionToString(int transition) {
1503 switch (transition) {
1504 case TRANSIT_UNSET: {
1505 return "TRANSIT_UNSET";
1506 }
1507 case TRANSIT_NONE: {
1508 return "TRANSIT_NONE";
1509 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001510 case TRANSIT_ACTIVITY_OPEN: {
1511 return "TRANSIT_ACTIVITY_OPEN";
1512 }
1513 case TRANSIT_ACTIVITY_CLOSE: {
1514 return "TRANSIT_ACTIVITY_CLOSE";
1515 }
1516 case TRANSIT_TASK_OPEN: {
1517 return "TRANSIT_TASK_OPEN";
1518 }
1519 case TRANSIT_TASK_CLOSE: {
1520 return "TRANSIT_TASK_CLOSE";
1521 }
1522 case TRANSIT_TASK_TO_FRONT: {
1523 return "TRANSIT_TASK_TO_FRONT";
1524 }
1525 case TRANSIT_TASK_TO_BACK: {
1526 return "TRANSIT_TASK_TO_BACK";
1527 }
1528 case TRANSIT_WALLPAPER_CLOSE: {
1529 return "TRANSIT_WALLPAPER_CLOSE";
1530 }
1531 case TRANSIT_WALLPAPER_OPEN: {
1532 return "TRANSIT_WALLPAPER_OPEN";
1533 }
1534 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1535 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1536 }
1537 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1538 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1539 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001540 case TRANSIT_TASK_OPEN_BEHIND: {
1541 return "TRANSIT_TASK_OPEN_BEHIND";
1542 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001543 case TRANSIT_ACTIVITY_RELAUNCH: {
1544 return "TRANSIT_ACTIVITY_RELAUNCH";
1545 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001546 default: {
1547 return "<UNKNOWN>";
1548 }
1549 }
1550 }
1551
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001552 private String appStateToString() {
1553 switch (mAppTransitionState) {
1554 case APP_STATE_IDLE:
1555 return "APP_STATE_IDLE";
1556 case APP_STATE_READY:
1557 return "APP_STATE_READY";
1558 case APP_STATE_RUNNING:
1559 return "APP_STATE_RUNNING";
1560 case APP_STATE_TIMEOUT:
1561 return "APP_STATE_TIMEOUT";
1562 default:
1563 return "unknown state=" + mAppTransitionState;
1564 }
1565 }
1566
1567 private String transitTypeToString() {
1568 switch (mNextAppTransitionType) {
1569 case NEXT_TRANSIT_TYPE_NONE:
1570 return "NEXT_TRANSIT_TYPE_NONE";
1571 case NEXT_TRANSIT_TYPE_CUSTOM:
1572 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001573 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1574 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001575 case NEXT_TRANSIT_TYPE_SCALE_UP:
1576 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1577 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1578 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1579 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1580 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001581 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1582 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1583 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1584 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001585 default:
1586 return "unknown type=" + mNextAppTransitionType;
1587 }
1588 }
1589
Craig Mautner164d4bb2012-11-26 13:51:23 -08001590 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001591 public void dump(PrintWriter pw, String prefix) {
1592 pw.print(prefix); pw.println(this);
1593 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001594 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001595 pw.print(prefix); pw.print("mNextAppTransitionType=");
1596 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001597 }
1598 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001599 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001600 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001601 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001602 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001603 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1604 pw.print(" mNextAppTransitionExit=0x");
1605 pw.println(Integer.toHexString(mNextAppTransitionExit));
1606 break;
Winson Chung044d5292014-11-06 11:05:19 -08001607 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001608 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001609 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001610 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001611 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1612 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001613 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001614 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001615 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001616 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001617 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001618 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001619 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001620 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001621 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001622 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001623 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001624 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001625 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1626 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001627 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001628 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1629 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1630 pw.println(mDefaultNextAppTransitionAnimationSpec);
1631 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1632 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001633 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1634 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001635 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001636 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001637 }
1638 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001639 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1640 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001641 }
1642 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001643
1644 public void setCurrentUser(int newUserId) {
1645 mCurrentUserId = newUserId;
1646 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001647
1648 /**
1649 * @return true if transition is not running and should not be skipped, false if transition is
1650 * already running
1651 */
1652 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent) {
1653 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
1654 + " transit=" + appTransitionToString(transit)
1655 + " " + this
1656 + " alwaysKeepCurrent=" + alwaysKeepCurrent
1657 + " Callers=" + Debug.getCallers(3));
1658 if (!isTransitionSet() || mNextAppTransition == TRANSIT_NONE) {
1659 setAppTransition(transit);
1660 } else if (!alwaysKeepCurrent) {
1661 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
1662 // Opening a new task always supersedes a close for the anim.
1663 setAppTransition(transit);
1664 } else if (transit == TRANSIT_ACTIVITY_OPEN
1665 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
1666 // Opening a new activity always supersedes a close for the anim.
1667 setAppTransition(transit);
1668 }
1669 }
1670 boolean prepared = prepare();
1671 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001672 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
1673 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001674 }
1675 return prepared;
1676 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001677}