blob: d4d6f3225edd30392261672a97651b49a91a17cc [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;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080060import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080061import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070062import android.util.SparseArray;
63import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010064import android.view.IAppTransitionAnimationSpecsFuture;
Craig Mautner164d4bb2012-11-26 13:51:23 -080065import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080066import android.view.animation.AlphaAnimation;
67import android.view.animation.Animation;
68import android.view.animation.AnimationSet;
69import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070070import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080071import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070072import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080073import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070074import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070075
Craig Mautner164d4bb2012-11-26 13:51:23 -080076import com.android.internal.util.DumpUtils.Dump;
77import com.android.server.AttributeCache;
78import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -080079import com.android.server.wm.animation.ClipRectLRAnimation;
80import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010081import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080082
83import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010084import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010085import java.util.concurrent.ExecutorService;
86import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -080087
Craig Mautner164d4bb2012-11-26 13:51:23 -080088// State management of app transitions. When we are preparing for a
89// transition, mNextAppTransition will be the kind of transition to
90// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
91// mOpeningApps and mClosingApps are the lists of tokens that will be
92// made visible or hidden at the next transition.
93public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080094 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070095 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080096
Craig Mautner4b71aa12012-12-27 17:20:01 -080097 /** Not set up for a transition. */
98 public static final int TRANSIT_UNSET = -1;
99 /** No animation for transition. */
100 public static final int TRANSIT_NONE = 0;
101 /** 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 -0700102 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800103 /** The window in the top-most activity is being closed to reveal the
104 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700105 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800106 /** A window in a new task is being opened on top of an existing one
107 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700108 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800109 /** A window in the top-most activity is being closed to reveal the
110 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700111 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800112 /** A window in an existing task is being displayed on top of an existing one
113 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700114 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800115 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700116 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800117 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
118 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700119 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800120 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
121 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700122 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800123 /** A window in a new activity is being opened on top of an existing one, and both are on top
124 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700125 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800126 /** The window in the top-most activity is being closed to reveal the previous activity, and
127 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700128 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
129 /** A window in a new task is being opened behind an existing one in another activity's task.
130 * The new window will show briefly and then be gone. */
131 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800132 /** A window in a task is being animated in-place. */
133 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700134 /** An activity is being relaunched (e.g. due to configuration change). */
135 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Jorim Jaggi192086e2016-03-11 17:17:03 +0100136 /** A task is being docked from recents. */
137 public static final int TRANSIT_DOCK_TASK_FROM_RECENTS = 19;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800138
Winson Chunga4ccb862014-08-22 15:26:27 -0700139 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700140 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800141 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700142 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800143
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800144 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800145
146 /** Interpolator to be used for animations that respond directly to a touch */
147 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
148 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
149
Jorim Jaggic69bd222016-03-15 14:38:37 +0100150 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
151 new PathInterpolator(0.85f, 0f, 1f, 1f);
152
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800153 /**
154 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
155 * involved, to make it more understandable.
156 */
157 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700158 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700159 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800160
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800161 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800162 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800163
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800164 private int mNextAppTransition = TRANSIT_UNSET;
Chong Zhang60091a92016-07-27 17:52:45 -0700165 private int mLastUsedAppTransition = TRANSIT_UNSET;
166 private String mLastOpeningApp;
167 private String mLastClosingApp;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800168
169 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
170 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
171 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
172 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
173 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700174 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
175 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800176 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800177 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800178 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
179
Winson Chung399f6202014-03-19 10:47:20 -0700180 // These are the possible states for the enter/exit activities during a thumbnail transition
181 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
182 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
183 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
184 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
185
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800186 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800187 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800188 private boolean mNextAppTransitionScaleUp;
189 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100190 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700191 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800192 private int mNextAppTransitionEnter;
193 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800194 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700195
196 // Keyed by task id.
197 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
198 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100199 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
200 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700201 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
202
Winson Chunga4ccb862014-08-22 15:26:27 -0700203 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800204
Winson Chung2820c452014-04-15 15:34:44 -0700205 private Rect mTmpFromClipRect = new Rect();
206 private Rect mTmpToClipRect = new Rect();
207
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700208 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700209
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800210 private final static int APP_STATE_IDLE = 0;
211 private final static int APP_STATE_READY = 1;
212 private final static int APP_STATE_RUNNING = 2;
213 private final static int APP_STATE_TIMEOUT = 3;
214 private int mAppTransitionState = APP_STATE_IDLE;
215
216 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800217 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700218 private final Interpolator mThumbnailFadeInInterpolator;
219 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800220 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700221 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100222 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700223 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
224
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700225 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800226
Amith Yamasani4befbec2013-07-10 16:18:01 -0700227 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800228 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700229
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100230 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100231 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100232
Jorim Jaggif97ed922016-02-18 18:57:07 -0800233 private int mLastClipRevealMaxTranslation;
234 private boolean mLastHadClipReveal;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700235 private boolean mProlongedAnimationsEnded;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800236
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800237 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800238 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800239 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800240 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
241 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700242 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
243 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100244 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
245 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800246 mConfigShortAnimTime = context.getResources().getInteger(
247 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800248 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
249 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700250 mThumbnailFadeInInterpolator = new Interpolator() {
251 @Override
252 public float getInterpolation(float input) {
253 // Linear response for first fraction, then complete after that.
254 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
255 return 0f;
256 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700257 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700258 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700259 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700260 }
261 };
262 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800263 @Override
264 public float getInterpolation(float input) {
265 // Linear response for first fraction, then complete after that.
266 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700267 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
268 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800269 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700270 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800271 }
272 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700273 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
274 * mContext.getResources().getDisplayMetrics().density);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800275 }
276
277 boolean isTransitionSet() {
278 return mNextAppTransition != TRANSIT_UNSET;
279 }
280
Craig Mautner164d4bb2012-11-26 13:51:23 -0800281 boolean isTransitionEqual(int transit) {
282 return mNextAppTransition == transit;
283 }
284
285 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800286 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800287 }
288
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700289 private void setAppTransition(int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800290 mNextAppTransition = transit;
Chong Zhang60091a92016-07-27 17:52:45 -0700291 setLastAppTransition(TRANSIT_UNSET, null, null);
292 }
293
294 void setLastAppTransition(int transit, AppWindowToken openingApp, AppWindowToken closingApp) {
295 mLastUsedAppTransition = transit;
296 mLastOpeningApp = "" + openingApp;
297 mLastClosingApp = "" + closingApp;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800298 }
299
300 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800301 return mAppTransitionState == APP_STATE_READY
302 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800303 }
304
Craig Mautnerae446592012-12-06 19:05:05 -0800305 void setReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800306 mAppTransitionState = APP_STATE_READY;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100307 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800308 }
309
310 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800311 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800312 }
313
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800314 void setIdle() {
315 mAppTransitionState = APP_STATE_IDLE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800316 }
317
318 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800319 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800320 }
321
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800322 void setTimeout() {
323 mAppTransitionState = APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800324 }
325
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700326 Bitmap getAppTransitionThumbnailHeader(int taskId) {
327 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800328 if (spec == null) {
329 spec = mDefaultNextAppTransitionAnimationSpec;
330 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700331 return spec != null ? spec.bitmap : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800332 }
333
Winson Chunga4ccb862014-08-22 15:26:27 -0700334 /** Returns whether the next thumbnail transition is aspect scaled up. */
335 boolean isNextThumbnailTransitionAspectScaled() {
336 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
337 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
338 }
339
340 /** Returns whether the next thumbnail transition is scaling up. */
341 boolean isNextThumbnailTransitionScaleUp() {
342 return mNextAppTransitionScaleUp;
343 }
344
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800345 boolean isNextAppTransitionThumbnailUp() {
346 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
347 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
348 }
349
350 boolean isNextAppTransitionThumbnailDown() {
351 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
352 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
353 }
354
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100355 /**
356 * @return true if and only if we are currently fetching app transition specs from the future
357 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
358 */
359 boolean isFetchingAppTransitionsSpecs() {
360 return mNextAppTransitionAnimationsSpecsPending;
361 }
362
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700363 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800364 if (!isRunning()) {
365 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100366 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800367 mLastHadClipReveal = false;
368 mLastClipRevealMaxTranslation = 0;
369 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700370 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800371 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700372 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800373 }
374
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800375 void goodToGo(AppWindowAnimator topOpeningAppAnimator, AppWindowAnimator topClosingAppAnimator,
376 ArraySet<AppWindowToken> openingApps, ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800377 mNextAppTransition = TRANSIT_UNSET;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800378 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100379 notifyAppTransitionStartingLocked(
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800380 topOpeningAppAnimator != null ? topOpeningAppAnimator.mAppToken.token : null,
381 topClosingAppAnimator != null ? topClosingAppAnimator.mAppToken.token : null,
382 topOpeningAppAnimator != null ? topOpeningAppAnimator.animation : null,
383 topClosingAppAnimator != null ? topClosingAppAnimator.animation : null);
384 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700385 .notifyAppTransitionStarting();
Jorim Jaggi363ab982016-04-26 19:51:20 -0700386
387 // Prolong the start for the transition when docking a task from recents, unless recents
388 // ended it already then we don't need to wait.
389 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS && !mProlongedAnimationsEnded) {
390 for (int i = openingApps.size() - 1; i >= 0; i--) {
391 final AppWindowAnimator appAnimator = openingApps.valueAt(i).mAppAnimator;
392 appAnimator.startProlongAnimation(PROLONG_ANIMATION_AT_START);
393 }
394 }
395 }
396
397 /**
398 * Let the transitions manager know that the somebody wanted to end the prolonged animations.
399 */
400 void notifyProlongedAnimationsEnded() {
401 mProlongedAnimationsEnded = true;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800402 }
403
404 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800405 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800406 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700407 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi65193992015-11-23 16:49:59 -0800408 mNextAppTransitionAnimationsSpecsFuture = null;
409 mDefaultNextAppTransitionAnimationSpec = null;
410 mAnimationFinishedCallback = null;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700411 mProlongedAnimationsEnded = false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800412 }
413
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800414 void freeze() {
415 setAppTransition(AppTransition.TRANSIT_UNSET);
416 clear();
417 setReady();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100418 notifyAppTransitionCancelledLocked();
419 }
420
421 void registerListenerLocked(AppTransitionListener listener) {
422 mListeners.add(listener);
423 }
424
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700425 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100426 for (int i = 0; i < mListeners.size(); i++) {
427 mListeners.get(i).onAppTransitionFinishedLocked(token);
428 }
429 }
430
431 private void notifyAppTransitionPendingLocked() {
432 for (int i = 0; i < mListeners.size(); i++) {
433 mListeners.get(i).onAppTransitionPendingLocked();
434 }
435 }
436
437 private void notifyAppTransitionCancelledLocked() {
438 for (int i = 0; i < mListeners.size(); i++) {
439 mListeners.get(i).onAppTransitionCancelledLocked();
440 }
441 }
442
443 private void notifyAppTransitionStartingLocked(IBinder openToken,
444 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
445 for (int i = 0; i < mListeners.size(); i++) {
446 mListeners.get(i).onAppTransitionStartingLocked(openToken, closeToken, openAnimation,
447 closeAnimation);
448 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800449 }
450
Craig Mautner164d4bb2012-11-26 13:51:23 -0800451 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
452 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
453 + (lp != null ? lp.packageName : null)
454 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
455 if (lp != null && lp.windowAnimations != 0) {
456 // If this is a system resource, don't try to load it from the
457 // application resources. It is nice to avoid loading application
458 // resources if we can.
459 String packageName = lp.packageName != null ? lp.packageName : "android";
460 int resId = lp.windowAnimations;
461 if ((resId&0xFF000000) == 0x01000000) {
462 packageName = "android";
463 }
464 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
465 + packageName);
466 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700467 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800468 }
469 return null;
470 }
471
472 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
473 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
474 + packageName + " resId=0x" + Integer.toHexString(resId));
475 if (packageName != null) {
476 if ((resId&0xFF000000) == 0x01000000) {
477 packageName = "android";
478 }
479 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
480 + packageName);
481 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700482 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800483 }
484 return null;
485 }
486
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700487 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800488 int anim = 0;
489 Context context = mContext;
490 if (animAttr >= 0) {
491 AttributeCache.Entry ent = getCachedAnimations(lp);
492 if (ent != null) {
493 context = ent.context;
494 anim = ent.array.getResourceId(animAttr, 0);
495 }
496 }
497 if (anim != 0) {
498 return AnimationUtils.loadAnimation(context, anim);
499 }
500 return null;
501 }
502
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700503 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
504 Context context = mContext;
505 if (resId >= 0) {
506 AttributeCache.Entry ent = getCachedAnimations(lp);
507 if (ent != null) {
508 context = ent.context;
509 }
510 return AnimationUtils.loadAnimation(context, resId);
511 }
512 return null;
513 }
514
515 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800516 int anim = 0;
517 Context context = mContext;
518 if (resId >= 0) {
519 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
520 if (ent != null) {
521 context = ent.context;
522 anim = resId;
523 }
524 }
525 if (anim != 0) {
526 return AnimationUtils.loadAnimation(context, anim);
527 }
528 return null;
529 }
530
Craig Mautner164d4bb2012-11-26 13:51:23 -0800531 /**
532 * Compute the pivot point for an animation that is scaling from a small
533 * rect on screen to a larger rect. The pivot point varies depending on
534 * the distance between the inner and outer edges on both sides. This
535 * function computes the pivot point for one dimension.
536 * @param startPos Offset from left/top edge of outer rectangle to
537 * left/top edge of inner rectangle.
538 * @param finalScale The scaling factor between the size of the outer
539 * and inner rectangles.
540 */
541 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800542
543 /*
544 Theorem of intercepting lines:
545
546 + + +-----------------------------------------------+
547 | | | |
548 | | | |
549 | | | |
550 | | | |
551 x | y | | |
552 | | | |
553 | | | |
554 | | | |
555 | | | |
556 | + | +--------------------+ |
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 p ++
594
595 scale = (x - y) / x
596 <=> x = -y / (scale - 1)
597 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800598 final float denom = finalScale-1;
599 if (Math.abs(denom) < .0001f) {
600 return startPos;
601 }
602 return -startPos / denom;
603 }
604
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700605 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
606 Rect containingFrame) {
607 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700608 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700609 final int appWidth = containingFrame.width();
610 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800611 if (enter) {
612 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700613 float scaleW = mTmpRect.width() / (float) appWidth;
614 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800615 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700616 computePivot(mTmpRect.left, scaleW),
Winson4c3fecd2016-07-13 12:29:48 -0700617 computePivot(mTmpRect.top, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800618 scale.setInterpolator(mDecelerateInterpolator);
619
Craig Mautner164d4bb2012-11-26 13:51:23 -0800620 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700621 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800622
623 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800624 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800625 set.addAnimation(alpha);
626 set.setDetachWallpaper(true);
627 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800628 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
629 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800630 // If we are on top of the wallpaper, we need an animation that
631 // correctly handles the wallpaper staying static behind all of
632 // the animated elements. To do this, will just have the existing
633 // element fade out.
634 a = new AlphaAnimation(1, 0);
635 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800636 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800637 // For normal animations, the exiting element just holds in place.
638 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800639 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800640
641 // Pick the desired duration. If this is an inter-activity transition,
642 // it is the standard duration for that. Otherwise we use the longer
643 // task transition duration.
644 final long duration;
645 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800646 case TRANSIT_ACTIVITY_OPEN:
647 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800648 duration = mConfigShortAnimTime;
649 break;
650 default:
651 duration = DEFAULT_APP_TRANSITION_DURATION;
652 break;
653 }
654 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800655 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800656 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800657 a.initialize(appWidth, appHeight, appWidth, appHeight);
658 return a;
659 }
660
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700661 private void getDefaultNextAppTransitionStartRect(Rect rect) {
662 if (mDefaultNextAppTransitionAnimationSpec == null ||
663 mDefaultNextAppTransitionAnimationSpec.rect == null) {
664 Slog.wtf(TAG, "Starting rect for app requested, but none available", new Throwable());
665 rect.setEmpty();
666 } else {
667 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
668 }
669 }
670
671 void getNextAppTransitionStartRect(int taskId, Rect rect) {
672 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800673 if (spec == null) {
674 spec = mDefaultNextAppTransitionAnimationSpec;
675 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700676 if (spec == null || spec.rect == null) {
677 Slog.wtf(TAG, "Starting rect for task: " + taskId + " requested, but not available",
678 new Throwable());
679 rect.setEmpty();
680 } else {
681 rect.set(spec.rect);
682 }
683 }
684
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800685 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
686 Bitmap bitmap) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700687 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800688 bitmap, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700689 }
690
Jorim Jaggif97ed922016-02-18 18:57:07 -0800691 /**
692 * @return the duration of the last clip reveal animation
693 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800694 long getLastClipRevealTransitionDuration() {
695 return mLastClipRevealTransitionDuration;
696 }
697
698 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800699 * @return the maximum distance the app surface is traveling of the last clip reveal animation
700 */
701 int getLastClipRevealMaxTranslation() {
702 return mLastClipRevealMaxTranslation;
703 }
704
705 /**
706 * @return true if in the last app transition had a clip reveal animation, false otherwise
707 */
708 boolean hadClipRevealAnimation() {
709 return mLastHadClipReveal;
710 }
711
712 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800713 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
714 * the start rect is outside of the target rect, and there is a lot of movement going on.
715 *
716 * @param cutOff whether the start rect was not fully contained by the end rect
717 * @param translationX the total translation the surface moves in x direction
718 * @param translationY the total translation the surfaces moves in y direction
719 * @param displayFrame our display frame
720 *
721 * @return the duration of the clip reveal animation, in milliseconds
722 */
723 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
724 float translationY, Rect displayFrame) {
725 if (!cutOff) {
726 return DEFAULT_APP_TRANSITION_DURATION;
727 }
728 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
729 Math.abs(translationY) / displayFrame.height());
730 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
731 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
732 }
733
734 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
735 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800736 final Animation anim;
737 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700738 final int appWidth = appFrame.width();
739 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800740
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700741 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700742 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700743 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700744
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700745 float t = 0f;
746 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800747 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700748 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800749 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
750 int translationX = 0;
751 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700752 int centerX = mTmpRect.centerX();
753 int centerY = mTmpRect.centerY();
754 int halfWidth = mTmpRect.width() / 2;
755 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800756 int clipStartX = centerX - halfWidth - appFrame.left;
757 int clipStartY = centerY - halfHeight - appFrame.top;
758 boolean cutOff = false;
759
760 // If the starting rectangle is fully or partially outside of the target rectangle, we
761 // need to start the clipping at the edge and then achieve the rest with translation
762 // and extending the clip rect from that edge.
763 if (appFrame.top > centerY - halfHeight) {
764 translationY = (centerY - halfHeight) - appFrame.top;
765 translationYCorrection = 0;
766 clipStartY = 0;
767 cutOff = true;
768 }
769 if (appFrame.left > centerX - halfWidth) {
770 translationX = (centerX - halfWidth) - appFrame.left;
771 clipStartX = 0;
772 cutOff = true;
773 }
774 if (appFrame.right < centerX + halfWidth) {
775 translationX = (centerX + halfWidth) - appFrame.right;
776 clipStartX = appWidth - mTmpRect.width();
777 cutOff = true;
778 }
779 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
780 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700781
782 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800783 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800784 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700785 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800786 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700787
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800788 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
789 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
790 : mLinearOutSlowInInterpolator);
791 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800792
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800793 Animation clipAnimTB = new ClipRectTBAnimation(
794 clipStartY, clipStartY + mTmpRect.height(),
795 0, appHeight,
796 translationYCorrection, 0,
797 mLinearOutSlowInInterpolator);
798 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
799 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800800
801 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800802 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700803 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800804 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700805 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800806
807 AnimationSet set = new AnimationSet(false);
808 set.addAnimation(clipAnimLR);
809 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700810 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800811 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700812 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800813 set.initialize(appWidth, appHeight, appWidth, appHeight);
814 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800815 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800816 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800817
818 // If the start rect was full inside the target rect (cutOff == false), we don't need
819 // to store the translation, because it's only used if cutOff == true.
820 mLastClipRevealMaxTranslation = cutOff
821 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800822 } else {
823 final long duration;
824 switch (transit) {
825 case TRANSIT_ACTIVITY_OPEN:
826 case TRANSIT_ACTIVITY_CLOSE:
827 duration = mConfigShortAnimTime;
828 break;
829 default:
830 duration = DEFAULT_APP_TRANSITION_DURATION;
831 break;
832 }
833 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
834 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
835 // If we are on top of the wallpaper, we need an animation that
836 // correctly handles the wallpaper staying static behind all of
837 // the animated elements. To do this, will just have the existing
838 // element fade out.
839 anim = new AlphaAnimation(1, 0);
840 anim.setDetachWallpaper(true);
841 } else {
842 // For normal animations, the exiting element just holds in place.
843 anim = new AlphaAnimation(1, 1);
844 }
845 anim.setInterpolator(mDecelerateInterpolator);
846 anim.setDuration(duration);
847 anim.setFillAfter(true);
848 }
849 return anim;
850 }
851
Winson Chung399f6202014-03-19 10:47:20 -0700852 /**
853 * Prepares the specified animation with a standard duration, interpolator, etc.
854 */
Winson Chung5393dff2014-05-08 14:25:43 -0700855 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100856 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700857 if (duration > 0) {
858 a.setDuration(duration);
859 }
Winson Chung5393dff2014-05-08 14:25:43 -0700860 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100861 if (interpolator != null) {
862 a.setInterpolator(interpolator);
863 }
Winson Chung5393dff2014-05-08 14:25:43 -0700864 a.initialize(appWidth, appHeight, appWidth, appHeight);
865 return a;
866 }
867
868 /**
869 * Prepares the specified animation with a standard duration, interpolator, etc.
870 */
Winson Chung399f6202014-03-19 10:47:20 -0700871 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800872 // Pick the desired duration. If this is an inter-activity transition,
873 // it is the standard duration for that. Otherwise we use the longer
874 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700875 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800876 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800877 case TRANSIT_ACTIVITY_OPEN:
878 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800879 duration = mConfigShortAnimTime;
880 break;
881 default:
882 duration = DEFAULT_APP_TRANSITION_DURATION;
883 break;
884 }
Winson Chung5393dff2014-05-08 14:25:43 -0700885 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
886 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800887 }
888
Winson Chung399f6202014-03-19 10:47:20 -0700889 /**
890 * Return the current thumbnail transition state.
891 */
892 int getThumbnailTransitionState(boolean enter) {
893 if (enter) {
894 if (mNextAppTransitionScaleUp) {
895 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
896 } else {
897 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
898 }
899 } else {
900 if (mNextAppTransitionScaleUp) {
901 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
902 } else {
903 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
904 }
905 }
906 }
907
908 /**
909 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700910 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700911 */
Jorim Jaggide63d442016-03-14 14:56:56 +0100912 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winsonb2024762016-04-05 17:32:30 -0700913 Bitmap thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -0700914 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700915 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700916 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700917 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700918 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700919
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700920 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700921 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -0700922 final float fromX;
923 final float fromY;
924 final float toX;
925 final float toY;
926 final float pivotX;
927 final float pivotY;
Winsonb2024762016-04-05 17:32:30 -0700928 if (isTvUiMode(uiMode) || orientation == Configuration.ORIENTATION_PORTRAIT) {
Jorim Jaggi09072002016-03-25 16:48:42 -0700929 fromX = mTmpRect.left;
930 fromY = mTmpRect.top;
931
932 // For the curved translate animation to work, the pivot points needs to be at the
933 // same absolute position as the one from the real surface.
934 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
935 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
936 pivotX = mTmpRect.width() / 2;
937 pivotY = appRect.height() / 2 / scaleW;
938 } else {
939 pivotX = 0;
940 pivotY = 0;
941 fromX = mTmpRect.left;
942 fromY = mTmpRect.top;
943 toX = appRect.left;
944 toY = appRect.top;
945 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100946 final long duration = getAspectScaleDuration();
947 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -0700948 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700949 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +0100950 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100951 scale.setInterpolator(interpolator);
952 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800953 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100954 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
955 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
956 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
957 ? duration / 2
958 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100959 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
960 translate.setInterpolator(interpolator);
961 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -0700962
Jorim Jaggide63d442016-03-14 14:56:56 +0100963 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
964 mTmpToClipRect.set(appRect);
965
966 // Containing frame is in screen space, but we need the clip rect in the
967 // app space.
968 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100969 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
970 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +0100971
972 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +0100973 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
974 (int) (-contentInsets.top * scaleW),
975 (int) (-contentInsets.right * scaleW),
976 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +0100977 }
978
979 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100980 clipAnim.setInterpolator(interpolator);
981 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +0100982
Winson Chung399f6202014-03-19 10:47:20 -0700983 // This AnimationSet uses the Interpolators assigned above.
984 AnimationSet set = new AnimationSet(false);
985 set.addAnimation(scale);
986 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -0700987 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +0100988 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -0700989 a = set;
990 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700991 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +0100992 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100993 scale.setInterpolator(interpolator);
994 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -0700995 Animation alpha = new AlphaAnimation(0f, 1f);
996 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100997 alpha.setDuration(duration);
998 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
999 translate.setInterpolator(interpolator);
1000 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001001
Winson Chunga4ccb862014-08-22 15:26:27 -07001002 // This AnimationSet uses the Interpolators assigned above.
1003 AnimationSet set = new AnimationSet(false);
1004 set.addAnimation(scale);
1005 set.addAnimation(alpha);
1006 set.addAnimation(translate);
1007 a = set;
1008
1009 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001010 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001011 null);
Winson Chung399f6202014-03-19 10:47:20 -07001012 }
1013
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001014 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1015
1016 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001017 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001018 return new TranslateAnimation(fromX, toX, fromY, toY);
1019 } else {
1020 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1021 return new CurvedTranslateAnimation(path);
1022 }
1023 }
1024
1025 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1026 final Path path = new Path();
1027 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001028
1029 if (fromY > toY) {
1030 // If the object needs to go up, move it in horizontal direction first, then vertical.
1031 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1032 } else {
1033 // If the object needs to go down, move it in vertical direction first, then horizontal.
1034 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1035 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001036 return path;
1037 }
1038
1039 private long getAspectScaleDuration() {
1040 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001041 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001042 } else {
1043 return THUMBNAIL_APP_TRANSITION_DURATION;
1044 }
1045 }
1046
1047 private Interpolator getAspectScaleInterpolator() {
1048 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1049 return mFastOutSlowInInterpolator;
1050 } else {
1051 return TOUCH_RESPONSE_INTERPOLATOR;
1052 }
1053 }
1054
Winson Chung399f6202014-03-19 10:47:20 -07001055 /**
1056 * This alternate animation is created when we are doing a thumbnail transition, for the
1057 * activity that is leaving, and the activity that is entering.
1058 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001059 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001060 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001061 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001062 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001063 final int appWidth = containingFrame.width();
1064 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001065 getDefaultNextAppTransitionStartRect(mTmpRect);
1066 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001067 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001068 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001069 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001070 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001071 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001072
1073 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001074 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1075 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1076 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1077 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001078 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001079 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001080 } else if (freeform) {
1081 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1082 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001083 } else {
Winson21700932016-03-24 17:26:23 -07001084 AnimationSet set = new AnimationSet(true);
1085
1086 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001087 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001088 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001089
1090 // Containing frame is in screen space, but we need the clip rect in the
1091 // app space.
1092 mTmpFromClipRect.offsetTo(0, 0);
1093 mTmpToClipRect.offsetTo(0, 0);
1094
1095 // Exclude insets region from the source clip.
1096 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001097 mNextAppTransitionInsets.set(contentInsets);
1098
Winsonb2024762016-04-05 17:32:30 -07001099 if (isTvUiMode(uiMode) || orientation == Configuration.ORIENTATION_PORTRAIT) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001100 // We scale the width and clip to the top/left square
1101 float scale = thumbWidth /
1102 (appWidth - contentInsets.left - contentInsets.right);
1103 int unscaledThumbHeight = (int) (thumbHeight / scale);
1104 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1105
1106 mNextAppTransitionInsets.set(contentInsets);
1107
Jorim Jaggi8448f332016-03-14 17:50:37 +01001108 Animation scaleAnim = new ScaleAnimation(
1109 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1110 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001111 containingFrame.width() / 2f,
1112 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001113 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001114 final float x = containingFrame.width() / 2f
1115 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001116 final float targetY = (mTmpRect.top - containingFrame.top);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001117 final float y = containingFrame.height() / 2f
1118 - containingFrame.height() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001119 final float startX = targetX - x;
1120 final float startY = targetY - y;
1121 Animation clipAnim = scaleUp
1122 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1123 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1124 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001125 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1126 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1127
Winson21700932016-03-24 17:26:23 -07001128 set.addAnimation(clipAnim);
1129 set.addAnimation(scaleAnim);
1130 set.addAnimation(translateAnim);
1131
1132 } else {
1133 // In landscape, we don't scale at all and only crop
1134 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1135 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1136
Jorim Jaggi8448f332016-03-14 17:50:37 +01001137 Animation clipAnim = scaleUp
1138 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1139 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1140 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001141 ? createCurvedMotion(thumbStartX, 0,
1142 thumbStartY - contentInsets.top, 0)
1143 : createCurvedMotion(0, thumbStartX, 0,
1144 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001145
1146 set.addAnimation(clipAnim);
1147 set.addAnimation(translateAnim);
1148 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001149 a = set;
Winson21700932016-03-24 17:26:23 -07001150 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001151 }
Winson Chung399f6202014-03-19 10:47:20 -07001152 break;
1153 }
1154 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001155 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001156 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001157 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001158 // activity.
1159 a = new AlphaAnimation(1, 0);
1160 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001161 a = new AlphaAnimation(1, 1);
1162 }
1163 break;
1164 }
1165 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001166 // Target app window during the scale down
1167 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1168 // Fade in the destination activity if we are animating from a wallpaper
1169 // activity.
1170 a = new AlphaAnimation(0, 1);
1171 } else {
1172 a = new AlphaAnimation(1, 1);
1173 }
Winson Chung399f6202014-03-19 10:47:20 -07001174 break;
1175 }
Winson Chung399f6202014-03-19 10:47:20 -07001176 default:
1177 throw new RuntimeException("Invalid thumbnail transition state");
1178 }
1179
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001180 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1181 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001182 }
1183
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001184 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1185 @Nullable Rect surfaceInsets, int taskId) {
1186 getNextAppTransitionStartRect(taskId, mTmpRect);
1187 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1188 true);
1189 }
1190
1191 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1192 @Nullable Rect surfaceInsets, int taskId) {
1193 getNextAppTransitionStartRect(taskId, mTmpRect);
1194 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1195 false);
1196 }
1197
1198 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1199 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1200 final float sourceWidth = sourceFrame.width();
1201 final float sourceHeight = sourceFrame.height();
1202 final float destWidth = destFrame.width();
1203 final float destHeight = destFrame.height();
1204 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1205 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001206 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001207 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001208 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001209 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001210 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1211 // We want the scaling to happen from the center of the surface. In order to achieve that,
1212 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001213 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1214 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1215 final ScaleAnimation scale = enter ?
1216 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1217 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1218 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1219 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1220 final int destHCenter = destFrame.left + destFrame.width() / 2;
1221 final int destVCenter = destFrame.top + destFrame.height() / 2;
1222 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1223 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1224 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1225 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001226 set.addAnimation(scale);
1227 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001228
1229 final IRemoteCallback callback = mAnimationFinishedCallback;
1230 if (callback != null) {
1231 set.setAnimationListener(new Animation.AnimationListener() {
1232 @Override
1233 public void onAnimationStart(Animation animation) { }
1234
1235 @Override
1236 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001237 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001238 }
1239
1240 @Override
1241 public void onAnimationRepeat(Animation animation) { }
1242 });
1243 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001244 return set;
1245 }
1246
Winson Chung399f6202014-03-19 10:47:20 -07001247 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001248 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001249 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001250 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001251 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
1252 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001253 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001254 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001255 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001256 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001257 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001258 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1259
1260 if (mNextAppTransitionScaleUp) {
1261 // Animation for the thumbnail zooming from its initial size to the full screen
1262 float scaleW = appWidth / thumbWidth;
1263 float scaleH = appHeight / thumbHeight;
1264 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001265 computePivot(mTmpRect.left, 1 / scaleW),
1266 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001267 scale.setInterpolator(mDecelerateInterpolator);
1268
1269 Animation alpha = new AlphaAnimation(1, 0);
1270 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1271
1272 // This AnimationSet uses the Interpolators assigned above.
1273 AnimationSet set = new AnimationSet(false);
1274 set.addAnimation(scale);
1275 set.addAnimation(alpha);
1276 a = set;
1277 } else {
1278 // Animation for the thumbnail zooming down from the full screen to its final size
1279 float scaleW = appWidth / thumbWidth;
1280 float scaleH = appHeight / thumbHeight;
1281 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001282 computePivot(mTmpRect.left, 1 / scaleW),
1283 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001284 }
1285
1286 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1287 }
1288
1289 /**
Winson Chung399f6202014-03-19 10:47:20 -07001290 * This animation is created when we are doing a thumbnail transition, for the activity that is
1291 * leaving, and the activity that is entering.
1292 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001293 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1294 int transit, int taskId) {
1295 final int appWidth = containingFrame.width();
1296 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001297 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001298 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001299 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001300 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001301 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001302 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001303 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1304
1305 switch (thumbTransitState) {
1306 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1307 // Entering app scales up with the thumbnail
1308 float scaleW = thumbWidth / appWidth;
1309 float scaleH = thumbHeight / appHeight;
1310 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001311 computePivot(mTmpRect.left, scaleW),
1312 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001313 break;
1314 }
1315 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1316 // Exiting app while the thumbnail is scaling up should fade or stay in place
1317 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1318 // Fade out while bringing up selected activity. This keeps the
1319 // current activity from showing through a launching wallpaper
1320 // activity.
1321 a = new AlphaAnimation(1, 0);
1322 } else {
1323 // noop animation
1324 a = new AlphaAnimation(1, 1);
1325 }
1326 break;
1327 }
1328 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1329 // Entering the other app, it should just be visible while we scale the thumbnail
1330 // down above it
1331 a = new AlphaAnimation(1, 1);
1332 break;
1333 }
1334 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1335 // Exiting the current app, the app should scale down with the thumbnail
1336 float scaleW = thumbWidth / appWidth;
1337 float scaleH = thumbHeight / appHeight;
1338 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001339 computePivot(mTmpRect.left, scaleW),
1340 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001341
1342 Animation alpha = new AlphaAnimation(1, 0);
1343
1344 AnimationSet set = new AnimationSet(true);
1345 set.addAnimation(scale);
1346 set.addAnimation(alpha);
1347 set.setZAdjustment(Animation.ZORDER_TOP);
1348 a = set;
1349 break;
1350 }
1351 default:
1352 throw new RuntimeException("Invalid thumbnail transition state");
1353 }
1354
1355 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1356 }
1357
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001358 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001359 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1360 final int left = mTmpFromClipRect.left;
1361 final int top = mTmpFromClipRect.top;
1362 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001363 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1364 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001365 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001366 float fromWidth = mTmpFromClipRect.width();
1367 float toWidth = mTmpToClipRect.width();
1368 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001369 // While the window might span the whole display, the actual content will be cropped to the
1370 // system decoration frame, for example when the window is docked. We need to take into
1371 // account the visible height when constructing the animation.
1372 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1373 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001374 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1375 // The final window is larger in both dimensions than current window (e.g. we are
1376 // maximizing), so we can simply unclip the new window and there will be no disappearing
1377 // frame.
1378 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1379 } else {
1380 // The disappearing window has one larger dimension. We need to apply scaling, so the
1381 // first frame of the entry animation matches the old window.
1382 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001383 // We might not be going exactly full screen, but instead be aligned under the status
1384 // bar using cropping. We still need to account for the cropped part, which will also
1385 // be scaled.
1386 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001387 }
1388
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001389 // We animate the translation from the old position of the removed window, to the new
1390 // position of the added window. The latter might not be full screen, for example docked for
1391 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001392 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001393 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001394 set.addAnimation(translate);
1395 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001396 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001397 return set;
1398 }
1399
Jorim Jaggic554b772015-06-04 16:07:57 -07001400 /**
1401 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1402 * frame of the transition doesn't change the visuals on screen, so we can start
1403 * directly with the second one
1404 */
1405 boolean canSkipFirstFrame() {
1406 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1407 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
1408 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1409 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001410
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001411 /**
1412 *
1413 * @param frame These are the bounds of the window when it finishes the animation. This is where
1414 * the animation must usually finish in entrance animation, as the next frame will
1415 * display the window at these coordinates. In case of exit animation, this is
1416 * where the animation must start, as the frame before the animation is displaying
1417 * the window at these bounds.
1418 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1419 * window might be obscured, usually by the system windows (status bar and
1420 * navigation bar) and we use content insets to convey that information. This
1421 * usually affects the animation aspects vertically, as the system decoration is
1422 * at the top and the bottom. For example when we animate from full screen to
1423 * recents, we want to exclude the covered parts, because they won't match the
1424 * thumbnail after the last frame is executed.
1425 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1426 * know about this to make the animation frames match. We currently use
1427 * this for freeform windows, which have larger surfaces to display
1428 * shadows. When we animate them from recents, we want to match the content
1429 * to the recents thumbnail and hence need to account for the surface being
1430 * bigger.
1431 */
Winsonb2024762016-04-05 17:32:30 -07001432 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001433 int orientation, Rect frame, Rect displayFrame, Rect insets,
1434 @Nullable Rect surfaceInsets, boolean isVoiceInteraction, boolean freeform,
1435 int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001436 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001437 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
1438 || transit == TRANSIT_TASK_OPEN
1439 || transit == TRANSIT_TASK_TO_FRONT)) {
1440 a = loadAnimationRes(lp, enter
1441 ? com.android.internal.R.anim.voice_activity_open_enter
1442 : com.android.internal.R.anim.voice_activity_open_exit);
1443 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1444 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001445 + " anim=" + a + " transit=" + appTransitionToString(transit)
1446 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001447 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1448 || transit == TRANSIT_TASK_CLOSE
1449 || transit == TRANSIT_TASK_TO_BACK)) {
1450 a = loadAnimationRes(lp, enter
1451 ? com.android.internal.R.anim.voice_activity_close_enter
1452 : com.android.internal.R.anim.voice_activity_close_exit);
1453 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1454 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001455 + " anim=" + a + " transit=" + appTransitionToString(transit)
1456 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001457 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001458 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001459 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1460 "applyAnimation:"
1461 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1462 + " transit=" + appTransitionToString(transit)
1463 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001464 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1465 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001466 mNextAppTransitionEnter : mNextAppTransitionExit);
1467 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1468 "applyAnimation:"
1469 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001470 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001471 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001472 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1473 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1474 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1475 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001476 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1477 + " transit=" + appTransitionToString(transit)
1478 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001479 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001480 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001481 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1482 "applyAnimation:"
1483 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001484 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001485 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001486 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001487 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001488 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1489 "applyAnimation:"
1490 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001491 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001492 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001493 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1494 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001495 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001496 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001497 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001498 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001499 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1500 String animName = mNextAppTransitionScaleUp ?
1501 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1502 Slog.v(TAG, "applyAnimation:"
1503 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001504 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001505 + " Callers=" + Debug.getCallers(3));
1506 }
1507 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1508 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1509 mNextAppTransitionScaleUp =
1510 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1511 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001512 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001513 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001514 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1515 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001516 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001517 Slog.v(TAG, "applyAnimation:"
1518 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001519 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001520 + " Callers=" + Debug.getCallers(3));
1521 }
1522 } else {
1523 int animAttr = 0;
1524 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001525 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001526 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001527 ? WindowAnimation_activityOpenEnterAnimation
1528 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001529 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001530 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001531 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001532 ? WindowAnimation_activityCloseEnterAnimation
1533 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001534 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001535 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001536 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001537 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001538 ? WindowAnimation_taskOpenEnterAnimation
1539 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001540 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001541 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001542 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001543 ? WindowAnimation_taskCloseEnterAnimation
1544 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001545 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001546 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001547 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001548 ? WindowAnimation_taskToFrontEnterAnimation
1549 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001550 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001551 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001552 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001553 ? WindowAnimation_taskToBackEnterAnimation
1554 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001555 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001556 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001557 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001558 ? WindowAnimation_wallpaperOpenEnterAnimation
1559 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001560 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001561 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001562 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001563 ? WindowAnimation_wallpaperCloseEnterAnimation
1564 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001565 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001566 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001567 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001568 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1569 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001570 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001571 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001572 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001573 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1574 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001575 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001576 case TRANSIT_TASK_OPEN_BEHIND:
1577 animAttr = enter
1578 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001579 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001580 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001581 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001582 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1583 "applyAnimation:"
1584 + " anim=" + a
1585 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001586 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001587 + " Callers=" + Debug.getCallers(3));
1588 }
1589 return a;
1590 }
1591
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001592 int getAppStackClipMode() {
1593 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001594 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001595 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001596 ? STACK_CLIP_NONE
1597 : STACK_CLIP_AFTER_ANIM;
1598 }
1599
Craig Mautner164d4bb2012-11-26 13:51:23 -08001600 void postAnimationCallback() {
1601 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001602 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1603 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001604 mNextAppTransitionCallback = null;
1605 }
1606 }
1607
1608 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001609 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001610 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001611 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001612 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001613 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001614 mNextAppTransitionEnter = enterAnim;
1615 mNextAppTransitionExit = exitAnim;
1616 postAnimationCallback();
1617 mNextAppTransitionCallback = startedCallback;
1618 } else {
1619 postAnimationCallback();
1620 }
1621 }
1622
1623 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001624 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001625 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001626 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001627 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001628 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001629 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001630 }
1631 }
1632
Chet Haase10e23ab2015-02-11 15:08:38 -08001633 void overridePendingAppTransitionClipReveal(int startX, int startY,
1634 int startWidth, int startHeight) {
1635 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001636 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001637 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001638 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001639 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001640 }
1641 }
1642
Craig Mautner164d4bb2012-11-26 13:51:23 -08001643 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1644 IRemoteCallback startedCallback, boolean scaleUp) {
1645 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001646 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001647 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1648 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001649 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001650 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001651 postAnimationCallback();
1652 mNextAppTransitionCallback = startedCallback;
1653 } else {
1654 postAnimationCallback();
1655 }
1656 }
1657
Winson Chunga4ccb862014-08-22 15:26:27 -07001658 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001659 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001660 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001661 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001662 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1663 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001664 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001665 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1666 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001667 postAnimationCallback();
1668 mNextAppTransitionCallback = startedCallback;
1669 } else {
1670 postAnimationCallback();
1671 }
1672 }
1673
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001674 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001675 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1676 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001677 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001678 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001679 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1680 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001681 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001682 if (specs != null) {
1683 for (int i = 0; i < specs.length; i++) {
1684 AppTransitionAnimationSpec spec = specs[i];
1685 if (spec != null) {
1686 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1687 if (i == 0) {
1688 // In full screen mode, the transition code depends on the default spec
1689 // to be set.
1690 Rect rect = spec.rect;
1691 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Filip Gruszczynskie3264d82015-11-20 17:10:04 -08001692 rect.width(), rect.height(), spec.bitmap);
Jorim Jaggi43102412015-11-11 16:28:37 +01001693 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001694 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001695 }
1696 }
1697 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001698 mNextAppTransitionCallback = onAnimationStartedCallback;
1699 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001700 } else {
1701 postAnimationCallback();
1702 }
1703 }
1704
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001705 void overridePendingAppTransitionMultiThumbFuture(
1706 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1707 boolean scaleUp) {
1708 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001709 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001710 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1711 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001712 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1713 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001714 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001715 }
1716 }
1717
Winson Chung044d5292014-11-06 11:05:19 -08001718 void overrideInPlaceAppTransition(String packageName, int anim) {
1719 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001720 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001721 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1722 mNextAppTransitionPackage = packageName;
1723 mNextAppTransitionInPlace = anim;
1724 } else {
1725 postAnimationCallback();
1726 }
1727 }
1728
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001729 /**
1730 * If a future is set for the app transition specs, fetch it in another thread.
1731 */
1732 private void fetchAppTransitionSpecsFromFuture() {
1733 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1734 mNextAppTransitionAnimationsSpecsPending = true;
1735 final IAppTransitionAnimationSpecsFuture future
1736 = mNextAppTransitionAnimationsSpecsFuture;
1737 mNextAppTransitionAnimationsSpecsFuture = null;
1738 mDefaultExecutor.execute(new Runnable() {
1739 @Override
1740 public void run() {
1741 AppTransitionAnimationSpec[] specs = null;
1742 try {
1743 specs = future.get();
1744 } catch (RemoteException e) {
1745 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1746 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001747 synchronized (mService.mWindowMap) {
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001748 mNextAppTransitionAnimationsSpecsPending = false;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001749 overridePendingAppTransitionMultiThumb(specs,
1750 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1751 mNextAppTransitionScaleUp);
1752 mNextAppTransitionFutureCallback = null;
Filip Gruszczynski96daf322015-11-18 18:01:27 -08001753 if (specs != null) {
1754 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1755 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001756 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001757 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001758 }
1759 });
1760 }
1761 }
1762
Craig Mautner164d4bb2012-11-26 13:51:23 -08001763 @Override
1764 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001765 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001766 }
1767
Craig Mautner4b71aa12012-12-27 17:20:01 -08001768 /**
1769 * Returns the human readable name of a window transition.
1770 *
1771 * @param transition The window transition.
1772 * @return The transition symbolic name.
1773 */
1774 public static String appTransitionToString(int transition) {
1775 switch (transition) {
1776 case TRANSIT_UNSET: {
1777 return "TRANSIT_UNSET";
1778 }
1779 case TRANSIT_NONE: {
1780 return "TRANSIT_NONE";
1781 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001782 case TRANSIT_ACTIVITY_OPEN: {
1783 return "TRANSIT_ACTIVITY_OPEN";
1784 }
1785 case TRANSIT_ACTIVITY_CLOSE: {
1786 return "TRANSIT_ACTIVITY_CLOSE";
1787 }
1788 case TRANSIT_TASK_OPEN: {
1789 return "TRANSIT_TASK_OPEN";
1790 }
1791 case TRANSIT_TASK_CLOSE: {
1792 return "TRANSIT_TASK_CLOSE";
1793 }
1794 case TRANSIT_TASK_TO_FRONT: {
1795 return "TRANSIT_TASK_TO_FRONT";
1796 }
1797 case TRANSIT_TASK_TO_BACK: {
1798 return "TRANSIT_TASK_TO_BACK";
1799 }
1800 case TRANSIT_WALLPAPER_CLOSE: {
1801 return "TRANSIT_WALLPAPER_CLOSE";
1802 }
1803 case TRANSIT_WALLPAPER_OPEN: {
1804 return "TRANSIT_WALLPAPER_OPEN";
1805 }
1806 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1807 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1808 }
1809 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1810 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1811 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001812 case TRANSIT_TASK_OPEN_BEHIND: {
1813 return "TRANSIT_TASK_OPEN_BEHIND";
1814 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001815 case TRANSIT_ACTIVITY_RELAUNCH: {
1816 return "TRANSIT_ACTIVITY_RELAUNCH";
1817 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001818 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1819 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1820 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001821 default: {
1822 return "<UNKNOWN>";
1823 }
1824 }
1825 }
1826
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001827 private String appStateToString() {
1828 switch (mAppTransitionState) {
1829 case APP_STATE_IDLE:
1830 return "APP_STATE_IDLE";
1831 case APP_STATE_READY:
1832 return "APP_STATE_READY";
1833 case APP_STATE_RUNNING:
1834 return "APP_STATE_RUNNING";
1835 case APP_STATE_TIMEOUT:
1836 return "APP_STATE_TIMEOUT";
1837 default:
1838 return "unknown state=" + mAppTransitionState;
1839 }
1840 }
1841
1842 private String transitTypeToString() {
1843 switch (mNextAppTransitionType) {
1844 case NEXT_TRANSIT_TYPE_NONE:
1845 return "NEXT_TRANSIT_TYPE_NONE";
1846 case NEXT_TRANSIT_TYPE_CUSTOM:
1847 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001848 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1849 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001850 case NEXT_TRANSIT_TYPE_SCALE_UP:
1851 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1852 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1853 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1854 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1855 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001856 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1857 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1858 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1859 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001860 default:
1861 return "unknown type=" + mNextAppTransitionType;
1862 }
1863 }
1864
Craig Mautner164d4bb2012-11-26 13:51:23 -08001865 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001866 public void dump(PrintWriter pw, String prefix) {
1867 pw.print(prefix); pw.println(this);
1868 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001869 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001870 pw.print(prefix); pw.print("mNextAppTransitionType=");
1871 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001872 }
1873 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001874 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001875 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001876 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001877 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001878 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1879 pw.print(" mNextAppTransitionExit=0x");
1880 pw.println(Integer.toHexString(mNextAppTransitionExit));
1881 break;
Winson Chung044d5292014-11-06 11:05:19 -08001882 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001883 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001884 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001885 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001886 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1887 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001888 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001889 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001890 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001891 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001892 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001893 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001894 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001895 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001896 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001897 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001898 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001899 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001900 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1901 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001902 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001903 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1904 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1905 pw.println(mDefaultNextAppTransitionAnimationSpec);
1906 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1907 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001908 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1909 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001910 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001911 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001912 }
1913 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001914 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1915 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001916 }
Chong Zhang60091a92016-07-27 17:52:45 -07001917 if (mLastUsedAppTransition != TRANSIT_NONE) {
1918 pw.print(prefix); pw.print("mLastUsedAppTransition=");
1919 pw.println(appTransitionToString(mLastUsedAppTransition));
1920 pw.print(prefix); pw.print("mLastOpeningApp=");
1921 pw.println(mLastOpeningApp);
1922 pw.print(prefix); pw.print("mLastClosingApp=");
1923 pw.println(mLastClosingApp);
1924 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001925 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001926
1927 public void setCurrentUser(int newUserId) {
1928 mCurrentUserId = newUserId;
1929 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001930
1931 /**
1932 * @return true if transition is not running and should not be skipped, false if transition is
1933 * already running
1934 */
1935 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent) {
1936 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
1937 + " transit=" + appTransitionToString(transit)
1938 + " " + this
1939 + " alwaysKeepCurrent=" + alwaysKeepCurrent
1940 + " Callers=" + Debug.getCallers(3));
1941 if (!isTransitionSet() || mNextAppTransition == TRANSIT_NONE) {
1942 setAppTransition(transit);
1943 } else if (!alwaysKeepCurrent) {
1944 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
1945 // Opening a new task always supersedes a close for the anim.
1946 setAppTransition(transit);
1947 } else if (transit == TRANSIT_ACTIVITY_OPEN
1948 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
1949 // Opening a new activity always supersedes a close for the anim.
1950 setAppTransition(transit);
1951 }
1952 }
1953 boolean prepared = prepare();
1954 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001955 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
1956 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001957 }
1958 return prepared;
1959 }
Winsonb2024762016-04-05 17:32:30 -07001960
1961 /**
1962 * @return whether the specified {@param uiMode} is the TV mode.
1963 */
1964 private boolean isTvUiMode(int uiMode) {
1965 return (uiMode & Configuration.UI_MODE_TYPE_TELEVISION) > 0;
1966 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001967}