blob: 25ef8e6df656efc1bbbe6a1cd456414618fbd41a [file] [log] [blame]
Craig Mautner164d4bb2012-11-26 13:51:23 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Filip Gruszczynski82861362015-10-16 14:21:09 -070019import static android.view.WindowManagerInternal.AppTransitionListener;
20import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
21import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
22import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
23import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
24import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
25import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
26import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
27import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
28import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
29import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
30import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
31import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
32import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
33import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
34import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
35import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
36import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
37import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
38import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
39import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
40import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
41import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
42
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070043import android.annotation.Nullable;
Craig Mautner164d4bb2012-11-26 13:51:23 -080044import android.content.Context;
Winson Chung2820c452014-04-15 15:34:44 -070045import android.content.res.Configuration;
Craig Mautner164d4bb2012-11-26 13:51:23 -080046import android.graphics.Bitmap;
Winson Chung399f6202014-03-19 10:47:20 -070047import android.graphics.Rect;
Craig Mautner164d4bb2012-11-26 13:51:23 -080048import android.os.Debug;
49import android.os.Handler;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010050import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080051import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010052import android.os.RemoteException;
Craig Mautner164d4bb2012-11-26 13:51:23 -080053import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070054import android.util.SparseArray;
55import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010056import android.view.IAppTransitionAnimationSpecsFuture;
Craig Mautner164d4bb2012-11-26 13:51:23 -080057import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080058import android.view.animation.AlphaAnimation;
59import android.view.animation.Animation;
60import android.view.animation.AnimationSet;
61import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070062import android.view.animation.ClipRectAnimation;
Chet Haase10e23ab2015-02-11 15:08:38 -080063import android.view.animation.ClipRectLRAnimation;
64import android.view.animation.ClipRectTBAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080065import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070066import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080067import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070068import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070069
Craig Mautner164d4bb2012-11-26 13:51:23 -080070import com.android.internal.util.DumpUtils.Dump;
71import com.android.server.AttributeCache;
72import com.android.server.wm.WindowManagerService.H;
73
74import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010075import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010076import java.util.concurrent.ExecutorService;
77import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -080078
Craig Mautner164d4bb2012-11-26 13:51:23 -080079// State management of app transitions. When we are preparing for a
80// transition, mNextAppTransition will be the kind of transition to
81// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
82// mOpeningApps and mClosingApps are the lists of tokens that will be
83// made visible or hidden at the next transition.
84public class AppTransition implements Dump {
85 private static final String TAG = "AppTransition";
Craig Mautner321bdf52012-12-18 09:53:24 -080086 private static final boolean DEBUG_APP_TRANSITIONS =
87 WindowManagerService.DEBUG_APP_TRANSITIONS;
88 private static final boolean DEBUG_ANIM = WindowManagerService.DEBUG_ANIM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070089 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080090
Craig Mautner4b71aa12012-12-27 17:20:01 -080091 /** Not set up for a transition. */
92 public static final int TRANSIT_UNSET = -1;
93 /** No animation for transition. */
94 public static final int TRANSIT_NONE = 0;
95 /** A window in a new activity is being opened on top of an existing one in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -070096 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -080097 /** The window in the top-most activity is being closed to reveal the
98 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -070099 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800100 /** A window in a new task is being opened on top of an existing one
101 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700102 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800103 /** A window in the top-most activity is being closed to reveal the
104 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700105 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800106 /** A window in an existing task is being displayed on top of an existing one
107 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700108 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800109 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700110 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800111 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
112 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700113 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800114 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
115 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700116 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800117 /** A window in a new activity is being opened on top of an existing one, and both are on top
118 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700119 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800120 /** The window in the top-most activity is being closed to reveal the previous activity, and
121 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700122 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
123 /** A window in a new task is being opened behind an existing one in another activity's task.
124 * The new window will show briefly and then be gone. */
125 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800126 /** A window in a task is being animated in-place. */
127 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700128 /** An activity is being relaunched (e.g. due to configuration change). */
129 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800130
Winson Chunga4ccb862014-08-22 15:26:27 -0700131 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700132 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800133 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700134 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800135
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700136 private static final int DEFAULT_APP_TRANSITION_DURATION = 336;
137 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
138 private static final int THUMBNAIL_APP_TRANSITION_ALPHA_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700139 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800140
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800141 private final Context mContext;
142 private final Handler mH;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800143
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800144 private int mNextAppTransition = TRANSIT_UNSET;
145
146 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
147 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
148 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
149 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
150 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700151 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
152 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800153 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800154 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800155 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
156
Winson Chung399f6202014-03-19 10:47:20 -0700157 // These are the possible states for the enter/exit activities during a thumbnail transition
158 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
159 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
160 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
161 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
162
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800163 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800164 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800165 private boolean mNextAppTransitionScaleUp;
166 private IRemoteCallback mNextAppTransitionCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700167 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800168 private int mNextAppTransitionEnter;
169 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800170 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700171
172 // Keyed by task id.
173 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
174 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100175 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
176 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700177 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
178
Winson Chunga4ccb862014-08-22 15:26:27 -0700179 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800180
Winson Chung2820c452014-04-15 15:34:44 -0700181 private Rect mTmpFromClipRect = new Rect();
182 private Rect mTmpToClipRect = new Rect();
183
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700184 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700185
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800186 private final static int APP_STATE_IDLE = 0;
187 private final static int APP_STATE_READY = 1;
188 private final static int APP_STATE_RUNNING = 2;
189 private final static int APP_STATE_TIMEOUT = 3;
190 private int mAppTransitionState = APP_STATE_IDLE;
191
192 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800193 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700194 private final Interpolator mThumbnailFadeInInterpolator;
195 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800196 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700197 private final Interpolator mFastOutLinearInInterpolator;
198 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
199
200 /** Interpolator to be used for animations that respond directly to a touch */
201 private final Interpolator mTouchResponseInterpolator =
202 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
203
204 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800205
Amith Yamasani4befbec2013-07-10 16:18:01 -0700206 private int mCurrentUserId = 0;
207
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100208 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100209 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
210 private final Object mServiceLock;
211 private final WindowSurfacePlacer mWindowSurfacePlacer;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100212
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100213 AppTransition(Context context, Handler h, Object serviceLock,
214 WindowSurfacePlacer windowSurfacePlacer) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800215 mContext = context;
216 mH = h;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100217 mServiceLock = serviceLock;
218 mWindowSurfacePlacer = windowSurfacePlacer;
Chet Haase10e23ab2015-02-11 15:08:38 -0800219 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
220 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700221 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
222 com.android.internal.R.interpolator.fast_out_linear_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800223 mConfigShortAnimTime = context.getResources().getInteger(
224 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800225 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
226 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700227 mThumbnailFadeInInterpolator = new Interpolator() {
228 @Override
229 public float getInterpolation(float input) {
230 // Linear response for first fraction, then complete after that.
231 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
232 return 0f;
233 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700234 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700235 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700236 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700237 }
238 };
239 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800240 @Override
241 public float getInterpolation(float input) {
242 // Linear response for first fraction, then complete after that.
243 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700244 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
245 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800246 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700247 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800248 }
249 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700250 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
251 * mContext.getResources().getDisplayMetrics().density);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800252 }
253
254 boolean isTransitionSet() {
255 return mNextAppTransition != TRANSIT_UNSET;
256 }
257
Craig Mautner164d4bb2012-11-26 13:51:23 -0800258 boolean isTransitionEqual(int transit) {
259 return mNextAppTransition == transit;
260 }
261
262 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800263 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800264 }
265
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700266 private void setAppTransition(int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800267 mNextAppTransition = transit;
268 }
269
270 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800271 return mAppTransitionState == APP_STATE_READY
272 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800273 }
274
Craig Mautnerae446592012-12-06 19:05:05 -0800275 void setReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800276 mAppTransitionState = APP_STATE_READY;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100277 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800278 }
279
280 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800281 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800282 }
283
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800284 void setIdle() {
285 mAppTransitionState = APP_STATE_IDLE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800286 }
287
288 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800289 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800290 }
291
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800292 void setTimeout() {
293 mAppTransitionState = APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800294 }
295
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700296 Bitmap getAppTransitionThumbnailHeader(int taskId) {
297 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800298 if (spec == null) {
299 spec = mDefaultNextAppTransitionAnimationSpec;
300 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700301 return spec != null ? spec.bitmap : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800302 }
303
Winson Chunga4ccb862014-08-22 15:26:27 -0700304 /** Returns whether the next thumbnail transition is aspect scaled up. */
305 boolean isNextThumbnailTransitionAspectScaled() {
306 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
307 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
308 }
309
310 /** Returns whether the next thumbnail transition is scaling up. */
311 boolean isNextThumbnailTransitionScaleUp() {
312 return mNextAppTransitionScaleUp;
313 }
314
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100315 /**
316 * @return true if and only if we are currently fetching app transition specs from the future
317 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
318 */
319 boolean isFetchingAppTransitionsSpecs() {
320 return mNextAppTransitionAnimationsSpecsPending;
321 }
322
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700323 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800324 if (!isRunning()) {
325 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100326 notifyAppTransitionPendingLocked();
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700327 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800328 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700329 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800330 }
331
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100332 void goodToGo(AppWindowAnimator openingAppAnimator, AppWindowAnimator closingAppAnimator) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800333 mNextAppTransition = TRANSIT_UNSET;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800334 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100335 notifyAppTransitionStartingLocked(
336 openingAppAnimator != null ? openingAppAnimator.mAppToken.token : null,
337 closingAppAnimator != null ? closingAppAnimator.mAppToken.token : null,
338 openingAppAnimator != null ? openingAppAnimator.animation : null,
339 closingAppAnimator != null ? closingAppAnimator.animation : null);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800340 }
341
342 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800343 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800344 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700345 mNextAppTransitionAnimationsSpecs.clear();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800346 }
347
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800348 void freeze() {
349 setAppTransition(AppTransition.TRANSIT_UNSET);
350 clear();
351 setReady();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100352 notifyAppTransitionCancelledLocked();
353 }
354
355 void registerListenerLocked(AppTransitionListener listener) {
356 mListeners.add(listener);
357 }
358
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700359 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100360 for (int i = 0; i < mListeners.size(); i++) {
361 mListeners.get(i).onAppTransitionFinishedLocked(token);
362 }
363 }
364
365 private void notifyAppTransitionPendingLocked() {
366 for (int i = 0; i < mListeners.size(); i++) {
367 mListeners.get(i).onAppTransitionPendingLocked();
368 }
369 }
370
371 private void notifyAppTransitionCancelledLocked() {
372 for (int i = 0; i < mListeners.size(); i++) {
373 mListeners.get(i).onAppTransitionCancelledLocked();
374 }
375 }
376
377 private void notifyAppTransitionStartingLocked(IBinder openToken,
378 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
379 for (int i = 0; i < mListeners.size(); i++) {
380 mListeners.get(i).onAppTransitionStartingLocked(openToken, closeToken, openAnimation,
381 closeAnimation);
382 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800383 }
384
Craig Mautner164d4bb2012-11-26 13:51:23 -0800385 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
386 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
387 + (lp != null ? lp.packageName : null)
388 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
389 if (lp != null && lp.windowAnimations != 0) {
390 // If this is a system resource, don't try to load it from the
391 // application resources. It is nice to avoid loading application
392 // resources if we can.
393 String packageName = lp.packageName != null ? lp.packageName : "android";
394 int resId = lp.windowAnimations;
395 if ((resId&0xFF000000) == 0x01000000) {
396 packageName = "android";
397 }
398 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
399 + packageName);
400 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700401 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800402 }
403 return null;
404 }
405
406 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
407 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
408 + packageName + " resId=0x" + Integer.toHexString(resId));
409 if (packageName != null) {
410 if ((resId&0xFF000000) == 0x01000000) {
411 packageName = "android";
412 }
413 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
414 + packageName);
415 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700416 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800417 }
418 return null;
419 }
420
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700421 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800422 int anim = 0;
423 Context context = mContext;
424 if (animAttr >= 0) {
425 AttributeCache.Entry ent = getCachedAnimations(lp);
426 if (ent != null) {
427 context = ent.context;
428 anim = ent.array.getResourceId(animAttr, 0);
429 }
430 }
431 if (anim != 0) {
432 return AnimationUtils.loadAnimation(context, anim);
433 }
434 return null;
435 }
436
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700437 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
438 Context context = mContext;
439 if (resId >= 0) {
440 AttributeCache.Entry ent = getCachedAnimations(lp);
441 if (ent != null) {
442 context = ent.context;
443 }
444 return AnimationUtils.loadAnimation(context, resId);
445 }
446 return null;
447 }
448
449 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800450 int anim = 0;
451 Context context = mContext;
452 if (resId >= 0) {
453 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
454 if (ent != null) {
455 context = ent.context;
456 anim = resId;
457 }
458 }
459 if (anim != 0) {
460 return AnimationUtils.loadAnimation(context, anim);
461 }
462 return null;
463 }
464
Craig Mautner164d4bb2012-11-26 13:51:23 -0800465 /**
466 * Compute the pivot point for an animation that is scaling from a small
467 * rect on screen to a larger rect. The pivot point varies depending on
468 * the distance between the inner and outer edges on both sides. This
469 * function computes the pivot point for one dimension.
470 * @param startPos Offset from left/top edge of outer rectangle to
471 * left/top edge of inner rectangle.
472 * @param finalScale The scaling factor between the size of the outer
473 * and inner rectangles.
474 */
475 private static float computePivot(int startPos, float finalScale) {
476 final float denom = finalScale-1;
477 if (Math.abs(denom) < .0001f) {
478 return startPos;
479 }
480 return -startPos / denom;
481 }
482
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700483 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
484 Rect containingFrame) {
485 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700486 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700487 final int appWidth = containingFrame.width();
488 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800489 if (enter) {
490 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700491 float scaleW = mTmpRect.width() / (float) appWidth;
492 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800493 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700494 computePivot(mTmpRect.left, scaleW),
495 computePivot(mTmpRect.right, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800496 scale.setInterpolator(mDecelerateInterpolator);
497
Craig Mautner164d4bb2012-11-26 13:51:23 -0800498 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700499 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800500
501 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800502 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800503 set.addAnimation(alpha);
504 set.setDetachWallpaper(true);
505 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800506 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
507 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800508 // If we are on top of the wallpaper, we need an animation that
509 // correctly handles the wallpaper staying static behind all of
510 // the animated elements. To do this, will just have the existing
511 // element fade out.
512 a = new AlphaAnimation(1, 0);
513 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800514 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800515 // For normal animations, the exiting element just holds in place.
516 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800517 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800518
519 // Pick the desired duration. If this is an inter-activity transition,
520 // it is the standard duration for that. Otherwise we use the longer
521 // task transition duration.
522 final long duration;
523 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800524 case TRANSIT_ACTIVITY_OPEN:
525 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800526 duration = mConfigShortAnimTime;
527 break;
528 default:
529 duration = DEFAULT_APP_TRANSITION_DURATION;
530 break;
531 }
532 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800533 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800534 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800535 a.initialize(appWidth, appHeight, appWidth, appHeight);
536 return a;
537 }
538
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700539 private void getDefaultNextAppTransitionStartRect(Rect rect) {
540 if (mDefaultNextAppTransitionAnimationSpec == null ||
541 mDefaultNextAppTransitionAnimationSpec.rect == null) {
542 Slog.wtf(TAG, "Starting rect for app requested, but none available", new Throwable());
543 rect.setEmpty();
544 } else {
545 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
546 }
547 }
548
549 void getNextAppTransitionStartRect(int taskId, Rect rect) {
550 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800551 if (spec == null) {
552 spec = mDefaultNextAppTransitionAnimationSpec;
553 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700554 if (spec == null || spec.rect == null) {
555 Slog.wtf(TAG, "Starting rect for task: " + taskId + " requested, but not available",
556 new Throwable());
557 rect.setEmpty();
558 } else {
559 rect.set(spec.rect);
560 }
561 }
562
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800563 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
564 Bitmap bitmap) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700565 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800566 bitmap, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700567 }
568
Craig Mautner80b1f642015-04-22 10:59:09 -0700569 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800570 final Animation anim;
571 if (enter) {
572 // Reveal will expand and move faster in horizontal direction
573
Craig Mautner80b1f642015-04-22 10:59:09 -0700574 final int appWidth = appFrame.width();
575 final int appHeight = appFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700576 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700577 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700578 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700579
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700580 float t = 0f;
581 if (appHeight > 0) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700582 t = (float) mTmpRect.left / appHeight;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700583 }
Filip Gruszczynski82861362015-10-16 14:21:09 -0700584 int translationY = mClipRevealTranslationY + (int)(appHeight / 7f * t);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700585
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700586 int centerX = mTmpRect.centerX();
587 int centerY = mTmpRect.centerY();
588 int halfWidth = mTmpRect.width() / 2;
589 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700590
591 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800592 Animation clipAnimLR = new ClipRectLRAnimation(
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700593 centerX - halfWidth, centerX + halfWidth, 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700594 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
595 clipAnimLR.setDuration((long) (DEFAULT_APP_TRANSITION_DURATION / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700596
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700597 Animation clipAnimTB = new ClipRectTBAnimation(centerY - halfHeight - translationY,
598 centerY + halfHeight/ 2 - translationY, 0, appHeight);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700599 clipAnimTB.setInterpolator(mTouchResponseInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800600 clipAnimTB.setDuration(DEFAULT_APP_TRANSITION_DURATION);
601
Filip Gruszczynski82861362015-10-16 14:21:09 -0700602 // We might be animating entrance of a docked task, so we need the translate to account
603 // for the app frame in which the window will reside. Every other calculation here
604 // is performed as if the window started at 0,0.
605 translationY -= appFrame.top;
606 TranslateAnimation translate = new TranslateAnimation(-appFrame.left, 0, translationY,
607 0);
608 translate.setInterpolator(mLinearOutSlowInInterpolator);
609 translate.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Chet Haase10e23ab2015-02-11 15:08:38 -0800610
611 // Quick fade-in from icon to app window
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700612 final int alphaDuration = DEFAULT_APP_TRANSITION_DURATION / 4;
613 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800614 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700615 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800616
617 AnimationSet set = new AnimationSet(false);
618 set.addAnimation(clipAnimLR);
619 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700620 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800621 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700622 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800623 set.initialize(appWidth, appHeight, appWidth, appHeight);
624 anim = set;
625 } else {
626 final long duration;
627 switch (transit) {
628 case TRANSIT_ACTIVITY_OPEN:
629 case TRANSIT_ACTIVITY_CLOSE:
630 duration = mConfigShortAnimTime;
631 break;
632 default:
633 duration = DEFAULT_APP_TRANSITION_DURATION;
634 break;
635 }
636 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
637 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
638 // If we are on top of the wallpaper, we need an animation that
639 // correctly handles the wallpaper staying static behind all of
640 // the animated elements. To do this, will just have the existing
641 // element fade out.
642 anim = new AlphaAnimation(1, 0);
643 anim.setDetachWallpaper(true);
644 } else {
645 // For normal animations, the exiting element just holds in place.
646 anim = new AlphaAnimation(1, 1);
647 }
648 anim.setInterpolator(mDecelerateInterpolator);
649 anim.setDuration(duration);
650 anim.setFillAfter(true);
651 }
652 return anim;
653 }
654
Winson Chung399f6202014-03-19 10:47:20 -0700655 /**
656 * Prepares the specified animation with a standard duration, interpolator, etc.
657 */
Winson Chung5393dff2014-05-08 14:25:43 -0700658 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
659 int duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700660 if (duration > 0) {
661 a.setDuration(duration);
662 }
Winson Chung5393dff2014-05-08 14:25:43 -0700663 a.setFillAfter(true);
664 a.setInterpolator(interpolator);
665 a.initialize(appWidth, appHeight, appWidth, appHeight);
666 return a;
667 }
668
669 /**
670 * Prepares the specified animation with a standard duration, interpolator, etc.
671 */
Winson Chung399f6202014-03-19 10:47:20 -0700672 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800673 // Pick the desired duration. If this is an inter-activity transition,
674 // it is the standard duration for that. Otherwise we use the longer
675 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700676 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800677 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800678 case TRANSIT_ACTIVITY_OPEN:
679 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800680 duration = mConfigShortAnimTime;
681 break;
682 default:
683 duration = DEFAULT_APP_TRANSITION_DURATION;
684 break;
685 }
Winson Chung5393dff2014-05-08 14:25:43 -0700686 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
687 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800688 }
689
Winson Chung399f6202014-03-19 10:47:20 -0700690 /**
691 * Return the current thumbnail transition state.
692 */
693 int getThumbnailTransitionState(boolean enter) {
694 if (enter) {
695 if (mNextAppTransitionScaleUp) {
696 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
697 } else {
698 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
699 }
700 } else {
701 if (mNextAppTransitionScaleUp) {
702 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
703 } else {
704 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
705 }
706 }
707 }
708
709 /**
710 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700711 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700712 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700713 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, Bitmap thumbnailHeader,
714 final int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700715 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700716 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700717 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700718 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chung399f6202014-03-19 10:47:20 -0700719 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700720 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700721
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700722 float scaleW = appWidth / thumbWidth;
Winson Chunga4ccb862014-08-22 15:26:27 -0700723 float unscaledHeight = thumbHeight * scaleW;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700724 getNextAppTransitionStartRect(taskId, mTmpRect);
725 float unscaledStartY = mTmpRect.top - (unscaledHeight - thumbHeight) / 2f;
Winson Chung399f6202014-03-19 10:47:20 -0700726 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700727 // Animation up from the thumbnail to the full screen
728 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700729 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700730 scale.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700731 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700732 Animation alpha = new AlphaAnimation(1, 0);
Winson Chunga4ccb862014-08-22 15:26:27 -0700733 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
734 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700735 final float toX = appRect.left + appRect.width() / 2 -
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700736 (mTmpRect.left + thumbWidth / 2);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700737 final float toY = appRect.top + mNextAppTransitionInsets.top + -unscaledStartY;
738 Animation translate = new TranslateAnimation(0, toX, 0, toY);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700739 translate.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700740 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700741
742 // This AnimationSet uses the Interpolators assigned above.
743 AnimationSet set = new AnimationSet(false);
744 set.addAnimation(scale);
745 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -0700746 set.addAnimation(translate);
Winson Chung399f6202014-03-19 10:47:20 -0700747 a = set;
748 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700749 // Animation down from the full screen to the thumbnail
750 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700751 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700752 scale.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700753 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
754 Animation alpha = new AlphaAnimation(0f, 1f);
755 alpha.setInterpolator(mThumbnailFadeInInterpolator);
756 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
757 Animation translate = new TranslateAnimation(0, 0, -unscaledStartY +
758 mNextAppTransitionInsets.top, 0);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700759 translate.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700760 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700761
Winson Chunga4ccb862014-08-22 15:26:27 -0700762 // This AnimationSet uses the Interpolators assigned above.
763 AnimationSet set = new AnimationSet(false);
764 set.addAnimation(scale);
765 set.addAnimation(alpha);
766 set.addAnimation(translate);
767 a = set;
768
769 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700770 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700771 mTouchResponseInterpolator);
Winson Chung399f6202014-03-19 10:47:20 -0700772 }
773
774 /**
775 * This alternate animation is created when we are doing a thumbnail transition, for the
776 * activity that is leaving, and the activity that is entering.
777 */
Winson Chunga4ccb862014-08-22 15:26:27 -0700778 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700779 int orientation, int transit, Rect containingFrame, Rect contentInsets,
780 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700781 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700782 final int appWidth = containingFrame.width();
783 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700784 getDefaultNextAppTransitionStartRect(mTmpRect);
785 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700786 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700787 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -0700788 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
789
Winson Chung2820c452014-04-15 15:34:44 -0700790 // Used for the ENTER_SCALE_UP and EXIT_SCALE_DOWN transitions
791 float scale = 1f;
792 int scaledTopDecor = 0;
793
Winson Chung399f6202014-03-19 10:47:20 -0700794 switch (thumbTransitState) {
795 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700796 if (freeform) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700797 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700798 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -0700799 } else {
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700800 mTmpFromClipRect.set(containingFrame);
801 // exclude top screen decor (status bar) region from the source clip.
802 mTmpFromClipRect.top = contentInsets.top;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700803 // App window scaling up to become full screen
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700804 mTmpToClipRect.set(containingFrame);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700805 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
806 // In portrait, we scale the width and clip to the top/left square
807 scale = thumbWidth / appWidth;
808 scaledTopDecor = (int) (scale * contentInsets.top);
809 int unscaledThumbHeight = (int) (thumbHeight / scale);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700810 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700811 } else {
Filip Gruszczynskidd2ff842015-10-25 13:11:04 -0700812 // In landscape, we scale the height and clip to the top/left square. We
813 // only scale the part that is not covered by status bar and the nav bar.
814 scale = thumbHeight / (appHeight - contentInsets.top
815 - contentInsets.bottom);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700816 scaledTopDecor = (int) (scale * contentInsets.top);
817 int unscaledThumbWidth = (int) (thumbWidth / scale);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700818 mTmpFromClipRect.right = mTmpFromClipRect.left + unscaledThumbWidth;
Filip Gruszczynskidd2ff842015-10-25 13:11:04 -0700819 // This removes the navigation bar from the first frame, so it better
820 // matches the thumbnail. We need to do this explicitly in landscape,
821 // because in portrait we already crop vertically.
822 mTmpFromClipRect.bottom = mTmpFromClipRect.bottom - contentInsets.bottom;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700823 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700824
825 mNextAppTransitionInsets.set(contentInsets);
826
827 Animation scaleAnim = new ScaleAnimation(scale, 1, scale, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700828 computePivot(mTmpRect.left, scale),
829 computePivot(mTmpRect.top, scale));
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700830 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
831 Animation translateAnim = new TranslateAnimation(0, 0, -scaledTopDecor, 0);
832
833 AnimationSet set = new AnimationSet(true);
834 set.addAnimation(clipAnim);
835 set.addAnimation(scaleAnim);
836 set.addAnimation(translateAnim);
837 a = set;
Winson Chung2820c452014-04-15 15:34:44 -0700838 }
Winson Chung399f6202014-03-19 10:47:20 -0700839 break;
840 }
841 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700842 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -0700843 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700844 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -0700845 // activity.
846 a = new AlphaAnimation(1, 0);
847 } else {
Winson Chung399f6202014-03-19 10:47:20 -0700848 a = new AlphaAnimation(1, 1);
849 }
850 break;
851 }
852 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700853 // Target app window during the scale down
854 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
855 // Fade in the destination activity if we are animating from a wallpaper
856 // activity.
857 a = new AlphaAnimation(0, 1);
858 } else {
859 a = new AlphaAnimation(1, 1);
860 }
Winson Chung399f6202014-03-19 10:47:20 -0700861 break;
862 }
863 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700864 // App window scaling down from full screen
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700865 if (freeform) {
866 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
867 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -0700868 } else {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700869 mTmpFromClipRect.set(containingFrame);
870 mTmpToClipRect.set(containingFrame);
871 // exclude top screen decor (status bar) region from the destination clip.
872 mTmpToClipRect.top = contentInsets.top;
873 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
874 // In portrait, we scale the width and clip to the top/left square
875 scale = thumbWidth / appWidth;
876 scaledTopDecor = (int) (scale * contentInsets.top);
877 int unscaledThumbHeight = (int) (thumbHeight / scale);
878 mTmpToClipRect.bottom = mTmpToClipRect.top + unscaledThumbHeight;
879 } else {
880 // In landscape, we scale the height and clip to the top/left square. We only
881 // scale the part that is not covered by status bar and the nav bar.
882 scale = thumbHeight / (appHeight - contentInsets.top - contentInsets.bottom);
883 scaledTopDecor = (int) (scale * contentInsets.top);
884 int unscaledThumbWidth = (int) (thumbWidth / scale);
885 mTmpToClipRect.right = mTmpToClipRect.left + unscaledThumbWidth;
886 // This removes the navigation bar from the last frame, so it better matches the
887 // thumbnail. We need to do this explicitly in landscape, because in portrait we
888 // already crop vertically.
889 mTmpToClipRect.bottom = mTmpToClipRect.bottom - contentInsets.bottom;
890 }
891
892 mNextAppTransitionInsets.set(contentInsets);
893
894 Animation scaleAnim = new ScaleAnimation(1, scale, 1, scale,
895 computePivot(mTmpRect.left, scale),
896 computePivot(mTmpRect.top, scale));
897 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
898 Animation translateAnim = new TranslateAnimation(0, 0, 0, -scaledTopDecor);
899
900 AnimationSet set = new AnimationSet(true);
901 set.addAnimation(clipAnim);
902 set.addAnimation(scaleAnim);
903 set.addAnimation(translateAnim);
904
905 a = set;
906 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -0700907 }
Winson Chung399f6202014-03-19 10:47:20 -0700908 break;
909 }
910 default:
911 throw new RuntimeException("Invalid thumbnail transition state");
912 }
913
Winson Chungab79fce2014-11-04 16:15:22 -0800914 int duration = Math.max(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION,
915 THUMBNAIL_APP_TRANSITION_DURATION);
916 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700917 mTouchResponseInterpolator);
Winson Chung399f6202014-03-19 10:47:20 -0700918 }
919
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700920 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
921 @Nullable Rect surfaceInsets, int taskId) {
922 getNextAppTransitionStartRect(taskId, mTmpRect);
923 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
924 true);
925 }
926
927 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
928 @Nullable Rect surfaceInsets, int taskId) {
929 getNextAppTransitionStartRect(taskId, mTmpRect);
930 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
931 false);
932 }
933
934 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
935 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
936 final float sourceWidth = sourceFrame.width();
937 final float sourceHeight = sourceFrame.height();
938 final float destWidth = destFrame.width();
939 final float destHeight = destFrame.height();
940 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
941 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700942 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700943 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700944 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700945 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700946 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
947 // We want the scaling to happen from the center of the surface. In order to achieve that,
948 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700949 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
950 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
951 final ScaleAnimation scale = enter ?
952 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
953 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
954 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
955 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
956 final int destHCenter = destFrame.left + destFrame.width() / 2;
957 final int destVCenter = destFrame.top + destFrame.height() / 2;
958 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
959 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
960 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
961 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700962 set.addAnimation(scale);
963 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700964
965 final IRemoteCallback callback = mAnimationFinishedCallback;
966 if (callback != null) {
967 set.setAnimationListener(new Animation.AnimationListener() {
968 @Override
969 public void onAnimationStart(Animation animation) { }
970
971 @Override
972 public void onAnimationEnd(Animation animation) {
973 mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
974 }
975
976 @Override
977 public void onAnimationRepeat(Animation animation) { }
978 });
979 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700980 return set;
981 }
982
Winson Chung399f6202014-03-19 10:47:20 -0700983 /**
Winson Chunga4ccb862014-08-22 15:26:27 -0700984 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700985 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -0700986 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700987 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
988 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700989 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700990 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700991 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -0700992 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700993 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -0700994 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
995
996 if (mNextAppTransitionScaleUp) {
997 // Animation for the thumbnail zooming from its initial size to the full screen
998 float scaleW = appWidth / thumbWidth;
999 float scaleH = appHeight / thumbHeight;
1000 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001001 computePivot(mTmpRect.left, 1 / scaleW),
1002 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001003 scale.setInterpolator(mDecelerateInterpolator);
1004
1005 Animation alpha = new AlphaAnimation(1, 0);
1006 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1007
1008 // This AnimationSet uses the Interpolators assigned above.
1009 AnimationSet set = new AnimationSet(false);
1010 set.addAnimation(scale);
1011 set.addAnimation(alpha);
1012 a = set;
1013 } else {
1014 // Animation for the thumbnail zooming down from the full screen to its final size
1015 float scaleW = appWidth / thumbWidth;
1016 float scaleH = appHeight / thumbHeight;
1017 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001018 computePivot(mTmpRect.left, 1 / scaleW),
1019 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001020 }
1021
1022 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1023 }
1024
1025 /**
Winson Chung399f6202014-03-19 10:47:20 -07001026 * This animation is created when we are doing a thumbnail transition, for the activity that is
1027 * leaving, and the activity that is entering.
1028 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001029 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1030 int transit, int taskId) {
1031 final int appWidth = containingFrame.width();
1032 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001033 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001034 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001035 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001036 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001037 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001038 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001039 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1040
1041 switch (thumbTransitState) {
1042 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1043 // Entering app scales up with the thumbnail
1044 float scaleW = thumbWidth / appWidth;
1045 float scaleH = thumbHeight / appHeight;
1046 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001047 computePivot(mTmpRect.left, scaleW),
1048 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001049 break;
1050 }
1051 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1052 // Exiting app while the thumbnail is scaling up should fade or stay in place
1053 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1054 // Fade out while bringing up selected activity. This keeps the
1055 // current activity from showing through a launching wallpaper
1056 // activity.
1057 a = new AlphaAnimation(1, 0);
1058 } else {
1059 // noop animation
1060 a = new AlphaAnimation(1, 1);
1061 }
1062 break;
1063 }
1064 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1065 // Entering the other app, it should just be visible while we scale the thumbnail
1066 // down above it
1067 a = new AlphaAnimation(1, 1);
1068 break;
1069 }
1070 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1071 // Exiting the current app, the app should scale down with the thumbnail
1072 float scaleW = thumbWidth / appWidth;
1073 float scaleH = thumbHeight / appHeight;
1074 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001075 computePivot(mTmpRect.left, scaleW),
1076 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001077
1078 Animation alpha = new AlphaAnimation(1, 0);
1079
1080 AnimationSet set = new AnimationSet(true);
1081 set.addAnimation(scale);
1082 set.addAnimation(alpha);
1083 set.setZAdjustment(Animation.ZORDER_TOP);
1084 a = set;
1085 break;
1086 }
1087 default:
1088 throw new RuntimeException("Invalid thumbnail transition state");
1089 }
1090
1091 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1092 }
1093
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001094 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001095 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1096 final int left = mTmpFromClipRect.left;
1097 final int top = mTmpFromClipRect.top;
1098 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001099 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1100 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001101 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001102 float fromWidth = mTmpFromClipRect.width();
1103 float toWidth = mTmpToClipRect.width();
1104 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001105 // While the window might span the whole display, the actual content will be cropped to the
1106 // system decoration frame, for example when the window is docked. We need to take into
1107 // account the visible height when constructing the animation.
1108 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1109 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001110 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1111 // The final window is larger in both dimensions than current window (e.g. we are
1112 // maximizing), so we can simply unclip the new window and there will be no disappearing
1113 // frame.
1114 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1115 } else {
1116 // The disappearing window has one larger dimension. We need to apply scaling, so the
1117 // first frame of the entry animation matches the old window.
1118 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001119 // We might not be going exactly full screen, but instead be aligned under the status
1120 // bar using cropping. We still need to account for the cropped part, which will also
1121 // be scaled.
1122 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001123 }
1124
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001125 // We animate the translation from the old position of the removed window, to the new
1126 // position of the added window. The latter might not be full screen, for example docked for
1127 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001128 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001129 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001130 set.addAnimation(translate);
1131 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001132 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001133 return set;
1134 }
1135
Jorim Jaggic554b772015-06-04 16:07:57 -07001136 /**
1137 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1138 * frame of the transition doesn't change the visuals on screen, so we can start
1139 * directly with the second one
1140 */
1141 boolean canSkipFirstFrame() {
1142 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1143 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
1144 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1145 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001146
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001147 /**
1148 *
1149 * @param frame These are the bounds of the window when it finishes the animation. This is where
1150 * the animation must usually finish in entrance animation, as the next frame will
1151 * display the window at these coordinates. In case of exit animation, this is
1152 * where the animation must start, as the frame before the animation is displaying
1153 * the window at these bounds.
1154 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1155 * window might be obscured, usually by the system windows (status bar and
1156 * navigation bar) and we use content insets to convey that information. This
1157 * usually affects the animation aspects vertically, as the system decoration is
1158 * at the top and the bottom. For example when we animate from full screen to
1159 * recents, we want to exclude the covered parts, because they won't match the
1160 * thumbnail after the last frame is executed.
1161 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1162 * know about this to make the animation frames match. We currently use
1163 * this for freeform windows, which have larger surfaces to display
1164 * shadows. When we animate them from recents, we want to match the content
1165 * to the recents thumbnail and hence need to account for the surface being
1166 * bigger.
1167 */
Craig Mautner164d4bb2012-11-26 13:51:23 -08001168 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001169 int orientation, Rect frame, Rect insets, @Nullable Rect surfaceInsets,
1170 boolean isVoiceInteraction, boolean freeform, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001171 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001172 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
1173 || transit == TRANSIT_TASK_OPEN
1174 || transit == TRANSIT_TASK_TO_FRONT)) {
1175 a = loadAnimationRes(lp, enter
1176 ? com.android.internal.R.anim.voice_activity_open_enter
1177 : com.android.internal.R.anim.voice_activity_open_exit);
1178 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1179 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001180 + " anim=" + a + " transit=" + appTransitionToString(transit)
1181 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001182 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1183 || transit == TRANSIT_TASK_CLOSE
1184 || transit == TRANSIT_TASK_TO_BACK)) {
1185 a = loadAnimationRes(lp, enter
1186 ? com.android.internal.R.anim.voice_activity_close_enter
1187 : com.android.internal.R.anim.voice_activity_close_exit);
1188 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1189 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001190 + " anim=" + a + " transit=" + appTransitionToString(transit)
1191 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001192 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001193 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001194 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1195 "applyAnimation:"
1196 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1197 + " transit=" + appTransitionToString(transit)
1198 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001199 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1200 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001201 mNextAppTransitionEnter : mNextAppTransitionExit);
1202 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1203 "applyAnimation:"
1204 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001205 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001206 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001207 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1208 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1209 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1210 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001211 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1212 + " transit=" + appTransitionToString(transit)
1213 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001214 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001215 a = createClipRevealAnimationLocked(transit, enter, frame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001216 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1217 "applyAnimation:"
1218 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001219 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001220 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001221 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001222 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001223 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1224 "applyAnimation:"
1225 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001226 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001227 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001228 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1229 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001230 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001231 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001232 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001233 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001234 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1235 String animName = mNextAppTransitionScaleUp ?
1236 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1237 Slog.v(TAG, "applyAnimation:"
1238 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001239 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001240 + " Callers=" + Debug.getCallers(3));
1241 }
1242 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1243 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1244 mNextAppTransitionScaleUp =
1245 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1246 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001247 getThumbnailTransitionState(enter), orientation, transit, frame,
1248 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001249 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1250 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001251 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001252 Slog.v(TAG, "applyAnimation:"
1253 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001254 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001255 + " Callers=" + Debug.getCallers(3));
1256 }
1257 } else {
1258 int animAttr = 0;
1259 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001260 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001261 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001262 ? WindowAnimation_activityOpenEnterAnimation
1263 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001264 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001265 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001266 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001267 ? WindowAnimation_activityCloseEnterAnimation
1268 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001269 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001270 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001271 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001272 ? WindowAnimation_taskOpenEnterAnimation
1273 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001274 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001275 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001276 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001277 ? WindowAnimation_taskCloseEnterAnimation
1278 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001279 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001280 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001281 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001282 ? WindowAnimation_taskToFrontEnterAnimation
1283 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001284 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001285 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001286 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001287 ? WindowAnimation_taskToBackEnterAnimation
1288 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001289 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001290 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001291 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001292 ? WindowAnimation_wallpaperOpenEnterAnimation
1293 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001294 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001295 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001296 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001297 ? WindowAnimation_wallpaperCloseEnterAnimation
1298 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001299 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001300 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001301 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001302 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1303 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001304 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001305 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001306 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001307 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1308 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001309 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001310 case TRANSIT_TASK_OPEN_BEHIND:
1311 animAttr = enter
1312 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001313 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001314 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001315 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001316 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1317 "applyAnimation:"
1318 + " anim=" + a
1319 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001320 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001321 + " Callers=" + Debug.getCallers(3));
1322 }
1323 return a;
1324 }
1325
1326 void postAnimationCallback() {
1327 if (mNextAppTransitionCallback != null) {
1328 mH.sendMessage(mH.obtainMessage(H.DO_ANIMATION_CALLBACK, mNextAppTransitionCallback));
1329 mNextAppTransitionCallback = null;
1330 }
1331 }
1332
1333 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001334 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001335 if (isTransitionSet()) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001336 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001337 mNextAppTransitionPackage = packageName;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001338 mNextAppTransitionAnimationsSpecs.clear();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001339 mNextAppTransitionEnter = enterAnim;
1340 mNextAppTransitionExit = exitAnim;
1341 postAnimationCallback();
1342 mNextAppTransitionCallback = startedCallback;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001343 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001344 } else {
1345 postAnimationCallback();
1346 }
1347 }
1348
1349 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001350 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001351 if (isTransitionSet()) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001352 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001353 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001354 mNextAppTransitionAnimationsSpecs.clear();
1355 putDefaultNextAppTransitionCoordinates(startX, startY, startX + startWidth,
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001356 startY + startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001357 postAnimationCallback();
1358 mNextAppTransitionCallback = null;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001359 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001360 }
1361 }
1362
Chet Haase10e23ab2015-02-11 15:08:38 -08001363 void overridePendingAppTransitionClipReveal(int startX, int startY,
1364 int startWidth, int startHeight) {
1365 if (isTransitionSet()) {
1366 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001367 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001368 postAnimationCallback();
1369 mNextAppTransitionCallback = null;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001370 mAnimationFinishedCallback = null;
Chet Haase10e23ab2015-02-11 15:08:38 -08001371 }
1372 }
1373
Craig Mautner164d4bb2012-11-26 13:51:23 -08001374 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1375 IRemoteCallback startedCallback, boolean scaleUp) {
1376 if (isTransitionSet()) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001377 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1378 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001379 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001380 mNextAppTransitionAnimationsSpecs.clear();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001381 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001382 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001383 postAnimationCallback();
1384 mNextAppTransitionCallback = startedCallback;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001385 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001386 } else {
1387 postAnimationCallback();
1388 }
1389 }
1390
Winson Chunga4ccb862014-08-22 15:26:27 -07001391 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001392 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001393 if (isTransitionSet()) {
1394 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1395 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
1396 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001397 mNextAppTransitionAnimationsSpecs.clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001398 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001399 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1400 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001401 postAnimationCallback();
1402 mNextAppTransitionCallback = startedCallback;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001403 mAnimationFinishedCallback = null;
Winson Chunga4ccb862014-08-22 15:26:27 -07001404 } else {
1405 postAnimationCallback();
1406 }
1407 }
1408
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001409 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001410 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1411 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001412 if (isTransitionSet()) {
1413 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1414 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
1415 mNextAppTransitionPackage = null;
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001416 mDefaultNextAppTransitionAnimationSpec = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001417 mNextAppTransitionAnimationsSpecs.clear();
1418 mNextAppTransitionScaleUp = scaleUp;
1419 for (int i = 0; i < specs.length; i++) {
1420 AppTransitionAnimationSpec spec = specs[i];
1421 if (spec != null) {
1422 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001423 if (i == 0) {
1424 // In full screen mode, the transition code depends on the default spec to
1425 // be set.
1426 Rect rect = spec.rect;
1427 putDefaultNextAppTransitionCoordinates(rect.left, rect.top, rect.width(),
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001428 rect.height(), null);
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001429 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001430 }
1431 }
1432 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001433 mNextAppTransitionCallback = onAnimationStartedCallback;
1434 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001435 } else {
1436 postAnimationCallback();
1437 }
1438 }
1439
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001440 void overridePendingAppTransitionMultiThumbFuture(
1441 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1442 boolean scaleUp) {
1443 if (isTransitionSet()) {
1444 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1445 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
1446 mNextAppTransitionPackage = null;
1447 mDefaultNextAppTransitionAnimationSpec = null;
1448 mNextAppTransitionAnimationsSpecs.clear();
1449 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1450 mNextAppTransitionScaleUp = scaleUp;
1451 postAnimationCallback();
1452 mNextAppTransitionCallback = callback;
1453 } else {
1454 postAnimationCallback();
1455 }
1456 }
1457
Winson Chung044d5292014-11-06 11:05:19 -08001458 void overrideInPlaceAppTransition(String packageName, int anim) {
1459 if (isTransitionSet()) {
1460 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1461 mNextAppTransitionPackage = packageName;
1462 mNextAppTransitionInPlace = anim;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001463 mAnimationFinishedCallback = null;
Winson Chung044d5292014-11-06 11:05:19 -08001464 } else {
1465 postAnimationCallback();
1466 }
1467 }
1468
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001469 /**
1470 * If a future is set for the app transition specs, fetch it in another thread.
1471 */
1472 private void fetchAppTransitionSpecsFromFuture() {
1473 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1474 mNextAppTransitionAnimationsSpecsPending = true;
1475 final IAppTransitionAnimationSpecsFuture future
1476 = mNextAppTransitionAnimationsSpecsFuture;
1477 mNextAppTransitionAnimationsSpecsFuture = null;
1478 mDefaultExecutor.execute(new Runnable() {
1479 @Override
1480 public void run() {
1481 AppTransitionAnimationSpec[] specs = null;
1482 try {
1483 specs = future.get();
1484 } catch (RemoteException e) {
1485 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1486 }
1487 synchronized (mServiceLock) {
1488 mNextAppTransitionAnimationsSpecsPending = false;
1489 overridePendingAppTransitionMultiThumb(specs, mNextAppTransitionCallback,
1490 null /* finishedCallback */, mNextAppTransitionScaleUp);
1491 mWindowSurfacePlacer.requestTraversal();
1492 }
1493 }
1494 });
1495 }
1496 }
1497
Craig Mautner164d4bb2012-11-26 13:51:23 -08001498 @Override
1499 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001500 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001501 }
1502
Craig Mautner4b71aa12012-12-27 17:20:01 -08001503 /**
1504 * Returns the human readable name of a window transition.
1505 *
1506 * @param transition The window transition.
1507 * @return The transition symbolic name.
1508 */
1509 public static String appTransitionToString(int transition) {
1510 switch (transition) {
1511 case TRANSIT_UNSET: {
1512 return "TRANSIT_UNSET";
1513 }
1514 case TRANSIT_NONE: {
1515 return "TRANSIT_NONE";
1516 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001517 case TRANSIT_ACTIVITY_OPEN: {
1518 return "TRANSIT_ACTIVITY_OPEN";
1519 }
1520 case TRANSIT_ACTIVITY_CLOSE: {
1521 return "TRANSIT_ACTIVITY_CLOSE";
1522 }
1523 case TRANSIT_TASK_OPEN: {
1524 return "TRANSIT_TASK_OPEN";
1525 }
1526 case TRANSIT_TASK_CLOSE: {
1527 return "TRANSIT_TASK_CLOSE";
1528 }
1529 case TRANSIT_TASK_TO_FRONT: {
1530 return "TRANSIT_TASK_TO_FRONT";
1531 }
1532 case TRANSIT_TASK_TO_BACK: {
1533 return "TRANSIT_TASK_TO_BACK";
1534 }
1535 case TRANSIT_WALLPAPER_CLOSE: {
1536 return "TRANSIT_WALLPAPER_CLOSE";
1537 }
1538 case TRANSIT_WALLPAPER_OPEN: {
1539 return "TRANSIT_WALLPAPER_OPEN";
1540 }
1541 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1542 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1543 }
1544 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1545 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1546 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001547 case TRANSIT_TASK_OPEN_BEHIND: {
1548 return "TRANSIT_TASK_OPEN_BEHIND";
1549 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001550 case TRANSIT_ACTIVITY_RELAUNCH: {
1551 return "TRANSIT_ACTIVITY_RELAUNCH";
1552 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001553 default: {
1554 return "<UNKNOWN>";
1555 }
1556 }
1557 }
1558
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001559 private String appStateToString() {
1560 switch (mAppTransitionState) {
1561 case APP_STATE_IDLE:
1562 return "APP_STATE_IDLE";
1563 case APP_STATE_READY:
1564 return "APP_STATE_READY";
1565 case APP_STATE_RUNNING:
1566 return "APP_STATE_RUNNING";
1567 case APP_STATE_TIMEOUT:
1568 return "APP_STATE_TIMEOUT";
1569 default:
1570 return "unknown state=" + mAppTransitionState;
1571 }
1572 }
1573
1574 private String transitTypeToString() {
1575 switch (mNextAppTransitionType) {
1576 case NEXT_TRANSIT_TYPE_NONE:
1577 return "NEXT_TRANSIT_TYPE_NONE";
1578 case NEXT_TRANSIT_TYPE_CUSTOM:
1579 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001580 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1581 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001582 case NEXT_TRANSIT_TYPE_SCALE_UP:
1583 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1584 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1585 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1586 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1587 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001588 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1589 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1590 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1591 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001592 default:
1593 return "unknown type=" + mNextAppTransitionType;
1594 }
1595 }
1596
Craig Mautner164d4bb2012-11-26 13:51:23 -08001597 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001598 public void dump(PrintWriter pw, String prefix) {
1599 pw.print(prefix); pw.println(this);
1600 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001601 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001602 pw.print(prefix); pw.print("mNextAppTransitionType=");
1603 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001604 }
1605 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001606 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001607 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001608 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001609 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001610 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1611 pw.print(" mNextAppTransitionExit=0x");
1612 pw.println(Integer.toHexString(mNextAppTransitionExit));
1613 break;
Winson Chung044d5292014-11-06 11:05:19 -08001614 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001615 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001616 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001617 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001618 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1619 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001620 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001621 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001622 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001623 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001624 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001625 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001626 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001627 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001628 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001629 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001630 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001631 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001632 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1633 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001634 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001635 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1636 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1637 pw.println(mDefaultNextAppTransitionAnimationSpec);
1638 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1639 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001640 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1641 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001642 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001643 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001644 }
1645 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001646 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1647 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001648 }
1649 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001650
1651 public void setCurrentUser(int newUserId) {
1652 mCurrentUserId = newUserId;
1653 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001654
1655 /**
1656 * @return true if transition is not running and should not be skipped, false if transition is
1657 * already running
1658 */
1659 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent) {
1660 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
1661 + " transit=" + appTransitionToString(transit)
1662 + " " + this
1663 + " alwaysKeepCurrent=" + alwaysKeepCurrent
1664 + " Callers=" + Debug.getCallers(3));
1665 if (!isTransitionSet() || mNextAppTransition == TRANSIT_NONE) {
1666 setAppTransition(transit);
1667 } else if (!alwaysKeepCurrent) {
1668 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
1669 // Opening a new task always supersedes a close for the anim.
1670 setAppTransition(transit);
1671 } else if (transit == TRANSIT_ACTIVITY_OPEN
1672 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
1673 // Opening a new activity always supersedes a close for the anim.
1674 setAppTransition(transit);
1675 }
1676 }
1677 boolean prepared = prepare();
1678 if (isTransitionSet()) {
1679 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
1680 mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
1681 }
1682 return prepared;
1683 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001684}