blob: 24f9eb705a3b2e8d7bc760c4b4f974aae9d096be [file] [log] [blame]
Craig Mautner164d4bb2012-11-26 13:51:23 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Filip Gruszczynski82861362015-10-16 14:21:09 -070019import static android.view.WindowManagerInternal.AppTransitionListener;
20import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
21import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
22import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
23import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
24import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
25import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
26import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
27import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
28import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
29import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
30import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
31import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
32import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
33import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
34import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
35import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
36import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
37import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
38import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
39import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
40import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
41import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Jorim Jaggi363ab982016-04-26 19:51:20 -070042import static com.android.server.wm.AppWindowAnimator.PROLONG_ANIMATION_AT_START;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080043import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
44import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080045import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
46import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010047import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
48import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
Filip Gruszczynski82861362015-10-16 14:21:09 -070049
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070050import android.annotation.Nullable;
Craig Mautner164d4bb2012-11-26 13:51:23 -080051import android.content.Context;
Winson21700932016-03-24 17:26:23 -070052import android.content.res.Configuration;
Craig Mautner164d4bb2012-11-26 13:51:23 -080053import android.graphics.Bitmap;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010054import android.graphics.Path;
Winson Chung399f6202014-03-19 10:47:20 -070055import android.graphics.Rect;
Craig Mautner164d4bb2012-11-26 13:51:23 -080056import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010057import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080058import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010059import android.os.RemoteException;
Manu Cornetda5900d2017-01-12 15:05:13 -080060import android.os.SystemProperties;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080061import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080062import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070063import android.util.SparseArray;
64import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010065import android.view.IAppTransitionAnimationSpecsFuture;
Craig Mautner164d4bb2012-11-26 13:51:23 -080066import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080067import android.view.animation.AlphaAnimation;
68import android.view.animation.Animation;
69import android.view.animation.AnimationSet;
70import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070071import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080072import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070073import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080074import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070075import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070076
Craig Mautner164d4bb2012-11-26 13:51:23 -080077import com.android.internal.util.DumpUtils.Dump;
78import com.android.server.AttributeCache;
79import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -080080import com.android.server.wm.animation.ClipRectLRAnimation;
81import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010082import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080083
84import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010085import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010086import java.util.concurrent.ExecutorService;
87import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -080088
Craig Mautner164d4bb2012-11-26 13:51:23 -080089// State management of app transitions. When we are preparing for a
90// transition, mNextAppTransition will be the kind of transition to
91// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
92// mOpeningApps and mClosingApps are the lists of tokens that will be
93// made visible or hidden at the next transition.
94public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080095 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070096 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080097
Craig Mautner4b71aa12012-12-27 17:20:01 -080098 /** Not set up for a transition. */
99 public static final int TRANSIT_UNSET = -1;
100 /** No animation for transition. */
101 public static final int TRANSIT_NONE = 0;
102 /** A window in a new activity is being opened on top of an existing one in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700103 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800104 /** The window in the top-most activity is being closed to reveal the
105 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700106 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800107 /** A window in a new task is being opened on top of an existing one
108 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700109 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800110 /** A window in the top-most activity is being closed to reveal the
111 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700112 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800113 /** A window in an existing task is being displayed on top of an existing one
114 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700115 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800116 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700117 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800118 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
119 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700120 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800121 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
122 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700123 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800124 /** A window in a new activity is being opened on top of an existing one, and both are on top
125 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700126 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800127 /** The window in the top-most activity is being closed to reveal the previous activity, and
128 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700129 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
130 /** A window in a new task is being opened behind an existing one in another activity's task.
131 * The new window will show briefly and then be gone. */
132 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800133 /** A window in a task is being animated in-place. */
134 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700135 /** An activity is being relaunched (e.g. due to configuration change). */
136 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Jorim Jaggi192086e2016-03-11 17:17:03 +0100137 /** A task is being docked from recents. */
138 public static final int TRANSIT_DOCK_TASK_FROM_RECENTS = 19;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800139
Winson Chunga4ccb862014-08-22 15:26:27 -0700140 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700141 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800142 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700143 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800144
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800145 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800146
147 /** Interpolator to be used for animations that respond directly to a touch */
148 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
149 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
150
Jorim Jaggic69bd222016-03-15 14:38:37 +0100151 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
152 new PathInterpolator(0.85f, 0f, 1f, 1f);
153
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800154 /**
155 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
156 * involved, to make it more understandable.
157 */
158 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700159 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700160 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800161
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800162 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800163 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800164
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800165 private int mNextAppTransition = TRANSIT_UNSET;
Chong Zhang60091a92016-07-27 17:52:45 -0700166 private int mLastUsedAppTransition = TRANSIT_UNSET;
167 private String mLastOpeningApp;
168 private String mLastClosingApp;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800169
170 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
171 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
172 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
173 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
174 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700175 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
176 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800177 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800178 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800179 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
180
Winson Chung399f6202014-03-19 10:47:20 -0700181 // These are the possible states for the enter/exit activities during a thumbnail transition
182 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
183 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
184 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
185 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
186
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800187 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800188 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800189 private boolean mNextAppTransitionScaleUp;
190 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100191 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700192 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800193 private int mNextAppTransitionEnter;
194 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800195 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700196
197 // Keyed by task id.
198 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
199 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100200 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
201 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700202 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
203
Winson Chunga4ccb862014-08-22 15:26:27 -0700204 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800205
Winson Chung2820c452014-04-15 15:34:44 -0700206 private Rect mTmpFromClipRect = new Rect();
207 private Rect mTmpToClipRect = new Rect();
208
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700209 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700210
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800211 private final static int APP_STATE_IDLE = 0;
212 private final static int APP_STATE_READY = 1;
213 private final static int APP_STATE_RUNNING = 2;
214 private final static int APP_STATE_TIMEOUT = 3;
215 private int mAppTransitionState = APP_STATE_IDLE;
216
217 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800218 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700219 private final Interpolator mThumbnailFadeInInterpolator;
220 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800221 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700222 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100223 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700224 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
225
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700226 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800227
Amith Yamasani4befbec2013-07-10 16:18:01 -0700228 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800229 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700230
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100231 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100232 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100233
Jorim Jaggif97ed922016-02-18 18:57:07 -0800234 private int mLastClipRevealMaxTranslation;
235 private boolean mLastHadClipReveal;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700236 private boolean mProlongedAnimationsEnded;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800237
Manu Cornetda5900d2017-01-12 15:05:13 -0800238 private final boolean mGridLayoutRecentsEnabled;
239
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800240 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800241 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800242 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800243 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
244 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700245 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
246 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100247 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
248 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800249 mConfigShortAnimTime = context.getResources().getInteger(
250 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800251 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
252 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700253 mThumbnailFadeInInterpolator = new Interpolator() {
254 @Override
255 public float getInterpolation(float input) {
256 // Linear response for first fraction, then complete after that.
257 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
258 return 0f;
259 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700260 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700261 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700262 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700263 }
264 };
265 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800266 @Override
267 public float getInterpolation(float input) {
268 // Linear response for first fraction, then complete after that.
269 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700270 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
271 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800272 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700273 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800274 }
275 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700276 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
277 * mContext.getResources().getDisplayMetrics().density);
Manu Cornetda5900d2017-01-12 15:05:13 -0800278 mGridLayoutRecentsEnabled = SystemProperties.getBoolean("ro.recents.grid", false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800279 }
280
281 boolean isTransitionSet() {
282 return mNextAppTransition != TRANSIT_UNSET;
283 }
284
Craig Mautner164d4bb2012-11-26 13:51:23 -0800285 boolean isTransitionEqual(int transit) {
286 return mNextAppTransition == transit;
287 }
288
289 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800290 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800291 }
292
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700293 private void setAppTransition(int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800294 mNextAppTransition = transit;
Chong Zhang60091a92016-07-27 17:52:45 -0700295 setLastAppTransition(TRANSIT_UNSET, null, null);
296 }
297
298 void setLastAppTransition(int transit, AppWindowToken openingApp, AppWindowToken closingApp) {
299 mLastUsedAppTransition = transit;
300 mLastOpeningApp = "" + openingApp;
301 mLastClosingApp = "" + closingApp;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800302 }
303
304 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800305 return mAppTransitionState == APP_STATE_READY
306 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800307 }
308
Craig Mautnerae446592012-12-06 19:05:05 -0800309 void setReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800310 mAppTransitionState = APP_STATE_READY;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100311 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800312 }
313
314 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800315 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800316 }
317
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800318 void setIdle() {
319 mAppTransitionState = APP_STATE_IDLE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800320 }
321
322 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800323 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800324 }
325
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800326 void setTimeout() {
327 mAppTransitionState = APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800328 }
329
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700330 Bitmap getAppTransitionThumbnailHeader(int taskId) {
331 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800332 if (spec == null) {
333 spec = mDefaultNextAppTransitionAnimationSpec;
334 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700335 return spec != null ? spec.bitmap : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800336 }
337
Winson Chunga4ccb862014-08-22 15:26:27 -0700338 /** Returns whether the next thumbnail transition is aspect scaled up. */
339 boolean isNextThumbnailTransitionAspectScaled() {
340 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
341 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
342 }
343
344 /** Returns whether the next thumbnail transition is scaling up. */
345 boolean isNextThumbnailTransitionScaleUp() {
346 return mNextAppTransitionScaleUp;
347 }
348
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800349 boolean isNextAppTransitionThumbnailUp() {
350 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
351 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
352 }
353
354 boolean isNextAppTransitionThumbnailDown() {
355 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
356 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
357 }
358
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100359 /**
360 * @return true if and only if we are currently fetching app transition specs from the future
361 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
362 */
363 boolean isFetchingAppTransitionsSpecs() {
364 return mNextAppTransitionAnimationsSpecsPending;
365 }
366
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700367 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800368 if (!isRunning()) {
369 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100370 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800371 mLastHadClipReveal = false;
372 mLastClipRevealMaxTranslation = 0;
373 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700374 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800375 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700376 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800377 }
378
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800379 void goodToGo(AppWindowAnimator topOpeningAppAnimator, AppWindowAnimator topClosingAppAnimator,
380 ArraySet<AppWindowToken> openingApps, ArraySet<AppWindowToken> closingApps) {
Jorim Jaggi84afb1a2016-09-28 14:54:04 +0200381 int appTransition = mNextAppTransition;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800382 mNextAppTransition = TRANSIT_UNSET;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800383 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100384 notifyAppTransitionStartingLocked(
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800385 topOpeningAppAnimator != null ? topOpeningAppAnimator.mAppToken.token : null,
386 topClosingAppAnimator != null ? topClosingAppAnimator.mAppToken.token : null,
387 topOpeningAppAnimator != null ? topOpeningAppAnimator.animation : null,
388 topClosingAppAnimator != null ? topClosingAppAnimator.animation : null);
389 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Jorim Jaggi84afb1a2016-09-28 14:54:04 +0200390 .notifyAppTransitionStarting(openingApps, appTransition);
Jorim Jaggi363ab982016-04-26 19:51:20 -0700391
392 // Prolong the start for the transition when docking a task from recents, unless recents
393 // ended it already then we don't need to wait.
394 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS && !mProlongedAnimationsEnded) {
395 for (int i = openingApps.size() - 1; i >= 0; i--) {
396 final AppWindowAnimator appAnimator = openingApps.valueAt(i).mAppAnimator;
397 appAnimator.startProlongAnimation(PROLONG_ANIMATION_AT_START);
398 }
399 }
400 }
401
402 /**
403 * Let the transitions manager know that the somebody wanted to end the prolonged animations.
404 */
405 void notifyProlongedAnimationsEnded() {
406 mProlongedAnimationsEnded = true;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800407 }
408
409 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800410 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800411 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700412 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi65193992015-11-23 16:49:59 -0800413 mNextAppTransitionAnimationsSpecsFuture = null;
414 mDefaultNextAppTransitionAnimationSpec = null;
415 mAnimationFinishedCallback = null;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700416 mProlongedAnimationsEnded = false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800417 }
418
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800419 void freeze() {
420 setAppTransition(AppTransition.TRANSIT_UNSET);
421 clear();
422 setReady();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100423 notifyAppTransitionCancelledLocked();
424 }
425
426 void registerListenerLocked(AppTransitionListener listener) {
427 mListeners.add(listener);
428 }
429
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700430 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100431 for (int i = 0; i < mListeners.size(); i++) {
432 mListeners.get(i).onAppTransitionFinishedLocked(token);
433 }
434 }
435
436 private void notifyAppTransitionPendingLocked() {
437 for (int i = 0; i < mListeners.size(); i++) {
438 mListeners.get(i).onAppTransitionPendingLocked();
439 }
440 }
441
442 private void notifyAppTransitionCancelledLocked() {
443 for (int i = 0; i < mListeners.size(); i++) {
444 mListeners.get(i).onAppTransitionCancelledLocked();
445 }
446 }
447
448 private void notifyAppTransitionStartingLocked(IBinder openToken,
449 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
450 for (int i = 0; i < mListeners.size(); i++) {
451 mListeners.get(i).onAppTransitionStartingLocked(openToken, closeToken, openAnimation,
452 closeAnimation);
453 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800454 }
455
Craig Mautner164d4bb2012-11-26 13:51:23 -0800456 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
457 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
458 + (lp != null ? lp.packageName : null)
459 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
460 if (lp != null && lp.windowAnimations != 0) {
461 // If this is a system resource, don't try to load it from the
462 // application resources. It is nice to avoid loading application
463 // resources if we can.
464 String packageName = lp.packageName != null ? lp.packageName : "android";
465 int resId = lp.windowAnimations;
466 if ((resId&0xFF000000) == 0x01000000) {
467 packageName = "android";
468 }
469 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
470 + packageName);
471 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700472 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800473 }
474 return null;
475 }
476
477 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
478 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
479 + packageName + " resId=0x" + Integer.toHexString(resId));
480 if (packageName != null) {
481 if ((resId&0xFF000000) == 0x01000000) {
482 packageName = "android";
483 }
484 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
485 + packageName);
486 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700487 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800488 }
489 return null;
490 }
491
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700492 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800493 int anim = 0;
494 Context context = mContext;
495 if (animAttr >= 0) {
496 AttributeCache.Entry ent = getCachedAnimations(lp);
497 if (ent != null) {
498 context = ent.context;
499 anim = ent.array.getResourceId(animAttr, 0);
500 }
501 }
502 if (anim != 0) {
503 return AnimationUtils.loadAnimation(context, anim);
504 }
505 return null;
506 }
507
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700508 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
509 Context context = mContext;
510 if (resId >= 0) {
511 AttributeCache.Entry ent = getCachedAnimations(lp);
512 if (ent != null) {
513 context = ent.context;
514 }
515 return AnimationUtils.loadAnimation(context, resId);
516 }
517 return null;
518 }
519
520 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800521 int anim = 0;
522 Context context = mContext;
523 if (resId >= 0) {
524 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
525 if (ent != null) {
526 context = ent.context;
527 anim = resId;
528 }
529 }
530 if (anim != 0) {
531 return AnimationUtils.loadAnimation(context, anim);
532 }
533 return null;
534 }
535
Craig Mautner164d4bb2012-11-26 13:51:23 -0800536 /**
537 * Compute the pivot point for an animation that is scaling from a small
538 * rect on screen to a larger rect. The pivot point varies depending on
539 * the distance between the inner and outer edges on both sides. This
540 * function computes the pivot point for one dimension.
541 * @param startPos Offset from left/top edge of outer rectangle to
542 * left/top edge of inner rectangle.
543 * @param finalScale The scaling factor between the size of the outer
544 * and inner rectangles.
545 */
546 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800547
548 /*
549 Theorem of intercepting lines:
550
551 + + +-----------------------------------------------+
552 | | | |
553 | | | |
554 | | | |
555 | | | |
556 x | y | | |
557 | | | |
558 | | | |
559 | | | |
560 | | | |
561 | + | +--------------------+ |
562 | | | | |
563 | | | | |
564 | | | | |
565 | | | | |
566 | | | | |
567 | | | | |
568 | | | | |
569 | | | | |
570 | | | | |
571 | | | | |
572 | | | | |
573 | | | | |
574 | | | | |
575 | | | | |
576 | | | | |
577 | | | | |
578 | | | | |
579 | | +--------------------+ |
580 | | |
581 | | |
582 | | |
583 | | |
584 | | |
585 | | |
586 | | |
587 | +-----------------------------------------------+
588 |
589 |
590 |
591 |
592 |
593 |
594 |
595 |
596 |
597 + ++
598 p ++
599
600 scale = (x - y) / x
601 <=> x = -y / (scale - 1)
602 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800603 final float denom = finalScale-1;
604 if (Math.abs(denom) < .0001f) {
605 return startPos;
606 }
607 return -startPos / denom;
608 }
609
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700610 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
611 Rect containingFrame) {
612 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700613 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700614 final int appWidth = containingFrame.width();
615 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800616 if (enter) {
617 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700618 float scaleW = mTmpRect.width() / (float) appWidth;
619 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800620 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700621 computePivot(mTmpRect.left, scaleW),
Winson4c3fecd2016-07-13 12:29:48 -0700622 computePivot(mTmpRect.top, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800623 scale.setInterpolator(mDecelerateInterpolator);
624
Craig Mautner164d4bb2012-11-26 13:51:23 -0800625 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700626 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800627
628 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800629 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800630 set.addAnimation(alpha);
631 set.setDetachWallpaper(true);
632 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800633 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
634 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800635 // If we are on top of the wallpaper, we need an animation that
636 // correctly handles the wallpaper staying static behind all of
637 // the animated elements. To do this, will just have the existing
638 // element fade out.
639 a = new AlphaAnimation(1, 0);
640 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800641 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800642 // For normal animations, the exiting element just holds in place.
643 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800644 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800645
646 // Pick the desired duration. If this is an inter-activity transition,
647 // it is the standard duration for that. Otherwise we use the longer
648 // task transition duration.
649 final long duration;
650 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800651 case TRANSIT_ACTIVITY_OPEN:
652 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800653 duration = mConfigShortAnimTime;
654 break;
655 default:
656 duration = DEFAULT_APP_TRANSITION_DURATION;
657 break;
658 }
659 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800660 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800661 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800662 a.initialize(appWidth, appHeight, appWidth, appHeight);
663 return a;
664 }
665
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700666 private void getDefaultNextAppTransitionStartRect(Rect rect) {
667 if (mDefaultNextAppTransitionAnimationSpec == null ||
668 mDefaultNextAppTransitionAnimationSpec.rect == null) {
669 Slog.wtf(TAG, "Starting rect for app requested, but none available", new Throwable());
670 rect.setEmpty();
671 } else {
672 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
673 }
674 }
675
676 void getNextAppTransitionStartRect(int taskId, Rect rect) {
677 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800678 if (spec == null) {
679 spec = mDefaultNextAppTransitionAnimationSpec;
680 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700681 if (spec == null || spec.rect == null) {
682 Slog.wtf(TAG, "Starting rect for task: " + taskId + " requested, but not available",
683 new Throwable());
684 rect.setEmpty();
685 } else {
686 rect.set(spec.rect);
687 }
688 }
689
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800690 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
691 Bitmap bitmap) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700692 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800693 bitmap, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700694 }
695
Jorim Jaggif97ed922016-02-18 18:57:07 -0800696 /**
697 * @return the duration of the last clip reveal animation
698 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800699 long getLastClipRevealTransitionDuration() {
700 return mLastClipRevealTransitionDuration;
701 }
702
703 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800704 * @return the maximum distance the app surface is traveling of the last clip reveal animation
705 */
706 int getLastClipRevealMaxTranslation() {
707 return mLastClipRevealMaxTranslation;
708 }
709
710 /**
711 * @return true if in the last app transition had a clip reveal animation, false otherwise
712 */
713 boolean hadClipRevealAnimation() {
714 return mLastHadClipReveal;
715 }
716
717 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800718 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
719 * the start rect is outside of the target rect, and there is a lot of movement going on.
720 *
721 * @param cutOff whether the start rect was not fully contained by the end rect
722 * @param translationX the total translation the surface moves in x direction
723 * @param translationY the total translation the surfaces moves in y direction
724 * @param displayFrame our display frame
725 *
726 * @return the duration of the clip reveal animation, in milliseconds
727 */
728 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
729 float translationY, Rect displayFrame) {
730 if (!cutOff) {
731 return DEFAULT_APP_TRANSITION_DURATION;
732 }
733 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
734 Math.abs(translationY) / displayFrame.height());
735 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
736 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
737 }
738
739 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
740 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800741 final Animation anim;
742 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700743 final int appWidth = appFrame.width();
744 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800745
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700746 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700747 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700748 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700749
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700750 float t = 0f;
751 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800752 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700753 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800754 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
755 int translationX = 0;
756 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700757 int centerX = mTmpRect.centerX();
758 int centerY = mTmpRect.centerY();
759 int halfWidth = mTmpRect.width() / 2;
760 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800761 int clipStartX = centerX - halfWidth - appFrame.left;
762 int clipStartY = centerY - halfHeight - appFrame.top;
763 boolean cutOff = false;
764
765 // If the starting rectangle is fully or partially outside of the target rectangle, we
766 // need to start the clipping at the edge and then achieve the rest with translation
767 // and extending the clip rect from that edge.
768 if (appFrame.top > centerY - halfHeight) {
769 translationY = (centerY - halfHeight) - appFrame.top;
770 translationYCorrection = 0;
771 clipStartY = 0;
772 cutOff = true;
773 }
774 if (appFrame.left > centerX - halfWidth) {
775 translationX = (centerX - halfWidth) - appFrame.left;
776 clipStartX = 0;
777 cutOff = true;
778 }
779 if (appFrame.right < centerX + halfWidth) {
780 translationX = (centerX + halfWidth) - appFrame.right;
781 clipStartX = appWidth - mTmpRect.width();
782 cutOff = true;
783 }
784 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
785 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700786
787 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800788 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800789 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700790 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800791 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700792
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800793 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
794 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
795 : mLinearOutSlowInInterpolator);
796 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800797
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800798 Animation clipAnimTB = new ClipRectTBAnimation(
799 clipStartY, clipStartY + mTmpRect.height(),
800 0, appHeight,
801 translationYCorrection, 0,
802 mLinearOutSlowInInterpolator);
803 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
804 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800805
806 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800807 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700808 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800809 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700810 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800811
812 AnimationSet set = new AnimationSet(false);
813 set.addAnimation(clipAnimLR);
814 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700815 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800816 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700817 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800818 set.initialize(appWidth, appHeight, appWidth, appHeight);
819 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800820 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800821 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800822
823 // If the start rect was full inside the target rect (cutOff == false), we don't need
824 // to store the translation, because it's only used if cutOff == true.
825 mLastClipRevealMaxTranslation = cutOff
826 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800827 } else {
828 final long duration;
829 switch (transit) {
830 case TRANSIT_ACTIVITY_OPEN:
831 case TRANSIT_ACTIVITY_CLOSE:
832 duration = mConfigShortAnimTime;
833 break;
834 default:
835 duration = DEFAULT_APP_TRANSITION_DURATION;
836 break;
837 }
838 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
839 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
840 // If we are on top of the wallpaper, we need an animation that
841 // correctly handles the wallpaper staying static behind all of
842 // the animated elements. To do this, will just have the existing
843 // element fade out.
844 anim = new AlphaAnimation(1, 0);
845 anim.setDetachWallpaper(true);
846 } else {
847 // For normal animations, the exiting element just holds in place.
848 anim = new AlphaAnimation(1, 1);
849 }
850 anim.setInterpolator(mDecelerateInterpolator);
851 anim.setDuration(duration);
852 anim.setFillAfter(true);
853 }
854 return anim;
855 }
856
Winson Chung399f6202014-03-19 10:47:20 -0700857 /**
858 * Prepares the specified animation with a standard duration, interpolator, etc.
859 */
Winson Chung5393dff2014-05-08 14:25:43 -0700860 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100861 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700862 if (duration > 0) {
863 a.setDuration(duration);
864 }
Winson Chung5393dff2014-05-08 14:25:43 -0700865 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100866 if (interpolator != null) {
867 a.setInterpolator(interpolator);
868 }
Winson Chung5393dff2014-05-08 14:25:43 -0700869 a.initialize(appWidth, appHeight, appWidth, appHeight);
870 return a;
871 }
872
873 /**
874 * Prepares the specified animation with a standard duration, interpolator, etc.
875 */
Winson Chung399f6202014-03-19 10:47:20 -0700876 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800877 // Pick the desired duration. If this is an inter-activity transition,
878 // it is the standard duration for that. Otherwise we use the longer
879 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700880 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800881 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800882 case TRANSIT_ACTIVITY_OPEN:
883 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800884 duration = mConfigShortAnimTime;
885 break;
886 default:
887 duration = DEFAULT_APP_TRANSITION_DURATION;
888 break;
889 }
Winson Chung5393dff2014-05-08 14:25:43 -0700890 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
891 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800892 }
893
Winson Chung399f6202014-03-19 10:47:20 -0700894 /**
895 * Return the current thumbnail transition state.
896 */
897 int getThumbnailTransitionState(boolean enter) {
898 if (enter) {
899 if (mNextAppTransitionScaleUp) {
900 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
901 } else {
902 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
903 }
904 } else {
905 if (mNextAppTransitionScaleUp) {
906 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
907 } else {
908 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
909 }
910 }
911 }
912
913 /**
914 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700915 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700916 */
Jorim Jaggide63d442016-03-14 14:56:56 +0100917 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winsonb2024762016-04-05 17:32:30 -0700918 Bitmap thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -0700919 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700920 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700921 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700922 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700923 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700924
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700925 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700926 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -0700927 final float fromX;
928 final float fromY;
929 final float toX;
930 final float toY;
931 final float pivotX;
932 final float pivotY;
Manu Cornetda5900d2017-01-12 15:05:13 -0800933 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggi09072002016-03-25 16:48:42 -0700934 fromX = mTmpRect.left;
935 fromY = mTmpRect.top;
936
937 // For the curved translate animation to work, the pivot points needs to be at the
938 // same absolute position as the one from the real surface.
939 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
940 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
941 pivotX = mTmpRect.width() / 2;
942 pivotY = appRect.height() / 2 / scaleW;
943 } else {
944 pivotX = 0;
945 pivotY = 0;
946 fromX = mTmpRect.left;
947 fromY = mTmpRect.top;
948 toX = appRect.left;
949 toY = appRect.top;
950 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100951 final long duration = getAspectScaleDuration();
952 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -0700953 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700954 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +0100955 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100956 scale.setInterpolator(interpolator);
957 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800958 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100959 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
960 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
961 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
962 ? duration / 2
963 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100964 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
965 translate.setInterpolator(interpolator);
966 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -0700967
Jorim Jaggide63d442016-03-14 14:56:56 +0100968 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
969 mTmpToClipRect.set(appRect);
970
971 // Containing frame is in screen space, but we need the clip rect in the
972 // app space.
973 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100974 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
975 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +0100976
977 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +0100978 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
979 (int) (-contentInsets.top * scaleW),
980 (int) (-contentInsets.right * scaleW),
981 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +0100982 }
983
984 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100985 clipAnim.setInterpolator(interpolator);
986 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +0100987
Winson Chung399f6202014-03-19 10:47:20 -0700988 // This AnimationSet uses the Interpolators assigned above.
989 AnimationSet set = new AnimationSet(false);
990 set.addAnimation(scale);
991 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -0700992 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +0100993 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -0700994 a = set;
995 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700996 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +0100997 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100998 scale.setInterpolator(interpolator);
999 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001000 Animation alpha = new AlphaAnimation(0f, 1f);
1001 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001002 alpha.setDuration(duration);
1003 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1004 translate.setInterpolator(interpolator);
1005 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001006
Winson Chunga4ccb862014-08-22 15:26:27 -07001007 // This AnimationSet uses the Interpolators assigned above.
1008 AnimationSet set = new AnimationSet(false);
1009 set.addAnimation(scale);
1010 set.addAnimation(alpha);
1011 set.addAnimation(translate);
1012 a = set;
1013
1014 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001015 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001016 null);
Winson Chung399f6202014-03-19 10:47:20 -07001017 }
1018
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001019 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1020
1021 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001022 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001023 return new TranslateAnimation(fromX, toX, fromY, toY);
1024 } else {
1025 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1026 return new CurvedTranslateAnimation(path);
1027 }
1028 }
1029
1030 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1031 final Path path = new Path();
1032 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001033
1034 if (fromY > toY) {
1035 // If the object needs to go up, move it in horizontal direction first, then vertical.
1036 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1037 } else {
1038 // If the object needs to go down, move it in vertical direction first, then horizontal.
1039 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1040 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001041 return path;
1042 }
1043
1044 private long getAspectScaleDuration() {
1045 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001046 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001047 } else {
1048 return THUMBNAIL_APP_TRANSITION_DURATION;
1049 }
1050 }
1051
1052 private Interpolator getAspectScaleInterpolator() {
1053 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1054 return mFastOutSlowInInterpolator;
1055 } else {
1056 return TOUCH_RESPONSE_INTERPOLATOR;
1057 }
1058 }
1059
Winson Chung399f6202014-03-19 10:47:20 -07001060 /**
1061 * This alternate animation is created when we are doing a thumbnail transition, for the
1062 * activity that is leaving, and the activity that is entering.
1063 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001064 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001065 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001066 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001067 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001068 final int appWidth = containingFrame.width();
1069 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001070 getDefaultNextAppTransitionStartRect(mTmpRect);
1071 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001072 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001073 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001074 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001075 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001076 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001077
1078 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001079 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1080 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1081 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1082 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001083 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001084 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001085 } else if (freeform) {
1086 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1087 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001088 } else {
Winson21700932016-03-24 17:26:23 -07001089 AnimationSet set = new AnimationSet(true);
1090
1091 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001092 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001093 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001094
1095 // Containing frame is in screen space, but we need the clip rect in the
1096 // app space.
1097 mTmpFromClipRect.offsetTo(0, 0);
1098 mTmpToClipRect.offsetTo(0, 0);
1099
1100 // Exclude insets region from the source clip.
1101 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001102 mNextAppTransitionInsets.set(contentInsets);
1103
Manu Cornetda5900d2017-01-12 15:05:13 -08001104 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001105 // We scale the width and clip to the top/left square
1106 float scale = thumbWidth /
1107 (appWidth - contentInsets.left - contentInsets.right);
Manu Cornetb68b7652017-01-23 19:37:53 +09001108 if (!mGridLayoutRecentsEnabled) {
1109 int unscaledThumbHeight = (int) (thumbHeight / scale);
1110 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1111 }
Jorim Jaggic69bd222016-03-15 14:38:37 +01001112
1113 mNextAppTransitionInsets.set(contentInsets);
1114
Jorim Jaggi8448f332016-03-14 17:50:37 +01001115 Animation scaleAnim = new ScaleAnimation(
1116 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1117 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001118 containingFrame.width() / 2f,
1119 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001120 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001121 final float x = containingFrame.width() / 2f
1122 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001123 final float targetY = (mTmpRect.top - containingFrame.top);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001124 final float y = containingFrame.height() / 2f
1125 - containingFrame.height() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001126 final float startX = targetX - x;
1127 final float startY = targetY - y;
1128 Animation clipAnim = scaleUp
1129 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1130 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1131 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001132 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1133 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1134
Winson21700932016-03-24 17:26:23 -07001135 set.addAnimation(clipAnim);
1136 set.addAnimation(scaleAnim);
1137 set.addAnimation(translateAnim);
1138
1139 } else {
1140 // In landscape, we don't scale at all and only crop
1141 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1142 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1143
Jorim Jaggi8448f332016-03-14 17:50:37 +01001144 Animation clipAnim = scaleUp
1145 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1146 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1147 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001148 ? createCurvedMotion(thumbStartX, 0,
1149 thumbStartY - contentInsets.top, 0)
1150 : createCurvedMotion(0, thumbStartX, 0,
1151 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001152
1153 set.addAnimation(clipAnim);
1154 set.addAnimation(translateAnim);
1155 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001156 a = set;
Winson21700932016-03-24 17:26:23 -07001157 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001158 }
Winson Chung399f6202014-03-19 10:47:20 -07001159 break;
1160 }
1161 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001162 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001163 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001164 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001165 // activity.
1166 a = new AlphaAnimation(1, 0);
1167 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001168 a = new AlphaAnimation(1, 1);
1169 }
1170 break;
1171 }
1172 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001173 // Target app window during the scale down
1174 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1175 // Fade in the destination activity if we are animating from a wallpaper
1176 // activity.
1177 a = new AlphaAnimation(0, 1);
1178 } else {
1179 a = new AlphaAnimation(1, 1);
1180 }
Winson Chung399f6202014-03-19 10:47:20 -07001181 break;
1182 }
Winson Chung399f6202014-03-19 10:47:20 -07001183 default:
1184 throw new RuntimeException("Invalid thumbnail transition state");
1185 }
1186
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001187 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1188 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001189 }
1190
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001191 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1192 @Nullable Rect surfaceInsets, int taskId) {
1193 getNextAppTransitionStartRect(taskId, mTmpRect);
1194 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1195 true);
1196 }
1197
1198 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1199 @Nullable Rect surfaceInsets, int taskId) {
1200 getNextAppTransitionStartRect(taskId, mTmpRect);
1201 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1202 false);
1203 }
1204
1205 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1206 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1207 final float sourceWidth = sourceFrame.width();
1208 final float sourceHeight = sourceFrame.height();
1209 final float destWidth = destFrame.width();
1210 final float destHeight = destFrame.height();
1211 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1212 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001213 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001214 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001215 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001216 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001217 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1218 // We want the scaling to happen from the center of the surface. In order to achieve that,
1219 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001220 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1221 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1222 final ScaleAnimation scale = enter ?
1223 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1224 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1225 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1226 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1227 final int destHCenter = destFrame.left + destFrame.width() / 2;
1228 final int destVCenter = destFrame.top + destFrame.height() / 2;
1229 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1230 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1231 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1232 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001233 set.addAnimation(scale);
1234 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001235
1236 final IRemoteCallback callback = mAnimationFinishedCallback;
1237 if (callback != null) {
1238 set.setAnimationListener(new Animation.AnimationListener() {
1239 @Override
1240 public void onAnimationStart(Animation animation) { }
1241
1242 @Override
1243 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001244 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001245 }
1246
1247 @Override
1248 public void onAnimationRepeat(Animation animation) { }
1249 });
1250 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001251 return set;
1252 }
1253
Winson Chung399f6202014-03-19 10:47:20 -07001254 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001255 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001256 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001257 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001258 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
1259 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001260 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001261 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001262 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001263 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001264 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001265 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1266
1267 if (mNextAppTransitionScaleUp) {
1268 // Animation for the thumbnail zooming from its initial size to the full screen
1269 float scaleW = appWidth / thumbWidth;
1270 float scaleH = appHeight / thumbHeight;
1271 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001272 computePivot(mTmpRect.left, 1 / scaleW),
1273 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001274 scale.setInterpolator(mDecelerateInterpolator);
1275
1276 Animation alpha = new AlphaAnimation(1, 0);
1277 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1278
1279 // This AnimationSet uses the Interpolators assigned above.
1280 AnimationSet set = new AnimationSet(false);
1281 set.addAnimation(scale);
1282 set.addAnimation(alpha);
1283 a = set;
1284 } else {
1285 // Animation for the thumbnail zooming down from the full screen to its final size
1286 float scaleW = appWidth / thumbWidth;
1287 float scaleH = appHeight / thumbHeight;
1288 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001289 computePivot(mTmpRect.left, 1 / scaleW),
1290 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001291 }
1292
1293 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1294 }
1295
1296 /**
Winson Chung399f6202014-03-19 10:47:20 -07001297 * This animation is created when we are doing a thumbnail transition, for the activity that is
1298 * leaving, and the activity that is entering.
1299 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001300 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1301 int transit, int taskId) {
1302 final int appWidth = containingFrame.width();
1303 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001304 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001305 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001306 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001307 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001308 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001309 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001310 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1311
1312 switch (thumbTransitState) {
1313 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1314 // Entering app scales up with the thumbnail
1315 float scaleW = thumbWidth / appWidth;
1316 float scaleH = thumbHeight / appHeight;
1317 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001318 computePivot(mTmpRect.left, scaleW),
1319 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001320 break;
1321 }
1322 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1323 // Exiting app while the thumbnail is scaling up should fade or stay in place
1324 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1325 // Fade out while bringing up selected activity. This keeps the
1326 // current activity from showing through a launching wallpaper
1327 // activity.
1328 a = new AlphaAnimation(1, 0);
1329 } else {
1330 // noop animation
1331 a = new AlphaAnimation(1, 1);
1332 }
1333 break;
1334 }
1335 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1336 // Entering the other app, it should just be visible while we scale the thumbnail
1337 // down above it
1338 a = new AlphaAnimation(1, 1);
1339 break;
1340 }
1341 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1342 // Exiting the current app, the app should scale down with the thumbnail
1343 float scaleW = thumbWidth / appWidth;
1344 float scaleH = thumbHeight / appHeight;
1345 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001346 computePivot(mTmpRect.left, scaleW),
1347 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001348
1349 Animation alpha = new AlphaAnimation(1, 0);
1350
1351 AnimationSet set = new AnimationSet(true);
1352 set.addAnimation(scale);
1353 set.addAnimation(alpha);
1354 set.setZAdjustment(Animation.ZORDER_TOP);
1355 a = set;
1356 break;
1357 }
1358 default:
1359 throw new RuntimeException("Invalid thumbnail transition state");
1360 }
1361
1362 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1363 }
1364
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001365 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001366 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1367 final int left = mTmpFromClipRect.left;
1368 final int top = mTmpFromClipRect.top;
1369 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001370 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1371 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001372 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001373 float fromWidth = mTmpFromClipRect.width();
1374 float toWidth = mTmpToClipRect.width();
1375 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001376 // While the window might span the whole display, the actual content will be cropped to the
1377 // system decoration frame, for example when the window is docked. We need to take into
1378 // account the visible height when constructing the animation.
1379 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1380 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001381 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1382 // The final window is larger in both dimensions than current window (e.g. we are
1383 // maximizing), so we can simply unclip the new window and there will be no disappearing
1384 // frame.
1385 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1386 } else {
1387 // The disappearing window has one larger dimension. We need to apply scaling, so the
1388 // first frame of the entry animation matches the old window.
1389 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001390 // We might not be going exactly full screen, but instead be aligned under the status
1391 // bar using cropping. We still need to account for the cropped part, which will also
1392 // be scaled.
1393 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001394 }
1395
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001396 // We animate the translation from the old position of the removed window, to the new
1397 // position of the added window. The latter might not be full screen, for example docked for
1398 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001399 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001400 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001401 set.addAnimation(translate);
1402 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001403 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001404 return set;
1405 }
1406
Jorim Jaggic554b772015-06-04 16:07:57 -07001407 /**
1408 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1409 * frame of the transition doesn't change the visuals on screen, so we can start
1410 * directly with the second one
1411 */
1412 boolean canSkipFirstFrame() {
1413 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1414 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
1415 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1416 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001417
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001418 /**
1419 *
1420 * @param frame These are the bounds of the window when it finishes the animation. This is where
1421 * the animation must usually finish in entrance animation, as the next frame will
1422 * display the window at these coordinates. In case of exit animation, this is
1423 * where the animation must start, as the frame before the animation is displaying
1424 * the window at these bounds.
1425 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1426 * window might be obscured, usually by the system windows (status bar and
1427 * navigation bar) and we use content insets to convey that information. This
1428 * usually affects the animation aspects vertically, as the system decoration is
1429 * at the top and the bottom. For example when we animate from full screen to
1430 * recents, we want to exclude the covered parts, because they won't match the
1431 * thumbnail after the last frame is executed.
1432 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1433 * know about this to make the animation frames match. We currently use
1434 * this for freeform windows, which have larger surfaces to display
1435 * shadows. When we animate them from recents, we want to match the content
1436 * to the recents thumbnail and hence need to account for the surface being
1437 * bigger.
1438 */
Winsonb2024762016-04-05 17:32:30 -07001439 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001440 int orientation, Rect frame, Rect displayFrame, Rect insets,
1441 @Nullable Rect surfaceInsets, boolean isVoiceInteraction, boolean freeform,
1442 int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001443 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001444 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
1445 || transit == TRANSIT_TASK_OPEN
1446 || transit == TRANSIT_TASK_TO_FRONT)) {
1447 a = loadAnimationRes(lp, enter
1448 ? com.android.internal.R.anim.voice_activity_open_enter
1449 : com.android.internal.R.anim.voice_activity_open_exit);
1450 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1451 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001452 + " anim=" + a + " transit=" + appTransitionToString(transit)
1453 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001454 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1455 || transit == TRANSIT_TASK_CLOSE
1456 || transit == TRANSIT_TASK_TO_BACK)) {
1457 a = loadAnimationRes(lp, enter
1458 ? com.android.internal.R.anim.voice_activity_close_enter
1459 : com.android.internal.R.anim.voice_activity_close_exit);
1460 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1461 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001462 + " anim=" + a + " transit=" + appTransitionToString(transit)
1463 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001464 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001465 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001466 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1467 "applyAnimation:"
1468 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1469 + " transit=" + appTransitionToString(transit)
1470 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001471 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1472 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001473 mNextAppTransitionEnter : mNextAppTransitionExit);
1474 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1475 "applyAnimation:"
1476 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001477 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001478 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001479 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1480 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1481 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1482 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001483 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1484 + " transit=" + appTransitionToString(transit)
1485 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001486 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001487 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001488 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1489 "applyAnimation:"
1490 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001491 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001492 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001493 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001494 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001495 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1496 "applyAnimation:"
1497 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001498 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001499 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001500 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1501 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001502 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001503 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001504 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001505 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001506 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1507 String animName = mNextAppTransitionScaleUp ?
1508 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1509 Slog.v(TAG, "applyAnimation:"
1510 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001511 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001512 + " Callers=" + Debug.getCallers(3));
1513 }
1514 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1515 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1516 mNextAppTransitionScaleUp =
1517 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1518 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001519 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001520 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001521 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1522 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001523 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001524 Slog.v(TAG, "applyAnimation:"
1525 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001526 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001527 + " Callers=" + Debug.getCallers(3));
1528 }
1529 } else {
1530 int animAttr = 0;
1531 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001532 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001533 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001534 ? WindowAnimation_activityOpenEnterAnimation
1535 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001536 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001537 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001538 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001539 ? WindowAnimation_activityCloseEnterAnimation
1540 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001541 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001542 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001543 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001544 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001545 ? WindowAnimation_taskOpenEnterAnimation
1546 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001547 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001548 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001549 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001550 ? WindowAnimation_taskCloseEnterAnimation
1551 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001552 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001553 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001554 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001555 ? WindowAnimation_taskToFrontEnterAnimation
1556 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001557 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001558 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001559 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001560 ? WindowAnimation_taskToBackEnterAnimation
1561 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001562 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001563 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001564 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001565 ? WindowAnimation_wallpaperOpenEnterAnimation
1566 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001567 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001568 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001569 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001570 ? WindowAnimation_wallpaperCloseEnterAnimation
1571 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001572 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001573 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001574 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001575 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1576 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001577 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001578 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001579 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001580 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1581 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001582 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001583 case TRANSIT_TASK_OPEN_BEHIND:
1584 animAttr = enter
1585 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001586 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001587 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001588 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001589 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1590 "applyAnimation:"
1591 + " anim=" + a
1592 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001593 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001594 + " Callers=" + Debug.getCallers(3));
1595 }
1596 return a;
1597 }
1598
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001599 int getAppStackClipMode() {
1600 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001601 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001602 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001603 ? STACK_CLIP_NONE
1604 : STACK_CLIP_AFTER_ANIM;
1605 }
1606
Craig Mautner164d4bb2012-11-26 13:51:23 -08001607 void postAnimationCallback() {
1608 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001609 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1610 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001611 mNextAppTransitionCallback = null;
1612 }
1613 }
1614
1615 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001616 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001617 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001618 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001619 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001620 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001621 mNextAppTransitionEnter = enterAnim;
1622 mNextAppTransitionExit = exitAnim;
1623 postAnimationCallback();
1624 mNextAppTransitionCallback = startedCallback;
1625 } else {
1626 postAnimationCallback();
1627 }
1628 }
1629
1630 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001631 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001632 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001633 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001634 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001635 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001636 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001637 }
1638 }
1639
Chet Haase10e23ab2015-02-11 15:08:38 -08001640 void overridePendingAppTransitionClipReveal(int startX, int startY,
1641 int startWidth, int startHeight) {
1642 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001643 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001644 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001645 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001646 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001647 }
1648 }
1649
Craig Mautner164d4bb2012-11-26 13:51:23 -08001650 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1651 IRemoteCallback startedCallback, boolean scaleUp) {
1652 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001653 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001654 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1655 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001656 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001657 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001658 postAnimationCallback();
1659 mNextAppTransitionCallback = startedCallback;
1660 } else {
1661 postAnimationCallback();
1662 }
1663 }
1664
Winson Chunga4ccb862014-08-22 15:26:27 -07001665 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001666 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001667 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001668 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001669 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1670 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001671 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001672 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1673 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001674 postAnimationCallback();
1675 mNextAppTransitionCallback = startedCallback;
1676 } else {
1677 postAnimationCallback();
1678 }
1679 }
1680
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001681 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001682 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1683 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001684 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001685 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001686 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1687 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001688 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001689 if (specs != null) {
1690 for (int i = 0; i < specs.length; i++) {
1691 AppTransitionAnimationSpec spec = specs[i];
1692 if (spec != null) {
1693 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1694 if (i == 0) {
1695 // In full screen mode, the transition code depends on the default spec
1696 // to be set.
1697 Rect rect = spec.rect;
1698 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Filip Gruszczynskie3264d82015-11-20 17:10:04 -08001699 rect.width(), rect.height(), spec.bitmap);
Jorim Jaggi43102412015-11-11 16:28:37 +01001700 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001701 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001702 }
1703 }
1704 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001705 mNextAppTransitionCallback = onAnimationStartedCallback;
1706 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001707 } else {
1708 postAnimationCallback();
1709 }
1710 }
1711
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001712 void overridePendingAppTransitionMultiThumbFuture(
1713 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1714 boolean scaleUp) {
1715 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001716 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001717 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1718 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001719 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1720 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001721 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001722 }
1723 }
1724
Winson Chung044d5292014-11-06 11:05:19 -08001725 void overrideInPlaceAppTransition(String packageName, int anim) {
1726 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001727 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001728 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1729 mNextAppTransitionPackage = packageName;
1730 mNextAppTransitionInPlace = anim;
1731 } else {
1732 postAnimationCallback();
1733 }
1734 }
1735
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001736 /**
1737 * If a future is set for the app transition specs, fetch it in another thread.
1738 */
1739 private void fetchAppTransitionSpecsFromFuture() {
1740 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1741 mNextAppTransitionAnimationsSpecsPending = true;
1742 final IAppTransitionAnimationSpecsFuture future
1743 = mNextAppTransitionAnimationsSpecsFuture;
1744 mNextAppTransitionAnimationsSpecsFuture = null;
1745 mDefaultExecutor.execute(new Runnable() {
1746 @Override
1747 public void run() {
1748 AppTransitionAnimationSpec[] specs = null;
1749 try {
1750 specs = future.get();
1751 } catch (RemoteException e) {
1752 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1753 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001754 synchronized (mService.mWindowMap) {
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001755 mNextAppTransitionAnimationsSpecsPending = false;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001756 overridePendingAppTransitionMultiThumb(specs,
1757 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1758 mNextAppTransitionScaleUp);
1759 mNextAppTransitionFutureCallback = null;
Filip Gruszczynski96daf322015-11-18 18:01:27 -08001760 if (specs != null) {
1761 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1762 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001763 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001764 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001765 }
1766 });
1767 }
1768 }
1769
Craig Mautner164d4bb2012-11-26 13:51:23 -08001770 @Override
1771 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001772 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001773 }
1774
Craig Mautner4b71aa12012-12-27 17:20:01 -08001775 /**
1776 * Returns the human readable name of a window transition.
1777 *
1778 * @param transition The window transition.
1779 * @return The transition symbolic name.
1780 */
1781 public static String appTransitionToString(int transition) {
1782 switch (transition) {
1783 case TRANSIT_UNSET: {
1784 return "TRANSIT_UNSET";
1785 }
1786 case TRANSIT_NONE: {
1787 return "TRANSIT_NONE";
1788 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001789 case TRANSIT_ACTIVITY_OPEN: {
1790 return "TRANSIT_ACTIVITY_OPEN";
1791 }
1792 case TRANSIT_ACTIVITY_CLOSE: {
1793 return "TRANSIT_ACTIVITY_CLOSE";
1794 }
1795 case TRANSIT_TASK_OPEN: {
1796 return "TRANSIT_TASK_OPEN";
1797 }
1798 case TRANSIT_TASK_CLOSE: {
1799 return "TRANSIT_TASK_CLOSE";
1800 }
1801 case TRANSIT_TASK_TO_FRONT: {
1802 return "TRANSIT_TASK_TO_FRONT";
1803 }
1804 case TRANSIT_TASK_TO_BACK: {
1805 return "TRANSIT_TASK_TO_BACK";
1806 }
1807 case TRANSIT_WALLPAPER_CLOSE: {
1808 return "TRANSIT_WALLPAPER_CLOSE";
1809 }
1810 case TRANSIT_WALLPAPER_OPEN: {
1811 return "TRANSIT_WALLPAPER_OPEN";
1812 }
1813 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1814 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1815 }
1816 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1817 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1818 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001819 case TRANSIT_TASK_OPEN_BEHIND: {
1820 return "TRANSIT_TASK_OPEN_BEHIND";
1821 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001822 case TRANSIT_ACTIVITY_RELAUNCH: {
1823 return "TRANSIT_ACTIVITY_RELAUNCH";
1824 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001825 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1826 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1827 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001828 default: {
1829 return "<UNKNOWN>";
1830 }
1831 }
1832 }
1833
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001834 private String appStateToString() {
1835 switch (mAppTransitionState) {
1836 case APP_STATE_IDLE:
1837 return "APP_STATE_IDLE";
1838 case APP_STATE_READY:
1839 return "APP_STATE_READY";
1840 case APP_STATE_RUNNING:
1841 return "APP_STATE_RUNNING";
1842 case APP_STATE_TIMEOUT:
1843 return "APP_STATE_TIMEOUT";
1844 default:
1845 return "unknown state=" + mAppTransitionState;
1846 }
1847 }
1848
1849 private String transitTypeToString() {
1850 switch (mNextAppTransitionType) {
1851 case NEXT_TRANSIT_TYPE_NONE:
1852 return "NEXT_TRANSIT_TYPE_NONE";
1853 case NEXT_TRANSIT_TYPE_CUSTOM:
1854 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001855 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1856 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001857 case NEXT_TRANSIT_TYPE_SCALE_UP:
1858 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1859 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1860 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1861 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1862 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001863 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1864 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1865 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1866 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001867 default:
1868 return "unknown type=" + mNextAppTransitionType;
1869 }
1870 }
1871
Craig Mautner164d4bb2012-11-26 13:51:23 -08001872 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001873 public void dump(PrintWriter pw, String prefix) {
1874 pw.print(prefix); pw.println(this);
1875 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001876 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001877 pw.print(prefix); pw.print("mNextAppTransitionType=");
1878 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001879 }
1880 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001881 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001882 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001883 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001884 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001885 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1886 pw.print(" mNextAppTransitionExit=0x");
1887 pw.println(Integer.toHexString(mNextAppTransitionExit));
1888 break;
Winson Chung044d5292014-11-06 11:05:19 -08001889 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001890 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001891 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001892 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001893 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1894 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001895 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001896 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001897 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001898 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001899 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001900 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001901 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001902 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001903 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001904 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001905 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001906 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001907 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1908 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001909 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001910 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1911 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1912 pw.println(mDefaultNextAppTransitionAnimationSpec);
1913 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1914 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001915 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1916 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001917 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001918 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001919 }
1920 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001921 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1922 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001923 }
Chong Zhang60091a92016-07-27 17:52:45 -07001924 if (mLastUsedAppTransition != TRANSIT_NONE) {
1925 pw.print(prefix); pw.print("mLastUsedAppTransition=");
1926 pw.println(appTransitionToString(mLastUsedAppTransition));
1927 pw.print(prefix); pw.print("mLastOpeningApp=");
1928 pw.println(mLastOpeningApp);
1929 pw.print(prefix); pw.print("mLastClosingApp=");
1930 pw.println(mLastClosingApp);
1931 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001932 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001933
1934 public void setCurrentUser(int newUserId) {
1935 mCurrentUserId = newUserId;
1936 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001937
1938 /**
1939 * @return true if transition is not running and should not be skipped, false if transition is
1940 * already running
1941 */
1942 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent) {
1943 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
1944 + " transit=" + appTransitionToString(transit)
1945 + " " + this
1946 + " alwaysKeepCurrent=" + alwaysKeepCurrent
1947 + " Callers=" + Debug.getCallers(3));
1948 if (!isTransitionSet() || mNextAppTransition == TRANSIT_NONE) {
1949 setAppTransition(transit);
1950 } else if (!alwaysKeepCurrent) {
1951 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
1952 // Opening a new task always supersedes a close for the anim.
1953 setAppTransition(transit);
1954 } else if (transit == TRANSIT_ACTIVITY_OPEN
1955 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
1956 // Opening a new activity always supersedes a close for the anim.
1957 setAppTransition(transit);
1958 }
1959 }
1960 boolean prepared = prepare();
1961 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001962 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
1963 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001964 }
1965 return prepared;
1966 }
Winsonb2024762016-04-05 17:32:30 -07001967
1968 /**
Manu Cornetda5900d2017-01-12 15:05:13 -08001969 * @return whether the transition should show the thumbnail being scaled down.
1970 */
1971 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
1972 return isTvUiMode(uiMode)
1973 || mGridLayoutRecentsEnabled
1974 || orientation == Configuration.ORIENTATION_PORTRAIT;
1975 }
1976
1977 /**
Winsonb2024762016-04-05 17:32:30 -07001978 * @return whether the specified {@param uiMode} is the TV mode.
1979 */
1980 private boolean isTvUiMode(int uiMode) {
1981 return (uiMode & Configuration.UI_MODE_TYPE_TELEVISION) > 0;
1982 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001983}