blob: a38addb1dad0b8798578084677faf43f9c18b0b6 [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;
Matthew Ngbf1d9852017-03-14 12:23:09 -070047import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010048import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
49import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
Filip Gruszczynski82861362015-10-16 14:21:09 -070050
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070051import android.annotation.Nullable;
Craig Mautner164d4bb2012-11-26 13:51:23 -080052import android.content.Context;
Winson21700932016-03-24 17:26:23 -070053import android.content.res.Configuration;
Craig Mautner164d4bb2012-11-26 13:51:23 -080054import android.graphics.Bitmap;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010055import android.graphics.Path;
Winson Chung399f6202014-03-19 10:47:20 -070056import android.graphics.Rect;
Jorim Jaggied410b62017-05-05 15:16:14 +020057import android.os.Binder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080058import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010059import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080060import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010061import android.os.RemoteException;
Manu Cornetd7376802017-01-13 13:44:07 -080062import android.os.SystemProperties;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080063import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080064import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070065import android.util.SparseArray;
66import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010067import android.view.IAppTransitionAnimationSpecsFuture;
Craig Mautner164d4bb2012-11-26 13:51:23 -080068import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080069import android.view.animation.AlphaAnimation;
70import android.view.animation.Animation;
71import android.view.animation.AnimationSet;
72import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070073import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080074import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070075import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080076import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070077import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070078
Craig Mautner164d4bb2012-11-26 13:51:23 -080079import com.android.internal.util.DumpUtils.Dump;
80import com.android.server.AttributeCache;
81import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -080082import com.android.server.wm.animation.ClipRectLRAnimation;
83import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010084import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080085
86import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010087import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010088import java.util.concurrent.ExecutorService;
89import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -080090
Craig Mautner164d4bb2012-11-26 13:51:23 -080091// State management of app transitions. When we are preparing for a
92// transition, mNextAppTransition will be the kind of transition to
93// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
94// mOpeningApps and mClosingApps are the lists of tokens that will be
95// made visible or hidden at the next transition.
96public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080097 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070098 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080099
Craig Mautner4b71aa12012-12-27 17:20:01 -0800100 /** Not set up for a transition. */
101 public static final int TRANSIT_UNSET = -1;
102 /** No animation for transition. */
103 public static final int TRANSIT_NONE = 0;
104 /** 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 -0700105 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800106 /** The window in the top-most activity is being closed to reveal the
107 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700108 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800109 /** A window in a new task is being opened on top of an existing one
110 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700111 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800112 /** A window in the top-most activity is being closed to reveal the
113 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700114 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800115 /** A window in an existing task is being displayed on top of an existing one
116 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700117 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800118 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700119 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800120 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
121 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700122 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800123 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
124 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700125 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800126 /** A window in a new activity is being opened on top of an existing one, and both are on top
127 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700128 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800129 /** The window in the top-most activity is being closed to reveal the previous activity, and
130 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700131 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
132 /** A window in a new task is being opened behind an existing one in another activity's task.
133 * The new window will show briefly and then be gone. */
134 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800135 /** A window in a task is being animated in-place. */
136 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700137 /** An activity is being relaunched (e.g. due to configuration change). */
138 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Jorim Jaggi192086e2016-03-11 17:17:03 +0100139 /** A task is being docked from recents. */
140 public static final int TRANSIT_DOCK_TASK_FROM_RECENTS = 19;
Jorim Jaggife762342016-10-13 14:33:27 +0200141 /** Keyguard is going away */
142 public static final int TRANSIT_KEYGUARD_GOING_AWAY = 20;
143 /** Keyguard is going away with showing an activity behind that requests wallpaper */
144 public static final int TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER = 21;
145 /** Keyguard is being occluded */
146 public static final int TRANSIT_KEYGUARD_OCCLUDE = 22;
147 /** Keyguard is being unoccluded */
148 public static final int TRANSIT_KEYGUARD_UNOCCLUDE = 23;
149
150 /** Transition flag: Keyguard is going away, but keeping the notification shade open */
151 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE = 0x1;
152 /** Transition flag: Keyguard is going away, but doesn't want an animation for it */
153 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION = 0x2;
154 /** Transition flag: Keyguard is going away while it was showing the system wallpaper. */
155 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER = 0x4;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800156
Winson Chunga4ccb862014-08-22 15:26:27 -0700157 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700158 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800159 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700160 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800161
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800162 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800163
164 /** Interpolator to be used for animations that respond directly to a touch */
165 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
166 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
167
Jorim Jaggic69bd222016-03-15 14:38:37 +0100168 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
169 new PathInterpolator(0.85f, 0f, 1f, 1f);
170
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800171 /**
172 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
173 * involved, to make it more understandable.
174 */
175 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700176 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700177 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800178
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800179 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800180 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800181
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800182 private int mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200183 private int mNextAppTransitionFlags = 0;
Chong Zhang60091a92016-07-27 17:52:45 -0700184 private int mLastUsedAppTransition = TRANSIT_UNSET;
185 private String mLastOpeningApp;
186 private String mLastClosingApp;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800187
188 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
189 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
190 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
191 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
192 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700193 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
194 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800195 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800196 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800197 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
198
Winson Chung399f6202014-03-19 10:47:20 -0700199 // These are the possible states for the enter/exit activities during a thumbnail transition
200 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
201 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
202 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
203 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
204
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800205 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800206 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800207 private boolean mNextAppTransitionScaleUp;
208 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100209 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700210 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800211 private int mNextAppTransitionEnter;
212 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800213 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700214
215 // Keyed by task id.
216 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
217 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100218 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
219 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700220 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
221
Winson Chunga4ccb862014-08-22 15:26:27 -0700222 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800223
Winson Chung2820c452014-04-15 15:34:44 -0700224 private Rect mTmpFromClipRect = new Rect();
225 private Rect mTmpToClipRect = new Rect();
226
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700227 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700228
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800229 private final static int APP_STATE_IDLE = 0;
230 private final static int APP_STATE_READY = 1;
231 private final static int APP_STATE_RUNNING = 2;
232 private final static int APP_STATE_TIMEOUT = 3;
233 private int mAppTransitionState = APP_STATE_IDLE;
234
235 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800236 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700237 private final Interpolator mThumbnailFadeInInterpolator;
238 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800239 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700240 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100241 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700242 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
243
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700244 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800245
Amith Yamasani4befbec2013-07-10 16:18:01 -0700246 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800247 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700248
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100249 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100250 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100251
Jorim Jaggif97ed922016-02-18 18:57:07 -0800252 private int mLastClipRevealMaxTranslation;
253 private boolean mLastHadClipReveal;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700254 private boolean mProlongedAnimationsEnded;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800255
Manu Cornetd7376802017-01-13 13:44:07 -0800256 private final boolean mGridLayoutRecentsEnabled;
257
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800258 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800259 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800260 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800261 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
262 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700263 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
264 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100265 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
266 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800267 mConfigShortAnimTime = context.getResources().getInteger(
268 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800269 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
270 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700271 mThumbnailFadeInInterpolator = new Interpolator() {
272 @Override
273 public float getInterpolation(float input) {
274 // Linear response for first fraction, then complete after that.
275 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
276 return 0f;
277 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700278 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700279 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700280 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700281 }
282 };
283 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800284 @Override
285 public float getInterpolation(float input) {
286 // Linear response for first fraction, then complete after that.
287 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700288 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
289 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800290 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700291 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800292 }
293 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700294 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
295 * mContext.getResources().getDisplayMetrics().density);
Manu Cornetd7376802017-01-13 13:44:07 -0800296 mGridLayoutRecentsEnabled = SystemProperties.getBoolean("ro.recents.grid", false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800297 }
298
299 boolean isTransitionSet() {
300 return mNextAppTransition != TRANSIT_UNSET;
301 }
302
Craig Mautner164d4bb2012-11-26 13:51:23 -0800303 boolean isTransitionEqual(int transit) {
304 return mNextAppTransition == transit;
305 }
306
307 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800308 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800309 }
310
Jorim Jaggife762342016-10-13 14:33:27 +0200311 private void setAppTransition(int transit, int flags) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800312 mNextAppTransition = transit;
Jorim Jaggife762342016-10-13 14:33:27 +0200313 mNextAppTransitionFlags |= flags;
Chong Zhang60091a92016-07-27 17:52:45 -0700314 setLastAppTransition(TRANSIT_UNSET, null, null);
315 }
316
317 void setLastAppTransition(int transit, AppWindowToken openingApp, AppWindowToken closingApp) {
318 mLastUsedAppTransition = transit;
319 mLastOpeningApp = "" + openingApp;
320 mLastClosingApp = "" + closingApp;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800321 }
322
323 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800324 return mAppTransitionState == APP_STATE_READY
325 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800326 }
327
Craig Mautnerae446592012-12-06 19:05:05 -0800328 void setReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800329 mAppTransitionState = APP_STATE_READY;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100330 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800331 }
332
333 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800334 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800335 }
336
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800337 void setIdle() {
338 mAppTransitionState = APP_STATE_IDLE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800339 }
340
341 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800342 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800343 }
344
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800345 void setTimeout() {
346 mAppTransitionState = APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800347 }
348
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700349 Bitmap getAppTransitionThumbnailHeader(int taskId) {
350 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800351 if (spec == null) {
352 spec = mDefaultNextAppTransitionAnimationSpec;
353 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700354 return spec != null ? spec.bitmap : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800355 }
356
Winson Chunga4ccb862014-08-22 15:26:27 -0700357 /** Returns whether the next thumbnail transition is aspect scaled up. */
358 boolean isNextThumbnailTransitionAspectScaled() {
359 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
360 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
361 }
362
363 /** Returns whether the next thumbnail transition is scaling up. */
364 boolean isNextThumbnailTransitionScaleUp() {
365 return mNextAppTransitionScaleUp;
366 }
367
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800368 boolean isNextAppTransitionThumbnailUp() {
369 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
370 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
371 }
372
373 boolean isNextAppTransitionThumbnailDown() {
374 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
375 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
376 }
377
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100378 /**
379 * @return true if and only if we are currently fetching app transition specs from the future
380 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
381 */
382 boolean isFetchingAppTransitionsSpecs() {
383 return mNextAppTransitionAnimationsSpecsPending;
384 }
385
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700386 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800387 if (!isRunning()) {
388 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100389 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800390 mLastHadClipReveal = false;
391 mLastClipRevealMaxTranslation = 0;
392 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700393 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800394 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700395 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800396 }
397
Jorim Jaggife762342016-10-13 14:33:27 +0200398 /**
399 * @return bit-map of WindowManagerPolicy#FINISH_LAYOUT_REDO_* to indicate whether another
400 * layout pass needs to be done
401 */
402 int goodToGo(int transit, AppWindowAnimator topOpeningAppAnimator,
403 AppWindowAnimator topClosingAppAnimator, ArraySet<AppWindowToken> openingApps,
404 ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800405 mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200406 mNextAppTransitionFlags = 0;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800407 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggife762342016-10-13 14:33:27 +0200408 int redoLayout = notifyAppTransitionStartingLocked(transit,
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800409 topOpeningAppAnimator != null ? topOpeningAppAnimator.mAppToken.token : null,
410 topClosingAppAnimator != null ? topClosingAppAnimator.mAppToken.token : null,
411 topOpeningAppAnimator != null ? topOpeningAppAnimator.animation : null,
412 topClosingAppAnimator != null ? topClosingAppAnimator.animation : null);
413 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Jorim Jaggife762342016-10-13 14:33:27 +0200414 .notifyAppTransitionStarting(openingApps, transit);
Jorim Jaggi363ab982016-04-26 19:51:20 -0700415
416 // Prolong the start for the transition when docking a task from recents, unless recents
417 // ended it already then we don't need to wait.
Jorim Jaggife762342016-10-13 14:33:27 +0200418 if (transit == TRANSIT_DOCK_TASK_FROM_RECENTS && !mProlongedAnimationsEnded) {
Jorim Jaggi363ab982016-04-26 19:51:20 -0700419 for (int i = openingApps.size() - 1; i >= 0; i--) {
420 final AppWindowAnimator appAnimator = openingApps.valueAt(i).mAppAnimator;
421 appAnimator.startProlongAnimation(PROLONG_ANIMATION_AT_START);
422 }
423 }
Jorim Jaggife762342016-10-13 14:33:27 +0200424 return redoLayout;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700425 }
426
427 /**
428 * Let the transitions manager know that the somebody wanted to end the prolonged animations.
429 */
430 void notifyProlongedAnimationsEnded() {
431 mProlongedAnimationsEnded = true;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800432 }
433
434 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800435 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800436 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700437 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi65193992015-11-23 16:49:59 -0800438 mNextAppTransitionAnimationsSpecsFuture = null;
439 mDefaultNextAppTransitionAnimationSpec = null;
440 mAnimationFinishedCallback = null;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700441 mProlongedAnimationsEnded = false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800442 }
443
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800444 void freeze() {
Jorim Jaggife762342016-10-13 14:33:27 +0200445 final int transit = mNextAppTransition;
446 setAppTransition(AppTransition.TRANSIT_UNSET, 0 /* flags */);
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800447 clear();
448 setReady();
Jorim Jaggife762342016-10-13 14:33:27 +0200449 notifyAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100450 }
451
452 void registerListenerLocked(AppTransitionListener listener) {
453 mListeners.add(listener);
454 }
455
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700456 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100457 for (int i = 0; i < mListeners.size(); i++) {
458 mListeners.get(i).onAppTransitionFinishedLocked(token);
459 }
460 }
461
462 private void notifyAppTransitionPendingLocked() {
463 for (int i = 0; i < mListeners.size(); i++) {
464 mListeners.get(i).onAppTransitionPendingLocked();
465 }
466 }
467
Jorim Jaggife762342016-10-13 14:33:27 +0200468 private void notifyAppTransitionCancelledLocked(int transit) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100469 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200470 mListeners.get(i).onAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100471 }
472 }
473
Jorim Jaggife762342016-10-13 14:33:27 +0200474 private int notifyAppTransitionStartingLocked(int transit, IBinder openToken,
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100475 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
Jorim Jaggife762342016-10-13 14:33:27 +0200476 int redoLayout = 0;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100477 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200478 redoLayout |= mListeners.get(i).onAppTransitionStartingLocked(transit, openToken,
479 closeToken, openAnimation, closeAnimation);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100480 }
Jorim Jaggife762342016-10-13 14:33:27 +0200481 return redoLayout;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800482 }
483
Craig Mautner164d4bb2012-11-26 13:51:23 -0800484 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
485 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
486 + (lp != null ? lp.packageName : null)
487 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
488 if (lp != null && lp.windowAnimations != 0) {
489 // If this is a system resource, don't try to load it from the
490 // application resources. It is nice to avoid loading application
491 // resources if we can.
492 String packageName = lp.packageName != null ? lp.packageName : "android";
493 int resId = lp.windowAnimations;
494 if ((resId&0xFF000000) == 0x01000000) {
495 packageName = "android";
496 }
497 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
498 + packageName);
499 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700500 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800501 }
502 return null;
503 }
504
505 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
506 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
507 + packageName + " resId=0x" + Integer.toHexString(resId));
508 if (packageName != null) {
509 if ((resId&0xFF000000) == 0x01000000) {
510 packageName = "android";
511 }
512 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
513 + packageName);
514 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700515 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800516 }
517 return null;
518 }
519
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700520 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800521 int anim = 0;
522 Context context = mContext;
523 if (animAttr >= 0) {
524 AttributeCache.Entry ent = getCachedAnimations(lp);
525 if (ent != null) {
526 context = ent.context;
527 anim = ent.array.getResourceId(animAttr, 0);
528 }
529 }
530 if (anim != 0) {
531 return AnimationUtils.loadAnimation(context, anim);
532 }
533 return null;
534 }
535
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700536 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
537 Context context = mContext;
538 if (resId >= 0) {
539 AttributeCache.Entry ent = getCachedAnimations(lp);
540 if (ent != null) {
541 context = ent.context;
542 }
543 return AnimationUtils.loadAnimation(context, resId);
544 }
545 return null;
546 }
547
548 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800549 int anim = 0;
550 Context context = mContext;
551 if (resId >= 0) {
552 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
553 if (ent != null) {
554 context = ent.context;
555 anim = resId;
556 }
557 }
558 if (anim != 0) {
559 return AnimationUtils.loadAnimation(context, anim);
560 }
561 return null;
562 }
563
Craig Mautner164d4bb2012-11-26 13:51:23 -0800564 /**
565 * Compute the pivot point for an animation that is scaling from a small
566 * rect on screen to a larger rect. The pivot point varies depending on
567 * the distance between the inner and outer edges on both sides. This
568 * function computes the pivot point for one dimension.
569 * @param startPos Offset from left/top edge of outer rectangle to
570 * left/top edge of inner rectangle.
571 * @param finalScale The scaling factor between the size of the outer
572 * and inner rectangles.
573 */
574 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800575
576 /*
577 Theorem of intercepting lines:
578
579 + + +-----------------------------------------------+
580 | | | |
581 | | | |
582 | | | |
583 | | | |
584 x | y | | |
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 |
625 + ++
626 p ++
627
628 scale = (x - y) / x
629 <=> x = -y / (scale - 1)
630 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800631 final float denom = finalScale-1;
632 if (Math.abs(denom) < .0001f) {
633 return startPos;
634 }
635 return -startPos / denom;
636 }
637
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700638 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
639 Rect containingFrame) {
640 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700641 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700642 final int appWidth = containingFrame.width();
643 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800644 if (enter) {
645 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700646 float scaleW = mTmpRect.width() / (float) appWidth;
647 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800648 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700649 computePivot(mTmpRect.left, scaleW),
Winson4c3fecd2016-07-13 12:29:48 -0700650 computePivot(mTmpRect.top, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800651 scale.setInterpolator(mDecelerateInterpolator);
652
Craig Mautner164d4bb2012-11-26 13:51:23 -0800653 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700654 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800655
656 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800657 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800658 set.addAnimation(alpha);
659 set.setDetachWallpaper(true);
660 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800661 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
662 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800663 // If we are on top of the wallpaper, we need an animation that
664 // correctly handles the wallpaper staying static behind all of
665 // the animated elements. To do this, will just have the existing
666 // element fade out.
667 a = new AlphaAnimation(1, 0);
668 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800669 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800670 // For normal animations, the exiting element just holds in place.
671 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800672 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800673
674 // Pick the desired duration. If this is an inter-activity transition,
675 // it is the standard duration for that. Otherwise we use the longer
676 // task transition duration.
677 final long duration;
678 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800679 case TRANSIT_ACTIVITY_OPEN:
680 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800681 duration = mConfigShortAnimTime;
682 break;
683 default:
684 duration = DEFAULT_APP_TRANSITION_DURATION;
685 break;
686 }
687 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800688 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800689 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800690 a.initialize(appWidth, appHeight, appWidth, appHeight);
691 return a;
692 }
693
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700694 private void getDefaultNextAppTransitionStartRect(Rect rect) {
695 if (mDefaultNextAppTransitionAnimationSpec == null ||
696 mDefaultNextAppTransitionAnimationSpec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100697 Slog.e(TAG, "Starting rect for app requested, but none available", new Throwable());
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700698 rect.setEmpty();
699 } else {
700 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
701 }
702 }
703
704 void getNextAppTransitionStartRect(int taskId, Rect rect) {
705 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800706 if (spec == null) {
707 spec = mDefaultNextAppTransitionAnimationSpec;
708 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700709 if (spec == null || spec.rect == null) {
Jorim Jaggi2550f3f2017-03-14 20:15:59 +0100710 Slog.e(TAG, "Starting rect for task: " + taskId + " requested, but not available",
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700711 new Throwable());
712 rect.setEmpty();
713 } else {
714 rect.set(spec.rect);
715 }
716 }
717
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800718 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
719 Bitmap bitmap) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700720 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800721 bitmap, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700722 }
723
Jorim Jaggif97ed922016-02-18 18:57:07 -0800724 /**
725 * @return the duration of the last clip reveal animation
726 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800727 long getLastClipRevealTransitionDuration() {
728 return mLastClipRevealTransitionDuration;
729 }
730
731 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800732 * @return the maximum distance the app surface is traveling of the last clip reveal animation
733 */
734 int getLastClipRevealMaxTranslation() {
735 return mLastClipRevealMaxTranslation;
736 }
737
738 /**
739 * @return true if in the last app transition had a clip reveal animation, false otherwise
740 */
741 boolean hadClipRevealAnimation() {
742 return mLastHadClipReveal;
743 }
744
745 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800746 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
747 * the start rect is outside of the target rect, and there is a lot of movement going on.
748 *
749 * @param cutOff whether the start rect was not fully contained by the end rect
750 * @param translationX the total translation the surface moves in x direction
751 * @param translationY the total translation the surfaces moves in y direction
752 * @param displayFrame our display frame
753 *
754 * @return the duration of the clip reveal animation, in milliseconds
755 */
756 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
757 float translationY, Rect displayFrame) {
758 if (!cutOff) {
759 return DEFAULT_APP_TRANSITION_DURATION;
760 }
761 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
762 Math.abs(translationY) / displayFrame.height());
763 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
764 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
765 }
766
767 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
768 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800769 final Animation anim;
770 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700771 final int appWidth = appFrame.width();
772 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800773
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700774 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700775 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700776 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700777
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700778 float t = 0f;
779 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800780 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700781 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800782 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
783 int translationX = 0;
784 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700785 int centerX = mTmpRect.centerX();
786 int centerY = mTmpRect.centerY();
787 int halfWidth = mTmpRect.width() / 2;
788 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800789 int clipStartX = centerX - halfWidth - appFrame.left;
790 int clipStartY = centerY - halfHeight - appFrame.top;
791 boolean cutOff = false;
792
793 // If the starting rectangle is fully or partially outside of the target rectangle, we
794 // need to start the clipping at the edge and then achieve the rest with translation
795 // and extending the clip rect from that edge.
796 if (appFrame.top > centerY - halfHeight) {
797 translationY = (centerY - halfHeight) - appFrame.top;
798 translationYCorrection = 0;
799 clipStartY = 0;
800 cutOff = true;
801 }
802 if (appFrame.left > centerX - halfWidth) {
803 translationX = (centerX - halfWidth) - appFrame.left;
804 clipStartX = 0;
805 cutOff = true;
806 }
807 if (appFrame.right < centerX + halfWidth) {
808 translationX = (centerX + halfWidth) - appFrame.right;
809 clipStartX = appWidth - mTmpRect.width();
810 cutOff = true;
811 }
812 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
813 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700814
815 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800816 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800817 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700818 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800819 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700820
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800821 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
822 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
823 : mLinearOutSlowInInterpolator);
824 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800825
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800826 Animation clipAnimTB = new ClipRectTBAnimation(
827 clipStartY, clipStartY + mTmpRect.height(),
828 0, appHeight,
829 translationYCorrection, 0,
830 mLinearOutSlowInInterpolator);
831 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
832 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800833
834 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800835 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700836 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800837 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700838 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800839
840 AnimationSet set = new AnimationSet(false);
841 set.addAnimation(clipAnimLR);
842 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700843 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800844 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700845 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800846 set.initialize(appWidth, appHeight, appWidth, appHeight);
847 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800848 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800849 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800850
851 // If the start rect was full inside the target rect (cutOff == false), we don't need
852 // to store the translation, because it's only used if cutOff == true.
853 mLastClipRevealMaxTranslation = cutOff
854 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800855 } else {
856 final long duration;
857 switch (transit) {
858 case TRANSIT_ACTIVITY_OPEN:
859 case TRANSIT_ACTIVITY_CLOSE:
860 duration = mConfigShortAnimTime;
861 break;
862 default:
863 duration = DEFAULT_APP_TRANSITION_DURATION;
864 break;
865 }
866 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
867 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
868 // If we are on top of the wallpaper, we need an animation that
869 // correctly handles the wallpaper staying static behind all of
870 // the animated elements. To do this, will just have the existing
871 // element fade out.
872 anim = new AlphaAnimation(1, 0);
873 anim.setDetachWallpaper(true);
874 } else {
875 // For normal animations, the exiting element just holds in place.
876 anim = new AlphaAnimation(1, 1);
877 }
878 anim.setInterpolator(mDecelerateInterpolator);
879 anim.setDuration(duration);
880 anim.setFillAfter(true);
881 }
882 return anim;
883 }
884
Winson Chung399f6202014-03-19 10:47:20 -0700885 /**
886 * Prepares the specified animation with a standard duration, interpolator, etc.
887 */
Winson Chung5393dff2014-05-08 14:25:43 -0700888 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100889 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700890 if (duration > 0) {
891 a.setDuration(duration);
892 }
Winson Chung5393dff2014-05-08 14:25:43 -0700893 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100894 if (interpolator != null) {
895 a.setInterpolator(interpolator);
896 }
Winson Chung5393dff2014-05-08 14:25:43 -0700897 a.initialize(appWidth, appHeight, appWidth, appHeight);
898 return a;
899 }
900
901 /**
902 * Prepares the specified animation with a standard duration, interpolator, etc.
903 */
Winson Chung399f6202014-03-19 10:47:20 -0700904 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800905 // Pick the desired duration. If this is an inter-activity transition,
906 // it is the standard duration for that. Otherwise we use the longer
907 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700908 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800909 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800910 case TRANSIT_ACTIVITY_OPEN:
911 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800912 duration = mConfigShortAnimTime;
913 break;
914 default:
915 duration = DEFAULT_APP_TRANSITION_DURATION;
916 break;
917 }
Winson Chung5393dff2014-05-08 14:25:43 -0700918 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
919 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800920 }
921
Winson Chung399f6202014-03-19 10:47:20 -0700922 /**
923 * Return the current thumbnail transition state.
924 */
925 int getThumbnailTransitionState(boolean enter) {
926 if (enter) {
927 if (mNextAppTransitionScaleUp) {
928 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
929 } else {
930 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
931 }
932 } else {
933 if (mNextAppTransitionScaleUp) {
934 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
935 } else {
936 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
937 }
938 }
939 }
940
941 /**
942 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700943 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700944 */
Jorim Jaggide63d442016-03-14 14:56:56 +0100945 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winsonb2024762016-04-05 17:32:30 -0700946 Bitmap thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -0700947 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700948 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700949 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700950 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700951 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700952
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700953 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700954 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -0700955 final float fromX;
Manu Cornet57b61492017-01-24 18:19:05 +0900956 float fromY;
Jorim Jaggi09072002016-03-25 16:48:42 -0700957 final float toX;
Manu Cornet57b61492017-01-24 18:19:05 +0900958 float toY;
Jorim Jaggi09072002016-03-25 16:48:42 -0700959 final float pivotX;
960 final float pivotY;
Manu Cornetd7376802017-01-13 13:44:07 -0800961 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggi09072002016-03-25 16:48:42 -0700962 fromX = mTmpRect.left;
963 fromY = mTmpRect.top;
964
965 // For the curved translate animation to work, the pivot points needs to be at the
966 // same absolute position as the one from the real surface.
967 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
968 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
969 pivotX = mTmpRect.width() / 2;
970 pivotY = appRect.height() / 2 / scaleW;
Manu Cornet57b61492017-01-24 18:19:05 +0900971 if (mGridLayoutRecentsEnabled) {
972 // In the grid layout, the header is displayed above the thumbnail instead of
973 // overlapping it.
974 fromY -= thumbHeightI;
975 toY -= thumbHeightI * scaleW;
976 }
Jorim Jaggi09072002016-03-25 16:48:42 -0700977 } else {
978 pivotX = 0;
979 pivotY = 0;
980 fromX = mTmpRect.left;
981 fromY = mTmpRect.top;
982 toX = appRect.left;
983 toY = appRect.top;
984 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100985 final long duration = getAspectScaleDuration();
986 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -0700987 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700988 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +0100989 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100990 scale.setInterpolator(interpolator);
991 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800992 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100993 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
994 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
995 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
996 ? duration / 2
997 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100998 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
999 translate.setInterpolator(interpolator);
1000 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001001
Jorim Jaggide63d442016-03-14 14:56:56 +01001002 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
1003 mTmpToClipRect.set(appRect);
1004
1005 // Containing frame is in screen space, but we need the clip rect in the
1006 // app space.
1007 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001008 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
1009 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +01001010
1011 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001012 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
1013 (int) (-contentInsets.top * scaleW),
1014 (int) (-contentInsets.right * scaleW),
1015 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +01001016 }
1017
1018 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001019 clipAnim.setInterpolator(interpolator);
1020 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +01001021
Winson Chung399f6202014-03-19 10:47:20 -07001022 // This AnimationSet uses the Interpolators assigned above.
1023 AnimationSet set = new AnimationSet(false);
1024 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001025 if (!mGridLayoutRecentsEnabled) {
1026 // In the grid layout, the header should be shown for the whole animation.
1027 set.addAnimation(alpha);
1028 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001029 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001030 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001031 a = set;
1032 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001033 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001034 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001035 scale.setInterpolator(interpolator);
1036 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001037 Animation alpha = new AlphaAnimation(0f, 1f);
1038 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001039 alpha.setDuration(duration);
1040 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1041 translate.setInterpolator(interpolator);
1042 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001043
Winson Chunga4ccb862014-08-22 15:26:27 -07001044 // This AnimationSet uses the Interpolators assigned above.
1045 AnimationSet set = new AnimationSet(false);
1046 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001047 if (!mGridLayoutRecentsEnabled) {
1048 // In the grid layout, the header should be shown for the whole animation.
1049 set.addAnimation(alpha);
1050 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001051 set.addAnimation(translate);
1052 a = set;
1053
1054 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001055 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001056 null);
Winson Chung399f6202014-03-19 10:47:20 -07001057 }
1058
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001059 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1060
1061 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001062 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001063 return new TranslateAnimation(fromX, toX, fromY, toY);
1064 } else {
1065 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1066 return new CurvedTranslateAnimation(path);
1067 }
1068 }
1069
1070 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1071 final Path path = new Path();
1072 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001073
1074 if (fromY > toY) {
1075 // If the object needs to go up, move it in horizontal direction first, then vertical.
1076 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1077 } else {
1078 // If the object needs to go down, move it in vertical direction first, then horizontal.
1079 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1080 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001081 return path;
1082 }
1083
1084 private long getAspectScaleDuration() {
1085 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001086 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001087 } else {
1088 return THUMBNAIL_APP_TRANSITION_DURATION;
1089 }
1090 }
1091
1092 private Interpolator getAspectScaleInterpolator() {
1093 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1094 return mFastOutSlowInInterpolator;
1095 } else {
1096 return TOUCH_RESPONSE_INTERPOLATOR;
1097 }
1098 }
1099
Winson Chung399f6202014-03-19 10:47:20 -07001100 /**
1101 * This alternate animation is created when we are doing a thumbnail transition, for the
1102 * activity that is leaving, and the activity that is entering.
1103 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001104 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001105 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001106 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001107 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001108 final int appWidth = containingFrame.width();
1109 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001110 getDefaultNextAppTransitionStartRect(mTmpRect);
1111 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001112 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001113 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001114 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001115 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001116 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001117
1118 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001119 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1120 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1121 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1122 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001123 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001124 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001125 } else if (freeform) {
1126 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1127 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001128 } else {
Winson21700932016-03-24 17:26:23 -07001129 AnimationSet set = new AnimationSet(true);
1130
1131 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001132 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001133 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001134
1135 // Containing frame is in screen space, but we need the clip rect in the
1136 // app space.
1137 mTmpFromClipRect.offsetTo(0, 0);
1138 mTmpToClipRect.offsetTo(0, 0);
1139
1140 // Exclude insets region from the source clip.
1141 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001142 mNextAppTransitionInsets.set(contentInsets);
1143
Manu Cornetd7376802017-01-13 13:44:07 -08001144 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001145 // We scale the width and clip to the top/left square
1146 float scale = thumbWidth /
1147 (appWidth - contentInsets.left - contentInsets.right);
Manu Cornetb68b7652017-01-23 19:37:53 +09001148 if (!mGridLayoutRecentsEnabled) {
1149 int unscaledThumbHeight = (int) (thumbHeight / scale);
1150 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1151 }
Jorim Jaggic69bd222016-03-15 14:38:37 +01001152
1153 mNextAppTransitionInsets.set(contentInsets);
1154
Jorim Jaggi8448f332016-03-14 17:50:37 +01001155 Animation scaleAnim = new ScaleAnimation(
1156 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1157 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001158 containingFrame.width() / 2f,
1159 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001160 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001161 final float x = containingFrame.width() / 2f
1162 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001163 final float targetY = (mTmpRect.top - containingFrame.top);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001164 final float y = containingFrame.height() / 2f
1165 - containingFrame.height() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001166 final float startX = targetX - x;
1167 final float startY = targetY - y;
1168 Animation clipAnim = scaleUp
1169 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1170 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1171 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001172 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1173 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1174
Winson21700932016-03-24 17:26:23 -07001175 set.addAnimation(clipAnim);
1176 set.addAnimation(scaleAnim);
1177 set.addAnimation(translateAnim);
1178
1179 } else {
1180 // In landscape, we don't scale at all and only crop
1181 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1182 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1183
Jorim Jaggi8448f332016-03-14 17:50:37 +01001184 Animation clipAnim = scaleUp
1185 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1186 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1187 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001188 ? createCurvedMotion(thumbStartX, 0,
1189 thumbStartY - contentInsets.top, 0)
1190 : createCurvedMotion(0, thumbStartX, 0,
1191 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001192
1193 set.addAnimation(clipAnim);
1194 set.addAnimation(translateAnim);
1195 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001196 a = set;
Winson21700932016-03-24 17:26:23 -07001197 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001198 }
Winson Chung399f6202014-03-19 10:47:20 -07001199 break;
1200 }
1201 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001202 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001203 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001204 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001205 // activity.
1206 a = new AlphaAnimation(1, 0);
1207 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001208 a = new AlphaAnimation(1, 1);
1209 }
1210 break;
1211 }
1212 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001213 // Target app window during the scale down
1214 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1215 // Fade in the destination activity if we are animating from a wallpaper
1216 // activity.
1217 a = new AlphaAnimation(0, 1);
1218 } else {
1219 a = new AlphaAnimation(1, 1);
1220 }
Winson Chung399f6202014-03-19 10:47:20 -07001221 break;
1222 }
Winson Chung399f6202014-03-19 10:47:20 -07001223 default:
1224 throw new RuntimeException("Invalid thumbnail transition state");
1225 }
1226
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001227 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1228 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001229 }
1230
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001231 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1232 @Nullable Rect surfaceInsets, int taskId) {
1233 getNextAppTransitionStartRect(taskId, mTmpRect);
1234 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1235 true);
1236 }
1237
1238 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1239 @Nullable Rect surfaceInsets, int taskId) {
1240 getNextAppTransitionStartRect(taskId, mTmpRect);
1241 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1242 false);
1243 }
1244
1245 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1246 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1247 final float sourceWidth = sourceFrame.width();
1248 final float sourceHeight = sourceFrame.height();
1249 final float destWidth = destFrame.width();
1250 final float destHeight = destFrame.height();
1251 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1252 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001253 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001254 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001255 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001256 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001257 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1258 // We want the scaling to happen from the center of the surface. In order to achieve that,
1259 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001260 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1261 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1262 final ScaleAnimation scale = enter ?
1263 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1264 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1265 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1266 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1267 final int destHCenter = destFrame.left + destFrame.width() / 2;
1268 final int destVCenter = destFrame.top + destFrame.height() / 2;
1269 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1270 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1271 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1272 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001273 set.addAnimation(scale);
1274 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001275
1276 final IRemoteCallback callback = mAnimationFinishedCallback;
1277 if (callback != null) {
1278 set.setAnimationListener(new Animation.AnimationListener() {
1279 @Override
1280 public void onAnimationStart(Animation animation) { }
1281
1282 @Override
1283 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001284 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001285 }
1286
1287 @Override
1288 public void onAnimationRepeat(Animation animation) { }
1289 });
1290 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001291 return set;
1292 }
1293
Winson Chung399f6202014-03-19 10:47:20 -07001294 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001295 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001296 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001297 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001298 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
1299 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001300 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001301 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001302 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001303 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001304 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001305 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1306
1307 if (mNextAppTransitionScaleUp) {
1308 // Animation for the thumbnail zooming from its initial size to the full screen
1309 float scaleW = appWidth / thumbWidth;
1310 float scaleH = appHeight / thumbHeight;
1311 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001312 computePivot(mTmpRect.left, 1 / scaleW),
1313 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001314 scale.setInterpolator(mDecelerateInterpolator);
1315
1316 Animation alpha = new AlphaAnimation(1, 0);
1317 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1318
1319 // This AnimationSet uses the Interpolators assigned above.
1320 AnimationSet set = new AnimationSet(false);
1321 set.addAnimation(scale);
1322 set.addAnimation(alpha);
1323 a = set;
1324 } else {
1325 // Animation for the thumbnail zooming down from the full screen to its final size
1326 float scaleW = appWidth / thumbWidth;
1327 float scaleH = appHeight / thumbHeight;
1328 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001329 computePivot(mTmpRect.left, 1 / scaleW),
1330 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001331 }
1332
1333 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1334 }
1335
1336 /**
Winson Chung399f6202014-03-19 10:47:20 -07001337 * This animation is created when we are doing a thumbnail transition, for the activity that is
1338 * leaving, and the activity that is entering.
1339 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001340 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1341 int transit, int taskId) {
1342 final int appWidth = containingFrame.width();
1343 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001344 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001345 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001346 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001347 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001348 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001349 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001350 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1351
1352 switch (thumbTransitState) {
1353 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1354 // Entering app scales up with the thumbnail
1355 float scaleW = thumbWidth / appWidth;
1356 float scaleH = thumbHeight / appHeight;
1357 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001358 computePivot(mTmpRect.left, scaleW),
1359 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001360 break;
1361 }
1362 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1363 // Exiting app while the thumbnail is scaling up should fade or stay in place
1364 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1365 // Fade out while bringing up selected activity. This keeps the
1366 // current activity from showing through a launching wallpaper
1367 // activity.
1368 a = new AlphaAnimation(1, 0);
1369 } else {
1370 // noop animation
1371 a = new AlphaAnimation(1, 1);
1372 }
1373 break;
1374 }
1375 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1376 // Entering the other app, it should just be visible while we scale the thumbnail
1377 // down above it
1378 a = new AlphaAnimation(1, 1);
1379 break;
1380 }
1381 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1382 // Exiting the current app, the app should scale down with the thumbnail
1383 float scaleW = thumbWidth / appWidth;
1384 float scaleH = thumbHeight / appHeight;
1385 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001386 computePivot(mTmpRect.left, scaleW),
1387 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001388
1389 Animation alpha = new AlphaAnimation(1, 0);
1390
1391 AnimationSet set = new AnimationSet(true);
1392 set.addAnimation(scale);
1393 set.addAnimation(alpha);
1394 set.setZAdjustment(Animation.ZORDER_TOP);
1395 a = set;
1396 break;
1397 }
1398 default:
1399 throw new RuntimeException("Invalid thumbnail transition state");
1400 }
1401
1402 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1403 }
1404
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001405 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001406 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1407 final int left = mTmpFromClipRect.left;
1408 final int top = mTmpFromClipRect.top;
1409 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001410 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1411 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001412 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001413 float fromWidth = mTmpFromClipRect.width();
1414 float toWidth = mTmpToClipRect.width();
1415 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001416 // While the window might span the whole display, the actual content will be cropped to the
1417 // system decoration frame, for example when the window is docked. We need to take into
1418 // account the visible height when constructing the animation.
1419 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1420 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001421 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1422 // The final window is larger in both dimensions than current window (e.g. we are
1423 // maximizing), so we can simply unclip the new window and there will be no disappearing
1424 // frame.
1425 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1426 } else {
1427 // The disappearing window has one larger dimension. We need to apply scaling, so the
1428 // first frame of the entry animation matches the old window.
1429 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001430 // We might not be going exactly full screen, but instead be aligned under the status
1431 // bar using cropping. We still need to account for the cropped part, which will also
1432 // be scaled.
1433 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001434 }
1435
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001436 // We animate the translation from the old position of the removed window, to the new
1437 // position of the added window. The latter might not be full screen, for example docked for
1438 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001439 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001440 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001441 set.addAnimation(translate);
1442 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001443 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001444 return set;
1445 }
1446
Jorim Jaggic554b772015-06-04 16:07:57 -07001447 /**
1448 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1449 * frame of the transition doesn't change the visuals on screen, so we can start
1450 * directly with the second one
1451 */
1452 boolean canSkipFirstFrame() {
1453 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1454 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
Jorim Jaggife762342016-10-13 14:33:27 +02001455 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
1456 && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY;
Jorim Jaggic554b772015-06-04 16:07:57 -07001457 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001458
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001459 /**
1460 *
1461 * @param frame These are the bounds of the window when it finishes the animation. This is where
1462 * the animation must usually finish in entrance animation, as the next frame will
1463 * display the window at these coordinates. In case of exit animation, this is
1464 * where the animation must start, as the frame before the animation is displaying
1465 * the window at these bounds.
1466 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1467 * window might be obscured, usually by the system windows (status bar and
1468 * navigation bar) and we use content insets to convey that information. This
1469 * usually affects the animation aspects vertically, as the system decoration is
1470 * at the top and the bottom. For example when we animate from full screen to
1471 * recents, we want to exclude the covered parts, because they won't match the
1472 * thumbnail after the last frame is executed.
1473 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1474 * know about this to make the animation frames match. We currently use
1475 * this for freeform windows, which have larger surfaces to display
1476 * shadows. When we animate them from recents, we want to match the content
1477 * to the recents thumbnail and hence need to account for the surface being
1478 * bigger.
1479 */
Winsonb2024762016-04-05 17:32:30 -07001480 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001481 int orientation, Rect frame, Rect displayFrame, Rect insets,
1482 @Nullable Rect surfaceInsets, boolean isVoiceInteraction, boolean freeform,
1483 int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001484 Animation a;
Jorim Jaggife762342016-10-13 14:33:27 +02001485 if (isKeyguardGoingAwayTransit(transit) && enter) {
1486 a = loadKeyguardExitAnimation(transit);
1487 } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) {
1488 a = null;
1489 } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) {
1490 a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit);
1491 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001492 || transit == TRANSIT_TASK_OPEN
1493 || transit == TRANSIT_TASK_TO_FRONT)) {
1494 a = loadAnimationRes(lp, enter
1495 ? com.android.internal.R.anim.voice_activity_open_enter
1496 : com.android.internal.R.anim.voice_activity_open_exit);
1497 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1498 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001499 + " anim=" + a + " transit=" + appTransitionToString(transit)
1500 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001501 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1502 || transit == TRANSIT_TASK_CLOSE
1503 || transit == TRANSIT_TASK_TO_BACK)) {
1504 a = loadAnimationRes(lp, enter
1505 ? com.android.internal.R.anim.voice_activity_close_enter
1506 : com.android.internal.R.anim.voice_activity_close_exit);
1507 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1508 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001509 + " anim=" + a + " transit=" + appTransitionToString(transit)
1510 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001511 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001512 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001513 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1514 "applyAnimation:"
1515 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1516 + " transit=" + appTransitionToString(transit)
1517 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001518 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1519 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001520 mNextAppTransitionEnter : mNextAppTransitionExit);
1521 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1522 "applyAnimation:"
1523 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001524 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001525 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001526 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1527 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1528 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1529 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001530 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1531 + " transit=" + appTransitionToString(transit)
1532 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001533 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001534 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001535 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1536 "applyAnimation:"
1537 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001538 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001539 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001540 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001541 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001542 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1543 "applyAnimation:"
1544 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001545 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001546 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001547 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1548 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001549 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001550 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001551 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001552 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001553 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1554 String animName = mNextAppTransitionScaleUp ?
1555 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1556 Slog.v(TAG, "applyAnimation:"
1557 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001558 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001559 + " Callers=" + Debug.getCallers(3));
1560 }
1561 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1562 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1563 mNextAppTransitionScaleUp =
1564 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1565 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001566 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001567 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001568 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1569 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001570 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001571 Slog.v(TAG, "applyAnimation:"
1572 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001573 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001574 + " Callers=" + Debug.getCallers(3));
1575 }
1576 } else {
1577 int animAttr = 0;
1578 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001579 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001580 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001581 ? WindowAnimation_activityOpenEnterAnimation
1582 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001583 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001584 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001585 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001586 ? WindowAnimation_activityCloseEnterAnimation
1587 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001588 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001589 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001590 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001591 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001592 ? WindowAnimation_taskOpenEnterAnimation
1593 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001594 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001595 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001596 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001597 ? WindowAnimation_taskCloseEnterAnimation
1598 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001599 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001600 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001601 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001602 ? WindowAnimation_taskToFrontEnterAnimation
1603 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001604 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001605 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001606 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001607 ? WindowAnimation_taskToBackEnterAnimation
1608 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001609 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001610 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001611 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001612 ? WindowAnimation_wallpaperOpenEnterAnimation
1613 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001614 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001615 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001616 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001617 ? WindowAnimation_wallpaperCloseEnterAnimation
1618 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001619 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001620 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001621 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001622 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1623 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001624 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001625 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001626 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001627 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1628 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001629 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001630 case TRANSIT_TASK_OPEN_BEHIND:
1631 animAttr = enter
1632 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001633 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001634 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001635 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001636 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1637 "applyAnimation:"
1638 + " anim=" + a
1639 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001640 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001641 + " Callers=" + Debug.getCallers(3));
1642 }
1643 return a;
1644 }
1645
Jorim Jaggife762342016-10-13 14:33:27 +02001646 private Animation loadKeyguardExitAnimation(int transit) {
1647 if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) {
1648 return null;
1649 }
1650 final boolean toShade =
1651 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0;
1652 return mService.mPolicy.createHiddenByKeyguardExit(
1653 transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade);
1654 }
1655
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001656 int getAppStackClipMode() {
Matthew Ngbf1d9852017-03-14 12:23:09 -07001657 // When dismiss keyguard animation occurs, clip before the animation to prevent docked
1658 // app from showing beyond the divider
1659 if (mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY
1660 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER) {
1661 return STACK_CLIP_BEFORE_ANIM;
1662 }
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001663 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001664 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001665 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001666 ? STACK_CLIP_NONE
1667 : STACK_CLIP_AFTER_ANIM;
1668 }
1669
Jorim Jaggife762342016-10-13 14:33:27 +02001670 public int getTransitFlags() {
1671 return mNextAppTransitionFlags;
1672 }
1673
Craig Mautner164d4bb2012-11-26 13:51:23 -08001674 void postAnimationCallback() {
1675 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001676 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1677 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001678 mNextAppTransitionCallback = null;
1679 }
1680 }
1681
1682 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001683 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001684 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001685 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001686 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001687 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001688 mNextAppTransitionEnter = enterAnim;
1689 mNextAppTransitionExit = exitAnim;
1690 postAnimationCallback();
1691 mNextAppTransitionCallback = startedCallback;
1692 } else {
1693 postAnimationCallback();
1694 }
1695 }
1696
1697 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001698 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001699 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001700 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001701 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001702 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001703 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001704 }
1705 }
1706
Chet Haase10e23ab2015-02-11 15:08:38 -08001707 void overridePendingAppTransitionClipReveal(int startX, int startY,
1708 int startWidth, int startHeight) {
1709 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001710 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001711 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001712 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001713 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001714 }
1715 }
1716
Craig Mautner164d4bb2012-11-26 13:51:23 -08001717 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1718 IRemoteCallback startedCallback, boolean scaleUp) {
1719 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001720 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001721 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1722 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001723 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001724 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001725 postAnimationCallback();
1726 mNextAppTransitionCallback = startedCallback;
1727 } else {
1728 postAnimationCallback();
1729 }
1730 }
1731
Winson Chunga4ccb862014-08-22 15:26:27 -07001732 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001733 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001734 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001735 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001736 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1737 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001738 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001739 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1740 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001741 postAnimationCallback();
1742 mNextAppTransitionCallback = startedCallback;
1743 } else {
1744 postAnimationCallback();
1745 }
1746 }
1747
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001748 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001749 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1750 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001751 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001752 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001753 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1754 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001755 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001756 if (specs != null) {
1757 for (int i = 0; i < specs.length; i++) {
1758 AppTransitionAnimationSpec spec = specs[i];
1759 if (spec != null) {
1760 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1761 if (i == 0) {
1762 // In full screen mode, the transition code depends on the default spec
1763 // to be set.
1764 Rect rect = spec.rect;
1765 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Filip Gruszczynskie3264d82015-11-20 17:10:04 -08001766 rect.width(), rect.height(), spec.bitmap);
Jorim Jaggi43102412015-11-11 16:28:37 +01001767 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001768 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001769 }
1770 }
1771 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001772 mNextAppTransitionCallback = onAnimationStartedCallback;
1773 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001774 } else {
1775 postAnimationCallback();
1776 }
1777 }
1778
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001779 void overridePendingAppTransitionMultiThumbFuture(
1780 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1781 boolean scaleUp) {
1782 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001783 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001784 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1785 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001786 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1787 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001788 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001789 }
1790 }
1791
Winson Chung044d5292014-11-06 11:05:19 -08001792 void overrideInPlaceAppTransition(String packageName, int anim) {
1793 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001794 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001795 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1796 mNextAppTransitionPackage = packageName;
1797 mNextAppTransitionInPlace = anim;
1798 } else {
1799 postAnimationCallback();
1800 }
1801 }
1802
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001803 /**
1804 * If a future is set for the app transition specs, fetch it in another thread.
1805 */
1806 private void fetchAppTransitionSpecsFromFuture() {
1807 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1808 mNextAppTransitionAnimationsSpecsPending = true;
1809 final IAppTransitionAnimationSpecsFuture future
1810 = mNextAppTransitionAnimationsSpecsFuture;
1811 mNextAppTransitionAnimationsSpecsFuture = null;
Jorim Jaggied410b62017-05-05 15:16:14 +02001812 mDefaultExecutor.execute(() -> {
1813 AppTransitionAnimationSpec[] specs = null;
1814 try {
1815 Binder.allowBlocking(future.asBinder());
1816 specs = future.get();
1817 } catch (RemoteException e) {
1818 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001819 }
Jorim Jaggied410b62017-05-05 15:16:14 +02001820 synchronized (mService.mWindowMap) {
1821 mNextAppTransitionAnimationsSpecsPending = false;
1822 overridePendingAppTransitionMultiThumb(specs,
1823 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1824 mNextAppTransitionScaleUp);
1825 mNextAppTransitionFutureCallback = null;
1826 if (specs != null) {
1827 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1828 }
1829 }
1830 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001831 });
1832 }
1833 }
1834
Craig Mautner164d4bb2012-11-26 13:51:23 -08001835 @Override
1836 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001837 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001838 }
1839
Craig Mautner4b71aa12012-12-27 17:20:01 -08001840 /**
1841 * Returns the human readable name of a window transition.
1842 *
1843 * @param transition The window transition.
1844 * @return The transition symbolic name.
1845 */
1846 public static String appTransitionToString(int transition) {
1847 switch (transition) {
1848 case TRANSIT_UNSET: {
1849 return "TRANSIT_UNSET";
1850 }
1851 case TRANSIT_NONE: {
1852 return "TRANSIT_NONE";
1853 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001854 case TRANSIT_ACTIVITY_OPEN: {
1855 return "TRANSIT_ACTIVITY_OPEN";
1856 }
1857 case TRANSIT_ACTIVITY_CLOSE: {
1858 return "TRANSIT_ACTIVITY_CLOSE";
1859 }
1860 case TRANSIT_TASK_OPEN: {
1861 return "TRANSIT_TASK_OPEN";
1862 }
1863 case TRANSIT_TASK_CLOSE: {
1864 return "TRANSIT_TASK_CLOSE";
1865 }
1866 case TRANSIT_TASK_TO_FRONT: {
1867 return "TRANSIT_TASK_TO_FRONT";
1868 }
1869 case TRANSIT_TASK_TO_BACK: {
1870 return "TRANSIT_TASK_TO_BACK";
1871 }
1872 case TRANSIT_WALLPAPER_CLOSE: {
1873 return "TRANSIT_WALLPAPER_CLOSE";
1874 }
1875 case TRANSIT_WALLPAPER_OPEN: {
1876 return "TRANSIT_WALLPAPER_OPEN";
1877 }
1878 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1879 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1880 }
1881 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1882 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1883 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001884 case TRANSIT_TASK_OPEN_BEHIND: {
1885 return "TRANSIT_TASK_OPEN_BEHIND";
1886 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001887 case TRANSIT_ACTIVITY_RELAUNCH: {
1888 return "TRANSIT_ACTIVITY_RELAUNCH";
1889 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001890 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1891 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1892 }
Jorim Jaggife762342016-10-13 14:33:27 +02001893 case TRANSIT_KEYGUARD_GOING_AWAY: {
1894 return "TRANSIT_KEYGUARD_GOING_AWAY";
1895 }
1896 case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: {
1897 return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER";
1898 }
1899 case TRANSIT_KEYGUARD_OCCLUDE: {
1900 return "TRANSIT_KEYGUARD_OCCLUDE";
1901 }
1902 case TRANSIT_KEYGUARD_UNOCCLUDE: {
1903 return "TRANSIT_KEYGUARD_UNOCCLUDE";
1904 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001905 default: {
1906 return "<UNKNOWN>";
1907 }
1908 }
1909 }
1910
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001911 private String appStateToString() {
1912 switch (mAppTransitionState) {
1913 case APP_STATE_IDLE:
1914 return "APP_STATE_IDLE";
1915 case APP_STATE_READY:
1916 return "APP_STATE_READY";
1917 case APP_STATE_RUNNING:
1918 return "APP_STATE_RUNNING";
1919 case APP_STATE_TIMEOUT:
1920 return "APP_STATE_TIMEOUT";
1921 default:
1922 return "unknown state=" + mAppTransitionState;
1923 }
1924 }
1925
1926 private String transitTypeToString() {
1927 switch (mNextAppTransitionType) {
1928 case NEXT_TRANSIT_TYPE_NONE:
1929 return "NEXT_TRANSIT_TYPE_NONE";
1930 case NEXT_TRANSIT_TYPE_CUSTOM:
1931 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001932 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1933 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001934 case NEXT_TRANSIT_TYPE_SCALE_UP:
1935 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1936 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1937 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1938 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1939 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001940 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1941 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1942 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1943 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001944 default:
1945 return "unknown type=" + mNextAppTransitionType;
1946 }
1947 }
1948
Craig Mautner164d4bb2012-11-26 13:51:23 -08001949 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001950 public void dump(PrintWriter pw, String prefix) {
1951 pw.print(prefix); pw.println(this);
1952 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001953 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001954 pw.print(prefix); pw.print("mNextAppTransitionType=");
1955 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001956 }
1957 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001958 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001959 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001960 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001961 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001962 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1963 pw.print(" mNextAppTransitionExit=0x");
1964 pw.println(Integer.toHexString(mNextAppTransitionExit));
1965 break;
Winson Chung044d5292014-11-06 11:05:19 -08001966 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001967 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001968 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001969 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001970 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1971 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001972 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001973 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001974 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001975 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001976 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001977 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001978 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001979 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001980 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001981 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001982 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001983 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001984 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1985 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001986 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001987 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1988 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1989 pw.println(mDefaultNextAppTransitionAnimationSpec);
1990 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1991 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001992 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1993 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001994 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001995 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001996 }
1997 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001998 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1999 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08002000 }
Chong Zhang60091a92016-07-27 17:52:45 -07002001 if (mLastUsedAppTransition != TRANSIT_NONE) {
2002 pw.print(prefix); pw.print("mLastUsedAppTransition=");
2003 pw.println(appTransitionToString(mLastUsedAppTransition));
2004 pw.print(prefix); pw.print("mLastOpeningApp=");
2005 pw.println(mLastOpeningApp);
2006 pw.print(prefix); pw.print("mLastClosingApp=");
2007 pw.println(mLastClosingApp);
2008 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002009 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07002010
2011 public void setCurrentUser(int newUserId) {
2012 mCurrentUserId = newUserId;
2013 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002014
2015 /**
2016 * @return true if transition is not running and should not be skipped, false if transition is
2017 * already running
2018 */
Jorim Jaggife762342016-10-13 14:33:27 +02002019 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent, int flags,
2020 boolean forceOverride) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002021 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
2022 + " transit=" + appTransitionToString(transit)
2023 + " " + this
2024 + " alwaysKeepCurrent=" + alwaysKeepCurrent
2025 + " Callers=" + Debug.getCallers(3));
Jorim Jaggife762342016-10-13 14:33:27 +02002026 if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
2027 || mNextAppTransition == TRANSIT_NONE) {
2028 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002029 } else if (!alwaysKeepCurrent) {
2030 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
2031 // Opening a new task 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 } else if (transit == TRANSIT_ACTIVITY_OPEN
2034 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
2035 // Opening a new activity always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002036 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002037 }
2038 }
2039 boolean prepared = prepare();
2040 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08002041 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
2042 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002043 }
2044 return prepared;
2045 }
Winsonb2024762016-04-05 17:32:30 -07002046
2047 /**
Jorim Jaggife762342016-10-13 14:33:27 +02002048 * @return true if {@param transit} is representing a transition in which Keyguard is going
2049 * away, false otherwise
2050 */
2051 public static boolean isKeyguardGoingAwayTransit(int transit) {
2052 return transit == TRANSIT_KEYGUARD_GOING_AWAY
2053 || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
2054 }
2055
2056 private static boolean isKeyguardTransit(int transit) {
2057 return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE
2058 || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
2059 }
2060
2061 /**
Manu Cornetd7376802017-01-13 13:44:07 -08002062 * @return whether the transition should show the thumbnail being scaled down.
2063 */
2064 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
Sid Soundararajan0e88d322017-03-07 15:37:30 -08002065 return mGridLayoutRecentsEnabled
Manu Cornetd7376802017-01-13 13:44:07 -08002066 || orientation == Configuration.ORIENTATION_PORTRAIT;
2067 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002068}