blob: 124d0219909f1eda94a09466543d1ab5d212708c [file] [log] [blame]
Craig Mautner164d4bb2012-11-26 13:51:23 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Filip Gruszczynski82861362015-10-16 14:21:09 -070019import static android.view.WindowManagerInternal.AppTransitionListener;
20import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
21import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
22import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
23import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
24import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
25import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
26import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
27import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
28import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
29import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
30import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
31import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
32import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
33import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
34import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
35import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
36import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
37import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
38import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
39import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
40import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
41import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Jorim Jaggi363ab982016-04-26 19:51:20 -070042import static com.android.server.wm.AppWindowAnimator.PROLONG_ANIMATION_AT_START;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080043import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
44import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080045import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
46import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010047import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
48import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
Filip Gruszczynski82861362015-10-16 14:21:09 -070049
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070050import android.annotation.Nullable;
Craig Mautner164d4bb2012-11-26 13:51:23 -080051import android.content.Context;
Winson21700932016-03-24 17:26:23 -070052import android.content.res.Configuration;
Craig Mautner164d4bb2012-11-26 13:51:23 -080053import android.graphics.Bitmap;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010054import android.graphics.Path;
Winson Chung399f6202014-03-19 10:47:20 -070055import android.graphics.Rect;
Craig Mautner164d4bb2012-11-26 13:51:23 -080056import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010057import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080058import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010059import android.os.RemoteException;
Manu Cornetda5900d2017-01-12 15:05:13 -080060import android.os.SystemProperties;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080061import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080062import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070063import android.util.SparseArray;
64import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010065import android.view.IAppTransitionAnimationSpecsFuture;
Craig Mautner164d4bb2012-11-26 13:51:23 -080066import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080067import android.view.animation.AlphaAnimation;
68import android.view.animation.Animation;
69import android.view.animation.AnimationSet;
70import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070071import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080072import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070073import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080074import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070075import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070076
Craig Mautner164d4bb2012-11-26 13:51:23 -080077import com.android.internal.util.DumpUtils.Dump;
78import com.android.server.AttributeCache;
79import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -080080import com.android.server.wm.animation.ClipRectLRAnimation;
81import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010082import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080083
84import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010085import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010086import java.util.concurrent.ExecutorService;
87import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -080088
Craig Mautner164d4bb2012-11-26 13:51:23 -080089// State management of app transitions. When we are preparing for a
90// transition, mNextAppTransition will be the kind of transition to
91// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
92// mOpeningApps and mClosingApps are the lists of tokens that will be
93// made visible or hidden at the next transition.
94public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080095 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070096 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080097
Craig Mautner4b71aa12012-12-27 17:20:01 -080098 /** Not set up for a transition. */
99 public static final int TRANSIT_UNSET = -1;
100 /** No animation for transition. */
101 public static final int TRANSIT_NONE = 0;
102 /** A window in a new activity is being opened on top of an existing one in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700103 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800104 /** The window in the top-most activity is being closed to reveal the
105 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700106 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800107 /** A window in a new task is being opened on top of an existing one
108 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700109 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800110 /** A window in the top-most activity is being closed to reveal the
111 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700112 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800113 /** A window in an existing task is being displayed on top of an existing one
114 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700115 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800116 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700117 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800118 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
119 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700120 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800121 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
122 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700123 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800124 /** A window in a new activity is being opened on top of an existing one, and both are on top
125 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700126 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800127 /** The window in the top-most activity is being closed to reveal the previous activity, and
128 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700129 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
130 /** A window in a new task is being opened behind an existing one in another activity's task.
131 * The new window will show briefly and then be gone. */
132 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800133 /** A window in a task is being animated in-place. */
134 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700135 /** An activity is being relaunched (e.g. due to configuration change). */
136 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Jorim Jaggi192086e2016-03-11 17:17:03 +0100137 /** A task is being docked from recents. */
138 public static final int TRANSIT_DOCK_TASK_FROM_RECENTS = 19;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800139
Winson Chunga4ccb862014-08-22 15:26:27 -0700140 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700141 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800142 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700143 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800144
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800145 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800146
147 /** Interpolator to be used for animations that respond directly to a touch */
148 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
149 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
150
Jorim Jaggic69bd222016-03-15 14:38:37 +0100151 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
152 new PathInterpolator(0.85f, 0f, 1f, 1f);
153
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800154 /**
155 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
156 * involved, to make it more understandable.
157 */
158 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700159 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700160 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800161
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800162 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800163 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800164
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800165 private int mNextAppTransition = TRANSIT_UNSET;
Chong Zhang60091a92016-07-27 17:52:45 -0700166 private int mLastUsedAppTransition = TRANSIT_UNSET;
167 private String mLastOpeningApp;
168 private String mLastClosingApp;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800169
170 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
171 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
172 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
173 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
174 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700175 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
176 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800177 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800178 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800179 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
180
Winson Chung399f6202014-03-19 10:47:20 -0700181 // These are the possible states for the enter/exit activities during a thumbnail transition
182 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
183 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
184 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
185 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
186
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800187 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800188 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800189 private boolean mNextAppTransitionScaleUp;
190 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100191 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700192 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800193 private int mNextAppTransitionEnter;
194 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800195 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700196
197 // Keyed by task id.
198 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
199 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100200 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
201 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700202 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
203
Winson Chunga4ccb862014-08-22 15:26:27 -0700204 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800205
Winson Chung2820c452014-04-15 15:34:44 -0700206 private Rect mTmpFromClipRect = new Rect();
207 private Rect mTmpToClipRect = new Rect();
208
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700209 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700210
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800211 private final static int APP_STATE_IDLE = 0;
212 private final static int APP_STATE_READY = 1;
213 private final static int APP_STATE_RUNNING = 2;
214 private final static int APP_STATE_TIMEOUT = 3;
215 private int mAppTransitionState = APP_STATE_IDLE;
216
217 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800218 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700219 private final Interpolator mThumbnailFadeInInterpolator;
220 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800221 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700222 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100223 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700224 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
225
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700226 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800227
Amith Yamasani4befbec2013-07-10 16:18:01 -0700228 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800229 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700230
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100231 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100232 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100233
Jorim Jaggif97ed922016-02-18 18:57:07 -0800234 private int mLastClipRevealMaxTranslation;
235 private boolean mLastHadClipReveal;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700236 private boolean mProlongedAnimationsEnded;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800237
Manu Cornetda5900d2017-01-12 15:05:13 -0800238 private final boolean mGridLayoutRecentsEnabled;
239
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800240 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800241 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800242 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800243 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
244 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700245 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
246 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100247 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
248 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800249 mConfigShortAnimTime = context.getResources().getInteger(
250 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800251 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
252 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700253 mThumbnailFadeInInterpolator = new Interpolator() {
254 @Override
255 public float getInterpolation(float input) {
256 // Linear response for first fraction, then complete after that.
257 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
258 return 0f;
259 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700260 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700261 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700262 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700263 }
264 };
265 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800266 @Override
267 public float getInterpolation(float input) {
268 // Linear response for first fraction, then complete after that.
269 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700270 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
271 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800272 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700273 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800274 }
275 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700276 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
277 * mContext.getResources().getDisplayMetrics().density);
Manu Cornetda5900d2017-01-12 15:05:13 -0800278 mGridLayoutRecentsEnabled = SystemProperties.getBoolean("ro.recents.grid", false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800279 }
280
281 boolean isTransitionSet() {
282 return mNextAppTransition != TRANSIT_UNSET;
283 }
284
Craig Mautner164d4bb2012-11-26 13:51:23 -0800285 boolean isTransitionEqual(int transit) {
286 return mNextAppTransition == transit;
287 }
288
289 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800290 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800291 }
292
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700293 private void setAppTransition(int transit) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800294 mNextAppTransition = transit;
Chong Zhang60091a92016-07-27 17:52:45 -0700295 setLastAppTransition(TRANSIT_UNSET, null, null);
296 }
297
298 void setLastAppTransition(int transit, AppWindowToken openingApp, AppWindowToken closingApp) {
299 mLastUsedAppTransition = transit;
300 mLastOpeningApp = "" + openingApp;
301 mLastClosingApp = "" + closingApp;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800302 }
303
304 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800305 return mAppTransitionState == APP_STATE_READY
306 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800307 }
308
Craig Mautnerae446592012-12-06 19:05:05 -0800309 void setReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800310 mAppTransitionState = APP_STATE_READY;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100311 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800312 }
313
314 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800315 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800316 }
317
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800318 void setIdle() {
319 mAppTransitionState = APP_STATE_IDLE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800320 }
321
322 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800323 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800324 }
325
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800326 void setTimeout() {
327 mAppTransitionState = APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800328 }
329
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700330 Bitmap getAppTransitionThumbnailHeader(int taskId) {
331 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800332 if (spec == null) {
333 spec = mDefaultNextAppTransitionAnimationSpec;
334 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700335 return spec != null ? spec.bitmap : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800336 }
337
Winson Chunga4ccb862014-08-22 15:26:27 -0700338 /** Returns whether the next thumbnail transition is aspect scaled up. */
339 boolean isNextThumbnailTransitionAspectScaled() {
340 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
341 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
342 }
343
344 /** Returns whether the next thumbnail transition is scaling up. */
345 boolean isNextThumbnailTransitionScaleUp() {
346 return mNextAppTransitionScaleUp;
347 }
348
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800349 boolean isNextAppTransitionThumbnailUp() {
350 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
351 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
352 }
353
354 boolean isNextAppTransitionThumbnailDown() {
355 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
356 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
357 }
358
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100359 /**
360 * @return true if and only if we are currently fetching app transition specs from the future
361 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
362 */
363 boolean isFetchingAppTransitionsSpecs() {
364 return mNextAppTransitionAnimationsSpecsPending;
365 }
366
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700367 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800368 if (!isRunning()) {
369 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100370 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800371 mLastHadClipReveal = false;
372 mLastClipRevealMaxTranslation = 0;
373 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700374 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800375 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700376 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800377 }
378
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800379 void goodToGo(AppWindowAnimator topOpeningAppAnimator, AppWindowAnimator topClosingAppAnimator,
380 ArraySet<AppWindowToken> openingApps, ArraySet<AppWindowToken> closingApps) {
Jorim Jaggi84afb1a2016-09-28 14:54:04 +0200381 int appTransition = mNextAppTransition;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800382 mNextAppTransition = TRANSIT_UNSET;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800383 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100384 notifyAppTransitionStartingLocked(
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800385 topOpeningAppAnimator != null ? topOpeningAppAnimator.mAppToken.token : null,
386 topClosingAppAnimator != null ? topClosingAppAnimator.mAppToken.token : null,
387 topOpeningAppAnimator != null ? topOpeningAppAnimator.animation : null,
388 topClosingAppAnimator != null ? topClosingAppAnimator.animation : null);
389 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Jorim Jaggi84afb1a2016-09-28 14:54:04 +0200390 .notifyAppTransitionStarting(openingApps, appTransition);
Jorim Jaggi363ab982016-04-26 19:51:20 -0700391
392 // Prolong the start for the transition when docking a task from recents, unless recents
393 // ended it already then we don't need to wait.
394 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS && !mProlongedAnimationsEnded) {
395 for (int i = openingApps.size() - 1; i >= 0; i--) {
396 final AppWindowAnimator appAnimator = openingApps.valueAt(i).mAppAnimator;
397 appAnimator.startProlongAnimation(PROLONG_ANIMATION_AT_START);
398 }
399 }
400 }
401
402 /**
403 * Let the transitions manager know that the somebody wanted to end the prolonged animations.
404 */
405 void notifyProlongedAnimationsEnded() {
406 mProlongedAnimationsEnded = true;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800407 }
408
409 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800410 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800411 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700412 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi65193992015-11-23 16:49:59 -0800413 mNextAppTransitionAnimationsSpecsFuture = null;
414 mDefaultNextAppTransitionAnimationSpec = null;
415 mAnimationFinishedCallback = null;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700416 mProlongedAnimationsEnded = false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800417 }
418
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800419 void freeze() {
420 setAppTransition(AppTransition.TRANSIT_UNSET);
421 clear();
422 setReady();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100423 notifyAppTransitionCancelledLocked();
424 }
425
426 void registerListenerLocked(AppTransitionListener listener) {
427 mListeners.add(listener);
428 }
429
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700430 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100431 for (int i = 0; i < mListeners.size(); i++) {
432 mListeners.get(i).onAppTransitionFinishedLocked(token);
433 }
434 }
435
436 private void notifyAppTransitionPendingLocked() {
437 for (int i = 0; i < mListeners.size(); i++) {
438 mListeners.get(i).onAppTransitionPendingLocked();
439 }
440 }
441
442 private void notifyAppTransitionCancelledLocked() {
443 for (int i = 0; i < mListeners.size(); i++) {
444 mListeners.get(i).onAppTransitionCancelledLocked();
445 }
446 }
447
448 private void notifyAppTransitionStartingLocked(IBinder openToken,
449 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
450 for (int i = 0; i < mListeners.size(); i++) {
451 mListeners.get(i).onAppTransitionStartingLocked(openToken, closeToken, openAnimation,
452 closeAnimation);
453 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800454 }
455
Craig Mautner164d4bb2012-11-26 13:51:23 -0800456 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
457 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
458 + (lp != null ? lp.packageName : null)
459 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
460 if (lp != null && lp.windowAnimations != 0) {
461 // If this is a system resource, don't try to load it from the
462 // application resources. It is nice to avoid loading application
463 // resources if we can.
464 String packageName = lp.packageName != null ? lp.packageName : "android";
465 int resId = lp.windowAnimations;
466 if ((resId&0xFF000000) == 0x01000000) {
467 packageName = "android";
468 }
469 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
470 + packageName);
471 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700472 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800473 }
474 return null;
475 }
476
477 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
478 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
479 + packageName + " resId=0x" + Integer.toHexString(resId));
480 if (packageName != null) {
481 if ((resId&0xFF000000) == 0x01000000) {
482 packageName = "android";
483 }
484 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
485 + packageName);
486 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700487 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800488 }
489 return null;
490 }
491
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700492 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800493 int anim = 0;
494 Context context = mContext;
495 if (animAttr >= 0) {
496 AttributeCache.Entry ent = getCachedAnimations(lp);
497 if (ent != null) {
498 context = ent.context;
499 anim = ent.array.getResourceId(animAttr, 0);
500 }
501 }
502 if (anim != 0) {
503 return AnimationUtils.loadAnimation(context, anim);
504 }
505 return null;
506 }
507
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700508 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
509 Context context = mContext;
510 if (resId >= 0) {
511 AttributeCache.Entry ent = getCachedAnimations(lp);
512 if (ent != null) {
513 context = ent.context;
514 }
515 return AnimationUtils.loadAnimation(context, resId);
516 }
517 return null;
518 }
519
520 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800521 int anim = 0;
522 Context context = mContext;
523 if (resId >= 0) {
524 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
525 if (ent != null) {
526 context = ent.context;
527 anim = resId;
528 }
529 }
530 if (anim != 0) {
531 return AnimationUtils.loadAnimation(context, anim);
532 }
533 return null;
534 }
535
Craig Mautner164d4bb2012-11-26 13:51:23 -0800536 /**
537 * Compute the pivot point for an animation that is scaling from a small
538 * rect on screen to a larger rect. The pivot point varies depending on
539 * the distance between the inner and outer edges on both sides. This
540 * function computes the pivot point for one dimension.
541 * @param startPos Offset from left/top edge of outer rectangle to
542 * left/top edge of inner rectangle.
543 * @param finalScale The scaling factor between the size of the outer
544 * and inner rectangles.
545 */
546 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800547
548 /*
549 Theorem of intercepting lines:
550
551 + + +-----------------------------------------------+
552 | | | |
553 | | | |
554 | | | |
555 | | | |
556 x | y | | |
557 | | | |
558 | | | |
559 | | | |
560 | | | |
561 | + | +--------------------+ |
562 | | | | |
563 | | | | |
564 | | | | |
565 | | | | |
566 | | | | |
567 | | | | |
568 | | | | |
569 | | | | |
570 | | | | |
571 | | | | |
572 | | | | |
573 | | | | |
574 | | | | |
575 | | | | |
576 | | | | |
577 | | | | |
578 | | | | |
579 | | +--------------------+ |
580 | | |
581 | | |
582 | | |
583 | | |
584 | | |
585 | | |
586 | | |
587 | +-----------------------------------------------+
588 |
589 |
590 |
591 |
592 |
593 |
594 |
595 |
596 |
597 + ++
598 p ++
599
600 scale = (x - y) / x
601 <=> x = -y / (scale - 1)
602 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800603 final float denom = finalScale-1;
604 if (Math.abs(denom) < .0001f) {
605 return startPos;
606 }
607 return -startPos / denom;
608 }
609
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700610 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
611 Rect containingFrame) {
612 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700613 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700614 final int appWidth = containingFrame.width();
615 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800616 if (enter) {
617 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700618 float scaleW = mTmpRect.width() / (float) appWidth;
619 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800620 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700621 computePivot(mTmpRect.left, scaleW),
Winson4c3fecd2016-07-13 12:29:48 -0700622 computePivot(mTmpRect.top, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800623 scale.setInterpolator(mDecelerateInterpolator);
624
Craig Mautner164d4bb2012-11-26 13:51:23 -0800625 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700626 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800627
628 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800629 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800630 set.addAnimation(alpha);
631 set.setDetachWallpaper(true);
632 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800633 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
634 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800635 // If we are on top of the wallpaper, we need an animation that
636 // correctly handles the wallpaper staying static behind all of
637 // the animated elements. To do this, will just have the existing
638 // element fade out.
639 a = new AlphaAnimation(1, 0);
640 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800641 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800642 // For normal animations, the exiting element just holds in place.
643 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800644 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800645
646 // Pick the desired duration. If this is an inter-activity transition,
647 // it is the standard duration for that. Otherwise we use the longer
648 // task transition duration.
649 final long duration;
650 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800651 case TRANSIT_ACTIVITY_OPEN:
652 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800653 duration = mConfigShortAnimTime;
654 break;
655 default:
656 duration = DEFAULT_APP_TRANSITION_DURATION;
657 break;
658 }
659 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800660 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800661 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800662 a.initialize(appWidth, appHeight, appWidth, appHeight);
663 return a;
664 }
665
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700666 private void getDefaultNextAppTransitionStartRect(Rect rect) {
667 if (mDefaultNextAppTransitionAnimationSpec == null ||
668 mDefaultNextAppTransitionAnimationSpec.rect == null) {
669 Slog.wtf(TAG, "Starting rect for app requested, but none available", new Throwable());
670 rect.setEmpty();
671 } else {
672 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
673 }
674 }
675
676 void getNextAppTransitionStartRect(int taskId, Rect rect) {
677 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800678 if (spec == null) {
679 spec = mDefaultNextAppTransitionAnimationSpec;
680 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700681 if (spec == null || spec.rect == null) {
682 Slog.wtf(TAG, "Starting rect for task: " + taskId + " requested, but not available",
683 new Throwable());
684 rect.setEmpty();
685 } else {
686 rect.set(spec.rect);
687 }
688 }
689
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800690 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
691 Bitmap bitmap) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700692 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800693 bitmap, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700694 }
695
Jorim Jaggif97ed922016-02-18 18:57:07 -0800696 /**
697 * @return the duration of the last clip reveal animation
698 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800699 long getLastClipRevealTransitionDuration() {
700 return mLastClipRevealTransitionDuration;
701 }
702
703 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800704 * @return the maximum distance the app surface is traveling of the last clip reveal animation
705 */
706 int getLastClipRevealMaxTranslation() {
707 return mLastClipRevealMaxTranslation;
708 }
709
710 /**
711 * @return true if in the last app transition had a clip reveal animation, false otherwise
712 */
713 boolean hadClipRevealAnimation() {
714 return mLastHadClipReveal;
715 }
716
717 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800718 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
719 * the start rect is outside of the target rect, and there is a lot of movement going on.
720 *
721 * @param cutOff whether the start rect was not fully contained by the end rect
722 * @param translationX the total translation the surface moves in x direction
723 * @param translationY the total translation the surfaces moves in y direction
724 * @param displayFrame our display frame
725 *
726 * @return the duration of the clip reveal animation, in milliseconds
727 */
728 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
729 float translationY, Rect displayFrame) {
730 if (!cutOff) {
731 return DEFAULT_APP_TRANSITION_DURATION;
732 }
733 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
734 Math.abs(translationY) / displayFrame.height());
735 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
736 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
737 }
738
739 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
740 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800741 final Animation anim;
742 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700743 final int appWidth = appFrame.width();
744 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800745
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700746 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700747 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700748 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700749
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700750 float t = 0f;
751 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800752 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700753 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800754 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
755 int translationX = 0;
756 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700757 int centerX = mTmpRect.centerX();
758 int centerY = mTmpRect.centerY();
759 int halfWidth = mTmpRect.width() / 2;
760 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800761 int clipStartX = centerX - halfWidth - appFrame.left;
762 int clipStartY = centerY - halfHeight - appFrame.top;
763 boolean cutOff = false;
764
765 // If the starting rectangle is fully or partially outside of the target rectangle, we
766 // need to start the clipping at the edge and then achieve the rest with translation
767 // and extending the clip rect from that edge.
768 if (appFrame.top > centerY - halfHeight) {
769 translationY = (centerY - halfHeight) - appFrame.top;
770 translationYCorrection = 0;
771 clipStartY = 0;
772 cutOff = true;
773 }
774 if (appFrame.left > centerX - halfWidth) {
775 translationX = (centerX - halfWidth) - appFrame.left;
776 clipStartX = 0;
777 cutOff = true;
778 }
779 if (appFrame.right < centerX + halfWidth) {
780 translationX = (centerX + halfWidth) - appFrame.right;
781 clipStartX = appWidth - mTmpRect.width();
782 cutOff = true;
783 }
784 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
785 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700786
787 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800788 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800789 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700790 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800791 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700792
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800793 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
794 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
795 : mLinearOutSlowInInterpolator);
796 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800797
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800798 Animation clipAnimTB = new ClipRectTBAnimation(
799 clipStartY, clipStartY + mTmpRect.height(),
800 0, appHeight,
801 translationYCorrection, 0,
802 mLinearOutSlowInInterpolator);
803 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
804 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800805
806 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800807 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700808 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800809 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700810 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800811
812 AnimationSet set = new AnimationSet(false);
813 set.addAnimation(clipAnimLR);
814 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700815 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800816 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700817 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800818 set.initialize(appWidth, appHeight, appWidth, appHeight);
819 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800820 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800821 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800822
823 // If the start rect was full inside the target rect (cutOff == false), we don't need
824 // to store the translation, because it's only used if cutOff == true.
825 mLastClipRevealMaxTranslation = cutOff
826 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800827 } else {
828 final long duration;
829 switch (transit) {
830 case TRANSIT_ACTIVITY_OPEN:
831 case TRANSIT_ACTIVITY_CLOSE:
832 duration = mConfigShortAnimTime;
833 break;
834 default:
835 duration = DEFAULT_APP_TRANSITION_DURATION;
836 break;
837 }
838 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
839 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
840 // If we are on top of the wallpaper, we need an animation that
841 // correctly handles the wallpaper staying static behind all of
842 // the animated elements. To do this, will just have the existing
843 // element fade out.
844 anim = new AlphaAnimation(1, 0);
845 anim.setDetachWallpaper(true);
846 } else {
847 // For normal animations, the exiting element just holds in place.
848 anim = new AlphaAnimation(1, 1);
849 }
850 anim.setInterpolator(mDecelerateInterpolator);
851 anim.setDuration(duration);
852 anim.setFillAfter(true);
853 }
854 return anim;
855 }
856
Winson Chung399f6202014-03-19 10:47:20 -0700857 /**
858 * Prepares the specified animation with a standard duration, interpolator, etc.
859 */
Winson Chung5393dff2014-05-08 14:25:43 -0700860 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100861 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700862 if (duration > 0) {
863 a.setDuration(duration);
864 }
Winson Chung5393dff2014-05-08 14:25:43 -0700865 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100866 if (interpolator != null) {
867 a.setInterpolator(interpolator);
868 }
Winson Chung5393dff2014-05-08 14:25:43 -0700869 a.initialize(appWidth, appHeight, appWidth, appHeight);
870 return a;
871 }
872
873 /**
874 * Prepares the specified animation with a standard duration, interpolator, etc.
875 */
Winson Chung399f6202014-03-19 10:47:20 -0700876 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800877 // Pick the desired duration. If this is an inter-activity transition,
878 // it is the standard duration for that. Otherwise we use the longer
879 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700880 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800881 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800882 case TRANSIT_ACTIVITY_OPEN:
883 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800884 duration = mConfigShortAnimTime;
885 break;
886 default:
887 duration = DEFAULT_APP_TRANSITION_DURATION;
888 break;
889 }
Winson Chung5393dff2014-05-08 14:25:43 -0700890 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
891 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800892 }
893
Winson Chung399f6202014-03-19 10:47:20 -0700894 /**
895 * Return the current thumbnail transition state.
896 */
897 int getThumbnailTransitionState(boolean enter) {
898 if (enter) {
899 if (mNextAppTransitionScaleUp) {
900 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
901 } else {
902 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
903 }
904 } else {
905 if (mNextAppTransitionScaleUp) {
906 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
907 } else {
908 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
909 }
910 }
911 }
912
913 /**
914 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700915 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700916 */
Jorim Jaggide63d442016-03-14 14:56:56 +0100917 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winsonb2024762016-04-05 17:32:30 -0700918 Bitmap thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -0700919 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700920 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700921 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700922 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700923 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700924
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700925 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700926 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -0700927 final float fromX;
Manu Cornet57b61492017-01-24 18:19:05 +0900928 float fromY;
Jorim Jaggi09072002016-03-25 16:48:42 -0700929 final float toX;
Manu Cornet57b61492017-01-24 18:19:05 +0900930 float toY;
Jorim Jaggi09072002016-03-25 16:48:42 -0700931 final float pivotX;
932 final float pivotY;
Manu Cornetda5900d2017-01-12 15:05:13 -0800933 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggi09072002016-03-25 16:48:42 -0700934 fromX = mTmpRect.left;
935 fromY = mTmpRect.top;
936
937 // For the curved translate animation to work, the pivot points needs to be at the
938 // same absolute position as the one from the real surface.
939 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
940 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
941 pivotX = mTmpRect.width() / 2;
942 pivotY = appRect.height() / 2 / scaleW;
Manu Cornet57b61492017-01-24 18:19:05 +0900943 if (mGridLayoutRecentsEnabled) {
944 // In the grid layout, the header is displayed above the thumbnail instead of
945 // overlapping it.
946 fromY -= thumbHeightI;
947 toY -= thumbHeightI * scaleW;
948 }
Jorim Jaggi09072002016-03-25 16:48:42 -0700949 } else {
950 pivotX = 0;
951 pivotY = 0;
952 fromX = mTmpRect.left;
953 fromY = mTmpRect.top;
954 toX = appRect.left;
955 toY = appRect.top;
956 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100957 final long duration = getAspectScaleDuration();
958 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -0700959 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700960 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +0100961 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100962 scale.setInterpolator(interpolator);
963 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800964 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100965 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
966 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
967 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
968 ? duration / 2
969 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100970 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
971 translate.setInterpolator(interpolator);
972 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -0700973
Jorim Jaggide63d442016-03-14 14:56:56 +0100974 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
975 mTmpToClipRect.set(appRect);
976
977 // Containing frame is in screen space, but we need the clip rect in the
978 // app space.
979 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100980 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
981 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +0100982
983 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +0100984 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
985 (int) (-contentInsets.top * scaleW),
986 (int) (-contentInsets.right * scaleW),
987 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +0100988 }
989
990 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100991 clipAnim.setInterpolator(interpolator);
992 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +0100993
Winson Chung399f6202014-03-19 10:47:20 -0700994 // This AnimationSet uses the Interpolators assigned above.
995 AnimationSet set = new AnimationSet(false);
996 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +0900997 if (!mGridLayoutRecentsEnabled) {
998 // In the grid layout, the header should be shown for the whole animation.
999 set.addAnimation(alpha);
1000 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001001 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001002 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001003 a = set;
1004 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001005 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001006 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001007 scale.setInterpolator(interpolator);
1008 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001009 Animation alpha = new AlphaAnimation(0f, 1f);
1010 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001011 alpha.setDuration(duration);
1012 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1013 translate.setInterpolator(interpolator);
1014 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001015
Winson Chunga4ccb862014-08-22 15:26:27 -07001016 // This AnimationSet uses the Interpolators assigned above.
1017 AnimationSet set = new AnimationSet(false);
1018 set.addAnimation(scale);
Manu Cornet57b61492017-01-24 18:19:05 +09001019 if (!mGridLayoutRecentsEnabled) {
1020 // In the grid layout, the header should be shown for the whole animation.
1021 set.addAnimation(alpha);
1022 }
Winson Chunga4ccb862014-08-22 15:26:27 -07001023 set.addAnimation(translate);
1024 a = set;
1025
1026 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001027 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001028 null);
Winson Chung399f6202014-03-19 10:47:20 -07001029 }
1030
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001031 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1032
1033 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001034 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001035 return new TranslateAnimation(fromX, toX, fromY, toY);
1036 } else {
1037 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1038 return new CurvedTranslateAnimation(path);
1039 }
1040 }
1041
1042 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1043 final Path path = new Path();
1044 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001045
1046 if (fromY > toY) {
1047 // If the object needs to go up, move it in horizontal direction first, then vertical.
1048 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1049 } else {
1050 // If the object needs to go down, move it in vertical direction first, then horizontal.
1051 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1052 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001053 return path;
1054 }
1055
1056 private long getAspectScaleDuration() {
1057 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001058 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001059 } else {
1060 return THUMBNAIL_APP_TRANSITION_DURATION;
1061 }
1062 }
1063
1064 private Interpolator getAspectScaleInterpolator() {
1065 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1066 return mFastOutSlowInInterpolator;
1067 } else {
1068 return TOUCH_RESPONSE_INTERPOLATOR;
1069 }
1070 }
1071
Winson Chung399f6202014-03-19 10:47:20 -07001072 /**
1073 * This alternate animation is created when we are doing a thumbnail transition, for the
1074 * activity that is leaving, and the activity that is entering.
1075 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001076 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001077 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001078 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001079 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001080 final int appWidth = containingFrame.width();
1081 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001082 getDefaultNextAppTransitionStartRect(mTmpRect);
1083 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001084 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001085 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001086 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001087 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001088 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001089
1090 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001091 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1092 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1093 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1094 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001095 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001096 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001097 } else if (freeform) {
1098 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1099 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001100 } else {
Winson21700932016-03-24 17:26:23 -07001101 AnimationSet set = new AnimationSet(true);
1102
1103 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001104 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001105 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001106
1107 // Containing frame is in screen space, but we need the clip rect in the
1108 // app space.
1109 mTmpFromClipRect.offsetTo(0, 0);
1110 mTmpToClipRect.offsetTo(0, 0);
1111
1112 // Exclude insets region from the source clip.
1113 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001114 mNextAppTransitionInsets.set(contentInsets);
1115
Manu Cornetda5900d2017-01-12 15:05:13 -08001116 if (shouldScaleDownThumbnailTransition(uiMode, orientation)) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001117 // We scale the width and clip to the top/left square
1118 float scale = thumbWidth /
1119 (appWidth - contentInsets.left - contentInsets.right);
1120 int unscaledThumbHeight = (int) (thumbHeight / scale);
1121 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1122
1123 mNextAppTransitionInsets.set(contentInsets);
1124
Jorim Jaggi8448f332016-03-14 17:50:37 +01001125 Animation scaleAnim = new ScaleAnimation(
1126 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1127 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001128 containingFrame.width() / 2f,
1129 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001130 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001131 final float x = containingFrame.width() / 2f
1132 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001133 final float targetY = (mTmpRect.top - containingFrame.top);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001134 final float y = containingFrame.height() / 2f
1135 - containingFrame.height() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001136 final float startX = targetX - x;
1137 final float startY = targetY - y;
1138 Animation clipAnim = scaleUp
1139 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1140 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1141 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001142 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1143 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1144
Winson21700932016-03-24 17:26:23 -07001145 set.addAnimation(clipAnim);
1146 set.addAnimation(scaleAnim);
1147 set.addAnimation(translateAnim);
1148
1149 } else {
1150 // In landscape, we don't scale at all and only crop
1151 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1152 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1153
Jorim Jaggi8448f332016-03-14 17:50:37 +01001154 Animation clipAnim = scaleUp
1155 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1156 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1157 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001158 ? createCurvedMotion(thumbStartX, 0,
1159 thumbStartY - contentInsets.top, 0)
1160 : createCurvedMotion(0, thumbStartX, 0,
1161 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001162
1163 set.addAnimation(clipAnim);
1164 set.addAnimation(translateAnim);
1165 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001166 a = set;
Winson21700932016-03-24 17:26:23 -07001167 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001168 }
Winson Chung399f6202014-03-19 10:47:20 -07001169 break;
1170 }
1171 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001172 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001173 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001174 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001175 // activity.
1176 a = new AlphaAnimation(1, 0);
1177 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001178 a = new AlphaAnimation(1, 1);
1179 }
1180 break;
1181 }
1182 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001183 // Target app window during the scale down
1184 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1185 // Fade in the destination activity if we are animating from a wallpaper
1186 // activity.
1187 a = new AlphaAnimation(0, 1);
1188 } else {
1189 a = new AlphaAnimation(1, 1);
1190 }
Winson Chung399f6202014-03-19 10:47:20 -07001191 break;
1192 }
Winson Chung399f6202014-03-19 10:47:20 -07001193 default:
1194 throw new RuntimeException("Invalid thumbnail transition state");
1195 }
1196
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001197 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1198 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001199 }
1200
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001201 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1202 @Nullable Rect surfaceInsets, int taskId) {
1203 getNextAppTransitionStartRect(taskId, mTmpRect);
1204 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1205 true);
1206 }
1207
1208 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1209 @Nullable Rect surfaceInsets, int taskId) {
1210 getNextAppTransitionStartRect(taskId, mTmpRect);
1211 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1212 false);
1213 }
1214
1215 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1216 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1217 final float sourceWidth = sourceFrame.width();
1218 final float sourceHeight = sourceFrame.height();
1219 final float destWidth = destFrame.width();
1220 final float destHeight = destFrame.height();
1221 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1222 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001223 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001224 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001225 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001226 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001227 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1228 // We want the scaling to happen from the center of the surface. In order to achieve that,
1229 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001230 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1231 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1232 final ScaleAnimation scale = enter ?
1233 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1234 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1235 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1236 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1237 final int destHCenter = destFrame.left + destFrame.width() / 2;
1238 final int destVCenter = destFrame.top + destFrame.height() / 2;
1239 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1240 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1241 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1242 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001243 set.addAnimation(scale);
1244 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001245
1246 final IRemoteCallback callback = mAnimationFinishedCallback;
1247 if (callback != null) {
1248 set.setAnimationListener(new Animation.AnimationListener() {
1249 @Override
1250 public void onAnimationStart(Animation animation) { }
1251
1252 @Override
1253 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001254 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001255 }
1256
1257 @Override
1258 public void onAnimationRepeat(Animation animation) { }
1259 });
1260 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001261 return set;
1262 }
1263
Winson Chung399f6202014-03-19 10:47:20 -07001264 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001265 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001266 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001267 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001268 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
1269 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001270 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001271 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001272 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001273 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001274 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001275 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1276
1277 if (mNextAppTransitionScaleUp) {
1278 // Animation for the thumbnail zooming from its initial size to the full screen
1279 float scaleW = appWidth / thumbWidth;
1280 float scaleH = appHeight / thumbHeight;
1281 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001282 computePivot(mTmpRect.left, 1 / scaleW),
1283 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001284 scale.setInterpolator(mDecelerateInterpolator);
1285
1286 Animation alpha = new AlphaAnimation(1, 0);
1287 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1288
1289 // This AnimationSet uses the Interpolators assigned above.
1290 AnimationSet set = new AnimationSet(false);
1291 set.addAnimation(scale);
1292 set.addAnimation(alpha);
1293 a = set;
1294 } else {
1295 // Animation for the thumbnail zooming down from the full screen to its final size
1296 float scaleW = appWidth / thumbWidth;
1297 float scaleH = appHeight / thumbHeight;
1298 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001299 computePivot(mTmpRect.left, 1 / scaleW),
1300 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001301 }
1302
1303 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1304 }
1305
1306 /**
Winson Chung399f6202014-03-19 10:47:20 -07001307 * This animation is created when we are doing a thumbnail transition, for the activity that is
1308 * leaving, and the activity that is entering.
1309 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001310 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1311 int transit, int taskId) {
1312 final int appWidth = containingFrame.width();
1313 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001314 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001315 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001316 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001317 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001318 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001319 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001320 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1321
1322 switch (thumbTransitState) {
1323 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1324 // Entering app scales up with the thumbnail
1325 float scaleW = thumbWidth / appWidth;
1326 float scaleH = thumbHeight / appHeight;
1327 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001328 computePivot(mTmpRect.left, scaleW),
1329 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001330 break;
1331 }
1332 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1333 // Exiting app while the thumbnail is scaling up should fade or stay in place
1334 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1335 // Fade out while bringing up selected activity. This keeps the
1336 // current activity from showing through a launching wallpaper
1337 // activity.
1338 a = new AlphaAnimation(1, 0);
1339 } else {
1340 // noop animation
1341 a = new AlphaAnimation(1, 1);
1342 }
1343 break;
1344 }
1345 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1346 // Entering the other app, it should just be visible while we scale the thumbnail
1347 // down above it
1348 a = new AlphaAnimation(1, 1);
1349 break;
1350 }
1351 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1352 // Exiting the current app, the app should scale down with the thumbnail
1353 float scaleW = thumbWidth / appWidth;
1354 float scaleH = thumbHeight / appHeight;
1355 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001356 computePivot(mTmpRect.left, scaleW),
1357 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001358
1359 Animation alpha = new AlphaAnimation(1, 0);
1360
1361 AnimationSet set = new AnimationSet(true);
1362 set.addAnimation(scale);
1363 set.addAnimation(alpha);
1364 set.setZAdjustment(Animation.ZORDER_TOP);
1365 a = set;
1366 break;
1367 }
1368 default:
1369 throw new RuntimeException("Invalid thumbnail transition state");
1370 }
1371
1372 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1373 }
1374
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001375 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001376 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1377 final int left = mTmpFromClipRect.left;
1378 final int top = mTmpFromClipRect.top;
1379 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001380 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1381 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001382 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001383 float fromWidth = mTmpFromClipRect.width();
1384 float toWidth = mTmpToClipRect.width();
1385 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001386 // While the window might span the whole display, the actual content will be cropped to the
1387 // system decoration frame, for example when the window is docked. We need to take into
1388 // account the visible height when constructing the animation.
1389 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1390 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001391 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1392 // The final window is larger in both dimensions than current window (e.g. we are
1393 // maximizing), so we can simply unclip the new window and there will be no disappearing
1394 // frame.
1395 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1396 } else {
1397 // The disappearing window has one larger dimension. We need to apply scaling, so the
1398 // first frame of the entry animation matches the old window.
1399 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001400 // We might not be going exactly full screen, but instead be aligned under the status
1401 // bar using cropping. We still need to account for the cropped part, which will also
1402 // be scaled.
1403 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001404 }
1405
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001406 // We animate the translation from the old position of the removed window, to the new
1407 // position of the added window. The latter might not be full screen, for example docked for
1408 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001409 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001410 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001411 set.addAnimation(translate);
1412 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001413 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001414 return set;
1415 }
1416
Jorim Jaggic554b772015-06-04 16:07:57 -07001417 /**
1418 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1419 * frame of the transition doesn't change the visuals on screen, so we can start
1420 * directly with the second one
1421 */
1422 boolean canSkipFirstFrame() {
1423 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1424 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
1425 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL;
1426 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001427
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001428 /**
1429 *
1430 * @param frame These are the bounds of the window when it finishes the animation. This is where
1431 * the animation must usually finish in entrance animation, as the next frame will
1432 * display the window at these coordinates. In case of exit animation, this is
1433 * where the animation must start, as the frame before the animation is displaying
1434 * the window at these bounds.
1435 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1436 * window might be obscured, usually by the system windows (status bar and
1437 * navigation bar) and we use content insets to convey that information. This
1438 * usually affects the animation aspects vertically, as the system decoration is
1439 * at the top and the bottom. For example when we animate from full screen to
1440 * recents, we want to exclude the covered parts, because they won't match the
1441 * thumbnail after the last frame is executed.
1442 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1443 * know about this to make the animation frames match. We currently use
1444 * this for freeform windows, which have larger surfaces to display
1445 * shadows. When we animate them from recents, we want to match the content
1446 * to the recents thumbnail and hence need to account for the surface being
1447 * bigger.
1448 */
Winsonb2024762016-04-05 17:32:30 -07001449 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001450 int orientation, Rect frame, Rect displayFrame, Rect insets,
1451 @Nullable Rect surfaceInsets, boolean isVoiceInteraction, boolean freeform,
1452 int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001453 Animation a;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001454 if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
1455 || transit == TRANSIT_TASK_OPEN
1456 || transit == TRANSIT_TASK_TO_FRONT)) {
1457 a = loadAnimationRes(lp, enter
1458 ? com.android.internal.R.anim.voice_activity_open_enter
1459 : com.android.internal.R.anim.voice_activity_open_exit);
1460 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1461 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001462 + " anim=" + a + " transit=" + appTransitionToString(transit)
1463 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001464 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1465 || transit == TRANSIT_TASK_CLOSE
1466 || transit == TRANSIT_TASK_TO_BACK)) {
1467 a = loadAnimationRes(lp, enter
1468 ? com.android.internal.R.anim.voice_activity_close_enter
1469 : com.android.internal.R.anim.voice_activity_close_exit);
1470 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1471 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001472 + " anim=" + a + " transit=" + appTransitionToString(transit)
1473 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001474 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001475 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001476 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1477 "applyAnimation:"
1478 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1479 + " transit=" + appTransitionToString(transit)
1480 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001481 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1482 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001483 mNextAppTransitionEnter : mNextAppTransitionExit);
1484 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1485 "applyAnimation:"
1486 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001487 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001488 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001489 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1490 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1491 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1492 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001493 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1494 + " transit=" + appTransitionToString(transit)
1495 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001496 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001497 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001498 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1499 "applyAnimation:"
1500 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001501 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001502 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001503 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001504 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001505 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1506 "applyAnimation:"
1507 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001508 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001509 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001510 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1511 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001512 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001513 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001514 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001515 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001516 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1517 String animName = mNextAppTransitionScaleUp ?
1518 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1519 Slog.v(TAG, "applyAnimation:"
1520 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001521 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001522 + " Callers=" + Debug.getCallers(3));
1523 }
1524 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1525 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1526 mNextAppTransitionScaleUp =
1527 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1528 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001529 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001530 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001531 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1532 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001533 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001534 Slog.v(TAG, "applyAnimation:"
1535 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001536 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001537 + " Callers=" + Debug.getCallers(3));
1538 }
1539 } else {
1540 int animAttr = 0;
1541 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001542 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001543 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001544 ? WindowAnimation_activityOpenEnterAnimation
1545 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001546 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001547 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001548 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001549 ? WindowAnimation_activityCloseEnterAnimation
1550 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001551 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001552 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001553 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001554 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001555 ? WindowAnimation_taskOpenEnterAnimation
1556 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001557 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001558 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001559 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001560 ? WindowAnimation_taskCloseEnterAnimation
1561 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001562 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001563 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001564 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001565 ? WindowAnimation_taskToFrontEnterAnimation
1566 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001567 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001568 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001569 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001570 ? WindowAnimation_taskToBackEnterAnimation
1571 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001572 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001573 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001574 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001575 ? WindowAnimation_wallpaperOpenEnterAnimation
1576 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001577 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001578 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001579 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001580 ? WindowAnimation_wallpaperCloseEnterAnimation
1581 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001582 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001583 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001584 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001585 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1586 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001587 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001588 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001589 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001590 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1591 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001592 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001593 case TRANSIT_TASK_OPEN_BEHIND:
1594 animAttr = enter
1595 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001596 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001597 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001598 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001599 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1600 "applyAnimation:"
1601 + " anim=" + a
1602 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001603 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001604 + " Callers=" + Debug.getCallers(3));
1605 }
1606 return a;
1607 }
1608
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001609 int getAppStackClipMode() {
1610 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001611 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001612 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001613 ? STACK_CLIP_NONE
1614 : STACK_CLIP_AFTER_ANIM;
1615 }
1616
Craig Mautner164d4bb2012-11-26 13:51:23 -08001617 void postAnimationCallback() {
1618 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001619 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1620 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001621 mNextAppTransitionCallback = null;
1622 }
1623 }
1624
1625 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001626 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001627 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001628 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001629 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001630 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001631 mNextAppTransitionEnter = enterAnim;
1632 mNextAppTransitionExit = exitAnim;
1633 postAnimationCallback();
1634 mNextAppTransitionCallback = startedCallback;
1635 } else {
1636 postAnimationCallback();
1637 }
1638 }
1639
1640 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001641 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001642 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001643 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001644 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001645 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001646 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001647 }
1648 }
1649
Chet Haase10e23ab2015-02-11 15:08:38 -08001650 void overridePendingAppTransitionClipReveal(int startX, int startY,
1651 int startWidth, int startHeight) {
1652 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001653 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001654 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001655 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001656 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001657 }
1658 }
1659
Craig Mautner164d4bb2012-11-26 13:51:23 -08001660 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1661 IRemoteCallback startedCallback, boolean scaleUp) {
1662 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001663 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001664 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1665 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001666 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001667 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001668 postAnimationCallback();
1669 mNextAppTransitionCallback = startedCallback;
1670 } else {
1671 postAnimationCallback();
1672 }
1673 }
1674
Winson Chunga4ccb862014-08-22 15:26:27 -07001675 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001676 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001677 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001678 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001679 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1680 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001681 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001682 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1683 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001684 postAnimationCallback();
1685 mNextAppTransitionCallback = startedCallback;
1686 } else {
1687 postAnimationCallback();
1688 }
1689 }
1690
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001691 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001692 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1693 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001694 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001695 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001696 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1697 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001698 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001699 if (specs != null) {
1700 for (int i = 0; i < specs.length; i++) {
1701 AppTransitionAnimationSpec spec = specs[i];
1702 if (spec != null) {
1703 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1704 if (i == 0) {
1705 // In full screen mode, the transition code depends on the default spec
1706 // to be set.
1707 Rect rect = spec.rect;
1708 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Filip Gruszczynskie3264d82015-11-20 17:10:04 -08001709 rect.width(), rect.height(), spec.bitmap);
Jorim Jaggi43102412015-11-11 16:28:37 +01001710 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001711 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001712 }
1713 }
1714 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001715 mNextAppTransitionCallback = onAnimationStartedCallback;
1716 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001717 } else {
1718 postAnimationCallback();
1719 }
1720 }
1721
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001722 void overridePendingAppTransitionMultiThumbFuture(
1723 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1724 boolean scaleUp) {
1725 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001726 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001727 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1728 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001729 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1730 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001731 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001732 }
1733 }
1734
Winson Chung044d5292014-11-06 11:05:19 -08001735 void overrideInPlaceAppTransition(String packageName, int anim) {
1736 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001737 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001738 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1739 mNextAppTransitionPackage = packageName;
1740 mNextAppTransitionInPlace = anim;
1741 } else {
1742 postAnimationCallback();
1743 }
1744 }
1745
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001746 /**
1747 * If a future is set for the app transition specs, fetch it in another thread.
1748 */
1749 private void fetchAppTransitionSpecsFromFuture() {
1750 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1751 mNextAppTransitionAnimationsSpecsPending = true;
1752 final IAppTransitionAnimationSpecsFuture future
1753 = mNextAppTransitionAnimationsSpecsFuture;
1754 mNextAppTransitionAnimationsSpecsFuture = null;
1755 mDefaultExecutor.execute(new Runnable() {
1756 @Override
1757 public void run() {
1758 AppTransitionAnimationSpec[] specs = null;
1759 try {
1760 specs = future.get();
1761 } catch (RemoteException e) {
1762 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1763 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001764 synchronized (mService.mWindowMap) {
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001765 mNextAppTransitionAnimationsSpecsPending = false;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001766 overridePendingAppTransitionMultiThumb(specs,
1767 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1768 mNextAppTransitionScaleUp);
1769 mNextAppTransitionFutureCallback = null;
Filip Gruszczynski96daf322015-11-18 18:01:27 -08001770 if (specs != null) {
1771 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1772 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001773 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001774 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001775 }
1776 });
1777 }
1778 }
1779
Craig Mautner164d4bb2012-11-26 13:51:23 -08001780 @Override
1781 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001782 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001783 }
1784
Craig Mautner4b71aa12012-12-27 17:20:01 -08001785 /**
1786 * Returns the human readable name of a window transition.
1787 *
1788 * @param transition The window transition.
1789 * @return The transition symbolic name.
1790 */
1791 public static String appTransitionToString(int transition) {
1792 switch (transition) {
1793 case TRANSIT_UNSET: {
1794 return "TRANSIT_UNSET";
1795 }
1796 case TRANSIT_NONE: {
1797 return "TRANSIT_NONE";
1798 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001799 case TRANSIT_ACTIVITY_OPEN: {
1800 return "TRANSIT_ACTIVITY_OPEN";
1801 }
1802 case TRANSIT_ACTIVITY_CLOSE: {
1803 return "TRANSIT_ACTIVITY_CLOSE";
1804 }
1805 case TRANSIT_TASK_OPEN: {
1806 return "TRANSIT_TASK_OPEN";
1807 }
1808 case TRANSIT_TASK_CLOSE: {
1809 return "TRANSIT_TASK_CLOSE";
1810 }
1811 case TRANSIT_TASK_TO_FRONT: {
1812 return "TRANSIT_TASK_TO_FRONT";
1813 }
1814 case TRANSIT_TASK_TO_BACK: {
1815 return "TRANSIT_TASK_TO_BACK";
1816 }
1817 case TRANSIT_WALLPAPER_CLOSE: {
1818 return "TRANSIT_WALLPAPER_CLOSE";
1819 }
1820 case TRANSIT_WALLPAPER_OPEN: {
1821 return "TRANSIT_WALLPAPER_OPEN";
1822 }
1823 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1824 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1825 }
1826 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1827 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1828 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001829 case TRANSIT_TASK_OPEN_BEHIND: {
1830 return "TRANSIT_TASK_OPEN_BEHIND";
1831 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001832 case TRANSIT_ACTIVITY_RELAUNCH: {
1833 return "TRANSIT_ACTIVITY_RELAUNCH";
1834 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001835 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1836 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1837 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001838 default: {
1839 return "<UNKNOWN>";
1840 }
1841 }
1842 }
1843
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001844 private String appStateToString() {
1845 switch (mAppTransitionState) {
1846 case APP_STATE_IDLE:
1847 return "APP_STATE_IDLE";
1848 case APP_STATE_READY:
1849 return "APP_STATE_READY";
1850 case APP_STATE_RUNNING:
1851 return "APP_STATE_RUNNING";
1852 case APP_STATE_TIMEOUT:
1853 return "APP_STATE_TIMEOUT";
1854 default:
1855 return "unknown state=" + mAppTransitionState;
1856 }
1857 }
1858
1859 private String transitTypeToString() {
1860 switch (mNextAppTransitionType) {
1861 case NEXT_TRANSIT_TYPE_NONE:
1862 return "NEXT_TRANSIT_TYPE_NONE";
1863 case NEXT_TRANSIT_TYPE_CUSTOM:
1864 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001865 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1866 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001867 case NEXT_TRANSIT_TYPE_SCALE_UP:
1868 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1869 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1870 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1871 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1872 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001873 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1874 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1875 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1876 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001877 default:
1878 return "unknown type=" + mNextAppTransitionType;
1879 }
1880 }
1881
Craig Mautner164d4bb2012-11-26 13:51:23 -08001882 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001883 public void dump(PrintWriter pw, String prefix) {
1884 pw.print(prefix); pw.println(this);
1885 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001886 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001887 pw.print(prefix); pw.print("mNextAppTransitionType=");
1888 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001889 }
1890 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001891 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001892 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001893 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001894 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001895 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1896 pw.print(" mNextAppTransitionExit=0x");
1897 pw.println(Integer.toHexString(mNextAppTransitionExit));
1898 break;
Winson Chung044d5292014-11-06 11:05:19 -08001899 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001900 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001901 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001902 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001903 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1904 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001905 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001906 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001907 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001908 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001909 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001910 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001911 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001912 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001913 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001914 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001915 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001916 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001917 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1918 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001919 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001920 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1921 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1922 pw.println(mDefaultNextAppTransitionAnimationSpec);
1923 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1924 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001925 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1926 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001927 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001928 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001929 }
1930 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001931 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1932 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001933 }
Chong Zhang60091a92016-07-27 17:52:45 -07001934 if (mLastUsedAppTransition != TRANSIT_NONE) {
1935 pw.print(prefix); pw.print("mLastUsedAppTransition=");
1936 pw.println(appTransitionToString(mLastUsedAppTransition));
1937 pw.print(prefix); pw.print("mLastOpeningApp=");
1938 pw.println(mLastOpeningApp);
1939 pw.print(prefix); pw.print("mLastClosingApp=");
1940 pw.println(mLastClosingApp);
1941 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001942 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001943
1944 public void setCurrentUser(int newUserId) {
1945 mCurrentUserId = newUserId;
1946 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001947
1948 /**
1949 * @return true if transition is not running and should not be skipped, false if transition is
1950 * already running
1951 */
1952 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent) {
1953 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
1954 + " transit=" + appTransitionToString(transit)
1955 + " " + this
1956 + " alwaysKeepCurrent=" + alwaysKeepCurrent
1957 + " Callers=" + Debug.getCallers(3));
1958 if (!isTransitionSet() || mNextAppTransition == TRANSIT_NONE) {
1959 setAppTransition(transit);
1960 } else if (!alwaysKeepCurrent) {
1961 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
1962 // Opening a new task always supersedes a close for the anim.
1963 setAppTransition(transit);
1964 } else if (transit == TRANSIT_ACTIVITY_OPEN
1965 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
1966 // Opening a new activity always supersedes a close for the anim.
1967 setAppTransition(transit);
1968 }
1969 }
1970 boolean prepared = prepare();
1971 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001972 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
1973 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001974 }
1975 return prepared;
1976 }
Winsonb2024762016-04-05 17:32:30 -07001977
1978 /**
Manu Cornetda5900d2017-01-12 15:05:13 -08001979 * @return whether the transition should show the thumbnail being scaled down.
1980 */
1981 private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) {
1982 return isTvUiMode(uiMode)
1983 || mGridLayoutRecentsEnabled
1984 || orientation == Configuration.ORIENTATION_PORTRAIT;
1985 }
1986
1987 /**
Winsonb2024762016-04-05 17:32:30 -07001988 * @return whether the specified {@param uiMode} is the TV mode.
1989 */
1990 private boolean isTvUiMode(int uiMode) {
1991 return (uiMode & Configuration.UI_MODE_TYPE_TELEVISION) > 0;
1992 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001993}