blob: 75a7385c9bf470b9179583e661dc39218953ea34 [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) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100695 Slog.e(TAG, "Starting rect for app requested, but none available", new Throwable());
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700696 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) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100708 Slog.e(TAG, "Starting rect for task: " + taskId + " requested, but not available",
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700709 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;
Manu Cornet57b61492017-01-24 18:19:05 +0900954 float fromY;
Jorim Jaggi09072002016-03-25 16:48:42 -0700955 final float toX;
Manu Cornet57b61492017-01-24 18:19:05 +0900956 float toY;
Jorim Jaggi09072002016-03-25 16:48:42 -0700957 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;
Manu Cornet57b61492017-01-24 18:19:05 +0900969 if (mGridLayoutRecentsEnabled) {
970 // In the grid layout, the header is displayed above the thumbnail instead of
971 // overlapping it.
972 fromY -= thumbHeightI;
973 toY -= thumbHeightI * scaleW;
974 }
Jorim Jaggi09072002016-03-25 16:48:42 -0700975 } else {
976 pivotX = 0;
977 pivotY = 0;
978 fromX = mTmpRect.left;
979 fromY = mTmpRect.top;
980 toX = appRect.left;
981 toY = appRect.top;
982 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100983 final long duration = getAspectScaleDuration();
984 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -0700985 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700986 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +0100987 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100988 scale.setInterpolator(interpolator);
989 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800990 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100991 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
992 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
993 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
994 ? duration / 2
995 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100996 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
997 translate.setInterpolator(interpolator);
998 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -0700999
Jorim Jaggide63d442016-03-14 14:56:56 +01001000 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
1001 mTmpToClipRect.set(appRect);
1002
1003 // Containing frame is in screen space, but we need the clip rect in the
1004 // app space.
1005 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001006 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
1007 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +01001008
1009 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001010 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
1011 (int) (-contentInsets.top * scaleW),
1012 (int) (-contentInsets.right * scaleW),
1013 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +01001014 }
1015
1016 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001017 clipAnim.setInterpolator(interpolator);
1018 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +01001019
Winson Chung399f6202014-03-19 10:47:20 -07001020 // This AnimationSet uses the Interpolators assigned above.
1021 AnimationSet set = new AnimationSet(false);
1022 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001023 if (!mGridLayoutRecentsEnabled) {
1024 // In the grid layout, the header should be shown for the whole animation.
1025 set.addAnimation(alpha);
1026 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001027 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001028 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001029 a = set;
1030 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001031 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001032 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001033 scale.setInterpolator(interpolator);
1034 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001035 Animation alpha = new AlphaAnimation(0f, 1f);
1036 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001037 alpha.setDuration(duration);
1038 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1039 translate.setInterpolator(interpolator);
1040 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001041
Winson Chunga4ccb862014-08-22 15:26:27 -07001042 // This AnimationSet uses the Interpolators assigned above.
1043 AnimationSet set = new AnimationSet(false);
1044 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001045 if (!mGridLayoutRecentsEnabled) {
1046 // In the grid layout, the header should be shown for the whole animation.
1047 set.addAnimation(alpha);
1048 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001049 set.addAnimation(translate);
1050 a = set;
1051
1052 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001053 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001054 null);
Winson Chung399f6202014-03-19 10:47:20 -07001055 }
1056
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001057 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1058
1059 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001060 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001061 return new TranslateAnimation(fromX, toX, fromY, toY);
1062 } else {
1063 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1064 return new CurvedTranslateAnimation(path);
1065 }
1066 }
1067
1068 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1069 final Path path = new Path();
1070 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001071
1072 if (fromY > toY) {
1073 // If the object needs to go up, move it in horizontal direction first, then vertical.
1074 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1075 } else {
1076 // If the object needs to go down, move it in vertical direction first, then horizontal.
1077 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1078 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001079 return path;
1080 }
1081
1082 private long getAspectScaleDuration() {
1083 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001084 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001085 } else {
1086 return THUMBNAIL_APP_TRANSITION_DURATION;
1087 }
1088 }
1089
1090 private Interpolator getAspectScaleInterpolator() {
1091 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1092 return mFastOutSlowInInterpolator;
1093 } else {
1094 return TOUCH_RESPONSE_INTERPOLATOR;
1095 }
1096 }
1097
Winson Chung399f6202014-03-19 10:47:20 -07001098 /**
1099 * This alternate animation is created when we are doing a thumbnail transition, for the
1100 * activity that is leaving, and the activity that is entering.
1101 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001102 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001103 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001104 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001105 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001106 final int appWidth = containingFrame.width();
1107 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001108 getDefaultNextAppTransitionStartRect(mTmpRect);
1109 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001110 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001111 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001112 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001113 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001114 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001115
1116 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001117 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1118 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1119 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1120 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001121 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001122 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001123 } else if (freeform) {
1124 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1125 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001126 } else {
Winson21700932016-03-24 17:26:23 -07001127 AnimationSet set = new AnimationSet(true);
1128
1129 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001130 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001131 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001132
1133 // Containing frame is in screen space, but we need the clip rect in the
1134 // app space.
1135 mTmpFromClipRect.offsetTo(0, 0);
1136 mTmpToClipRect.offsetTo(0, 0);
1137
1138 // Exclude insets region from the source clip.
1139 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001140 mNextAppTransitionInsets.set(contentInsets);
1141
Manu Cornetd7376802017-01-13 13:44:07 -08001142 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001143 // We scale the width and clip to the top/left square
1144 float scale = thumbWidth /
1145 (appWidth - contentInsets.left - contentInsets.right);
Manu Cornetb68b7652017-01-23 19:37:53 +09001146 if (!mGridLayoutRecentsEnabled) {
1147 int unscaledThumbHeight = (int) (thumbHeight / scale);
1148 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1149 }
Jorim Jaggic69bd222016-03-15 14:38:37 +01001150
1151 mNextAppTransitionInsets.set(contentInsets);
1152
Jorim Jaggi8448f332016-03-14 17:50:37 +01001153 Animation scaleAnim = new ScaleAnimation(
1154 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1155 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001156 containingFrame.width() / 2f,
1157 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001158 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001159 final float x = containingFrame.width() / 2f
1160 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001161 final float targetY = (mTmpRect.top - containingFrame.top);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001162 final float y = containingFrame.height() / 2f
1163 - containingFrame.height() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001164 final float startX = targetX - x;
1165 final float startY = targetY - y;
1166 Animation clipAnim = scaleUp
1167 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1168 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1169 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001170 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1171 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1172
Winson21700932016-03-24 17:26:23 -07001173 set.addAnimation(clipAnim);
1174 set.addAnimation(scaleAnim);
1175 set.addAnimation(translateAnim);
1176
1177 } else {
1178 // In landscape, we don't scale at all and only crop
1179 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1180 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1181
Jorim Jaggi8448f332016-03-14 17:50:37 +01001182 Animation clipAnim = scaleUp
1183 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1184 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1185 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001186 ? createCurvedMotion(thumbStartX, 0,
1187 thumbStartY - contentInsets.top, 0)
1188 : createCurvedMotion(0, thumbStartX, 0,
1189 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001190
1191 set.addAnimation(clipAnim);
1192 set.addAnimation(translateAnim);
1193 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001194 a = set;
Winson21700932016-03-24 17:26:23 -07001195 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001196 }
Winson Chung399f6202014-03-19 10:47:20 -07001197 break;
1198 }
1199 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001200 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001201 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001202 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001203 // activity.
1204 a = new AlphaAnimation(1, 0);
1205 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001206 a = new AlphaAnimation(1, 1);
1207 }
1208 break;
1209 }
1210 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001211 // Target app window during the scale down
1212 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1213 // Fade in the destination activity if we are animating from a wallpaper
1214 // activity.
1215 a = new AlphaAnimation(0, 1);
1216 } else {
1217 a = new AlphaAnimation(1, 1);
1218 }
Winson Chung399f6202014-03-19 10:47:20 -07001219 break;
1220 }
Winson Chung399f6202014-03-19 10:47:20 -07001221 default:
1222 throw new RuntimeException("Invalid thumbnail transition state");
1223 }
1224
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001225 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1226 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001227 }
1228
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001229 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1230 @Nullable Rect surfaceInsets, int taskId) {
1231 getNextAppTransitionStartRect(taskId, mTmpRect);
1232 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1233 true);
1234 }
1235
1236 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1237 @Nullable Rect surfaceInsets, int taskId) {
1238 getNextAppTransitionStartRect(taskId, mTmpRect);
1239 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1240 false);
1241 }
1242
1243 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1244 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1245 final float sourceWidth = sourceFrame.width();
1246 final float sourceHeight = sourceFrame.height();
1247 final float destWidth = destFrame.width();
1248 final float destHeight = destFrame.height();
1249 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1250 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001251 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001252 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001253 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001254 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001255 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1256 // We want the scaling to happen from the center of the surface. In order to achieve that,
1257 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001258 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1259 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1260 final ScaleAnimation scale = enter ?
1261 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1262 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1263 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1264 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1265 final int destHCenter = destFrame.left + destFrame.width() / 2;
1266 final int destVCenter = destFrame.top + destFrame.height() / 2;
1267 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1268 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1269 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1270 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001271 set.addAnimation(scale);
1272 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001273
1274 final IRemoteCallback callback = mAnimationFinishedCallback;
1275 if (callback != null) {
1276 set.setAnimationListener(new Animation.AnimationListener() {
1277 @Override
1278 public void onAnimationStart(Animation animation) { }
1279
1280 @Override
1281 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001282 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001283 }
1284
1285 @Override
1286 public void onAnimationRepeat(Animation animation) { }
1287 });
1288 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001289 return set;
1290 }
1291
Winson Chung399f6202014-03-19 10:47:20 -07001292 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001293 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001294 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001295 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001296 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
1297 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001298 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001299 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001300 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001301 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001302 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001303 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1304
1305 if (mNextAppTransitionScaleUp) {
1306 // Animation for the thumbnail zooming from its initial size to the full screen
1307 float scaleW = appWidth / thumbWidth;
1308 float scaleH = appHeight / thumbHeight;
1309 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001310 computePivot(mTmpRect.left, 1 / scaleW),
1311 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001312 scale.setInterpolator(mDecelerateInterpolator);
1313
1314 Animation alpha = new AlphaAnimation(1, 0);
1315 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1316
1317 // This AnimationSet uses the Interpolators assigned above.
1318 AnimationSet set = new AnimationSet(false);
1319 set.addAnimation(scale);
1320 set.addAnimation(alpha);
1321 a = set;
1322 } else {
1323 // Animation for the thumbnail zooming down from the full screen to its final size
1324 float scaleW = appWidth / thumbWidth;
1325 float scaleH = appHeight / thumbHeight;
1326 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001327 computePivot(mTmpRect.left, 1 / scaleW),
1328 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001329 }
1330
1331 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1332 }
1333
1334 /**
Winson Chung399f6202014-03-19 10:47:20 -07001335 * This animation is created when we are doing a thumbnail transition, for the activity that is
1336 * leaving, and the activity that is entering.
1337 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001338 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1339 int transit, int taskId) {
1340 final int appWidth = containingFrame.width();
1341 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001342 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001343 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001344 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001345 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001346 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001347 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001348 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1349
1350 switch (thumbTransitState) {
1351 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1352 // Entering app scales up with the thumbnail
1353 float scaleW = thumbWidth / appWidth;
1354 float scaleH = thumbHeight / appHeight;
1355 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001356 computePivot(mTmpRect.left, scaleW),
1357 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001358 break;
1359 }
1360 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1361 // Exiting app while the thumbnail is scaling up should fade or stay in place
1362 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1363 // Fade out while bringing up selected activity. This keeps the
1364 // current activity from showing through a launching wallpaper
1365 // activity.
1366 a = new AlphaAnimation(1, 0);
1367 } else {
1368 // noop animation
1369 a = new AlphaAnimation(1, 1);
1370 }
1371 break;
1372 }
1373 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1374 // Entering the other app, it should just be visible while we scale the thumbnail
1375 // down above it
1376 a = new AlphaAnimation(1, 1);
1377 break;
1378 }
1379 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1380 // Exiting the current app, the app should scale down with the thumbnail
1381 float scaleW = thumbWidth / appWidth;
1382 float scaleH = thumbHeight / appHeight;
1383 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001384 computePivot(mTmpRect.left, scaleW),
1385 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001386
1387 Animation alpha = new AlphaAnimation(1, 0);
1388
1389 AnimationSet set = new AnimationSet(true);
1390 set.addAnimation(scale);
1391 set.addAnimation(alpha);
1392 set.setZAdjustment(Animation.ZORDER_TOP);
1393 a = set;
1394 break;
1395 }
1396 default:
1397 throw new RuntimeException("Invalid thumbnail transition state");
1398 }
1399
1400 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1401 }
1402
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001403 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001404 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1405 final int left = mTmpFromClipRect.left;
1406 final int top = mTmpFromClipRect.top;
1407 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001408 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1409 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001410 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001411 float fromWidth = mTmpFromClipRect.width();
1412 float toWidth = mTmpToClipRect.width();
1413 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001414 // While the window might span the whole display, the actual content will be cropped to the
1415 // system decoration frame, for example when the window is docked. We need to take into
1416 // account the visible height when constructing the animation.
1417 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1418 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001419 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1420 // The final window is larger in both dimensions than current window (e.g. we are
1421 // maximizing), so we can simply unclip the new window and there will be no disappearing
1422 // frame.
1423 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1424 } else {
1425 // The disappearing window has one larger dimension. We need to apply scaling, so the
1426 // first frame of the entry animation matches the old window.
1427 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001428 // We might not be going exactly full screen, but instead be aligned under the status
1429 // bar using cropping. We still need to account for the cropped part, which will also
1430 // be scaled.
1431 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001432 }
1433
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001434 // We animate the translation from the old position of the removed window, to the new
1435 // position of the added window. The latter might not be full screen, for example docked for
1436 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001437 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001438 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001439 set.addAnimation(translate);
1440 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001441 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001442 return set;
1443 }
1444
Jorim Jaggic554b772015-06-04 16:07:57 -07001445 /**
1446 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1447 * frame of the transition doesn't change the visuals on screen, so we can start
1448 * directly with the second one
1449 */
1450 boolean canSkipFirstFrame() {
1451 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1452 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
Jorim Jaggife762342016-10-13 14:33:27 +02001453 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
1454 && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY;
Jorim Jaggic554b772015-06-04 16:07:57 -07001455 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001456
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001457 /**
1458 *
1459 * @param frame These are the bounds of the window when it finishes the animation. This is where
1460 * the animation must usually finish in entrance animation, as the next frame will
1461 * display the window at these coordinates. In case of exit animation, this is
1462 * where the animation must start, as the frame before the animation is displaying
1463 * the window at these bounds.
1464 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1465 * window might be obscured, usually by the system windows (status bar and
1466 * navigation bar) and we use content insets to convey that information. This
1467 * usually affects the animation aspects vertically, as the system decoration is
1468 * at the top and the bottom. For example when we animate from full screen to
1469 * recents, we want to exclude the covered parts, because they won't match the
1470 * thumbnail after the last frame is executed.
1471 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1472 * know about this to make the animation frames match. We currently use
1473 * this for freeform windows, which have larger surfaces to display
1474 * shadows. When we animate them from recents, we want to match the content
1475 * to the recents thumbnail and hence need to account for the surface being
1476 * bigger.
1477 */
Winsonb2024762016-04-05 17:32:30 -07001478 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001479 int orientation, Rect frame, Rect displayFrame, Rect insets,
1480 @Nullable Rect surfaceInsets, boolean isVoiceInteraction, boolean freeform,
1481 int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001482 Animation a;
Jorim Jaggife762342016-10-13 14:33:27 +02001483 if (isKeyguardGoingAwayTransit(transit) && enter) {
1484 a = loadKeyguardExitAnimation(transit);
1485 } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) {
1486 a = null;
1487 } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) {
1488 a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit);
1489 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001490 || transit == TRANSIT_TASK_OPEN
1491 || transit == TRANSIT_TASK_TO_FRONT)) {
1492 a = loadAnimationRes(lp, enter
1493 ? com.android.internal.R.anim.voice_activity_open_enter
1494 : com.android.internal.R.anim.voice_activity_open_exit);
1495 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1496 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001497 + " anim=" + a + " transit=" + appTransitionToString(transit)
1498 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001499 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1500 || transit == TRANSIT_TASK_CLOSE
1501 || transit == TRANSIT_TASK_TO_BACK)) {
1502 a = loadAnimationRes(lp, enter
1503 ? com.android.internal.R.anim.voice_activity_close_enter
1504 : com.android.internal.R.anim.voice_activity_close_exit);
1505 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1506 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001507 + " anim=" + a + " transit=" + appTransitionToString(transit)
1508 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001509 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001510 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001511 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1512 "applyAnimation:"
1513 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1514 + " transit=" + appTransitionToString(transit)
1515 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001516 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1517 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001518 mNextAppTransitionEnter : mNextAppTransitionExit);
1519 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1520 "applyAnimation:"
1521 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001522 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001523 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001524 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1525 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1526 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1527 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001528 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1529 + " transit=" + appTransitionToString(transit)
1530 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001531 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001532 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001533 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1534 "applyAnimation:"
1535 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001536 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001537 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001538 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001539 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001540 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1541 "applyAnimation:"
1542 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001543 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001544 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001545 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1546 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001547 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001548 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001549 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001550 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001551 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1552 String animName = mNextAppTransitionScaleUp ?
1553 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1554 Slog.v(TAG, "applyAnimation:"
1555 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001556 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001557 + " Callers=" + Debug.getCallers(3));
1558 }
1559 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1560 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1561 mNextAppTransitionScaleUp =
1562 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1563 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001564 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001565 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001566 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1567 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001568 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001569 Slog.v(TAG, "applyAnimation:"
1570 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001571 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001572 + " Callers=" + Debug.getCallers(3));
1573 }
1574 } else {
1575 int animAttr = 0;
1576 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001577 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001578 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001579 ? WindowAnimation_activityOpenEnterAnimation
1580 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001581 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001582 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001583 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001584 ? WindowAnimation_activityCloseEnterAnimation
1585 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001586 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001587 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001588 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001589 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001590 ? WindowAnimation_taskOpenEnterAnimation
1591 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001592 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001593 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001594 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001595 ? WindowAnimation_taskCloseEnterAnimation
1596 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001597 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001598 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001599 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001600 ? WindowAnimation_taskToFrontEnterAnimation
1601 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001602 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001603 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001604 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001605 ? WindowAnimation_taskToBackEnterAnimation
1606 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001607 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001608 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001609 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001610 ? WindowAnimation_wallpaperOpenEnterAnimation
1611 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001612 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001613 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001614 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001615 ? WindowAnimation_wallpaperCloseEnterAnimation
1616 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001617 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001618 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001619 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001620 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1621 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001622 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001623 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001624 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001625 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1626 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001627 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001628 case TRANSIT_TASK_OPEN_BEHIND:
1629 animAttr = enter
1630 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001631 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001632 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001633 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001634 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1635 "applyAnimation:"
1636 + " anim=" + a
1637 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001638 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001639 + " Callers=" + Debug.getCallers(3));
1640 }
1641 return a;
1642 }
1643
Jorim Jaggife762342016-10-13 14:33:27 +02001644 private Animation loadKeyguardExitAnimation(int transit) {
1645 if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) {
1646 return null;
1647 }
1648 final boolean toShade =
1649 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0;
1650 return mService.mPolicy.createHiddenByKeyguardExit(
1651 transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade);
1652 }
1653
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001654 int getAppStackClipMode() {
1655 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001656 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggife762342016-10-13 14:33:27 +02001657 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY
1658 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001659 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001660 ? STACK_CLIP_NONE
1661 : STACK_CLIP_AFTER_ANIM;
1662 }
1663
Jorim Jaggife762342016-10-13 14:33:27 +02001664 public int getTransitFlags() {
1665 return mNextAppTransitionFlags;
1666 }
1667
Craig Mautner164d4bb2012-11-26 13:51:23 -08001668 void postAnimationCallback() {
1669 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001670 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1671 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001672 mNextAppTransitionCallback = null;
1673 }
1674 }
1675
1676 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001677 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001678 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001679 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001680 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001681 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001682 mNextAppTransitionEnter = enterAnim;
1683 mNextAppTransitionExit = exitAnim;
1684 postAnimationCallback();
1685 mNextAppTransitionCallback = startedCallback;
1686 } else {
1687 postAnimationCallback();
1688 }
1689 }
1690
1691 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001692 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001693 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001694 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001695 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001696 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001697 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001698 }
1699 }
1700
Chet Haase10e23ab2015-02-11 15:08:38 -08001701 void overridePendingAppTransitionClipReveal(int startX, int startY,
1702 int startWidth, int startHeight) {
1703 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001704 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001705 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001706 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001707 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001708 }
1709 }
1710
Craig Mautner164d4bb2012-11-26 13:51:23 -08001711 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1712 IRemoteCallback startedCallback, boolean scaleUp) {
1713 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001714 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001715 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1716 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001717 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001718 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001719 postAnimationCallback();
1720 mNextAppTransitionCallback = startedCallback;
1721 } else {
1722 postAnimationCallback();
1723 }
1724 }
1725
Winson Chunga4ccb862014-08-22 15:26:27 -07001726 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001727 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001728 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001729 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001730 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1731 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001732 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001733 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1734 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001735 postAnimationCallback();
1736 mNextAppTransitionCallback = startedCallback;
1737 } else {
1738 postAnimationCallback();
1739 }
1740 }
1741
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001742 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001743 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1744 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001745 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001746 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001747 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1748 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001749 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001750 if (specs != null) {
1751 for (int i = 0; i < specs.length; i++) {
1752 AppTransitionAnimationSpec spec = specs[i];
1753 if (spec != null) {
1754 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1755 if (i == 0) {
1756 // In full screen mode, the transition code depends on the default spec
1757 // to be set.
1758 Rect rect = spec.rect;
1759 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Filip Gruszczynskie3264d82015-11-20 17:10:04 -08001760 rect.width(), rect.height(), spec.bitmap);
Jorim Jaggi43102412015-11-11 16:28:37 +01001761 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001762 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001763 }
1764 }
1765 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001766 mNextAppTransitionCallback = onAnimationStartedCallback;
1767 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001768 } else {
1769 postAnimationCallback();
1770 }
1771 }
1772
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001773 void overridePendingAppTransitionMultiThumbFuture(
1774 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1775 boolean scaleUp) {
1776 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001777 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001778 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1779 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001780 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1781 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001782 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001783 }
1784 }
1785
Winson Chung044d5292014-11-06 11:05:19 -08001786 void overrideInPlaceAppTransition(String packageName, int anim) {
1787 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001788 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001789 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1790 mNextAppTransitionPackage = packageName;
1791 mNextAppTransitionInPlace = anim;
1792 } else {
1793 postAnimationCallback();
1794 }
1795 }
1796
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001797 /**
1798 * If a future is set for the app transition specs, fetch it in another thread.
1799 */
1800 private void fetchAppTransitionSpecsFromFuture() {
1801 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1802 mNextAppTransitionAnimationsSpecsPending = true;
1803 final IAppTransitionAnimationSpecsFuture future
1804 = mNextAppTransitionAnimationsSpecsFuture;
1805 mNextAppTransitionAnimationsSpecsFuture = null;
1806 mDefaultExecutor.execute(new Runnable() {
1807 @Override
1808 public void run() {
1809 AppTransitionAnimationSpec[] specs = null;
1810 try {
1811 specs = future.get();
1812 } catch (RemoteException e) {
1813 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1814 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001815 synchronized (mService.mWindowMap) {
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001816 mNextAppTransitionAnimationsSpecsPending = false;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001817 overridePendingAppTransitionMultiThumb(specs,
1818 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1819 mNextAppTransitionScaleUp);
1820 mNextAppTransitionFutureCallback = null;
Filip Gruszczynski96daf322015-11-18 18:01:27 -08001821 if (specs != null) {
1822 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1823 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001824 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001825 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001826 }
1827 });
1828 }
1829 }
1830
Craig Mautner164d4bb2012-11-26 13:51:23 -08001831 @Override
1832 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001833 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001834 }
1835
Craig Mautner4b71aa12012-12-27 17:20:01 -08001836 /**
1837 * Returns the human readable name of a window transition.
1838 *
1839 * @param transition The window transition.
1840 * @return The transition symbolic name.
1841 */
1842 public static String appTransitionToString(int transition) {
1843 switch (transition) {
1844 case TRANSIT_UNSET: {
1845 return "TRANSIT_UNSET";
1846 }
1847 case TRANSIT_NONE: {
1848 return "TRANSIT_NONE";
1849 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001850 case TRANSIT_ACTIVITY_OPEN: {
1851 return "TRANSIT_ACTIVITY_OPEN";
1852 }
1853 case TRANSIT_ACTIVITY_CLOSE: {
1854 return "TRANSIT_ACTIVITY_CLOSE";
1855 }
1856 case TRANSIT_TASK_OPEN: {
1857 return "TRANSIT_TASK_OPEN";
1858 }
1859 case TRANSIT_TASK_CLOSE: {
1860 return "TRANSIT_TASK_CLOSE";
1861 }
1862 case TRANSIT_TASK_TO_FRONT: {
1863 return "TRANSIT_TASK_TO_FRONT";
1864 }
1865 case TRANSIT_TASK_TO_BACK: {
1866 return "TRANSIT_TASK_TO_BACK";
1867 }
1868 case TRANSIT_WALLPAPER_CLOSE: {
1869 return "TRANSIT_WALLPAPER_CLOSE";
1870 }
1871 case TRANSIT_WALLPAPER_OPEN: {
1872 return "TRANSIT_WALLPAPER_OPEN";
1873 }
1874 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1875 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1876 }
1877 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1878 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1879 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001880 case TRANSIT_TASK_OPEN_BEHIND: {
1881 return "TRANSIT_TASK_OPEN_BEHIND";
1882 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001883 case TRANSIT_ACTIVITY_RELAUNCH: {
1884 return "TRANSIT_ACTIVITY_RELAUNCH";
1885 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001886 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1887 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1888 }
Jorim Jaggife762342016-10-13 14:33:27 +02001889 case TRANSIT_KEYGUARD_GOING_AWAY: {
1890 return "TRANSIT_KEYGUARD_GOING_AWAY";
1891 }
1892 case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: {
1893 return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER";
1894 }
1895 case TRANSIT_KEYGUARD_OCCLUDE: {
1896 return "TRANSIT_KEYGUARD_OCCLUDE";
1897 }
1898 case TRANSIT_KEYGUARD_UNOCCLUDE: {
1899 return "TRANSIT_KEYGUARD_UNOCCLUDE";
1900 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001901 default: {
1902 return "<UNKNOWN>";
1903 }
1904 }
1905 }
1906
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001907 private String appStateToString() {
1908 switch (mAppTransitionState) {
1909 case APP_STATE_IDLE:
1910 return "APP_STATE_IDLE";
1911 case APP_STATE_READY:
1912 return "APP_STATE_READY";
1913 case APP_STATE_RUNNING:
1914 return "APP_STATE_RUNNING";
1915 case APP_STATE_TIMEOUT:
1916 return "APP_STATE_TIMEOUT";
1917 default:
1918 return "unknown state=" + mAppTransitionState;
1919 }
1920 }
1921
1922 private String transitTypeToString() {
1923 switch (mNextAppTransitionType) {
1924 case NEXT_TRANSIT_TYPE_NONE:
1925 return "NEXT_TRANSIT_TYPE_NONE";
1926 case NEXT_TRANSIT_TYPE_CUSTOM:
1927 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001928 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1929 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001930 case NEXT_TRANSIT_TYPE_SCALE_UP:
1931 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1932 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1933 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1934 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1935 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001936 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1937 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1938 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1939 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001940 default:
1941 return "unknown type=" + mNextAppTransitionType;
1942 }
1943 }
1944
Craig Mautner164d4bb2012-11-26 13:51:23 -08001945 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001946 public void dump(PrintWriter pw, String prefix) {
1947 pw.print(prefix); pw.println(this);
1948 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001949 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001950 pw.print(prefix); pw.print("mNextAppTransitionType=");
1951 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001952 }
1953 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001954 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001955 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001956 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001957 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001958 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1959 pw.print(" mNextAppTransitionExit=0x");
1960 pw.println(Integer.toHexString(mNextAppTransitionExit));
1961 break;
Winson Chung044d5292014-11-06 11:05:19 -08001962 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001963 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001964 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001965 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001966 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1967 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001968 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001969 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001970 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001971 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001972 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001973 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001974 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001975 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001976 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001977 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001978 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001979 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001980 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1981 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001982 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001983 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1984 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1985 pw.println(mDefaultNextAppTransitionAnimationSpec);
1986 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1987 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001988 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1989 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001990 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001991 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001992 }
1993 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001994 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1995 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001996 }
Chong Zhang60091a92016-07-27 17:52:45 -07001997 if (mLastUsedAppTransition != TRANSIT_NONE) {
1998 pw.print(prefix); pw.print("mLastUsedAppTransition=");
1999 pw.println(appTransitionToString(mLastUsedAppTransition));
2000 pw.print(prefix); pw.print("mLastOpeningApp=");
2001 pw.println(mLastOpeningApp);
2002 pw.print(prefix); pw.print("mLastClosingApp=");
2003 pw.println(mLastClosingApp);
2004 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002005 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07002006
2007 public void setCurrentUser(int newUserId) {
2008 mCurrentUserId = newUserId;
2009 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002010
2011 /**
2012 * @return true if transition is not running and should not be skipped, false if transition is
2013 * already running
2014 */
Jorim Jaggife762342016-10-13 14:33:27 +02002015 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent, int flags,
2016 boolean forceOverride) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002017 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
2018 + " transit=" + appTransitionToString(transit)
2019 + " " + this
2020 + " alwaysKeepCurrent=" + alwaysKeepCurrent
2021 + " Callers=" + Debug.getCallers(3));
Jorim Jaggife762342016-10-13 14:33:27 +02002022 if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
2023 || mNextAppTransition == TRANSIT_NONE) {
2024 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002025 } else if (!alwaysKeepCurrent) {
2026 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
2027 // Opening a new task always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002028 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002029 } else if (transit == TRANSIT_ACTIVITY_OPEN
2030 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
2031 // Opening a new activity always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002032 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002033 }
2034 }
2035 boolean prepared = prepare();
2036 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08002037 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
2038 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002039 }
2040 return prepared;
2041 }
Winsonb2024762016-04-05 17:32:30 -07002042
2043 /**
Jorim Jaggife762342016-10-13 14:33:27 +02002044 * @return true if {@param transit} is representing a transition in which Keyguard is going
2045 * away, false otherwise
2046 */
2047 public static boolean isKeyguardGoingAwayTransit(int transit) {
2048 return transit == TRANSIT_KEYGUARD_GOING_AWAY
2049 || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
2050 }
2051
2052 private static boolean isKeyguardTransit(int transit) {
2053 return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE
2054 || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
2055 }
2056
2057 /**
Manu Cornetd7376802017-01-13 13:44:07 -08002058 * @return whether the transition should show the thumbnail being scaled down.
2059 */
2060 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
Sid Soundararajan0e88d322017-03-07 15:37:30 -08002061 return mGridLayoutRecentsEnabled
Manu Cornetd7376802017-01-13 13:44:07 -08002062 || orientation == Configuration.ORIENTATION_PORTRAIT;
2063 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002064}