blob: 915951381ac756af597ae7b13ce8125ff36b8f42 [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;
Jorim Jaggi363ab982016-04-26 19:51:20 -070042import static com.android.server.wm.AppWindowAnimator.PROLONG_ANIMATION_AT_START;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080043import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
44import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080045import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
46import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010047import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
48import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
Filip Gruszczynski82861362015-10-16 14:21:09 -070049
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070050import android.annotation.Nullable;
Craig Mautner164d4bb2012-11-26 13:51:23 -080051import android.content.Context;
Winson21700932016-03-24 17:26:23 -070052import android.content.res.Configuration;
Craig Mautner164d4bb2012-11-26 13:51:23 -080053import android.graphics.Bitmap;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010054import android.graphics.Path;
Winson Chung399f6202014-03-19 10:47:20 -070055import android.graphics.Rect;
Craig Mautner164d4bb2012-11-26 13:51:23 -080056import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010057import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080058import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010059import android.os.RemoteException;
Manu Cornetd7376802017-01-13 13:44:07 -080060import android.os.SystemProperties;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080061import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080062import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070063import android.util.SparseArray;
64import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010065import android.view.IAppTransitionAnimationSpecsFuture;
Craig Mautner164d4bb2012-11-26 13:51:23 -080066import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080067import android.view.animation.AlphaAnimation;
68import android.view.animation.Animation;
69import android.view.animation.AnimationSet;
70import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070071import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080072import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070073import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080074import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070075import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070076
Craig Mautner164d4bb2012-11-26 13:51:23 -080077import com.android.internal.util.DumpUtils.Dump;
78import com.android.server.AttributeCache;
79import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -080080import com.android.server.wm.animation.ClipRectLRAnimation;
81import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010082import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080083
84import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010085import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010086import java.util.concurrent.ExecutorService;
87import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -080088
Craig Mautner164d4bb2012-11-26 13:51:23 -080089// State management of app transitions. When we are preparing for a
90// transition, mNextAppTransition will be the kind of transition to
91// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
92// mOpeningApps and mClosingApps are the lists of tokens that will be
93// made visible or hidden at the next transition.
94public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080095 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070096 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080097
Craig Mautner4b71aa12012-12-27 17:20:01 -080098 /** Not set up for a transition. */
99 public static final int TRANSIT_UNSET = -1;
100 /** No animation for transition. */
101 public static final int TRANSIT_NONE = 0;
102 /** 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 -0700103 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800104 /** The window in the top-most activity is being closed to reveal the
105 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700106 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800107 /** A window in a new task is being opened on top of an existing one
108 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700109 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800110 /** A window in the top-most activity is being closed to reveal the
111 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700112 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800113 /** A window in an existing task is being displayed on top of an existing one
114 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700115 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800116 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700117 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800118 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
119 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700120 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800121 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
122 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700123 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800124 /** A window in a new activity is being opened on top of an existing one, and both are on top
125 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700126 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800127 /** The window in the top-most activity is being closed to reveal the previous activity, and
128 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700129 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
130 /** A window in a new task is being opened behind an existing one in another activity's task.
131 * The new window will show briefly and then be gone. */
132 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800133 /** A window in a task is being animated in-place. */
134 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700135 /** An activity is being relaunched (e.g. due to configuration change). */
136 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Jorim Jaggi192086e2016-03-11 17:17:03 +0100137 /** A task is being docked from recents. */
138 public static final int TRANSIT_DOCK_TASK_FROM_RECENTS = 19;
Jorim Jaggife762342016-10-13 14:33:27 +0200139 /** Keyguard is going away */
140 public static final int TRANSIT_KEYGUARD_GOING_AWAY = 20;
141 /** Keyguard is going away with showing an activity behind that requests wallpaper */
142 public static final int TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER = 21;
143 /** Keyguard is being occluded */
144 public static final int TRANSIT_KEYGUARD_OCCLUDE = 22;
145 /** Keyguard is being unoccluded */
146 public static final int TRANSIT_KEYGUARD_UNOCCLUDE = 23;
147
148 /** Transition flag: Keyguard is going away, but keeping the notification shade open */
149 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE = 0x1;
150 /** Transition flag: Keyguard is going away, but doesn't want an animation for it */
151 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION = 0x2;
152 /** Transition flag: Keyguard is going away while it was showing the system wallpaper. */
153 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER = 0x4;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800154
Winson Chunga4ccb862014-08-22 15:26:27 -0700155 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700156 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800157 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700158 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800159
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800160 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800161
162 /** Interpolator to be used for animations that respond directly to a touch */
163 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
164 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
165
Jorim Jaggic69bd222016-03-15 14:38:37 +0100166 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
167 new PathInterpolator(0.85f, 0f, 1f, 1f);
168
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800169 /**
170 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
171 * involved, to make it more understandable.
172 */
173 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700174 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700175 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800176
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800177 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800178 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800179
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800180 private int mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200181 private int mNextAppTransitionFlags = 0;
Chong Zhang60091a92016-07-27 17:52:45 -0700182 private int mLastUsedAppTransition = TRANSIT_UNSET;
183 private String mLastOpeningApp;
184 private String mLastClosingApp;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800185
186 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
187 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
188 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
189 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
190 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700191 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
192 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800193 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800194 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800195 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
196
Winson Chung399f6202014-03-19 10:47:20 -0700197 // These are the possible states for the enter/exit activities during a thumbnail transition
198 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
199 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
200 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
201 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
202
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800203 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800204 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800205 private boolean mNextAppTransitionScaleUp;
206 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100207 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700208 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800209 private int mNextAppTransitionEnter;
210 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800211 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700212
213 // Keyed by task id.
214 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
215 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100216 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
217 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700218 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
219
Winson Chunga4ccb862014-08-22 15:26:27 -0700220 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800221
Winson Chung2820c452014-04-15 15:34:44 -0700222 private Rect mTmpFromClipRect = new Rect();
223 private Rect mTmpToClipRect = new Rect();
224
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700225 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700226
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800227 private final static int APP_STATE_IDLE = 0;
228 private final static int APP_STATE_READY = 1;
229 private final static int APP_STATE_RUNNING = 2;
230 private final static int APP_STATE_TIMEOUT = 3;
231 private int mAppTransitionState = APP_STATE_IDLE;
232
233 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800234 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700235 private final Interpolator mThumbnailFadeInInterpolator;
236 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800237 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700238 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100239 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700240 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
241
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700242 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800243
Amith Yamasani4befbec2013-07-10 16:18:01 -0700244 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800245 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700246
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100247 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100248 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100249
Jorim Jaggif97ed922016-02-18 18:57:07 -0800250 private int mLastClipRevealMaxTranslation;
251 private boolean mLastHadClipReveal;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700252 private boolean mProlongedAnimationsEnded;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800253
Manu Cornetd7376802017-01-13 13:44:07 -0800254 private final boolean mGridLayoutRecentsEnabled;
255
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800256 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800257 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800258 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800259 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
260 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700261 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
262 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100263 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
264 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800265 mConfigShortAnimTime = context.getResources().getInteger(
266 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800267 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
268 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700269 mThumbnailFadeInInterpolator = new Interpolator() {
270 @Override
271 public float getInterpolation(float input) {
272 // Linear response for first fraction, then complete after that.
273 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
274 return 0f;
275 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700276 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700277 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700278 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700279 }
280 };
281 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800282 @Override
283 public float getInterpolation(float input) {
284 // Linear response for first fraction, then complete after that.
285 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700286 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
287 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800288 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700289 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800290 }
291 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700292 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
293 * mContext.getResources().getDisplayMetrics().density);
Manu Cornetd7376802017-01-13 13:44:07 -0800294 mGridLayoutRecentsEnabled = SystemProperties.getBoolean("ro.recents.grid", false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800295 }
296
297 boolean isTransitionSet() {
298 return mNextAppTransition != TRANSIT_UNSET;
299 }
300
Craig Mautner164d4bb2012-11-26 13:51:23 -0800301 boolean isTransitionEqual(int transit) {
302 return mNextAppTransition == transit;
303 }
304
305 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800306 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800307 }
308
Jorim Jaggife762342016-10-13 14:33:27 +0200309 private void setAppTransition(int transit, int flags) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800310 mNextAppTransition = transit;
Jorim Jaggife762342016-10-13 14:33:27 +0200311 mNextAppTransitionFlags |= flags;
Chong Zhang60091a92016-07-27 17:52:45 -0700312 setLastAppTransition(TRANSIT_UNSET, null, null);
313 }
314
315 void setLastAppTransition(int transit, AppWindowToken openingApp, AppWindowToken closingApp) {
316 mLastUsedAppTransition = transit;
317 mLastOpeningApp = "" + openingApp;
318 mLastClosingApp = "" + closingApp;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800319 }
320
321 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800322 return mAppTransitionState == APP_STATE_READY
323 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800324 }
325
Craig Mautnerae446592012-12-06 19:05:05 -0800326 void setReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800327 mAppTransitionState = APP_STATE_READY;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100328 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800329 }
330
331 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800332 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800333 }
334
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800335 void setIdle() {
336 mAppTransitionState = APP_STATE_IDLE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800337 }
338
339 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800340 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800341 }
342
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800343 void setTimeout() {
344 mAppTransitionState = APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800345 }
346
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700347 Bitmap getAppTransitionThumbnailHeader(int taskId) {
348 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800349 if (spec == null) {
350 spec = mDefaultNextAppTransitionAnimationSpec;
351 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700352 return spec != null ? spec.bitmap : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800353 }
354
Winson Chunga4ccb862014-08-22 15:26:27 -0700355 /** Returns whether the next thumbnail transition is aspect scaled up. */
356 boolean isNextThumbnailTransitionAspectScaled() {
357 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
358 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
359 }
360
361 /** Returns whether the next thumbnail transition is scaling up. */
362 boolean isNextThumbnailTransitionScaleUp() {
363 return mNextAppTransitionScaleUp;
364 }
365
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800366 boolean isNextAppTransitionThumbnailUp() {
367 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
368 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
369 }
370
371 boolean isNextAppTransitionThumbnailDown() {
372 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
373 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
374 }
375
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100376 /**
377 * @return true if and only if we are currently fetching app transition specs from the future
378 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
379 */
380 boolean isFetchingAppTransitionsSpecs() {
381 return mNextAppTransitionAnimationsSpecsPending;
382 }
383
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700384 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800385 if (!isRunning()) {
386 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100387 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800388 mLastHadClipReveal = false;
389 mLastClipRevealMaxTranslation = 0;
390 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700391 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800392 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700393 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800394 }
395
Jorim Jaggife762342016-10-13 14:33:27 +0200396 /**
397 * @return bit-map of WindowManagerPolicy#FINISH_LAYOUT_REDO_* to indicate whether another
398 * layout pass needs to be done
399 */
400 int goodToGo(int transit, AppWindowAnimator topOpeningAppAnimator,
401 AppWindowAnimator topClosingAppAnimator, ArraySet<AppWindowToken> openingApps,
402 ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800403 mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200404 mNextAppTransitionFlags = 0;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800405 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggife762342016-10-13 14:33:27 +0200406 int redoLayout = notifyAppTransitionStartingLocked(transit,
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800407 topOpeningAppAnimator != null ? topOpeningAppAnimator.mAppToken.token : null,
408 topClosingAppAnimator != null ? topClosingAppAnimator.mAppToken.token : null,
409 topOpeningAppAnimator != null ? topOpeningAppAnimator.animation : null,
410 topClosingAppAnimator != null ? topClosingAppAnimator.animation : null);
411 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Jorim Jaggife762342016-10-13 14:33:27 +0200412 .notifyAppTransitionStarting(openingApps, transit);
Jorim Jaggi363ab982016-04-26 19:51:20 -0700413
414 // Prolong the start for the transition when docking a task from recents, unless recents
415 // ended it already then we don't need to wait.
Jorim Jaggife762342016-10-13 14:33:27 +0200416 if (transit == TRANSIT_DOCK_TASK_FROM_RECENTS && !mProlongedAnimationsEnded) {
Jorim Jaggi363ab982016-04-26 19:51:20 -0700417 for (int i = openingApps.size() - 1; i >= 0; i--) {
418 final AppWindowAnimator appAnimator = openingApps.valueAt(i).mAppAnimator;
419 appAnimator.startProlongAnimation(PROLONG_ANIMATION_AT_START);
420 }
421 }
Jorim Jaggife762342016-10-13 14:33:27 +0200422 return redoLayout;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700423 }
424
425 /**
426 * Let the transitions manager know that the somebody wanted to end the prolonged animations.
427 */
428 void notifyProlongedAnimationsEnded() {
429 mProlongedAnimationsEnded = true;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800430 }
431
432 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800433 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800434 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700435 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi65193992015-11-23 16:49:59 -0800436 mNextAppTransitionAnimationsSpecsFuture = null;
437 mDefaultNextAppTransitionAnimationSpec = null;
438 mAnimationFinishedCallback = null;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700439 mProlongedAnimationsEnded = false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800440 }
441
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800442 void freeze() {
Jorim Jaggife762342016-10-13 14:33:27 +0200443 final int transit = mNextAppTransition;
444 setAppTransition(AppTransition.TRANSIT_UNSET, 0 /* flags */);
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800445 clear();
446 setReady();
Jorim Jaggife762342016-10-13 14:33:27 +0200447 notifyAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100448 }
449
450 void registerListenerLocked(AppTransitionListener listener) {
451 mListeners.add(listener);
452 }
453
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700454 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100455 for (int i = 0; i < mListeners.size(); i++) {
456 mListeners.get(i).onAppTransitionFinishedLocked(token);
457 }
458 }
459
460 private void notifyAppTransitionPendingLocked() {
461 for (int i = 0; i < mListeners.size(); i++) {
462 mListeners.get(i).onAppTransitionPendingLocked();
463 }
464 }
465
Jorim Jaggife762342016-10-13 14:33:27 +0200466 private void notifyAppTransitionCancelledLocked(int transit) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100467 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200468 mListeners.get(i).onAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100469 }
470 }
471
Jorim Jaggife762342016-10-13 14:33:27 +0200472 private int notifyAppTransitionStartingLocked(int transit, IBinder openToken,
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100473 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
Jorim Jaggife762342016-10-13 14:33:27 +0200474 int redoLayout = 0;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100475 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200476 redoLayout |= mListeners.get(i).onAppTransitionStartingLocked(transit, openToken,
477 closeToken, openAnimation, closeAnimation);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100478 }
Jorim Jaggife762342016-10-13 14:33:27 +0200479 return redoLayout;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800480 }
481
Craig Mautner164d4bb2012-11-26 13:51:23 -0800482 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
483 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
484 + (lp != null ? lp.packageName : null)
485 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
486 if (lp != null && lp.windowAnimations != 0) {
487 // If this is a system resource, don't try to load it from the
488 // application resources. It is nice to avoid loading application
489 // resources if we can.
490 String packageName = lp.packageName != null ? lp.packageName : "android";
491 int resId = lp.windowAnimations;
492 if ((resId&0xFF000000) == 0x01000000) {
493 packageName = "android";
494 }
495 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
496 + packageName);
497 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700498 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800499 }
500 return null;
501 }
502
503 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
504 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
505 + packageName + " resId=0x" + Integer.toHexString(resId));
506 if (packageName != null) {
507 if ((resId&0xFF000000) == 0x01000000) {
508 packageName = "android";
509 }
510 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
511 + packageName);
512 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700513 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800514 }
515 return null;
516 }
517
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700518 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800519 int anim = 0;
520 Context context = mContext;
521 if (animAttr >= 0) {
522 AttributeCache.Entry ent = getCachedAnimations(lp);
523 if (ent != null) {
524 context = ent.context;
525 anim = ent.array.getResourceId(animAttr, 0);
526 }
527 }
528 if (anim != 0) {
529 return AnimationUtils.loadAnimation(context, anim);
530 }
531 return null;
532 }
533
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700534 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
535 Context context = mContext;
536 if (resId >= 0) {
537 AttributeCache.Entry ent = getCachedAnimations(lp);
538 if (ent != null) {
539 context = ent.context;
540 }
541 return AnimationUtils.loadAnimation(context, resId);
542 }
543 return null;
544 }
545
546 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800547 int anim = 0;
548 Context context = mContext;
549 if (resId >= 0) {
550 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
551 if (ent != null) {
552 context = ent.context;
553 anim = resId;
554 }
555 }
556 if (anim != 0) {
557 return AnimationUtils.loadAnimation(context, anim);
558 }
559 return null;
560 }
561
Craig Mautner164d4bb2012-11-26 13:51:23 -0800562 /**
563 * Compute the pivot point for an animation that is scaling from a small
564 * rect on screen to a larger rect. The pivot point varies depending on
565 * the distance between the inner and outer edges on both sides. This
566 * function computes the pivot point for one dimension.
567 * @param startPos Offset from left/top edge of outer rectangle to
568 * left/top edge of inner rectangle.
569 * @param finalScale The scaling factor between the size of the outer
570 * and inner rectangles.
571 */
572 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800573
574 /*
575 Theorem of intercepting lines:
576
577 + + +-----------------------------------------------+
578 | | | |
579 | | | |
580 | | | |
581 | | | |
582 x | y | | |
583 | | | |
584 | | | |
585 | | | |
586 | | | |
587 | + | +--------------------+ |
588 | | | | |
589 | | | | |
590 | | | | |
591 | | | | |
592 | | | | |
593 | | | | |
594 | | | | |
595 | | | | |
596 | | | | |
597 | | | | |
598 | | | | |
599 | | | | |
600 | | | | |
601 | | | | |
602 | | | | |
603 | | | | |
604 | | | | |
605 | | +--------------------+ |
606 | | |
607 | | |
608 | | |
609 | | |
610 | | |
611 | | |
612 | | |
613 | +-----------------------------------------------+
614 |
615 |
616 |
617 |
618 |
619 |
620 |
621 |
622 |
623 + ++
624 p ++
625
626 scale = (x - y) / x
627 <=> x = -y / (scale - 1)
628 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800629 final float denom = finalScale-1;
630 if (Math.abs(denom) < .0001f) {
631 return startPos;
632 }
633 return -startPos / denom;
634 }
635
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700636 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
637 Rect containingFrame) {
638 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700639 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700640 final int appWidth = containingFrame.width();
641 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800642 if (enter) {
643 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700644 float scaleW = mTmpRect.width() / (float) appWidth;
645 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800646 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700647 computePivot(mTmpRect.left, scaleW),
Winson4c3fecd2016-07-13 12:29:48 -0700648 computePivot(mTmpRect.top, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800649 scale.setInterpolator(mDecelerateInterpolator);
650
Craig Mautner164d4bb2012-11-26 13:51:23 -0800651 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700652 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800653
654 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800655 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800656 set.addAnimation(alpha);
657 set.setDetachWallpaper(true);
658 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800659 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
660 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800661 // If we are on top of the wallpaper, we need an animation that
662 // correctly handles the wallpaper staying static behind all of
663 // the animated elements. To do this, will just have the existing
664 // element fade out.
665 a = new AlphaAnimation(1, 0);
666 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800667 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800668 // For normal animations, the exiting element just holds in place.
669 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800670 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800671
672 // Pick the desired duration. If this is an inter-activity transition,
673 // it is the standard duration for that. Otherwise we use the longer
674 // task transition duration.
675 final long duration;
676 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800677 case TRANSIT_ACTIVITY_OPEN:
678 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800679 duration = mConfigShortAnimTime;
680 break;
681 default:
682 duration = DEFAULT_APP_TRANSITION_DURATION;
683 break;
684 }
685 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800686 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800687 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800688 a.initialize(appWidth, appHeight, appWidth, appHeight);
689 return a;
690 }
691
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700692 private void getDefaultNextAppTransitionStartRect(Rect rect) {
693 if (mDefaultNextAppTransitionAnimationSpec == null ||
694 mDefaultNextAppTransitionAnimationSpec.rect == null) {
695 Slog.wtf(TAG, "Starting rect for app requested, but none available", new Throwable());
696 rect.setEmpty();
697 } else {
698 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
699 }
700 }
701
702 void getNextAppTransitionStartRect(int taskId, Rect rect) {
703 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800704 if (spec == null) {
705 spec = mDefaultNextAppTransitionAnimationSpec;
706 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700707 if (spec == null || spec.rect == null) {
708 Slog.wtf(TAG, "Starting rect for task: " + taskId + " requested, but not available",
709 new Throwable());
710 rect.setEmpty();
711 } else {
712 rect.set(spec.rect);
713 }
714 }
715
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800716 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
717 Bitmap bitmap) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700718 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800719 bitmap, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700720 }
721
Jorim Jaggif97ed922016-02-18 18:57:07 -0800722 /**
723 * @return the duration of the last clip reveal animation
724 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800725 long getLastClipRevealTransitionDuration() {
726 return mLastClipRevealTransitionDuration;
727 }
728
729 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800730 * @return the maximum distance the app surface is traveling of the last clip reveal animation
731 */
732 int getLastClipRevealMaxTranslation() {
733 return mLastClipRevealMaxTranslation;
734 }
735
736 /**
737 * @return true if in the last app transition had a clip reveal animation, false otherwise
738 */
739 boolean hadClipRevealAnimation() {
740 return mLastHadClipReveal;
741 }
742
743 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800744 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
745 * the start rect is outside of the target rect, and there is a lot of movement going on.
746 *
747 * @param cutOff whether the start rect was not fully contained by the end rect
748 * @param translationX the total translation the surface moves in x direction
749 * @param translationY the total translation the surfaces moves in y direction
750 * @param displayFrame our display frame
751 *
752 * @return the duration of the clip reveal animation, in milliseconds
753 */
754 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
755 float translationY, Rect displayFrame) {
756 if (!cutOff) {
757 return DEFAULT_APP_TRANSITION_DURATION;
758 }
759 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
760 Math.abs(translationY) / displayFrame.height());
761 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
762 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
763 }
764
765 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
766 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800767 final Animation anim;
768 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700769 final int appWidth = appFrame.width();
770 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800771
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700772 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700773 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700774 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700775
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700776 float t = 0f;
777 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800778 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700779 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800780 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
781 int translationX = 0;
782 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700783 int centerX = mTmpRect.centerX();
784 int centerY = mTmpRect.centerY();
785 int halfWidth = mTmpRect.width() / 2;
786 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800787 int clipStartX = centerX - halfWidth - appFrame.left;
788 int clipStartY = centerY - halfHeight - appFrame.top;
789 boolean cutOff = false;
790
791 // If the starting rectangle is fully or partially outside of the target rectangle, we
792 // need to start the clipping at the edge and then achieve the rest with translation
793 // and extending the clip rect from that edge.
794 if (appFrame.top > centerY - halfHeight) {
795 translationY = (centerY - halfHeight) - appFrame.top;
796 translationYCorrection = 0;
797 clipStartY = 0;
798 cutOff = true;
799 }
800 if (appFrame.left > centerX - halfWidth) {
801 translationX = (centerX - halfWidth) - appFrame.left;
802 clipStartX = 0;
803 cutOff = true;
804 }
805 if (appFrame.right < centerX + halfWidth) {
806 translationX = (centerX + halfWidth) - appFrame.right;
807 clipStartX = appWidth - mTmpRect.width();
808 cutOff = true;
809 }
810 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
811 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700812
813 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800814 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800815 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700816 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800817 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700818
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800819 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
820 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
821 : mLinearOutSlowInInterpolator);
822 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800823
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800824 Animation clipAnimTB = new ClipRectTBAnimation(
825 clipStartY, clipStartY + mTmpRect.height(),
826 0, appHeight,
827 translationYCorrection, 0,
828 mLinearOutSlowInInterpolator);
829 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
830 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800831
832 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800833 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700834 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800835 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700836 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800837
838 AnimationSet set = new AnimationSet(false);
839 set.addAnimation(clipAnimLR);
840 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700841 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800842 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700843 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800844 set.initialize(appWidth, appHeight, appWidth, appHeight);
845 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800846 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800847 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800848
849 // If the start rect was full inside the target rect (cutOff == false), we don't need
850 // to store the translation, because it's only used if cutOff == true.
851 mLastClipRevealMaxTranslation = cutOff
852 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800853 } else {
854 final long duration;
855 switch (transit) {
856 case TRANSIT_ACTIVITY_OPEN:
857 case TRANSIT_ACTIVITY_CLOSE:
858 duration = mConfigShortAnimTime;
859 break;
860 default:
861 duration = DEFAULT_APP_TRANSITION_DURATION;
862 break;
863 }
864 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
865 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
866 // If we are on top of the wallpaper, we need an animation that
867 // correctly handles the wallpaper staying static behind all of
868 // the animated elements. To do this, will just have the existing
869 // element fade out.
870 anim = new AlphaAnimation(1, 0);
871 anim.setDetachWallpaper(true);
872 } else {
873 // For normal animations, the exiting element just holds in place.
874 anim = new AlphaAnimation(1, 1);
875 }
876 anim.setInterpolator(mDecelerateInterpolator);
877 anim.setDuration(duration);
878 anim.setFillAfter(true);
879 }
880 return anim;
881 }
882
Winson Chung399f6202014-03-19 10:47:20 -0700883 /**
884 * Prepares the specified animation with a standard duration, interpolator, etc.
885 */
Winson Chung5393dff2014-05-08 14:25:43 -0700886 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100887 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700888 if (duration > 0) {
889 a.setDuration(duration);
890 }
Winson Chung5393dff2014-05-08 14:25:43 -0700891 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100892 if (interpolator != null) {
893 a.setInterpolator(interpolator);
894 }
Winson Chung5393dff2014-05-08 14:25:43 -0700895 a.initialize(appWidth, appHeight, appWidth, appHeight);
896 return a;
897 }
898
899 /**
900 * Prepares the specified animation with a standard duration, interpolator, etc.
901 */
Winson Chung399f6202014-03-19 10:47:20 -0700902 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800903 // Pick the desired duration. If this is an inter-activity transition,
904 // it is the standard duration for that. Otherwise we use the longer
905 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700906 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800907 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800908 case TRANSIT_ACTIVITY_OPEN:
909 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800910 duration = mConfigShortAnimTime;
911 break;
912 default:
913 duration = DEFAULT_APP_TRANSITION_DURATION;
914 break;
915 }
Winson Chung5393dff2014-05-08 14:25:43 -0700916 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
917 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800918 }
919
Winson Chung399f6202014-03-19 10:47:20 -0700920 /**
921 * Return the current thumbnail transition state.
922 */
923 int getThumbnailTransitionState(boolean enter) {
924 if (enter) {
925 if (mNextAppTransitionScaleUp) {
926 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
927 } else {
928 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
929 }
930 } else {
931 if (mNextAppTransitionScaleUp) {
932 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
933 } else {
934 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
935 }
936 }
937 }
938
939 /**
940 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700941 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700942 */
Jorim Jaggide63d442016-03-14 14:56:56 +0100943 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winsonb2024762016-04-05 17:32:30 -0700944 Bitmap thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -0700945 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700946 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700947 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700948 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700949 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700950
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700951 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700952 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -0700953 final float fromX;
954 final float fromY;
955 final float toX;
956 final float toY;
957 final float pivotX;
958 final float pivotY;
Manu Cornetd7376802017-01-13 13:44:07 -0800959 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggi09072002016-03-25 16:48:42 -0700960 fromX = mTmpRect.left;
961 fromY = mTmpRect.top;
962
963 // For the curved translate animation to work, the pivot points needs to be at the
964 // same absolute position as the one from the real surface.
965 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
966 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
967 pivotX = mTmpRect.width() / 2;
968 pivotY = appRect.height() / 2 / scaleW;
969 } else {
970 pivotX = 0;
971 pivotY = 0;
972 fromX = mTmpRect.left;
973 fromY = mTmpRect.top;
974 toX = appRect.left;
975 toY = appRect.top;
976 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100977 final long duration = getAspectScaleDuration();
978 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -0700979 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700980 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +0100981 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100982 scale.setInterpolator(interpolator);
983 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800984 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100985 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
986 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
987 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
988 ? duration / 2
989 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100990 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
991 translate.setInterpolator(interpolator);
992 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -0700993
Jorim Jaggide63d442016-03-14 14:56:56 +0100994 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
995 mTmpToClipRect.set(appRect);
996
997 // Containing frame is in screen space, but we need the clip rect in the
998 // app space.
999 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001000 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
1001 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +01001002
1003 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001004 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
1005 (int) (-contentInsets.top * scaleW),
1006 (int) (-contentInsets.right * scaleW),
1007 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +01001008 }
1009
1010 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001011 clipAnim.setInterpolator(interpolator);
1012 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +01001013
Winson Chung399f6202014-03-19 10:47:20 -07001014 // This AnimationSet uses the Interpolators assigned above.
1015 AnimationSet set = new AnimationSet(false);
1016 set.addAnimation(scale);
1017 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -07001018 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001019 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001020 a = set;
1021 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001022 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001023 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001024 scale.setInterpolator(interpolator);
1025 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001026 Animation alpha = new AlphaAnimation(0f, 1f);
1027 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001028 alpha.setDuration(duration);
1029 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1030 translate.setInterpolator(interpolator);
1031 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001032
Winson Chunga4ccb862014-08-22 15:26:27 -07001033 // This AnimationSet uses the Interpolators assigned above.
1034 AnimationSet set = new AnimationSet(false);
1035 set.addAnimation(scale);
1036 set.addAnimation(alpha);
1037 set.addAnimation(translate);
1038 a = set;
1039
1040 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001041 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001042 null);
Winson Chung399f6202014-03-19 10:47:20 -07001043 }
1044
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001045 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1046
1047 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001048 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001049 return new TranslateAnimation(fromX, toX, fromY, toY);
1050 } else {
1051 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1052 return new CurvedTranslateAnimation(path);
1053 }
1054 }
1055
1056 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1057 final Path path = new Path();
1058 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001059
1060 if (fromY > toY) {
1061 // If the object needs to go up, move it in horizontal direction first, then vertical.
1062 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1063 } else {
1064 // If the object needs to go down, move it in vertical direction first, then horizontal.
1065 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1066 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001067 return path;
1068 }
1069
1070 private long getAspectScaleDuration() {
1071 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001072 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001073 } else {
1074 return THUMBNAIL_APP_TRANSITION_DURATION;
1075 }
1076 }
1077
1078 private Interpolator getAspectScaleInterpolator() {
1079 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1080 return mFastOutSlowInInterpolator;
1081 } else {
1082 return TOUCH_RESPONSE_INTERPOLATOR;
1083 }
1084 }
1085
Winson Chung399f6202014-03-19 10:47:20 -07001086 /**
1087 * This alternate animation is created when we are doing a thumbnail transition, for the
1088 * activity that is leaving, and the activity that is entering.
1089 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001090 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001091 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001092 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001093 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001094 final int appWidth = containingFrame.width();
1095 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001096 getDefaultNextAppTransitionStartRect(mTmpRect);
1097 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001098 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001099 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001100 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001101 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001102 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001103
1104 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001105 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1106 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1107 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1108 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001109 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001110 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001111 } else if (freeform) {
1112 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1113 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001114 } else {
Winson21700932016-03-24 17:26:23 -07001115 AnimationSet set = new AnimationSet(true);
1116
1117 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001118 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001119 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001120
1121 // Containing frame is in screen space, but we need the clip rect in the
1122 // app space.
1123 mTmpFromClipRect.offsetTo(0, 0);
1124 mTmpToClipRect.offsetTo(0, 0);
1125
1126 // Exclude insets region from the source clip.
1127 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001128 mNextAppTransitionInsets.set(contentInsets);
1129
Manu Cornetd7376802017-01-13 13:44:07 -08001130 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001131 // We scale the width and clip to the top/left square
1132 float scale = thumbWidth /
1133 (appWidth - contentInsets.left - contentInsets.right);
1134 int unscaledThumbHeight = (int) (thumbHeight / scale);
1135 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1136
1137 mNextAppTransitionInsets.set(contentInsets);
1138
Jorim Jaggi8448f332016-03-14 17:50:37 +01001139 Animation scaleAnim = new ScaleAnimation(
1140 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1141 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001142 containingFrame.width() / 2f,
1143 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001144 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001145 final float x = containingFrame.width() / 2f
1146 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001147 final float targetY = (mTmpRect.top - containingFrame.top);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001148 final float y = containingFrame.height() / 2f
1149 - containingFrame.height() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001150 final float startX = targetX - x;
1151 final float startY = targetY - y;
1152 Animation clipAnim = scaleUp
1153 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1154 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1155 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001156 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1157 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1158
Winson21700932016-03-24 17:26:23 -07001159 set.addAnimation(clipAnim);
1160 set.addAnimation(scaleAnim);
1161 set.addAnimation(translateAnim);
1162
1163 } else {
1164 // In landscape, we don't scale at all and only crop
1165 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1166 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1167
Jorim Jaggi8448f332016-03-14 17:50:37 +01001168 Animation clipAnim = scaleUp
1169 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1170 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1171 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001172 ? createCurvedMotion(thumbStartX, 0,
1173 thumbStartY - contentInsets.top, 0)
1174 : createCurvedMotion(0, thumbStartX, 0,
1175 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001176
1177 set.addAnimation(clipAnim);
1178 set.addAnimation(translateAnim);
1179 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001180 a = set;
Winson21700932016-03-24 17:26:23 -07001181 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001182 }
Winson Chung399f6202014-03-19 10:47:20 -07001183 break;
1184 }
1185 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001186 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001187 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001188 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001189 // activity.
1190 a = new AlphaAnimation(1, 0);
1191 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001192 a = new AlphaAnimation(1, 1);
1193 }
1194 break;
1195 }
1196 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001197 // Target app window during the scale down
1198 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1199 // Fade in the destination activity if we are animating from a wallpaper
1200 // activity.
1201 a = new AlphaAnimation(0, 1);
1202 } else {
1203 a = new AlphaAnimation(1, 1);
1204 }
Winson Chung399f6202014-03-19 10:47:20 -07001205 break;
1206 }
Winson Chung399f6202014-03-19 10:47:20 -07001207 default:
1208 throw new RuntimeException("Invalid thumbnail transition state");
1209 }
1210
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001211 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1212 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001213 }
1214
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001215 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1216 @Nullable Rect surfaceInsets, int taskId) {
1217 getNextAppTransitionStartRect(taskId, mTmpRect);
1218 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1219 true);
1220 }
1221
1222 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1223 @Nullable Rect surfaceInsets, int taskId) {
1224 getNextAppTransitionStartRect(taskId, mTmpRect);
1225 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1226 false);
1227 }
1228
1229 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1230 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1231 final float sourceWidth = sourceFrame.width();
1232 final float sourceHeight = sourceFrame.height();
1233 final float destWidth = destFrame.width();
1234 final float destHeight = destFrame.height();
1235 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1236 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001237 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001238 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001239 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001240 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001241 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1242 // We want the scaling to happen from the center of the surface. In order to achieve that,
1243 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001244 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1245 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1246 final ScaleAnimation scale = enter ?
1247 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1248 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1249 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1250 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1251 final int destHCenter = destFrame.left + destFrame.width() / 2;
1252 final int destVCenter = destFrame.top + destFrame.height() / 2;
1253 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1254 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1255 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1256 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001257 set.addAnimation(scale);
1258 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001259
1260 final IRemoteCallback callback = mAnimationFinishedCallback;
1261 if (callback != null) {
1262 set.setAnimationListener(new Animation.AnimationListener() {
1263 @Override
1264 public void onAnimationStart(Animation animation) { }
1265
1266 @Override
1267 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001268 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001269 }
1270
1271 @Override
1272 public void onAnimationRepeat(Animation animation) { }
1273 });
1274 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001275 return set;
1276 }
1277
Winson Chung399f6202014-03-19 10:47:20 -07001278 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001279 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001280 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001281 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001282 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
1283 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001284 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001285 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001286 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001287 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001288 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001289 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1290
1291 if (mNextAppTransitionScaleUp) {
1292 // Animation for the thumbnail zooming from its initial size to the full screen
1293 float scaleW = appWidth / thumbWidth;
1294 float scaleH = appHeight / thumbHeight;
1295 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001296 computePivot(mTmpRect.left, 1 / scaleW),
1297 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001298 scale.setInterpolator(mDecelerateInterpolator);
1299
1300 Animation alpha = new AlphaAnimation(1, 0);
1301 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1302
1303 // This AnimationSet uses the Interpolators assigned above.
1304 AnimationSet set = new AnimationSet(false);
1305 set.addAnimation(scale);
1306 set.addAnimation(alpha);
1307 a = set;
1308 } else {
1309 // Animation for the thumbnail zooming down from the full screen to its final size
1310 float scaleW = appWidth / thumbWidth;
1311 float scaleH = appHeight / thumbHeight;
1312 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001313 computePivot(mTmpRect.left, 1 / scaleW),
1314 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001315 }
1316
1317 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1318 }
1319
1320 /**
Winson Chung399f6202014-03-19 10:47:20 -07001321 * This animation is created when we are doing a thumbnail transition, for the activity that is
1322 * leaving, and the activity that is entering.
1323 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001324 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1325 int transit, int taskId) {
1326 final int appWidth = containingFrame.width();
1327 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001328 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001329 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001330 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001331 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001332 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001333 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001334 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1335
1336 switch (thumbTransitState) {
1337 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1338 // Entering app scales up with the thumbnail
1339 float scaleW = thumbWidth / appWidth;
1340 float scaleH = thumbHeight / appHeight;
1341 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001342 computePivot(mTmpRect.left, scaleW),
1343 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001344 break;
1345 }
1346 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1347 // Exiting app while the thumbnail is scaling up should fade or stay in place
1348 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1349 // Fade out while bringing up selected activity. This keeps the
1350 // current activity from showing through a launching wallpaper
1351 // activity.
1352 a = new AlphaAnimation(1, 0);
1353 } else {
1354 // noop animation
1355 a = new AlphaAnimation(1, 1);
1356 }
1357 break;
1358 }
1359 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1360 // Entering the other app, it should just be visible while we scale the thumbnail
1361 // down above it
1362 a = new AlphaAnimation(1, 1);
1363 break;
1364 }
1365 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1366 // Exiting the current app, the app should scale down with the thumbnail
1367 float scaleW = thumbWidth / appWidth;
1368 float scaleH = thumbHeight / appHeight;
1369 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001370 computePivot(mTmpRect.left, scaleW),
1371 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001372
1373 Animation alpha = new AlphaAnimation(1, 0);
1374
1375 AnimationSet set = new AnimationSet(true);
1376 set.addAnimation(scale);
1377 set.addAnimation(alpha);
1378 set.setZAdjustment(Animation.ZORDER_TOP);
1379 a = set;
1380 break;
1381 }
1382 default:
1383 throw new RuntimeException("Invalid thumbnail transition state");
1384 }
1385
1386 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1387 }
1388
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001389 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001390 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1391 final int left = mTmpFromClipRect.left;
1392 final int top = mTmpFromClipRect.top;
1393 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001394 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1395 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001396 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001397 float fromWidth = mTmpFromClipRect.width();
1398 float toWidth = mTmpToClipRect.width();
1399 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001400 // While the window might span the whole display, the actual content will be cropped to the
1401 // system decoration frame, for example when the window is docked. We need to take into
1402 // account the visible height when constructing the animation.
1403 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1404 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001405 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1406 // The final window is larger in both dimensions than current window (e.g. we are
1407 // maximizing), so we can simply unclip the new window and there will be no disappearing
1408 // frame.
1409 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1410 } else {
1411 // The disappearing window has one larger dimension. We need to apply scaling, so the
1412 // first frame of the entry animation matches the old window.
1413 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001414 // We might not be going exactly full screen, but instead be aligned under the status
1415 // bar using cropping. We still need to account for the cropped part, which will also
1416 // be scaled.
1417 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001418 }
1419
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001420 // We animate the translation from the old position of the removed window, to the new
1421 // position of the added window. The latter might not be full screen, for example docked for
1422 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001423 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001424 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001425 set.addAnimation(translate);
1426 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001427 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001428 return set;
1429 }
1430
Jorim Jaggic554b772015-06-04 16:07:57 -07001431 /**
1432 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1433 * frame of the transition doesn't change the visuals on screen, so we can start
1434 * directly with the second one
1435 */
1436 boolean canSkipFirstFrame() {
1437 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1438 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
Jorim Jaggife762342016-10-13 14:33:27 +02001439 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
1440 && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY;
Jorim Jaggic554b772015-06-04 16:07:57 -07001441 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001442
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001443 /**
1444 *
1445 * @param frame These are the bounds of the window when it finishes the animation. This is where
1446 * the animation must usually finish in entrance animation, as the next frame will
1447 * display the window at these coordinates. In case of exit animation, this is
1448 * where the animation must start, as the frame before the animation is displaying
1449 * the window at these bounds.
1450 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1451 * window might be obscured, usually by the system windows (status bar and
1452 * navigation bar) and we use content insets to convey that information. This
1453 * usually affects the animation aspects vertically, as the system decoration is
1454 * at the top and the bottom. For example when we animate from full screen to
1455 * recents, we want to exclude the covered parts, because they won't match the
1456 * thumbnail after the last frame is executed.
1457 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1458 * know about this to make the animation frames match. We currently use
1459 * this for freeform windows, which have larger surfaces to display
1460 * shadows. When we animate them from recents, we want to match the content
1461 * to the recents thumbnail and hence need to account for the surface being
1462 * bigger.
1463 */
Winsonb2024762016-04-05 17:32:30 -07001464 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001465 int orientation, Rect frame, Rect displayFrame, Rect insets,
1466 @Nullable Rect surfaceInsets, boolean isVoiceInteraction, boolean freeform,
1467 int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001468 Animation a;
Jorim Jaggife762342016-10-13 14:33:27 +02001469 if (isKeyguardGoingAwayTransit(transit) && enter) {
1470 a = loadKeyguardExitAnimation(transit);
1471 } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) {
1472 a = null;
1473 } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) {
1474 a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit);
1475 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001476 || transit == TRANSIT_TASK_OPEN
1477 || transit == TRANSIT_TASK_TO_FRONT)) {
1478 a = loadAnimationRes(lp, enter
1479 ? com.android.internal.R.anim.voice_activity_open_enter
1480 : com.android.internal.R.anim.voice_activity_open_exit);
1481 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1482 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001483 + " anim=" + a + " transit=" + appTransitionToString(transit)
1484 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001485 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1486 || transit == TRANSIT_TASK_CLOSE
1487 || transit == TRANSIT_TASK_TO_BACK)) {
1488 a = loadAnimationRes(lp, enter
1489 ? com.android.internal.R.anim.voice_activity_close_enter
1490 : com.android.internal.R.anim.voice_activity_close_exit);
1491 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1492 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001493 + " anim=" + a + " transit=" + appTransitionToString(transit)
1494 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001495 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001496 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001497 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1498 "applyAnimation:"
1499 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1500 + " transit=" + appTransitionToString(transit)
1501 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001502 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1503 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001504 mNextAppTransitionEnter : mNextAppTransitionExit);
1505 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1506 "applyAnimation:"
1507 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001508 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001509 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001510 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1511 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1512 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1513 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001514 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1515 + " transit=" + appTransitionToString(transit)
1516 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001517 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001518 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001519 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1520 "applyAnimation:"
1521 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001522 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001523 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001524 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001525 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001526 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1527 "applyAnimation:"
1528 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001529 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001530 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001531 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1532 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001533 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001534 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001535 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001536 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001537 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1538 String animName = mNextAppTransitionScaleUp ?
1539 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1540 Slog.v(TAG, "applyAnimation:"
1541 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001542 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001543 + " Callers=" + Debug.getCallers(3));
1544 }
1545 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1546 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1547 mNextAppTransitionScaleUp =
1548 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1549 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001550 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001551 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001552 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1553 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001554 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001555 Slog.v(TAG, "applyAnimation:"
1556 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001557 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001558 + " Callers=" + Debug.getCallers(3));
1559 }
1560 } else {
1561 int animAttr = 0;
1562 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001563 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001564 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001565 ? WindowAnimation_activityOpenEnterAnimation
1566 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001567 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001568 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001569 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001570 ? WindowAnimation_activityCloseEnterAnimation
1571 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001572 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001573 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001574 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001575 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001576 ? WindowAnimation_taskOpenEnterAnimation
1577 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001578 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001579 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001580 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001581 ? WindowAnimation_taskCloseEnterAnimation
1582 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001583 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001584 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001585 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001586 ? WindowAnimation_taskToFrontEnterAnimation
1587 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001588 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001589 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001590 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001591 ? WindowAnimation_taskToBackEnterAnimation
1592 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001593 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001594 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001595 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001596 ? WindowAnimation_wallpaperOpenEnterAnimation
1597 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001598 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001599 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001600 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001601 ? WindowAnimation_wallpaperCloseEnterAnimation
1602 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001603 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001604 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001605 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001606 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1607 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001608 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001609 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001610 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001611 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1612 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001613 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001614 case TRANSIT_TASK_OPEN_BEHIND:
1615 animAttr = enter
1616 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001617 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001618 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001619 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001620 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1621 "applyAnimation:"
1622 + " anim=" + a
1623 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001624 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001625 + " Callers=" + Debug.getCallers(3));
1626 }
1627 return a;
1628 }
1629
Jorim Jaggife762342016-10-13 14:33:27 +02001630 private Animation loadKeyguardExitAnimation(int transit) {
1631 if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) {
1632 return null;
1633 }
1634 final boolean toShade =
1635 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0;
1636 return mService.mPolicy.createHiddenByKeyguardExit(
1637 transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade);
1638 }
1639
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001640 int getAppStackClipMode() {
1641 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001642 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggife762342016-10-13 14:33:27 +02001643 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY
1644 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001645 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001646 ? STACK_CLIP_NONE
1647 : STACK_CLIP_AFTER_ANIM;
1648 }
1649
Jorim Jaggife762342016-10-13 14:33:27 +02001650 public int getTransitFlags() {
1651 return mNextAppTransitionFlags;
1652 }
1653
Craig Mautner164d4bb2012-11-26 13:51:23 -08001654 void postAnimationCallback() {
1655 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001656 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1657 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001658 mNextAppTransitionCallback = null;
1659 }
1660 }
1661
1662 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001663 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001664 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001665 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001666 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001667 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001668 mNextAppTransitionEnter = enterAnim;
1669 mNextAppTransitionExit = exitAnim;
1670 postAnimationCallback();
1671 mNextAppTransitionCallback = startedCallback;
1672 } else {
1673 postAnimationCallback();
1674 }
1675 }
1676
1677 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001678 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001679 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001680 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001681 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001682 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001683 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001684 }
1685 }
1686
Chet Haase10e23ab2015-02-11 15:08:38 -08001687 void overridePendingAppTransitionClipReveal(int startX, int startY,
1688 int startWidth, int startHeight) {
1689 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001690 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001691 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001692 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001693 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001694 }
1695 }
1696
Craig Mautner164d4bb2012-11-26 13:51:23 -08001697 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1698 IRemoteCallback startedCallback, boolean scaleUp) {
1699 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001700 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001701 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1702 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001703 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001704 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001705 postAnimationCallback();
1706 mNextAppTransitionCallback = startedCallback;
1707 } else {
1708 postAnimationCallback();
1709 }
1710 }
1711
Winson Chunga4ccb862014-08-22 15:26:27 -07001712 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001713 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001714 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001715 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001716 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1717 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001718 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001719 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1720 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001721 postAnimationCallback();
1722 mNextAppTransitionCallback = startedCallback;
1723 } else {
1724 postAnimationCallback();
1725 }
1726 }
1727
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001728 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001729 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1730 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001731 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001732 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001733 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1734 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001735 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001736 if (specs != null) {
1737 for (int i = 0; i < specs.length; i++) {
1738 AppTransitionAnimationSpec spec = specs[i];
1739 if (spec != null) {
1740 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1741 if (i == 0) {
1742 // In full screen mode, the transition code depends on the default spec
1743 // to be set.
1744 Rect rect = spec.rect;
1745 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Filip Gruszczynskie3264d82015-11-20 17:10:04 -08001746 rect.width(), rect.height(), spec.bitmap);
Jorim Jaggi43102412015-11-11 16:28:37 +01001747 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001748 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001749 }
1750 }
1751 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001752 mNextAppTransitionCallback = onAnimationStartedCallback;
1753 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001754 } else {
1755 postAnimationCallback();
1756 }
1757 }
1758
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001759 void overridePendingAppTransitionMultiThumbFuture(
1760 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1761 boolean scaleUp) {
1762 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001763 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001764 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1765 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001766 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1767 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001768 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001769 }
1770 }
1771
Winson Chung044d5292014-11-06 11:05:19 -08001772 void overrideInPlaceAppTransition(String packageName, int anim) {
1773 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001774 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001775 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1776 mNextAppTransitionPackage = packageName;
1777 mNextAppTransitionInPlace = anim;
1778 } else {
1779 postAnimationCallback();
1780 }
1781 }
1782
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001783 /**
1784 * If a future is set for the app transition specs, fetch it in another thread.
1785 */
1786 private void fetchAppTransitionSpecsFromFuture() {
1787 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1788 mNextAppTransitionAnimationsSpecsPending = true;
1789 final IAppTransitionAnimationSpecsFuture future
1790 = mNextAppTransitionAnimationsSpecsFuture;
1791 mNextAppTransitionAnimationsSpecsFuture = null;
1792 mDefaultExecutor.execute(new Runnable() {
1793 @Override
1794 public void run() {
1795 AppTransitionAnimationSpec[] specs = null;
1796 try {
1797 specs = future.get();
1798 } catch (RemoteException e) {
1799 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1800 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001801 synchronized (mService.mWindowMap) {
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001802 mNextAppTransitionAnimationsSpecsPending = false;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001803 overridePendingAppTransitionMultiThumb(specs,
1804 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1805 mNextAppTransitionScaleUp);
1806 mNextAppTransitionFutureCallback = null;
Filip Gruszczynski96daf322015-11-18 18:01:27 -08001807 if (specs != null) {
1808 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1809 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001810 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001811 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001812 }
1813 });
1814 }
1815 }
1816
Craig Mautner164d4bb2012-11-26 13:51:23 -08001817 @Override
1818 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001819 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001820 }
1821
Craig Mautner4b71aa12012-12-27 17:20:01 -08001822 /**
1823 * Returns the human readable name of a window transition.
1824 *
1825 * @param transition The window transition.
1826 * @return The transition symbolic name.
1827 */
1828 public static String appTransitionToString(int transition) {
1829 switch (transition) {
1830 case TRANSIT_UNSET: {
1831 return "TRANSIT_UNSET";
1832 }
1833 case TRANSIT_NONE: {
1834 return "TRANSIT_NONE";
1835 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001836 case TRANSIT_ACTIVITY_OPEN: {
1837 return "TRANSIT_ACTIVITY_OPEN";
1838 }
1839 case TRANSIT_ACTIVITY_CLOSE: {
1840 return "TRANSIT_ACTIVITY_CLOSE";
1841 }
1842 case TRANSIT_TASK_OPEN: {
1843 return "TRANSIT_TASK_OPEN";
1844 }
1845 case TRANSIT_TASK_CLOSE: {
1846 return "TRANSIT_TASK_CLOSE";
1847 }
1848 case TRANSIT_TASK_TO_FRONT: {
1849 return "TRANSIT_TASK_TO_FRONT";
1850 }
1851 case TRANSIT_TASK_TO_BACK: {
1852 return "TRANSIT_TASK_TO_BACK";
1853 }
1854 case TRANSIT_WALLPAPER_CLOSE: {
1855 return "TRANSIT_WALLPAPER_CLOSE";
1856 }
1857 case TRANSIT_WALLPAPER_OPEN: {
1858 return "TRANSIT_WALLPAPER_OPEN";
1859 }
1860 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1861 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1862 }
1863 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1864 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1865 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001866 case TRANSIT_TASK_OPEN_BEHIND: {
1867 return "TRANSIT_TASK_OPEN_BEHIND";
1868 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001869 case TRANSIT_ACTIVITY_RELAUNCH: {
1870 return "TRANSIT_ACTIVITY_RELAUNCH";
1871 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001872 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1873 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1874 }
Jorim Jaggife762342016-10-13 14:33:27 +02001875 case TRANSIT_KEYGUARD_GOING_AWAY: {
1876 return "TRANSIT_KEYGUARD_GOING_AWAY";
1877 }
1878 case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: {
1879 return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER";
1880 }
1881 case TRANSIT_KEYGUARD_OCCLUDE: {
1882 return "TRANSIT_KEYGUARD_OCCLUDE";
1883 }
1884 case TRANSIT_KEYGUARD_UNOCCLUDE: {
1885 return "TRANSIT_KEYGUARD_UNOCCLUDE";
1886 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001887 default: {
1888 return "<UNKNOWN>";
1889 }
1890 }
1891 }
1892
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001893 private String appStateToString() {
1894 switch (mAppTransitionState) {
1895 case APP_STATE_IDLE:
1896 return "APP_STATE_IDLE";
1897 case APP_STATE_READY:
1898 return "APP_STATE_READY";
1899 case APP_STATE_RUNNING:
1900 return "APP_STATE_RUNNING";
1901 case APP_STATE_TIMEOUT:
1902 return "APP_STATE_TIMEOUT";
1903 default:
1904 return "unknown state=" + mAppTransitionState;
1905 }
1906 }
1907
1908 private String transitTypeToString() {
1909 switch (mNextAppTransitionType) {
1910 case NEXT_TRANSIT_TYPE_NONE:
1911 return "NEXT_TRANSIT_TYPE_NONE";
1912 case NEXT_TRANSIT_TYPE_CUSTOM:
1913 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001914 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1915 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001916 case NEXT_TRANSIT_TYPE_SCALE_UP:
1917 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1918 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1919 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1920 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1921 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001922 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1923 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1924 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1925 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001926 default:
1927 return "unknown type=" + mNextAppTransitionType;
1928 }
1929 }
1930
Craig Mautner164d4bb2012-11-26 13:51:23 -08001931 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001932 public void dump(PrintWriter pw, String prefix) {
1933 pw.print(prefix); pw.println(this);
1934 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001935 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001936 pw.print(prefix); pw.print("mNextAppTransitionType=");
1937 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001938 }
1939 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001940 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001941 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001942 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001943 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001944 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1945 pw.print(" mNextAppTransitionExit=0x");
1946 pw.println(Integer.toHexString(mNextAppTransitionExit));
1947 break;
Winson Chung044d5292014-11-06 11:05:19 -08001948 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001949 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001950 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001951 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001952 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1953 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001954 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001955 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001956 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001957 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001958 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001959 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001960 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001961 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001962 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001963 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001964 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001965 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001966 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1967 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001968 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001969 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1970 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1971 pw.println(mDefaultNextAppTransitionAnimationSpec);
1972 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1973 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001974 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1975 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001976 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001977 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001978 }
1979 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001980 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1981 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001982 }
Chong Zhang60091a92016-07-27 17:52:45 -07001983 if (mLastUsedAppTransition != TRANSIT_NONE) {
1984 pw.print(prefix); pw.print("mLastUsedAppTransition=");
1985 pw.println(appTransitionToString(mLastUsedAppTransition));
1986 pw.print(prefix); pw.print("mLastOpeningApp=");
1987 pw.println(mLastOpeningApp);
1988 pw.print(prefix); pw.print("mLastClosingApp=");
1989 pw.println(mLastClosingApp);
1990 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001991 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001992
1993 public void setCurrentUser(int newUserId) {
1994 mCurrentUserId = newUserId;
1995 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001996
1997 /**
1998 * @return true if transition is not running and should not be skipped, false if transition is
1999 * already running
2000 */
Jorim Jaggife762342016-10-13 14:33:27 +02002001 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent, int flags,
2002 boolean forceOverride) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002003 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
2004 + " transit=" + appTransitionToString(transit)
2005 + " " + this
2006 + " alwaysKeepCurrent=" + alwaysKeepCurrent
2007 + " Callers=" + Debug.getCallers(3));
Jorim Jaggife762342016-10-13 14:33:27 +02002008 if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
2009 || mNextAppTransition == TRANSIT_NONE) {
2010 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002011 } else if (!alwaysKeepCurrent) {
2012 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
2013 // Opening a new task always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002014 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002015 } else if (transit == TRANSIT_ACTIVITY_OPEN
2016 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
2017 // Opening a new activity always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002018 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002019 }
2020 }
2021 boolean prepared = prepare();
2022 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08002023 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
2024 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002025 }
2026 return prepared;
2027 }
Winsonb2024762016-04-05 17:32:30 -07002028
2029 /**
Jorim Jaggife762342016-10-13 14:33:27 +02002030 * @return true if {@param transit} is representing a transition in which Keyguard is going
2031 * away, false otherwise
2032 */
2033 public static boolean isKeyguardGoingAwayTransit(int transit) {
2034 return transit == TRANSIT_KEYGUARD_GOING_AWAY
2035 || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
2036 }
2037
2038 private static boolean isKeyguardTransit(int transit) {
2039 return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE
2040 || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
2041 }
2042
2043 /**
Manu Cornetd7376802017-01-13 13:44:07 -08002044 * @return whether the transition should show the thumbnail being scaled down.
2045 */
2046 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
2047 return isTvUiMode(uiMode)
2048 || mGridLayoutRecentsEnabled
2049 || orientation == Configuration.ORIENTATION_PORTRAIT;
2050 }
2051
2052 /**
Winsonb2024762016-04-05 17:32:30 -07002053 * @return whether the specified {@param uiMode} is the TV mode.
2054 */
2055 private boolean isTvUiMode(int uiMode) {
2056 return (uiMode & Configuration.UI_MODE_TYPE_TELEVISION) > 0;
2057 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002058}