blob: 2b581562d68042dd4bfe5065ecd0c0829d11c7f7 [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;
165
166 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
167 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
168 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
169 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
170 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700171 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
172 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800173 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800174 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800175 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
176
Winson Chung399f6202014-03-19 10:47:20 -0700177 // These are the possible states for the enter/exit activities during a thumbnail transition
178 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
179 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
180 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
181 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
182
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800183 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800184 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800185 private boolean mNextAppTransitionScaleUp;
186 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100187 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700188 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800189 private int mNextAppTransitionEnter;
190 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800191 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700192
193 // Keyed by task id.
194 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
195 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100196 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
197 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700198 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
199
Winson Chunga4ccb862014-08-22 15:26:27 -0700200 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800201
Winson Chung2820c452014-04-15 15:34:44 -0700202 private Rect mTmpFromClipRect = new Rect();
203 private Rect mTmpToClipRect = new Rect();
204
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700205 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700206
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800207 private final static int APP_STATE_IDLE = 0;
208 private final static int APP_STATE_READY = 1;
209 private final static int APP_STATE_RUNNING = 2;
210 private final static int APP_STATE_TIMEOUT = 3;
211 private int mAppTransitionState = APP_STATE_IDLE;
212
213 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800214 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700215 private final Interpolator mThumbnailFadeInInterpolator;
216 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800217 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700218 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100219 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700220 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
221
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700222 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800223
Amith Yamasani4befbec2013-07-10 16:18:01 -0700224 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800225 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700226
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100227 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100228 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100229
Jorim Jaggif97ed922016-02-18 18:57:07 -0800230 private int mLastClipRevealMaxTranslation;
231 private boolean mLastHadClipReveal;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700232 private boolean mProlongedAnimationsEnded;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800233
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800234 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800235 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800236 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800237 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
238 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700239 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
240 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100241 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
242 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800243 mConfigShortAnimTime = context.getResources().getInteger(
244 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800245 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
246 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700247 mThumbnailFadeInInterpolator = new Interpolator() {
248 @Override
249 public float getInterpolation(float input) {
250 // Linear response for first fraction, then complete after that.
251 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
252 return 0f;
253 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700254 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700255 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700256 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700257 }
258 };
259 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800260 @Override
261 public float getInterpolation(float input) {
262 // Linear response for first fraction, then complete after that.
263 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700264 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
265 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800266 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700267 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800268 }
269 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700270 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
271 * mContext.getResources().getDisplayMetrics().density);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800272 }
273
274 boolean isTransitionSet() {
275 return mNextAppTransition != TRANSIT_UNSET;
276 }
277
Craig Mautner164d4bb2012-11-26 13:51:23 -0800278 boolean isTransitionEqual(int transit) {
279 return mNextAppTransition == transit;
280 }
281
282 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800283 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800284 }
285
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700286 private void setAppTransition(int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800287 mNextAppTransition = transit;
288 }
289
290 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800291 return mAppTransitionState == APP_STATE_READY
292 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800293 }
294
Craig Mautnerae446592012-12-06 19:05:05 -0800295 void setReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800296 mAppTransitionState = APP_STATE_READY;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100297 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800298 }
299
300 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800301 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800302 }
303
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800304 void setIdle() {
305 mAppTransitionState = APP_STATE_IDLE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800306 }
307
308 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800309 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800310 }
311
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800312 void setTimeout() {
313 mAppTransitionState = APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800314 }
315
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700316 Bitmap getAppTransitionThumbnailHeader(int taskId) {
317 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800318 if (spec == null) {
319 spec = mDefaultNextAppTransitionAnimationSpec;
320 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700321 return spec != null ? spec.bitmap : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800322 }
323
Winson Chunga4ccb862014-08-22 15:26:27 -0700324 /** Returns whether the next thumbnail transition is aspect scaled up. */
325 boolean isNextThumbnailTransitionAspectScaled() {
326 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
327 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
328 }
329
330 /** Returns whether the next thumbnail transition is scaling up. */
331 boolean isNextThumbnailTransitionScaleUp() {
332 return mNextAppTransitionScaleUp;
333 }
334
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800335 boolean isNextAppTransitionThumbnailUp() {
336 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
337 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
338 }
339
340 boolean isNextAppTransitionThumbnailDown() {
341 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
342 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
343 }
344
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100345 /**
346 * @return true if and only if we are currently fetching app transition specs from the future
347 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
348 */
349 boolean isFetchingAppTransitionsSpecs() {
350 return mNextAppTransitionAnimationsSpecsPending;
351 }
352
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700353 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800354 if (!isRunning()) {
355 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100356 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800357 mLastHadClipReveal = false;
358 mLastClipRevealMaxTranslation = 0;
359 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700360 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800361 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700362 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800363 }
364
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800365 void goodToGo(AppWindowAnimator topOpeningAppAnimator, AppWindowAnimator topClosingAppAnimator,
366 ArraySet<AppWindowToken> openingApps, ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800367 mNextAppTransition = TRANSIT_UNSET;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800368 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100369 notifyAppTransitionStartingLocked(
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800370 topOpeningAppAnimator != null ? topOpeningAppAnimator.mAppToken.token : null,
371 topClosingAppAnimator != null ? topClosingAppAnimator.mAppToken.token : null,
372 topOpeningAppAnimator != null ? topOpeningAppAnimator.animation : null,
373 topClosingAppAnimator != null ? topClosingAppAnimator.animation : null);
374 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Jorim Jaggid3ec5072016-04-28 15:57:47 -0700375 .notifyAppTransitionStarting();
Jorim Jaggi363ab982016-04-26 19:51:20 -0700376
377 // Prolong the start for the transition when docking a task from recents, unless recents
378 // ended it already then we don't need to wait.
379 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS && !mProlongedAnimationsEnded) {
380 for (int i = openingApps.size() - 1; i >= 0; i--) {
381 final AppWindowAnimator appAnimator = openingApps.valueAt(i).mAppAnimator;
382 appAnimator.startProlongAnimation(PROLONG_ANIMATION_AT_START);
383 }
384 }
385 }
386
387 /**
388 * Let the transitions manager know that the somebody wanted to end the prolonged animations.
389 */
390 void notifyProlongedAnimationsEnded() {
391 mProlongedAnimationsEnded = true;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800392 }
393
394 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800395 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800396 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700397 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi65193992015-11-23 16:49:59 -0800398 mNextAppTransitionAnimationsSpecsFuture = null;
399 mDefaultNextAppTransitionAnimationSpec = null;
400 mAnimationFinishedCallback = null;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700401 mProlongedAnimationsEnded = false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800402 }
403
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800404 void freeze() {
405 setAppTransition(AppTransition.TRANSIT_UNSET);
406 clear();
407 setReady();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100408 notifyAppTransitionCancelledLocked();
409 }
410
411 void registerListenerLocked(AppTransitionListener listener) {
412 mListeners.add(listener);
413 }
414
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700415 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100416 for (int i = 0; i < mListeners.size(); i++) {
417 mListeners.get(i).onAppTransitionFinishedLocked(token);
418 }
419 }
420
421 private void notifyAppTransitionPendingLocked() {
422 for (int i = 0; i < mListeners.size(); i++) {
423 mListeners.get(i).onAppTransitionPendingLocked();
424 }
425 }
426
427 private void notifyAppTransitionCancelledLocked() {
428 for (int i = 0; i < mListeners.size(); i++) {
429 mListeners.get(i).onAppTransitionCancelledLocked();
430 }
431 }
432
433 private void notifyAppTransitionStartingLocked(IBinder openToken,
434 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
435 for (int i = 0; i < mListeners.size(); i++) {
436 mListeners.get(i).onAppTransitionStartingLocked(openToken, closeToken, openAnimation,
437 closeAnimation);
438 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800439 }
440
Craig Mautner164d4bb2012-11-26 13:51:23 -0800441 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
442 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
443 + (lp != null ? lp.packageName : null)
444 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
445 if (lp != null && lp.windowAnimations != 0) {
446 // If this is a system resource, don't try to load it from the
447 // application resources. It is nice to avoid loading application
448 // resources if we can.
449 String packageName = lp.packageName != null ? lp.packageName : "android";
450 int resId = lp.windowAnimations;
451 if ((resId&0xFF000000) == 0x01000000) {
452 packageName = "android";
453 }
454 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
455 + packageName);
456 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700457 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800458 }
459 return null;
460 }
461
462 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
463 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
464 + packageName + " resId=0x" + Integer.toHexString(resId));
465 if (packageName != null) {
466 if ((resId&0xFF000000) == 0x01000000) {
467 packageName = "android";
468 }
469 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
470 + packageName);
471 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700472 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800473 }
474 return null;
475 }
476
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700477 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800478 int anim = 0;
479 Context context = mContext;
480 if (animAttr >= 0) {
481 AttributeCache.Entry ent = getCachedAnimations(lp);
482 if (ent != null) {
483 context = ent.context;
484 anim = ent.array.getResourceId(animAttr, 0);
485 }
486 }
487 if (anim != 0) {
488 return AnimationUtils.loadAnimation(context, anim);
489 }
490 return null;
491 }
492
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700493 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
494 Context context = mContext;
495 if (resId >= 0) {
496 AttributeCache.Entry ent = getCachedAnimations(lp);
497 if (ent != null) {
498 context = ent.context;
499 }
500 return AnimationUtils.loadAnimation(context, resId);
501 }
502 return null;
503 }
504
505 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800506 int anim = 0;
507 Context context = mContext;
508 if (resId >= 0) {
509 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
510 if (ent != null) {
511 context = ent.context;
512 anim = resId;
513 }
514 }
515 if (anim != 0) {
516 return AnimationUtils.loadAnimation(context, anim);
517 }
518 return null;
519 }
520
Craig Mautner164d4bb2012-11-26 13:51:23 -0800521 /**
522 * Compute the pivot point for an animation that is scaling from a small
523 * rect on screen to a larger rect. The pivot point varies depending on
524 * the distance between the inner and outer edges on both sides. This
525 * function computes the pivot point for one dimension.
526 * @param startPos Offset from left/top edge of outer rectangle to
527 * left/top edge of inner rectangle.
528 * @param finalScale The scaling factor between the size of the outer
529 * and inner rectangles.
530 */
531 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800532
533 /*
534 Theorem of intercepting lines:
535
536 + + +-----------------------------------------------+
537 | | | |
538 | | | |
539 | | | |
540 | | | |
541 x | y | | |
542 | | | |
543 | | | |
544 | | | |
545 | | | |
546 | + | +--------------------+ |
547 | | | | |
548 | | | | |
549 | | | | |
550 | | | | |
551 | | | | |
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 p ++
584
585 scale = (x - y) / x
586 <=> x = -y / (scale - 1)
587 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800588 final float denom = finalScale-1;
589 if (Math.abs(denom) < .0001f) {
590 return startPos;
591 }
592 return -startPos / denom;
593 }
594
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700595 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
596 Rect containingFrame) {
597 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700598 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700599 final int appWidth = containingFrame.width();
600 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800601 if (enter) {
602 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700603 float scaleW = mTmpRect.width() / (float) appWidth;
604 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800605 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700606 computePivot(mTmpRect.left, scaleW),
607 computePivot(mTmpRect.right, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800608 scale.setInterpolator(mDecelerateInterpolator);
609
Craig Mautner164d4bb2012-11-26 13:51:23 -0800610 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700611 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800612
613 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800614 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800615 set.addAnimation(alpha);
616 set.setDetachWallpaper(true);
617 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800618 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
619 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800620 // If we are on top of the wallpaper, we need an animation that
621 // correctly handles the wallpaper staying static behind all of
622 // the animated elements. To do this, will just have the existing
623 // element fade out.
624 a = new AlphaAnimation(1, 0);
625 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800626 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800627 // For normal animations, the exiting element just holds in place.
628 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800629 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800630
631 // Pick the desired duration. If this is an inter-activity transition,
632 // it is the standard duration for that. Otherwise we use the longer
633 // task transition duration.
634 final long duration;
635 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800636 case TRANSIT_ACTIVITY_OPEN:
637 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800638 duration = mConfigShortAnimTime;
639 break;
640 default:
641 duration = DEFAULT_APP_TRANSITION_DURATION;
642 break;
643 }
644 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800645 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800646 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800647 a.initialize(appWidth, appHeight, appWidth, appHeight);
648 return a;
649 }
650
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700651 private void getDefaultNextAppTransitionStartRect(Rect rect) {
652 if (mDefaultNextAppTransitionAnimationSpec == null ||
653 mDefaultNextAppTransitionAnimationSpec.rect == null) {
654 Slog.wtf(TAG, "Starting rect for app requested, but none available", new Throwable());
655 rect.setEmpty();
656 } else {
657 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
658 }
659 }
660
661 void getNextAppTransitionStartRect(int taskId, Rect rect) {
662 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800663 if (spec == null) {
664 spec = mDefaultNextAppTransitionAnimationSpec;
665 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700666 if (spec == null || spec.rect == null) {
667 Slog.wtf(TAG, "Starting rect for task: " + taskId + " requested, but not available",
668 new Throwable());
669 rect.setEmpty();
670 } else {
671 rect.set(spec.rect);
672 }
673 }
674
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800675 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
676 Bitmap bitmap) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700677 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800678 bitmap, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700679 }
680
Jorim Jaggif97ed922016-02-18 18:57:07 -0800681 /**
682 * @return the duration of the last clip reveal animation
683 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800684 long getLastClipRevealTransitionDuration() {
685 return mLastClipRevealTransitionDuration;
686 }
687
688 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800689 * @return the maximum distance the app surface is traveling of the last clip reveal animation
690 */
691 int getLastClipRevealMaxTranslation() {
692 return mLastClipRevealMaxTranslation;
693 }
694
695 /**
696 * @return true if in the last app transition had a clip reveal animation, false otherwise
697 */
698 boolean hadClipRevealAnimation() {
699 return mLastHadClipReveal;
700 }
701
702 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800703 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
704 * the start rect is outside of the target rect, and there is a lot of movement going on.
705 *
706 * @param cutOff whether the start rect was not fully contained by the end rect
707 * @param translationX the total translation the surface moves in x direction
708 * @param translationY the total translation the surfaces moves in y direction
709 * @param displayFrame our display frame
710 *
711 * @return the duration of the clip reveal animation, in milliseconds
712 */
713 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
714 float translationY, Rect displayFrame) {
715 if (!cutOff) {
716 return DEFAULT_APP_TRANSITION_DURATION;
717 }
718 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
719 Math.abs(translationY) / displayFrame.height());
720 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
721 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
722 }
723
724 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
725 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800726 final Animation anim;
727 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700728 final int appWidth = appFrame.width();
729 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800730
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700731 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700732 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700733 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700734
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700735 float t = 0f;
736 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800737 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700738 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800739 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
740 int translationX = 0;
741 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700742 int centerX = mTmpRect.centerX();
743 int centerY = mTmpRect.centerY();
744 int halfWidth = mTmpRect.width() / 2;
745 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800746 int clipStartX = centerX - halfWidth - appFrame.left;
747 int clipStartY = centerY - halfHeight - appFrame.top;
748 boolean cutOff = false;
749
750 // If the starting rectangle is fully or partially outside of the target rectangle, we
751 // need to start the clipping at the edge and then achieve the rest with translation
752 // and extending the clip rect from that edge.
753 if (appFrame.top > centerY - halfHeight) {
754 translationY = (centerY - halfHeight) - appFrame.top;
755 translationYCorrection = 0;
756 clipStartY = 0;
757 cutOff = true;
758 }
759 if (appFrame.left > centerX - halfWidth) {
760 translationX = (centerX - halfWidth) - appFrame.left;
761 clipStartX = 0;
762 cutOff = true;
763 }
764 if (appFrame.right < centerX + halfWidth) {
765 translationX = (centerX + halfWidth) - appFrame.right;
766 clipStartX = appWidth - mTmpRect.width();
767 cutOff = true;
768 }
769 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
770 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700771
772 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800773 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800774 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700775 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800776 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700777
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800778 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
779 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
780 : mLinearOutSlowInInterpolator);
781 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800782
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800783 Animation clipAnimTB = new ClipRectTBAnimation(
784 clipStartY, clipStartY + mTmpRect.height(),
785 0, appHeight,
786 translationYCorrection, 0,
787 mLinearOutSlowInInterpolator);
788 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
789 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800790
791 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800792 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700793 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800794 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700795 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800796
797 AnimationSet set = new AnimationSet(false);
798 set.addAnimation(clipAnimLR);
799 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700800 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800801 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700802 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800803 set.initialize(appWidth, appHeight, appWidth, appHeight);
804 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800805 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800806 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800807
808 // If the start rect was full inside the target rect (cutOff == false), we don't need
809 // to store the translation, because it's only used if cutOff == true.
810 mLastClipRevealMaxTranslation = cutOff
811 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800812 } else {
813 final long duration;
814 switch (transit) {
815 case TRANSIT_ACTIVITY_OPEN:
816 case TRANSIT_ACTIVITY_CLOSE:
817 duration = mConfigShortAnimTime;
818 break;
819 default:
820 duration = DEFAULT_APP_TRANSITION_DURATION;
821 break;
822 }
823 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
824 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
825 // If we are on top of the wallpaper, we need an animation that
826 // correctly handles the wallpaper staying static behind all of
827 // the animated elements. To do this, will just have the existing
828 // element fade out.
829 anim = new AlphaAnimation(1, 0);
830 anim.setDetachWallpaper(true);
831 } else {
832 // For normal animations, the exiting element just holds in place.
833 anim = new AlphaAnimation(1, 1);
834 }
835 anim.setInterpolator(mDecelerateInterpolator);
836 anim.setDuration(duration);
837 anim.setFillAfter(true);
838 }
839 return anim;
840 }
841
Winson Chung399f6202014-03-19 10:47:20 -0700842 /**
843 * Prepares the specified animation with a standard duration, interpolator, etc.
844 */
Winson Chung5393dff2014-05-08 14:25:43 -0700845 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100846 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700847 if (duration > 0) {
848 a.setDuration(duration);
849 }
Winson Chung5393dff2014-05-08 14:25:43 -0700850 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100851 if (interpolator != null) {
852 a.setInterpolator(interpolator);
853 }
Winson Chung5393dff2014-05-08 14:25:43 -0700854 a.initialize(appWidth, appHeight, appWidth, appHeight);
855 return a;
856 }
857
858 /**
859 * Prepares the specified animation with a standard duration, interpolator, etc.
860 */
Winson Chung399f6202014-03-19 10:47:20 -0700861 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800862 // Pick the desired duration. If this is an inter-activity transition,
863 // it is the standard duration for that. Otherwise we use the longer
864 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700865 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800866 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800867 case TRANSIT_ACTIVITY_OPEN:
868 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800869 duration = mConfigShortAnimTime;
870 break;
871 default:
872 duration = DEFAULT_APP_TRANSITION_DURATION;
873 break;
874 }
Winson Chung5393dff2014-05-08 14:25:43 -0700875 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
876 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800877 }
878
Winson Chung399f6202014-03-19 10:47:20 -0700879 /**
880 * Return the current thumbnail transition state.
881 */
882 int getThumbnailTransitionState(boolean enter) {
883 if (enter) {
884 if (mNextAppTransitionScaleUp) {
885 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
886 } else {
887 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
888 }
889 } else {
890 if (mNextAppTransitionScaleUp) {
891 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
892 } else {
893 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
894 }
895 }
896 }
897
898 /**
899 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700900 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700901 */
Jorim Jaggide63d442016-03-14 14:56:56 +0100902 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winsonb2024762016-04-05 17:32:30 -0700903 Bitmap thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -0700904 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700905 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700906 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700907 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700908 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700909
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700910 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700911 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -0700912 final float fromX;
913 final float fromY;
914 final float toX;
915 final float toY;
916 final float pivotX;
917 final float pivotY;
Winsonb2024762016-04-05 17:32:30 -0700918 if (isTvUiMode(uiMode) || orientation == Configuration.ORIENTATION_PORTRAIT) {
Jorim Jaggi09072002016-03-25 16:48:42 -0700919 fromX = mTmpRect.left;
920 fromY = mTmpRect.top;
921
922 // For the curved translate animation to work, the pivot points needs to be at the
923 // same absolute position as the one from the real surface.
924 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
925 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
926 pivotX = mTmpRect.width() / 2;
927 pivotY = appRect.height() / 2 / scaleW;
928 } else {
929 pivotX = 0;
930 pivotY = 0;
931 fromX = mTmpRect.left;
932 fromY = mTmpRect.top;
933 toX = appRect.left;
934 toY = appRect.top;
935 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100936 final long duration = getAspectScaleDuration();
937 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -0700938 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700939 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +0100940 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100941 scale.setInterpolator(interpolator);
942 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800943 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100944 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
945 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
946 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
947 ? duration / 2
948 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100949 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
950 translate.setInterpolator(interpolator);
951 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -0700952
Jorim Jaggide63d442016-03-14 14:56:56 +0100953 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
954 mTmpToClipRect.set(appRect);
955
956 // Containing frame is in screen space, but we need the clip rect in the
957 // app space.
958 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100959 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
960 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +0100961
962 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +0100963 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
964 (int) (-contentInsets.top * scaleW),
965 (int) (-contentInsets.right * scaleW),
966 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +0100967 }
968
969 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100970 clipAnim.setInterpolator(interpolator);
971 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +0100972
Winson Chung399f6202014-03-19 10:47:20 -0700973 // This AnimationSet uses the Interpolators assigned above.
974 AnimationSet set = new AnimationSet(false);
975 set.addAnimation(scale);
976 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -0700977 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +0100978 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -0700979 a = set;
980 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700981 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +0100982 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100983 scale.setInterpolator(interpolator);
984 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -0700985 Animation alpha = new AlphaAnimation(0f, 1f);
986 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100987 alpha.setDuration(duration);
988 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
989 translate.setInterpolator(interpolator);
990 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -0700991
Winson Chunga4ccb862014-08-22 15:26:27 -0700992 // This AnimationSet uses the Interpolators assigned above.
993 AnimationSet set = new AnimationSet(false);
994 set.addAnimation(scale);
995 set.addAnimation(alpha);
996 set.addAnimation(translate);
997 a = set;
998
999 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001000 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001001 null);
Winson Chung399f6202014-03-19 10:47:20 -07001002 }
1003
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001004 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1005
1006 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001007 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001008 return new TranslateAnimation(fromX, toX, fromY, toY);
1009 } else {
1010 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1011 return new CurvedTranslateAnimation(path);
1012 }
1013 }
1014
1015 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1016 final Path path = new Path();
1017 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001018
1019 if (fromY > toY) {
1020 // If the object needs to go up, move it in horizontal direction first, then vertical.
1021 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1022 } else {
1023 // If the object needs to go down, move it in vertical direction first, then horizontal.
1024 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1025 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001026 return path;
1027 }
1028
1029 private long getAspectScaleDuration() {
1030 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001031 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001032 } else {
1033 return THUMBNAIL_APP_TRANSITION_DURATION;
1034 }
1035 }
1036
1037 private Interpolator getAspectScaleInterpolator() {
1038 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1039 return mFastOutSlowInInterpolator;
1040 } else {
1041 return TOUCH_RESPONSE_INTERPOLATOR;
1042 }
1043 }
1044
Winson Chung399f6202014-03-19 10:47:20 -07001045 /**
1046 * This alternate animation is created when we are doing a thumbnail transition, for the
1047 * activity that is leaving, and the activity that is entering.
1048 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001049 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001050 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001051 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001052 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001053 final int appWidth = containingFrame.width();
1054 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001055 getDefaultNextAppTransitionStartRect(mTmpRect);
1056 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001057 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001058 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001059 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001060 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001061 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001062
1063 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001064 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1065 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1066 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1067 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001068 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001069 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001070 } else if (freeform) {
1071 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1072 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001073 } else {
Winson21700932016-03-24 17:26:23 -07001074 AnimationSet set = new AnimationSet(true);
1075
1076 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001077 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001078 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001079
1080 // Containing frame is in screen space, but we need the clip rect in the
1081 // app space.
1082 mTmpFromClipRect.offsetTo(0, 0);
1083 mTmpToClipRect.offsetTo(0, 0);
1084
1085 // Exclude insets region from the source clip.
1086 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001087 mNextAppTransitionInsets.set(contentInsets);
1088
Winsonb2024762016-04-05 17:32:30 -07001089 if (isTvUiMode(uiMode) || orientation == Configuration.ORIENTATION_PORTRAIT) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001090 // We scale the width and clip to the top/left square
1091 float scale = thumbWidth /
1092 (appWidth - contentInsets.left - contentInsets.right);
1093 int unscaledThumbHeight = (int) (thumbHeight / scale);
1094 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1095
1096 mNextAppTransitionInsets.set(contentInsets);
1097
Jorim Jaggi8448f332016-03-14 17:50:37 +01001098 Animation scaleAnim = new ScaleAnimation(
1099 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1100 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001101 containingFrame.width() / 2f,
1102 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001103 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001104 final float x = containingFrame.width() / 2f
1105 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001106 final float targetY = (mTmpRect.top - containingFrame.top);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001107 final float y = containingFrame.height() / 2f
1108 - containingFrame.height() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001109 final float startX = targetX - x;
1110 final float startY = targetY - y;
1111 Animation clipAnim = scaleUp
1112 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1113 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1114 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001115 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1116 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1117
Winson21700932016-03-24 17:26:23 -07001118 set.addAnimation(clipAnim);
1119 set.addAnimation(scaleAnim);
1120 set.addAnimation(translateAnim);
1121
1122 } else {
1123 // In landscape, we don't scale at all and only crop
1124 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1125 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1126
Jorim Jaggi8448f332016-03-14 17:50:37 +01001127 Animation clipAnim = scaleUp
1128 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1129 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1130 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001131 ? createCurvedMotion(thumbStartX, 0,
1132 thumbStartY - contentInsets.top, 0)
1133 : createCurvedMotion(0, thumbStartX, 0,
1134 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001135
1136 set.addAnimation(clipAnim);
1137 set.addAnimation(translateAnim);
1138 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001139 a = set;
Winson21700932016-03-24 17:26:23 -07001140 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001141 }
Winson Chung399f6202014-03-19 10:47:20 -07001142 break;
1143 }
1144 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001145 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001146 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001147 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001148 // activity.
1149 a = new AlphaAnimation(1, 0);
1150 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001151 a = new AlphaAnimation(1, 1);
1152 }
1153 break;
1154 }
1155 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001156 // Target app window during the scale down
1157 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1158 // Fade in the destination activity if we are animating from a wallpaper
1159 // activity.
1160 a = new AlphaAnimation(0, 1);
1161 } else {
1162 a = new AlphaAnimation(1, 1);
1163 }
Winson Chung399f6202014-03-19 10:47:20 -07001164 break;
1165 }
Winson Chung399f6202014-03-19 10:47:20 -07001166 default:
1167 throw new RuntimeException("Invalid thumbnail transition state");
1168 }
1169
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001170 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1171 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001172 }
1173
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001174 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1175 @Nullable Rect surfaceInsets, int taskId) {
1176 getNextAppTransitionStartRect(taskId, mTmpRect);
1177 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1178 true);
1179 }
1180
1181 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1182 @Nullable Rect surfaceInsets, int taskId) {
1183 getNextAppTransitionStartRect(taskId, mTmpRect);
1184 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1185 false);
1186 }
1187
1188 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1189 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1190 final float sourceWidth = sourceFrame.width();
1191 final float sourceHeight = sourceFrame.height();
1192 final float destWidth = destFrame.width();
1193 final float destHeight = destFrame.height();
1194 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1195 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001196 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001197 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001198 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001199 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001200 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1201 // We want the scaling to happen from the center of the surface. In order to achieve that,
1202 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001203 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1204 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1205 final ScaleAnimation scale = enter ?
1206 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1207 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1208 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1209 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1210 final int destHCenter = destFrame.left + destFrame.width() / 2;
1211 final int destVCenter = destFrame.top + destFrame.height() / 2;
1212 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1213 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1214 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1215 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001216 set.addAnimation(scale);
1217 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001218
1219 final IRemoteCallback callback = mAnimationFinishedCallback;
1220 if (callback != null) {
1221 set.setAnimationListener(new Animation.AnimationListener() {
1222 @Override
1223 public void onAnimationStart(Animation animation) { }
1224
1225 @Override
1226 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001227 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001228 }
1229
1230 @Override
1231 public void onAnimationRepeat(Animation animation) { }
1232 });
1233 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001234 return set;
1235 }
1236
Winson Chung399f6202014-03-19 10:47:20 -07001237 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001238 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001239 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001240 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001241 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
1242 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001243 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001244 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001245 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001246 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001247 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001248 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1249
1250 if (mNextAppTransitionScaleUp) {
1251 // Animation for the thumbnail zooming from its initial size to the full screen
1252 float scaleW = appWidth / thumbWidth;
1253 float scaleH = appHeight / thumbHeight;
1254 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001255 computePivot(mTmpRect.left, 1 / scaleW),
1256 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001257 scale.setInterpolator(mDecelerateInterpolator);
1258
1259 Animation alpha = new AlphaAnimation(1, 0);
1260 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1261
1262 // This AnimationSet uses the Interpolators assigned above.
1263 AnimationSet set = new AnimationSet(false);
1264 set.addAnimation(scale);
1265 set.addAnimation(alpha);
1266 a = set;
1267 } else {
1268 // Animation for the thumbnail zooming down from the full screen to its final size
1269 float scaleW = appWidth / thumbWidth;
1270 float scaleH = appHeight / thumbHeight;
1271 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001272 computePivot(mTmpRect.left, 1 / scaleW),
1273 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001274 }
1275
1276 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1277 }
1278
1279 /**
Winson Chung399f6202014-03-19 10:47:20 -07001280 * This animation is created when we are doing a thumbnail transition, for the activity that is
1281 * leaving, and the activity that is entering.
1282 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001283 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1284 int transit, int taskId) {
1285 final int appWidth = containingFrame.width();
1286 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001287 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001288 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001289 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001290 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001291 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001292 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001293 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1294
1295 switch (thumbTransitState) {
1296 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1297 // Entering app scales up with the thumbnail
1298 float scaleW = thumbWidth / appWidth;
1299 float scaleH = thumbHeight / appHeight;
1300 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001301 computePivot(mTmpRect.left, scaleW),
1302 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001303 break;
1304 }
1305 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1306 // Exiting app while the thumbnail is scaling up should fade or stay in place
1307 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1308 // Fade out while bringing up selected activity. This keeps the
1309 // current activity from showing through a launching wallpaper
1310 // activity.
1311 a = new AlphaAnimation(1, 0);
1312 } else {
1313 // noop animation
1314 a = new AlphaAnimation(1, 1);
1315 }
1316 break;
1317 }
1318 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1319 // Entering the other app, it should just be visible while we scale the thumbnail
1320 // down above it
1321 a = new AlphaAnimation(1, 1);
1322 break;
1323 }
1324 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1325 // Exiting the current app, the app should scale down with the thumbnail
1326 float scaleW = thumbWidth / appWidth;
1327 float scaleH = thumbHeight / appHeight;
1328 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001329 computePivot(mTmpRect.left, scaleW),
1330 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001331
1332 Animation alpha = new AlphaAnimation(1, 0);
1333
1334 AnimationSet set = new AnimationSet(true);
1335 set.addAnimation(scale);
1336 set.addAnimation(alpha);
1337 set.setZAdjustment(Animation.ZORDER_TOP);
1338 a = set;
1339 break;
1340 }
1341 default:
1342 throw new RuntimeException("Invalid thumbnail transition state");
1343 }
1344
1345 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1346 }
1347
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001348 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001349 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1350 final int left = mTmpFromClipRect.left;
1351 final int top = mTmpFromClipRect.top;
1352 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001353 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1354 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001355 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001356 float fromWidth = mTmpFromClipRect.width();
1357 float toWidth = mTmpToClipRect.width();
1358 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001359 // While the window might span the whole display, the actual content will be cropped to the
1360 // system decoration frame, for example when the window is docked. We need to take into
1361 // account the visible height when constructing the animation.
1362 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1363 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001364 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1365 // The final window is larger in both dimensions than current window (e.g. we are
1366 // maximizing), so we can simply unclip the new window and there will be no disappearing
1367 // frame.
1368 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1369 } else {
1370 // The disappearing window has one larger dimension. We need to apply scaling, so the
1371 // first frame of the entry animation matches the old window.
1372 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001373 // We might not be going exactly full screen, but instead be aligned under the status
1374 // bar using cropping. We still need to account for the cropped part, which will also
1375 // be scaled.
1376 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001377 }
1378
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001379 // We animate the translation from the old position of the removed window, to the new
1380 // position of the added window. The latter might not be full screen, for example docked for
1381 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001382 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001383 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001384 set.addAnimation(translate);
1385 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001386 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001387 return set;
1388 }
1389
Jorim Jaggic554b772015-06-04 16:07:57 -07001390 /**
1391 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1392 * frame of the transition doesn't change the visuals on screen, so we can start
1393 * directly with the second one
1394 */
1395 boolean canSkipFirstFrame() {
1396 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1397 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
1398 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1399 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001400
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001401 /**
1402 *
1403 * @param frame These are the bounds of the window when it finishes the animation. This is where
1404 * the animation must usually finish in entrance animation, as the next frame will
1405 * display the window at these coordinates. In case of exit animation, this is
1406 * where the animation must start, as the frame before the animation is displaying
1407 * the window at these bounds.
1408 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1409 * window might be obscured, usually by the system windows (status bar and
1410 * navigation bar) and we use content insets to convey that information. This
1411 * usually affects the animation aspects vertically, as the system decoration is
1412 * at the top and the bottom. For example when we animate from full screen to
1413 * recents, we want to exclude the covered parts, because they won't match the
1414 * thumbnail after the last frame is executed.
1415 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1416 * know about this to make the animation frames match. We currently use
1417 * this for freeform windows, which have larger surfaces to display
1418 * shadows. When we animate them from recents, we want to match the content
1419 * to the recents thumbnail and hence need to account for the surface being
1420 * bigger.
1421 */
Winsonb2024762016-04-05 17:32:30 -07001422 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001423 int orientation, Rect frame, Rect displayFrame, Rect insets,
1424 @Nullable Rect surfaceInsets, boolean isVoiceInteraction, boolean freeform,
1425 int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001426 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001427 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
1428 || transit == TRANSIT_TASK_OPEN
1429 || transit == TRANSIT_TASK_TO_FRONT)) {
1430 a = loadAnimationRes(lp, enter
1431 ? com.android.internal.R.anim.voice_activity_open_enter
1432 : com.android.internal.R.anim.voice_activity_open_exit);
1433 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1434 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001435 + " anim=" + a + " transit=" + appTransitionToString(transit)
1436 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001437 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1438 || transit == TRANSIT_TASK_CLOSE
1439 || transit == TRANSIT_TASK_TO_BACK)) {
1440 a = loadAnimationRes(lp, enter
1441 ? com.android.internal.R.anim.voice_activity_close_enter
1442 : com.android.internal.R.anim.voice_activity_close_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));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001447 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001448 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001449 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1450 "applyAnimation:"
1451 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1452 + " transit=" + appTransitionToString(transit)
1453 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001454 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1455 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001456 mNextAppTransitionEnter : mNextAppTransitionExit);
1457 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1458 "applyAnimation:"
1459 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001460 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001461 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001462 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1463 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1464 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1465 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001466 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1467 + " transit=" + appTransitionToString(transit)
1468 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001469 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001470 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001471 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1472 "applyAnimation:"
1473 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001474 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001475 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001476 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001477 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001478 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1479 "applyAnimation:"
1480 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001481 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001482 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001483 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1484 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001485 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001486 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001487 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001488 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001489 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1490 String animName = mNextAppTransitionScaleUp ?
1491 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1492 Slog.v(TAG, "applyAnimation:"
1493 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001494 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001495 + " Callers=" + Debug.getCallers(3));
1496 }
1497 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1498 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1499 mNextAppTransitionScaleUp =
1500 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1501 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001502 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001503 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001504 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1505 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001506 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001507 Slog.v(TAG, "applyAnimation:"
1508 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001509 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001510 + " Callers=" + Debug.getCallers(3));
1511 }
1512 } else {
1513 int animAttr = 0;
1514 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001515 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001516 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001517 ? WindowAnimation_activityOpenEnterAnimation
1518 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001519 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001520 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001521 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001522 ? WindowAnimation_activityCloseEnterAnimation
1523 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001524 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001525 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001526 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001527 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001528 ? WindowAnimation_taskOpenEnterAnimation
1529 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001530 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001531 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001532 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001533 ? WindowAnimation_taskCloseEnterAnimation
1534 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001535 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001536 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001537 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001538 ? WindowAnimation_taskToFrontEnterAnimation
1539 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001540 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001541 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001542 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001543 ? WindowAnimation_taskToBackEnterAnimation
1544 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001545 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001546 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001547 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001548 ? WindowAnimation_wallpaperOpenEnterAnimation
1549 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001550 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001551 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001552 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001553 ? WindowAnimation_wallpaperCloseEnterAnimation
1554 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001555 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001556 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001557 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001558 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1559 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001560 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001561 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001562 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001563 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1564 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001565 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001566 case TRANSIT_TASK_OPEN_BEHIND:
1567 animAttr = enter
1568 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001569 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001570 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001571 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001572 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1573 "applyAnimation:"
1574 + " anim=" + a
1575 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001576 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001577 + " Callers=" + Debug.getCallers(3));
1578 }
1579 return a;
1580 }
1581
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001582 int getAppStackClipMode() {
1583 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001584 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001585 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001586 ? STACK_CLIP_NONE
1587 : STACK_CLIP_AFTER_ANIM;
1588 }
1589
Craig Mautner164d4bb2012-11-26 13:51:23 -08001590 void postAnimationCallback() {
1591 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001592 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1593 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001594 mNextAppTransitionCallback = null;
1595 }
1596 }
1597
1598 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001599 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001600 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001601 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001602 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001603 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001604 mNextAppTransitionEnter = enterAnim;
1605 mNextAppTransitionExit = exitAnim;
1606 postAnimationCallback();
1607 mNextAppTransitionCallback = startedCallback;
1608 } else {
1609 postAnimationCallback();
1610 }
1611 }
1612
1613 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001614 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001615 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001616 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001617 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001618 putDefaultNextAppTransitionCoordinates(startX, startY, startX + startWidth,
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001619 startY + startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001620 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001621 }
1622 }
1623
Chet Haase10e23ab2015-02-11 15:08:38 -08001624 void overridePendingAppTransitionClipReveal(int startX, int startY,
1625 int startWidth, int startHeight) {
1626 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001627 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001628 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001629 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001630 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001631 }
1632 }
1633
Craig Mautner164d4bb2012-11-26 13:51:23 -08001634 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1635 IRemoteCallback startedCallback, boolean scaleUp) {
1636 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001637 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001638 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1639 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001640 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001641 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001642 postAnimationCallback();
1643 mNextAppTransitionCallback = startedCallback;
1644 } else {
1645 postAnimationCallback();
1646 }
1647 }
1648
Winson Chunga4ccb862014-08-22 15:26:27 -07001649 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001650 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001651 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001652 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001653 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1654 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001655 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001656 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1657 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001658 postAnimationCallback();
1659 mNextAppTransitionCallback = startedCallback;
1660 } else {
1661 postAnimationCallback();
1662 }
1663 }
1664
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001665 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001666 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1667 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001668 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001669 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001670 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1671 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001672 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001673 if (specs != null) {
1674 for (int i = 0; i < specs.length; i++) {
1675 AppTransitionAnimationSpec spec = specs[i];
1676 if (spec != null) {
1677 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1678 if (i == 0) {
1679 // In full screen mode, the transition code depends on the default spec
1680 // to be set.
1681 Rect rect = spec.rect;
1682 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Filip Gruszczynskie3264d82015-11-20 17:10:04 -08001683 rect.width(), rect.height(), spec.bitmap);
Jorim Jaggi43102412015-11-11 16:28:37 +01001684 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001685 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001686 }
1687 }
1688 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001689 mNextAppTransitionCallback = onAnimationStartedCallback;
1690 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001691 } else {
1692 postAnimationCallback();
1693 }
1694 }
1695
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001696 void overridePendingAppTransitionMultiThumbFuture(
1697 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1698 boolean scaleUp) {
1699 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001700 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001701 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1702 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001703 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1704 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001705 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001706 }
1707 }
1708
Winson Chung044d5292014-11-06 11:05:19 -08001709 void overrideInPlaceAppTransition(String packageName, int anim) {
1710 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001711 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001712 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1713 mNextAppTransitionPackage = packageName;
1714 mNextAppTransitionInPlace = anim;
1715 } else {
1716 postAnimationCallback();
1717 }
1718 }
1719
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001720 /**
1721 * If a future is set for the app transition specs, fetch it in another thread.
1722 */
1723 private void fetchAppTransitionSpecsFromFuture() {
1724 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1725 mNextAppTransitionAnimationsSpecsPending = true;
1726 final IAppTransitionAnimationSpecsFuture future
1727 = mNextAppTransitionAnimationsSpecsFuture;
1728 mNextAppTransitionAnimationsSpecsFuture = null;
1729 mDefaultExecutor.execute(new Runnable() {
1730 @Override
1731 public void run() {
1732 AppTransitionAnimationSpec[] specs = null;
1733 try {
1734 specs = future.get();
1735 } catch (RemoteException e) {
1736 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1737 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001738 synchronized (mService.mWindowMap) {
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001739 mNextAppTransitionAnimationsSpecsPending = false;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001740 overridePendingAppTransitionMultiThumb(specs,
1741 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1742 mNextAppTransitionScaleUp);
1743 mNextAppTransitionFutureCallback = null;
Filip Gruszczynski96daf322015-11-18 18:01:27 -08001744 if (specs != null) {
1745 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1746 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001747 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001748 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001749 }
1750 });
1751 }
1752 }
1753
Craig Mautner164d4bb2012-11-26 13:51:23 -08001754 @Override
1755 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001756 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001757 }
1758
Craig Mautner4b71aa12012-12-27 17:20:01 -08001759 /**
1760 * Returns the human readable name of a window transition.
1761 *
1762 * @param transition The window transition.
1763 * @return The transition symbolic name.
1764 */
1765 public static String appTransitionToString(int transition) {
1766 switch (transition) {
1767 case TRANSIT_UNSET: {
1768 return "TRANSIT_UNSET";
1769 }
1770 case TRANSIT_NONE: {
1771 return "TRANSIT_NONE";
1772 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001773 case TRANSIT_ACTIVITY_OPEN: {
1774 return "TRANSIT_ACTIVITY_OPEN";
1775 }
1776 case TRANSIT_ACTIVITY_CLOSE: {
1777 return "TRANSIT_ACTIVITY_CLOSE";
1778 }
1779 case TRANSIT_TASK_OPEN: {
1780 return "TRANSIT_TASK_OPEN";
1781 }
1782 case TRANSIT_TASK_CLOSE: {
1783 return "TRANSIT_TASK_CLOSE";
1784 }
1785 case TRANSIT_TASK_TO_FRONT: {
1786 return "TRANSIT_TASK_TO_FRONT";
1787 }
1788 case TRANSIT_TASK_TO_BACK: {
1789 return "TRANSIT_TASK_TO_BACK";
1790 }
1791 case TRANSIT_WALLPAPER_CLOSE: {
1792 return "TRANSIT_WALLPAPER_CLOSE";
1793 }
1794 case TRANSIT_WALLPAPER_OPEN: {
1795 return "TRANSIT_WALLPAPER_OPEN";
1796 }
1797 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1798 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1799 }
1800 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1801 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1802 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001803 case TRANSIT_TASK_OPEN_BEHIND: {
1804 return "TRANSIT_TASK_OPEN_BEHIND";
1805 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001806 case TRANSIT_ACTIVITY_RELAUNCH: {
1807 return "TRANSIT_ACTIVITY_RELAUNCH";
1808 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001809 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1810 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1811 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001812 default: {
1813 return "<UNKNOWN>";
1814 }
1815 }
1816 }
1817
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001818 private String appStateToString() {
1819 switch (mAppTransitionState) {
1820 case APP_STATE_IDLE:
1821 return "APP_STATE_IDLE";
1822 case APP_STATE_READY:
1823 return "APP_STATE_READY";
1824 case APP_STATE_RUNNING:
1825 return "APP_STATE_RUNNING";
1826 case APP_STATE_TIMEOUT:
1827 return "APP_STATE_TIMEOUT";
1828 default:
1829 return "unknown state=" + mAppTransitionState;
1830 }
1831 }
1832
1833 private String transitTypeToString() {
1834 switch (mNextAppTransitionType) {
1835 case NEXT_TRANSIT_TYPE_NONE:
1836 return "NEXT_TRANSIT_TYPE_NONE";
1837 case NEXT_TRANSIT_TYPE_CUSTOM:
1838 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001839 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1840 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001841 case NEXT_TRANSIT_TYPE_SCALE_UP:
1842 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1843 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1844 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1845 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1846 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001847 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1848 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1849 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1850 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001851 default:
1852 return "unknown type=" + mNextAppTransitionType;
1853 }
1854 }
1855
Craig Mautner164d4bb2012-11-26 13:51:23 -08001856 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001857 public void dump(PrintWriter pw, String prefix) {
1858 pw.print(prefix); pw.println(this);
1859 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001860 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001861 pw.print(prefix); pw.print("mNextAppTransitionType=");
1862 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001863 }
1864 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001865 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001866 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001867 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001868 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001869 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1870 pw.print(" mNextAppTransitionExit=0x");
1871 pw.println(Integer.toHexString(mNextAppTransitionExit));
1872 break;
Winson Chung044d5292014-11-06 11:05:19 -08001873 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001874 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001875 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001876 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001877 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1878 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001879 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001880 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001881 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001882 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001883 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001884 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001885 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001886 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001887 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001888 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001889 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001890 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001891 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1892 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001893 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001894 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1895 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1896 pw.println(mDefaultNextAppTransitionAnimationSpec);
1897 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1898 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001899 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1900 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001901 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001902 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001903 }
1904 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001905 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1906 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001907 }
1908 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001909
1910 public void setCurrentUser(int newUserId) {
1911 mCurrentUserId = newUserId;
1912 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001913
1914 /**
1915 * @return true if transition is not running and should not be skipped, false if transition is
1916 * already running
1917 */
1918 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent) {
1919 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
1920 + " transit=" + appTransitionToString(transit)
1921 + " " + this
1922 + " alwaysKeepCurrent=" + alwaysKeepCurrent
1923 + " Callers=" + Debug.getCallers(3));
1924 if (!isTransitionSet() || mNextAppTransition == TRANSIT_NONE) {
1925 setAppTransition(transit);
1926 } else if (!alwaysKeepCurrent) {
1927 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
1928 // Opening a new task always supersedes a close for the anim.
1929 setAppTransition(transit);
1930 } else if (transit == TRANSIT_ACTIVITY_OPEN
1931 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
1932 // Opening a new activity always supersedes a close for the anim.
1933 setAppTransition(transit);
1934 }
1935 }
1936 boolean prepared = prepare();
1937 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001938 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
1939 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001940 }
1941 return prepared;
1942 }
Winsonb2024762016-04-05 17:32:30 -07001943
1944 /**
1945 * @return whether the specified {@param uiMode} is the TV mode.
1946 */
1947 private boolean isTvUiMode(int uiMode) {
1948 return (uiMode & Configuration.UI_MODE_TYPE_TELEVISION) > 0;
1949 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001950}