blob: 862c1455d3a14e107e67548d568b343d5e546fda [file] [log] [blame]
Craig Mautner164d4bb2012-11-26 13:51:23 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Filip Gruszczynski82861362015-10-16 14:21:09 -070019import static android.view.WindowManagerInternal.AppTransitionListener;
20import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation;
21import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation;
22import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation;
23import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation;
24import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation;
25import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation;
26import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation;
27import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation;
28import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation;
29import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation;
30import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation;
31import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation;
32import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation;
33import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation;
34import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation;
35import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation;
36import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation;
37import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation;
38import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation;
39import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation;
40import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation;
41import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation;
Jorim Jaggi363ab982016-04-26 19:51:20 -070042import static com.android.server.wm.AppWindowAnimator.PROLONG_ANIMATION_AT_START;
Filip Gruszczynski198dcbf2016-01-18 10:02:00 -080043import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
44import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080045import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
46import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +010047import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE;
48import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
Filip Gruszczynski82861362015-10-16 14:21:09 -070049
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -070050import android.annotation.Nullable;
Craig Mautner164d4bb2012-11-26 13:51:23 -080051import android.content.Context;
Winson21700932016-03-24 17:26:23 -070052import android.content.res.Configuration;
Craig Mautner164d4bb2012-11-26 13:51:23 -080053import android.graphics.Bitmap;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010054import android.graphics.Path;
Winson Chung399f6202014-03-19 10:47:20 -070055import android.graphics.Rect;
Craig Mautner164d4bb2012-11-26 13:51:23 -080056import android.os.Debug;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010057import android.os.IBinder;
Craig Mautner164d4bb2012-11-26 13:51:23 -080058import android.os.IRemoteCallback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010059import android.os.RemoteException;
Jorim Jaggi42625d1b2016-02-11 20:11:07 -080060import android.util.ArraySet;
Craig Mautner164d4bb2012-11-26 13:51:23 -080061import android.util.Slog;
Filip Gruszczynski170192a2015-08-16 17:46:34 -070062import android.util.SparseArray;
63import android.view.AppTransitionAnimationSpec;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010064import android.view.IAppTransitionAnimationSpecsFuture;
Craig Mautner164d4bb2012-11-26 13:51:23 -080065import android.view.WindowManager;
Craig Mautner164d4bb2012-11-26 13:51:23 -080066import android.view.animation.AlphaAnimation;
67import android.view.animation.Animation;
68import android.view.animation.AnimationSet;
69import android.view.animation.AnimationUtils;
Winson Chung399f6202014-03-19 10:47:20 -070070import android.view.animation.ClipRectAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080071import android.view.animation.Interpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070072import android.view.animation.PathInterpolator;
Craig Mautner164d4bb2012-11-26 13:51:23 -080073import android.view.animation.ScaleAnimation;
Winson Chung399f6202014-03-19 10:47:20 -070074import android.view.animation.TranslateAnimation;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070075
Craig Mautner164d4bb2012-11-26 13:51:23 -080076import com.android.internal.util.DumpUtils.Dump;
77import com.android.server.AttributeCache;
78import com.android.server.wm.WindowManagerService.H;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -080079import com.android.server.wm.animation.ClipRectLRAnimation;
80import com.android.server.wm.animation.ClipRectTBAnimation;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +010081import com.android.server.wm.animation.CurvedTranslateAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -080082
83import java.io.PrintWriter;
Jorim Jaggi77ba4802015-02-18 13:57:50 +010084import java.util.ArrayList;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +010085import java.util.concurrent.ExecutorService;
86import java.util.concurrent.Executors;
Craig Mautner164d4bb2012-11-26 13:51:23 -080087
Craig Mautner164d4bb2012-11-26 13:51:23 -080088// State management of app transitions. When we are preparing for a
89// transition, mNextAppTransition will be the kind of transition to
90// perform or TRANSIT_NONE if we are not waiting. If we are waiting,
91// mOpeningApps and mClosingApps are the lists of tokens that will be
92// made visible or hidden at the next transition.
93public class AppTransition implements Dump {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080094 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM;
Jorim Jaggi1d763a62015-06-02 17:07:39 -070095 private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -080096
Craig Mautner4b71aa12012-12-27 17:20:01 -080097 /** Not set up for a transition. */
98 public static final int TRANSIT_UNSET = -1;
99 /** No animation for transition. */
100 public static final int TRANSIT_NONE = 0;
101 /** A window in a new activity is being opened on top of an existing one in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700102 public static final int TRANSIT_ACTIVITY_OPEN = 6;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800103 /** The window in the top-most activity is being closed to reveal the
104 * previous activity in the same task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700105 public static final int TRANSIT_ACTIVITY_CLOSE = 7;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800106 /** A window in a new task is being opened on top of an existing one
107 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700108 public static final int TRANSIT_TASK_OPEN = 8;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800109 /** A window in the top-most activity is being closed to reveal the
110 * previous activity in a different task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700111 public static final int TRANSIT_TASK_CLOSE = 9;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800112 /** A window in an existing task is being displayed on top of an existing one
113 * in another activity's task. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700114 public static final int TRANSIT_TASK_TO_FRONT = 10;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800115 /** A window in an existing task is being put below all other tasks. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700116 public static final int TRANSIT_TASK_TO_BACK = 11;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800117 /** A window in a new activity that doesn't have a wallpaper is being opened on top of one that
118 * does, effectively closing the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700119 public static final int TRANSIT_WALLPAPER_CLOSE = 12;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800120 /** A window in a new activity that does have a wallpaper is being opened on one that didn't,
121 * effectively opening the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700122 public static final int TRANSIT_WALLPAPER_OPEN = 13;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800123 /** A window in a new activity is being opened on top of an existing one, and both are on top
124 * of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700125 public static final int TRANSIT_WALLPAPER_INTRA_OPEN = 14;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800126 /** The window in the top-most activity is being closed to reveal the previous activity, and
127 * both are on top of the wallpaper. */
Craig Mautnerbb742462014-07-07 15:28:55 -0700128 public static final int TRANSIT_WALLPAPER_INTRA_CLOSE = 15;
129 /** A window in a new task is being opened behind an existing one in another activity's task.
130 * The new window will show briefly and then be gone. */
131 public static final int TRANSIT_TASK_OPEN_BEHIND = 16;
Winson Chung044d5292014-11-06 11:05:19 -0800132 /** A window in a task is being animated in-place. */
133 public static final int TRANSIT_TASK_IN_PLACE = 17;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700134 /** An activity is being relaunched (e.g. due to configuration change). */
135 public static final int TRANSIT_ACTIVITY_RELAUNCH = 18;
Jorim Jaggi192086e2016-03-11 17:17:03 +0100136 /** A task is being docked from recents. */
137 public static final int TRANSIT_DOCK_TASK_FROM_RECENTS = 19;
Jorim Jaggife762342016-10-13 14:33:27 +0200138 /** Keyguard is going away */
139 public static final int TRANSIT_KEYGUARD_GOING_AWAY = 20;
140 /** Keyguard is going away with showing an activity behind that requests wallpaper */
141 public static final int TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER = 21;
142 /** Keyguard is being occluded */
143 public static final int TRANSIT_KEYGUARD_OCCLUDE = 22;
144 /** Keyguard is being unoccluded */
145 public static final int TRANSIT_KEYGUARD_UNOCCLUDE = 23;
146
147 /** Transition flag: Keyguard is going away, but keeping the notification shade open */
148 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE = 0x1;
149 /** Transition flag: Keyguard is going away, but doesn't want an animation for it */
150 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION = 0x2;
151 /** Transition flag: Keyguard is going away while it was showing the system wallpaper. */
152 public static final int TRANSIT_FLAG_KEYGUARD_GOING_AWAY_WITH_WALLPAPER = 0x4;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800153
Winson Chunga4ccb862014-08-22 15:26:27 -0700154 /** Fraction of animation at which the recents thumbnail stays completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700155 private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800156 /** Fraction of animation at which the recents thumbnail becomes completely transparent */
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700157 private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800158
Filip Gruszczynski84fa3352016-01-25 16:28:49 -0800159 static final int DEFAULT_APP_TRANSITION_DURATION = 336;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800160
161 /** Interpolator to be used for animations that respond directly to a touch */
162 static final Interpolator TOUCH_RESPONSE_INTERPOLATOR =
163 new PathInterpolator(0.3f, 0f, 0.1f, 1f);
164
Jorim Jaggic69bd222016-03-15 14:38:37 +0100165 private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR =
166 new PathInterpolator(0.85f, 0f, 1f, 1f);
167
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800168 /**
169 * Maximum duration for the clip reveal animation. This is used when there is a lot of movement
170 * involved, to make it more understandable.
171 */
172 private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700173 private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336;
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700174 private static final long APP_TRANSITION_TIMEOUT_MS = 5000;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800175
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800176 private final Context mContext;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800177 private final WindowManagerService mService;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800178
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800179 private int mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200180 private int mNextAppTransitionFlags = 0;
Chong Zhang60091a92016-07-27 17:52:45 -0700181 private int mLastUsedAppTransition = TRANSIT_UNSET;
182 private String mLastOpeningApp;
183 private String mLastClosingApp;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800184
185 private static final int NEXT_TRANSIT_TYPE_NONE = 0;
186 private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1;
187 private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2;
188 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3;
189 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4;
Winson Chunga4ccb862014-08-22 15:26:27 -0700190 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5;
191 private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6;
Winson Chung044d5292014-11-06 11:05:19 -0800192 private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7;
Chet Haase10e23ab2015-02-11 15:08:38 -0800193 private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800194 private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
195
Winson Chung399f6202014-03-19 10:47:20 -0700196 // These are the possible states for the enter/exit activities during a thumbnail transition
197 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0;
198 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1;
199 private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2;
200 private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3;
201
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800202 private String mNextAppTransitionPackage;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800203 // Used for thumbnail transitions. True if we're scaling up, false if scaling down
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800204 private boolean mNextAppTransitionScaleUp;
205 private IRemoteCallback mNextAppTransitionCallback;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +0100206 private IRemoteCallback mNextAppTransitionFutureCallback;
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -0700207 private IRemoteCallback mAnimationFinishedCallback;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800208 private int mNextAppTransitionEnter;
209 private int mNextAppTransitionExit;
Winson Chung044d5292014-11-06 11:05:19 -0800210 private int mNextAppTransitionInPlace;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700211
212 // Keyed by task id.
213 private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs
214 = new SparseArray<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100215 private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture;
216 private boolean mNextAppTransitionAnimationsSpecsPending;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700217 private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec;
218
Winson Chunga4ccb862014-08-22 15:26:27 -0700219 private Rect mNextAppTransitionInsets = new Rect();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800220
Winson Chung2820c452014-04-15 15:34:44 -0700221 private Rect mTmpFromClipRect = new Rect();
222 private Rect mTmpToClipRect = new Rect();
223
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700224 private final Rect mTmpRect = new Rect();
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700225
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800226 private final static int APP_STATE_IDLE = 0;
227 private final static int APP_STATE_READY = 1;
228 private final static int APP_STATE_RUNNING = 2;
229 private final static int APP_STATE_TIMEOUT = 3;
230 private int mAppTransitionState = APP_STATE_IDLE;
231
232 private final int mConfigShortAnimTime;
Craig Mautner321bdf52012-12-18 09:53:24 -0800233 private final Interpolator mDecelerateInterpolator;
Winson Chunga4ccb862014-08-22 15:26:27 -0700234 private final Interpolator mThumbnailFadeInInterpolator;
235 private final Interpolator mThumbnailFadeOutInterpolator;
Chet Haase10e23ab2015-02-11 15:08:38 -0800236 private final Interpolator mLinearOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700237 private final Interpolator mFastOutLinearInInterpolator;
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100238 private final Interpolator mFastOutSlowInInterpolator;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700239 private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f);
240
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700241 private final int mClipRevealTranslationY;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800242
Amith Yamasani4befbec2013-07-10 16:18:01 -0700243 private int mCurrentUserId = 0;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800244 private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Amith Yamasani4befbec2013-07-10 16:18:01 -0700245
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100246 private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100247 private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor();
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100248
Jorim Jaggif97ed922016-02-18 18:57:07 -0800249 private int mLastClipRevealMaxTranslation;
250 private boolean mLastHadClipReveal;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700251 private boolean mProlongedAnimationsEnded;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800252
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800253 AppTransition(Context context, WindowManagerService service) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800254 mContext = context;
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -0800255 mService = service;
Chet Haase10e23ab2015-02-11 15:08:38 -0800256 mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
257 com.android.internal.R.interpolator.linear_out_slow_in);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700258 mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context,
259 com.android.internal.R.interpolator.fast_out_linear_in);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100260 mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
261 com.android.internal.R.interpolator.fast_out_slow_in);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800262 mConfigShortAnimTime = context.getResources().getInteger(
263 com.android.internal.R.integer.config_shortAnimTime);
Craig Mautner321bdf52012-12-18 09:53:24 -0800264 mDecelerateInterpolator = AnimationUtils.loadInterpolator(context,
265 com.android.internal.R.interpolator.decelerate_cubic);
Winson Chunga4ccb862014-08-22 15:26:27 -0700266 mThumbnailFadeInInterpolator = new Interpolator() {
267 @Override
268 public float getInterpolation(float input) {
269 // Linear response for first fraction, then complete after that.
270 if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) {
271 return 0f;
272 }
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700273 float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) /
Winson Chunga4ccb862014-08-22 15:26:27 -0700274 (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700275 return mFastOutLinearInInterpolator.getInterpolation(t);
Winson Chunga4ccb862014-08-22 15:26:27 -0700276 }
277 };
278 mThumbnailFadeOutInterpolator = new Interpolator() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800279 @Override
280 public float getInterpolation(float input) {
281 // Linear response for first fraction, then complete after that.
282 if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) {
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700283 float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION;
284 return mLinearOutSlowInInterpolator.getInterpolation(t);
Craig Mautner321bdf52012-12-18 09:53:24 -0800285 }
Winson Chunga4ccb862014-08-22 15:26:27 -0700286 return 1f;
Craig Mautner321bdf52012-12-18 09:53:24 -0800287 }
288 };
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700289 mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP
290 * mContext.getResources().getDisplayMetrics().density);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800291 }
292
293 boolean isTransitionSet() {
294 return mNextAppTransition != TRANSIT_UNSET;
295 }
296
Craig Mautner164d4bb2012-11-26 13:51:23 -0800297 boolean isTransitionEqual(int transit) {
298 return mNextAppTransition == transit;
299 }
300
301 int getAppTransition() {
Craig Mautner321bdf52012-12-18 09:53:24 -0800302 return mNextAppTransition;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800303 }
304
Jorim Jaggife762342016-10-13 14:33:27 +0200305 private void setAppTransition(int transit, int flags) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800306 mNextAppTransition = transit;
Jorim Jaggife762342016-10-13 14:33:27 +0200307 mNextAppTransitionFlags |= flags;
Chong Zhang60091a92016-07-27 17:52:45 -0700308 setLastAppTransition(TRANSIT_UNSET, null, null);
309 }
310
311 void setLastAppTransition(int transit, AppWindowToken openingApp, AppWindowToken closingApp) {
312 mLastUsedAppTransition = transit;
313 mLastOpeningApp = "" + openingApp;
314 mLastClosingApp = "" + closingApp;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800315 }
316
317 boolean isReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800318 return mAppTransitionState == APP_STATE_READY
319 || mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800320 }
321
Craig Mautnerae446592012-12-06 19:05:05 -0800322 void setReady() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800323 mAppTransitionState = APP_STATE_READY;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100324 fetchAppTransitionSpecsFromFuture();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800325 }
326
327 boolean isRunning() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800328 return mAppTransitionState == APP_STATE_RUNNING;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800329 }
330
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800331 void setIdle() {
332 mAppTransitionState = APP_STATE_IDLE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800333 }
334
335 boolean isTimeout() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800336 return mAppTransitionState == APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800337 }
338
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800339 void setTimeout() {
340 mAppTransitionState = APP_STATE_TIMEOUT;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800341 }
342
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700343 Bitmap getAppTransitionThumbnailHeader(int taskId) {
344 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800345 if (spec == null) {
346 spec = mDefaultNextAppTransitionAnimationSpec;
347 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700348 return spec != null ? spec.bitmap : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800349 }
350
Winson Chunga4ccb862014-08-22 15:26:27 -0700351 /** Returns whether the next thumbnail transition is aspect scaled up. */
352 boolean isNextThumbnailTransitionAspectScaled() {
353 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
354 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
355 }
356
357 /** Returns whether the next thumbnail transition is scaling up. */
358 boolean isNextThumbnailTransitionScaleUp() {
359 return mNextAppTransitionScaleUp;
360 }
361
Filip Gruszczynski4cbc3152015-12-07 11:50:57 -0800362 boolean isNextAppTransitionThumbnailUp() {
363 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
364 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP;
365 }
366
367 boolean isNextAppTransitionThumbnailDown() {
368 return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN ||
369 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
370 }
371
Jorim Jaggi2f7d2922015-10-29 13:08:29 +0100372 /**
373 * @return true if and only if we are currently fetching app transition specs from the future
374 * passed into {@link #overridePendingAppTransitionMultiThumbFuture}
375 */
376 boolean isFetchingAppTransitionsSpecs() {
377 return mNextAppTransitionAnimationsSpecsPending;
378 }
379
Filip Gruszczynski24966d42015-09-05 15:00:00 -0700380 private boolean prepare() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800381 if (!isRunning()) {
382 mAppTransitionState = APP_STATE_IDLE;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100383 notifyAppTransitionPendingLocked();
Jorim Jaggif97ed922016-02-18 18:57:07 -0800384 mLastHadClipReveal = false;
385 mLastClipRevealMaxTranslation = 0;
386 mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION;
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700387 return true;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800388 }
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -0700389 return false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800390 }
391
Jorim Jaggife762342016-10-13 14:33:27 +0200392 /**
393 * @return bit-map of WindowManagerPolicy#FINISH_LAYOUT_REDO_* to indicate whether another
394 * layout pass needs to be done
395 */
396 int goodToGo(int transit, AppWindowAnimator topOpeningAppAnimator,
397 AppWindowAnimator topClosingAppAnimator, ArraySet<AppWindowToken> openingApps,
398 ArraySet<AppWindowToken> closingApps) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800399 mNextAppTransition = TRANSIT_UNSET;
Jorim Jaggife762342016-10-13 14:33:27 +0200400 mNextAppTransitionFlags = 0;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800401 mAppTransitionState = APP_STATE_RUNNING;
Jorim Jaggife762342016-10-13 14:33:27 +0200402 int redoLayout = notifyAppTransitionStartingLocked(transit,
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800403 topOpeningAppAnimator != null ? topOpeningAppAnimator.mAppToken.token : null,
404 topClosingAppAnimator != null ? topClosingAppAnimator.mAppToken.token : null,
405 topOpeningAppAnimator != null ? topOpeningAppAnimator.animation : null,
406 topClosingAppAnimator != null ? topClosingAppAnimator.animation : null);
407 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Jorim Jaggife762342016-10-13 14:33:27 +0200408 .notifyAppTransitionStarting(openingApps, transit);
Jorim Jaggi363ab982016-04-26 19:51:20 -0700409
410 // Prolong the start for the transition when docking a task from recents, unless recents
411 // ended it already then we don't need to wait.
Jorim Jaggife762342016-10-13 14:33:27 +0200412 if (transit == TRANSIT_DOCK_TASK_FROM_RECENTS && !mProlongedAnimationsEnded) {
Jorim Jaggi363ab982016-04-26 19:51:20 -0700413 for (int i = openingApps.size() - 1; i >= 0; i--) {
414 final AppWindowAnimator appAnimator = openingApps.valueAt(i).mAppAnimator;
415 appAnimator.startProlongAnimation(PROLONG_ANIMATION_AT_START);
416 }
417 }
Jorim Jaggife762342016-10-13 14:33:27 +0200418 return redoLayout;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700419 }
420
421 /**
422 * Let the transitions manager know that the somebody wanted to end the prolonged animations.
423 */
424 void notifyProlongedAnimationsEnded() {
425 mProlongedAnimationsEnded = true;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800426 }
427
428 void clear() {
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800429 mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800430 mNextAppTransitionPackage = null;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700431 mNextAppTransitionAnimationsSpecs.clear();
Jorim Jaggi65193992015-11-23 16:49:59 -0800432 mNextAppTransitionAnimationsSpecsFuture = null;
433 mDefaultNextAppTransitionAnimationSpec = null;
434 mAnimationFinishedCallback = null;
Jorim Jaggi363ab982016-04-26 19:51:20 -0700435 mProlongedAnimationsEnded = false;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800436 }
437
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800438 void freeze() {
Jorim Jaggife762342016-10-13 14:33:27 +0200439 final int transit = mNextAppTransition;
440 setAppTransition(AppTransition.TRANSIT_UNSET, 0 /* flags */);
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800441 clear();
442 setReady();
Jorim Jaggife762342016-10-13 14:33:27 +0200443 notifyAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100444 }
445
446 void registerListenerLocked(AppTransitionListener listener) {
447 mListeners.add(listener);
448 }
449
Wale Ogunwalea48eadb2015-05-14 17:43:12 -0700450 public void notifyAppTransitionFinishedLocked(IBinder token) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100451 for (int i = 0; i < mListeners.size(); i++) {
452 mListeners.get(i).onAppTransitionFinishedLocked(token);
453 }
454 }
455
456 private void notifyAppTransitionPendingLocked() {
457 for (int i = 0; i < mListeners.size(); i++) {
458 mListeners.get(i).onAppTransitionPendingLocked();
459 }
460 }
461
Jorim Jaggife762342016-10-13 14:33:27 +0200462 private void notifyAppTransitionCancelledLocked(int transit) {
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100463 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200464 mListeners.get(i).onAppTransitionCancelledLocked(transit);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100465 }
466 }
467
Jorim Jaggife762342016-10-13 14:33:27 +0200468 private int notifyAppTransitionStartingLocked(int transit, IBinder openToken,
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100469 IBinder closeToken, Animation openAnimation, Animation closeAnimation) {
Jorim Jaggife762342016-10-13 14:33:27 +0200470 int redoLayout = 0;
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100471 for (int i = 0; i < mListeners.size(); i++) {
Jorim Jaggife762342016-10-13 14:33:27 +0200472 redoLayout |= mListeners.get(i).onAppTransitionStartingLocked(transit, openToken,
473 closeToken, openAnimation, closeAnimation);
Jorim Jaggi77ba4802015-02-18 13:57:50 +0100474 }
Jorim Jaggife762342016-10-13 14:33:27 +0200475 return redoLayout;
Craig Mautner9a29a5d2012-12-27 19:03:40 -0800476 }
477
Craig Mautner164d4bb2012-11-26 13:51:23 -0800478 private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) {
479 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg="
480 + (lp != null ? lp.packageName : null)
481 + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null));
482 if (lp != null && lp.windowAnimations != 0) {
483 // If this is a system resource, don't try to load it from the
484 // application resources. It is nice to avoid loading application
485 // resources if we can.
486 String packageName = lp.packageName != null ? lp.packageName : "android";
487 int resId = lp.windowAnimations;
488 if ((resId&0xFF000000) == 0x01000000) {
489 packageName = "android";
490 }
491 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
492 + packageName);
493 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700494 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800495 }
496 return null;
497 }
498
499 private AttributeCache.Entry getCachedAnimations(String packageName, int resId) {
500 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package="
501 + packageName + " resId=0x" + Integer.toHexString(resId));
502 if (packageName != null) {
503 if ((resId&0xFF000000) == 0x01000000) {
504 packageName = "android";
505 }
506 if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package="
507 + packageName);
508 return AttributeCache.instance().get(packageName, resId,
Amith Yamasani4befbec2013-07-10 16:18:01 -0700509 com.android.internal.R.styleable.WindowAnimation, mCurrentUserId);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800510 }
511 return null;
512 }
513
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700514 Animation loadAnimationAttr(WindowManager.LayoutParams lp, int animAttr) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800515 int anim = 0;
516 Context context = mContext;
517 if (animAttr >= 0) {
518 AttributeCache.Entry ent = getCachedAnimations(lp);
519 if (ent != null) {
520 context = ent.context;
521 anim = ent.array.getResourceId(animAttr, 0);
522 }
523 }
524 if (anim != 0) {
525 return AnimationUtils.loadAnimation(context, anim);
526 }
527 return null;
528 }
529
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700530 Animation loadAnimationRes(WindowManager.LayoutParams lp, int resId) {
531 Context context = mContext;
532 if (resId >= 0) {
533 AttributeCache.Entry ent = getCachedAnimations(lp);
534 if (ent != null) {
535 context = ent.context;
536 }
537 return AnimationUtils.loadAnimation(context, resId);
538 }
539 return null;
540 }
541
542 private Animation loadAnimationRes(String packageName, int resId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -0800543 int anim = 0;
544 Context context = mContext;
545 if (resId >= 0) {
546 AttributeCache.Entry ent = getCachedAnimations(packageName, resId);
547 if (ent != null) {
548 context = ent.context;
549 anim = resId;
550 }
551 }
552 if (anim != 0) {
553 return AnimationUtils.loadAnimation(context, anim);
554 }
555 return null;
556 }
557
Craig Mautner164d4bb2012-11-26 13:51:23 -0800558 /**
559 * Compute the pivot point for an animation that is scaling from a small
560 * rect on screen to a larger rect. The pivot point varies depending on
561 * the distance between the inner and outer edges on both sides. This
562 * function computes the pivot point for one dimension.
563 * @param startPos Offset from left/top edge of outer rectangle to
564 * left/top edge of inner rectangle.
565 * @param finalScale The scaling factor between the size of the outer
566 * and inner rectangles.
567 */
568 private static float computePivot(int startPos, float finalScale) {
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800569
570 /*
571 Theorem of intercepting lines:
572
573 + + +-----------------------------------------------+
574 | | | |
575 | | | |
576 | | | |
577 | | | |
578 x | y | | |
579 | | | |
580 | | | |
581 | | | |
582 | | | |
583 | + | +--------------------+ |
584 | | | | |
585 | | | | |
586 | | | | |
587 | | | | |
588 | | | | |
589 | | | | |
590 | | | | |
591 | | | | |
592 | | | | |
593 | | | | |
594 | | | | |
595 | | | | |
596 | | | | |
597 | | | | |
598 | | | | |
599 | | | | |
600 | | | | |
601 | | +--------------------+ |
602 | | |
603 | | |
604 | | |
605 | | |
606 | | |
607 | | |
608 | | |
609 | +-----------------------------------------------+
610 |
611 |
612 |
613 |
614 |
615 |
616 |
617 |
618 |
619 + ++
620 p ++
621
622 scale = (x - y) / x
623 <=> x = -y / (scale - 1)
624 */
Craig Mautner164d4bb2012-11-26 13:51:23 -0800625 final float denom = finalScale-1;
626 if (Math.abs(denom) < .0001f) {
627 return startPos;
628 }
629 return -startPos / denom;
630 }
631
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700632 private Animation createScaleUpAnimationLocked(int transit, boolean enter,
633 Rect containingFrame) {
634 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700635 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -0700636 final int appWidth = containingFrame.width();
637 final int appHeight = containingFrame.height();
Craig Mautner164d4bb2012-11-26 13:51:23 -0800638 if (enter) {
639 // Entering app zooms out from the center of the initial rect.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700640 float scaleW = mTmpRect.width() / (float) appWidth;
641 float scaleH = mTmpRect.height() / (float) appHeight;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800642 Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700643 computePivot(mTmpRect.left, scaleW),
Winson4c3fecd2016-07-13 12:29:48 -0700644 computePivot(mTmpRect.top, scaleH));
Craig Mautner321bdf52012-12-18 09:53:24 -0800645 scale.setInterpolator(mDecelerateInterpolator);
646
Craig Mautner164d4bb2012-11-26 13:51:23 -0800647 Animation alpha = new AlphaAnimation(0, 1);
Winson Chunga4ccb862014-08-22 15:26:27 -0700648 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
Craig Mautner321bdf52012-12-18 09:53:24 -0800649
650 AnimationSet set = new AnimationSet(false);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800651 set.addAnimation(scale);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800652 set.addAnimation(alpha);
653 set.setDetachWallpaper(true);
654 a = set;
Craig Mautner4b71aa12012-12-27 17:20:01 -0800655 } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
656 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800657 // If we are on top of the wallpaper, we need an animation that
658 // correctly handles the wallpaper staying static behind all of
659 // the animated elements. To do this, will just have the existing
660 // element fade out.
661 a = new AlphaAnimation(1, 0);
662 a.setDetachWallpaper(true);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800663 } else {
Craig Mautner321bdf52012-12-18 09:53:24 -0800664 // For normal animations, the exiting element just holds in place.
665 a = new AlphaAnimation(1, 1);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800666 }
Craig Mautner321bdf52012-12-18 09:53:24 -0800667
668 // Pick the desired duration. If this is an inter-activity transition,
669 // it is the standard duration for that. Otherwise we use the longer
670 // task transition duration.
671 final long duration;
672 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800673 case TRANSIT_ACTIVITY_OPEN:
674 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800675 duration = mConfigShortAnimTime;
676 break;
677 default:
678 duration = DEFAULT_APP_TRANSITION_DURATION;
679 break;
680 }
681 a.setDuration(duration);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800682 a.setFillAfter(true);
Craig Mautner321bdf52012-12-18 09:53:24 -0800683 a.setInterpolator(mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800684 a.initialize(appWidth, appHeight, appWidth, appHeight);
685 return a;
686 }
687
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700688 private void getDefaultNextAppTransitionStartRect(Rect rect) {
689 if (mDefaultNextAppTransitionAnimationSpec == null ||
690 mDefaultNextAppTransitionAnimationSpec.rect == null) {
691 Slog.wtf(TAG, "Starting rect for app requested, but none available", new Throwable());
692 rect.setEmpty();
693 } else {
694 rect.set(mDefaultNextAppTransitionAnimationSpec.rect);
695 }
696 }
697
698 void getNextAppTransitionStartRect(int taskId, Rect rect) {
699 AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId);
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800700 if (spec == null) {
701 spec = mDefaultNextAppTransitionAnimationSpec;
702 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700703 if (spec == null || spec.rect == null) {
704 Slog.wtf(TAG, "Starting rect for task: " + taskId + " requested, but not available",
705 new Throwable());
706 rect.setEmpty();
707 } else {
708 rect.set(spec.rect);
709 }
710 }
711
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800712 private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height,
713 Bitmap bitmap) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700714 mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */,
Filip Gruszczynski7248c562015-11-09 13:05:40 -0800715 bitmap, new Rect(left, top, left + width, top + height));
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700716 }
717
Jorim Jaggif97ed922016-02-18 18:57:07 -0800718 /**
719 * @return the duration of the last clip reveal animation
720 */
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800721 long getLastClipRevealTransitionDuration() {
722 return mLastClipRevealTransitionDuration;
723 }
724
725 /**
Jorim Jaggif97ed922016-02-18 18:57:07 -0800726 * @return the maximum distance the app surface is traveling of the last clip reveal animation
727 */
728 int getLastClipRevealMaxTranslation() {
729 return mLastClipRevealMaxTranslation;
730 }
731
732 /**
733 * @return true if in the last app transition had a clip reveal animation, false otherwise
734 */
735 boolean hadClipRevealAnimation() {
736 return mLastHadClipReveal;
737 }
738
739 /**
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800740 * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that
741 * the start rect is outside of the target rect, and there is a lot of movement going on.
742 *
743 * @param cutOff whether the start rect was not fully contained by the end rect
744 * @param translationX the total translation the surface moves in x direction
745 * @param translationY the total translation the surfaces moves in y direction
746 * @param displayFrame our display frame
747 *
748 * @return the duration of the clip reveal animation, in milliseconds
749 */
750 private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX,
751 float translationY, Rect displayFrame) {
752 if (!cutOff) {
753 return DEFAULT_APP_TRANSITION_DURATION;
754 }
755 final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(),
756 Math.abs(translationY) / displayFrame.height());
757 return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction *
758 (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION));
759 }
760
761 private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame,
762 Rect displayFrame) {
Chet Haase10e23ab2015-02-11 15:08:38 -0800763 final Animation anim;
764 if (enter) {
Craig Mautner80b1f642015-04-22 10:59:09 -0700765 final int appWidth = appFrame.width();
766 final int appHeight = appFrame.height();
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800767
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700768 // mTmpRect will contain an area around the launcher icon that was pressed. We will
Filip Gruszczynski82861362015-10-16 14:21:09 -0700769 // clip reveal from that area in the final area of the app.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700770 getDefaultNextAppTransitionStartRect(mTmpRect);
Craig Mautner80b1f642015-04-22 10:59:09 -0700771
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700772 float t = 0f;
773 if (appHeight > 0) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800774 t = (float) mTmpRect.top / displayFrame.height();
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700775 }
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800776 int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t);
777 int translationX = 0;
778 int translationYCorrection = translationY;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700779 int centerX = mTmpRect.centerX();
780 int centerY = mTmpRect.centerY();
781 int halfWidth = mTmpRect.width() / 2;
782 int halfHeight = mTmpRect.height() / 2;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800783 int clipStartX = centerX - halfWidth - appFrame.left;
784 int clipStartY = centerY - halfHeight - appFrame.top;
785 boolean cutOff = false;
786
787 // If the starting rectangle is fully or partially outside of the target rectangle, we
788 // need to start the clipping at the edge and then achieve the rest with translation
789 // and extending the clip rect from that edge.
790 if (appFrame.top > centerY - halfHeight) {
791 translationY = (centerY - halfHeight) - appFrame.top;
792 translationYCorrection = 0;
793 clipStartY = 0;
794 cutOff = true;
795 }
796 if (appFrame.left > centerX - halfWidth) {
797 translationX = (centerX - halfWidth) - appFrame.left;
798 clipStartX = 0;
799 cutOff = true;
800 }
801 if (appFrame.right < centerX + halfWidth) {
802 translationX = (centerX + halfWidth) - appFrame.right;
803 clipStartX = appWidth - mTmpRect.width();
804 cutOff = true;
805 }
806 final long duration = calculateClipRevealTransitionDuration(cutOff, translationX,
807 translationY, displayFrame);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700808
809 // Clip third of the from size of launch icon, expand to full width/height
Chet Haase10e23ab2015-02-11 15:08:38 -0800810 Animation clipAnimLR = new ClipRectLRAnimation(
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800811 clipStartX, clipStartX + mTmpRect.width(), 0, appWidth);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700812 clipAnimLR.setInterpolator(mClipHorizontalInterpolator);
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800813 clipAnimLR.setDuration((long) (duration / 2.5f));
Filip Gruszczynski82861362015-10-16 14:21:09 -0700814
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800815 TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0);
816 translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR
817 : mLinearOutSlowInInterpolator);
818 translate.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800819
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800820 Animation clipAnimTB = new ClipRectTBAnimation(
821 clipStartY, clipStartY + mTmpRect.height(),
822 0, appHeight,
823 translationYCorrection, 0,
824 mLinearOutSlowInInterpolator);
825 clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
826 clipAnimTB.setDuration(duration);
Chet Haase10e23ab2015-02-11 15:08:38 -0800827
828 // Quick fade-in from icon to app window
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800829 final long alphaDuration = duration / 4;
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700830 AlphaAnimation alpha = new AlphaAnimation(0.5f, 1);
Chet Haase10e23ab2015-02-11 15:08:38 -0800831 alpha.setDuration(alphaDuration);
Jorim Jaggi1d763a62015-06-02 17:07:39 -0700832 alpha.setInterpolator(mLinearOutSlowInInterpolator);
Chet Haase10e23ab2015-02-11 15:08:38 -0800833
834 AnimationSet set = new AnimationSet(false);
835 set.addAnimation(clipAnimLR);
836 set.addAnimation(clipAnimTB);
Filip Gruszczynski82861362015-10-16 14:21:09 -0700837 set.addAnimation(translate);
Chet Haase10e23ab2015-02-11 15:08:38 -0800838 set.addAnimation(alpha);
Filip Gruszczynski9e2cf5b2015-07-31 12:20:40 -0700839 set.setZAdjustment(Animation.ZORDER_TOP);
Chet Haase10e23ab2015-02-11 15:08:38 -0800840 set.initialize(appWidth, appHeight, appWidth, appHeight);
841 anim = set;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800842 mLastHadClipReveal = true;
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -0800843 mLastClipRevealTransitionDuration = duration;
Jorim Jaggif97ed922016-02-18 18:57:07 -0800844
845 // If the start rect was full inside the target rect (cutOff == false), we don't need
846 // to store the translation, because it's only used if cutOff == true.
847 mLastClipRevealMaxTranslation = cutOff
848 ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0;
Chet Haase10e23ab2015-02-11 15:08:38 -0800849 } else {
850 final long duration;
851 switch (transit) {
852 case TRANSIT_ACTIVITY_OPEN:
853 case TRANSIT_ACTIVITY_CLOSE:
854 duration = mConfigShortAnimTime;
855 break;
856 default:
857 duration = DEFAULT_APP_TRANSITION_DURATION;
858 break;
859 }
860 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN ||
861 transit == TRANSIT_WALLPAPER_INTRA_CLOSE) {
862 // If we are on top of the wallpaper, we need an animation that
863 // correctly handles the wallpaper staying static behind all of
864 // the animated elements. To do this, will just have the existing
865 // element fade out.
866 anim = new AlphaAnimation(1, 0);
867 anim.setDetachWallpaper(true);
868 } else {
869 // For normal animations, the exiting element just holds in place.
870 anim = new AlphaAnimation(1, 1);
871 }
872 anim.setInterpolator(mDecelerateInterpolator);
873 anim.setDuration(duration);
874 anim.setFillAfter(true);
875 }
876 return anim;
877 }
878
Winson Chung399f6202014-03-19 10:47:20 -0700879 /**
880 * Prepares the specified animation with a standard duration, interpolator, etc.
881 */
Winson Chung5393dff2014-05-08 14:25:43 -0700882 Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100883 long duration, Interpolator interpolator) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700884 if (duration > 0) {
885 a.setDuration(duration);
886 }
Winson Chung5393dff2014-05-08 14:25:43 -0700887 a.setFillAfter(true);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100888 if (interpolator != null) {
889 a.setInterpolator(interpolator);
890 }
Winson Chung5393dff2014-05-08 14:25:43 -0700891 a.initialize(appWidth, appHeight, appWidth, appHeight);
892 return a;
893 }
894
895 /**
896 * Prepares the specified animation with a standard duration, interpolator, etc.
897 */
Winson Chung399f6202014-03-19 10:47:20 -0700898 Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) {
Craig Mautner321bdf52012-12-18 09:53:24 -0800899 // Pick the desired duration. If this is an inter-activity transition,
900 // it is the standard duration for that. Otherwise we use the longer
901 // task transition duration.
Winson Chung5393dff2014-05-08 14:25:43 -0700902 final int duration;
Craig Mautner321bdf52012-12-18 09:53:24 -0800903 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -0800904 case TRANSIT_ACTIVITY_OPEN:
905 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner321bdf52012-12-18 09:53:24 -0800906 duration = mConfigShortAnimTime;
907 break;
908 default:
909 duration = DEFAULT_APP_TRANSITION_DURATION;
910 break;
911 }
Winson Chung5393dff2014-05-08 14:25:43 -0700912 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration,
913 mDecelerateInterpolator);
Craig Mautner164d4bb2012-11-26 13:51:23 -0800914 }
915
Winson Chung399f6202014-03-19 10:47:20 -0700916 /**
917 * Return the current thumbnail transition state.
918 */
919 int getThumbnailTransitionState(boolean enter) {
920 if (enter) {
921 if (mNextAppTransitionScaleUp) {
922 return THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
923 } else {
924 return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN;
925 }
926 } else {
927 if (mNextAppTransitionScaleUp) {
928 return THUMBNAIL_TRANSITION_EXIT_SCALE_UP;
929 } else {
930 return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN;
931 }
932 }
933 }
934
935 /**
936 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700937 * when a thumbnail is specified with the pending animation override.
Winson Chung399f6202014-03-19 10:47:20 -0700938 */
Jorim Jaggide63d442016-03-14 14:56:56 +0100939 Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets,
Winsonb2024762016-04-05 17:32:30 -0700940 Bitmap thumbnailHeader, final int taskId, int uiMode, int orientation) {
Winson Chung399f6202014-03-19 10:47:20 -0700941 Animation a;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700942 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chung399f6202014-03-19 10:47:20 -0700943 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -0700944 final int thumbHeightI = thumbnailHeader.getHeight();
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700945 final int appWidth = appRect.width();
Winson Chung399f6202014-03-19 10:47:20 -0700946
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -0700947 float scaleW = appWidth / thumbWidth;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -0700948 getNextAppTransitionStartRect(taskId, mTmpRect);
Jorim Jaggi09072002016-03-25 16:48:42 -0700949 final float fromX;
950 final float fromY;
951 final float toX;
952 final float toY;
953 final float pivotX;
954 final float pivotY;
Winsonb2024762016-04-05 17:32:30 -0700955 if (isTvUiMode(uiMode) || orientation == Configuration.ORIENTATION_PORTRAIT) {
Jorim Jaggi09072002016-03-25 16:48:42 -0700956 fromX = mTmpRect.left;
957 fromY = mTmpRect.top;
958
959 // For the curved translate animation to work, the pivot points needs to be at the
960 // same absolute position as the one from the real surface.
961 toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left;
962 toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top;
963 pivotX = mTmpRect.width() / 2;
964 pivotY = appRect.height() / 2 / scaleW;
965 } else {
966 pivotX = 0;
967 pivotY = 0;
968 fromX = mTmpRect.left;
969 fromY = mTmpRect.top;
970 toX = appRect.left;
971 toY = appRect.top;
972 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100973 final long duration = getAspectScaleDuration();
974 final Interpolator interpolator = getAspectScaleInterpolator();
Winson Chung399f6202014-03-19 10:47:20 -0700975 if (mNextAppTransitionScaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -0700976 // Animation up from the thumbnail to the full screen
Jorim Jaggi8448f332016-03-14 17:50:37 +0100977 Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100978 scale.setInterpolator(interpolator);
979 scale.setDuration(duration);
Jorim Jaggic6c89a82016-01-28 17:48:21 -0800980 Animation alpha = new AlphaAnimation(1f, 0f);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100981 alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
982 ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator);
983 alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
984 ? duration / 2
985 : duration);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +0100986 Animation translate = createCurvedMotion(fromX, toX, fromY, toY);
987 translate.setInterpolator(interpolator);
988 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -0700989
Jorim Jaggide63d442016-03-14 14:56:56 +0100990 mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI);
991 mTmpToClipRect.set(appRect);
992
993 // Containing frame is in screen space, but we need the clip rect in the
994 // app space.
995 mTmpToClipRect.offsetTo(0, 0);
Jorim Jaggic69bd222016-03-15 14:38:37 +0100996 mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW);
997 mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW);
Jorim Jaggide63d442016-03-14 14:56:56 +0100998
999 if (contentInsets != null) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001000 mTmpToClipRect.inset((int) (-contentInsets.left * scaleW),
1001 (int) (-contentInsets.top * scaleW),
1002 (int) (-contentInsets.right * scaleW),
1003 (int) (-contentInsets.bottom * scaleW));
Jorim Jaggide63d442016-03-14 14:56:56 +01001004 }
1005
1006 Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001007 clipAnim.setInterpolator(interpolator);
1008 clipAnim.setDuration(duration);
Jorim Jaggide63d442016-03-14 14:56:56 +01001009
Winson Chung399f6202014-03-19 10:47:20 -07001010 // This AnimationSet uses the Interpolators assigned above.
1011 AnimationSet set = new AnimationSet(false);
1012 set.addAnimation(scale);
1013 set.addAnimation(alpha);
Winson Chunga4ccb862014-08-22 15:26:27 -07001014 set.addAnimation(translate);
Jorim Jaggide63d442016-03-14 14:56:56 +01001015 set.addAnimation(clipAnim);
Winson Chung399f6202014-03-19 10:47:20 -07001016 a = set;
1017 } else {
Winson Chunga4ccb862014-08-22 15:26:27 -07001018 // Animation down from the full screen to the thumbnail
Jorim Jaggi8448f332016-03-14 17:50:37 +01001019 Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001020 scale.setInterpolator(interpolator);
1021 scale.setDuration(duration);
Winson Chunga4ccb862014-08-22 15:26:27 -07001022 Animation alpha = new AlphaAnimation(0f, 1f);
1023 alpha.setInterpolator(mThumbnailFadeInInterpolator);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001024 alpha.setDuration(duration);
1025 Animation translate = createCurvedMotion(toX, fromX, toY, fromY);
1026 translate.setInterpolator(interpolator);
1027 translate.setDuration(duration);
Winson Chung399f6202014-03-19 10:47:20 -07001028
Winson Chunga4ccb862014-08-22 15:26:27 -07001029 // This AnimationSet uses the Interpolators assigned above.
1030 AnimationSet set = new AnimationSet(false);
1031 set.addAnimation(scale);
1032 set.addAnimation(alpha);
1033 set.addAnimation(translate);
1034 a = set;
1035
1036 }
Filip Gruszczynskidfb25d32015-08-14 11:06:18 -07001037 return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001038 null);
Winson Chung399f6202014-03-19 10:47:20 -07001039 }
1040
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001041 private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) {
1042
1043 // Almost no x-change - use linear animation
Jorim Jaggic69bd222016-03-15 14:38:37 +01001044 if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001045 return new TranslateAnimation(fromX, toX, fromY, toY);
1046 } else {
1047 final Path path = createCurvedPath(fromX, toX, fromY, toY);
1048 return new CurvedTranslateAnimation(path);
1049 }
1050 }
1051
1052 private Path createCurvedPath(float fromX, float toX, float fromY, float toY) {
1053 final Path path = new Path();
1054 path.moveTo(fromX, fromY);
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001055
1056 if (fromY > toY) {
1057 // If the object needs to go up, move it in horizontal direction first, then vertical.
1058 path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY);
1059 } else {
1060 // If the object needs to go down, move it in vertical direction first, then horizontal.
1061 path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY);
1062 }
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001063 return path;
1064 }
1065
1066 private long getAspectScaleDuration() {
1067 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001068 return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f);
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001069 } else {
1070 return THUMBNAIL_APP_TRANSITION_DURATION;
1071 }
1072 }
1073
1074 private Interpolator getAspectScaleInterpolator() {
1075 if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) {
1076 return mFastOutSlowInInterpolator;
1077 } else {
1078 return TOUCH_RESPONSE_INTERPOLATOR;
1079 }
1080 }
1081
Winson Chung399f6202014-03-19 10:47:20 -07001082 /**
1083 * This alternate animation is created when we are doing a thumbnail transition, for the
1084 * activity that is leaving, and the activity that is entering.
1085 */
Winson Chunga4ccb862014-08-22 15:26:27 -07001086 Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState,
Winsonb2024762016-04-05 17:32:30 -07001087 int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001088 @Nullable Rect surfaceInsets, boolean freeform, int taskId) {
Winson Chung399f6202014-03-19 10:47:20 -07001089 Animation a;
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001090 final int appWidth = containingFrame.width();
1091 final int appHeight = containingFrame.height();
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001092 getDefaultNextAppTransitionStartRect(mTmpRect);
1093 final int thumbWidthI = mTmpRect.width();
Winson Chung399f6202014-03-19 10:47:20 -07001094 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001095 final int thumbHeightI = mTmpRect.height();
Winson Chung399f6202014-03-19 10:47:20 -07001096 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
Winsoncbb625b2016-07-06 15:24:15 -07001097 final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left;
Winson21700932016-03-24 17:26:23 -07001098 final int thumbStartY = mTmpRect.top - containingFrame.top;
Winson Chung399f6202014-03-19 10:47:20 -07001099
1100 switch (thumbTransitState) {
Jorim Jaggi8448f332016-03-14 17:50:37 +01001101 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP:
1102 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1103 final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP;
1104 if (freeform && scaleUp) {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001105 a = createAspectScaledThumbnailEnterFreeformAnimationLocked(
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001106 containingFrame, surfaceInsets, taskId);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001107 } else if (freeform) {
1108 a = createAspectScaledThumbnailExitFreeformAnimationLocked(
1109 containingFrame, surfaceInsets, taskId);
Winson Chung2820c452014-04-15 15:34:44 -07001110 } else {
Winson21700932016-03-24 17:26:23 -07001111 AnimationSet set = new AnimationSet(true);
1112
1113 // In portrait, we scale to fit the width
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001114 mTmpFromClipRect.set(containingFrame);
Filip Gruszczynskiefd3d1b2015-10-14 13:57:55 -07001115 mTmpToClipRect.set(containingFrame);
Jorim Jaggic6c89a82016-01-28 17:48:21 -08001116
1117 // Containing frame is in screen space, but we need the clip rect in the
1118 // app space.
1119 mTmpFromClipRect.offsetTo(0, 0);
1120 mTmpToClipRect.offsetTo(0, 0);
1121
1122 // Exclude insets region from the source clip.
1123 mTmpFromClipRect.inset(contentInsets);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001124 mNextAppTransitionInsets.set(contentInsets);
1125
Winsonb2024762016-04-05 17:32:30 -07001126 if (isTvUiMode(uiMode) || orientation == Configuration.ORIENTATION_PORTRAIT) {
Jorim Jaggic69bd222016-03-15 14:38:37 +01001127 // We scale the width and clip to the top/left square
1128 float scale = thumbWidth /
1129 (appWidth - contentInsets.left - contentInsets.right);
1130 int unscaledThumbHeight = (int) (thumbHeight / scale);
1131 mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight;
1132
1133 mNextAppTransitionInsets.set(contentInsets);
1134
Jorim Jaggi8448f332016-03-14 17:50:37 +01001135 Animation scaleAnim = new ScaleAnimation(
1136 scaleUp ? scale : 1, scaleUp ? 1 : scale,
1137 scaleUp ? scale : 1, scaleUp ? 1 : scale,
Jorim Jaggic69bd222016-03-15 14:38:37 +01001138 containingFrame.width() / 2f,
1139 containingFrame.height() / 2f + contentInsets.top);
Jorim Jaggi8448f332016-03-14 17:50:37 +01001140 final float targetX = (mTmpRect.left - containingFrame.left);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001141 final float x = containingFrame.width() / 2f
1142 - containingFrame.width() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001143 final float targetY = (mTmpRect.top - containingFrame.top);
Jorim Jaggic69bd222016-03-15 14:38:37 +01001144 final float y = containingFrame.height() / 2f
1145 - containingFrame.height() / 2f * scale;
Jorim Jaggi8448f332016-03-14 17:50:37 +01001146 final float startX = targetX - x;
1147 final float startY = targetY - y;
1148 Animation clipAnim = scaleUp
1149 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1150 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1151 Animation translateAnim = scaleUp
Jorim Jaggic69bd222016-03-15 14:38:37 +01001152 ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0)
1153 : createCurvedMotion(0, startX, 0, startY - contentInsets.top);
1154
Winson21700932016-03-24 17:26:23 -07001155 set.addAnimation(clipAnim);
1156 set.addAnimation(scaleAnim);
1157 set.addAnimation(translateAnim);
1158
1159 } else {
1160 // In landscape, we don't scale at all and only crop
1161 mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI;
1162 mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI;
1163
Jorim Jaggi8448f332016-03-14 17:50:37 +01001164 Animation clipAnim = scaleUp
1165 ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)
1166 : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect);
1167 Animation translateAnim = scaleUp
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001168 ? createCurvedMotion(thumbStartX, 0,
1169 thumbStartY - contentInsets.top, 0)
1170 : createCurvedMotion(0, thumbStartX, 0,
1171 thumbStartY - contentInsets.top);
Winson21700932016-03-24 17:26:23 -07001172
1173 set.addAnimation(clipAnim);
1174 set.addAnimation(translateAnim);
1175 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001176 a = set;
Winson21700932016-03-24 17:26:23 -07001177 a.setZAdjustment(Animation.ZORDER_TOP);
Winson Chung2820c452014-04-15 15:34:44 -07001178 }
Winson Chung399f6202014-03-19 10:47:20 -07001179 break;
1180 }
1181 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001182 // Previous app window during the scale up
Winson Chung399f6202014-03-19 10:47:20 -07001183 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001184 // Fade out the source activity if we are animating to a wallpaper
Winson Chung399f6202014-03-19 10:47:20 -07001185 // activity.
1186 a = new AlphaAnimation(1, 0);
1187 } else {
Winson Chung399f6202014-03-19 10:47:20 -07001188 a = new AlphaAnimation(1, 1);
1189 }
1190 break;
1191 }
1192 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
Winson Chunga4ccb862014-08-22 15:26:27 -07001193 // Target app window during the scale down
1194 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1195 // Fade in the destination activity if we are animating from a wallpaper
1196 // activity.
1197 a = new AlphaAnimation(0, 1);
1198 } else {
1199 a = new AlphaAnimation(1, 1);
1200 }
Winson Chung399f6202014-03-19 10:47:20 -07001201 break;
1202 }
Winson Chung399f6202014-03-19 10:47:20 -07001203 default:
1204 throw new RuntimeException("Invalid thumbnail transition state");
1205 }
1206
Jorim Jaggi787e9dd2016-03-15 10:52:40 +01001207 return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight,
1208 getAspectScaleDuration(), getAspectScaleInterpolator());
Winson Chung399f6202014-03-19 10:47:20 -07001209 }
1210
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001211 private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame,
1212 @Nullable Rect surfaceInsets, int taskId) {
1213 getNextAppTransitionStartRect(taskId, mTmpRect);
1214 return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets,
1215 true);
1216 }
1217
1218 private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame,
1219 @Nullable Rect surfaceInsets, int taskId) {
1220 getNextAppTransitionStartRect(taskId, mTmpRect);
1221 return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets,
1222 false);
1223 }
1224
1225 private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame,
1226 Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) {
1227 final float sourceWidth = sourceFrame.width();
1228 final float sourceHeight = sourceFrame.height();
1229 final float destWidth = destFrame.width();
1230 final float destHeight = destFrame.height();
1231 final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth;
1232 final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight;
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001233 AnimationSet set = new AnimationSet(true);
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001234 final int surfaceInsetsH = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001235 ? 0 : surfaceInsets.left + surfaceInsets.right;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001236 final int surfaceInsetsV = surfaceInsets == null
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001237 ? 0 : surfaceInsets.top + surfaceInsets.bottom;
1238 // We want the scaling to happen from the center of the surface. In order to achieve that,
1239 // we need to account for surface insets that will be used to enlarge the surface.
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001240 final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2;
1241 final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2;
1242 final ScaleAnimation scale = enter ?
1243 new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter)
1244 : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter);
1245 final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2;
1246 final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2;
1247 final int destHCenter = destFrame.left + destFrame.width() / 2;
1248 final int destVCenter = destFrame.top + destFrame.height() / 2;
1249 final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter;
1250 final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter;
1251 final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0)
1252 : new TranslateAnimation(0, fromX, 0, fromY);
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001253 set.addAnimation(scale);
1254 set.addAnimation(translation);
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001255
1256 final IRemoteCallback callback = mAnimationFinishedCallback;
1257 if (callback != null) {
1258 set.setAnimationListener(new Animation.AnimationListener() {
1259 @Override
1260 public void onAnimationStart(Animation animation) { }
1261
1262 @Override
1263 public void onAnimationEnd(Animation animation) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001264 mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001265 }
1266
1267 @Override
1268 public void onAnimationRepeat(Animation animation) { }
1269 });
1270 }
Filip Gruszczynski71b0d2d2015-08-12 18:52:26 -07001271 return set;
1272 }
1273
Winson Chung399f6202014-03-19 10:47:20 -07001274 /**
Winson Chunga4ccb862014-08-22 15:26:27 -07001275 * This animation runs for the thumbnail that gets cross faded with the enter/exit activity
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001276 * when a thumbnail is specified with the pending animation override.
Winson Chunga4ccb862014-08-22 15:26:27 -07001277 */
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001278 Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit,
1279 Bitmap thumbnailHeader) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001280 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001281 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001282 final int thumbWidthI = thumbnailHeader.getWidth();
Winson Chunga4ccb862014-08-22 15:26:27 -07001283 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001284 final int thumbHeightI = thumbnailHeader.getHeight();
Winson Chunga4ccb862014-08-22 15:26:27 -07001285 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1286
1287 if (mNextAppTransitionScaleUp) {
1288 // Animation for the thumbnail zooming from its initial size to the full screen
1289 float scaleW = appWidth / thumbWidth;
1290 float scaleH = appHeight / thumbHeight;
1291 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001292 computePivot(mTmpRect.left, 1 / scaleW),
1293 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001294 scale.setInterpolator(mDecelerateInterpolator);
1295
1296 Animation alpha = new AlphaAnimation(1, 0);
1297 alpha.setInterpolator(mThumbnailFadeOutInterpolator);
1298
1299 // This AnimationSet uses the Interpolators assigned above.
1300 AnimationSet set = new AnimationSet(false);
1301 set.addAnimation(scale);
1302 set.addAnimation(alpha);
1303 a = set;
1304 } else {
1305 // Animation for the thumbnail zooming down from the full screen to its final size
1306 float scaleW = appWidth / thumbWidth;
1307 float scaleH = appHeight / thumbHeight;
1308 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001309 computePivot(mTmpRect.left, 1 / scaleW),
1310 computePivot(mTmpRect.top, 1 / scaleH));
Winson Chunga4ccb862014-08-22 15:26:27 -07001311 }
1312
1313 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1314 }
1315
1316 /**
Winson Chung399f6202014-03-19 10:47:20 -07001317 * This animation is created when we are doing a thumbnail transition, for the activity that is
1318 * leaving, and the activity that is entering.
1319 */
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001320 Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame,
1321 int transit, int taskId) {
1322 final int appWidth = containingFrame.width();
1323 final int appHeight = containingFrame.height();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001324 Bitmap thumbnailHeader = getAppTransitionThumbnailHeader(taskId);
Winson Chung399f6202014-03-19 10:47:20 -07001325 Animation a;
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001326 getDefaultNextAppTransitionStartRect(mTmpRect);
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001327 final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth;
Winson Chung399f6202014-03-19 10:47:20 -07001328 final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001329 final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight;
Winson Chung399f6202014-03-19 10:47:20 -07001330 final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1;
1331
1332 switch (thumbTransitState) {
1333 case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: {
1334 // Entering app scales up with the thumbnail
1335 float scaleW = thumbWidth / appWidth;
1336 float scaleH = thumbHeight / appHeight;
1337 a = new ScaleAnimation(scaleW, 1, scaleH, 1,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001338 computePivot(mTmpRect.left, scaleW),
1339 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001340 break;
1341 }
1342 case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: {
1343 // Exiting app while the thumbnail is scaling up should fade or stay in place
1344 if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) {
1345 // Fade out while bringing up selected activity. This keeps the
1346 // current activity from showing through a launching wallpaper
1347 // activity.
1348 a = new AlphaAnimation(1, 0);
1349 } else {
1350 // noop animation
1351 a = new AlphaAnimation(1, 1);
1352 }
1353 break;
1354 }
1355 case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: {
1356 // Entering the other app, it should just be visible while we scale the thumbnail
1357 // down above it
1358 a = new AlphaAnimation(1, 1);
1359 break;
1360 }
1361 case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: {
1362 // Exiting the current app, the app should scale down with the thumbnail
1363 float scaleW = thumbWidth / appWidth;
1364 float scaleH = thumbHeight / appHeight;
1365 Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH,
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001366 computePivot(mTmpRect.left, scaleW),
1367 computePivot(mTmpRect.top, scaleH));
Winson Chung399f6202014-03-19 10:47:20 -07001368
1369 Animation alpha = new AlphaAnimation(1, 0);
1370
1371 AnimationSet set = new AnimationSet(true);
1372 set.addAnimation(scale);
1373 set.addAnimation(alpha);
1374 set.setZAdjustment(Animation.ZORDER_TOP);
1375 a = set;
1376 break;
1377 }
1378 default:
1379 throw new RuntimeException("Invalid thumbnail transition state");
1380 }
1381
1382 return prepareThumbnailAnimation(a, appWidth, appHeight, transit);
1383 }
1384
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001385 private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001386 getDefaultNextAppTransitionStartRect(mTmpFromClipRect);
1387 final int left = mTmpFromClipRect.left;
1388 final int top = mTmpFromClipRect.top;
1389 mTmpFromClipRect.offset(-left, -top);
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001390 // TODO: Isn't that strange that we ignore exact position of the containingFrame?
1391 mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height());
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001392 AnimationSet set = new AnimationSet(true);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001393 float fromWidth = mTmpFromClipRect.width();
1394 float toWidth = mTmpToClipRect.width();
1395 float fromHeight = mTmpFromClipRect.height();
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001396 // While the window might span the whole display, the actual content will be cropped to the
1397 // system decoration frame, for example when the window is docked. We need to take into
1398 // account the visible height when constructing the animation.
1399 float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom;
1400 int translateAdjustment = 0;
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001401 if (fromWidth <= toWidth && fromHeight <= toHeight) {
1402 // The final window is larger in both dimensions than current window (e.g. we are
1403 // maximizing), so we can simply unclip the new window and there will be no disappearing
1404 // frame.
1405 set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect));
1406 } else {
1407 // The disappearing window has one larger dimension. We need to apply scaling, so the
1408 // first frame of the entry animation matches the old window.
1409 set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1));
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001410 // We might not be going exactly full screen, but instead be aligned under the status
1411 // bar using cropping. We still need to account for the cropped part, which will also
1412 // be scaled.
1413 translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001414 }
1415
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001416 // We animate the translation from the old position of the removed window, to the new
1417 // position of the added window. The latter might not be full screen, for example docked for
1418 // docked windows.
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001419 TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left,
Filip Gruszczynski2dfcf842015-10-25 13:40:47 -07001420 0, top - containingFrame.top - translateAdjustment, 0);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001421 set.addAnimation(translate);
1422 set.setDuration(DEFAULT_APP_TRANSITION_DURATION);
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07001423 set.setZAdjustment(Animation.ZORDER_TOP);
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001424 return set;
1425 }
1426
Jorim Jaggic554b772015-06-04 16:07:57 -07001427 /**
1428 * @return true if and only if the first frame of the transition can be skipped, i.e. the first
1429 * frame of the transition doesn't change the visuals on screen, so we can start
1430 * directly with the second one
1431 */
1432 boolean canSkipFirstFrame() {
1433 return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM
1434 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE
Jorim Jaggife762342016-10-13 14:33:27 +02001435 && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL
1436 && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY;
Jorim Jaggic554b772015-06-04 16:07:57 -07001437 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001438
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001439 /**
1440 *
1441 * @param frame These are the bounds of the window when it finishes the animation. This is where
1442 * the animation must usually finish in entrance animation, as the next frame will
1443 * display the window at these coordinates. In case of exit animation, this is
1444 * where the animation must start, as the frame before the animation is displaying
1445 * the window at these bounds.
1446 * @param insets Knowing where the window will be positioned is not enough. Some parts of the
1447 * window might be obscured, usually by the system windows (status bar and
1448 * navigation bar) and we use content insets to convey that information. This
1449 * usually affects the animation aspects vertically, as the system decoration is
1450 * at the top and the bottom. For example when we animate from full screen to
1451 * recents, we want to exclude the covered parts, because they won't match the
1452 * thumbnail after the last frame is executed.
1453 * @param surfaceInsets In rare situation the surface is larger than the content and we need to
1454 * know about this to make the animation frames match. We currently use
1455 * this for freeform windows, which have larger surfaces to display
1456 * shadows. When we animate them from recents, we want to match the content
1457 * to the recents thumbnail and hence need to account for the surface being
1458 * bigger.
1459 */
Winsonb2024762016-04-05 17:32:30 -07001460 Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter, int uiMode,
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001461 int orientation, Rect frame, Rect displayFrame, Rect insets,
1462 @Nullable Rect surfaceInsets, boolean isVoiceInteraction, boolean freeform,
1463 int taskId) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001464 Animation a;
Jorim Jaggife762342016-10-13 14:33:27 +02001465 if (isKeyguardGoingAwayTransit(transit) && enter) {
1466 a = loadKeyguardExitAnimation(transit);
1467 } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) {
1468 a = null;
1469 } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) {
1470 a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit);
1471 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001472 || transit == TRANSIT_TASK_OPEN
1473 || transit == TRANSIT_TASK_TO_FRONT)) {
1474 a = loadAnimationRes(lp, enter
1475 ? com.android.internal.R.anim.voice_activity_open_enter
1476 : com.android.internal.R.anim.voice_activity_open_exit);
1477 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1478 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001479 + " anim=" + a + " transit=" + appTransitionToString(transit)
1480 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001481 } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE
1482 || transit == TRANSIT_TASK_CLOSE
1483 || transit == TRANSIT_TASK_TO_BACK)) {
1484 a = loadAnimationRes(lp, enter
1485 ? com.android.internal.R.anim.voice_activity_close_enter
1486 : com.android.internal.R.anim.voice_activity_close_exit);
1487 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1488 "applyAnimation voice:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001489 + " anim=" + a + " transit=" + appTransitionToString(transit)
1490 + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3));
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001491 } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001492 a = createRelaunchAnimation(frame, insets);
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001493 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1494 "applyAnimation:"
1495 + " anim=" + a + " nextAppTransition=" + mNextAppTransition
1496 + " transit=" + appTransitionToString(transit)
1497 + " Callers=" + Debug.getCallers(3));
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001498 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) {
1499 a = loadAnimationRes(mNextAppTransitionPackage, enter ?
Craig Mautner164d4bb2012-11-26 13:51:23 -08001500 mNextAppTransitionEnter : mNextAppTransitionExit);
1501 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1502 "applyAnimation:"
1503 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001504 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001505 + " Callers=" + Debug.getCallers(3));
Winson Chung044d5292014-11-06 11:05:19 -08001506 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) {
1507 a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace);
1508 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1509 "applyAnimation:"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001510 + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE"
1511 + " transit=" + appTransitionToString(transit)
1512 + " Callers=" + Debug.getCallers(3));
Chet Haase10e23ab2015-02-11 15:08:38 -08001513 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) {
Jorim Jaggi8fe7e0a2016-02-12 19:43:39 -08001514 a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame);
Chet Haase10e23ab2015-02-11 15:08:38 -08001515 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1516 "applyAnimation:"
1517 + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL"
Filip Gruszczynski49b80af2015-09-24 09:04:26 -07001518 + " transit=" + appTransitionToString(transit)
Chet Haase10e23ab2015-02-11 15:08:38 -08001519 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001520 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) {
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001521 a = createScaleUpAnimationLocked(transit, enter, frame);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001522 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1523 "applyAnimation:"
1524 + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP"
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001525 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001526 + " Callers=" + Debug.getCallers(3));
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001527 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP ||
1528 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001529 mNextAppTransitionScaleUp =
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001530 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP);
Winson Chunga4ccb862014-08-22 15:26:27 -07001531 a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter),
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001532 frame, transit, taskId);
Winson Chunga4ccb862014-08-22 15:26:27 -07001533 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1534 String animName = mNextAppTransitionScaleUp ?
1535 "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN";
1536 Slog.v(TAG, "applyAnimation:"
1537 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001538 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Winson Chunga4ccb862014-08-22 15:26:27 -07001539 + " Callers=" + Debug.getCallers(3));
1540 }
1541 } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP ||
1542 mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) {
1543 mNextAppTransitionScaleUp =
1544 (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP);
1545 a = createAspectScaledThumbnailEnterExitAnimationLocked(
Winsonb2024762016-04-05 17:32:30 -07001546 getThumbnailTransitionState(enter), uiMode, orientation, transit, frame,
Filip Gruszczynski541f92c2015-10-25 17:15:06 -07001547 insets, surfaceInsets, freeform, taskId);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001548 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1549 String animName = mNextAppTransitionScaleUp ?
Winson Chunga4ccb862014-08-22 15:26:27 -07001550 "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner164d4bb2012-11-26 13:51:23 -08001551 Slog.v(TAG, "applyAnimation:"
1552 + " anim=" + a + " nextAppTransition=" + animName
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001553 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001554 + " Callers=" + Debug.getCallers(3));
1555 }
1556 } else {
1557 int animAttr = 0;
1558 switch (transit) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001559 case TRANSIT_ACTIVITY_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001560 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001561 ? WindowAnimation_activityOpenEnterAnimation
1562 : WindowAnimation_activityOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001563 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001564 case TRANSIT_ACTIVITY_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001565 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001566 ? WindowAnimation_activityCloseEnterAnimation
1567 : WindowAnimation_activityCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001568 break;
Jorim Jaggi192086e2016-03-11 17:17:03 +01001569 case TRANSIT_DOCK_TASK_FROM_RECENTS:
Craig Mautner4b71aa12012-12-27 17:20:01 -08001570 case TRANSIT_TASK_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001571 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001572 ? WindowAnimation_taskOpenEnterAnimation
1573 : WindowAnimation_taskOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001574 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001575 case TRANSIT_TASK_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001576 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001577 ? WindowAnimation_taskCloseEnterAnimation
1578 : WindowAnimation_taskCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001579 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001580 case TRANSIT_TASK_TO_FRONT:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001581 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001582 ? WindowAnimation_taskToFrontEnterAnimation
1583 : WindowAnimation_taskToFrontExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001584 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001585 case TRANSIT_TASK_TO_BACK:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001586 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001587 ? WindowAnimation_taskToBackEnterAnimation
1588 : WindowAnimation_taskToBackExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001589 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001590 case TRANSIT_WALLPAPER_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001591 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001592 ? WindowAnimation_wallpaperOpenEnterAnimation
1593 : WindowAnimation_wallpaperOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001594 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001595 case TRANSIT_WALLPAPER_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001596 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001597 ? WindowAnimation_wallpaperCloseEnterAnimation
1598 : WindowAnimation_wallpaperCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001599 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001600 case TRANSIT_WALLPAPER_INTRA_OPEN:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001601 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001602 ? WindowAnimation_wallpaperIntraOpenEnterAnimation
1603 : WindowAnimation_wallpaperIntraOpenExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001604 break;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001605 case TRANSIT_WALLPAPER_INTRA_CLOSE:
Craig Mautner164d4bb2012-11-26 13:51:23 -08001606 animAttr = enter
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001607 ? WindowAnimation_wallpaperIntraCloseEnterAnimation
1608 : WindowAnimation_wallpaperIntraCloseExitAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001609 break;
Craig Mautnerbb742462014-07-07 15:28:55 -07001610 case TRANSIT_TASK_OPEN_BEHIND:
1611 animAttr = enter
1612 ? WindowAnimation_launchTaskBehindSourceAnimation
Craig Mautner3b2cd1d2014-08-25 14:25:54 -07001613 : WindowAnimation_launchTaskBehindTargetAnimation;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001614 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001615 a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001616 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG,
1617 "applyAnimation:"
1618 + " anim=" + a
1619 + " animAttr=0x" + Integer.toHexString(animAttr)
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001620 + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter
Craig Mautner164d4bb2012-11-26 13:51:23 -08001621 + " Callers=" + Debug.getCallers(3));
1622 }
1623 return a;
1624 }
1625
Jorim Jaggife762342016-10-13 14:33:27 +02001626 private Animation loadKeyguardExitAnimation(int transit) {
1627 if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) {
1628 return null;
1629 }
1630 final boolean toShade =
1631 (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0;
1632 return mService.mPolicy.createHiddenByKeyguardExit(
1633 transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade);
1634 }
1635
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001636 int getAppStackClipMode() {
1637 return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH
Jorim Jaggic69bd222016-03-15 14:38:37 +01001638 || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS
Jorim Jaggife762342016-10-13 14:33:27 +02001639 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY
1640 || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER
Jorim Jaggi1f458fb2016-03-25 17:36:37 -07001641 || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +01001642 ? STACK_CLIP_NONE
1643 : STACK_CLIP_AFTER_ANIM;
1644 }
1645
Jorim Jaggife762342016-10-13 14:33:27 +02001646 public int getTransitFlags() {
1647 return mNextAppTransitionFlags;
1648 }
1649
Craig Mautner164d4bb2012-11-26 13:51:23 -08001650 void postAnimationCallback() {
1651 if (mNextAppTransitionCallback != null) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001652 mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK,
1653 mNextAppTransitionCallback));
Craig Mautner164d4bb2012-11-26 13:51:23 -08001654 mNextAppTransitionCallback = null;
1655 }
1656 }
1657
1658 void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim,
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001659 IRemoteCallback startedCallback) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001660 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001661 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001662 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001663 mNextAppTransitionPackage = packageName;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001664 mNextAppTransitionEnter = enterAnim;
1665 mNextAppTransitionExit = exitAnim;
1666 postAnimationCallback();
1667 mNextAppTransitionCallback = startedCallback;
1668 } else {
1669 postAnimationCallback();
1670 }
1671 }
1672
1673 void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001674 int startHeight) {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001675 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001676 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001677 mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP;
Winson4c3fecd2016-07-13 12:29:48 -07001678 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001679 postAnimationCallback();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001680 }
1681 }
1682
Chet Haase10e23ab2015-02-11 15:08:38 -08001683 void overridePendingAppTransitionClipReveal(int startX, int startY,
1684 int startWidth, int startHeight) {
1685 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001686 clear();
Chet Haase10e23ab2015-02-11 15:08:38 -08001687 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001688 putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null);
Chet Haase10e23ab2015-02-11 15:08:38 -08001689 postAnimationCallback();
Chet Haase10e23ab2015-02-11 15:08:38 -08001690 }
1691 }
1692
Craig Mautner164d4bb2012-11-26 13:51:23 -08001693 void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX, int startY,
1694 IRemoteCallback startedCallback, boolean scaleUp) {
1695 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001696 clear();
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001697 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP
1698 : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN;
Craig Mautner164d4bb2012-11-26 13:51:23 -08001699 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001700 putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001701 postAnimationCallback();
1702 mNextAppTransitionCallback = startedCallback;
1703 } else {
1704 postAnimationCallback();
1705 }
1706 }
1707
Winson Chunga4ccb862014-08-22 15:26:27 -07001708 void overridePendingAppTransitionAspectScaledThumb(Bitmap srcThumb, int startX, int startY,
Winson Chung2e7f3bd2014-09-05 13:17:22 +02001709 int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) {
Winson Chunga4ccb862014-08-22 15:26:27 -07001710 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001711 clear();
Winson Chunga4ccb862014-08-22 15:26:27 -07001712 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1713 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Winson Chunga4ccb862014-08-22 15:26:27 -07001714 mNextAppTransitionScaleUp = scaleUp;
Filip Gruszczynski7248c562015-11-09 13:05:40 -08001715 putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight,
1716 srcThumb);
Winson Chunga4ccb862014-08-22 15:26:27 -07001717 postAnimationCallback();
1718 mNextAppTransitionCallback = startedCallback;
1719 } else {
1720 postAnimationCallback();
1721 }
1722 }
1723
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001724 public void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs,
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001725 IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback,
1726 boolean scaleUp) {
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001727 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001728 clear();
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001729 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1730 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001731 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi43102412015-11-11 16:28:37 +01001732 if (specs != null) {
1733 for (int i = 0; i < specs.length; i++) {
1734 AppTransitionAnimationSpec spec = specs[i];
1735 if (spec != null) {
1736 mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec);
1737 if (i == 0) {
1738 // In full screen mode, the transition code depends on the default spec
1739 // to be set.
1740 Rect rect = spec.rect;
1741 putDefaultNextAppTransitionCoordinates(rect.left, rect.top,
Filip Gruszczynskie3264d82015-11-20 17:10:04 -08001742 rect.width(), rect.height(), spec.bitmap);
Jorim Jaggi43102412015-11-11 16:28:37 +01001743 }
Filip Gruszczynskid1431422015-09-08 11:18:54 -07001744 }
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001745 }
1746 }
1747 postAnimationCallback();
Filip Gruszczynski1a5203d2015-10-29 17:43:49 -07001748 mNextAppTransitionCallback = onAnimationStartedCallback;
1749 mAnimationFinishedCallback = onAnimationFinishedCallback;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001750 } else {
1751 postAnimationCallback();
1752 }
1753 }
1754
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001755 void overridePendingAppTransitionMultiThumbFuture(
1756 IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback,
1757 boolean scaleUp) {
1758 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001759 clear();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001760 mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP
1761 : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001762 mNextAppTransitionAnimationsSpecsFuture = specsFuture;
1763 mNextAppTransitionScaleUp = scaleUp;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001764 mNextAppTransitionFutureCallback = callback;
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001765 }
1766 }
1767
Winson Chung044d5292014-11-06 11:05:19 -08001768 void overrideInPlaceAppTransition(String packageName, int anim) {
1769 if (isTransitionSet()) {
Jorim Jaggi65193992015-11-23 16:49:59 -08001770 clear();
Winson Chung044d5292014-11-06 11:05:19 -08001771 mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE;
1772 mNextAppTransitionPackage = packageName;
1773 mNextAppTransitionInPlace = anim;
1774 } else {
1775 postAnimationCallback();
1776 }
1777 }
1778
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001779 /**
1780 * If a future is set for the app transition specs, fetch it in another thread.
1781 */
1782 private void fetchAppTransitionSpecsFromFuture() {
1783 if (mNextAppTransitionAnimationsSpecsFuture != null) {
1784 mNextAppTransitionAnimationsSpecsPending = true;
1785 final IAppTransitionAnimationSpecsFuture future
1786 = mNextAppTransitionAnimationsSpecsFuture;
1787 mNextAppTransitionAnimationsSpecsFuture = null;
1788 mDefaultExecutor.execute(new Runnable() {
1789 @Override
1790 public void run() {
1791 AppTransitionAnimationSpec[] specs = null;
1792 try {
1793 specs = future.get();
1794 } catch (RemoteException e) {
1795 Slog.w(TAG, "Failed to fetch app transition specs: " + e);
1796 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001797 synchronized (mService.mWindowMap) {
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001798 mNextAppTransitionAnimationsSpecsPending = false;
Jorim Jaggi7cc7b082015-11-10 16:06:54 +01001799 overridePendingAppTransitionMultiThumb(specs,
1800 mNextAppTransitionFutureCallback, null /* finishedCallback */,
1801 mNextAppTransitionScaleUp);
1802 mNextAppTransitionFutureCallback = null;
Filip Gruszczynski96daf322015-11-18 18:01:27 -08001803 if (specs != null) {
1804 mService.prolongAnimationsFromSpecs(specs, mNextAppTransitionScaleUp);
1805 }
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001806 }
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08001807 mService.requestTraversal();
Jorim Jaggi2f7d2922015-10-29 13:08:29 +01001808 }
1809 });
1810 }
1811 }
1812
Craig Mautner164d4bb2012-11-26 13:51:23 -08001813 @Override
1814 public String toString() {
Wale Ogunwale8ebc82a2015-05-13 15:27:12 -07001815 return "mNextAppTransition=" + appTransitionToString(mNextAppTransition);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001816 }
1817
Craig Mautner4b71aa12012-12-27 17:20:01 -08001818 /**
1819 * Returns the human readable name of a window transition.
1820 *
1821 * @param transition The window transition.
1822 * @return The transition symbolic name.
1823 */
1824 public static String appTransitionToString(int transition) {
1825 switch (transition) {
1826 case TRANSIT_UNSET: {
1827 return "TRANSIT_UNSET";
1828 }
1829 case TRANSIT_NONE: {
1830 return "TRANSIT_NONE";
1831 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001832 case TRANSIT_ACTIVITY_OPEN: {
1833 return "TRANSIT_ACTIVITY_OPEN";
1834 }
1835 case TRANSIT_ACTIVITY_CLOSE: {
1836 return "TRANSIT_ACTIVITY_CLOSE";
1837 }
1838 case TRANSIT_TASK_OPEN: {
1839 return "TRANSIT_TASK_OPEN";
1840 }
1841 case TRANSIT_TASK_CLOSE: {
1842 return "TRANSIT_TASK_CLOSE";
1843 }
1844 case TRANSIT_TASK_TO_FRONT: {
1845 return "TRANSIT_TASK_TO_FRONT";
1846 }
1847 case TRANSIT_TASK_TO_BACK: {
1848 return "TRANSIT_TASK_TO_BACK";
1849 }
1850 case TRANSIT_WALLPAPER_CLOSE: {
1851 return "TRANSIT_WALLPAPER_CLOSE";
1852 }
1853 case TRANSIT_WALLPAPER_OPEN: {
1854 return "TRANSIT_WALLPAPER_OPEN";
1855 }
1856 case TRANSIT_WALLPAPER_INTRA_OPEN: {
1857 return "TRANSIT_WALLPAPER_INTRA_OPEN";
1858 }
1859 case TRANSIT_WALLPAPER_INTRA_CLOSE: {
1860 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
1861 }
Craig Mautnerbb742462014-07-07 15:28:55 -07001862 case TRANSIT_TASK_OPEN_BEHIND: {
1863 return "TRANSIT_TASK_OPEN_BEHIND";
1864 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001865 case TRANSIT_ACTIVITY_RELAUNCH: {
1866 return "TRANSIT_ACTIVITY_RELAUNCH";
1867 }
Jorim Jaggi192086e2016-03-11 17:17:03 +01001868 case TRANSIT_DOCK_TASK_FROM_RECENTS: {
1869 return "TRANSIT_DOCK_TASK_FROM_RECENTS";
1870 }
Jorim Jaggife762342016-10-13 14:33:27 +02001871 case TRANSIT_KEYGUARD_GOING_AWAY: {
1872 return "TRANSIT_KEYGUARD_GOING_AWAY";
1873 }
1874 case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: {
1875 return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER";
1876 }
1877 case TRANSIT_KEYGUARD_OCCLUDE: {
1878 return "TRANSIT_KEYGUARD_OCCLUDE";
1879 }
1880 case TRANSIT_KEYGUARD_UNOCCLUDE: {
1881 return "TRANSIT_KEYGUARD_UNOCCLUDE";
1882 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001883 default: {
1884 return "<UNKNOWN>";
1885 }
1886 }
1887 }
1888
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001889 private String appStateToString() {
1890 switch (mAppTransitionState) {
1891 case APP_STATE_IDLE:
1892 return "APP_STATE_IDLE";
1893 case APP_STATE_READY:
1894 return "APP_STATE_READY";
1895 case APP_STATE_RUNNING:
1896 return "APP_STATE_RUNNING";
1897 case APP_STATE_TIMEOUT:
1898 return "APP_STATE_TIMEOUT";
1899 default:
1900 return "unknown state=" + mAppTransitionState;
1901 }
1902 }
1903
1904 private String transitTypeToString() {
1905 switch (mNextAppTransitionType) {
1906 case NEXT_TRANSIT_TYPE_NONE:
1907 return "NEXT_TRANSIT_TYPE_NONE";
1908 case NEXT_TRANSIT_TYPE_CUSTOM:
1909 return "NEXT_TRANSIT_TYPE_CUSTOM";
Winson Chung044d5292014-11-06 11:05:19 -08001910 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
1911 return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001912 case NEXT_TRANSIT_TYPE_SCALE_UP:
1913 return "NEXT_TRANSIT_TYPE_SCALE_UP";
1914 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1915 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP";
1916 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
1917 return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN";
Winson Chunga4ccb862014-08-22 15:26:27 -07001918 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
1919 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP";
1920 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN:
1921 return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN";
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001922 default:
1923 return "unknown type=" + mNextAppTransitionType;
1924 }
1925 }
1926
Craig Mautner164d4bb2012-11-26 13:51:23 -08001927 @Override
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001928 public void dump(PrintWriter pw, String prefix) {
1929 pw.print(prefix); pw.println(this);
1930 pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString());
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001931 if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001932 pw.print(prefix); pw.print("mNextAppTransitionType=");
1933 pw.println(transitTypeToString());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001934 }
1935 switch (mNextAppTransitionType) {
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001936 case NEXT_TRANSIT_TYPE_CUSTOM:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001937 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001938 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001939 pw.print(prefix); pw.print("mNextAppTransitionEnter=0x");
Craig Mautner164d4bb2012-11-26 13:51:23 -08001940 pw.print(Integer.toHexString(mNextAppTransitionEnter));
1941 pw.print(" mNextAppTransitionExit=0x");
1942 pw.println(Integer.toHexString(mNextAppTransitionExit));
1943 break;
Winson Chung044d5292014-11-06 11:05:19 -08001944 case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE:
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001945 pw.print(prefix); pw.print("mNextAppTransitionPackage=");
Winson Chung044d5292014-11-06 11:05:19 -08001946 pw.println(mNextAppTransitionPackage);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001947 pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x");
Winson Chung044d5292014-11-06 11:05:19 -08001948 pw.print(Integer.toHexString(mNextAppTransitionInPlace));
1949 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001950 case NEXT_TRANSIT_TYPE_SCALE_UP: {
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001951 getDefaultNextAppTransitionStartRect(mTmpRect);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001952 pw.print(prefix); pw.print("mNextAppTransitionStartX=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001953 pw.print(mTmpRect.left);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001954 pw.print(" mNextAppTransitionStartY=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001955 pw.println(mTmpRect.top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001956 pw.print(prefix); pw.print("mNextAppTransitionStartWidth=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001957 pw.print(mTmpRect.width());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001958 pw.print(" mNextAppTransitionStartHeight=");
Filip Gruszczynskid64ef3e2015-10-27 17:58:02 -07001959 pw.println(mTmpRect.height());
Craig Mautner164d4bb2012-11-26 13:51:23 -08001960 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001961 }
Craig Mautner9a29a5d2012-12-27 19:03:40 -08001962 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP:
1963 case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN:
Winson Chunga4ccb862014-08-22 15:26:27 -07001964 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP:
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001965 case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: {
1966 pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec=");
1967 pw.println(mDefaultNextAppTransitionAnimationSpec);
1968 pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs=");
1969 pw.println(mNextAppTransitionAnimationsSpecs);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001970 pw.print(prefix); pw.print("mNextAppTransitionScaleUp=");
1971 pw.println(mNextAppTransitionScaleUp);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001972 break;
Filip Gruszczynski170192a2015-08-16 17:46:34 -07001973 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001974 }
1975 if (mNextAppTransitionCallback != null) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08001976 pw.print(prefix); pw.print("mNextAppTransitionCallback=");
1977 pw.println(mNextAppTransitionCallback);
Craig Mautner164d4bb2012-11-26 13:51:23 -08001978 }
Chong Zhang60091a92016-07-27 17:52:45 -07001979 if (mLastUsedAppTransition != TRANSIT_NONE) {
1980 pw.print(prefix); pw.print("mLastUsedAppTransition=");
1981 pw.println(appTransitionToString(mLastUsedAppTransition));
1982 pw.print(prefix); pw.print("mLastOpeningApp=");
1983 pw.println(mLastOpeningApp);
1984 pw.print(prefix); pw.print("mLastClosingApp=");
1985 pw.println(mLastClosingApp);
1986 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08001987 }
Amith Yamasani4befbec2013-07-10 16:18:01 -07001988
1989 public void setCurrentUser(int newUserId) {
1990 mCurrentUserId = newUserId;
1991 }
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001992
1993 /**
1994 * @return true if transition is not running and should not be skipped, false if transition is
1995 * already running
1996 */
Jorim Jaggife762342016-10-13 14:33:27 +02001997 boolean prepareAppTransitionLocked(int transit, boolean alwaysKeepCurrent, int flags,
1998 boolean forceOverride) {
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001999 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:"
2000 + " transit=" + appTransitionToString(transit)
2001 + " " + this
2002 + " alwaysKeepCurrent=" + alwaysKeepCurrent
2003 + " Callers=" + Debug.getCallers(3));
Jorim Jaggife762342016-10-13 14:33:27 +02002004 if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet()
2005 || mNextAppTransition == TRANSIT_NONE) {
2006 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002007 } else if (!alwaysKeepCurrent) {
2008 if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) {
2009 // Opening a new task always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002010 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002011 } else if (transit == TRANSIT_ACTIVITY_OPEN
2012 && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) {
2013 // Opening a new activity always supersedes a close for the anim.
Jorim Jaggife762342016-10-13 14:33:27 +02002014 setAppTransition(transit, flags);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002015 }
2016 }
2017 boolean prepared = prepare();
2018 if (isTransitionSet()) {
Filip Gruszczynski1a4dfe52015-11-15 10:58:57 -08002019 mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
2020 mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002021 }
2022 return prepared;
2023 }
Winsonb2024762016-04-05 17:32:30 -07002024
2025 /**
Jorim Jaggife762342016-10-13 14:33:27 +02002026 * @return true if {@param transit} is representing a transition in which Keyguard is going
2027 * away, false otherwise
2028 */
2029 public static boolean isKeyguardGoingAwayTransit(int transit) {
2030 return transit == TRANSIT_KEYGUARD_GOING_AWAY
2031 || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER;
2032 }
2033
2034 private static boolean isKeyguardTransit(int transit) {
2035 return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE
2036 || transit == TRANSIT_KEYGUARD_UNOCCLUDE;
2037 }
2038
2039 /**
Winsonb2024762016-04-05 17:32:30 -07002040 * @return whether the specified {@param uiMode} is the TV mode.
2041 */
2042 private boolean isTvUiMode(int uiMode) {
2043 return (uiMode & Configuration.UI_MODE_TYPE_TELEVISION) > 0;
2044 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002045}