blob: 7bd0635a814a085ef05b8d28838a6e546371f93c [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
Craig Mautner164d4bb2012-11-26 13:51:23 -080019import android.content.Context;
Winson Chung2820c452014-04-15 15:34:44 -070020import android.content.res.Configuration;
Craig Mautner164d4bb2012-11-26 13:51:23 -080021import android.graphics.Bitmap;
Winson Chung399f6202014-03-19 10:47:20 -070022import android.graphics.Rect;
Craig Mautner164d4bb2012-11-26 13:51:23 -080023import android.os.Debug;
24import android.os.Handler;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010025import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080026import android.os.IRemoteCallback;
27import android.util.Slog;
28import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080029import android.view.animation.AlphaAnimation;
30import android.view.animation.Animation;
31import android.view.animation.AnimationSet;
32import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070033import android.view.animation.ClipRectAnimation;
Chet Haase10e23ab2015-02-11 15:08:38 -080034import android.view.animation.ClipRectLRAnimation;
35import android.view.animation.ClipRectTBAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080036import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070037import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080038import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070039import android.view.animation.TranslateAnimation;
Chet Haase10e23ab2015-02-11 15:08:38 -080040import android.view.animation.TranslateYAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070041
Craig Mautner164d4bb2012-11-26 13:51:23 -080042import com.android.internal.util.DumpUtils.Dump;
43import com.android.server.AttributeCache;
44import com.android.server.wm.WindowManagerService.H;
45
46import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010047import java.util.ArrayList;
Craig Mautner164d4bb2012-11-26 13:51:23 -080048
Jorim Jaggi77ba4802015-02-18 13:57:50 +010049import static android.view.WindowManagerInternal.AppTransitionListener;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080050import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
51import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070052import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
53import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -070054import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070055import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080056import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
57import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070058import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
59import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080060import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
61import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070062import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
63import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080064import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
65import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080066import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
67import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070068import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
69import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
70import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
71import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080072
Craig Mautner164d4bb2012-11-26 13:51:23 -080073// State management of app transitions. When we are preparing for a
74// transition, mNextAppTransition will be the kind of transition to
75// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
76// mOpeningApps and mClosingApps are the lists of tokens that will be
77// made visible or hidden at the next transition.
78public class AppTransition implements Dump {
79 private static final String TAG = "AppTransition";
Craig Mautner321bdf52012-12-18 09:53:24 -080080 private static final boolean DEBUG_APP_TRANSITIONS =
81 WindowManagerService.DEBUG_APP_TRANSITIONS;
82 private static final boolean DEBUG_ANIM = WindowManagerService.DEBUG_ANIM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070083 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080084
Craig Mautner4b71aa12012-12-27 17:20:01 -080085 /** Not set up for a transition. */
86 public static final int TRANSIT_UNSET = -1;
87 /** No animation for transition. */
88 public static final int TRANSIT_NONE = 0;
89 /** 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 -070090 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -080091 /** The window in the top-most activity is being closed to reveal the
92 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -070093 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -080094 /** A window in a new task is being opened on top of an existing one
95 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -070096 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -080097 /** A window in the top-most activity is being closed to reveal the
98 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -070099 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800100 /** A window in an existing task is being displayed on top of an existing one
101 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700102 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800103 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700104 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800105 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
106 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700107 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800108 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
109 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700110 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800111 /** A window in a new activity is being opened on top of an existing one, and both are on top
112 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700113 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800114 /** The window in the top-most activity is being closed to reveal the previous activity, and
115 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700116 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
117 /** A window in a new task is being opened behind an existing one in another activity's task.
118 * The new window will show briefly and then be gone. */
119 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800120 /** A window in a task is being animated in-place. */
121 public static final int TRANSIT_TASK_IN_PLACE = 17;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800122
Winson Chunga4ccb862014-08-22 15:26:27 -0700123 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700124 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800125 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700126 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800127
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700128 private static final int DEFAULT_APP_TRANSITION_DURATION = 336;
129 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
130 private static final int THUMBNAIL_APP_TRANSITION_ALPHA_DURATION = 336;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800131
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800132 private final Context mContext;
133 private final Handler mH;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800134
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800135 private int mNextAppTransition = TRANSIT_UNSET;
136
137 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
138 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
139 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
140 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
141 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700142 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
143 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800144 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800145 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800146 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
147
Winson Chung399f6202014-03-19 10:47:20 -0700148 // These are the possible states for the enter/exit activities during a thumbnail transition
149 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
150 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
151 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
152 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
153
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800154 private String mNextAppTransitionPackage;
155 private Bitmap mNextAppTransitionThumbnail;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800156 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800157 private boolean mNextAppTransitionScaleUp;
158 private IRemoteCallback mNextAppTransitionCallback;
159 private int mNextAppTransitionEnter;
160 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800161 private int mNextAppTransitionInPlace;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800162 private int mNextAppTransitionStartX;
163 private int mNextAppTransitionStartY;
164 private int mNextAppTransitionStartWidth;
165 private int mNextAppTransitionStartHeight;
Winson Chunga4ccb862014-08-22 15:26:27 -0700166 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800167
Winson Chung2820c452014-04-15 15:34:44 -0700168 private Rect mTmpFromClipRect = new Rect();
169 private Rect mTmpToClipRect = new Rect();
170
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800171 private final static int APP_STATE_IDLE = 0;
172 private final static int APP_STATE_READY = 1;
173 private final static int APP_STATE_RUNNING = 2;
174 private final static int APP_STATE_TIMEOUT = 3;
175 private int mAppTransitionState = APP_STATE_IDLE;
176
177 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800178 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700179 private final Interpolator mThumbnailFadeInInterpolator;
180 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800181 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700182 private final Interpolator mFastOutLinearInInterpolator;
183 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
184
185 /** Interpolator to be used for animations that respond directly to a touch */
186 private final Interpolator mTouchResponseInterpolator =
187 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
188
189 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800190
Amith Yamasani4befbec2013-07-10 16:18:01 -0700191 private int mCurrentUserId = 0;
192
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100193 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
194
Craig Mautner164d4bb2012-11-26 13:51:23 -0800195 AppTransition(Context context, Handler h) {
196 mContext = context;
197 mH = h;
Chet Haase10e23ab2015-02-11 15:08:38 -0800198 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
199 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700200 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
201 com.android.internal.R.interpolator.fast_out_linear_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800202 mConfigShortAnimTime = context.getResources().getInteger(
203 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800204 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
205 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700206 mThumbnailFadeInInterpolator = new Interpolator() {
207 @Override
208 public float getInterpolation(float input) {
209 // Linear response for first fraction, then complete after that.
210 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
211 return 0f;
212 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700213 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700214 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700215 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700216 }
217 };
218 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800219 @Override
220 public float getInterpolation(float input) {
221 // Linear response for first fraction, then complete after that.
222 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700223 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
224 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800225 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700226 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800227 }
228 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700229 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
230 * mContext.getResources().getDisplayMetrics().density);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800231 }
232
233 boolean isTransitionSet() {
234 return mNextAppTransition != TRANSIT_UNSET;
235 }
236
237 boolean isTransitionNone() {
238 return mNextAppTransition == TRANSIT_NONE;
239 }
240
241 boolean isTransitionEqual(int transit) {
242 return mNextAppTransition == transit;
243 }
244
245 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800246 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800247 }
248
249 void setAppTransition(int transit) {
250 mNextAppTransition = transit;
251 }
252
253 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800254 return mAppTransitionState == APP_STATE_READY
255 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800256 }
257
Craig Mautnerae446592012-12-06 19:05:05 -0800258 void setReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800259 mAppTransitionState = APP_STATE_READY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800260 }
261
262 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800263 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800264 }
265
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800266 void setIdle() {
267 mAppTransitionState = APP_STATE_IDLE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800268 }
269
270 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800271 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800272 }
273
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800274 void setTimeout() {
275 mAppTransitionState = APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800276 }
277
278 Bitmap getNextAppTransitionThumbnail() {
279 return mNextAppTransitionThumbnail;
280 }
281
Winson Chunga4ccb862014-08-22 15:26:27 -0700282 /** Returns whether the next thumbnail transition is aspect scaled up. */
283 boolean isNextThumbnailTransitionAspectScaled() {
284 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
285 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
286 }
287
288 /** Returns whether the next thumbnail transition is scaling up. */
289 boolean isNextThumbnailTransitionScaleUp() {
290 return mNextAppTransitionScaleUp;
291 }
292
293 int getStartingX() {
294 return mNextAppTransitionStartX;
295 }
296
297 int getStartingY() {
298 return mNextAppTransitionStartY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800299 }
300
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700301 boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800302 if (!isRunning()) {
303 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100304 notifyAppTransitionPendingLocked();
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700305 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800306 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700307 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800308 }
309
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100310 void goodToGo(AppWindowAnimator openingAppAnimator, AppWindowAnimator closingAppAnimator) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800311 mNextAppTransition = TRANSIT_UNSET;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800312 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100313 notifyAppTransitionStartingLocked(
314 openingAppAnimator != null ? openingAppAnimator.mAppToken.token : null,
315 closingAppAnimator != null ? closingAppAnimator.mAppToken.token : null,
316 openingAppAnimator != null ? openingAppAnimator.animation : null,
317 closingAppAnimator != null ? closingAppAnimator.animation : null);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800318 }
319
320 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800321 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800322 mNextAppTransitionPackage = null;
323 mNextAppTransitionThumbnail = null;
324 }
325
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800326 void freeze() {
327 setAppTransition(AppTransition.TRANSIT_UNSET);
328 clear();
329 setReady();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100330 notifyAppTransitionCancelledLocked();
331 }
332
333 void registerListenerLocked(AppTransitionListener listener) {
334 mListeners.add(listener);
335 }
336
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700337 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100338 for (int i = 0; i < mListeners.size(); i++) {
339 mListeners.get(i).onAppTransitionFinishedLocked(token);
340 }
341 }
342
343 private void notifyAppTransitionPendingLocked() {
344 for (int i = 0; i < mListeners.size(); i++) {
345 mListeners.get(i).onAppTransitionPendingLocked();
346 }
347 }
348
349 private void notifyAppTransitionCancelledLocked() {
350 for (int i = 0; i < mListeners.size(); i++) {
351 mListeners.get(i).onAppTransitionCancelledLocked();
352 }
353 }
354
355 private void notifyAppTransitionStartingLocked(IBinder openToken,
356 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
357 for (int i = 0; i < mListeners.size(); i++) {
358 mListeners.get(i).onAppTransitionStartingLocked(openToken, closeToken, openAnimation,
359 closeAnimation);
360 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800361 }
362
Craig Mautner164d4bb2012-11-26 13:51:23 -0800363 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
364 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
365 + (lp != null ? lp.packageName : null)
366 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
367 if (lp != null && lp.windowAnimations != 0) {
368 // If this is a system resource, don't try to load it from the
369 // application resources. It is nice to avoid loading application
370 // resources if we can.
371 String packageName = lp.packageName != null ? lp.packageName : "android";
372 int resId = lp.windowAnimations;
373 if ((resId&0xFF000000) == 0x01000000) {
374 packageName = "android";
375 }
376 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
377 + packageName);
378 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700379 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800380 }
381 return null;
382 }
383
384 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
385 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
386 + packageName + " resId=0x" + Integer.toHexString(resId));
387 if (packageName != null) {
388 if ((resId&0xFF000000) == 0x01000000) {
389 packageName = "android";
390 }
391 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
392 + packageName);
393 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700394 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800395 }
396 return null;
397 }
398
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700399 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800400 int anim = 0;
401 Context context = mContext;
402 if (animAttr >= 0) {
403 AttributeCache.Entry ent = getCachedAnimations(lp);
404 if (ent != null) {
405 context = ent.context;
406 anim = ent.array.getResourceId(animAttr, 0);
407 }
408 }
409 if (anim != 0) {
410 return AnimationUtils.loadAnimation(context, anim);
411 }
412 return null;
413 }
414
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700415 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
416 Context context = mContext;
417 if (resId >= 0) {
418 AttributeCache.Entry ent = getCachedAnimations(lp);
419 if (ent != null) {
420 context = ent.context;
421 }
422 return AnimationUtils.loadAnimation(context, resId);
423 }
424 return null;
425 }
426
427 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800428 int anim = 0;
429 Context context = mContext;
430 if (resId >= 0) {
431 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
432 if (ent != null) {
433 context = ent.context;
434 anim = resId;
435 }
436 }
437 if (anim != 0) {
438 return AnimationUtils.loadAnimation(context, anim);
439 }
440 return null;
441 }
442
Craig Mautner164d4bb2012-11-26 13:51:23 -0800443 /**
444 * Compute the pivot point for an animation that is scaling from a small
445 * rect on screen to a larger rect. The pivot point varies depending on
446 * the distance between the inner and outer edges on both sides. This
447 * function computes the pivot point for one dimension.
448 * @param startPos Offset from left/top edge of outer rectangle to
449 * left/top edge of inner rectangle.
450 * @param finalScale The scaling factor between the size of the outer
451 * and inner rectangles.
452 */
453 private static float computePivot(int startPos, float finalScale) {
454 final float denom = finalScale-1;
455 if (Math.abs(denom) < .0001f) {
456 return startPos;
457 }
458 return -startPos / denom;
459 }
460
461 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
462 int appWidth, int appHeight) {
463 Animation a = null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800464 if (enter) {
465 // Entering app zooms out from the center of the initial rect.
466 float scaleW = mNextAppTransitionStartWidth / (float) appWidth;
467 float scaleH = mNextAppTransitionStartHeight / (float) appHeight;
468 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
469 computePivot(mNextAppTransitionStartX, scaleW),
470 computePivot(mNextAppTransitionStartY, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800471 scale.setInterpolator(mDecelerateInterpolator);
472
Craig Mautner164d4bb2012-11-26 13:51:23 -0800473 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700474 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800475
476 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800477 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800478 set.addAnimation(alpha);
479 set.setDetachWallpaper(true);
480 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800481 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
482 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800483 // If we are on top of the wallpaper, we need an animation that
484 // correctly handles the wallpaper staying static behind all of
485 // the animated elements. To do this, will just have the existing
486 // element fade out.
487 a = new AlphaAnimation(1, 0);
488 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800489 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800490 // For normal animations, the exiting element just holds in place.
491 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800492 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800493
494 // Pick the desired duration. If this is an inter-activity transition,
495 // it is the standard duration for that. Otherwise we use the longer
496 // task transition duration.
497 final long duration;
498 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800499 case TRANSIT_ACTIVITY_OPEN:
500 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800501 duration = mConfigShortAnimTime;
502 break;
503 default:
504 duration = DEFAULT_APP_TRANSITION_DURATION;
505 break;
506 }
507 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800508 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800509 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800510 a.initialize(appWidth, appHeight, appWidth, appHeight);
511 return a;
512 }
513
Craig Mautner80b1f642015-04-22 10:59:09 -0700514 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800515 final Animation anim;
516 if (enter) {
517 // Reveal will expand and move faster in horizontal direction
518
Craig Mautner80b1f642015-04-22 10:59:09 -0700519 final int appWidth = appFrame.width();
520 final int appHeight = appFrame.height();
521
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700522 float t = 0f;
523 if (appHeight > 0) {
524 t = (float) mNextAppTransitionStartY / appHeight;
525 }
526 int translationY = mClipRevealTranslationY
527 + (int)(appHeight / 7f * t);
528
529 int centerX = mNextAppTransitionStartX + mNextAppTransitionStartWidth / 2;
530 int centerY = mNextAppTransitionStartY + mNextAppTransitionStartHeight / 2;
531
532 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800533 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggib00dbd42015-07-01 12:54:58 -0700534 centerX - mNextAppTransitionStartWidth / 2,
535 centerX + mNextAppTransitionStartWidth / 2,
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700536 0, appWidth);
537 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
538 clipAnimLR.setDuration((long) (DEFAULT_APP_TRANSITION_DURATION / 2.5f));
Chet Haase10e23ab2015-02-11 15:08:38 -0800539 Animation clipAnimTB = new ClipRectTBAnimation(
Jorim Jaggib00dbd42015-07-01 12:54:58 -0700540 centerY - mNextAppTransitionStartHeight / 2 - translationY,
541 centerY + mNextAppTransitionStartHeight / 2 - translationY,
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700542 0, appHeight);
543 clipAnimTB.setInterpolator(mTouchResponseInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800544 clipAnimTB.setDuration(DEFAULT_APP_TRANSITION_DURATION);
545
Chet Haase10e23ab2015-02-11 15:08:38 -0800546 TranslateYAnimation translateY = new TranslateYAnimation(
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700547 Animation.ABSOLUTE, translationY, Animation.ABSOLUTE, 0);
548 translateY.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800549 translateY.setDuration(DEFAULT_APP_TRANSITION_DURATION);
550
551 // Quick fade-in from icon to app window
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700552 final int alphaDuration = DEFAULT_APP_TRANSITION_DURATION / 4;
553 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800554 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700555 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800556
557 AnimationSet set = new AnimationSet(false);
558 set.addAnimation(clipAnimLR);
559 set.addAnimation(clipAnimTB);
Chet Haase10e23ab2015-02-11 15:08:38 -0800560 set.addAnimation(translateY);
561 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700562 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800563 set.initialize(appWidth, appHeight, appWidth, appHeight);
564 anim = set;
565 } else {
566 final long duration;
567 switch (transit) {
568 case TRANSIT_ACTIVITY_OPEN:
569 case TRANSIT_ACTIVITY_CLOSE:
570 duration = mConfigShortAnimTime;
571 break;
572 default:
573 duration = DEFAULT_APP_TRANSITION_DURATION;
574 break;
575 }
576 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
577 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
578 // If we are on top of the wallpaper, we need an animation that
579 // correctly handles the wallpaper staying static behind all of
580 // the animated elements. To do this, will just have the existing
581 // element fade out.
582 anim = new AlphaAnimation(1, 0);
583 anim.setDetachWallpaper(true);
584 } else {
585 // For normal animations, the exiting element just holds in place.
586 anim = new AlphaAnimation(1, 1);
587 }
588 anim.setInterpolator(mDecelerateInterpolator);
589 anim.setDuration(duration);
590 anim.setFillAfter(true);
591 }
592 return anim;
593 }
594
Winson Chung399f6202014-03-19 10:47:20 -0700595 /**
596 * Prepares the specified animation with a standard duration, interpolator, etc.
597 */
Winson Chung5393dff2014-05-08 14:25:43 -0700598 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
599 int duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700600 if (duration > 0) {
601 a.setDuration(duration);
602 }
Winson Chung5393dff2014-05-08 14:25:43 -0700603 a.setFillAfter(true);
604 a.setInterpolator(interpolator);
605 a.initialize(appWidth, appHeight, appWidth, appHeight);
606 return a;
607 }
608
609 /**
610 * Prepares the specified animation with a standard duration, interpolator, etc.
611 */
Winson Chung399f6202014-03-19 10:47:20 -0700612 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800613 // Pick the desired duration. If this is an inter-activity transition,
614 // it is the standard duration for that. Otherwise we use the longer
615 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700616 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800617 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800618 case TRANSIT_ACTIVITY_OPEN:
619 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800620 duration = mConfigShortAnimTime;
621 break;
622 default:
623 duration = DEFAULT_APP_TRANSITION_DURATION;
624 break;
625 }
Winson Chung5393dff2014-05-08 14:25:43 -0700626 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
627 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800628 }
629
Winson Chung399f6202014-03-19 10:47:20 -0700630 /**
631 * Return the current thumbnail transition state.
632 */
633 int getThumbnailTransitionState(boolean enter) {
634 if (enter) {
635 if (mNextAppTransitionScaleUp) {
636 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
637 } else {
638 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
639 }
640 } else {
641 if (mNextAppTransitionScaleUp) {
642 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
643 } else {
644 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
645 }
646 }
647 }
648
649 /**
650 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
651 * when a thumbnail is specified with the activity options.
652 */
Winson Chunga4ccb862014-08-22 15:26:27 -0700653 Animation createThumbnailAspectScaleAnimationLocked(int appWidth, int appHeight,
654 int deviceWidth, int transit) {
Winson Chung399f6202014-03-19 10:47:20 -0700655 Animation a;
656 final int thumbWidthI = mNextAppTransitionThumbnail.getWidth();
657 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
658 final int thumbHeightI = mNextAppTransitionThumbnail.getHeight();
659 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
660
Winson Chunga4ccb862014-08-22 15:26:27 -0700661 float scaleW = deviceWidth / thumbWidth;
662 float unscaledWidth = deviceWidth;
663 float unscaledHeight = thumbHeight * scaleW;
664 float unscaledStartY = mNextAppTransitionStartY - (unscaledHeight - thumbHeight) / 2f;
Winson Chung399f6202014-03-19 10:47:20 -0700665 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700666 // Animation up from the thumbnail to the full screen
667 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW,
668 mNextAppTransitionStartX + (thumbWidth / 2f),
669 mNextAppTransitionStartY + (thumbHeight / 2f));
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700670 scale.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700671 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700672 Animation alpha = new AlphaAnimation(1, 0);
Winson Chunga4ccb862014-08-22 15:26:27 -0700673 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
674 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
675 Animation translate = new TranslateAnimation(0, 0, 0, -unscaledStartY +
676 mNextAppTransitionInsets.top);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700677 translate.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700678 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700679
680 // This AnimationSet uses the Interpolators assigned above.
681 AnimationSet set = new AnimationSet(false);
682 set.addAnimation(scale);
683 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -0700684 set.addAnimation(translate);
Winson Chung399f6202014-03-19 10:47:20 -0700685 a = set;
686 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -0700687 // Animation down from the full screen to the thumbnail
688 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f,
689 mNextAppTransitionStartX + (thumbWidth / 2f),
690 mNextAppTransitionStartY + (thumbHeight / 2f));
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700691 scale.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700692 scale.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
693 Animation alpha = new AlphaAnimation(0f, 1f);
694 alpha.setInterpolator(mThumbnailFadeInInterpolator);
695 alpha.setDuration(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION);
696 Animation translate = new TranslateAnimation(0, 0, -unscaledStartY +
697 mNextAppTransitionInsets.top, 0);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700698 translate.setInterpolator(mTouchResponseInterpolator);
Winson Chunga4ccb862014-08-22 15:26:27 -0700699 translate.setDuration(THUMBNAIL_APP_TRANSITION_DURATION);
Winson Chung399f6202014-03-19 10:47:20 -0700700
Winson Chunga4ccb862014-08-22 15:26:27 -0700701 // This AnimationSet uses the Interpolators assigned above.
702 AnimationSet set = new AnimationSet(false);
703 set.addAnimation(scale);
704 set.addAnimation(alpha);
705 set.addAnimation(translate);
706 a = set;
707
708 }
709 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, 0,
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700710 mTouchResponseInterpolator);
Winson Chung399f6202014-03-19 10:47:20 -0700711 }
712
713 /**
714 * This alternate animation is created when we are doing a thumbnail transition, for the
715 * activity that is leaving, and the activity that is entering.
716 */
Winson Chunga4ccb862014-08-22 15:26:27 -0700717 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
718 int appWidth, int appHeight, int orientation, int transit, Rect containingFrame,
Wale Ogunwale35a57f82015-07-01 15:07:36 -0700719 Rect contentInsets) {
Winson Chung399f6202014-03-19 10:47:20 -0700720 Animation a;
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200721 final int thumbWidthI = mNextAppTransitionStartWidth;
Winson Chung399f6202014-03-19 10:47:20 -0700722 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Winson Chung2e7f3bd2014-09-05 13:17:22 +0200723 final int thumbHeightI = mNextAppTransitionStartHeight;
Winson Chung399f6202014-03-19 10:47:20 -0700724 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
725
Winson Chung2820c452014-04-15 15:34:44 -0700726 // Used for the ENTER_SCALE_UP and EXIT_SCALE_DOWN transitions
727 float scale = 1f;
728 int scaledTopDecor = 0;
729
Winson Chung399f6202014-03-19 10:47:20 -0700730 switch (thumbTransitState) {
731 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700732 // App window scaling up to become full screen
Winson Chung2820c452014-04-15 15:34:44 -0700733 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
734 // In portrait, we scale the width and clip to the top/left square
735 scale = thumbWidth / appWidth;
736 scaledTopDecor = (int) (scale * contentInsets.top);
737 int unscaledThumbHeight = (int) (thumbHeight / scale);
738 mTmpFromClipRect.set(containingFrame);
739 mTmpFromClipRect.bottom = (mTmpFromClipRect.top + unscaledThumbHeight);
740 mTmpToClipRect.set(containingFrame);
741 } else {
742 // In landscape, we scale the height and clip to the top/left square
743 scale = thumbHeight / (appHeight - contentInsets.top);
744 scaledTopDecor = (int) (scale * contentInsets.top);
745 int unscaledThumbWidth = (int) (thumbWidth / scale);
746 mTmpFromClipRect.set(containingFrame);
747 mTmpFromClipRect.right = (mTmpFromClipRect.left + unscaledThumbWidth);
748 mTmpToClipRect.set(containingFrame);
749 }
Wale Ogunwale35a57f82015-07-01 15:07:36 -0700750 // exclude top screen decor (status bar) region from the source clip.
751 mTmpFromClipRect.top = contentInsets.top;
752
Winson Chunga4ccb862014-08-22 15:26:27 -0700753 mNextAppTransitionInsets.set(contentInsets);
Winson Chung399f6202014-03-19 10:47:20 -0700754
755 Animation scaleAnim = new ScaleAnimation(scale, 1, scale, 1,
756 computePivot(mNextAppTransitionStartX, scale),
757 computePivot(mNextAppTransitionStartY, scale));
Winson Chung2820c452014-04-15 15:34:44 -0700758 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Winson Chung399f6202014-03-19 10:47:20 -0700759 Animation translateAnim = new TranslateAnimation(0, 0, -scaledTopDecor, 0);
760
761 AnimationSet set = new AnimationSet(true);
Winson Chung399f6202014-03-19 10:47:20 -0700762 set.addAnimation(clipAnim);
763 set.addAnimation(scaleAnim);
764 set.addAnimation(translateAnim);
765 a = set;
766 break;
767 }
768 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700769 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -0700770 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700771 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -0700772 // activity.
773 a = new AlphaAnimation(1, 0);
774 } else {
Winson Chung399f6202014-03-19 10:47:20 -0700775 a = new AlphaAnimation(1, 1);
776 }
777 break;
778 }
779 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700780 // Target app window during the scale down
781 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
782 // Fade in the destination activity if we are animating from a wallpaper
783 // activity.
784 a = new AlphaAnimation(0, 1);
785 } else {
786 a = new AlphaAnimation(1, 1);
787 }
Winson Chung399f6202014-03-19 10:47:20 -0700788 break;
789 }
790 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -0700791 // App window scaling down from full screen
Winson Chung2820c452014-04-15 15:34:44 -0700792 if (orientation == Configuration.ORIENTATION_PORTRAIT) {
793 // In portrait, we scale the width and clip to the top/left square
794 scale = thumbWidth / appWidth;
795 scaledTopDecor = (int) (scale * contentInsets.top);
796 int unscaledThumbHeight = (int) (thumbHeight / scale);
797 mTmpFromClipRect.set(containingFrame);
798 mTmpToClipRect.set(containingFrame);
799 mTmpToClipRect.bottom = (mTmpToClipRect.top + unscaledThumbHeight);
800 } else {
801 // In landscape, we scale the height and clip to the top/left square
802 scale = thumbHeight / (appHeight - contentInsets.top);
803 scaledTopDecor = (int) (scale * contentInsets.top);
804 int unscaledThumbWidth = (int) (thumbWidth / scale);
805 mTmpFromClipRect.set(containingFrame);
806 mTmpToClipRect.set(containingFrame);
807 mTmpToClipRect.right = (mTmpToClipRect.left + unscaledThumbWidth);
808 }
Wale Ogunwale35a57f82015-07-01 15:07:36 -0700809 // exclude top screen decor (status bar) region from the destination clip.
810 mTmpToClipRect.top = contentInsets.top;
811
Winson Chunga4ccb862014-08-22 15:26:27 -0700812 mNextAppTransitionInsets.set(contentInsets);
Winson Chung399f6202014-03-19 10:47:20 -0700813
814 Animation scaleAnim = new ScaleAnimation(1, scale, 1, scale,
815 computePivot(mNextAppTransitionStartX, scale),
816 computePivot(mNextAppTransitionStartY, scale));
Winson Chung2820c452014-04-15 15:34:44 -0700817 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Winson Chung399f6202014-03-19 10:47:20 -0700818 Animation translateAnim = new TranslateAnimation(0, 0, 0, -scaledTopDecor);
819
820 AnimationSet set = new AnimationSet(true);
Winson Chung399f6202014-03-19 10:47:20 -0700821 set.addAnimation(clipAnim);
822 set.addAnimation(scaleAnim);
823 set.addAnimation(translateAnim);
824
825 a = set;
826 a.setZAdjustment(Animation.ZORDER_TOP);
827 break;
828 }
829 default:
830 throw new RuntimeException("Invalid thumbnail transition state");
831 }
832
Winson Chungab79fce2014-11-04 16:15:22 -0800833 int duration = Math.max(THUMBNAIL_APP_TRANSITION_ALPHA_DURATION,
834 THUMBNAIL_APP_TRANSITION_DURATION);
835 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700836 mTouchResponseInterpolator);
Winson Chung399f6202014-03-19 10:47:20 -0700837 }
838
839 /**
Winson Chunga4ccb862014-08-22 15:26:27 -0700840 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
841 * when a thumbnail is specified with the activity options.
842 */
843 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit) {
844 Animation a;
845 final int thumbWidthI = mNextAppTransitionThumbnail.getWidth();
846 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
847 final int thumbHeightI = mNextAppTransitionThumbnail.getHeight();
848 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
849
850 if (mNextAppTransitionScaleUp) {
851 // Animation for the thumbnail zooming from its initial size to the full screen
852 float scaleW = appWidth / thumbWidth;
853 float scaleH = appHeight / thumbHeight;
854 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
855 computePivot(mNextAppTransitionStartX, 1 / scaleW),
856 computePivot(mNextAppTransitionStartY, 1 / scaleH));
857 scale.setInterpolator(mDecelerateInterpolator);
858
859 Animation alpha = new AlphaAnimation(1, 0);
860 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
861
862 // This AnimationSet uses the Interpolators assigned above.
863 AnimationSet set = new AnimationSet(false);
864 set.addAnimation(scale);
865 set.addAnimation(alpha);
866 a = set;
867 } else {
868 // Animation for the thumbnail zooming down from the full screen to its final size
869 float scaleW = appWidth / thumbWidth;
870 float scaleH = appHeight / thumbHeight;
871 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
872 computePivot(mNextAppTransitionStartX, 1 / scaleW),
873 computePivot(mNextAppTransitionStartY, 1 / scaleH));
874 }
875
876 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
877 }
878
879 /**
Winson Chung399f6202014-03-19 10:47:20 -0700880 * This animation is created when we are doing a thumbnail transition, for the activity that is
881 * leaving, and the activity that is entering.
882 */
883 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, int appWidth,
884 int appHeight, int transit) {
885 Animation a;
886 final int thumbWidthI = mNextAppTransitionThumbnail.getWidth();
887 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
888 final int thumbHeightI = mNextAppTransitionThumbnail.getHeight();
889 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
890
891 switch (thumbTransitState) {
892 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
893 // Entering app scales up with the thumbnail
894 float scaleW = thumbWidth / appWidth;
895 float scaleH = thumbHeight / appHeight;
896 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
897 computePivot(mNextAppTransitionStartX, scaleW),
898 computePivot(mNextAppTransitionStartY, scaleH));
899 break;
900 }
901 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
902 // Exiting app while the thumbnail is scaling up should fade or stay in place
903 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
904 // Fade out while bringing up selected activity. This keeps the
905 // current activity from showing through a launching wallpaper
906 // activity.
907 a = new AlphaAnimation(1, 0);
908 } else {
909 // noop animation
910 a = new AlphaAnimation(1, 1);
911 }
912 break;
913 }
914 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
915 // Entering the other app, it should just be visible while we scale the thumbnail
916 // down above it
917 a = new AlphaAnimation(1, 1);
918 break;
919 }
920 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
921 // Exiting the current app, the app should scale down with the thumbnail
922 float scaleW = thumbWidth / appWidth;
923 float scaleH = thumbHeight / appHeight;
924 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
925 computePivot(mNextAppTransitionStartX, scaleW),
926 computePivot(mNextAppTransitionStartY, scaleH));
927
928 Animation alpha = new AlphaAnimation(1, 0);
929
930 AnimationSet set = new AnimationSet(true);
931 set.addAnimation(scale);
932 set.addAnimation(alpha);
933 set.setZAdjustment(Animation.ZORDER_TOP);
934 a = set;
935 break;
936 }
937 default:
938 throw new RuntimeException("Invalid thumbnail transition state");
939 }
940
941 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
942 }
943
Jorim Jaggic554b772015-06-04 16:07:57 -0700944 /**
945 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
946 * frame of the transition doesn't change the visuals on screen, so we can start
947 * directly with the second one
948 */
949 boolean canSkipFirstFrame() {
950 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
951 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
952 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
953 }
Craig Mautner164d4bb2012-11-26 13:51:23 -0800954
955 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700956 int appWidth, int appHeight, int orientation, Rect containingFrame, Rect contentInsets,
Wale Ogunwale35a57f82015-07-01 15:07:36 -0700957 Rect appFrame, boolean isVoiceInteraction) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800958 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700959 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
960 || transit == TRANSIT_TASK_OPEN
961 || transit == TRANSIT_TASK_TO_FRONT)) {
962 a = loadAnimationRes(lp, enter
963 ? com.android.internal.R.anim.voice_activity_open_enter
964 : com.android.internal.R.anim.voice_activity_open_exit);
965 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
966 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700967 + " anim=" + a + " transit=" + appTransitionToString(transit)
968 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700969 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
970 || transit == TRANSIT_TASK_CLOSE
971 || transit == TRANSIT_TASK_TO_BACK)) {
972 a = loadAnimationRes(lp, enter
973 ? com.android.internal.R.anim.voice_activity_close_enter
974 : com.android.internal.R.anim.voice_activity_close_exit);
975 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
976 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700977 + " anim=" + a + " transit=" + appTransitionToString(transit)
978 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700979 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
980 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -0800981 mNextAppTransitionEnter : mNextAppTransitionExit);
982 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
983 "applyAnimation:"
984 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700985 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -0800986 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -0800987 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
988 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
989 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
990 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700991 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
992 + " transit=" + appTransitionToString(transit)
993 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -0800994 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700995 a = createClipRevealAnimationLocked(transit, enter, appFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -0800996 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
997 "applyAnimation:"
998 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
999 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001000 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001001 a = createScaleUpAnimationLocked(transit, enter, appWidth, appHeight);
1002 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1003 "applyAnimation:"
1004 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001005 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001006 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001007 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1008 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001009 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001010 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001011 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
1012 appWidth, appHeight, transit);
1013 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1014 String animName = mNextAppTransitionScaleUp ?
1015 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1016 Slog.v(TAG, "applyAnimation:"
1017 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001018 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001019 + " Callers=" + Debug.getCallers(3));
1020 }
1021 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1022 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1023 mNextAppTransitionScaleUp =
1024 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1025 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winson Chungfd086222014-05-13 15:49:42 -07001026 getThumbnailTransitionState(enter), appWidth, appHeight, orientation,
Wale Ogunwale35a57f82015-07-01 15:07:36 -07001027 transit, containingFrame, contentInsets);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001028 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1029 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001030 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001031 Slog.v(TAG, "applyAnimation:"
1032 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001033 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001034 + " Callers=" + Debug.getCallers(3));
1035 }
1036 } else {
1037 int animAttr = 0;
1038 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001039 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001040 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001041 ? WindowAnimation_activityOpenEnterAnimation
1042 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001043 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001044 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001045 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001046 ? WindowAnimation_activityCloseEnterAnimation
1047 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001048 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001049 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001050 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001051 ? WindowAnimation_taskOpenEnterAnimation
1052 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001053 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001054 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001055 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001056 ? WindowAnimation_taskCloseEnterAnimation
1057 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001058 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001059 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001060 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001061 ? WindowAnimation_taskToFrontEnterAnimation
1062 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001063 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001064 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001065 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001066 ? WindowAnimation_taskToBackEnterAnimation
1067 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001068 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001069 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001070 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001071 ? WindowAnimation_wallpaperOpenEnterAnimation
1072 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001073 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001074 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001075 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001076 ? WindowAnimation_wallpaperCloseEnterAnimation
1077 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001078 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001079 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001080 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001081 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1082 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001083 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001084 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001085 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001086 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1087 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001088 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001089 case TRANSIT_TASK_OPEN_BEHIND:
1090 animAttr = enter
1091 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001092 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001093 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001094 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001095 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1096 "applyAnimation:"
1097 + " anim=" + a
1098 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001099 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001100 + " Callers=" + Debug.getCallers(3));
1101 }
1102 return a;
1103 }
1104
1105 void postAnimationCallback() {
1106 if (mNextAppTransitionCallback != null) {
1107 mH.sendMessage(mH.obtainMessage(H.DO_ANIMATION_CALLBACK, mNextAppTransitionCallback));
1108 mNextAppTransitionCallback = null;
1109 }
1110 }
1111
1112 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
1113 IRemoteCallback startedCallback) {
1114 if (isTransitionSet()) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001115 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001116 mNextAppTransitionPackage = packageName;
1117 mNextAppTransitionThumbnail = null;
1118 mNextAppTransitionEnter = enterAnim;
1119 mNextAppTransitionExit = exitAnim;
1120 postAnimationCallback();
1121 mNextAppTransitionCallback = startedCallback;
1122 } else {
1123 postAnimationCallback();
1124 }
1125 }
1126
1127 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
1128 int startHeight) {
1129 if (isTransitionSet()) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001130 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001131 mNextAppTransitionPackage = null;
1132 mNextAppTransitionThumbnail = null;
1133 mNextAppTransitionStartX = startX;
1134 mNextAppTransitionStartY = startY;
1135 mNextAppTransitionStartWidth = startWidth;
1136 mNextAppTransitionStartHeight = startHeight;
1137 postAnimationCallback();
1138 mNextAppTransitionCallback = null;
1139 }
1140 }
1141
Chet Haase10e23ab2015-02-11 15:08:38 -08001142 void overridePendingAppTransitionClipReveal(int startX, int startY,
1143 int startWidth, int startHeight) {
1144 if (isTransitionSet()) {
1145 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1146 mNextAppTransitionStartX = startX;
1147 mNextAppTransitionStartY = startY;
1148 mNextAppTransitionStartWidth = startWidth;
1149 mNextAppTransitionStartHeight = startHeight;
1150 postAnimationCallback();
1151 mNextAppTransitionCallback = null;
1152 }
1153 }
1154
Craig Mautner164d4bb2012-11-26 13:51:23 -08001155 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1156 IRemoteCallback startedCallback, boolean scaleUp) {
1157 if (isTransitionSet()) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001158 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1159 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001160 mNextAppTransitionPackage = null;
1161 mNextAppTransitionThumbnail = srcThumb;
1162 mNextAppTransitionScaleUp = scaleUp;
1163 mNextAppTransitionStartX = startX;
1164 mNextAppTransitionStartY = startY;
1165 postAnimationCallback();
1166 mNextAppTransitionCallback = startedCallback;
1167 } else {
1168 postAnimationCallback();
1169 }
1170 }
1171
Winson Chunga4ccb862014-08-22 15:26:27 -07001172 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001173 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001174 if (isTransitionSet()) {
1175 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1176 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
1177 mNextAppTransitionPackage = null;
1178 mNextAppTransitionThumbnail = srcThumb;
1179 mNextAppTransitionScaleUp = scaleUp;
1180 mNextAppTransitionStartX = startX;
1181 mNextAppTransitionStartY = startY;
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001182 mNextAppTransitionStartWidth = targetWidth;
1183 mNextAppTransitionStartHeight = targetHeight;
Winson Chunga4ccb862014-08-22 15:26:27 -07001184 postAnimationCallback();
1185 mNextAppTransitionCallback = startedCallback;
1186 } else {
1187 postAnimationCallback();
1188 }
1189 }
1190
Winson Chung044d5292014-11-06 11:05:19 -08001191 void overrideInPlaceAppTransition(String packageName, int anim) {
1192 if (isTransitionSet()) {
1193 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1194 mNextAppTransitionPackage = packageName;
1195 mNextAppTransitionInPlace = anim;
1196 } else {
1197 postAnimationCallback();
1198 }
1199 }
1200
Craig Mautner164d4bb2012-11-26 13:51:23 -08001201 @Override
1202 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001203 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001204 }
1205
Craig Mautner4b71aa12012-12-27 17:20:01 -08001206 /**
1207 * Returns the human readable name of a window transition.
1208 *
1209 * @param transition The window transition.
1210 * @return The transition symbolic name.
1211 */
1212 public static String appTransitionToString(int transition) {
1213 switch (transition) {
1214 case TRANSIT_UNSET: {
1215 return "TRANSIT_UNSET";
1216 }
1217 case TRANSIT_NONE: {
1218 return "TRANSIT_NONE";
1219 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001220 case TRANSIT_ACTIVITY_OPEN: {
1221 return "TRANSIT_ACTIVITY_OPEN";
1222 }
1223 case TRANSIT_ACTIVITY_CLOSE: {
1224 return "TRANSIT_ACTIVITY_CLOSE";
1225 }
1226 case TRANSIT_TASK_OPEN: {
1227 return "TRANSIT_TASK_OPEN";
1228 }
1229 case TRANSIT_TASK_CLOSE: {
1230 return "TRANSIT_TASK_CLOSE";
1231 }
1232 case TRANSIT_TASK_TO_FRONT: {
1233 return "TRANSIT_TASK_TO_FRONT";
1234 }
1235 case TRANSIT_TASK_TO_BACK: {
1236 return "TRANSIT_TASK_TO_BACK";
1237 }
1238 case TRANSIT_WALLPAPER_CLOSE: {
1239 return "TRANSIT_WALLPAPER_CLOSE";
1240 }
1241 case TRANSIT_WALLPAPER_OPEN: {
1242 return "TRANSIT_WALLPAPER_OPEN";
1243 }
1244 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1245 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1246 }
1247 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1248 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1249 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001250 case TRANSIT_TASK_OPEN_BEHIND: {
1251 return "TRANSIT_TASK_OPEN_BEHIND";
1252 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001253 default: {
1254 return "<UNKNOWN>";
1255 }
1256 }
1257 }
1258
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001259 private String appStateToString() {
1260 switch (mAppTransitionState) {
1261 case APP_STATE_IDLE:
1262 return "APP_STATE_IDLE";
1263 case APP_STATE_READY:
1264 return "APP_STATE_READY";
1265 case APP_STATE_RUNNING:
1266 return "APP_STATE_RUNNING";
1267 case APP_STATE_TIMEOUT:
1268 return "APP_STATE_TIMEOUT";
1269 default:
1270 return "unknown state=" + mAppTransitionState;
1271 }
1272 }
1273
1274 private String transitTypeToString() {
1275 switch (mNextAppTransitionType) {
1276 case NEXT_TRANSIT_TYPE_NONE:
1277 return "NEXT_TRANSIT_TYPE_NONE";
1278 case NEXT_TRANSIT_TYPE_CUSTOM:
1279 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001280 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1281 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001282 case NEXT_TRANSIT_TYPE_SCALE_UP:
1283 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1284 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1285 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1286 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1287 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001288 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1289 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1290 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1291 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001292 default:
1293 return "unknown type=" + mNextAppTransitionType;
1294 }
1295 }
1296
Craig Mautner164d4bb2012-11-26 13:51:23 -08001297 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001298 public void dump(PrintWriter pw, String prefix) {
1299 pw.print(prefix); pw.println(this);
1300 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001301 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001302 pw.print(prefix); pw.print("mNextAppTransitionType=");
1303 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001304 }
1305 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001306 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001307 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001308 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001309 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001310 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1311 pw.print(" mNextAppTransitionExit=0x");
1312 pw.println(Integer.toHexString(mNextAppTransitionExit));
1313 break;
Winson Chung044d5292014-11-06 11:05:19 -08001314 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001315 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001316 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001317 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001318 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1319 break;
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001320 case NEXT_TRANSIT_TYPE_SCALE_UP:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001321 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
1322 pw.print(mNextAppTransitionStartX);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001323 pw.print(" mNextAppTransitionStartY=");
1324 pw.println(mNextAppTransitionStartY);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001325 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001326 pw.print(mNextAppTransitionStartWidth);
1327 pw.print(" mNextAppTransitionStartHeight=");
1328 pw.println(mNextAppTransitionStartHeight);
1329 break;
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001330 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1331 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001332 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1333 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001334 pw.print(prefix); pw.print("mNextAppTransitionThumbnail=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001335 pw.print(mNextAppTransitionThumbnail);
1336 pw.print(" mNextAppTransitionStartX=");
1337 pw.print(mNextAppTransitionStartX);
1338 pw.print(" mNextAppTransitionStartY=");
1339 pw.println(mNextAppTransitionStartY);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001340 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001341 pw.print(mNextAppTransitionStartWidth);
1342 pw.print(" mNextAppTransitionStartHeight=");
1343 pw.println(mNextAppTransitionStartHeight);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001344 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1345 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001346 break;
1347 }
1348 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001349 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1350 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001351 }
1352 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001353
1354 public void setCurrentUser(int newUserId) {
1355 mCurrentUserId = newUserId;
1356 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001357}