blob: 182148758738676236414eb65b8b4ee60af34ee2 [file] [log] [blame]
Craig Mautner164d4bb2012-11-26 13:51:23 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Filip Gruszczynski82861362015-10-16 14:21:09 -070019import static android.view.WindowManagerInternal.AppTransitionListener;
20import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
21import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
22import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
23import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
24import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
25import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
26import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
27import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
28import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
29import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
30import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
31import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
32import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
33import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
34import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
35import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
36import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
37import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
38import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
39import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
40import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
41import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080042import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
43import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080044import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
45import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Filip Gruszczynski82861362015-10-16 14:21:09 -070046
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070047import android.annotation.Nullable;
Craig Mautner164d4bb2012-11-26 13:51:23 -080048import android.content.Context;
Winson Chung2820c452014-04-15 15:34:44 -070049import android.content.res.Configuration;
Craig Mautner164d4bb2012-11-26 13:51:23 -080050import android.graphics.Bitmap;
Winson Chung399f6202014-03-19 10:47:20 -070051import android.graphics.Rect;
Craig Mautner164d4bb2012-11-26 13:51:23 -080052import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010053import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080054import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010055import android.os.RemoteException;
Craig Mautner164d4bb2012-11-26 13:51:23 -080056import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070057import android.util.SparseArray;
58import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010059import android.view.IAppTransitionAnimationSpecsFuture;
Craig Mautner164d4bb2012-11-26 13:51:23 -080060import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080061import android.view.animation.AlphaAnimation;
62import android.view.animation.Animation;
63import android.view.animation.AnimationSet;
64import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070065import android.view.animation.ClipRectAnimation;
Chet Haase10e23ab2015-02-11 15:08:38 -080066import android.view.animation.ClipRectLRAnimation;
67import android.view.animation.ClipRectTBAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080068import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070069import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080070import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070071import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070072
Craig Mautner164d4bb2012-11-26 13:51:23 -080073import com.android.internal.util.DumpUtils.Dump;
74import com.android.server.AttributeCache;
75import com.android.server.wm.WindowManagerService.H;
76
77import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010078import java.util.ArrayList;
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -080079import java.util.Arrays;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010080import java.util.concurrent.ExecutorService;
81import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -080082
Craig Mautner164d4bb2012-11-26 13:51:23 -080083// State management of app transitions. When we are preparing for a
84// transition, mNextAppTransition will be the kind of transition to
85// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
86// mOpeningApps and mClosingApps are the lists of tokens that will be
87// made visible or hidden at the next transition.
88public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080089 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070090 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080091
Craig Mautner4b71aa12012-12-27 17:20:01 -080092 /** Not set up for a transition. */
93 public static final int TRANSIT_UNSET = -1;
94 /** No animation for transition. */
95 public static final int TRANSIT_NONE = 0;
96 /** 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 -070097 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -080098 /** The window in the top-most activity is being closed to reveal the
99 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700100 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800101 /** A window in a new task is being opened on top of an existing one
102 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700103 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800104 /** A window in the top-most activity is being closed to reveal the
105 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700106 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800107 /** A window in an existing task is being displayed on top of an existing one
108 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700109 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800110 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700111 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800112 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
113 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700114 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800115 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
116 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700117 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800118 /** A window in a new activity is being opened on top of an existing one, and both are on top
119 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700120 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800121 /** The window in the top-most activity is being closed to reveal the previous activity, and
122 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700123 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
124 /** A window in a new task is being opened behind an existing one in another activity's task.
125 * The new window will show briefly and then be gone. */
126 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800127 /** A window in a task is being animated in-place. */
128 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700129 /** An activity is being relaunched (e.g. due to configuration change). */
130 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800131
Winson Chunga4ccb862014-08-22 15:26:27 -0700132 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700133 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800134 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700135 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800136
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800137 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700138 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
139 private static final int THUMBNAIL_APP_TRANSITION_ALPHA_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700140 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800141
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800142 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800143 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800144
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800145 private int mNextAppTransition = TRANSIT_UNSET;
146
147 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
148 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
149 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
150 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
151 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700152 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
153 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800154 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800155 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800156 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
157
Winson Chung399f6202014-03-19 10:47:20 -0700158 // These are the possible states for the enter/exit activities during a thumbnail transition
159 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
160 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
161 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
162 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
163
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800164 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800165 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800166 private boolean mNextAppTransitionScaleUp;
167 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100168 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700169 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800170 private int mNextAppTransitionEnter;
171 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800172 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700173
174 // Keyed by task id.
175 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
176 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100177 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
178 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700179 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
180
Winson Chunga4ccb862014-08-22 15:26:27 -0700181 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800182
Winson Chung2820c452014-04-15 15:34:44 -0700183 private Rect mTmpFromClipRect = new Rect();
184 private Rect mTmpToClipRect = new Rect();
185
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700186 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700187
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800188 private final static int APP_STATE_IDLE = 0;
189 private final static int APP_STATE_READY = 1;
190 private final static int APP_STATE_RUNNING = 2;
191 private final static int APP_STATE_TIMEOUT = 3;
192 private int mAppTransitionState = APP_STATE_IDLE;
193
194 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800195 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700196 private final Interpolator mThumbnailFadeInInterpolator;
197 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800198 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700199 private final Interpolator mFastOutLinearInInterpolator;
200 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
201
202 /** Interpolator to be used for animations that respond directly to a touch */
203 private final Interpolator mTouchResponseInterpolator =
204 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
205
206 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800207
Amith Yamasani4befbec2013-07-10 16:18:01 -0700208 private int mCurrentUserId = 0;
209
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100210 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100211 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100212
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800213 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800214 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800215 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800216 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
217 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700218 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
219 com.android.internal.R.interpolator.fast_out_linear_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800220 mConfigShortAnimTime = context.getResources().getInteger(
221 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800222 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
223 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700224 mThumbnailFadeInInterpolator = new Interpolator() {
225 @Override
226 public float getInterpolation(float input) {
227 // Linear response for first fraction, then complete after that.
228 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
229 return 0f;
230 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700231 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700232 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700233 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700234 }
235 };
236 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800237 @Override
238 public float getInterpolation(float input) {
239 // Linear response for first fraction, then complete after that.
240 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700241 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
242 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800243 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700244 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800245 }
246 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700247 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
248 * mContext.getResources().getDisplayMetrics().density);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800249 }
250
251 boolean isTransitionSet() {
252 return mNextAppTransition != TRANSIT_UNSET;
253 }
254
Craig Mautner164d4bb2012-11-26 13:51:23 -0800255 boolean isTransitionEqual(int transit) {
256 return mNextAppTransition == transit;
257 }
258
259 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800260 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800261 }
262
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700263 private void setAppTransition(int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800264 mNextAppTransition = transit;
265 }
266
267 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800268 return mAppTransitionState == APP_STATE_READY
269 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800270 }
271
Craig Mautnerae446592012-12-06 19:05:05 -0800272 void setReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800273 mAppTransitionState = APP_STATE_READY;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100274 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800275 }
276
277 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800278 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800279 }
280
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800281 void setIdle() {
282 mAppTransitionState = APP_STATE_IDLE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800283 }
284
285 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800286 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800287 }
288
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800289 void setTimeout() {
290 mAppTransitionState = APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800291 }
292
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700293 Bitmap getAppTransitionThumbnailHeader(int taskId) {
294 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800295 if (spec == null) {
296 spec = mDefaultNextAppTransitionAnimationSpec;
297 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700298 return spec != null ? spec.bitmap : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800299 }
300
Winson Chunga4ccb862014-08-22 15:26:27 -0700301 /** Returns whether the next thumbnail transition is aspect scaled up. */
302 boolean isNextThumbnailTransitionAspectScaled() {
303 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
304 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
305 }
306
307 /** Returns whether the next thumbnail transition is scaling up. */
308 boolean isNextThumbnailTransitionScaleUp() {
309 return mNextAppTransitionScaleUp;
310 }
311
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800312 boolean isNextAppTransitionThumbnailUp() {
313 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
314 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
315 }
316
317 boolean isNextAppTransitionThumbnailDown() {
318 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
319 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
320 }
321
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100322 /**
323 * @return true if and only if we are currently fetching app transition specs from the future
324 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
325 */
326 boolean isFetchingAppTransitionsSpecs() {
327 return mNextAppTransitionAnimationsSpecsPending;
328 }
329
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700330 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800331 if (!isRunning()) {
332 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100333 notifyAppTransitionPendingLocked();
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700334 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800335 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700336 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800337 }
338
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100339 void goodToGo(AppWindowAnimator openingAppAnimator, AppWindowAnimator closingAppAnimator) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800340 mNextAppTransition = TRANSIT_UNSET;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800341 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100342 notifyAppTransitionStartingLocked(
343 openingAppAnimator != null ? openingAppAnimator.mAppToken.token : null,
344 closingAppAnimator != null ? closingAppAnimator.mAppToken.token : null,
345 openingAppAnimator != null ? openingAppAnimator.animation : null,
346 closingAppAnimator != null ? closingAppAnimator.animation : null);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800347 }
348
349 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800350 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800351 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700352 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi65193992015-11-23 16:49:59 -0800353 mNextAppTransitionAnimationsSpecsFuture = null;
354 mDefaultNextAppTransitionAnimationSpec = null;
355 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800356 }
357
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800358 void freeze() {
359 setAppTransition(AppTransition.TRANSIT_UNSET);
360 clear();
361 setReady();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100362 notifyAppTransitionCancelledLocked();
363 }
364
365 void registerListenerLocked(AppTransitionListener listener) {
366 mListeners.add(listener);
367 }
368
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700369 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100370 for (int i = 0; i < mListeners.size(); i++) {
371 mListeners.get(i).onAppTransitionFinishedLocked(token);
372 }
373 }
374
375 private void notifyAppTransitionPendingLocked() {
376 for (int i = 0; i < mListeners.size(); i++) {
377 mListeners.get(i).onAppTransitionPendingLocked();
378 }
379 }
380
381 private void notifyAppTransitionCancelledLocked() {
382 for (int i = 0; i < mListeners.size(); i++) {
383 mListeners.get(i).onAppTransitionCancelledLocked();
384 }
385 }
386
387 private void notifyAppTransitionStartingLocked(IBinder openToken,
388 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
389 for (int i = 0; i < mListeners.size(); i++) {
390 mListeners.get(i).onAppTransitionStartingLocked(openToken, closeToken, openAnimation,
391 closeAnimation);
392 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800393 }
394
Craig Mautner164d4bb2012-11-26 13:51:23 -0800395 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
396 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
397 + (lp != null ? lp.packageName : null)
398 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
399 if (lp != null && lp.windowAnimations != 0) {
400 // If this is a system resource, don't try to load it from the
401 // application resources. It is nice to avoid loading application
402 // resources if we can.
403 String packageName = lp.packageName != null ? lp.packageName : "android";
404 int resId = lp.windowAnimations;
405 if ((resId&0xFF000000) == 0x01000000) {
406 packageName = "android";
407 }
408 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
409 + packageName);
410 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700411 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800412 }
413 return null;
414 }
415
416 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
417 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
418 + packageName + " resId=0x" + Integer.toHexString(resId));
419 if (packageName != null) {
420 if ((resId&0xFF000000) == 0x01000000) {
421 packageName = "android";
422 }
423 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
424 + packageName);
425 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700426 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800427 }
428 return null;
429 }
430
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700431 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800432 int anim = 0;
433 Context context = mContext;
434 if (animAttr >= 0) {
435 AttributeCache.Entry ent = getCachedAnimations(lp);
436 if (ent != null) {
437 context = ent.context;
438 anim = ent.array.getResourceId(animAttr, 0);
439 }
440 }
441 if (anim != 0) {
442 return AnimationUtils.loadAnimation(context, anim);
443 }
444 return null;
445 }
446
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700447 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
448 Context context = mContext;
449 if (resId >= 0) {
450 AttributeCache.Entry ent = getCachedAnimations(lp);
451 if (ent != null) {
452 context = ent.context;
453 }
454 return AnimationUtils.loadAnimation(context, resId);
455 }
456 return null;
457 }
458
459 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800460 int anim = 0;
461 Context context = mContext;
462 if (resId >= 0) {
463 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
464 if (ent != null) {
465 context = ent.context;
466 anim = resId;
467 }
468 }
469 if (anim != 0) {
470 return AnimationUtils.loadAnimation(context, anim);
471 }
472 return null;
473 }
474
Craig Mautner164d4bb2012-11-26 13:51:23 -0800475 /**
476 * Compute the pivot point for an animation that is scaling from a small
477 * rect on screen to a larger rect. The pivot point varies depending on
478 * the distance between the inner and outer edges on both sides. This
479 * function computes the pivot point for one dimension.
480 * @param startPos Offset from left/top edge of outer rectangle to
481 * left/top edge of inner rectangle.
482 * @param finalScale The scaling factor between the size of the outer
483 * and inner rectangles.
484 */
485 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800486
487 /*
488 Theorem of intercepting lines:
489
490 + + +-----------------------------------------------+
491 | | | |
492 | | | |
493 | | | |
494 | | | |
495 x | y | | |
496 | | | |
497 | | | |
498 | | | |
499 | | | |
500 | + | +--------------------+ |
501 | | | | |
502 | | | | |
503 | | | | |
504 | | | | |
505 | | | | |
506 | | | | |
507 | | | | |
508 | | | | |
509 | | | | |
510 | | | | |
511 | | | | |
512 | | | | |
513 | | | | |
514 | | | | |
515 | | | | |
516 | | | | |
517 | | | | |
518 | | +--------------------+ |
519 | | |
520 | | |
521 | | |
522 | | |
523 | | |
524 | | |
525 | | |
526 | +-----------------------------------------------+
527 |
528 |
529 |
530 |
531 |
532 |
533 |
534 |
535 |
536 + ++
537 p ++
538
539 scale = (x - y) / x
540 <=> x = -y / (scale - 1)
541 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800542 final float denom = finalScale-1;
543 if (Math.abs(denom) < .0001f) {
544 return startPos;
545 }
546 return -startPos / denom;
547 }
548
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700549 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
550 Rect containingFrame) {
551 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700552 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700553 final int appWidth = containingFrame.width();
554 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800555 if (enter) {
556 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700557 float scaleW = mTmpRect.width() / (float) appWidth;
558 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800559 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700560 computePivot(mTmpRect.left, scaleW),
561 computePivot(mTmpRect.right, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800562 scale.setInterpolator(mDecelerateInterpolator);
563
Craig Mautner164d4bb2012-11-26 13:51:23 -0800564 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700565 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800566
567 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800568 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800569 set.addAnimation(alpha);
570 set.setDetachWallpaper(true);
571 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800572 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
573 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800574 // If we are on top of the wallpaper, we need an animation that
575 // correctly handles the wallpaper staying static behind all of
576 // the animated elements. To do this, will just have the existing
577 // element fade out.
578 a = new AlphaAnimation(1, 0);
579 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800580 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800581 // For normal animations, the exiting element just holds in place.
582 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800583 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800584
585 // Pick the desired duration. If this is an inter-activity transition,
586 // it is the standard duration for that. Otherwise we use the longer
587 // task transition duration.
588 final long duration;
589 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800590 case TRANSIT_ACTIVITY_OPEN:
591 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800592 duration = mConfigShortAnimTime;
593 break;
594 default:
595 duration = DEFAULT_APP_TRANSITION_DURATION;
596 break;
597 }
598 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800599 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800600 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800601 a.initialize(appWidth, appHeight, appWidth, appHeight);
602 return a;
603 }
604
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700605 private void getDefaultNextAppTransitionStartRect(Rect rect) {
606 if (mDefaultNextAppTransitionAnimationSpec == null ||
607 mDefaultNextAppTransitionAnimationSpec.rect == null) {
608 Slog.wtf(TAG, "Starting rect for app requested, but none available", new Throwable());
609 rect.setEmpty();
610 } else {
611 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
612 }
613 }
614
615 void getNextAppTransitionStartRect(int taskId, Rect rect) {
616 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800617 if (spec == null) {
618 spec = mDefaultNextAppTransitionAnimationSpec;
619 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700620 if (spec == null || spec.rect == null) {
621 Slog.wtf(TAG, "Starting rect for task: " + taskId + " requested, but not available",
622 new Throwable());
623 rect.setEmpty();
624 } else {
625 rect.set(spec.rect);
626 }
627 }
628
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800629 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
630 Bitmap bitmap) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700631 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800632 bitmap, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700633 }
634
Craig Mautner80b1f642015-04-22 10:59:09 -0700635 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800636 final Animation anim;
637 if (enter) {
638 // Reveal will expand and move faster in horizontal direction
639
Craig Mautner80b1f642015-04-22 10:59:09 -0700640 final int appWidth = appFrame.width();
641 final int appHeight = appFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700642 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700643 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700644 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700645
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700646 float t = 0f;
647 if (appHeight > 0) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700648 t = (float) mTmpRect.left / appHeight;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700649 }
Filip Gruszczynski82861362015-10-16 14:21:09 -0700650 int translationY = mClipRevealTranslationY + (int)(appHeight / 7f * t);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700651
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700652 int centerX = mTmpRect.centerX();
653 int centerY = mTmpRect.centerY();
654 int halfWidth = mTmpRect.width() / 2;
655 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700656
657 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800658 Animation clipAnimLR = new ClipRectLRAnimation(
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700659 centerX - halfWidth, centerX + halfWidth, 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700660 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
661 clipAnimLR.setDuration((long) (DEFAULT_APP_TRANSITION_DURATION / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700662
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700663 Animation clipAnimTB = new ClipRectTBAnimation(centerY - halfHeight - translationY,
664 centerY + halfHeight/ 2 - translationY, 0, appHeight);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700665 clipAnimTB.setInterpolator(mTouchResponseInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800666 clipAnimTB.setDuration(DEFAULT_APP_TRANSITION_DURATION);
667
Filip Gruszczynski82861362015-10-16 14:21:09 -0700668 // We might be animating entrance of a docked task, so we need the translate to account
669 // for the app frame in which the window will reside. Every other calculation here
670 // is performed as if the window started at 0,0.
671 translationY -= appFrame.top;
672 TranslateAnimation translate = new TranslateAnimation(-appFrame.left, 0, translationY,
673 0);
674 translate.setInterpolator(mLinearOutSlowInInterpolator);
675 translate.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Chet Haase10e23ab2015-02-11 15:08:38 -0800676
677 // Quick fade-in from icon to app window
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700678 final int alphaDuration = DEFAULT_APP_TRANSITION_DURATION / 4;
679 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800680 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700681 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800682
683 AnimationSet set = new AnimationSet(false);
684 set.addAnimation(clipAnimLR);
685 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700686 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800687 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700688 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800689 set.initialize(appWidth, appHeight, appWidth, appHeight);
690 anim = set;
691 } else {
692 final long duration;
693 switch (transit) {
694 case TRANSIT_ACTIVITY_OPEN:
695 case TRANSIT_ACTIVITY_CLOSE:
696 duration = mConfigShortAnimTime;
697 break;
698 default:
699 duration = DEFAULT_APP_TRANSITION_DURATION;
700 break;
701 }
702 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
703 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
704 // If we are on top of the wallpaper, we need an animation that
705 // correctly handles the wallpaper staying static behind all of
706 // the animated elements. To do this, will just have the existing
707 // element fade out.
708 anim = new AlphaAnimation(1, 0);
709 anim.setDetachWallpaper(true);
710 } else {
711 // For normal animations, the exiting element just holds in place.
712 anim = new AlphaAnimation(1, 1);
713 }
714 anim.setInterpolator(mDecelerateInterpolator);
715 anim.setDuration(duration);
716 anim.setFillAfter(true);
717 }
718 return anim;
719 }
720
Winson Chung399f6202014-03-19 10:47:20 -0700721 /**
722 * Prepares the specified animation with a standard duration, interpolator, etc.
723 */
Winson Chung5393dff2014-05-08 14:25:43 -0700724 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
725 int duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700726 if (duration > 0) {
727 a.setDuration(duration);
728 }
Winson Chung5393dff2014-05-08 14:25:43 -0700729 a.setFillAfter(true);
730 a.setInterpolator(interpolator);
731 a.initialize(appWidth, appHeight, appWidth, appHeight);
732 return a;
733 }
734
735 /**
736 * Prepares the specified animation with a standard duration, interpolator, etc.
737 */
Winson Chung399f6202014-03-19 10:47:20 -0700738 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800739 // Pick the desired duration. If this is an inter-activity transition,
740 // it is the standard duration for that. Otherwise we use the longer
741 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700742 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800743 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800744 case TRANSIT_ACTIVITY_OPEN:
745 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800746 duration = mConfigShortAnimTime;
747 break;
748 default:
749 duration = DEFAULT_APP_TRANSITION_DURATION;
750 break;
751 }
Winson Chung5393dff2014-05-08 14:25:43 -0700752 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
753 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800754 }
755
Winson Chung399f6202014-03-19 10:47:20 -0700756 /**
757 * Return the current thumbnail transition state.
758 */
759 int getThumbnailTransitionState(boolean enter) {
760 if (enter) {
761 if (mNextAppTransitionScaleUp) {
762 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
763 } else {
764 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
765 }
766 } else {
767 if (mNextAppTransitionScaleUp) {
768 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
769 } else {
770 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
771 }
772 }
773 }
774
775 /**
776 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700777 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700778 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700779 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, Bitmap thumbnailHeader,
780 final int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700781 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700782 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700783 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700784 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chung399f6202014-03-19 10:47:20 -0700785 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700786 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700787
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700788 float scaleW = appWidth / thumbWidth;
Winson Chunga4ccb862014-08-22 15:26:27 -0700789 float unscaledHeight = thumbHeight * scaleW;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700790 getNextAppTransitionStartRect(taskId, mTmpRect);
Filip Gruszczynski565a9df2016-01-22 11:10:42 -0800791 final float unscaledStartY = mTmpRect.top - (unscaledHeight - thumbHeight) / 2f;
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800792 final float toY = appRect.top + -unscaledStartY;
Winson Chung399f6202014-03-19 10:47:20 -0700793 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700794 // Animation up from the thumbnail to the full screen
795 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700796 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700797 scale.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700798 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800799 Animation alpha = new AlphaAnimation(1f, 0f);
Winson Chunga4ccb862014-08-22 15:26:27 -0700800 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
801 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700802 final float toX = appRect.left + appRect.width() / 2 -
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700803 (mTmpRect.left + thumbWidth / 2);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700804 Animation translate = new TranslateAnimation(0, toX, 0, toY);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700805 translate.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700806 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700807
808 // This AnimationSet uses the Interpolators assigned above.
809 AnimationSet set = new AnimationSet(false);
810 set.addAnimation(scale);
811 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -0700812 set.addAnimation(translate);
Winson Chung399f6202014-03-19 10:47:20 -0700813 a = set;
814 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700815 // Animation down from the full screen to the thumbnail
816 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700817 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700818 scale.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700819 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
820 Animation alpha = new AlphaAnimation(0f, 1f);
821 alpha.setInterpolator(mThumbnailFadeInInterpolator);
822 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
Filip Gruszczynski565a9df2016-01-22 11:10:42 -0800823 final float toX = appRect.left + appRect.width() / 2 -
824 (mTmpRect.left + thumbWidth / 2);
825 Animation translate = new TranslateAnimation(toX, 0, toY, 0);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700826 translate.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700827 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700828
Winson Chunga4ccb862014-08-22 15:26:27 -0700829 // This AnimationSet uses the Interpolators assigned above.
830 AnimationSet set = new AnimationSet(false);
831 set.addAnimation(scale);
832 set.addAnimation(alpha);
833 set.addAnimation(translate);
834 a = set;
835
836 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700837 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700838 mTouchResponseInterpolator);
Winson Chung399f6202014-03-19 10:47:20 -0700839 }
840
841 /**
842 * This alternate animation is created when we are doing a thumbnail transition, for the
843 * activity that is leaving, and the activity that is entering.
844 */
Winson Chunga4ccb862014-08-22 15:26:27 -0700845 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700846 int orientation, int transit, Rect containingFrame, Rect contentInsets,
847 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700848 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700849 final int appWidth = containingFrame.width();
850 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700851 getDefaultNextAppTransitionStartRect(mTmpRect);
852 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700853 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700854 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -0700855 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
856
Winson Chung2820c452014-04-15 15:34:44 -0700857 // Used for the ENTER_SCALE_UP and EXIT_SCALE_DOWN transitions
858 float scale = 1f;
859 int scaledTopDecor = 0;
860
Winson Chung399f6202014-03-19 10:47:20 -0700861 switch (thumbTransitState) {
862 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700863 if (freeform) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700864 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700865 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -0700866 } else {
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700867 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700868 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800869
870 // Containing frame is in screen space, but we need the clip rect in the
871 // app space.
872 mTmpFromClipRect.offsetTo(0, 0);
873 mTmpToClipRect.offsetTo(0, 0);
874
875 // Exclude insets region from the source clip.
876 mTmpFromClipRect.inset(contentInsets);
877
878 // We scale the width and clip to the top/left square
879 scale = thumbWidth / (appWidth - contentInsets.left - contentInsets.right);
880 scaledTopDecor = (int) (scale * contentInsets.top);
881 int unscaledThumbHeight = (int) (thumbHeight / scale);
882 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700883
884 mNextAppTransitionInsets.set(contentInsets);
885
886 Animation scaleAnim = new ScaleAnimation(scale, 1, scale, 1,
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800887 computePivot(mTmpRect.left - containingFrame.left, scale),
888 computePivot(mTmpRect.top - containingFrame.top, scale));
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700889 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
890 Animation translateAnim = new TranslateAnimation(0, 0, -scaledTopDecor, 0);
891
892 AnimationSet set = new AnimationSet(true);
893 set.addAnimation(clipAnim);
894 set.addAnimation(scaleAnim);
895 set.addAnimation(translateAnim);
896 a = set;
Winson Chung2820c452014-04-15 15:34:44 -0700897 }
Winson Chung399f6202014-03-19 10:47:20 -0700898 break;
899 }
900 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700901 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -0700902 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700903 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -0700904 // activity.
905 a = new AlphaAnimation(1, 0);
906 } else {
Winson Chung399f6202014-03-19 10:47:20 -0700907 a = new AlphaAnimation(1, 1);
908 }
909 break;
910 }
911 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700912 // Target app window during the scale down
913 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
914 // Fade in the destination activity if we are animating from a wallpaper
915 // activity.
916 a = new AlphaAnimation(0, 1);
917 } else {
918 a = new AlphaAnimation(1, 1);
919 }
Winson Chung399f6202014-03-19 10:47:20 -0700920 break;
921 }
922 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700923 // App window scaling down from full screen
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700924 if (freeform) {
925 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
926 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -0700927 } else {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700928 mTmpFromClipRect.set(containingFrame);
929 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800930
931 // Containing frame is in screen space, but we need the clip rect in the
932 // app space.
933 mTmpFromClipRect.offsetTo(0, 0);
934 mTmpToClipRect.offsetTo(0, 0);
935
936 // Exclude insets region from the target clip.
937 mTmpToClipRect.inset(contentInsets);
938
939 // We scale the width and clip to the top/left square
940 scale = thumbWidth / (appWidth - contentInsets.left - contentInsets.right);
941 scaledTopDecor = (int) (scale * contentInsets.top);
942 int unscaledThumbHeight = (int) (thumbHeight / scale);
943 mTmpToClipRect.bottom = mTmpToClipRect.top + unscaledThumbHeight;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700944
945 mNextAppTransitionInsets.set(contentInsets);
946
947 Animation scaleAnim = new ScaleAnimation(1, scale, 1, scale,
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800948 computePivot(mTmpRect.left - containingFrame.left, scale),
949 computePivot(mTmpRect.top - containingFrame.top, scale));
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700950 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
951 Animation translateAnim = new TranslateAnimation(0, 0, 0, -scaledTopDecor);
952
953 AnimationSet set = new AnimationSet(true);
954 set.addAnimation(clipAnim);
955 set.addAnimation(scaleAnim);
956 set.addAnimation(translateAnim);
957
958 a = set;
959 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -0700960 }
Winson Chung399f6202014-03-19 10:47:20 -0700961 break;
962 }
963 default:
964 throw new RuntimeException("Invalid thumbnail transition state");
965 }
966
Winson Chungab79fce2014-11-04 16:15:22 -0800967 int duration = Math.max(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION,
968 THUMBNAIL_APP_TRANSITION_DURATION);
969 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700970 mTouchResponseInterpolator);
Winson Chung399f6202014-03-19 10:47:20 -0700971 }
972
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700973 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
974 @Nullable Rect surfaceInsets, int taskId) {
975 getNextAppTransitionStartRect(taskId, mTmpRect);
976 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
977 true);
978 }
979
980 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
981 @Nullable Rect surfaceInsets, int taskId) {
982 getNextAppTransitionStartRect(taskId, mTmpRect);
983 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
984 false);
985 }
986
987 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
988 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
989 final float sourceWidth = sourceFrame.width();
990 final float sourceHeight = sourceFrame.height();
991 final float destWidth = destFrame.width();
992 final float destHeight = destFrame.height();
993 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
994 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700995 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700996 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700997 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700998 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700999 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1000 // We want the scaling to happen from the center of the surface. In order to achieve that,
1001 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001002 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1003 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1004 final ScaleAnimation scale = enter ?
1005 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1006 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1007 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1008 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1009 final int destHCenter = destFrame.left + destFrame.width() / 2;
1010 final int destVCenter = destFrame.top + destFrame.height() / 2;
1011 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1012 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1013 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1014 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001015 set.addAnimation(scale);
1016 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001017
1018 final IRemoteCallback callback = mAnimationFinishedCallback;
1019 if (callback != null) {
1020 set.setAnimationListener(new Animation.AnimationListener() {
1021 @Override
1022 public void onAnimationStart(Animation animation) { }
1023
1024 @Override
1025 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001026 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001027 }
1028
1029 @Override
1030 public void onAnimationRepeat(Animation animation) { }
1031 });
1032 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001033 return set;
1034 }
1035
Winson Chung399f6202014-03-19 10:47:20 -07001036 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001037 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001038 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001039 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001040 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
1041 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001042 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001043 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001044 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001045 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001046 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001047 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1048
1049 if (mNextAppTransitionScaleUp) {
1050 // Animation for the thumbnail zooming from its initial size to the full screen
1051 float scaleW = appWidth / thumbWidth;
1052 float scaleH = appHeight / thumbHeight;
1053 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001054 computePivot(mTmpRect.left, 1 / scaleW),
1055 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001056 scale.setInterpolator(mDecelerateInterpolator);
1057
1058 Animation alpha = new AlphaAnimation(1, 0);
1059 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1060
1061 // This AnimationSet uses the Interpolators assigned above.
1062 AnimationSet set = new AnimationSet(false);
1063 set.addAnimation(scale);
1064 set.addAnimation(alpha);
1065 a = set;
1066 } else {
1067 // Animation for the thumbnail zooming down from the full screen to its final size
1068 float scaleW = appWidth / thumbWidth;
1069 float scaleH = appHeight / thumbHeight;
1070 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001071 computePivot(mTmpRect.left, 1 / scaleW),
1072 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001073 }
1074
1075 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1076 }
1077
1078 /**
Winson Chung399f6202014-03-19 10:47:20 -07001079 * This animation is created when we are doing a thumbnail transition, for the activity that is
1080 * leaving, and the activity that is entering.
1081 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001082 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1083 int transit, int taskId) {
1084 final int appWidth = containingFrame.width();
1085 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001086 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001087 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001088 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001089 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001090 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001091 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001092 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1093
1094 switch (thumbTransitState) {
1095 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1096 // Entering app scales up with the thumbnail
1097 float scaleW = thumbWidth / appWidth;
1098 float scaleH = thumbHeight / appHeight;
1099 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001100 computePivot(mTmpRect.left, scaleW),
1101 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001102 break;
1103 }
1104 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1105 // Exiting app while the thumbnail is scaling up should fade or stay in place
1106 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1107 // Fade out while bringing up selected activity. This keeps the
1108 // current activity from showing through a launching wallpaper
1109 // activity.
1110 a = new AlphaAnimation(1, 0);
1111 } else {
1112 // noop animation
1113 a = new AlphaAnimation(1, 1);
1114 }
1115 break;
1116 }
1117 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1118 // Entering the other app, it should just be visible while we scale the thumbnail
1119 // down above it
1120 a = new AlphaAnimation(1, 1);
1121 break;
1122 }
1123 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1124 // Exiting the current app, the app should scale down with the thumbnail
1125 float scaleW = thumbWidth / appWidth;
1126 float scaleH = thumbHeight / appHeight;
1127 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001128 computePivot(mTmpRect.left, scaleW),
1129 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001130
1131 Animation alpha = new AlphaAnimation(1, 0);
1132
1133 AnimationSet set = new AnimationSet(true);
1134 set.addAnimation(scale);
1135 set.addAnimation(alpha);
1136 set.setZAdjustment(Animation.ZORDER_TOP);
1137 a = set;
1138 break;
1139 }
1140 default:
1141 throw new RuntimeException("Invalid thumbnail transition state");
1142 }
1143
1144 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1145 }
1146
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001147 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001148 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1149 final int left = mTmpFromClipRect.left;
1150 final int top = mTmpFromClipRect.top;
1151 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001152 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1153 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001154 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001155 float fromWidth = mTmpFromClipRect.width();
1156 float toWidth = mTmpToClipRect.width();
1157 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001158 // While the window might span the whole display, the actual content will be cropped to the
1159 // system decoration frame, for example when the window is docked. We need to take into
1160 // account the visible height when constructing the animation.
1161 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1162 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001163 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1164 // The final window is larger in both dimensions than current window (e.g. we are
1165 // maximizing), so we can simply unclip the new window and there will be no disappearing
1166 // frame.
1167 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1168 } else {
1169 // The disappearing window has one larger dimension. We need to apply scaling, so the
1170 // first frame of the entry animation matches the old window.
1171 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001172 // We might not be going exactly full screen, but instead be aligned under the status
1173 // bar using cropping. We still need to account for the cropped part, which will also
1174 // be scaled.
1175 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001176 }
1177
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001178 // We animate the translation from the old position of the removed window, to the new
1179 // position of the added window. The latter might not be full screen, for example docked for
1180 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001181 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001182 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001183 set.addAnimation(translate);
1184 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001185 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001186 return set;
1187 }
1188
Jorim Jaggic554b772015-06-04 16:07:57 -07001189 /**
1190 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1191 * frame of the transition doesn't change the visuals on screen, so we can start
1192 * directly with the second one
1193 */
1194 boolean canSkipFirstFrame() {
1195 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1196 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
1197 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1198 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001199
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001200 /**
1201 *
1202 * @param frame These are the bounds of the window when it finishes the animation. This is where
1203 * the animation must usually finish in entrance animation, as the next frame will
1204 * display the window at these coordinates. In case of exit animation, this is
1205 * where the animation must start, as the frame before the animation is displaying
1206 * the window at these bounds.
1207 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1208 * window might be obscured, usually by the system windows (status bar and
1209 * navigation bar) and we use content insets to convey that information. This
1210 * usually affects the animation aspects vertically, as the system decoration is
1211 * at the top and the bottom. For example when we animate from full screen to
1212 * recents, we want to exclude the covered parts, because they won't match the
1213 * thumbnail after the last frame is executed.
1214 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1215 * know about this to make the animation frames match. We currently use
1216 * this for freeform windows, which have larger surfaces to display
1217 * shadows. When we animate them from recents, we want to match the content
1218 * to the recents thumbnail and hence need to account for the surface being
1219 * bigger.
1220 */
Craig Mautner164d4bb2012-11-26 13:51:23 -08001221 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001222 int orientation, Rect frame, Rect insets, @Nullable Rect surfaceInsets,
1223 boolean isVoiceInteraction, boolean freeform, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001224 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001225 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
1226 || transit == TRANSIT_TASK_OPEN
1227 || transit == TRANSIT_TASK_TO_FRONT)) {
1228 a = loadAnimationRes(lp, enter
1229 ? com.android.internal.R.anim.voice_activity_open_enter
1230 : com.android.internal.R.anim.voice_activity_open_exit);
1231 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1232 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001233 + " anim=" + a + " transit=" + appTransitionToString(transit)
1234 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001235 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1236 || transit == TRANSIT_TASK_CLOSE
1237 || transit == TRANSIT_TASK_TO_BACK)) {
1238 a = loadAnimationRes(lp, enter
1239 ? com.android.internal.R.anim.voice_activity_close_enter
1240 : com.android.internal.R.anim.voice_activity_close_exit);
1241 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1242 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001243 + " anim=" + a + " transit=" + appTransitionToString(transit)
1244 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001245 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001246 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001247 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1248 "applyAnimation:"
1249 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1250 + " transit=" + appTransitionToString(transit)
1251 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001252 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1253 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001254 mNextAppTransitionEnter : mNextAppTransitionExit);
1255 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1256 "applyAnimation:"
1257 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001258 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001259 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001260 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1261 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1262 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1263 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001264 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1265 + " transit=" + appTransitionToString(transit)
1266 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001267 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001268 a = createClipRevealAnimationLocked(transit, enter, frame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001269 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1270 "applyAnimation:"
1271 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001272 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001273 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001274 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001275 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001276 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1277 "applyAnimation:"
1278 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001279 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001280 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001281 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1282 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001283 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001284 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001285 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001286 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001287 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1288 String animName = mNextAppTransitionScaleUp ?
1289 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1290 Slog.v(TAG, "applyAnimation:"
1291 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001292 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001293 + " Callers=" + Debug.getCallers(3));
1294 }
1295 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1296 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1297 mNextAppTransitionScaleUp =
1298 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1299 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001300 getThumbnailTransitionState(enter), orientation, transit, frame,
1301 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001302 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1303 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001304 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001305 Slog.v(TAG, "applyAnimation:"
1306 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001307 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001308 + " Callers=" + Debug.getCallers(3));
1309 }
1310 } else {
1311 int animAttr = 0;
1312 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001313 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001314 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001315 ? WindowAnimation_activityOpenEnterAnimation
1316 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001317 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001318 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001319 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001320 ? WindowAnimation_activityCloseEnterAnimation
1321 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001322 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001323 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001324 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001325 ? WindowAnimation_taskOpenEnterAnimation
1326 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001327 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001328 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001329 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001330 ? WindowAnimation_taskCloseEnterAnimation
1331 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001332 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001333 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001334 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001335 ? WindowAnimation_taskToFrontEnterAnimation
1336 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001337 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001338 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001339 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001340 ? WindowAnimation_taskToBackEnterAnimation
1341 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001342 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001343 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001344 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001345 ? WindowAnimation_wallpaperOpenEnterAnimation
1346 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001347 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001348 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001349 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001350 ? WindowAnimation_wallpaperCloseEnterAnimation
1351 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001352 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001353 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001354 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001355 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1356 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001357 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001358 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001359 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001360 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1361 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001362 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001363 case TRANSIT_TASK_OPEN_BEHIND:
1364 animAttr = enter
1365 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001366 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001367 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001368 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001369 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1370 "applyAnimation:"
1371 + " anim=" + a
1372 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001373 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001374 + " Callers=" + Debug.getCallers(3));
1375 }
1376 return a;
1377 }
1378
1379 void postAnimationCallback() {
1380 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001381 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1382 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001383 mNextAppTransitionCallback = null;
1384 }
1385 }
1386
1387 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001388 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001389 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001390 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001391 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001392 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001393 mNextAppTransitionEnter = enterAnim;
1394 mNextAppTransitionExit = exitAnim;
1395 postAnimationCallback();
1396 mNextAppTransitionCallback = startedCallback;
1397 } else {
1398 postAnimationCallback();
1399 }
1400 }
1401
1402 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001403 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001404 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001405 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001406 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001407 putDefaultNextAppTransitionCoordinates(startX, startY, startX + startWidth,
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001408 startY + startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001409 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001410 }
1411 }
1412
Chet Haase10e23ab2015-02-11 15:08:38 -08001413 void overridePendingAppTransitionClipReveal(int startX, int startY,
1414 int startWidth, int startHeight) {
1415 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001416 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001417 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001418 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001419 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001420 }
1421 }
1422
Craig Mautner164d4bb2012-11-26 13:51:23 -08001423 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1424 IRemoteCallback startedCallback, boolean scaleUp) {
1425 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001426 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001427 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1428 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001429 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001430 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001431 postAnimationCallback();
1432 mNextAppTransitionCallback = startedCallback;
1433 } else {
1434 postAnimationCallback();
1435 }
1436 }
1437
Winson Chunga4ccb862014-08-22 15:26:27 -07001438 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001439 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001440 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001441 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001442 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1443 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001444 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001445 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1446 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001447 postAnimationCallback();
1448 mNextAppTransitionCallback = startedCallback;
1449 } else {
1450 postAnimationCallback();
1451 }
1452 }
1453
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001454 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001455 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1456 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001457 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001458 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001459 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1460 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001461 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001462 if (specs != null) {
1463 for (int i = 0; i < specs.length; i++) {
1464 AppTransitionAnimationSpec spec = specs[i];
1465 if (spec != null) {
1466 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1467 if (i == 0) {
1468 // In full screen mode, the transition code depends on the default spec
1469 // to be set.
1470 Rect rect = spec.rect;
1471 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Filip Gruszczynskie3264d82015-11-20 17:10:04 -08001472 rect.width(), rect.height(), spec.bitmap);
Jorim Jaggi43102412015-11-11 16:28:37 +01001473 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001474 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001475 }
1476 }
1477 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001478 mNextAppTransitionCallback = onAnimationStartedCallback;
1479 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001480 } else {
1481 postAnimationCallback();
1482 }
1483 }
1484
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001485 void overridePendingAppTransitionMultiThumbFuture(
1486 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1487 boolean scaleUp) {
1488 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001489 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001490 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1491 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001492 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1493 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001494 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001495 }
1496 }
1497
Winson Chung044d5292014-11-06 11:05:19 -08001498 void overrideInPlaceAppTransition(String packageName, int anim) {
1499 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001500 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001501 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1502 mNextAppTransitionPackage = packageName;
1503 mNextAppTransitionInPlace = anim;
1504 } else {
1505 postAnimationCallback();
1506 }
1507 }
1508
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001509 /**
1510 * If a future is set for the app transition specs, fetch it in another thread.
1511 */
1512 private void fetchAppTransitionSpecsFromFuture() {
1513 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1514 mNextAppTransitionAnimationsSpecsPending = true;
1515 final IAppTransitionAnimationSpecsFuture future
1516 = mNextAppTransitionAnimationsSpecsFuture;
1517 mNextAppTransitionAnimationsSpecsFuture = null;
1518 mDefaultExecutor.execute(new Runnable() {
1519 @Override
1520 public void run() {
1521 AppTransitionAnimationSpec[] specs = null;
1522 try {
1523 specs = future.get();
1524 } catch (RemoteException e) {
1525 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1526 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001527 synchronized (mService.mWindowMap) {
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001528 mNextAppTransitionAnimationsSpecsPending = false;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001529 overridePendingAppTransitionMultiThumb(specs,
1530 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1531 mNextAppTransitionScaleUp);
1532 mNextAppTransitionFutureCallback = null;
Filip Gruszczynski96daf322015-11-18 18:01:27 -08001533 if (specs != null) {
1534 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1535 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001536 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001537 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001538 }
1539 });
1540 }
1541 }
1542
Craig Mautner164d4bb2012-11-26 13:51:23 -08001543 @Override
1544 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001545 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001546 }
1547
Craig Mautner4b71aa12012-12-27 17:20:01 -08001548 /**
1549 * Returns the human readable name of a window transition.
1550 *
1551 * @param transition The window transition.
1552 * @return The transition symbolic name.
1553 */
1554 public static String appTransitionToString(int transition) {
1555 switch (transition) {
1556 case TRANSIT_UNSET: {
1557 return "TRANSIT_UNSET";
1558 }
1559 case TRANSIT_NONE: {
1560 return "TRANSIT_NONE";
1561 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001562 case TRANSIT_ACTIVITY_OPEN: {
1563 return "TRANSIT_ACTIVITY_OPEN";
1564 }
1565 case TRANSIT_ACTIVITY_CLOSE: {
1566 return "TRANSIT_ACTIVITY_CLOSE";
1567 }
1568 case TRANSIT_TASK_OPEN: {
1569 return "TRANSIT_TASK_OPEN";
1570 }
1571 case TRANSIT_TASK_CLOSE: {
1572 return "TRANSIT_TASK_CLOSE";
1573 }
1574 case TRANSIT_TASK_TO_FRONT: {
1575 return "TRANSIT_TASK_TO_FRONT";
1576 }
1577 case TRANSIT_TASK_TO_BACK: {
1578 return "TRANSIT_TASK_TO_BACK";
1579 }
1580 case TRANSIT_WALLPAPER_CLOSE: {
1581 return "TRANSIT_WALLPAPER_CLOSE";
1582 }
1583 case TRANSIT_WALLPAPER_OPEN: {
1584 return "TRANSIT_WALLPAPER_OPEN";
1585 }
1586 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1587 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1588 }
1589 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1590 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1591 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001592 case TRANSIT_TASK_OPEN_BEHIND: {
1593 return "TRANSIT_TASK_OPEN_BEHIND";
1594 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001595 case TRANSIT_ACTIVITY_RELAUNCH: {
1596 return "TRANSIT_ACTIVITY_RELAUNCH";
1597 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001598 default: {
1599 return "<UNKNOWN>";
1600 }
1601 }
1602 }
1603
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001604 private String appStateToString() {
1605 switch (mAppTransitionState) {
1606 case APP_STATE_IDLE:
1607 return "APP_STATE_IDLE";
1608 case APP_STATE_READY:
1609 return "APP_STATE_READY";
1610 case APP_STATE_RUNNING:
1611 return "APP_STATE_RUNNING";
1612 case APP_STATE_TIMEOUT:
1613 return "APP_STATE_TIMEOUT";
1614 default:
1615 return "unknown state=" + mAppTransitionState;
1616 }
1617 }
1618
1619 private String transitTypeToString() {
1620 switch (mNextAppTransitionType) {
1621 case NEXT_TRANSIT_TYPE_NONE:
1622 return "NEXT_TRANSIT_TYPE_NONE";
1623 case NEXT_TRANSIT_TYPE_CUSTOM:
1624 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001625 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1626 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001627 case NEXT_TRANSIT_TYPE_SCALE_UP:
1628 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1629 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1630 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1631 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1632 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001633 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1634 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1635 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1636 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001637 default:
1638 return "unknown type=" + mNextAppTransitionType;
1639 }
1640 }
1641
Craig Mautner164d4bb2012-11-26 13:51:23 -08001642 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001643 public void dump(PrintWriter pw, String prefix) {
1644 pw.print(prefix); pw.println(this);
1645 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001646 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001647 pw.print(prefix); pw.print("mNextAppTransitionType=");
1648 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001649 }
1650 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001651 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001652 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001653 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001654 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001655 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1656 pw.print(" mNextAppTransitionExit=0x");
1657 pw.println(Integer.toHexString(mNextAppTransitionExit));
1658 break;
Winson Chung044d5292014-11-06 11:05:19 -08001659 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001660 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001661 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001662 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001663 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1664 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001665 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001666 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001667 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001668 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001669 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001670 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001671 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001672 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001673 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001674 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001675 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001676 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001677 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1678 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001679 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001680 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1681 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1682 pw.println(mDefaultNextAppTransitionAnimationSpec);
1683 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1684 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001685 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1686 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001687 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001688 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001689 }
1690 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001691 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1692 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001693 }
1694 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001695
1696 public void setCurrentUser(int newUserId) {
1697 mCurrentUserId = newUserId;
1698 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001699
1700 /**
1701 * @return true if transition is not running and should not be skipped, false if transition is
1702 * already running
1703 */
1704 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent) {
1705 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
1706 + " transit=" + appTransitionToString(transit)
1707 + " " + this
1708 + " alwaysKeepCurrent=" + alwaysKeepCurrent
1709 + " Callers=" + Debug.getCallers(3));
1710 if (!isTransitionSet() || mNextAppTransition == TRANSIT_NONE) {
1711 setAppTransition(transit);
1712 } else if (!alwaysKeepCurrent) {
1713 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
1714 // Opening a new task always supersedes a close for the anim.
1715 setAppTransition(transit);
1716 } else if (transit == TRANSIT_ACTIVITY_OPEN
1717 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
1718 // Opening a new activity always supersedes a close for the anim.
1719 setAppTransition(transit);
1720 }
1721 }
1722 boolean prepared = prepare();
1723 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001724 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
1725 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001726 }
1727 return prepared;
1728 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001729}