blob: 68034c8c4f794fa4f19dc08189cadd7e1d9572e9 [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);
298 return spec != null ? spec.bitmap : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800299 }
300
Winson Chunga4ccb862014-08-22 15:26:27 -0700301 /** Returns whether the next thumbnail transition is aspect scaled up. */
302 boolean isNextThumbnailTransitionAspectScaled() {
303 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
304 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
305 }
306
307 /** Returns whether the next thumbnail transition is scaling up. */
308 boolean isNextThumbnailTransitionScaleUp() {
309 return mNextAppTransitionScaleUp;
310 }
311
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100312 /**
313 * @return true if and only if we are currently fetching app transition specs from the future
314 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
315 */
316 boolean isFetchingAppTransitionsSpecs() {
317 return mNextAppTransitionAnimationsSpecsPending;
318 }
319
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700320 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800321 if (!isRunning()) {
322 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100323 notifyAppTransitionPendingLocked();
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700324 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800325 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700326 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800327 }
328
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100329 void goodToGo(AppWindowAnimator openingAppAnimator, AppWindowAnimator closingAppAnimator) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800330 mNextAppTransition = TRANSIT_UNSET;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800331 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100332 notifyAppTransitionStartingLocked(
333 openingAppAnimator != null ? openingAppAnimator.mAppToken.token : null,
334 closingAppAnimator != null ? closingAppAnimator.mAppToken.token : null,
335 openingAppAnimator != null ? openingAppAnimator.animation : null,
336 closingAppAnimator != null ? closingAppAnimator.animation : null);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800337 }
338
339 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800340 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800341 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700342 mNextAppTransitionAnimationsSpecs.clear();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800343 }
344
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800345 void freeze() {
346 setAppTransition(AppTransition.TRANSIT_UNSET);
347 clear();
348 setReady();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100349 notifyAppTransitionCancelledLocked();
350 }
351
352 void registerListenerLocked(AppTransitionListener listener) {
353 mListeners.add(listener);
354 }
355
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700356 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100357 for (int i = 0; i < mListeners.size(); i++) {
358 mListeners.get(i).onAppTransitionFinishedLocked(token);
359 }
360 }
361
362 private void notifyAppTransitionPendingLocked() {
363 for (int i = 0; i < mListeners.size(); i++) {
364 mListeners.get(i).onAppTransitionPendingLocked();
365 }
366 }
367
368 private void notifyAppTransitionCancelledLocked() {
369 for (int i = 0; i < mListeners.size(); i++) {
370 mListeners.get(i).onAppTransitionCancelledLocked();
371 }
372 }
373
374 private void notifyAppTransitionStartingLocked(IBinder openToken,
375 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
376 for (int i = 0; i < mListeners.size(); i++) {
377 mListeners.get(i).onAppTransitionStartingLocked(openToken, closeToken, openAnimation,
378 closeAnimation);
379 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800380 }
381
Craig Mautner164d4bb2012-11-26 13:51:23 -0800382 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
383 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
384 + (lp != null ? lp.packageName : null)
385 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
386 if (lp != null && lp.windowAnimations != 0) {
387 // If this is a system resource, don't try to load it from the
388 // application resources. It is nice to avoid loading application
389 // resources if we can.
390 String packageName = lp.packageName != null ? lp.packageName : "android";
391 int resId = lp.windowAnimations;
392 if ((resId&0xFF000000) == 0x01000000) {
393 packageName = "android";
394 }
395 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
396 + packageName);
397 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700398 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800399 }
400 return null;
401 }
402
403 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
404 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
405 + packageName + " resId=0x" + Integer.toHexString(resId));
406 if (packageName != null) {
407 if ((resId&0xFF000000) == 0x01000000) {
408 packageName = "android";
409 }
410 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
411 + packageName);
412 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700413 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800414 }
415 return null;
416 }
417
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700418 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800419 int anim = 0;
420 Context context = mContext;
421 if (animAttr >= 0) {
422 AttributeCache.Entry ent = getCachedAnimations(lp);
423 if (ent != null) {
424 context = ent.context;
425 anim = ent.array.getResourceId(animAttr, 0);
426 }
427 }
428 if (anim != 0) {
429 return AnimationUtils.loadAnimation(context, anim);
430 }
431 return null;
432 }
433
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700434 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
435 Context context = mContext;
436 if (resId >= 0) {
437 AttributeCache.Entry ent = getCachedAnimations(lp);
438 if (ent != null) {
439 context = ent.context;
440 }
441 return AnimationUtils.loadAnimation(context, resId);
442 }
443 return null;
444 }
445
446 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800447 int anim = 0;
448 Context context = mContext;
449 if (resId >= 0) {
450 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
451 if (ent != null) {
452 context = ent.context;
453 anim = resId;
454 }
455 }
456 if (anim != 0) {
457 return AnimationUtils.loadAnimation(context, anim);
458 }
459 return null;
460 }
461
Craig Mautner164d4bb2012-11-26 13:51:23 -0800462 /**
463 * Compute the pivot point for an animation that is scaling from a small
464 * rect on screen to a larger rect. The pivot point varies depending on
465 * the distance between the inner and outer edges on both sides. This
466 * function computes the pivot point for one dimension.
467 * @param startPos Offset from left/top edge of outer rectangle to
468 * left/top edge of inner rectangle.
469 * @param finalScale The scaling factor between the size of the outer
470 * and inner rectangles.
471 */
472 private static float computePivot(int startPos, float finalScale) {
473 final float denom = finalScale-1;
474 if (Math.abs(denom) < .0001f) {
475 return startPos;
476 }
477 return -startPos / denom;
478 }
479
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700480 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
481 Rect containingFrame) {
482 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700483 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700484 final int appWidth = containingFrame.width();
485 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800486 if (enter) {
487 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700488 float scaleW = mTmpRect.width() / (float) appWidth;
489 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800490 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700491 computePivot(mTmpRect.left, scaleW),
492 computePivot(mTmpRect.right, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800493 scale.setInterpolator(mDecelerateInterpolator);
494
Craig Mautner164d4bb2012-11-26 13:51:23 -0800495 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700496 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800497
498 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800499 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800500 set.addAnimation(alpha);
501 set.setDetachWallpaper(true);
502 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800503 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
504 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800505 // If we are on top of the wallpaper, we need an animation that
506 // correctly handles the wallpaper staying static behind all of
507 // the animated elements. To do this, will just have the existing
508 // element fade out.
509 a = new AlphaAnimation(1, 0);
510 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800511 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800512 // For normal animations, the exiting element just holds in place.
513 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800514 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800515
516 // Pick the desired duration. If this is an inter-activity transition,
517 // it is the standard duration for that. Otherwise we use the longer
518 // task transition duration.
519 final long duration;
520 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800521 case TRANSIT_ACTIVITY_OPEN:
522 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800523 duration = mConfigShortAnimTime;
524 break;
525 default:
526 duration = DEFAULT_APP_TRANSITION_DURATION;
527 break;
528 }
529 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800530 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800531 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800532 a.initialize(appWidth, appHeight, appWidth, appHeight);
533 return a;
534 }
535
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700536 private void getDefaultNextAppTransitionStartRect(Rect rect) {
537 if (mDefaultNextAppTransitionAnimationSpec == null ||
538 mDefaultNextAppTransitionAnimationSpec.rect == null) {
539 Slog.wtf(TAG, "Starting rect for app requested, but none available", new Throwable());
540 rect.setEmpty();
541 } else {
542 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
543 }
544 }
545
546 void getNextAppTransitionStartRect(int taskId, Rect rect) {
547 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
548 if (spec == null || spec.rect == null) {
549 Slog.wtf(TAG, "Starting rect for task: " + taskId + " requested, but not available",
550 new Throwable());
551 rect.setEmpty();
552 } else {
553 rect.set(spec.rect);
554 }
555 }
556
557 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height) {
558 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
559 null /* bitmap */, new Rect(left, top, left + width, top + height));
560 }
561
Craig Mautner80b1f642015-04-22 10:59:09 -0700562 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800563 final Animation anim;
564 if (enter) {
565 // Reveal will expand and move faster in horizontal direction
566
Craig Mautner80b1f642015-04-22 10:59:09 -0700567 final int appWidth = appFrame.width();
568 final int appHeight = appFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700569 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700570 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700571 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700572
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700573 float t = 0f;
574 if (appHeight > 0) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700575 t = (float) mTmpRect.left / appHeight;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700576 }
Filip Gruszczynski82861362015-10-16 14:21:09 -0700577 int translationY = mClipRevealTranslationY + (int)(appHeight / 7f * t);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700578
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700579 int centerX = mTmpRect.centerX();
580 int centerY = mTmpRect.centerY();
581 int halfWidth = mTmpRect.width() / 2;
582 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700583
584 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800585 Animation clipAnimLR = new ClipRectLRAnimation(
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700586 centerX - halfWidth, centerX + halfWidth, 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700587 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
588 clipAnimLR.setDuration((long) (DEFAULT_APP_TRANSITION_DURATION / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700589
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700590 Animation clipAnimTB = new ClipRectTBAnimation(centerY - halfHeight - translationY,
591 centerY + halfHeight/ 2 - translationY, 0, appHeight);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700592 clipAnimTB.setInterpolator(mTouchResponseInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800593 clipAnimTB.setDuration(DEFAULT_APP_TRANSITION_DURATION);
594
Filip Gruszczynski82861362015-10-16 14:21:09 -0700595 // We might be animating entrance of a docked task, so we need the translate to account
596 // for the app frame in which the window will reside. Every other calculation here
597 // is performed as if the window started at 0,0.
598 translationY -= appFrame.top;
599 TranslateAnimation translate = new TranslateAnimation(-appFrame.left, 0, translationY,
600 0);
601 translate.setInterpolator(mLinearOutSlowInInterpolator);
602 translate.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Chet Haase10e23ab2015-02-11 15:08:38 -0800603
604 // Quick fade-in from icon to app window
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700605 final int alphaDuration = DEFAULT_APP_TRANSITION_DURATION / 4;
606 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800607 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700608 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800609
610 AnimationSet set = new AnimationSet(false);
611 set.addAnimation(clipAnimLR);
612 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700613 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800614 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700615 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800616 set.initialize(appWidth, appHeight, appWidth, appHeight);
617 anim = set;
618 } else {
619 final long duration;
620 switch (transit) {
621 case TRANSIT_ACTIVITY_OPEN:
622 case TRANSIT_ACTIVITY_CLOSE:
623 duration = mConfigShortAnimTime;
624 break;
625 default:
626 duration = DEFAULT_APP_TRANSITION_DURATION;
627 break;
628 }
629 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
630 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
631 // If we are on top of the wallpaper, we need an animation that
632 // correctly handles the wallpaper staying static behind all of
633 // the animated elements. To do this, will just have the existing
634 // element fade out.
635 anim = new AlphaAnimation(1, 0);
636 anim.setDetachWallpaper(true);
637 } else {
638 // For normal animations, the exiting element just holds in place.
639 anim = new AlphaAnimation(1, 1);
640 }
641 anim.setInterpolator(mDecelerateInterpolator);
642 anim.setDuration(duration);
643 anim.setFillAfter(true);
644 }
645 return anim;
646 }
647
Winson Chung399f6202014-03-19 10:47:20 -0700648 /**
649 * Prepares the specified animation with a standard duration, interpolator, etc.
650 */
Winson Chung5393dff2014-05-08 14:25:43 -0700651 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
652 int duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700653 if (duration > 0) {
654 a.setDuration(duration);
655 }
Winson Chung5393dff2014-05-08 14:25:43 -0700656 a.setFillAfter(true);
657 a.setInterpolator(interpolator);
658 a.initialize(appWidth, appHeight, appWidth, appHeight);
659 return a;
660 }
661
662 /**
663 * Prepares the specified animation with a standard duration, interpolator, etc.
664 */
Winson Chung399f6202014-03-19 10:47:20 -0700665 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800666 // Pick the desired duration. If this is an inter-activity transition,
667 // it is the standard duration for that. Otherwise we use the longer
668 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700669 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800670 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800671 case TRANSIT_ACTIVITY_OPEN:
672 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800673 duration = mConfigShortAnimTime;
674 break;
675 default:
676 duration = DEFAULT_APP_TRANSITION_DURATION;
677 break;
678 }
Winson Chung5393dff2014-05-08 14:25:43 -0700679 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
680 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800681 }
682
Winson Chung399f6202014-03-19 10:47:20 -0700683 /**
684 * Return the current thumbnail transition state.
685 */
686 int getThumbnailTransitionState(boolean enter) {
687 if (enter) {
688 if (mNextAppTransitionScaleUp) {
689 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
690 } else {
691 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
692 }
693 } else {
694 if (mNextAppTransitionScaleUp) {
695 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
696 } else {
697 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
698 }
699 }
700 }
701
702 /**
703 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700704 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700705 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700706 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, Bitmap thumbnailHeader,
707 final int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700708 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700709 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700710 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700711 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chung399f6202014-03-19 10:47:20 -0700712 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700713 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700714
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700715 float scaleW = appWidth / thumbWidth;
Winson Chunga4ccb862014-08-22 15:26:27 -0700716 float unscaledHeight = thumbHeight * scaleW;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700717 getNextAppTransitionStartRect(taskId, mTmpRect);
718 float unscaledStartY = mTmpRect.top - (unscaledHeight - thumbHeight) / 2f;
Winson Chung399f6202014-03-19 10:47:20 -0700719 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700720 // Animation up from the thumbnail to the full screen
721 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700722 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700723 scale.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700724 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700725 Animation alpha = new AlphaAnimation(1, 0);
Winson Chunga4ccb862014-08-22 15:26:27 -0700726 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
727 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700728 final float toX = appRect.left + appRect.width() / 2 -
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700729 (mTmpRect.left + thumbWidth / 2);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700730 final float toY = appRect.top + mNextAppTransitionInsets.top + -unscaledStartY;
731 Animation translate = new TranslateAnimation(0, toX, 0, toY);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700732 translate.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700733 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700734
735 // This AnimationSet uses the Interpolators assigned above.
736 AnimationSet set = new AnimationSet(false);
737 set.addAnimation(scale);
738 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -0700739 set.addAnimation(translate);
Winson Chung399f6202014-03-19 10:47:20 -0700740 a = set;
741 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700742 // Animation down from the full screen to the thumbnail
743 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700744 mTmpRect.left + (thumbWidth / 2f), mTmpRect.top + (thumbHeight / 2f));
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700745 scale.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700746 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
747 Animation alpha = new AlphaAnimation(0f, 1f);
748 alpha.setInterpolator(mThumbnailFadeInInterpolator);
749 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
750 Animation translate = new TranslateAnimation(0, 0, -unscaledStartY +
751 mNextAppTransitionInsets.top, 0);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700752 translate.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700753 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700754
Winson Chunga4ccb862014-08-22 15:26:27 -0700755 // This AnimationSet uses the Interpolators assigned above.
756 AnimationSet set = new AnimationSet(false);
757 set.addAnimation(scale);
758 set.addAnimation(alpha);
759 set.addAnimation(translate);
760 a = set;
761
762 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700763 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700764 mTouchResponseInterpolator);
Winson Chung399f6202014-03-19 10:47:20 -0700765 }
766
767 /**
768 * This alternate animation is created when we are doing a thumbnail transition, for the
769 * activity that is leaving, and the activity that is entering.
770 */
Winson Chunga4ccb862014-08-22 15:26:27 -0700771 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700772 int orientation, int transit, Rect containingFrame, Rect contentInsets,
773 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700774 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700775 final int appWidth = containingFrame.width();
776 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700777 getDefaultNextAppTransitionStartRect(mTmpRect);
778 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700779 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700780 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -0700781 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
782
Winson Chung2820c452014-04-15 15:34:44 -0700783 // Used for the ENTER_SCALE_UP and EXIT_SCALE_DOWN transitions
784 float scale = 1f;
785 int scaledTopDecor = 0;
786
Winson Chung399f6202014-03-19 10:47:20 -0700787 switch (thumbTransitState) {
788 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700789 if (freeform) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700790 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700791 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -0700792 } else {
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700793 mTmpFromClipRect.set(containingFrame);
794 // exclude top screen decor (status bar) region from the source clip.
795 mTmpFromClipRect.top = contentInsets.top;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700796 // App window scaling up to become full screen
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700797 mTmpToClipRect.set(containingFrame);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700798 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
799 // In portrait, we scale the width and clip to the top/left square
800 scale = thumbWidth / appWidth;
801 scaledTopDecor = (int) (scale * contentInsets.top);
802 int unscaledThumbHeight = (int) (thumbHeight / scale);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700803 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700804 } else {
Filip Gruszczynskidd2ff842015-10-25 13:11:04 -0700805 // In landscape, we scale the height and clip to the top/left square. We
806 // only scale the part that is not covered by status bar and the nav bar.
807 scale = thumbHeight / (appHeight - contentInsets.top
808 - contentInsets.bottom);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700809 scaledTopDecor = (int) (scale * contentInsets.top);
810 int unscaledThumbWidth = (int) (thumbWidth / scale);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700811 mTmpFromClipRect.right = mTmpFromClipRect.left + unscaledThumbWidth;
Filip Gruszczynskidd2ff842015-10-25 13:11:04 -0700812 // This removes the navigation bar from the first frame, so it better
813 // matches the thumbnail. We need to do this explicitly in landscape,
814 // because in portrait we already crop vertically.
815 mTmpFromClipRect.bottom = mTmpFromClipRect.bottom - contentInsets.bottom;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700816 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700817
818 mNextAppTransitionInsets.set(contentInsets);
819
820 Animation scaleAnim = new ScaleAnimation(scale, 1, scale, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700821 computePivot(mTmpRect.left, scale),
822 computePivot(mTmpRect.top, scale));
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700823 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
824 Animation translateAnim = new TranslateAnimation(0, 0, -scaledTopDecor, 0);
825
826 AnimationSet set = new AnimationSet(true);
827 set.addAnimation(clipAnim);
828 set.addAnimation(scaleAnim);
829 set.addAnimation(translateAnim);
830 a = set;
Winson Chung2820c452014-04-15 15:34:44 -0700831 }
Winson Chung399f6202014-03-19 10:47:20 -0700832 break;
833 }
834 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700835 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -0700836 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700837 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -0700838 // activity.
839 a = new AlphaAnimation(1, 0);
840 } else {
Winson Chung399f6202014-03-19 10:47:20 -0700841 a = new AlphaAnimation(1, 1);
842 }
843 break;
844 }
845 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700846 // Target app window during the scale down
847 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
848 // Fade in the destination activity if we are animating from a wallpaper
849 // activity.
850 a = new AlphaAnimation(0, 1);
851 } else {
852 a = new AlphaAnimation(1, 1);
853 }
Winson Chung399f6202014-03-19 10:47:20 -0700854 break;
855 }
856 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700857 // App window scaling down from full screen
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700858 if (freeform) {
859 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
860 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -0700861 } else {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700862 mTmpFromClipRect.set(containingFrame);
863 mTmpToClipRect.set(containingFrame);
864 // exclude top screen decor (status bar) region from the destination clip.
865 mTmpToClipRect.top = contentInsets.top;
866 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
867 // In portrait, we scale the width and clip to the top/left square
868 scale = thumbWidth / appWidth;
869 scaledTopDecor = (int) (scale * contentInsets.top);
870 int unscaledThumbHeight = (int) (thumbHeight / scale);
871 mTmpToClipRect.bottom = mTmpToClipRect.top + unscaledThumbHeight;
872 } else {
873 // In landscape, we scale the height and clip to the top/left square. We only
874 // scale the part that is not covered by status bar and the nav bar.
875 scale = thumbHeight / (appHeight - contentInsets.top - contentInsets.bottom);
876 scaledTopDecor = (int) (scale * contentInsets.top);
877 int unscaledThumbWidth = (int) (thumbWidth / scale);
878 mTmpToClipRect.right = mTmpToClipRect.left + unscaledThumbWidth;
879 // This removes the navigation bar from the last frame, so it better matches the
880 // thumbnail. We need to do this explicitly in landscape, because in portrait we
881 // already crop vertically.
882 mTmpToClipRect.bottom = mTmpToClipRect.bottom - contentInsets.bottom;
883 }
884
885 mNextAppTransitionInsets.set(contentInsets);
886
887 Animation scaleAnim = new ScaleAnimation(1, scale, 1, scale,
888 computePivot(mTmpRect.left, scale),
889 computePivot(mTmpRect.top, scale));
890 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
891 Animation translateAnim = new TranslateAnimation(0, 0, 0, -scaledTopDecor);
892
893 AnimationSet set = new AnimationSet(true);
894 set.addAnimation(clipAnim);
895 set.addAnimation(scaleAnim);
896 set.addAnimation(translateAnim);
897
898 a = set;
899 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -0700900 }
Winson Chung399f6202014-03-19 10:47:20 -0700901 break;
902 }
903 default:
904 throw new RuntimeException("Invalid thumbnail transition state");
905 }
906
Winson Chungab79fce2014-11-04 16:15:22 -0800907 int duration = Math.max(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION,
908 THUMBNAIL_APP_TRANSITION_DURATION);
909 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700910 mTouchResponseInterpolator);
Winson Chung399f6202014-03-19 10:47:20 -0700911 }
912
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700913 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
914 @Nullable Rect surfaceInsets, int taskId) {
915 getNextAppTransitionStartRect(taskId, mTmpRect);
916 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
917 true);
918 }
919
920 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
921 @Nullable Rect surfaceInsets, int taskId) {
922 getNextAppTransitionStartRect(taskId, mTmpRect);
923 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
924 false);
925 }
926
927 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
928 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
929 final float sourceWidth = sourceFrame.width();
930 final float sourceHeight = sourceFrame.height();
931 final float destWidth = destFrame.width();
932 final float destHeight = destFrame.height();
933 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
934 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700935 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700936 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700937 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700938 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700939 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
940 // We want the scaling to happen from the center of the surface. In order to achieve that,
941 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700942 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
943 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
944 final ScaleAnimation scale = enter ?
945 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
946 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
947 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
948 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
949 final int destHCenter = destFrame.left + destFrame.width() / 2;
950 final int destVCenter = destFrame.top + destFrame.height() / 2;
951 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
952 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
953 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
954 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700955 set.addAnimation(scale);
956 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700957
958 final IRemoteCallback callback = mAnimationFinishedCallback;
959 if (callback != null) {
960 set.setAnimationListener(new Animation.AnimationListener() {
961 @Override
962 public void onAnimationStart(Animation animation) { }
963
964 @Override
965 public void onAnimationEnd(Animation animation) {
966 mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
967 }
968
969 @Override
970 public void onAnimationRepeat(Animation animation) { }
971 });
972 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700973 return set;
974 }
975
Winson Chung399f6202014-03-19 10:47:20 -0700976 /**
Winson Chunga4ccb862014-08-22 15:26:27 -0700977 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700978 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -0700979 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700980 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
981 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700982 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700983 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700984 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -0700985 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700986 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -0700987 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
988
989 if (mNextAppTransitionScaleUp) {
990 // Animation for the thumbnail zooming from its initial size to the full screen
991 float scaleW = appWidth / thumbWidth;
992 float scaleH = appHeight / thumbHeight;
993 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700994 computePivot(mTmpRect.left, 1 / scaleW),
995 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -0700996 scale.setInterpolator(mDecelerateInterpolator);
997
998 Animation alpha = new AlphaAnimation(1, 0);
999 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1000
1001 // This AnimationSet uses the Interpolators assigned above.
1002 AnimationSet set = new AnimationSet(false);
1003 set.addAnimation(scale);
1004 set.addAnimation(alpha);
1005 a = set;
1006 } else {
1007 // Animation for the thumbnail zooming down from the full screen to its final size
1008 float scaleW = appWidth / thumbWidth;
1009 float scaleH = appHeight / thumbHeight;
1010 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001011 computePivot(mTmpRect.left, 1 / scaleW),
1012 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001013 }
1014
1015 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1016 }
1017
1018 /**
Winson Chung399f6202014-03-19 10:47:20 -07001019 * This animation is created when we are doing a thumbnail transition, for the activity that is
1020 * leaving, and the activity that is entering.
1021 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001022 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1023 int transit, int taskId) {
1024 final int appWidth = containingFrame.width();
1025 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001026 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001027 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001028 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001029 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001030 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001031 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001032 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1033
1034 switch (thumbTransitState) {
1035 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1036 // Entering app scales up with the thumbnail
1037 float scaleW = thumbWidth / appWidth;
1038 float scaleH = thumbHeight / appHeight;
1039 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001040 computePivot(mTmpRect.left, scaleW),
1041 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001042 break;
1043 }
1044 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1045 // Exiting app while the thumbnail is scaling up should fade or stay in place
1046 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1047 // Fade out while bringing up selected activity. This keeps the
1048 // current activity from showing through a launching wallpaper
1049 // activity.
1050 a = new AlphaAnimation(1, 0);
1051 } else {
1052 // noop animation
1053 a = new AlphaAnimation(1, 1);
1054 }
1055 break;
1056 }
1057 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1058 // Entering the other app, it should just be visible while we scale the thumbnail
1059 // down above it
1060 a = new AlphaAnimation(1, 1);
1061 break;
1062 }
1063 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1064 // Exiting the current app, the app should scale down with the thumbnail
1065 float scaleW = thumbWidth / appWidth;
1066 float scaleH = thumbHeight / appHeight;
1067 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001068 computePivot(mTmpRect.left, scaleW),
1069 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001070
1071 Animation alpha = new AlphaAnimation(1, 0);
1072
1073 AnimationSet set = new AnimationSet(true);
1074 set.addAnimation(scale);
1075 set.addAnimation(alpha);
1076 set.setZAdjustment(Animation.ZORDER_TOP);
1077 a = set;
1078 break;
1079 }
1080 default:
1081 throw new RuntimeException("Invalid thumbnail transition state");
1082 }
1083
1084 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1085 }
1086
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001087 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001088 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1089 final int left = mTmpFromClipRect.left;
1090 final int top = mTmpFromClipRect.top;
1091 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001092 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1093 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001094 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001095 float fromWidth = mTmpFromClipRect.width();
1096 float toWidth = mTmpToClipRect.width();
1097 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001098 // While the window might span the whole display, the actual content will be cropped to the
1099 // system decoration frame, for example when the window is docked. We need to take into
1100 // account the visible height when constructing the animation.
1101 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1102 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001103 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1104 // The final window is larger in both dimensions than current window (e.g. we are
1105 // maximizing), so we can simply unclip the new window and there will be no disappearing
1106 // frame.
1107 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1108 } else {
1109 // The disappearing window has one larger dimension. We need to apply scaling, so the
1110 // first frame of the entry animation matches the old window.
1111 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001112 // We might not be going exactly full screen, but instead be aligned under the status
1113 // bar using cropping. We still need to account for the cropped part, which will also
1114 // be scaled.
1115 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001116 }
1117
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001118 // We animate the translation from the old position of the removed window, to the new
1119 // position of the added window. The latter might not be full screen, for example docked for
1120 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001121 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001122 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001123 set.addAnimation(translate);
1124 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001125 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001126 return set;
1127 }
1128
Jorim Jaggic554b772015-06-04 16:07:57 -07001129 /**
1130 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1131 * frame of the transition doesn't change the visuals on screen, so we can start
1132 * directly with the second one
1133 */
1134 boolean canSkipFirstFrame() {
1135 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1136 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
1137 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1138 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001139
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001140 /**
1141 *
1142 * @param frame These are the bounds of the window when it finishes the animation. This is where
1143 * the animation must usually finish in entrance animation, as the next frame will
1144 * display the window at these coordinates. In case of exit animation, this is
1145 * where the animation must start, as the frame before the animation is displaying
1146 * the window at these bounds.
1147 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1148 * window might be obscured, usually by the system windows (status bar and
1149 * navigation bar) and we use content insets to convey that information. This
1150 * usually affects the animation aspects vertically, as the system decoration is
1151 * at the top and the bottom. For example when we animate from full screen to
1152 * recents, we want to exclude the covered parts, because they won't match the
1153 * thumbnail after the last frame is executed.
1154 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1155 * know about this to make the animation frames match. We currently use
1156 * this for freeform windows, which have larger surfaces to display
1157 * shadows. When we animate them from recents, we want to match the content
1158 * to the recents thumbnail and hence need to account for the surface being
1159 * bigger.
1160 */
Craig Mautner164d4bb2012-11-26 13:51:23 -08001161 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001162 int orientation, Rect frame, Rect insets, @Nullable Rect surfaceInsets,
1163 boolean isVoiceInteraction, boolean freeform, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001164 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001165 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
1166 || transit == TRANSIT_TASK_OPEN
1167 || transit == TRANSIT_TASK_TO_FRONT)) {
1168 a = loadAnimationRes(lp, enter
1169 ? com.android.internal.R.anim.voice_activity_open_enter
1170 : com.android.internal.R.anim.voice_activity_open_exit);
1171 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1172 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001173 + " anim=" + a + " transit=" + appTransitionToString(transit)
1174 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001175 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1176 || transit == TRANSIT_TASK_CLOSE
1177 || transit == TRANSIT_TASK_TO_BACK)) {
1178 a = loadAnimationRes(lp, enter
1179 ? com.android.internal.R.anim.voice_activity_close_enter
1180 : com.android.internal.R.anim.voice_activity_close_exit);
1181 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1182 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001183 + " anim=" + a + " transit=" + appTransitionToString(transit)
1184 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001185 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001186 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001187 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1188 "applyAnimation:"
1189 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1190 + " transit=" + appTransitionToString(transit)
1191 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001192 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1193 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001194 mNextAppTransitionEnter : mNextAppTransitionExit);
1195 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1196 "applyAnimation:"
1197 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001198 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001199 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001200 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1201 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1202 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1203 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001204 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1205 + " transit=" + appTransitionToString(transit)
1206 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001207 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001208 a = createClipRevealAnimationLocked(transit, enter, frame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001209 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1210 "applyAnimation:"
1211 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001212 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001213 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001214 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001215 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001216 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1217 "applyAnimation:"
1218 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001219 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001220 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001221 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1222 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001223 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001224 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001225 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001226 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001227 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1228 String animName = mNextAppTransitionScaleUp ?
1229 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1230 Slog.v(TAG, "applyAnimation:"
1231 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001232 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001233 + " Callers=" + Debug.getCallers(3));
1234 }
1235 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1236 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1237 mNextAppTransitionScaleUp =
1238 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1239 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001240 getThumbnailTransitionState(enter), orientation, transit, frame,
1241 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001242 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1243 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001244 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001245 Slog.v(TAG, "applyAnimation:"
1246 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001247 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001248 + " Callers=" + Debug.getCallers(3));
1249 }
1250 } else {
1251 int animAttr = 0;
1252 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001253 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001254 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001255 ? WindowAnimation_activityOpenEnterAnimation
1256 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001257 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001258 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001259 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001260 ? WindowAnimation_activityCloseEnterAnimation
1261 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001262 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001263 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001264 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001265 ? WindowAnimation_taskOpenEnterAnimation
1266 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001267 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001268 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001269 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001270 ? WindowAnimation_taskCloseEnterAnimation
1271 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001272 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001273 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001274 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001275 ? WindowAnimation_taskToFrontEnterAnimation
1276 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001277 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001278 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001279 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001280 ? WindowAnimation_taskToBackEnterAnimation
1281 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001282 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001283 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001284 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001285 ? WindowAnimation_wallpaperOpenEnterAnimation
1286 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001287 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001288 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001289 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001290 ? WindowAnimation_wallpaperCloseEnterAnimation
1291 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001292 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001293 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001294 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001295 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1296 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001297 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001298 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001299 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001300 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1301 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001302 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001303 case TRANSIT_TASK_OPEN_BEHIND:
1304 animAttr = enter
1305 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001306 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001307 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001308 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001309 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1310 "applyAnimation:"
1311 + " anim=" + a
1312 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001313 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001314 + " Callers=" + Debug.getCallers(3));
1315 }
1316 return a;
1317 }
1318
1319 void postAnimationCallback() {
1320 if (mNextAppTransitionCallback != null) {
1321 mH.sendMessage(mH.obtainMessage(H.DO_ANIMATION_CALLBACK, mNextAppTransitionCallback));
1322 mNextAppTransitionCallback = null;
1323 }
1324 }
1325
1326 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001327 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001328 if (isTransitionSet()) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001329 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001330 mNextAppTransitionPackage = packageName;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001331 mNextAppTransitionAnimationsSpecs.clear();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001332 mNextAppTransitionEnter = enterAnim;
1333 mNextAppTransitionExit = exitAnim;
1334 postAnimationCallback();
1335 mNextAppTransitionCallback = startedCallback;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001336 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001337 } else {
1338 postAnimationCallback();
1339 }
1340 }
1341
1342 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001343 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001344 if (isTransitionSet()) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001345 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001346 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001347 mNextAppTransitionAnimationsSpecs.clear();
1348 putDefaultNextAppTransitionCoordinates(startX, startY, startX + startWidth,
1349 startY + startHeight);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001350 postAnimationCallback();
1351 mNextAppTransitionCallback = null;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001352 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001353 }
1354 }
1355
Chet Haase10e23ab2015-02-11 15:08:38 -08001356 void overridePendingAppTransitionClipReveal(int startX, int startY,
1357 int startWidth, int startHeight) {
1358 if (isTransitionSet()) {
1359 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001360 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight);
Chet Haase10e23ab2015-02-11 15:08:38 -08001361 postAnimationCallback();
1362 mNextAppTransitionCallback = null;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001363 mAnimationFinishedCallback = null;
Chet Haase10e23ab2015-02-11 15:08:38 -08001364 }
1365 }
1366
Craig Mautner164d4bb2012-11-26 13:51:23 -08001367 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1368 IRemoteCallback startedCallback, boolean scaleUp) {
1369 if (isTransitionSet()) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001370 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1371 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001372 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001373 mNextAppTransitionAnimationsSpecs.clear();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001374 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001375 putDefaultNextAppTransitionCoordinates(startX, startY, 0 ,0);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001376 postAnimationCallback();
1377 mNextAppTransitionCallback = startedCallback;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001378 mAnimationFinishedCallback = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001379 } else {
1380 postAnimationCallback();
1381 }
1382 }
1383
Winson Chunga4ccb862014-08-22 15:26:27 -07001384 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001385 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001386 if (isTransitionSet()) {
1387 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1388 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
1389 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001390 mNextAppTransitionAnimationsSpecs.clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001391 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001392 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight);
Winson Chunga4ccb862014-08-22 15:26:27 -07001393 postAnimationCallback();
1394 mNextAppTransitionCallback = startedCallback;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001395 mAnimationFinishedCallback = null;
Winson Chunga4ccb862014-08-22 15:26:27 -07001396 } else {
1397 postAnimationCallback();
1398 }
1399 }
1400
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001401 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001402 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1403 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001404 if (isTransitionSet()) {
1405 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1406 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
1407 mNextAppTransitionPackage = null;
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001408 mDefaultNextAppTransitionAnimationSpec = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001409 mNextAppTransitionAnimationsSpecs.clear();
1410 mNextAppTransitionScaleUp = scaleUp;
1411 for (int i = 0; i < specs.length; i++) {
1412 AppTransitionAnimationSpec spec = specs[i];
1413 if (spec != null) {
1414 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001415 if (i == 0) {
1416 // In full screen mode, the transition code depends on the default spec to
1417 // be set.
1418 Rect rect = spec.rect;
1419 putDefaultNextAppTransitionCoordinates(rect.left, rect.top, rect.width(),
1420 rect.height());
1421 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001422 }
1423 }
1424 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001425 mNextAppTransitionCallback = onAnimationStartedCallback;
1426 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001427 } else {
1428 postAnimationCallback();
1429 }
1430 }
1431
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001432 void overridePendingAppTransitionMultiThumbFuture(
1433 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1434 boolean scaleUp) {
1435 if (isTransitionSet()) {
1436 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1437 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
1438 mNextAppTransitionPackage = null;
1439 mDefaultNextAppTransitionAnimationSpec = null;
1440 mNextAppTransitionAnimationsSpecs.clear();
1441 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1442 mNextAppTransitionScaleUp = scaleUp;
1443 postAnimationCallback();
1444 mNextAppTransitionCallback = callback;
1445 } else {
1446 postAnimationCallback();
1447 }
1448 }
1449
Winson Chung044d5292014-11-06 11:05:19 -08001450 void overrideInPlaceAppTransition(String packageName, int anim) {
1451 if (isTransitionSet()) {
1452 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1453 mNextAppTransitionPackage = packageName;
1454 mNextAppTransitionInPlace = anim;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001455 mAnimationFinishedCallback = null;
Winson Chung044d5292014-11-06 11:05:19 -08001456 } else {
1457 postAnimationCallback();
1458 }
1459 }
1460
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001461 /**
1462 * If a future is set for the app transition specs, fetch it in another thread.
1463 */
1464 private void fetchAppTransitionSpecsFromFuture() {
1465 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1466 mNextAppTransitionAnimationsSpecsPending = true;
1467 final IAppTransitionAnimationSpecsFuture future
1468 = mNextAppTransitionAnimationsSpecsFuture;
1469 mNextAppTransitionAnimationsSpecsFuture = null;
1470 mDefaultExecutor.execute(new Runnable() {
1471 @Override
1472 public void run() {
1473 AppTransitionAnimationSpec[] specs = null;
1474 try {
1475 specs = future.get();
1476 } catch (RemoteException e) {
1477 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1478 }
1479 synchronized (mServiceLock) {
1480 mNextAppTransitionAnimationsSpecsPending = false;
1481 overridePendingAppTransitionMultiThumb(specs, mNextAppTransitionCallback,
1482 null /* finishedCallback */, mNextAppTransitionScaleUp);
1483 mWindowSurfacePlacer.requestTraversal();
1484 }
1485 }
1486 });
1487 }
1488 }
1489
Craig Mautner164d4bb2012-11-26 13:51:23 -08001490 @Override
1491 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001492 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001493 }
1494
Craig Mautner4b71aa12012-12-27 17:20:01 -08001495 /**
1496 * Returns the human readable name of a window transition.
1497 *
1498 * @param transition The window transition.
1499 * @return The transition symbolic name.
1500 */
1501 public static String appTransitionToString(int transition) {
1502 switch (transition) {
1503 case TRANSIT_UNSET: {
1504 return "TRANSIT_UNSET";
1505 }
1506 case TRANSIT_NONE: {
1507 return "TRANSIT_NONE";
1508 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001509 case TRANSIT_ACTIVITY_OPEN: {
1510 return "TRANSIT_ACTIVITY_OPEN";
1511 }
1512 case TRANSIT_ACTIVITY_CLOSE: {
1513 return "TRANSIT_ACTIVITY_CLOSE";
1514 }
1515 case TRANSIT_TASK_OPEN: {
1516 return "TRANSIT_TASK_OPEN";
1517 }
1518 case TRANSIT_TASK_CLOSE: {
1519 return "TRANSIT_TASK_CLOSE";
1520 }
1521 case TRANSIT_TASK_TO_FRONT: {
1522 return "TRANSIT_TASK_TO_FRONT";
1523 }
1524 case TRANSIT_TASK_TO_BACK: {
1525 return "TRANSIT_TASK_TO_BACK";
1526 }
1527 case TRANSIT_WALLPAPER_CLOSE: {
1528 return "TRANSIT_WALLPAPER_CLOSE";
1529 }
1530 case TRANSIT_WALLPAPER_OPEN: {
1531 return "TRANSIT_WALLPAPER_OPEN";
1532 }
1533 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1534 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1535 }
1536 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1537 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1538 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001539 case TRANSIT_TASK_OPEN_BEHIND: {
1540 return "TRANSIT_TASK_OPEN_BEHIND";
1541 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001542 case TRANSIT_ACTIVITY_RELAUNCH: {
1543 return "TRANSIT_ACTIVITY_RELAUNCH";
1544 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001545 default: {
1546 return "<UNKNOWN>";
1547 }
1548 }
1549 }
1550
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001551 private String appStateToString() {
1552 switch (mAppTransitionState) {
1553 case APP_STATE_IDLE:
1554 return "APP_STATE_IDLE";
1555 case APP_STATE_READY:
1556 return "APP_STATE_READY";
1557 case APP_STATE_RUNNING:
1558 return "APP_STATE_RUNNING";
1559 case APP_STATE_TIMEOUT:
1560 return "APP_STATE_TIMEOUT";
1561 default:
1562 return "unknown state=" + mAppTransitionState;
1563 }
1564 }
1565
1566 private String transitTypeToString() {
1567 switch (mNextAppTransitionType) {
1568 case NEXT_TRANSIT_TYPE_NONE:
1569 return "NEXT_TRANSIT_TYPE_NONE";
1570 case NEXT_TRANSIT_TYPE_CUSTOM:
1571 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001572 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1573 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001574 case NEXT_TRANSIT_TYPE_SCALE_UP:
1575 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1576 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1577 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1578 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1579 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001580 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1581 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1582 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1583 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001584 default:
1585 return "unknown type=" + mNextAppTransitionType;
1586 }
1587 }
1588
Craig Mautner164d4bb2012-11-26 13:51:23 -08001589 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001590 public void dump(PrintWriter pw, String prefix) {
1591 pw.print(prefix); pw.println(this);
1592 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001593 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001594 pw.print(prefix); pw.print("mNextAppTransitionType=");
1595 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001596 }
1597 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001598 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001599 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001600 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001601 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001602 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1603 pw.print(" mNextAppTransitionExit=0x");
1604 pw.println(Integer.toHexString(mNextAppTransitionExit));
1605 break;
Winson Chung044d5292014-11-06 11:05:19 -08001606 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001607 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001608 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001609 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001610 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1611 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001612 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001613 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001614 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001615 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001616 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001617 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001618 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001619 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001620 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001621 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001622 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001623 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001624 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1625 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001626 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001627 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1628 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1629 pw.println(mDefaultNextAppTransitionAnimationSpec);
1630 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1631 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001632 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1633 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001634 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001635 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001636 }
1637 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001638 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1639 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001640 }
1641 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001642
1643 public void setCurrentUser(int newUserId) {
1644 mCurrentUserId = newUserId;
1645 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001646
1647 /**
1648 * @return true if transition is not running and should not be skipped, false if transition is
1649 * already running
1650 */
1651 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent) {
1652 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
1653 + " transit=" + appTransitionToString(transit)
1654 + " " + this
1655 + " alwaysKeepCurrent=" + alwaysKeepCurrent
1656 + " Callers=" + Debug.getCallers(3));
1657 if (!isTransitionSet() || mNextAppTransition == TRANSIT_NONE) {
1658 setAppTransition(transit);
1659 } else if (!alwaysKeepCurrent) {
1660 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
1661 // Opening a new task always supersedes a close for the anim.
1662 setAppTransition(transit);
1663 } else if (transit == TRANSIT_ACTIVITY_OPEN
1664 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
1665 // Opening a new activity always supersedes a close for the anim.
1666 setAppTransition(transit);
1667 }
1668 }
1669 boolean prepared = prepare();
1670 if (isTransitionSet()) {
1671 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
1672 mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
1673 }
1674 return prepared;
1675 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001676}