blob: 9f44fea94d4acff433fc6b1b21dbe9cee670aae7 [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 Gruszczynski71b0d2d2015-08-12 18:52:26 -070019import android.annotation.Nullable;
Craig Mautner164d4bb2012-11-26 13:51:23 -080020import android.content.Context;
Winson Chung2820c452014-04-15 15:34:44 -070021import android.content.res.Configuration;
Craig Mautner164d4bb2012-11-26 13:51:23 -080022import android.graphics.Bitmap;
Winson Chung399f6202014-03-19 10:47:20 -070023import android.graphics.Rect;
Craig Mautner164d4bb2012-11-26 13:51:23 -080024import android.os.Debug;
25import android.os.Handler;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010026import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080027import android.os.IRemoteCallback;
28import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070029import android.util.SparseArray;
30import android.view.AppTransitionAnimationSpec;
Craig Mautner164d4bb2012-11-26 13:51:23 -080031import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080032import android.view.animation.AlphaAnimation;
33import android.view.animation.Animation;
34import android.view.animation.AnimationSet;
35import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070036import android.view.animation.ClipRectAnimation;
Chet Haase10e23ab2015-02-11 15:08:38 -080037import android.view.animation.ClipRectLRAnimation;
38import android.view.animation.ClipRectTBAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080039import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070040import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080041import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070042import android.view.animation.TranslateAnimation;
Chet Haase10e23ab2015-02-11 15:08:38 -080043import android.view.animation.TranslateYAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070044
Craig Mautner164d4bb2012-11-26 13:51:23 -080045import com.android.internal.util.DumpUtils.Dump;
46import com.android.server.AttributeCache;
47import com.android.server.wm.WindowManagerService.H;
48
49import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010050import java.util.ArrayList;
Craig Mautner164d4bb2012-11-26 13:51:23 -080051
Jorim Jaggi77ba4802015-02-18 13:57:50 +010052import static android.view.WindowManagerInternal.AppTransitionListener;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080053import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
54import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070055import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
56import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -070057import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070058import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080059import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
60import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070061import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
62import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080063import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
64import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070065import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
66import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080067import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
68import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080069import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
70import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070071import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
72import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
73import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
74import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080075
Craig Mautner164d4bb2012-11-26 13:51:23 -080076// State management of app transitions. When we are preparing for a
77// transition, mNextAppTransition will be the kind of transition to
78// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
79// mOpeningApps and mClosingApps are the lists of tokens that will be
80// made visible or hidden at the next transition.
81public class AppTransition implements Dump {
82 private static final String TAG = "AppTransition";
Craig Mautner321bdf52012-12-18 09:53:24 -080083 private static final boolean DEBUG_APP_TRANSITIONS =
84 WindowManagerService.DEBUG_APP_TRANSITIONS;
85 private static final boolean DEBUG_ANIM = WindowManagerService.DEBUG_ANIM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070086 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080087
Craig Mautner4b71aa12012-12-27 17:20:01 -080088 /** Not set up for a transition. */
89 public static final int TRANSIT_UNSET = -1;
90 /** No animation for transition. */
91 public static final int TRANSIT_NONE = 0;
92 /** 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 -070093 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -080094 /** The window in the top-most activity is being closed to reveal the
95 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -070096 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -080097 /** A window in a new task is being opened on top of an existing one
98 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -070099 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800100 /** A window in the top-most activity is being closed to reveal the
101 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700102 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800103 /** A window in an existing task is being displayed on top of an existing one
104 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700105 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800106 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700107 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800108 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
109 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700110 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800111 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
112 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700113 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800114 /** A window in a new activity is being opened on top of an existing one, and both are on top
115 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700116 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800117 /** The window in the top-most activity is being closed to reveal the previous activity, and
118 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700119 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
120 /** A window in a new task is being opened behind an existing one in another activity's task.
121 * The new window will show briefly and then be gone. */
122 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800123 /** A window in a task is being animated in-place. */
124 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700125 /** An activity is being relaunched (e.g. due to configuration change). */
126 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800127
Winson Chunga4ccb862014-08-22 15:26:27 -0700128 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700129 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800130 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700131 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800132
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700133 private static final int DEFAULT_APP_TRANSITION_DURATION = 336;
134 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
135 private static final int THUMBNAIL_APP_TRANSITION_ALPHA_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700136 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800137
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800138 private final Context mContext;
139 private final Handler mH;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800140
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800141 private int mNextAppTransition = TRANSIT_UNSET;
142
143 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
144 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
145 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
146 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
147 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700148 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
149 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800150 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800151 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800152 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
153
Winson Chung399f6202014-03-19 10:47:20 -0700154 // These are the possible states for the enter/exit activities during a thumbnail transition
155 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
156 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
157 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
158 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
159
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800160 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800161 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800162 private boolean mNextAppTransitionScaleUp;
163 private IRemoteCallback mNextAppTransitionCallback;
164 private int mNextAppTransitionEnter;
165 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800166 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700167
168 // Keyed by task id.
169 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
170 = new SparseArray<>();
171 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
172
Winson Chunga4ccb862014-08-22 15:26:27 -0700173 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800174
Winson Chung2820c452014-04-15 15:34:44 -0700175 private Rect mTmpFromClipRect = new Rect();
176 private Rect mTmpToClipRect = new Rect();
177
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700178 private final Rect mTmpStartRect = new Rect();
179
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800180 private final static int APP_STATE_IDLE = 0;
181 private final static int APP_STATE_READY = 1;
182 private final static int APP_STATE_RUNNING = 2;
183 private final static int APP_STATE_TIMEOUT = 3;
184 private int mAppTransitionState = APP_STATE_IDLE;
185
186 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800187 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700188 private final Interpolator mThumbnailFadeInInterpolator;
189 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800190 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700191 private final Interpolator mFastOutLinearInInterpolator;
192 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
193
194 /** Interpolator to be used for animations that respond directly to a touch */
195 private final Interpolator mTouchResponseInterpolator =
196 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
197
198 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800199
Amith Yamasani4befbec2013-07-10 16:18:01 -0700200 private int mCurrentUserId = 0;
201
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100202 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
203
Craig Mautner164d4bb2012-11-26 13:51:23 -0800204 AppTransition(Context context, Handler h) {
205 mContext = context;
206 mH = h;
Chet Haase10e23ab2015-02-11 15:08:38 -0800207 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
208 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700209 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
210 com.android.internal.R.interpolator.fast_out_linear_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800211 mConfigShortAnimTime = context.getResources().getInteger(
212 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800213 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
214 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700215 mThumbnailFadeInInterpolator = new Interpolator() {
216 @Override
217 public float getInterpolation(float input) {
218 // Linear response for first fraction, then complete after that.
219 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
220 return 0f;
221 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700222 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700223 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700224 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700225 }
226 };
227 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800228 @Override
229 public float getInterpolation(float input) {
230 // Linear response for first fraction, then complete after that.
231 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700232 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
233 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800234 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700235 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800236 }
237 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700238 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
239 * mContext.getResources().getDisplayMetrics().density);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800240 }
241
242 boolean isTransitionSet() {
243 return mNextAppTransition != TRANSIT_UNSET;
244 }
245
Craig Mautner164d4bb2012-11-26 13:51:23 -0800246 boolean isTransitionEqual(int transit) {
247 return mNextAppTransition == transit;
248 }
249
250 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800251 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800252 }
253
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700254 private void setAppTransition(int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800255 mNextAppTransition = transit;
256 }
257
258 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800259 return mAppTransitionState == APP_STATE_READY
260 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800261 }
262
Craig Mautnerae446592012-12-06 19:05:05 -0800263 void setReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800264 mAppTransitionState = APP_STATE_READY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800265 }
266
267 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800268 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800269 }
270
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800271 void setIdle() {
272 mAppTransitionState = APP_STATE_IDLE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800273 }
274
275 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800276 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800277 }
278
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800279 void setTimeout() {
280 mAppTransitionState = APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800281 }
282
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700283 Bitmap getAppTransitionThumbnailHeader(int taskId) {
284 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
285 return spec != null ? spec.bitmap : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800286 }
287
Winson Chunga4ccb862014-08-22 15:26:27 -0700288 /** Returns whether the next thumbnail transition is aspect scaled up. */
289 boolean isNextThumbnailTransitionAspectScaled() {
290 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
291 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
292 }
293
294 /** Returns whether the next thumbnail transition is scaling up. */
295 boolean isNextThumbnailTransitionScaleUp() {
296 return mNextAppTransitionScaleUp;
297 }
298
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700299 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800300 if (!isRunning()) {
301 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100302 notifyAppTransitionPendingLocked();
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700303 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800304 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700305 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800306 }
307
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100308 void goodToGo(AppWindowAnimator openingAppAnimator, AppWindowAnimator closingAppAnimator) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800309 mNextAppTransition = TRANSIT_UNSET;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800310 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100311 notifyAppTransitionStartingLocked(
312 openingAppAnimator != null ? openingAppAnimator.mAppToken.token : null,
313 closingAppAnimator != null ? closingAppAnimator.mAppToken.token : null,
314 openingAppAnimator != null ? openingAppAnimator.animation : null,
315 closingAppAnimator != null ? closingAppAnimator.animation : null);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800316 }
317
318 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800319 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800320 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700321 mNextAppTransitionAnimationsSpecs.clear();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800322 }
323
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800324 void freeze() {
325 setAppTransition(AppTransition.TRANSIT_UNSET);
326 clear();
327 setReady();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100328 notifyAppTransitionCancelledLocked();
329 }
330
331 void registerListenerLocked(AppTransitionListener listener) {
332 mListeners.add(listener);
333 }
334
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700335 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100336 for (int i = 0; i < mListeners.size(); i++) {
337 mListeners.get(i).onAppTransitionFinishedLocked(token);
338 }
339 }
340
341 private void notifyAppTransitionPendingLocked() {
342 for (int i = 0; i < mListeners.size(); i++) {
343 mListeners.get(i).onAppTransitionPendingLocked();
344 }
345 }
346
347 private void notifyAppTransitionCancelledLocked() {
348 for (int i = 0; i < mListeners.size(); i++) {
349 mListeners.get(i).onAppTransitionCancelledLocked();
350 }
351 }
352
353 private void notifyAppTransitionStartingLocked(IBinder openToken,
354 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
355 for (int i = 0; i < mListeners.size(); i++) {
356 mListeners.get(i).onAppTransitionStartingLocked(openToken, closeToken, openAnimation,
357 closeAnimation);
358 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800359 }
360
Craig Mautner164d4bb2012-11-26 13:51:23 -0800361 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
362 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
363 + (lp != null ? lp.packageName : null)
364 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
365 if (lp != null && lp.windowAnimations != 0) {
366 // If this is a system resource, don't try to load it from the
367 // application resources. It is nice to avoid loading application
368 // resources if we can.
369 String packageName = lp.packageName != null ? lp.packageName : "android";
370 int resId = lp.windowAnimations;
371 if ((resId&0xFF000000) == 0x01000000) {
372 packageName = "android";
373 }
374 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
375 + packageName);
376 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700377 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800378 }
379 return null;
380 }
381
382 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
383 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
384 + packageName + " resId=0x" + Integer.toHexString(resId));
385 if (packageName != null) {
386 if ((resId&0xFF000000) == 0x01000000) {
387 packageName = "android";
388 }
389 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
390 + packageName);
391 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700392 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800393 }
394 return null;
395 }
396
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700397 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800398 int anim = 0;
399 Context context = mContext;
400 if (animAttr >= 0) {
401 AttributeCache.Entry ent = getCachedAnimations(lp);
402 if (ent != null) {
403 context = ent.context;
404 anim = ent.array.getResourceId(animAttr, 0);
405 }
406 }
407 if (anim != 0) {
408 return AnimationUtils.loadAnimation(context, anim);
409 }
410 return null;
411 }
412
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700413 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
414 Context context = mContext;
415 if (resId >= 0) {
416 AttributeCache.Entry ent = getCachedAnimations(lp);
417 if (ent != null) {
418 context = ent.context;
419 }
420 return AnimationUtils.loadAnimation(context, resId);
421 }
422 return null;
423 }
424
425 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800426 int anim = 0;
427 Context context = mContext;
428 if (resId >= 0) {
429 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
430 if (ent != null) {
431 context = ent.context;
432 anim = resId;
433 }
434 }
435 if (anim != 0) {
436 return AnimationUtils.loadAnimation(context, anim);
437 }
438 return null;
439 }
440
Craig Mautner164d4bb2012-11-26 13:51:23 -0800441 /**
442 * Compute the pivot point for an animation that is scaling from a small
443 * rect on screen to a larger rect. The pivot point varies depending on
444 * the distance between the inner and outer edges on both sides. This
445 * function computes the pivot point for one dimension.
446 * @param startPos Offset from left/top edge of outer rectangle to
447 * left/top edge of inner rectangle.
448 * @param finalScale The scaling factor between the size of the outer
449 * and inner rectangles.
450 */
451 private static float computePivot(int startPos, float finalScale) {
452 final float denom = finalScale-1;
453 if (Math.abs(denom) < .0001f) {
454 return startPos;
455 }
456 return -startPos / denom;
457 }
458
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700459 private Animation createScaleUpAnimationLocked(
460 int transit, boolean enter, int appWidth, int appHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800461 Animation a = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700462 getDefaultNextAppTransitionStartRect(mTmpStartRect);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800463 if (enter) {
464 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700465 float scaleW = mTmpStartRect.width() / (float) appWidth;
466 float scaleH = mTmpStartRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800467 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700468 computePivot(mTmpStartRect.left, scaleW),
469 computePivot(mTmpStartRect.right, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800470 scale.setInterpolator(mDecelerateInterpolator);
471
Craig Mautner164d4bb2012-11-26 13:51:23 -0800472 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700473 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800474
475 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800476 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800477 set.addAnimation(alpha);
478 set.setDetachWallpaper(true);
479 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800480 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
481 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800482 // If we are on top of the wallpaper, we need an animation that
483 // correctly handles the wallpaper staying static behind all of
484 // the animated elements. To do this, will just have the existing
485 // element fade out.
486 a = new AlphaAnimation(1, 0);
487 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800488 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800489 // For normal animations, the exiting element just holds in place.
490 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800491 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800492
493 // Pick the desired duration. If this is an inter-activity transition,
494 // it is the standard duration for that. Otherwise we use the longer
495 // task transition duration.
496 final long duration;
497 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800498 case TRANSIT_ACTIVITY_OPEN:
499 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800500 duration = mConfigShortAnimTime;
501 break;
502 default:
503 duration = DEFAULT_APP_TRANSITION_DURATION;
504 break;
505 }
506 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800507 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800508 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800509 a.initialize(appWidth, appHeight, appWidth, appHeight);
510 return a;
511 }
512
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700513 private void getDefaultNextAppTransitionStartRect(Rect rect) {
514 if (mDefaultNextAppTransitionAnimationSpec == null ||
515 mDefaultNextAppTransitionAnimationSpec.rect == null) {
516 Slog.wtf(TAG, "Starting rect for app requested, but none available", new Throwable());
517 rect.setEmpty();
518 } else {
519 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
520 }
521 }
522
523 void getNextAppTransitionStartRect(int taskId, Rect rect) {
524 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
525 if (spec == null || spec.rect == null) {
526 Slog.wtf(TAG, "Starting rect for task: " + taskId + " requested, but not available",
527 new Throwable());
528 rect.setEmpty();
529 } else {
530 rect.set(spec.rect);
531 }
532 }
533
534 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height) {
535 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
536 null /* bitmap */, new Rect(left, top, left + width, top + height));
537 }
538
Craig Mautner80b1f642015-04-22 10:59:09 -0700539 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800540 final Animation anim;
541 if (enter) {
542 // Reveal will expand and move faster in horizontal direction
543
Craig Mautner80b1f642015-04-22 10:59:09 -0700544 final int appWidth = appFrame.width();
545 final int appHeight = appFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700546 getDefaultNextAppTransitionStartRect(mTmpStartRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700547
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700548 float t = 0f;
549 if (appHeight > 0) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700550 t = (float) mTmpStartRect.left / appHeight;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700551 }
552 int translationY = mClipRevealTranslationY
553 + (int)(appHeight / 7f * t);
554
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700555 int centerX = mTmpStartRect.centerX();
556 int centerY = mTmpStartRect.centerY();
557 int halfWidth = mTmpStartRect.width() / 2;
558 int halfHeight = mTmpStartRect.height() / 2;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700559
560 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800561 Animation clipAnimLR = new ClipRectLRAnimation(
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700562 centerX - halfWidth, centerX + halfWidth, 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700563 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
564 clipAnimLR.setDuration((long) (DEFAULT_APP_TRANSITION_DURATION / 2.5f));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700565 Animation clipAnimTB = new ClipRectTBAnimation(centerY - halfHeight - translationY,
566 centerY + halfHeight/ 2 - translationY, 0, appHeight);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700567 clipAnimTB.setInterpolator(mTouchResponseInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800568 clipAnimTB.setDuration(DEFAULT_APP_TRANSITION_DURATION);
569
Chet Haase10e23ab2015-02-11 15:08:38 -0800570 TranslateYAnimation translateY = new TranslateYAnimation(
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700571 Animation.ABSOLUTE, translationY, Animation.ABSOLUTE, 0);
572 translateY.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800573 translateY.setDuration(DEFAULT_APP_TRANSITION_DURATION);
574
575 // Quick fade-in from icon to app window
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700576 final int alphaDuration = DEFAULT_APP_TRANSITION_DURATION / 4;
577 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800578 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700579 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800580
581 AnimationSet set = new AnimationSet(false);
582 set.addAnimation(clipAnimLR);
583 set.addAnimation(clipAnimTB);
Chet Haase10e23ab2015-02-11 15:08:38 -0800584 set.addAnimation(translateY);
585 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700586 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800587 set.initialize(appWidth, appHeight, appWidth, appHeight);
588 anim = set;
589 } else {
590 final long duration;
591 switch (transit) {
592 case TRANSIT_ACTIVITY_OPEN:
593 case TRANSIT_ACTIVITY_CLOSE:
594 duration = mConfigShortAnimTime;
595 break;
596 default:
597 duration = DEFAULT_APP_TRANSITION_DURATION;
598 break;
599 }
600 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
601 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
602 // If we are on top of the wallpaper, we need an animation that
603 // correctly handles the wallpaper staying static behind all of
604 // the animated elements. To do this, will just have the existing
605 // element fade out.
606 anim = new AlphaAnimation(1, 0);
607 anim.setDetachWallpaper(true);
608 } else {
609 // For normal animations, the exiting element just holds in place.
610 anim = new AlphaAnimation(1, 1);
611 }
612 anim.setInterpolator(mDecelerateInterpolator);
613 anim.setDuration(duration);
614 anim.setFillAfter(true);
615 }
616 return anim;
617 }
618
Winson Chung399f6202014-03-19 10:47:20 -0700619 /**
620 * Prepares the specified animation with a standard duration, interpolator, etc.
621 */
Winson Chung5393dff2014-05-08 14:25:43 -0700622 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
623 int duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700624 if (duration > 0) {
625 a.setDuration(duration);
626 }
Winson Chung5393dff2014-05-08 14:25:43 -0700627 a.setFillAfter(true);
628 a.setInterpolator(interpolator);
629 a.initialize(appWidth, appHeight, appWidth, appHeight);
630 return a;
631 }
632
633 /**
634 * Prepares the specified animation with a standard duration, interpolator, etc.
635 */
Winson Chung399f6202014-03-19 10:47:20 -0700636 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800637 // Pick the desired duration. If this is an inter-activity transition,
638 // it is the standard duration for that. Otherwise we use the longer
639 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700640 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800641 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800642 case TRANSIT_ACTIVITY_OPEN:
643 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800644 duration = mConfigShortAnimTime;
645 break;
646 default:
647 duration = DEFAULT_APP_TRANSITION_DURATION;
648 break;
649 }
Winson Chung5393dff2014-05-08 14:25:43 -0700650 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
651 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800652 }
653
Winson Chung399f6202014-03-19 10:47:20 -0700654 /**
655 * Return the current thumbnail transition state.
656 */
657 int getThumbnailTransitionState(boolean enter) {
658 if (enter) {
659 if (mNextAppTransitionScaleUp) {
660 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
661 } else {
662 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
663 }
664 } else {
665 if (mNextAppTransitionScaleUp) {
666 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
667 } else {
668 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
669 }
670 }
671 }
672
673 /**
674 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700675 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700676 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700677 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, Bitmap thumbnailHeader,
678 final int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700679 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700680 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700681 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700682 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chung399f6202014-03-19 10:47:20 -0700683 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700684 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700685
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700686 float scaleW = appWidth / thumbWidth;
Winson Chunga4ccb862014-08-22 15:26:27 -0700687 float unscaledHeight = thumbHeight * scaleW;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700688 getNextAppTransitionStartRect(taskId, mTmpStartRect);
689 float unscaledStartY = mTmpStartRect.top - (unscaledHeight - thumbHeight) / 2f;
Winson Chung399f6202014-03-19 10:47:20 -0700690 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700691 // Animation up from the thumbnail to the full screen
692 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW,
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700693 mTmpStartRect.left + (thumbWidth / 2f), mTmpStartRect.top + (thumbHeight / 2f));
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700694 scale.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700695 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700696 Animation alpha = new AlphaAnimation(1, 0);
Winson Chunga4ccb862014-08-22 15:26:27 -0700697 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
698 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700699 final float toX = appRect.left + appRect.width() / 2 -
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700700 (mTmpStartRect.left + thumbWidth / 2);
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700701 final float toY = appRect.top + mNextAppTransitionInsets.top + -unscaledStartY;
702 Animation translate = new TranslateAnimation(0, toX, 0, toY);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700703 translate.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700704 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700705
706 // This AnimationSet uses the Interpolators assigned above.
707 AnimationSet set = new AnimationSet(false);
708 set.addAnimation(scale);
709 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -0700710 set.addAnimation(translate);
Winson Chung399f6202014-03-19 10:47:20 -0700711 a = set;
712 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700713 // Animation down from the full screen to the thumbnail
714 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f,
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700715 mTmpStartRect.left + (thumbWidth / 2f), mTmpStartRect.top + (thumbHeight / 2f));
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700716 scale.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700717 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
718 Animation alpha = new AlphaAnimation(0f, 1f);
719 alpha.setInterpolator(mThumbnailFadeInInterpolator);
720 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
721 Animation translate = new TranslateAnimation(0, 0, -unscaledStartY +
722 mNextAppTransitionInsets.top, 0);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700723 translate.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700724 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700725
Winson Chunga4ccb862014-08-22 15:26:27 -0700726 // This AnimationSet uses the Interpolators assigned above.
727 AnimationSet set = new AnimationSet(false);
728 set.addAnimation(scale);
729 set.addAnimation(alpha);
730 set.addAnimation(translate);
731 a = set;
732
733 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700734 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700735 mTouchResponseInterpolator);
Winson Chung399f6202014-03-19 10:47:20 -0700736 }
737
738 /**
739 * This alternate animation is created when we are doing a thumbnail transition, for the
740 * activity that is leaving, and the activity that is entering.
741 */
Winson Chunga4ccb862014-08-22 15:26:27 -0700742 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
743 int appWidth, int appHeight, int orientation, int transit, Rect containingFrame,
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700744 Rect contentInsets, @Nullable Rect surfaceInsets, boolean resizedWindow,
745 int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -0700746 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700747 getDefaultNextAppTransitionStartRect(mTmpStartRect);
748 final int thumbWidthI = mTmpStartRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700749 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700750 final int thumbHeightI = mTmpStartRect.height();
Winson Chung399f6202014-03-19 10:47:20 -0700751 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
752
Winson Chung2820c452014-04-15 15:34:44 -0700753 // Used for the ENTER_SCALE_UP and EXIT_SCALE_DOWN transitions
754 float scale = 1f;
755 int scaledTopDecor = 0;
756
Winson Chung399f6202014-03-19 10:47:20 -0700757 switch (thumbTransitState) {
758 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700759 if (resizedWindow) {
760 a = createAspectScaledThumbnailEnterNonFullscreenAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700761 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -0700762 } else {
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700763 mTmpFromClipRect.set(containingFrame);
764 // exclude top screen decor (status bar) region from the source clip.
765 mTmpFromClipRect.top = contentInsets.top;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700766 // App window scaling up to become full screen
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700767 mTmpToClipRect.set(containingFrame);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700768 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
769 // In portrait, we scale the width and clip to the top/left square
770 scale = thumbWidth / appWidth;
771 scaledTopDecor = (int) (scale * contentInsets.top);
772 int unscaledThumbHeight = (int) (thumbHeight / scale);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700773 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700774 } else {
775 // In landscape, we scale the height and clip to the top/left square
776 scale = thumbHeight / (appHeight - contentInsets.top);
777 scaledTopDecor = (int) (scale * contentInsets.top);
778 int unscaledThumbWidth = (int) (thumbWidth / scale);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700779 mTmpFromClipRect.right = mTmpFromClipRect.left + unscaledThumbWidth;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700780 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700781
782 mNextAppTransitionInsets.set(contentInsets);
783
784 Animation scaleAnim = new ScaleAnimation(scale, 1, scale, 1,
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700785 computePivot(mTmpStartRect.left, scale),
786 computePivot(mTmpStartRect.top, scale));
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700787 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
788 Animation translateAnim = new TranslateAnimation(0, 0, -scaledTopDecor, 0);
789
790 AnimationSet set = new AnimationSet(true);
791 set.addAnimation(clipAnim);
792 set.addAnimation(scaleAnim);
793 set.addAnimation(translateAnim);
794 a = set;
Winson Chung2820c452014-04-15 15:34:44 -0700795 }
Winson Chung399f6202014-03-19 10:47:20 -0700796 break;
797 }
798 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700799 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -0700800 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700801 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -0700802 // activity.
803 a = new AlphaAnimation(1, 0);
804 } else {
Winson Chung399f6202014-03-19 10:47:20 -0700805 a = new AlphaAnimation(1, 1);
806 }
807 break;
808 }
809 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700810 // Target app window during the scale down
811 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
812 // Fade in the destination activity if we are animating from a wallpaper
813 // activity.
814 a = new AlphaAnimation(0, 1);
815 } else {
816 a = new AlphaAnimation(1, 1);
817 }
Winson Chung399f6202014-03-19 10:47:20 -0700818 break;
819 }
820 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700821 // App window scaling down from full screen
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700822 mTmpFromClipRect.set(containingFrame);
823 mTmpToClipRect.set(containingFrame);
824 // exclude top screen decor (status bar) region from the destination clip.
825 mTmpToClipRect.top = contentInsets.top;
Winson Chung2820c452014-04-15 15:34:44 -0700826 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
827 // In portrait, we scale the width and clip to the top/left square
828 scale = thumbWidth / appWidth;
829 scaledTopDecor = (int) (scale * contentInsets.top);
830 int unscaledThumbHeight = (int) (thumbHeight / scale);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700831 mTmpToClipRect.bottom = mTmpToClipRect.top + unscaledThumbHeight;
Winson Chung2820c452014-04-15 15:34:44 -0700832 } else {
833 // In landscape, we scale the height and clip to the top/left square
834 scale = thumbHeight / (appHeight - contentInsets.top);
835 scaledTopDecor = (int) (scale * contentInsets.top);
836 int unscaledThumbWidth = (int) (thumbWidth / scale);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -0700837 mTmpToClipRect.right = mTmpToClipRect.left + unscaledThumbWidth;
Winson Chung2820c452014-04-15 15:34:44 -0700838 }
Wale Ogunwale35a57f82015-07-01 15:07:36 -0700839
Winson Chunga4ccb862014-08-22 15:26:27 -0700840 mNextAppTransitionInsets.set(contentInsets);
Winson Chung399f6202014-03-19 10:47:20 -0700841
842 Animation scaleAnim = new ScaleAnimation(1, scale, 1, scale,
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700843 computePivot(mTmpStartRect.left, scale),
844 computePivot(mTmpStartRect.top, scale));
Winson Chung2820c452014-04-15 15:34:44 -0700845 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Winson Chung399f6202014-03-19 10:47:20 -0700846 Animation translateAnim = new TranslateAnimation(0, 0, 0, -scaledTopDecor);
847
848 AnimationSet set = new AnimationSet(true);
Winson Chung399f6202014-03-19 10:47:20 -0700849 set.addAnimation(clipAnim);
850 set.addAnimation(scaleAnim);
851 set.addAnimation(translateAnim);
852
853 a = set;
854 a.setZAdjustment(Animation.ZORDER_TOP);
855 break;
856 }
857 default:
858 throw new RuntimeException("Invalid thumbnail transition state");
859 }
860
Winson Chungab79fce2014-11-04 16:15:22 -0800861 int duration = Math.max(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION,
862 THUMBNAIL_APP_TRANSITION_DURATION);
863 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700864 mTouchResponseInterpolator);
Winson Chung399f6202014-03-19 10:47:20 -0700865 }
866
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700867 private Animation createAspectScaledThumbnailEnterNonFullscreenAnimationLocked(
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -0700868 Rect frame, @Nullable Rect surfaceInsets, int taskId) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700869 getNextAppTransitionStartRect(taskId, mTmpStartRect);
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -0700870 float width = frame.width();
871 float height = frame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700872 float scaleWidth = mTmpStartRect.width() / width;
873 float scaleHeight = mTmpStartRect.height() / height;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700874 AnimationSet set = new AnimationSet(true);
875 int surfaceInsetsHorizontal = surfaceInsets == null
876 ? 0 : surfaceInsets.left + surfaceInsets.right;
877 int surfaceInsetsVertical = surfaceInsets == null
878 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
879 // We want the scaling to happen from the center of the surface. In order to achieve that,
880 // we need to account for surface insets that will be used to enlarge the surface.
881 ScaleAnimation scale = new ScaleAnimation(scaleWidth, 1, scaleHeight, 1,
882 (width + surfaceInsetsHorizontal) / 2, (height + surfaceInsetsVertical) / 2);
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700883 int fromX = mTmpStartRect.left + mTmpStartRect.width() / 2
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -0700884 - (frame.left + frame.width() / 2);
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700885 int fromY = mTmpStartRect.top + mTmpStartRect.height() / 2
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -0700886 - (frame.top + frame.height() / 2);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -0700887 TranslateAnimation translation = new TranslateAnimation(fromX, 0, fromY, 0);
888 set.addAnimation(scale);
889 set.addAnimation(translation);
890 return set;
891 }
892
Winson Chung399f6202014-03-19 10:47:20 -0700893 /**
Winson Chunga4ccb862014-08-22 15:26:27 -0700894 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700895 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -0700896 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700897 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
898 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700899 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700900 getDefaultNextAppTransitionStartRect(mTmpStartRect);
901 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -0700902 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700903 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -0700904 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
905
906 if (mNextAppTransitionScaleUp) {
907 // Animation for the thumbnail zooming from its initial size to the full screen
908 float scaleW = appWidth / thumbWidth;
909 float scaleH = appHeight / thumbHeight;
910 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700911 computePivot(mTmpStartRect.left, 1 / scaleW),
912 computePivot(mTmpStartRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -0700913 scale.setInterpolator(mDecelerateInterpolator);
914
915 Animation alpha = new AlphaAnimation(1, 0);
916 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
917
918 // This AnimationSet uses the Interpolators assigned above.
919 AnimationSet set = new AnimationSet(false);
920 set.addAnimation(scale);
921 set.addAnimation(alpha);
922 a = set;
923 } else {
924 // Animation for the thumbnail zooming down from the full screen to its final size
925 float scaleW = appWidth / thumbWidth;
926 float scaleH = appHeight / thumbHeight;
927 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700928 computePivot(mTmpStartRect.left, 1 / scaleW),
929 computePivot(mTmpStartRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -0700930 }
931
932 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
933 }
934
935 /**
Winson Chung399f6202014-03-19 10:47:20 -0700936 * This animation is created when we are doing a thumbnail transition, for the activity that is
937 * leaving, and the activity that is entering.
938 */
939 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, int appWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700940 int appHeight, int transit, int taskId) {
941 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -0700942 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700943 getDefaultNextAppTransitionStartRect(mTmpStartRect);
944 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -0700945 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700946 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -0700947 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
948
949 switch (thumbTransitState) {
950 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
951 // Entering app scales up with the thumbnail
952 float scaleW = thumbWidth / appWidth;
953 float scaleH = thumbHeight / appHeight;
954 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700955 computePivot(mTmpStartRect.left, scaleW),
956 computePivot(mTmpStartRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -0700957 break;
958 }
959 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
960 // Exiting app while the thumbnail is scaling up should fade or stay in place
961 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
962 // Fade out while bringing up selected activity. This keeps the
963 // current activity from showing through a launching wallpaper
964 // activity.
965 a = new AlphaAnimation(1, 0);
966 } else {
967 // noop animation
968 a = new AlphaAnimation(1, 1);
969 }
970 break;
971 }
972 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
973 // Entering the other app, it should just be visible while we scale the thumbnail
974 // down above it
975 a = new AlphaAnimation(1, 1);
976 break;
977 }
978 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
979 // Exiting the current app, the app should scale down with the thumbnail
980 float scaleW = thumbWidth / appWidth;
981 float scaleH = thumbHeight / appHeight;
982 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700983 computePivot(mTmpStartRect.left, scaleW),
984 computePivot(mTmpStartRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -0700985
986 Animation alpha = new AlphaAnimation(1, 0);
987
988 AnimationSet set = new AnimationSet(true);
989 set.addAnimation(scale);
990 set.addAnimation(alpha);
991 set.setZAdjustment(Animation.ZORDER_TOP);
992 a = set;
993 break;
994 }
995 default:
996 throw new RuntimeException("Invalid thumbnail transition state");
997 }
998
999 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1000 }
1001
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001002 private Animation createRelaunchAnimation(int appWidth, int appHeight,
1003 Rect containingFrame) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001004 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1005 final int left = mTmpFromClipRect.left;
1006 final int top = mTmpFromClipRect.top;
1007 mTmpFromClipRect.offset(-left, -top);
1008 mTmpToClipRect.set(0, 0, appWidth, appHeight);
1009 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001010 float fromWidth = mTmpFromClipRect.width();
1011 float toWidth = mTmpToClipRect.width();
1012 float fromHeight = mTmpFromClipRect.height();
1013 float toHeight = mTmpToClipRect.height();
1014 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1015 // The final window is larger in both dimensions than current window (e.g. we are
1016 // maximizing), so we can simply unclip the new window and there will be no disappearing
1017 // frame.
1018 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1019 } else {
1020 // The disappearing window has one larger dimension. We need to apply scaling, so the
1021 // first frame of the entry animation matches the old window.
1022 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
1023 }
1024
1025 // We might not be going exactly full screen, but instead be aligned under the status bar.
1026 // We need to take this into account when creating the translate animation.
1027 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
1028 0, top - containingFrame.top, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001029 set.addAnimation(translate);
1030 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001031 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001032 return set;
1033 }
1034
Jorim Jaggic554b772015-06-04 16:07:57 -07001035 /**
1036 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1037 * frame of the transition doesn't change the visuals on screen, so we can start
1038 * directly with the second one
1039 */
1040 boolean canSkipFirstFrame() {
1041 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1042 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
1043 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1044 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001045
1046 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001047 int appWidth, int appHeight, int orientation, Rect containingFrame, Rect contentInsets,
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001048 @Nullable Rect surfaceInsets, Rect appFrame, boolean isVoiceInteraction,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001049 boolean resizedWindow, int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001050 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001051 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
1052 || transit == TRANSIT_TASK_OPEN
1053 || transit == TRANSIT_TASK_TO_FRONT)) {
1054 a = loadAnimationRes(lp, enter
1055 ? com.android.internal.R.anim.voice_activity_open_enter
1056 : com.android.internal.R.anim.voice_activity_open_exit);
1057 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1058 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001059 + " anim=" + a + " transit=" + appTransitionToString(transit)
1060 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001061 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1062 || transit == TRANSIT_TASK_CLOSE
1063 || transit == TRANSIT_TASK_TO_BACK)) {
1064 a = loadAnimationRes(lp, enter
1065 ? com.android.internal.R.anim.voice_activity_close_enter
1066 : com.android.internal.R.anim.voice_activity_close_exit);
1067 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1068 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001069 + " anim=" + a + " transit=" + appTransitionToString(transit)
1070 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001071 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001072 a = createRelaunchAnimation(appWidth, appHeight, containingFrame);
1073 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1074 "applyAnimation:"
1075 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1076 + " transit=" + appTransitionToString(transit)
1077 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001078 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1079 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001080 mNextAppTransitionEnter : mNextAppTransitionExit);
1081 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1082 "applyAnimation:"
1083 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001084 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001085 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001086 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1087 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1088 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1089 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001090 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1091 + " transit=" + appTransitionToString(transit)
1092 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001093 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Craig Mautner80b1f642015-04-22 10:59:09 -07001094 a = createClipRevealAnimationLocked(transit, enter, appFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001095 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1096 "applyAnimation:"
1097 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001098 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001099 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001100 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001101 a = createScaleUpAnimationLocked(transit, enter, appWidth, appHeight);
1102 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1103 "applyAnimation:"
1104 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001105 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001106 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001107 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1108 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001109 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001110 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001111 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001112 appWidth, appHeight, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001113 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1114 String animName = mNextAppTransitionScaleUp ?
1115 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1116 Slog.v(TAG, "applyAnimation:"
1117 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001118 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001119 + " Callers=" + Debug.getCallers(3));
1120 }
1121 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1122 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1123 mNextAppTransitionScaleUp =
1124 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1125 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001126 getThumbnailTransitionState(enter), appWidth, appHeight, orientation, transit,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001127 containingFrame, contentInsets, surfaceInsets, resizedWindow, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001128 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1129 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001130 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001131 Slog.v(TAG, "applyAnimation:"
1132 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001133 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001134 + " Callers=" + Debug.getCallers(3));
1135 }
1136 } else {
1137 int animAttr = 0;
1138 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001139 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001140 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001141 ? WindowAnimation_activityOpenEnterAnimation
1142 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001143 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001144 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001145 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001146 ? WindowAnimation_activityCloseEnterAnimation
1147 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001148 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001149 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001150 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001151 ? WindowAnimation_taskOpenEnterAnimation
1152 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001153 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001154 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001155 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001156 ? WindowAnimation_taskCloseEnterAnimation
1157 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001158 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001159 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001160 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001161 ? WindowAnimation_taskToFrontEnterAnimation
1162 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001163 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001164 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001165 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001166 ? WindowAnimation_taskToBackEnterAnimation
1167 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001168 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001169 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001170 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001171 ? WindowAnimation_wallpaperOpenEnterAnimation
1172 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001173 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001174 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001175 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001176 ? WindowAnimation_wallpaperCloseEnterAnimation
1177 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001178 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001179 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001180 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001181 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1182 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001183 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001184 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001185 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001186 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1187 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001188 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001189 case TRANSIT_TASK_OPEN_BEHIND:
1190 animAttr = enter
1191 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001192 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001193 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001194 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001195 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1196 "applyAnimation:"
1197 + " anim=" + a
1198 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001199 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001200 + " Callers=" + Debug.getCallers(3));
1201 }
1202 return a;
1203 }
1204
1205 void postAnimationCallback() {
1206 if (mNextAppTransitionCallback != null) {
1207 mH.sendMessage(mH.obtainMessage(H.DO_ANIMATION_CALLBACK, mNextAppTransitionCallback));
1208 mNextAppTransitionCallback = null;
1209 }
1210 }
1211
1212 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001213 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001214 if (isTransitionSet()) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001215 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001216 mNextAppTransitionPackage = packageName;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001217 mNextAppTransitionAnimationsSpecs.clear();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001218 mNextAppTransitionEnter = enterAnim;
1219 mNextAppTransitionExit = exitAnim;
1220 postAnimationCallback();
1221 mNextAppTransitionCallback = startedCallback;
1222 } else {
1223 postAnimationCallback();
1224 }
1225 }
1226
1227 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001228 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001229 if (isTransitionSet()) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001230 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001231 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001232 mNextAppTransitionAnimationsSpecs.clear();
1233 putDefaultNextAppTransitionCoordinates(startX, startY, startX + startWidth,
1234 startY + startHeight);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001235 postAnimationCallback();
1236 mNextAppTransitionCallback = null;
1237 }
1238 }
1239
Chet Haase10e23ab2015-02-11 15:08:38 -08001240 void overridePendingAppTransitionClipReveal(int startX, int startY,
1241 int startWidth, int startHeight) {
1242 if (isTransitionSet()) {
1243 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001244 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight);
Chet Haase10e23ab2015-02-11 15:08:38 -08001245 postAnimationCallback();
1246 mNextAppTransitionCallback = null;
1247 }
1248 }
1249
Craig Mautner164d4bb2012-11-26 13:51:23 -08001250 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1251 IRemoteCallback startedCallback, boolean scaleUp) {
1252 if (isTransitionSet()) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001253 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1254 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001255 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001256 mNextAppTransitionAnimationsSpecs.clear();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001257 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001258 putDefaultNextAppTransitionCoordinates(startX, startY, 0 ,0);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001259 postAnimationCallback();
1260 mNextAppTransitionCallback = startedCallback;
1261 } else {
1262 postAnimationCallback();
1263 }
1264 }
1265
Winson Chunga4ccb862014-08-22 15:26:27 -07001266 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001267 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001268 if (isTransitionSet()) {
1269 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1270 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
1271 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001272 mNextAppTransitionAnimationsSpecs.clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001273 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001274 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight);
Winson Chunga4ccb862014-08-22 15:26:27 -07001275 postAnimationCallback();
1276 mNextAppTransitionCallback = startedCallback;
1277 } else {
1278 postAnimationCallback();
1279 }
1280 }
1281
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001282 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
1283 IRemoteCallback callback, boolean scaleUp) {
1284 if (isTransitionSet()) {
1285 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1286 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
1287 mNextAppTransitionPackage = null;
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001288 mDefaultNextAppTransitionAnimationSpec = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001289 mNextAppTransitionAnimationsSpecs.clear();
1290 mNextAppTransitionScaleUp = scaleUp;
1291 for (int i = 0; i < specs.length; i++) {
1292 AppTransitionAnimationSpec spec = specs[i];
1293 if (spec != null) {
1294 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001295 if (i == 0) {
1296 // In full screen mode, the transition code depends on the default spec to
1297 // be set.
1298 Rect rect = spec.rect;
1299 putDefaultNextAppTransitionCoordinates(rect.left, rect.top, rect.width(),
1300 rect.height());
1301 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001302 }
1303 }
1304 postAnimationCallback();
1305 mNextAppTransitionCallback = callback;
1306 } else {
1307 postAnimationCallback();
1308 }
1309 }
1310
Winson Chung044d5292014-11-06 11:05:19 -08001311 void overrideInPlaceAppTransition(String packageName, int anim) {
1312 if (isTransitionSet()) {
1313 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1314 mNextAppTransitionPackage = packageName;
1315 mNextAppTransitionInPlace = anim;
1316 } else {
1317 postAnimationCallback();
1318 }
1319 }
1320
Craig Mautner164d4bb2012-11-26 13:51:23 -08001321 @Override
1322 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001323 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001324 }
1325
Craig Mautner4b71aa12012-12-27 17:20:01 -08001326 /**
1327 * Returns the human readable name of a window transition.
1328 *
1329 * @param transition The window transition.
1330 * @return The transition symbolic name.
1331 */
1332 public static String appTransitionToString(int transition) {
1333 switch (transition) {
1334 case TRANSIT_UNSET: {
1335 return "TRANSIT_UNSET";
1336 }
1337 case TRANSIT_NONE: {
1338 return "TRANSIT_NONE";
1339 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001340 case TRANSIT_ACTIVITY_OPEN: {
1341 return "TRANSIT_ACTIVITY_OPEN";
1342 }
1343 case TRANSIT_ACTIVITY_CLOSE: {
1344 return "TRANSIT_ACTIVITY_CLOSE";
1345 }
1346 case TRANSIT_TASK_OPEN: {
1347 return "TRANSIT_TASK_OPEN";
1348 }
1349 case TRANSIT_TASK_CLOSE: {
1350 return "TRANSIT_TASK_CLOSE";
1351 }
1352 case TRANSIT_TASK_TO_FRONT: {
1353 return "TRANSIT_TASK_TO_FRONT";
1354 }
1355 case TRANSIT_TASK_TO_BACK: {
1356 return "TRANSIT_TASK_TO_BACK";
1357 }
1358 case TRANSIT_WALLPAPER_CLOSE: {
1359 return "TRANSIT_WALLPAPER_CLOSE";
1360 }
1361 case TRANSIT_WALLPAPER_OPEN: {
1362 return "TRANSIT_WALLPAPER_OPEN";
1363 }
1364 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1365 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1366 }
1367 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1368 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1369 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001370 case TRANSIT_TASK_OPEN_BEHIND: {
1371 return "TRANSIT_TASK_OPEN_BEHIND";
1372 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001373 case TRANSIT_ACTIVITY_RELAUNCH: {
1374 return "TRANSIT_ACTIVITY_RELAUNCH";
1375 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001376 default: {
1377 return "<UNKNOWN>";
1378 }
1379 }
1380 }
1381
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001382 private String appStateToString() {
1383 switch (mAppTransitionState) {
1384 case APP_STATE_IDLE:
1385 return "APP_STATE_IDLE";
1386 case APP_STATE_READY:
1387 return "APP_STATE_READY";
1388 case APP_STATE_RUNNING:
1389 return "APP_STATE_RUNNING";
1390 case APP_STATE_TIMEOUT:
1391 return "APP_STATE_TIMEOUT";
1392 default:
1393 return "unknown state=" + mAppTransitionState;
1394 }
1395 }
1396
1397 private String transitTypeToString() {
1398 switch (mNextAppTransitionType) {
1399 case NEXT_TRANSIT_TYPE_NONE:
1400 return "NEXT_TRANSIT_TYPE_NONE";
1401 case NEXT_TRANSIT_TYPE_CUSTOM:
1402 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001403 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1404 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001405 case NEXT_TRANSIT_TYPE_SCALE_UP:
1406 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1407 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1408 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1409 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1410 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001411 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1412 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1413 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1414 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001415 default:
1416 return "unknown type=" + mNextAppTransitionType;
1417 }
1418 }
1419
Craig Mautner164d4bb2012-11-26 13:51:23 -08001420 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001421 public void dump(PrintWriter pw, String prefix) {
1422 pw.print(prefix); pw.println(this);
1423 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001424 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001425 pw.print(prefix); pw.print("mNextAppTransitionType=");
1426 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001427 }
1428 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001429 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001430 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001431 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001432 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001433 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1434 pw.print(" mNextAppTransitionExit=0x");
1435 pw.println(Integer.toHexString(mNextAppTransitionExit));
1436 break;
Winson Chung044d5292014-11-06 11:05:19 -08001437 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001438 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001439 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001440 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001441 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1442 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001443 case NEXT_TRANSIT_TYPE_SCALE_UP: {
1444 getDefaultNextAppTransitionStartRect(mTmpStartRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001445 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001446 pw.print(mTmpStartRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001447 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001448 pw.println(mTmpStartRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001449 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001450 pw.print(mTmpStartRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001451 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001452 pw.println(mTmpStartRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001453 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001454 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001455 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1456 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001457 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001458 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1459 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1460 pw.println(mDefaultNextAppTransitionAnimationSpec);
1461 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1462 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001463 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1464 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001465 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001466 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001467 }
1468 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001469 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1470 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001471 }
1472 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001473
1474 public void setCurrentUser(int newUserId) {
1475 mCurrentUserId = newUserId;
1476 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001477
1478 /**
1479 * @return true if transition is not running and should not be skipped, false if transition is
1480 * already running
1481 */
1482 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent) {
1483 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
1484 + " transit=" + appTransitionToString(transit)
1485 + " " + this
1486 + " alwaysKeepCurrent=" + alwaysKeepCurrent
1487 + " Callers=" + Debug.getCallers(3));
1488 if (!isTransitionSet() || mNextAppTransition == TRANSIT_NONE) {
1489 setAppTransition(transit);
1490 } else if (!alwaysKeepCurrent) {
1491 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
1492 // Opening a new task always supersedes a close for the anim.
1493 setAppTransition(transit);
1494 } else if (transit == TRANSIT_ACTIVITY_OPEN
1495 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
1496 // Opening a new activity always supersedes a close for the anim.
1497 setAppTransition(transit);
1498 }
1499 }
1500 boolean prepared = prepare();
1501 if (isTransitionSet()) {
1502 mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
1503 mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
1504 }
1505 return prepared;
1506 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001507}