Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.wm; |
| 18 | |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 19 | import static android.view.WindowManager.LayoutParams; |
| 20 | import static android.view.WindowManager.TRANSIT_ACTIVITY_CLOSE; |
| 21 | import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN; |
| 22 | import static android.view.WindowManager.TRANSIT_ACTIVITY_RELAUNCH; |
| 23 | import static android.view.WindowManager.TRANSIT_DOCK_TASK_FROM_RECENTS; |
| 24 | import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION; |
| 25 | import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE; |
| 26 | import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY; |
| 27 | import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER; |
| 28 | import static android.view.WindowManager.TRANSIT_KEYGUARD_OCCLUDE; |
| 29 | import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE; |
| 30 | import static android.view.WindowManager.TRANSIT_NONE; |
| 31 | import static android.view.WindowManager.TRANSIT_TASK_CLOSE; |
Jorim Jaggi | cecf424 | 2018-02-21 18:46:53 +0100 | [diff] [blame] | 32 | import static android.view.WindowManager.TRANSIT_TASK_IN_PLACE; |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 33 | import static android.view.WindowManager.TRANSIT_TASK_OPEN; |
| 34 | import static android.view.WindowManager.TRANSIT_TASK_OPEN_BEHIND; |
| 35 | import static android.view.WindowManager.TRANSIT_TASK_TO_BACK; |
| 36 | import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT; |
Jorim Jaggi | 98a9d20 | 2018-03-26 16:17:07 +0200 | [diff] [blame^] | 37 | import static android.view.WindowManager.TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE; |
| 38 | import static android.view.WindowManager.TRANSIT_TRANSLUCENT_ACTIVITY_OPEN; |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 39 | import static android.view.WindowManager.TRANSIT_UNSET; |
| 40 | import static android.view.WindowManager.TRANSIT_WALLPAPER_CLOSE; |
| 41 | import static android.view.WindowManager.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 42 | import static android.view.WindowManager.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 43 | import static android.view.WindowManager.TRANSIT_WALLPAPER_OPEN; |
Tony Mak | 83546a8 | 2018-01-22 13:56:20 +0000 | [diff] [blame] | 44 | |
Filip Gruszczynski | 8286136 | 2015-10-16 14:21:09 -0700 | [diff] [blame] | 45 | import static com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation; |
| 46 | import static com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 47 | import static com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation; |
| 48 | import static com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 49 | import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindSourceAnimation; |
| 50 | import static com.android.internal.R.styleable.WindowAnimation_launchTaskBehindTargetAnimation; |
| 51 | import static com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation; |
| 52 | import static com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 53 | import static com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation; |
| 54 | import static com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 55 | import static com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation; |
| 56 | import static com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 57 | import static com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation; |
| 58 | import static com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 59 | import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation; |
| 60 | import static com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 61 | import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation; |
| 62 | import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
| 63 | import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation; |
| 64 | import static com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 65 | import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation; |
| 66 | import static com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
Filip Gruszczynski | 198dcbf | 2016-01-18 10:02:00 -0800 | [diff] [blame] | 67 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; |
| 68 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 69 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 70 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 71 | import static com.android.server.wm.WindowManagerInternal.AppTransitionListener; |
Tony Mak | 089c35e | 2017-12-18 20:34:14 +0000 | [diff] [blame] | 72 | import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM; |
Matthew Ng | bf1d985 | 2017-03-14 12:23:09 -0700 | [diff] [blame] | 73 | import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM; |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 74 | import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 75 | import static com.android.server.wm.AppTransitionProto.APP_TRANSITION_STATE; |
| 76 | import static com.android.server.wm.AppTransitionProto.LAST_USED_APP_TRANSITION; |
Filip Gruszczynski | 8286136 | 2015-10-16 14:21:09 -0700 | [diff] [blame] | 77 | |
Tony Mak | 64b8d56 | 2017-12-28 17:44:02 +0000 | [diff] [blame] | 78 | import android.annotation.DrawableRes; |
Filip Gruszczynski | 71b0d2d | 2015-08-12 18:52:26 -0700 | [diff] [blame] | 79 | import android.annotation.Nullable; |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 80 | import android.app.ActivityManager; |
Tony Mak | 089c35e | 2017-12-18 20:34:14 +0000 | [diff] [blame] | 81 | import android.content.ComponentName; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 82 | import android.content.Context; |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 83 | import android.content.res.Configuration; |
John Reck | 519ad48 | 2018-02-12 17:08:48 -0800 | [diff] [blame] | 84 | import android.graphics.Bitmap; |
| 85 | import android.graphics.Canvas; |
Tony Mak | 64b8d56 | 2017-12-28 17:44:02 +0000 | [diff] [blame] | 86 | import android.graphics.Color; |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 87 | import android.graphics.GraphicBuffer; |
Jorim Jaggi | 787e9dd | 2016-03-15 10:52:40 +0100 | [diff] [blame] | 88 | import android.graphics.Path; |
John Reck | 519ad48 | 2018-02-12 17:08:48 -0800 | [diff] [blame] | 89 | import android.graphics.Picture; |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 90 | import android.graphics.Rect; |
Tony Mak | 64b8d56 | 2017-12-28 17:44:02 +0000 | [diff] [blame] | 91 | import android.graphics.drawable.Drawable; |
Jorim Jaggi | ed410b6 | 2017-05-05 15:16:14 +0200 | [diff] [blame] | 92 | import android.os.Binder; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 93 | import android.os.Debug; |
Jorim Jaggi | 77ba480 | 2015-02-18 13:57:50 +0100 | [diff] [blame] | 94 | import android.os.IBinder; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 95 | import android.os.IRemoteCallback; |
Jorim Jaggi | 2f7d292 | 2015-10-29 13:08:29 +0100 | [diff] [blame] | 96 | import android.os.RemoteException; |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 97 | import android.os.SystemClock; |
Manu Cornet | d737680 | 2017-01-13 13:44:07 -0800 | [diff] [blame] | 98 | import android.os.SystemProperties; |
Tony Mak | 089c35e | 2017-12-18 20:34:14 +0000 | [diff] [blame] | 99 | import android.os.UserHandle; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 100 | import android.util.ArraySet; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 101 | import android.util.Slog; |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 102 | import android.util.SparseArray; |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 103 | import android.util.proto.ProtoOutputStream; |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 104 | import android.view.AppTransitionAnimationSpec; |
Jorim Jaggi | 2f7d292 | 2015-10-29 13:08:29 +0100 | [diff] [blame] | 105 | import android.view.IAppTransitionAnimationSpecsFuture; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 106 | import android.view.RemoteAnimationAdapter; |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 107 | import android.view.WindowManager.TransitionFlags; |
| 108 | import android.view.WindowManager.TransitionType; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 109 | import android.view.animation.AlphaAnimation; |
| 110 | import android.view.animation.Animation; |
| 111 | import android.view.animation.AnimationSet; |
| 112 | import android.view.animation.AnimationUtils; |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 113 | import android.view.animation.ClipRectAnimation; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 114 | import android.view.animation.Interpolator; |
Jorim Jaggi | 1d763a6 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 115 | import android.view.animation.PathInterpolator; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 116 | import android.view.animation.ScaleAnimation; |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 117 | import android.view.animation.TranslateAnimation; |
Jorim Jaggi | 1d763a6 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 118 | |
Jorim Jaggi | 98a9d20 | 2018-03-26 16:17:07 +0200 | [diff] [blame^] | 119 | import com.android.internal.R; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 120 | import com.android.internal.util.DumpUtils.Dump; |
| 121 | import com.android.server.AttributeCache; |
| 122 | import com.android.server.wm.WindowManagerService.H; |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 123 | import com.android.server.wm.animation.ClipRectLRAnimation; |
| 124 | import com.android.server.wm.animation.ClipRectTBAnimation; |
Jorim Jaggi | 787e9dd | 2016-03-15 10:52:40 +0100 | [diff] [blame] | 125 | import com.android.server.wm.animation.CurvedTranslateAnimation; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 126 | |
| 127 | import java.io.PrintWriter; |
Jorim Jaggi | 77ba480 | 2015-02-18 13:57:50 +0100 | [diff] [blame] | 128 | import java.util.ArrayList; |
Jorim Jaggi | 2f7d292 | 2015-10-29 13:08:29 +0100 | [diff] [blame] | 129 | import java.util.concurrent.ExecutorService; |
| 130 | import java.util.concurrent.Executors; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 131 | |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 132 | // State management of app transitions. When we are preparing for a |
| 133 | // transition, mNextAppTransition will be the kind of transition to |
| 134 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 135 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 136 | // made visible or hidden at the next transition. |
| 137 | public class AppTransition implements Dump { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 138 | private static final String TAG = TAG_WITH_CLASS_NAME ? "AppTransition" : TAG_WM; |
Jorim Jaggi | 1d763a6 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 139 | private static final int CLIP_REVEAL_TRANSLATION_Y_DP = 8; |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 140 | |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 141 | /** Fraction of animation at which the recents thumbnail stays completely transparent */ |
Jorim Jaggi | 1d763a6 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 142 | private static final float RECENTS_THUMBNAIL_FADEIN_FRACTION = 0.5f; |
Craig Mautner | 321bdf5 | 2012-12-18 09:53:24 -0800 | [diff] [blame] | 143 | /** Fraction of animation at which the recents thumbnail becomes completely transparent */ |
Jorim Jaggi | 1d763a6 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 144 | private static final float RECENTS_THUMBNAIL_FADEOUT_FRACTION = 0.5f; |
Craig Mautner | 321bdf5 | 2012-12-18 09:53:24 -0800 | [diff] [blame] | 145 | |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 146 | static final int DEFAULT_APP_TRANSITION_DURATION = 336; |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 147 | |
| 148 | /** Interpolator to be used for animations that respond directly to a touch */ |
| 149 | static final Interpolator TOUCH_RESPONSE_INTERPOLATOR = |
| 150 | new PathInterpolator(0.3f, 0f, 0.1f, 1f); |
| 151 | |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 152 | private static final Interpolator THUMBNAIL_DOCK_INTERPOLATOR = |
| 153 | new PathInterpolator(0.85f, 0f, 1f, 1f); |
| 154 | |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 155 | /** |
| 156 | * Maximum duration for the clip reveal animation. This is used when there is a lot of movement |
| 157 | * involved, to make it more understandable. |
| 158 | */ |
| 159 | private static final int MAX_CLIP_REVEAL_TRANSITION_DURATION = 420; |
Jorim Jaggi | 1d763a6 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 160 | private static final int THUMBNAIL_APP_TRANSITION_DURATION = 336; |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 161 | private static final long APP_TRANSITION_TIMEOUT_MS = 5000; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 162 | |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 163 | private final Context mContext; |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 164 | private final WindowManagerService mService; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 165 | |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 166 | private @TransitionType int mNextAppTransition = TRANSIT_UNSET; |
| 167 | private @TransitionFlags int mNextAppTransitionFlags = 0; |
Chong Zhang | 60091a9 | 2016-07-27 17:52:45 -0700 | [diff] [blame] | 168 | private int mLastUsedAppTransition = TRANSIT_UNSET; |
| 169 | private String mLastOpeningApp; |
| 170 | private String mLastClosingApp; |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 171 | |
| 172 | private static final int NEXT_TRANSIT_TYPE_NONE = 0; |
| 173 | private static final int NEXT_TRANSIT_TYPE_CUSTOM = 1; |
| 174 | private static final int NEXT_TRANSIT_TYPE_SCALE_UP = 2; |
| 175 | private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP = 3; |
| 176 | private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN = 4; |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 177 | private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP = 5; |
| 178 | private static final int NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN = 6; |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 179 | private static final int NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE = 7; |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 180 | private static final int NEXT_TRANSIT_TYPE_CLIP_REVEAL = 8; |
Tony Mak | 089c35e | 2017-12-18 20:34:14 +0000 | [diff] [blame] | 181 | |
| 182 | /** |
| 183 | * Refers to the transition to activity started by using {@link |
| 184 | * android.content.pm.crossprofile.CrossProfileApps#startMainActivity(ComponentName, UserHandle) |
| 185 | * }. |
| 186 | */ |
| 187 | private static final int NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS = 9; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 188 | private static final int NEXT_TRANSIT_TYPE_REMOTE = 10; |
| 189 | |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 190 | private int mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE; |
| 191 | |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 192 | // These are the possible states for the enter/exit activities during a thumbnail transition |
| 193 | private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_UP = 0; |
| 194 | private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_UP = 1; |
| 195 | private static final int THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN = 2; |
| 196 | private static final int THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN = 3; |
| 197 | |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 198 | private String mNextAppTransitionPackage; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 199 | // Used for thumbnail transitions. True if we're scaling up, false if scaling down |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 200 | private boolean mNextAppTransitionScaleUp; |
| 201 | private IRemoteCallback mNextAppTransitionCallback; |
Jorim Jaggi | 7cc7b08 | 2015-11-10 16:06:54 +0100 | [diff] [blame] | 202 | private IRemoteCallback mNextAppTransitionFutureCallback; |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 203 | private IRemoteCallback mAnimationFinishedCallback; |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 204 | private int mNextAppTransitionEnter; |
| 205 | private int mNextAppTransitionExit; |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 206 | private int mNextAppTransitionInPlace; |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 207 | |
| 208 | // Keyed by task id. |
| 209 | private final SparseArray<AppTransitionAnimationSpec> mNextAppTransitionAnimationsSpecs |
| 210 | = new SparseArray<>(); |
Jorim Jaggi | 2f7d292 | 2015-10-29 13:08:29 +0100 | [diff] [blame] | 211 | private IAppTransitionAnimationSpecsFuture mNextAppTransitionAnimationsSpecsFuture; |
| 212 | private boolean mNextAppTransitionAnimationsSpecsPending; |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 213 | private AppTransitionAnimationSpec mDefaultNextAppTransitionAnimationSpec; |
| 214 | |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 215 | private Rect mNextAppTransitionInsets = new Rect(); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 216 | |
Winson Chung | 2820c45 | 2014-04-15 15:34:44 -0700 | [diff] [blame] | 217 | private Rect mTmpFromClipRect = new Rect(); |
| 218 | private Rect mTmpToClipRect = new Rect(); |
| 219 | |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 220 | private final Rect mTmpRect = new Rect(); |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 221 | |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 222 | private final static int APP_STATE_IDLE = 0; |
| 223 | private final static int APP_STATE_READY = 1; |
| 224 | private final static int APP_STATE_RUNNING = 2; |
| 225 | private final static int APP_STATE_TIMEOUT = 3; |
| 226 | private int mAppTransitionState = APP_STATE_IDLE; |
| 227 | |
| 228 | private final int mConfigShortAnimTime; |
Craig Mautner | 321bdf5 | 2012-12-18 09:53:24 -0800 | [diff] [blame] | 229 | private final Interpolator mDecelerateInterpolator; |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 230 | private final Interpolator mThumbnailFadeInInterpolator; |
| 231 | private final Interpolator mThumbnailFadeOutInterpolator; |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 232 | private final Interpolator mLinearOutSlowInInterpolator; |
Jorim Jaggi | 1d763a6 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 233 | private final Interpolator mFastOutLinearInInterpolator; |
Jorim Jaggi | 787e9dd | 2016-03-15 10:52:40 +0100 | [diff] [blame] | 234 | private final Interpolator mFastOutSlowInInterpolator; |
Jorim Jaggi | 1d763a6 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 235 | private final Interpolator mClipHorizontalInterpolator = new PathInterpolator(0, 0, 0.4f, 1f); |
| 236 | |
Jorim Jaggi | 1d763a6 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 237 | private final int mClipRevealTranslationY; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 238 | |
Amith Yamasani | 4befbec | 2013-07-10 16:18:01 -0700 | [diff] [blame] | 239 | private int mCurrentUserId = 0; |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 240 | private long mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION; |
Amith Yamasani | 4befbec | 2013-07-10 16:18:01 -0700 | [diff] [blame] | 241 | |
Jorim Jaggi | 77ba480 | 2015-02-18 13:57:50 +0100 | [diff] [blame] | 242 | private final ArrayList<AppTransitionListener> mListeners = new ArrayList<>(); |
Jorim Jaggi | 2f7d292 | 2015-10-29 13:08:29 +0100 | [diff] [blame] | 243 | private final ExecutorService mDefaultExecutor = Executors.newSingleThreadExecutor(); |
Jorim Jaggi | 77ba480 | 2015-02-18 13:57:50 +0100 | [diff] [blame] | 244 | |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 245 | private int mLastClipRevealMaxTranslation; |
| 246 | private boolean mLastHadClipReveal; |
Jorim Jaggi | 363ab98 | 2016-04-26 19:51:20 -0700 | [diff] [blame] | 247 | private boolean mProlongedAnimationsEnded; |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 248 | |
Manu Cornet | d737680 | 2017-01-13 13:44:07 -0800 | [diff] [blame] | 249 | private final boolean mGridLayoutRecentsEnabled; |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 250 | private final boolean mLowRamRecentsEnabled; |
Manu Cornet | d737680 | 2017-01-13 13:44:07 -0800 | [diff] [blame] | 251 | |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 252 | private RemoteAnimationController mRemoteAnimationController; |
| 253 | |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 254 | AppTransition(Context context, WindowManagerService service) { |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 255 | mContext = context; |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 256 | mService = service; |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 257 | mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context, |
| 258 | com.android.internal.R.interpolator.linear_out_slow_in); |
Jorim Jaggi | 1d763a6 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 259 | mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(context, |
| 260 | com.android.internal.R.interpolator.fast_out_linear_in); |
Jorim Jaggi | 787e9dd | 2016-03-15 10:52:40 +0100 | [diff] [blame] | 261 | mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context, |
| 262 | com.android.internal.R.interpolator.fast_out_slow_in); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 263 | mConfigShortAnimTime = context.getResources().getInteger( |
| 264 | com.android.internal.R.integer.config_shortAnimTime); |
Craig Mautner | 321bdf5 | 2012-12-18 09:53:24 -0800 | [diff] [blame] | 265 | mDecelerateInterpolator = AnimationUtils.loadInterpolator(context, |
| 266 | com.android.internal.R.interpolator.decelerate_cubic); |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 267 | mThumbnailFadeInInterpolator = new Interpolator() { |
| 268 | @Override |
| 269 | public float getInterpolation(float input) { |
| 270 | // Linear response for first fraction, then complete after that. |
| 271 | if (input < RECENTS_THUMBNAIL_FADEIN_FRACTION) { |
| 272 | return 0f; |
| 273 | } |
Jorim Jaggi | 1d763a6 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 274 | float t = (input - RECENTS_THUMBNAIL_FADEIN_FRACTION) / |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 275 | (1f - RECENTS_THUMBNAIL_FADEIN_FRACTION); |
Jorim Jaggi | 1d763a6 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 276 | return mFastOutLinearInInterpolator.getInterpolation(t); |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 277 | } |
| 278 | }; |
| 279 | mThumbnailFadeOutInterpolator = new Interpolator() { |
Craig Mautner | 321bdf5 | 2012-12-18 09:53:24 -0800 | [diff] [blame] | 280 | @Override |
| 281 | public float getInterpolation(float input) { |
| 282 | // Linear response for first fraction, then complete after that. |
| 283 | if (input < RECENTS_THUMBNAIL_FADEOUT_FRACTION) { |
Jorim Jaggi | 1d763a6 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 284 | float t = input / RECENTS_THUMBNAIL_FADEOUT_FRACTION; |
| 285 | return mLinearOutSlowInInterpolator.getInterpolation(t); |
Craig Mautner | 321bdf5 | 2012-12-18 09:53:24 -0800 | [diff] [blame] | 286 | } |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 287 | return 1f; |
Craig Mautner | 321bdf5 | 2012-12-18 09:53:24 -0800 | [diff] [blame] | 288 | } |
| 289 | }; |
Jorim Jaggi | 1d763a6 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 290 | mClipRevealTranslationY = (int) (CLIP_REVEAL_TRANSLATION_Y_DP |
| 291 | * mContext.getResources().getDisplayMetrics().density); |
Manu Cornet | d737680 | 2017-01-13 13:44:07 -0800 | [diff] [blame] | 292 | mGridLayoutRecentsEnabled = SystemProperties.getBoolean("ro.recents.grid", false); |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 293 | mLowRamRecentsEnabled = ActivityManager.isLowRamDeviceStatic(); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | boolean isTransitionSet() { |
| 297 | return mNextAppTransition != TRANSIT_UNSET; |
| 298 | } |
| 299 | |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 300 | boolean isTransitionEqual(@TransitionType int transit) { |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 301 | return mNextAppTransition == transit; |
| 302 | } |
| 303 | |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 304 | @TransitionType int getAppTransition() { |
Craig Mautner | 321bdf5 | 2012-12-18 09:53:24 -0800 | [diff] [blame] | 305 | return mNextAppTransition; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 306 | } |
| 307 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 308 | private void setAppTransition(int transit, int flags) { |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 309 | mNextAppTransition = transit; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 310 | mNextAppTransitionFlags |= flags; |
Chong Zhang | 60091a9 | 2016-07-27 17:52:45 -0700 | [diff] [blame] | 311 | setLastAppTransition(TRANSIT_UNSET, null, null); |
Jorim Jaggi | 245281c | 2017-06-07 14:33:04 -0700 | [diff] [blame] | 312 | updateBooster(); |
Chong Zhang | 60091a9 | 2016-07-27 17:52:45 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | void setLastAppTransition(int transit, AppWindowToken openingApp, AppWindowToken closingApp) { |
| 316 | mLastUsedAppTransition = transit; |
| 317 | mLastOpeningApp = "" + openingApp; |
| 318 | mLastClosingApp = "" + closingApp; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | boolean isReady() { |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 322 | return mAppTransitionState == APP_STATE_READY |
| 323 | || mAppTransitionState == APP_STATE_TIMEOUT; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 324 | } |
| 325 | |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 326 | void setReady() { |
Jorim Jaggi | 245281c | 2017-06-07 14:33:04 -0700 | [diff] [blame] | 327 | setAppTransitionState(APP_STATE_READY); |
Jorim Jaggi | 2f7d292 | 2015-10-29 13:08:29 +0100 | [diff] [blame] | 328 | fetchAppTransitionSpecsFromFuture(); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | boolean isRunning() { |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 332 | return mAppTransitionState == APP_STATE_RUNNING; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 333 | } |
| 334 | |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 335 | void setIdle() { |
Jorim Jaggi | 245281c | 2017-06-07 14:33:04 -0700 | [diff] [blame] | 336 | setAppTransitionState(APP_STATE_IDLE); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | boolean isTimeout() { |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 340 | return mAppTransitionState == APP_STATE_TIMEOUT; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 341 | } |
| 342 | |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 343 | void setTimeout() { |
Jorim Jaggi | 245281c | 2017-06-07 14:33:04 -0700 | [diff] [blame] | 344 | setAppTransitionState(APP_STATE_TIMEOUT); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 345 | } |
| 346 | |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 347 | GraphicBuffer getAppTransitionThumbnailHeader(int taskId) { |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 348 | AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId); |
Filip Gruszczynski | 7248c56 | 2015-11-09 13:05:40 -0800 | [diff] [blame] | 349 | if (spec == null) { |
| 350 | spec = mDefaultNextAppTransitionAnimationSpec; |
| 351 | } |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 352 | return spec != null ? spec.buffer : null; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 353 | } |
| 354 | |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 355 | /** Returns whether the next thumbnail transition is aspect scaled up. */ |
| 356 | boolean isNextThumbnailTransitionAspectScaled() { |
| 357 | return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP || |
| 358 | mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN; |
| 359 | } |
| 360 | |
| 361 | /** Returns whether the next thumbnail transition is scaling up. */ |
| 362 | boolean isNextThumbnailTransitionScaleUp() { |
| 363 | return mNextAppTransitionScaleUp; |
| 364 | } |
| 365 | |
Filip Gruszczynski | 4cbc315 | 2015-12-07 11:50:57 -0800 | [diff] [blame] | 366 | boolean isNextAppTransitionThumbnailUp() { |
| 367 | return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP || |
| 368 | mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP; |
| 369 | } |
| 370 | |
| 371 | boolean isNextAppTransitionThumbnailDown() { |
| 372 | return mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN || |
| 373 | mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN; |
| 374 | } |
| 375 | |
Tony Mak | 64b8d56 | 2017-12-28 17:44:02 +0000 | [diff] [blame] | 376 | |
| 377 | boolean isNextAppTransitionOpenCrossProfileApps() { |
| 378 | return mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS; |
| 379 | } |
| 380 | |
Jorim Jaggi | 2f7d292 | 2015-10-29 13:08:29 +0100 | [diff] [blame] | 381 | /** |
| 382 | * @return true if and only if we are currently fetching app transition specs from the future |
| 383 | * passed into {@link #overridePendingAppTransitionMultiThumbFuture} |
| 384 | */ |
| 385 | boolean isFetchingAppTransitionsSpecs() { |
| 386 | return mNextAppTransitionAnimationsSpecsPending; |
| 387 | } |
| 388 | |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 389 | private boolean prepare() { |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 390 | if (!isRunning()) { |
Jorim Jaggi | 245281c | 2017-06-07 14:33:04 -0700 | [diff] [blame] | 391 | setAppTransitionState(APP_STATE_IDLE); |
Jorim Jaggi | 77ba480 | 2015-02-18 13:57:50 +0100 | [diff] [blame] | 392 | notifyAppTransitionPendingLocked(); |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 393 | mLastHadClipReveal = false; |
| 394 | mLastClipRevealMaxTranslation = 0; |
| 395 | mLastClipRevealTransitionDuration = DEFAULT_APP_TRANSITION_DURATION; |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 396 | return true; |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 397 | } |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 398 | return false; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 399 | } |
| 400 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 401 | /** |
| 402 | * @return bit-map of WindowManagerPolicy#FINISH_LAYOUT_REDO_* to indicate whether another |
| 403 | * layout pass needs to be done |
| 404 | */ |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 405 | int goodToGo(int transit, AppWindowToken topOpeningApp, |
| 406 | AppWindowToken topClosingApp, ArraySet<AppWindowToken> openingApps, |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 407 | ArraySet<AppWindowToken> closingApps) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 408 | mNextAppTransition = TRANSIT_UNSET; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 409 | mNextAppTransitionFlags = 0; |
Jorim Jaggi | 245281c | 2017-06-07 14:33:04 -0700 | [diff] [blame] | 410 | setAppTransitionState(APP_STATE_RUNNING); |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 411 | final AnimationAdapter topOpeningAnim = topOpeningApp != null |
| 412 | ? topOpeningApp.getAnimation() |
| 413 | : null; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 414 | int redoLayout = notifyAppTransitionStartingLocked(transit, |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 415 | topOpeningApp != null ? topOpeningApp.token : null, |
| 416 | topClosingApp != null ? topClosingApp.token : null, |
| 417 | topOpeningAnim != null ? topOpeningAnim.getDurationHint() : 0, |
| 418 | topOpeningAnim != null |
| 419 | ? topOpeningAnim.getStatusBarTransitionsStartTime() |
| 420 | : SystemClock.uptimeMillis(), |
| 421 | AnimationAdapter.STATUS_BAR_TRANSITION_DURATION); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 422 | mService.getDefaultDisplayContentLocked().getDockedDividerController() |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 423 | .notifyAppTransitionStarting(openingApps, transit); |
Jorim Jaggi | 363ab98 | 2016-04-26 19:51:20 -0700 | [diff] [blame] | 424 | |
| 425 | // Prolong the start for the transition when docking a task from recents, unless recents |
| 426 | // ended it already then we don't need to wait. |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 427 | if (transit == TRANSIT_DOCK_TASK_FROM_RECENTS && !mProlongedAnimationsEnded) { |
Jorim Jaggi | 363ab98 | 2016-04-26 19:51:20 -0700 | [diff] [blame] | 428 | for (int i = openingApps.size() - 1; i >= 0; i--) { |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 429 | final AppWindowToken app = openingApps.valueAt(i); |
| 430 | app.startDelayingAnimationStart(); |
Jorim Jaggi | 363ab98 | 2016-04-26 19:51:20 -0700 | [diff] [blame] | 431 | } |
| 432 | } |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 433 | if (mRemoteAnimationController != null) { |
| 434 | mRemoteAnimationController.goodToGo(); |
| 435 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 436 | return redoLayout; |
Jorim Jaggi | 363ab98 | 2016-04-26 19:51:20 -0700 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | /** |
| 440 | * Let the transitions manager know that the somebody wanted to end the prolonged animations. |
| 441 | */ |
| 442 | void notifyProlongedAnimationsEnded() { |
| 443 | mProlongedAnimationsEnded = true; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | void clear() { |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 447 | mNextAppTransitionType = NEXT_TRANSIT_TYPE_NONE; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 448 | mNextAppTransitionPackage = null; |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 449 | mNextAppTransitionAnimationsSpecs.clear(); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 450 | mRemoteAnimationController = null; |
Jorim Jaggi | 6519399 | 2015-11-23 16:49:59 -0800 | [diff] [blame] | 451 | mNextAppTransitionAnimationsSpecsFuture = null; |
| 452 | mDefaultNextAppTransitionAnimationSpec = null; |
| 453 | mAnimationFinishedCallback = null; |
Jorim Jaggi | 363ab98 | 2016-04-26 19:51:20 -0700 | [diff] [blame] | 454 | mProlongedAnimationsEnded = false; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 455 | } |
| 456 | |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 457 | void freeze() { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 458 | final int transit = mNextAppTransition; |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 459 | setAppTransition(TRANSIT_UNSET, 0 /* flags */); |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 460 | clear(); |
| 461 | setReady(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 462 | notifyAppTransitionCancelledLocked(transit); |
Jorim Jaggi | 77ba480 | 2015-02-18 13:57:50 +0100 | [diff] [blame] | 463 | } |
| 464 | |
Jorim Jaggi | 245281c | 2017-06-07 14:33:04 -0700 | [diff] [blame] | 465 | private void setAppTransitionState(int state) { |
| 466 | mAppTransitionState = state; |
| 467 | updateBooster(); |
| 468 | } |
| 469 | |
| 470 | /** |
| 471 | * Updates whether we currently boost wm locked sections and the animation thread. We want to |
| 472 | * boost the priorities to a more important value whenever an app transition is going to happen |
| 473 | * soon or an app transition is running. |
| 474 | */ |
Jorim Jaggi | c8cc229 | 2018-03-15 20:16:15 +0100 | [diff] [blame] | 475 | void updateBooster() { |
| 476 | WindowManagerService.sThreadPriorityBooster.setAppTransitionRunning(needsBoosting()); |
| 477 | } |
| 478 | |
| 479 | private boolean needsBoosting() { |
| 480 | final boolean recentsAnimRunning = mService.getRecentsAnimationController() != null; |
| 481 | return mNextAppTransition != TRANSIT_UNSET |
| 482 | || mAppTransitionState == APP_STATE_READY |
| 483 | || mAppTransitionState == APP_STATE_RUNNING |
| 484 | || recentsAnimRunning; |
Jorim Jaggi | 245281c | 2017-06-07 14:33:04 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Jorim Jaggi | 77ba480 | 2015-02-18 13:57:50 +0100 | [diff] [blame] | 487 | void registerListenerLocked(AppTransitionListener listener) { |
| 488 | mListeners.add(listener); |
| 489 | } |
| 490 | |
Wale Ogunwale | a48eadb | 2015-05-14 17:43:12 -0700 | [diff] [blame] | 491 | public void notifyAppTransitionFinishedLocked(IBinder token) { |
Jorim Jaggi | 77ba480 | 2015-02-18 13:57:50 +0100 | [diff] [blame] | 492 | for (int i = 0; i < mListeners.size(); i++) { |
| 493 | mListeners.get(i).onAppTransitionFinishedLocked(token); |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | private void notifyAppTransitionPendingLocked() { |
| 498 | for (int i = 0; i < mListeners.size(); i++) { |
| 499 | mListeners.get(i).onAppTransitionPendingLocked(); |
| 500 | } |
| 501 | } |
| 502 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 503 | private void notifyAppTransitionCancelledLocked(int transit) { |
Jorim Jaggi | 77ba480 | 2015-02-18 13:57:50 +0100 | [diff] [blame] | 504 | for (int i = 0; i < mListeners.size(); i++) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 505 | mListeners.get(i).onAppTransitionCancelledLocked(transit); |
Jorim Jaggi | 77ba480 | 2015-02-18 13:57:50 +0100 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 509 | private int notifyAppTransitionStartingLocked(int transit, IBinder openToken, |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 510 | IBinder closeToken, long duration, long statusBarAnimationStartTime, |
| 511 | long statusBarAnimationDuration) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 512 | int redoLayout = 0; |
Jorim Jaggi | 77ba480 | 2015-02-18 13:57:50 +0100 | [diff] [blame] | 513 | for (int i = 0; i < mListeners.size(); i++) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 514 | redoLayout |= mListeners.get(i).onAppTransitionStartingLocked(transit, openToken, |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 515 | closeToken, duration, statusBarAnimationStartTime, statusBarAnimationDuration); |
Jorim Jaggi | 77ba480 | 2015-02-18 13:57:50 +0100 | [diff] [blame] | 516 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 517 | return redoLayout; |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 518 | } |
| 519 | |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 520 | private AttributeCache.Entry getCachedAnimations(LayoutParams lp) { |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 521 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg=" |
| 522 | + (lp != null ? lp.packageName : null) |
| 523 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 524 | if (lp != null && lp.windowAnimations != 0) { |
| 525 | // If this is a system resource, don't try to load it from the |
| 526 | // application resources. It is nice to avoid loading application |
| 527 | // resources if we can. |
| 528 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 529 | int resId = lp.windowAnimations; |
| 530 | if ((resId&0xFF000000) == 0x01000000) { |
| 531 | packageName = "android"; |
| 532 | } |
| 533 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
| 534 | + packageName); |
| 535 | return AttributeCache.instance().get(packageName, resId, |
Amith Yamasani | 4befbec | 2013-07-10 16:18:01 -0700 | [diff] [blame] | 536 | com.android.internal.R.styleable.WindowAnimation, mCurrentUserId); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 537 | } |
| 538 | return null; |
| 539 | } |
| 540 | |
| 541 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
| 542 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package=" |
| 543 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 544 | if (packageName != null) { |
| 545 | if ((resId&0xFF000000) == 0x01000000) { |
| 546 | packageName = "android"; |
| 547 | } |
| 548 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
| 549 | + packageName); |
| 550 | return AttributeCache.instance().get(packageName, resId, |
Amith Yamasani | 4befbec | 2013-07-10 16:18:01 -0700 | [diff] [blame] | 551 | com.android.internal.R.styleable.WindowAnimation, mCurrentUserId); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 552 | } |
| 553 | return null; |
| 554 | } |
| 555 | |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 556 | Animation loadAnimationAttr(LayoutParams lp, int animAttr) { |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 557 | int anim = 0; |
| 558 | Context context = mContext; |
| 559 | if (animAttr >= 0) { |
| 560 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 561 | if (ent != null) { |
| 562 | context = ent.context; |
| 563 | anim = ent.array.getResourceId(animAttr, 0); |
| 564 | } |
| 565 | } |
| 566 | if (anim != 0) { |
| 567 | return AnimationUtils.loadAnimation(context, anim); |
| 568 | } |
| 569 | return null; |
| 570 | } |
| 571 | |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 572 | Animation loadAnimationRes(LayoutParams lp, int resId) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 573 | Context context = mContext; |
| 574 | if (resId >= 0) { |
| 575 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 576 | if (ent != null) { |
| 577 | context = ent.context; |
| 578 | } |
| 579 | return AnimationUtils.loadAnimation(context, resId); |
| 580 | } |
| 581 | return null; |
| 582 | } |
| 583 | |
| 584 | private Animation loadAnimationRes(String packageName, int resId) { |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 585 | int anim = 0; |
| 586 | Context context = mContext; |
| 587 | if (resId >= 0) { |
| 588 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 589 | if (ent != null) { |
| 590 | context = ent.context; |
| 591 | anim = resId; |
| 592 | } |
| 593 | } |
| 594 | if (anim != 0) { |
| 595 | return AnimationUtils.loadAnimation(context, anim); |
| 596 | } |
| 597 | return null; |
| 598 | } |
| 599 | |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 600 | /** |
| 601 | * Compute the pivot point for an animation that is scaling from a small |
| 602 | * rect on screen to a larger rect. The pivot point varies depending on |
| 603 | * the distance between the inner and outer edges on both sides. This |
| 604 | * function computes the pivot point for one dimension. |
| 605 | * @param startPos Offset from left/top edge of outer rectangle to |
| 606 | * left/top edge of inner rectangle. |
| 607 | * @param finalScale The scaling factor between the size of the outer |
| 608 | * and inner rectangles. |
| 609 | */ |
| 610 | private static float computePivot(int startPos, float finalScale) { |
Jorim Jaggi | c6c89a8 | 2016-01-28 17:48:21 -0800 | [diff] [blame] | 611 | |
| 612 | /* |
| 613 | Theorem of intercepting lines: |
| 614 | |
| 615 | + + +-----------------------------------------------+ |
| 616 | | | | | |
| 617 | | | | | |
| 618 | | | | | |
| 619 | | | | | |
| 620 | x | y | | | |
| 621 | | | | | |
| 622 | | | | | |
| 623 | | | | | |
| 624 | | | | | |
| 625 | | + | +--------------------+ | |
| 626 | | | | | | |
| 627 | | | | | | |
| 628 | | | | | | |
| 629 | | | | | | |
| 630 | | | | | | |
| 631 | | | | | | |
| 632 | | | | | | |
| 633 | | | | | | |
| 634 | | | | | | |
| 635 | | | | | | |
| 636 | | | | | | |
| 637 | | | | | | |
| 638 | | | | | | |
| 639 | | | | | | |
| 640 | | | | | | |
| 641 | | | | | | |
| 642 | | | | | | |
| 643 | | | +--------------------+ | |
| 644 | | | | |
| 645 | | | | |
| 646 | | | | |
| 647 | | | | |
| 648 | | | | |
| 649 | | | | |
| 650 | | | | |
| 651 | | +-----------------------------------------------+ |
| 652 | | |
| 653 | | |
| 654 | | |
| 655 | | |
| 656 | | |
| 657 | | |
| 658 | | |
| 659 | | |
| 660 | | |
| 661 | + ++ |
| 662 | p ++ |
| 663 | |
| 664 | scale = (x - y) / x |
| 665 | <=> x = -y / (scale - 1) |
| 666 | */ |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 667 | final float denom = finalScale-1; |
| 668 | if (Math.abs(denom) < .0001f) { |
| 669 | return startPos; |
| 670 | } |
| 671 | return -startPos / denom; |
| 672 | } |
| 673 | |
Filip Gruszczynski | 541f92c | 2015-10-25 17:15:06 -0700 | [diff] [blame] | 674 | private Animation createScaleUpAnimationLocked(int transit, boolean enter, |
| 675 | Rect containingFrame) { |
| 676 | Animation a; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 677 | getDefaultNextAppTransitionStartRect(mTmpRect); |
Filip Gruszczynski | 541f92c | 2015-10-25 17:15:06 -0700 | [diff] [blame] | 678 | final int appWidth = containingFrame.width(); |
| 679 | final int appHeight = containingFrame.height(); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 680 | if (enter) { |
| 681 | // Entering app zooms out from the center of the initial rect. |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 682 | float scaleW = mTmpRect.width() / (float) appWidth; |
| 683 | float scaleH = mTmpRect.height() / (float) appHeight; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 684 | Animation scale = new ScaleAnimation(scaleW, 1, scaleH, 1, |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 685 | computePivot(mTmpRect.left, scaleW), |
Winson | 4c3fecd | 2016-07-13 12:29:48 -0700 | [diff] [blame] | 686 | computePivot(mTmpRect.top, scaleH)); |
Craig Mautner | 321bdf5 | 2012-12-18 09:53:24 -0800 | [diff] [blame] | 687 | scale.setInterpolator(mDecelerateInterpolator); |
| 688 | |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 689 | Animation alpha = new AlphaAnimation(0, 1); |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 690 | alpha.setInterpolator(mThumbnailFadeOutInterpolator); |
Craig Mautner | 321bdf5 | 2012-12-18 09:53:24 -0800 | [diff] [blame] | 691 | |
| 692 | AnimationSet set = new AnimationSet(false); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 693 | set.addAnimation(scale); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 694 | set.addAnimation(alpha); |
| 695 | set.setDetachWallpaper(true); |
| 696 | a = set; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 697 | } else if (transit == TRANSIT_WALLPAPER_INTRA_OPEN || |
| 698 | transit == TRANSIT_WALLPAPER_INTRA_CLOSE) { |
Craig Mautner | 321bdf5 | 2012-12-18 09:53:24 -0800 | [diff] [blame] | 699 | // If we are on top of the wallpaper, we need an animation that |
| 700 | // correctly handles the wallpaper staying static behind all of |
| 701 | // the animated elements. To do this, will just have the existing |
| 702 | // element fade out. |
| 703 | a = new AlphaAnimation(1, 0); |
| 704 | a.setDetachWallpaper(true); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 705 | } else { |
Craig Mautner | 321bdf5 | 2012-12-18 09:53:24 -0800 | [diff] [blame] | 706 | // For normal animations, the exiting element just holds in place. |
| 707 | a = new AlphaAnimation(1, 1); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 708 | } |
Craig Mautner | 321bdf5 | 2012-12-18 09:53:24 -0800 | [diff] [blame] | 709 | |
| 710 | // Pick the desired duration. If this is an inter-activity transition, |
| 711 | // it is the standard duration for that. Otherwise we use the longer |
| 712 | // task transition duration. |
| 713 | final long duration; |
| 714 | switch (transit) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 715 | case TRANSIT_ACTIVITY_OPEN: |
| 716 | case TRANSIT_ACTIVITY_CLOSE: |
Craig Mautner | 321bdf5 | 2012-12-18 09:53:24 -0800 | [diff] [blame] | 717 | duration = mConfigShortAnimTime; |
| 718 | break; |
| 719 | default: |
| 720 | duration = DEFAULT_APP_TRANSITION_DURATION; |
| 721 | break; |
| 722 | } |
| 723 | a.setDuration(duration); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 724 | a.setFillAfter(true); |
Craig Mautner | 321bdf5 | 2012-12-18 09:53:24 -0800 | [diff] [blame] | 725 | a.setInterpolator(mDecelerateInterpolator); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 726 | a.initialize(appWidth, appHeight, appWidth, appHeight); |
| 727 | return a; |
| 728 | } |
| 729 | |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 730 | private void getDefaultNextAppTransitionStartRect(Rect rect) { |
| 731 | if (mDefaultNextAppTransitionAnimationSpec == null || |
| 732 | mDefaultNextAppTransitionAnimationSpec.rect == null) { |
Jorim Jaggi | 2550f3f | 2017-03-14 20:15:59 +0100 | [diff] [blame] | 733 | Slog.e(TAG, "Starting rect for app requested, but none available", new Throwable()); |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 734 | rect.setEmpty(); |
| 735 | } else { |
| 736 | rect.set(mDefaultNextAppTransitionAnimationSpec.rect); |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | void getNextAppTransitionStartRect(int taskId, Rect rect) { |
| 741 | AppTransitionAnimationSpec spec = mNextAppTransitionAnimationsSpecs.get(taskId); |
Filip Gruszczynski | 7248c56 | 2015-11-09 13:05:40 -0800 | [diff] [blame] | 742 | if (spec == null) { |
| 743 | spec = mDefaultNextAppTransitionAnimationSpec; |
| 744 | } |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 745 | if (spec == null || spec.rect == null) { |
Jorim Jaggi | 2550f3f | 2017-03-14 20:15:59 +0100 | [diff] [blame] | 746 | Slog.e(TAG, "Starting rect for task: " + taskId + " requested, but not available", |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 747 | new Throwable()); |
| 748 | rect.setEmpty(); |
| 749 | } else { |
| 750 | rect.set(spec.rect); |
| 751 | } |
| 752 | } |
| 753 | |
Filip Gruszczynski | 7248c56 | 2015-11-09 13:05:40 -0800 | [diff] [blame] | 754 | private void putDefaultNextAppTransitionCoordinates(int left, int top, int width, int height, |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 755 | GraphicBuffer buffer) { |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 756 | mDefaultNextAppTransitionAnimationSpec = new AppTransitionAnimationSpec(-1 /* taskId */, |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 757 | buffer, new Rect(left, top, left + width, top + height)); |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 758 | } |
| 759 | |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 760 | /** |
| 761 | * @return the duration of the last clip reveal animation |
| 762 | */ |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 763 | long getLastClipRevealTransitionDuration() { |
| 764 | return mLastClipRevealTransitionDuration; |
| 765 | } |
| 766 | |
| 767 | /** |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 768 | * @return the maximum distance the app surface is traveling of the last clip reveal animation |
| 769 | */ |
| 770 | int getLastClipRevealMaxTranslation() { |
| 771 | return mLastClipRevealMaxTranslation; |
| 772 | } |
| 773 | |
| 774 | /** |
| 775 | * @return true if in the last app transition had a clip reveal animation, false otherwise |
| 776 | */ |
| 777 | boolean hadClipRevealAnimation() { |
| 778 | return mLastHadClipReveal; |
| 779 | } |
| 780 | |
| 781 | /** |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 782 | * Calculates the duration for the clip reveal animation. If the clip is "cut off", meaning that |
| 783 | * the start rect is outside of the target rect, and there is a lot of movement going on. |
| 784 | * |
| 785 | * @param cutOff whether the start rect was not fully contained by the end rect |
| 786 | * @param translationX the total translation the surface moves in x direction |
| 787 | * @param translationY the total translation the surfaces moves in y direction |
| 788 | * @param displayFrame our display frame |
| 789 | * |
| 790 | * @return the duration of the clip reveal animation, in milliseconds |
| 791 | */ |
| 792 | private long calculateClipRevealTransitionDuration(boolean cutOff, float translationX, |
| 793 | float translationY, Rect displayFrame) { |
| 794 | if (!cutOff) { |
| 795 | return DEFAULT_APP_TRANSITION_DURATION; |
| 796 | } |
| 797 | final float fraction = Math.max(Math.abs(translationX) / displayFrame.width(), |
| 798 | Math.abs(translationY) / displayFrame.height()); |
| 799 | return (long) (DEFAULT_APP_TRANSITION_DURATION + fraction * |
| 800 | (MAX_CLIP_REVEAL_TRANSITION_DURATION - DEFAULT_APP_TRANSITION_DURATION)); |
| 801 | } |
| 802 | |
| 803 | private Animation createClipRevealAnimationLocked(int transit, boolean enter, Rect appFrame, |
| 804 | Rect displayFrame) { |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 805 | final Animation anim; |
| 806 | if (enter) { |
Craig Mautner | 80b1f64 | 2015-04-22 10:59:09 -0700 | [diff] [blame] | 807 | final int appWidth = appFrame.width(); |
| 808 | final int appHeight = appFrame.height(); |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 809 | |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 810 | // mTmpRect will contain an area around the launcher icon that was pressed. We will |
Filip Gruszczynski | 8286136 | 2015-10-16 14:21:09 -0700 | [diff] [blame] | 811 | // clip reveal from that area in the final area of the app. |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 812 | getDefaultNextAppTransitionStartRect(mTmpRect); |
Craig Mautner | 80b1f64 | 2015-04-22 10:59:09 -0700 | [diff] [blame] | 813 | |
Jorim Jaggi | 1d763a6 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 814 | float t = 0f; |
| 815 | if (appHeight > 0) { |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 816 | t = (float) mTmpRect.top / displayFrame.height(); |
Jorim Jaggi | 1d763a6 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 817 | } |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 818 | int translationY = mClipRevealTranslationY + (int)(displayFrame.height() / 7f * t); |
| 819 | int translationX = 0; |
| 820 | int translationYCorrection = translationY; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 821 | int centerX = mTmpRect.centerX(); |
| 822 | int centerY = mTmpRect.centerY(); |
| 823 | int halfWidth = mTmpRect.width() / 2; |
| 824 | int halfHeight = mTmpRect.height() / 2; |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 825 | int clipStartX = centerX - halfWidth - appFrame.left; |
| 826 | int clipStartY = centerY - halfHeight - appFrame.top; |
| 827 | boolean cutOff = false; |
| 828 | |
| 829 | // If the starting rectangle is fully or partially outside of the target rectangle, we |
| 830 | // need to start the clipping at the edge and then achieve the rest with translation |
| 831 | // and extending the clip rect from that edge. |
| 832 | if (appFrame.top > centerY - halfHeight) { |
| 833 | translationY = (centerY - halfHeight) - appFrame.top; |
| 834 | translationYCorrection = 0; |
| 835 | clipStartY = 0; |
| 836 | cutOff = true; |
| 837 | } |
| 838 | if (appFrame.left > centerX - halfWidth) { |
| 839 | translationX = (centerX - halfWidth) - appFrame.left; |
| 840 | clipStartX = 0; |
| 841 | cutOff = true; |
| 842 | } |
| 843 | if (appFrame.right < centerX + halfWidth) { |
| 844 | translationX = (centerX + halfWidth) - appFrame.right; |
| 845 | clipStartX = appWidth - mTmpRect.width(); |
| 846 | cutOff = true; |
| 847 | } |
| 848 | final long duration = calculateClipRevealTransitionDuration(cutOff, translationX, |
| 849 | translationY, displayFrame); |
Jorim Jaggi | 1d763a6 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 850 | |
| 851 | // Clip third of the from size of launch icon, expand to full width/height |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 852 | Animation clipAnimLR = new ClipRectLRAnimation( |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 853 | clipStartX, clipStartX + mTmpRect.width(), 0, appWidth); |
Jorim Jaggi | 1d763a6 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 854 | clipAnimLR.setInterpolator(mClipHorizontalInterpolator); |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 855 | clipAnimLR.setDuration((long) (duration / 2.5f)); |
Filip Gruszczynski | 8286136 | 2015-10-16 14:21:09 -0700 | [diff] [blame] | 856 | |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 857 | TranslateAnimation translate = new TranslateAnimation(translationX, 0, translationY, 0); |
| 858 | translate.setInterpolator(cutOff ? TOUCH_RESPONSE_INTERPOLATOR |
| 859 | : mLinearOutSlowInInterpolator); |
| 860 | translate.setDuration(duration); |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 861 | |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 862 | Animation clipAnimTB = new ClipRectTBAnimation( |
| 863 | clipStartY, clipStartY + mTmpRect.height(), |
| 864 | 0, appHeight, |
| 865 | translationYCorrection, 0, |
| 866 | mLinearOutSlowInInterpolator); |
| 867 | clipAnimTB.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR); |
| 868 | clipAnimTB.setDuration(duration); |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 869 | |
| 870 | // Quick fade-in from icon to app window |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 871 | final long alphaDuration = duration / 4; |
Jorim Jaggi | 1d763a6 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 872 | AlphaAnimation alpha = new AlphaAnimation(0.5f, 1); |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 873 | alpha.setDuration(alphaDuration); |
Jorim Jaggi | 1d763a6 | 2015-06-02 17:07:39 -0700 | [diff] [blame] | 874 | alpha.setInterpolator(mLinearOutSlowInInterpolator); |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 875 | |
| 876 | AnimationSet set = new AnimationSet(false); |
| 877 | set.addAnimation(clipAnimLR); |
| 878 | set.addAnimation(clipAnimTB); |
Filip Gruszczynski | 8286136 | 2015-10-16 14:21:09 -0700 | [diff] [blame] | 879 | set.addAnimation(translate); |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 880 | set.addAnimation(alpha); |
Filip Gruszczynski | 9e2cf5b | 2015-07-31 12:20:40 -0700 | [diff] [blame] | 881 | set.setZAdjustment(Animation.ZORDER_TOP); |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 882 | set.initialize(appWidth, appHeight, appWidth, appHeight); |
| 883 | anim = set; |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 884 | mLastHadClipReveal = true; |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 885 | mLastClipRevealTransitionDuration = duration; |
Jorim Jaggi | f97ed92 | 2016-02-18 18:57:07 -0800 | [diff] [blame] | 886 | |
| 887 | // If the start rect was full inside the target rect (cutOff == false), we don't need |
| 888 | // to store the translation, because it's only used if cutOff == true. |
| 889 | mLastClipRevealMaxTranslation = cutOff |
| 890 | ? Math.max(Math.abs(translationY), Math.abs(translationX)) : 0; |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 891 | } else { |
| 892 | final long duration; |
| 893 | switch (transit) { |
| 894 | case TRANSIT_ACTIVITY_OPEN: |
| 895 | case TRANSIT_ACTIVITY_CLOSE: |
| 896 | duration = mConfigShortAnimTime; |
| 897 | break; |
| 898 | default: |
| 899 | duration = DEFAULT_APP_TRANSITION_DURATION; |
| 900 | break; |
| 901 | } |
| 902 | if (transit == TRANSIT_WALLPAPER_INTRA_OPEN || |
| 903 | transit == TRANSIT_WALLPAPER_INTRA_CLOSE) { |
| 904 | // If we are on top of the wallpaper, we need an animation that |
| 905 | // correctly handles the wallpaper staying static behind all of |
| 906 | // the animated elements. To do this, will just have the existing |
| 907 | // element fade out. |
| 908 | anim = new AlphaAnimation(1, 0); |
| 909 | anim.setDetachWallpaper(true); |
| 910 | } else { |
| 911 | // For normal animations, the exiting element just holds in place. |
| 912 | anim = new AlphaAnimation(1, 1); |
| 913 | } |
| 914 | anim.setInterpolator(mDecelerateInterpolator); |
| 915 | anim.setDuration(duration); |
| 916 | anim.setFillAfter(true); |
| 917 | } |
| 918 | return anim; |
| 919 | } |
| 920 | |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 921 | /** |
| 922 | * Prepares the specified animation with a standard duration, interpolator, etc. |
| 923 | */ |
Winson Chung | 5393dff | 2014-05-08 14:25:43 -0700 | [diff] [blame] | 924 | Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight, |
Jorim Jaggi | 787e9dd | 2016-03-15 10:52:40 +0100 | [diff] [blame] | 925 | long duration, Interpolator interpolator) { |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 926 | if (duration > 0) { |
| 927 | a.setDuration(duration); |
| 928 | } |
Winson Chung | 5393dff | 2014-05-08 14:25:43 -0700 | [diff] [blame] | 929 | a.setFillAfter(true); |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 930 | if (interpolator != null) { |
| 931 | a.setInterpolator(interpolator); |
| 932 | } |
Winson Chung | 5393dff | 2014-05-08 14:25:43 -0700 | [diff] [blame] | 933 | a.initialize(appWidth, appHeight, appWidth, appHeight); |
| 934 | return a; |
| 935 | } |
| 936 | |
| 937 | /** |
| 938 | * Prepares the specified animation with a standard duration, interpolator, etc. |
| 939 | */ |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 940 | Animation prepareThumbnailAnimation(Animation a, int appWidth, int appHeight, int transit) { |
Craig Mautner | 321bdf5 | 2012-12-18 09:53:24 -0800 | [diff] [blame] | 941 | // Pick the desired duration. If this is an inter-activity transition, |
| 942 | // it is the standard duration for that. Otherwise we use the longer |
| 943 | // task transition duration. |
Winson Chung | 5393dff | 2014-05-08 14:25:43 -0700 | [diff] [blame] | 944 | final int duration; |
Craig Mautner | 321bdf5 | 2012-12-18 09:53:24 -0800 | [diff] [blame] | 945 | switch (transit) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 946 | case TRANSIT_ACTIVITY_OPEN: |
| 947 | case TRANSIT_ACTIVITY_CLOSE: |
Craig Mautner | 321bdf5 | 2012-12-18 09:53:24 -0800 | [diff] [blame] | 948 | duration = mConfigShortAnimTime; |
| 949 | break; |
| 950 | default: |
| 951 | duration = DEFAULT_APP_TRANSITION_DURATION; |
| 952 | break; |
| 953 | } |
Winson Chung | 5393dff | 2014-05-08 14:25:43 -0700 | [diff] [blame] | 954 | return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, duration, |
| 955 | mDecelerateInterpolator); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 956 | } |
| 957 | |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 958 | /** |
| 959 | * Return the current thumbnail transition state. |
| 960 | */ |
| 961 | int getThumbnailTransitionState(boolean enter) { |
| 962 | if (enter) { |
| 963 | if (mNextAppTransitionScaleUp) { |
| 964 | return THUMBNAIL_TRANSITION_ENTER_SCALE_UP; |
| 965 | } else { |
| 966 | return THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN; |
| 967 | } |
| 968 | } else { |
| 969 | if (mNextAppTransitionScaleUp) { |
| 970 | return THUMBNAIL_TRANSITION_EXIT_SCALE_UP; |
| 971 | } else { |
| 972 | return THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN; |
| 973 | } |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | /** |
Tony Mak | 64b8d56 | 2017-12-28 17:44:02 +0000 | [diff] [blame] | 978 | * Creates an overlay with a background color and a thumbnail for the cross profile apps |
| 979 | * animation. |
| 980 | */ |
| 981 | GraphicBuffer createCrossProfileAppsThumbnail( |
| 982 | @DrawableRes int thumbnailDrawableRes, Rect frame) { |
| 983 | final int width = frame.width(); |
| 984 | final int height = frame.height(); |
| 985 | |
John Reck | 519ad48 | 2018-02-12 17:08:48 -0800 | [diff] [blame] | 986 | final Picture picture = new Picture(); |
| 987 | final Canvas canvas = picture.beginRecording(width, height); |
Tony Mak | 64b8d56 | 2017-12-28 17:44:02 +0000 | [diff] [blame] | 988 | canvas.drawColor(Color.argb(0.6f, 0, 0, 0)); |
| 989 | final int thumbnailSize = mService.mContext.getResources().getDimensionPixelSize( |
| 990 | com.android.internal.R.dimen.cross_profile_apps_thumbnail_size); |
| 991 | final Drawable drawable = mService.mContext.getDrawable(thumbnailDrawableRes); |
| 992 | drawable.setBounds( |
| 993 | (width - thumbnailSize) / 2, |
| 994 | (height - thumbnailSize) / 2, |
| 995 | (width + thumbnailSize) / 2, |
| 996 | (height + thumbnailSize) / 2); |
| 997 | drawable.draw(canvas); |
John Reck | 519ad48 | 2018-02-12 17:08:48 -0800 | [diff] [blame] | 998 | picture.endRecording(); |
Tony Mak | 64b8d56 | 2017-12-28 17:44:02 +0000 | [diff] [blame] | 999 | |
John Reck | 519ad48 | 2018-02-12 17:08:48 -0800 | [diff] [blame] | 1000 | return Bitmap.createBitmap(picture).createGraphicBufferHandle(); |
Tony Mak | 64b8d56 | 2017-12-28 17:44:02 +0000 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | Animation createCrossProfileAppsThumbnailAnimationLocked(Rect appRect) { |
| 1004 | final Animation animation = loadAnimationRes( |
| 1005 | "android", com.android.internal.R.anim.cross_profile_apps_thumbnail_enter); |
| 1006 | return prepareThumbnailAnimationWithDuration(animation, appRect.width(), |
| 1007 | appRect.height(), 0, null); |
| 1008 | } |
| 1009 | |
| 1010 | /** |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1011 | * This animation runs for the thumbnail that gets cross faded with the enter/exit activity |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 1012 | * when a thumbnail is specified with the pending animation override. |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1013 | */ |
Jorim Jaggi | de63d44 | 2016-03-14 14:56:56 +0100 | [diff] [blame] | 1014 | Animation createThumbnailAspectScaleAnimationLocked(Rect appRect, @Nullable Rect contentInsets, |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 1015 | GraphicBuffer thumbnailHeader, final int taskId, int uiMode, int orientation) { |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1016 | Animation a; |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 1017 | final int thumbWidthI = thumbnailHeader.getWidth(); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1018 | final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1; |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 1019 | final int thumbHeightI = thumbnailHeader.getHeight(); |
Filip Gruszczynski | dfb25d3 | 2015-08-14 11:06:18 -0700 | [diff] [blame] | 1020 | final int appWidth = appRect.width(); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1021 | |
Filip Gruszczynski | dfb25d3 | 2015-08-14 11:06:18 -0700 | [diff] [blame] | 1022 | float scaleW = appWidth / thumbWidth; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 1023 | getNextAppTransitionStartRect(taskId, mTmpRect); |
Jorim Jaggi | 0907200 | 2016-03-25 16:48:42 -0700 | [diff] [blame] | 1024 | final float fromX; |
Manu Cornet | 57b6149 | 2017-01-24 18:19:05 +0900 | [diff] [blame] | 1025 | float fromY; |
Jorim Jaggi | 0907200 | 2016-03-25 16:48:42 -0700 | [diff] [blame] | 1026 | final float toX; |
Manu Cornet | 57b6149 | 2017-01-24 18:19:05 +0900 | [diff] [blame] | 1027 | float toY; |
Jorim Jaggi | 0907200 | 2016-03-25 16:48:42 -0700 | [diff] [blame] | 1028 | final float pivotX; |
| 1029 | final float pivotY; |
Manu Cornet | d737680 | 2017-01-13 13:44:07 -0800 | [diff] [blame] | 1030 | if (shouldScaleDownThumbnailTransition(uiMode, orientation)) { |
Jorim Jaggi | 0907200 | 2016-03-25 16:48:42 -0700 | [diff] [blame] | 1031 | fromX = mTmpRect.left; |
| 1032 | fromY = mTmpRect.top; |
| 1033 | |
| 1034 | // For the curved translate animation to work, the pivot points needs to be at the |
| 1035 | // same absolute position as the one from the real surface. |
| 1036 | toX = mTmpRect.width() / 2 * (scaleW - 1f) + appRect.left; |
| 1037 | toY = appRect.height() / 2 * (1 - 1 / scaleW) + appRect.top; |
| 1038 | pivotX = mTmpRect.width() / 2; |
| 1039 | pivotY = appRect.height() / 2 / scaleW; |
Manu Cornet | 57b6149 | 2017-01-24 18:19:05 +0900 | [diff] [blame] | 1040 | if (mGridLayoutRecentsEnabled) { |
| 1041 | // In the grid layout, the header is displayed above the thumbnail instead of |
| 1042 | // overlapping it. |
| 1043 | fromY -= thumbHeightI; |
| 1044 | toY -= thumbHeightI * scaleW; |
| 1045 | } |
Jorim Jaggi | 0907200 | 2016-03-25 16:48:42 -0700 | [diff] [blame] | 1046 | } else { |
| 1047 | pivotX = 0; |
| 1048 | pivotY = 0; |
| 1049 | fromX = mTmpRect.left; |
| 1050 | fromY = mTmpRect.top; |
| 1051 | toX = appRect.left; |
| 1052 | toY = appRect.top; |
| 1053 | } |
Jorim Jaggi | 787e9dd | 2016-03-15 10:52:40 +0100 | [diff] [blame] | 1054 | final long duration = getAspectScaleDuration(); |
| 1055 | final Interpolator interpolator = getAspectScaleInterpolator(); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1056 | if (mNextAppTransitionScaleUp) { |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1057 | // Animation up from the thumbnail to the full screen |
Jorim Jaggi | 8448f33 | 2016-03-14 17:50:37 +0100 | [diff] [blame] | 1058 | Animation scale = new ScaleAnimation(1f, scaleW, 1f, scaleW, pivotX, pivotY); |
Jorim Jaggi | 787e9dd | 2016-03-15 10:52:40 +0100 | [diff] [blame] | 1059 | scale.setInterpolator(interpolator); |
| 1060 | scale.setDuration(duration); |
Jorim Jaggi | c6c89a8 | 2016-01-28 17:48:21 -0800 | [diff] [blame] | 1061 | Animation alpha = new AlphaAnimation(1f, 0f); |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 1062 | alpha.setInterpolator(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS |
| 1063 | ? THUMBNAIL_DOCK_INTERPOLATOR : mThumbnailFadeOutInterpolator); |
| 1064 | alpha.setDuration(mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS |
| 1065 | ? duration / 2 |
| 1066 | : duration); |
Jorim Jaggi | 787e9dd | 2016-03-15 10:52:40 +0100 | [diff] [blame] | 1067 | Animation translate = createCurvedMotion(fromX, toX, fromY, toY); |
| 1068 | translate.setInterpolator(interpolator); |
| 1069 | translate.setDuration(duration); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1070 | |
Jorim Jaggi | de63d44 | 2016-03-14 14:56:56 +0100 | [diff] [blame] | 1071 | mTmpFromClipRect.set(0, 0, thumbWidthI, thumbHeightI); |
| 1072 | mTmpToClipRect.set(appRect); |
| 1073 | |
| 1074 | // Containing frame is in screen space, but we need the clip rect in the |
| 1075 | // app space. |
| 1076 | mTmpToClipRect.offsetTo(0, 0); |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 1077 | mTmpToClipRect.right = (int) (mTmpToClipRect.right / scaleW); |
| 1078 | mTmpToClipRect.bottom = (int) (mTmpToClipRect.bottom / scaleW); |
Jorim Jaggi | de63d44 | 2016-03-14 14:56:56 +0100 | [diff] [blame] | 1079 | |
| 1080 | if (contentInsets != null) { |
Jorim Jaggi | 8448f33 | 2016-03-14 17:50:37 +0100 | [diff] [blame] | 1081 | mTmpToClipRect.inset((int) (-contentInsets.left * scaleW), |
| 1082 | (int) (-contentInsets.top * scaleW), |
| 1083 | (int) (-contentInsets.right * scaleW), |
| 1084 | (int) (-contentInsets.bottom * scaleW)); |
Jorim Jaggi | de63d44 | 2016-03-14 14:56:56 +0100 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | Animation clipAnim = new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect); |
Jorim Jaggi | 787e9dd | 2016-03-15 10:52:40 +0100 | [diff] [blame] | 1088 | clipAnim.setInterpolator(interpolator); |
| 1089 | clipAnim.setDuration(duration); |
Jorim Jaggi | de63d44 | 2016-03-14 14:56:56 +0100 | [diff] [blame] | 1090 | |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1091 | // This AnimationSet uses the Interpolators assigned above. |
| 1092 | AnimationSet set = new AnimationSet(false); |
| 1093 | set.addAnimation(scale); |
Manu Cornet | 57b6149 | 2017-01-24 18:19:05 +0900 | [diff] [blame] | 1094 | if (!mGridLayoutRecentsEnabled) { |
| 1095 | // In the grid layout, the header should be shown for the whole animation. |
| 1096 | set.addAnimation(alpha); |
| 1097 | } |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1098 | set.addAnimation(translate); |
Jorim Jaggi | de63d44 | 2016-03-14 14:56:56 +0100 | [diff] [blame] | 1099 | set.addAnimation(clipAnim); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1100 | a = set; |
| 1101 | } else { |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1102 | // Animation down from the full screen to the thumbnail |
Jorim Jaggi | 8448f33 | 2016-03-14 17:50:37 +0100 | [diff] [blame] | 1103 | Animation scale = new ScaleAnimation(scaleW, 1f, scaleW, 1f, pivotX, pivotY); |
Jorim Jaggi | 787e9dd | 2016-03-15 10:52:40 +0100 | [diff] [blame] | 1104 | scale.setInterpolator(interpolator); |
| 1105 | scale.setDuration(duration); |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1106 | Animation alpha = new AlphaAnimation(0f, 1f); |
| 1107 | alpha.setInterpolator(mThumbnailFadeInInterpolator); |
Jorim Jaggi | 787e9dd | 2016-03-15 10:52:40 +0100 | [diff] [blame] | 1108 | alpha.setDuration(duration); |
| 1109 | Animation translate = createCurvedMotion(toX, fromX, toY, fromY); |
| 1110 | translate.setInterpolator(interpolator); |
| 1111 | translate.setDuration(duration); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1112 | |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1113 | // This AnimationSet uses the Interpolators assigned above. |
| 1114 | AnimationSet set = new AnimationSet(false); |
| 1115 | set.addAnimation(scale); |
Manu Cornet | 57b6149 | 2017-01-24 18:19:05 +0900 | [diff] [blame] | 1116 | if (!mGridLayoutRecentsEnabled) { |
| 1117 | // In the grid layout, the header should be shown for the whole animation. |
| 1118 | set.addAnimation(alpha); |
| 1119 | } |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1120 | set.addAnimation(translate); |
| 1121 | a = set; |
| 1122 | |
| 1123 | } |
Filip Gruszczynski | dfb25d3 | 2015-08-14 11:06:18 -0700 | [diff] [blame] | 1124 | return prepareThumbnailAnimationWithDuration(a, appWidth, appRect.height(), 0, |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 1125 | null); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
Jorim Jaggi | 787e9dd | 2016-03-15 10:52:40 +0100 | [diff] [blame] | 1128 | private Animation createCurvedMotion(float fromX, float toX, float fromY, float toY) { |
| 1129 | |
| 1130 | // Almost no x-change - use linear animation |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 1131 | if (Math.abs(toX - fromX) < 1f || mNextAppTransition != TRANSIT_DOCK_TASK_FROM_RECENTS) { |
Jorim Jaggi | 787e9dd | 2016-03-15 10:52:40 +0100 | [diff] [blame] | 1132 | return new TranslateAnimation(fromX, toX, fromY, toY); |
| 1133 | } else { |
| 1134 | final Path path = createCurvedPath(fromX, toX, fromY, toY); |
| 1135 | return new CurvedTranslateAnimation(path); |
| 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | private Path createCurvedPath(float fromX, float toX, float fromY, float toY) { |
| 1140 | final Path path = new Path(); |
| 1141 | path.moveTo(fromX, fromY); |
Jorim Jaggi | 1f458fb | 2016-03-25 17:36:37 -0700 | [diff] [blame] | 1142 | |
| 1143 | if (fromY > toY) { |
| 1144 | // If the object needs to go up, move it in horizontal direction first, then vertical. |
| 1145 | path.cubicTo(fromX, fromY, toX, 0.9f * fromY + 0.1f * toY, toX, toY); |
| 1146 | } else { |
| 1147 | // If the object needs to go down, move it in vertical direction first, then horizontal. |
| 1148 | path.cubicTo(fromX, fromY, fromX, 0.1f * fromY + 0.9f * toY, toX, toY); |
| 1149 | } |
Jorim Jaggi | 787e9dd | 2016-03-15 10:52:40 +0100 | [diff] [blame] | 1150 | return path; |
| 1151 | } |
| 1152 | |
| 1153 | private long getAspectScaleDuration() { |
| 1154 | if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) { |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 1155 | return (long) (THUMBNAIL_APP_TRANSITION_DURATION * 1.35f); |
Jorim Jaggi | 787e9dd | 2016-03-15 10:52:40 +0100 | [diff] [blame] | 1156 | } else { |
| 1157 | return THUMBNAIL_APP_TRANSITION_DURATION; |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | private Interpolator getAspectScaleInterpolator() { |
| 1162 | if (mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS) { |
| 1163 | return mFastOutSlowInInterpolator; |
| 1164 | } else { |
| 1165 | return TOUCH_RESPONSE_INTERPOLATOR; |
| 1166 | } |
| 1167 | } |
| 1168 | |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1169 | /** |
| 1170 | * This alternate animation is created when we are doing a thumbnail transition, for the |
| 1171 | * activity that is leaving, and the activity that is entering. |
| 1172 | */ |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1173 | Animation createAspectScaledThumbnailEnterExitAnimationLocked(int thumbTransitState, |
Winson | b202476 | 2016-04-05 17:32:30 -0700 | [diff] [blame] | 1174 | int uiMode, int orientation, int transit, Rect containingFrame, Rect contentInsets, |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 1175 | @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean freeform, |
| 1176 | int taskId) { |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1177 | Animation a; |
Filip Gruszczynski | 541f92c | 2015-10-25 17:15:06 -0700 | [diff] [blame] | 1178 | final int appWidth = containingFrame.width(); |
| 1179 | final int appHeight = containingFrame.height(); |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 1180 | getDefaultNextAppTransitionStartRect(mTmpRect); |
| 1181 | final int thumbWidthI = mTmpRect.width(); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1182 | final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 1183 | final int thumbHeightI = mTmpRect.height(); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1184 | final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1; |
Winson | cbb625b | 2016-07-06 15:24:15 -0700 | [diff] [blame] | 1185 | final int thumbStartX = mTmpRect.left - containingFrame.left - contentInsets.left; |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 1186 | final int thumbStartY = mTmpRect.top - containingFrame.top; |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1187 | |
| 1188 | switch (thumbTransitState) { |
Jorim Jaggi | 8448f33 | 2016-03-14 17:50:37 +0100 | [diff] [blame] | 1189 | case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: |
| 1190 | case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: { |
| 1191 | final boolean scaleUp = thumbTransitState == THUMBNAIL_TRANSITION_ENTER_SCALE_UP; |
| 1192 | if (freeform && scaleUp) { |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 1193 | a = createAspectScaledThumbnailEnterFreeformAnimationLocked( |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 1194 | containingFrame, surfaceInsets, taskId); |
Jorim Jaggi | 8448f33 | 2016-03-14 17:50:37 +0100 | [diff] [blame] | 1195 | } else if (freeform) { |
| 1196 | a = createAspectScaledThumbnailExitFreeformAnimationLocked( |
| 1197 | containingFrame, surfaceInsets, taskId); |
Winson Chung | 2820c45 | 2014-04-15 15:34:44 -0700 | [diff] [blame] | 1198 | } else { |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 1199 | AnimationSet set = new AnimationSet(true); |
| 1200 | |
| 1201 | // In portrait, we scale to fit the width |
Filip Gruszczynski | efd3d1b | 2015-10-14 13:57:55 -0700 | [diff] [blame] | 1202 | mTmpFromClipRect.set(containingFrame); |
Filip Gruszczynski | efd3d1b | 2015-10-14 13:57:55 -0700 | [diff] [blame] | 1203 | mTmpToClipRect.set(containingFrame); |
Jorim Jaggi | c6c89a8 | 2016-01-28 17:48:21 -0800 | [diff] [blame] | 1204 | |
| 1205 | // Containing frame is in screen space, but we need the clip rect in the |
| 1206 | // app space. |
| 1207 | mTmpFromClipRect.offsetTo(0, 0); |
| 1208 | mTmpToClipRect.offsetTo(0, 0); |
| 1209 | |
| 1210 | // Exclude insets region from the source clip. |
| 1211 | mTmpFromClipRect.inset(contentInsets); |
Filip Gruszczynski | 71b0d2d | 2015-08-12 18:52:26 -0700 | [diff] [blame] | 1212 | mNextAppTransitionInsets.set(contentInsets); |
| 1213 | |
Manu Cornet | d737680 | 2017-01-13 13:44:07 -0800 | [diff] [blame] | 1214 | if (shouldScaleDownThumbnailTransition(uiMode, orientation)) { |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 1215 | // We scale the width and clip to the top/left square |
| 1216 | float scale = thumbWidth / |
| 1217 | (appWidth - contentInsets.left - contentInsets.right); |
Manu Cornet | b68b765 | 2017-01-23 19:37:53 +0900 | [diff] [blame] | 1218 | if (!mGridLayoutRecentsEnabled) { |
| 1219 | int unscaledThumbHeight = (int) (thumbHeight / scale); |
| 1220 | mTmpFromClipRect.bottom = mTmpFromClipRect.top + unscaledThumbHeight; |
| 1221 | } |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 1222 | |
| 1223 | mNextAppTransitionInsets.set(contentInsets); |
| 1224 | |
Jorim Jaggi | 8448f33 | 2016-03-14 17:50:37 +0100 | [diff] [blame] | 1225 | Animation scaleAnim = new ScaleAnimation( |
| 1226 | scaleUp ? scale : 1, scaleUp ? 1 : scale, |
| 1227 | scaleUp ? scale : 1, scaleUp ? 1 : scale, |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 1228 | containingFrame.width() / 2f, |
| 1229 | containingFrame.height() / 2f + contentInsets.top); |
Jorim Jaggi | 8448f33 | 2016-03-14 17:50:37 +0100 | [diff] [blame] | 1230 | final float targetX = (mTmpRect.left - containingFrame.left); |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 1231 | final float x = containingFrame.width() / 2f |
| 1232 | - containingFrame.width() / 2f * scale; |
Jorim Jaggi | 8448f33 | 2016-03-14 17:50:37 +0100 | [diff] [blame] | 1233 | final float targetY = (mTmpRect.top - containingFrame.top); |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 1234 | float y = containingFrame.height() / 2f |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 1235 | - containingFrame.height() / 2f * scale; |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 1236 | |
| 1237 | // During transition may require clipping offset from any top stable insets |
| 1238 | // such as the statusbar height when statusbar is hidden |
| 1239 | if (mLowRamRecentsEnabled && contentInsets.top == 0 && scaleUp) { |
| 1240 | mTmpFromClipRect.top += stableInsets.top; |
| 1241 | y += stableInsets.top; |
| 1242 | } |
Jorim Jaggi | 8448f33 | 2016-03-14 17:50:37 +0100 | [diff] [blame] | 1243 | final float startX = targetX - x; |
| 1244 | final float startY = targetY - y; |
| 1245 | Animation clipAnim = scaleUp |
| 1246 | ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect) |
| 1247 | : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect); |
| 1248 | Animation translateAnim = scaleUp |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 1249 | ? createCurvedMotion(startX, 0, startY - contentInsets.top, 0) |
| 1250 | : createCurvedMotion(0, startX, 0, startY - contentInsets.top); |
| 1251 | |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 1252 | set.addAnimation(clipAnim); |
| 1253 | set.addAnimation(scaleAnim); |
| 1254 | set.addAnimation(translateAnim); |
| 1255 | |
| 1256 | } else { |
| 1257 | // In landscape, we don't scale at all and only crop |
| 1258 | mTmpFromClipRect.bottom = mTmpFromClipRect.top + thumbHeightI; |
| 1259 | mTmpFromClipRect.right = mTmpFromClipRect.left + thumbWidthI; |
| 1260 | |
Jorim Jaggi | 8448f33 | 2016-03-14 17:50:37 +0100 | [diff] [blame] | 1261 | Animation clipAnim = scaleUp |
| 1262 | ? new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect) |
| 1263 | : new ClipRectAnimation(mTmpToClipRect, mTmpFromClipRect); |
| 1264 | Animation translateAnim = scaleUp |
Jorim Jaggi | 787e9dd | 2016-03-15 10:52:40 +0100 | [diff] [blame] | 1265 | ? createCurvedMotion(thumbStartX, 0, |
| 1266 | thumbStartY - contentInsets.top, 0) |
| 1267 | : createCurvedMotion(0, thumbStartX, 0, |
| 1268 | thumbStartY - contentInsets.top); |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 1269 | |
| 1270 | set.addAnimation(clipAnim); |
| 1271 | set.addAnimation(translateAnim); |
| 1272 | } |
Filip Gruszczynski | 71b0d2d | 2015-08-12 18:52:26 -0700 | [diff] [blame] | 1273 | a = set; |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 1274 | a.setZAdjustment(Animation.ZORDER_TOP); |
Winson Chung | 2820c45 | 2014-04-15 15:34:44 -0700 | [diff] [blame] | 1275 | } |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1276 | break; |
| 1277 | } |
| 1278 | case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: { |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1279 | // Previous app window during the scale up |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1280 | if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) { |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1281 | // Fade out the source activity if we are animating to a wallpaper |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1282 | // activity. |
| 1283 | a = new AlphaAnimation(1, 0); |
| 1284 | } else { |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1285 | a = new AlphaAnimation(1, 1); |
| 1286 | } |
| 1287 | break; |
| 1288 | } |
| 1289 | case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: { |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1290 | // Target app window during the scale down |
| 1291 | if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) { |
| 1292 | // Fade in the destination activity if we are animating from a wallpaper |
| 1293 | // activity. |
| 1294 | a = new AlphaAnimation(0, 1); |
| 1295 | } else { |
| 1296 | a = new AlphaAnimation(1, 1); |
| 1297 | } |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1298 | break; |
| 1299 | } |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1300 | default: |
| 1301 | throw new RuntimeException("Invalid thumbnail transition state"); |
| 1302 | } |
| 1303 | |
Jorim Jaggi | 787e9dd | 2016-03-15 10:52:40 +0100 | [diff] [blame] | 1304 | return prepareThumbnailAnimationWithDuration(a, appWidth, appHeight, |
| 1305 | getAspectScaleDuration(), getAspectScaleInterpolator()); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1306 | } |
| 1307 | |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 1308 | private Animation createAspectScaledThumbnailEnterFreeformAnimationLocked(Rect frame, |
| 1309 | @Nullable Rect surfaceInsets, int taskId) { |
| 1310 | getNextAppTransitionStartRect(taskId, mTmpRect); |
| 1311 | return createAspectScaledThumbnailFreeformAnimationLocked(mTmpRect, frame, surfaceInsets, |
| 1312 | true); |
| 1313 | } |
| 1314 | |
| 1315 | private Animation createAspectScaledThumbnailExitFreeformAnimationLocked(Rect frame, |
| 1316 | @Nullable Rect surfaceInsets, int taskId) { |
| 1317 | getNextAppTransitionStartRect(taskId, mTmpRect); |
| 1318 | return createAspectScaledThumbnailFreeformAnimationLocked(frame, mTmpRect, surfaceInsets, |
| 1319 | false); |
| 1320 | } |
| 1321 | |
| 1322 | private AnimationSet createAspectScaledThumbnailFreeformAnimationLocked(Rect sourceFrame, |
| 1323 | Rect destFrame, @Nullable Rect surfaceInsets, boolean enter) { |
| 1324 | final float sourceWidth = sourceFrame.width(); |
| 1325 | final float sourceHeight = sourceFrame.height(); |
| 1326 | final float destWidth = destFrame.width(); |
| 1327 | final float destHeight = destFrame.height(); |
| 1328 | final float scaleH = enter ? sourceWidth / destWidth : destWidth / sourceWidth; |
| 1329 | final float scaleV = enter ? sourceHeight / destHeight : destHeight / sourceHeight; |
Filip Gruszczynski | 71b0d2d | 2015-08-12 18:52:26 -0700 | [diff] [blame] | 1330 | AnimationSet set = new AnimationSet(true); |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 1331 | final int surfaceInsetsH = surfaceInsets == null |
Filip Gruszczynski | 71b0d2d | 2015-08-12 18:52:26 -0700 | [diff] [blame] | 1332 | ? 0 : surfaceInsets.left + surfaceInsets.right; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 1333 | final int surfaceInsetsV = surfaceInsets == null |
Filip Gruszczynski | 71b0d2d | 2015-08-12 18:52:26 -0700 | [diff] [blame] | 1334 | ? 0 : surfaceInsets.top + surfaceInsets.bottom; |
| 1335 | // We want the scaling to happen from the center of the surface. In order to achieve that, |
| 1336 | // we need to account for surface insets that will be used to enlarge the surface. |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 1337 | final float scaleHCenter = ((enter ? destWidth : sourceWidth) + surfaceInsetsH) / 2; |
| 1338 | final float scaleVCenter = ((enter ? destHeight : sourceHeight) + surfaceInsetsV) / 2; |
| 1339 | final ScaleAnimation scale = enter ? |
| 1340 | new ScaleAnimation(scaleH, 1, scaleV, 1, scaleHCenter, scaleVCenter) |
| 1341 | : new ScaleAnimation(1, scaleH, 1, scaleV, scaleHCenter, scaleVCenter); |
| 1342 | final int sourceHCenter = sourceFrame.left + sourceFrame.width() / 2; |
| 1343 | final int sourceVCenter = sourceFrame.top + sourceFrame.height() / 2; |
| 1344 | final int destHCenter = destFrame.left + destFrame.width() / 2; |
| 1345 | final int destVCenter = destFrame.top + destFrame.height() / 2; |
| 1346 | final int fromX = enter ? sourceHCenter - destHCenter : destHCenter - sourceHCenter; |
| 1347 | final int fromY = enter ? sourceVCenter - destVCenter : destVCenter - sourceVCenter; |
| 1348 | final TranslateAnimation translation = enter ? new TranslateAnimation(fromX, 0, fromY, 0) |
| 1349 | : new TranslateAnimation(0, fromX, 0, fromY); |
Filip Gruszczynski | 71b0d2d | 2015-08-12 18:52:26 -0700 | [diff] [blame] | 1350 | set.addAnimation(scale); |
| 1351 | set.addAnimation(translation); |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 1352 | |
| 1353 | final IRemoteCallback callback = mAnimationFinishedCallback; |
| 1354 | if (callback != null) { |
| 1355 | set.setAnimationListener(new Animation.AnimationListener() { |
| 1356 | @Override |
| 1357 | public void onAnimationStart(Animation animation) { } |
| 1358 | |
| 1359 | @Override |
| 1360 | public void onAnimationEnd(Animation animation) { |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 1361 | mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, callback).sendToTarget(); |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | @Override |
| 1365 | public void onAnimationRepeat(Animation animation) { } |
| 1366 | }); |
| 1367 | } |
Filip Gruszczynski | 71b0d2d | 2015-08-12 18:52:26 -0700 | [diff] [blame] | 1368 | return set; |
| 1369 | } |
| 1370 | |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1371 | /** |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1372 | * This animation runs for the thumbnail that gets cross faded with the enter/exit activity |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 1373 | * when a thumbnail is specified with the pending animation override. |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1374 | */ |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 1375 | Animation createThumbnailScaleAnimationLocked(int appWidth, int appHeight, int transit, |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 1376 | GraphicBuffer thumbnailHeader) { |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1377 | Animation a; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 1378 | getDefaultNextAppTransitionStartRect(mTmpRect); |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 1379 | final int thumbWidthI = thumbnailHeader.getWidth(); |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1380 | final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1; |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 1381 | final int thumbHeightI = thumbnailHeader.getHeight(); |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1382 | final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1; |
| 1383 | |
| 1384 | if (mNextAppTransitionScaleUp) { |
| 1385 | // Animation for the thumbnail zooming from its initial size to the full screen |
| 1386 | float scaleW = appWidth / thumbWidth; |
| 1387 | float scaleH = appHeight / thumbHeight; |
| 1388 | Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH, |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 1389 | computePivot(mTmpRect.left, 1 / scaleW), |
| 1390 | computePivot(mTmpRect.top, 1 / scaleH)); |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1391 | scale.setInterpolator(mDecelerateInterpolator); |
| 1392 | |
| 1393 | Animation alpha = new AlphaAnimation(1, 0); |
| 1394 | alpha.setInterpolator(mThumbnailFadeOutInterpolator); |
| 1395 | |
| 1396 | // This AnimationSet uses the Interpolators assigned above. |
| 1397 | AnimationSet set = new AnimationSet(false); |
| 1398 | set.addAnimation(scale); |
| 1399 | set.addAnimation(alpha); |
| 1400 | a = set; |
| 1401 | } else { |
| 1402 | // Animation for the thumbnail zooming down from the full screen to its final size |
| 1403 | float scaleW = appWidth / thumbWidth; |
| 1404 | float scaleH = appHeight / thumbHeight; |
| 1405 | a = new ScaleAnimation(scaleW, 1, scaleH, 1, |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 1406 | computePivot(mTmpRect.left, 1 / scaleW), |
| 1407 | computePivot(mTmpRect.top, 1 / scaleH)); |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | return prepareThumbnailAnimation(a, appWidth, appHeight, transit); |
| 1411 | } |
| 1412 | |
| 1413 | /** |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1414 | * This animation is created when we are doing a thumbnail transition, for the activity that is |
| 1415 | * leaving, and the activity that is entering. |
| 1416 | */ |
Filip Gruszczynski | 541f92c | 2015-10-25 17:15:06 -0700 | [diff] [blame] | 1417 | Animation createThumbnailEnterExitAnimationLocked(int thumbTransitState, Rect containingFrame, |
| 1418 | int transit, int taskId) { |
| 1419 | final int appWidth = containingFrame.width(); |
| 1420 | final int appHeight = containingFrame.height(); |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 1421 | final GraphicBuffer thumbnailHeader = getAppTransitionThumbnailHeader(taskId); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1422 | Animation a; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 1423 | getDefaultNextAppTransitionStartRect(mTmpRect); |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 1424 | final int thumbWidthI = thumbnailHeader != null ? thumbnailHeader.getWidth() : appWidth; |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1425 | final float thumbWidth = thumbWidthI > 0 ? thumbWidthI : 1; |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 1426 | final int thumbHeightI = thumbnailHeader != null ? thumbnailHeader.getHeight() : appHeight; |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1427 | final float thumbHeight = thumbHeightI > 0 ? thumbHeightI : 1; |
| 1428 | |
| 1429 | switch (thumbTransitState) { |
| 1430 | case THUMBNAIL_TRANSITION_ENTER_SCALE_UP: { |
| 1431 | // Entering app scales up with the thumbnail |
| 1432 | float scaleW = thumbWidth / appWidth; |
| 1433 | float scaleH = thumbHeight / appHeight; |
| 1434 | a = new ScaleAnimation(scaleW, 1, scaleH, 1, |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 1435 | computePivot(mTmpRect.left, scaleW), |
| 1436 | computePivot(mTmpRect.top, scaleH)); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1437 | break; |
| 1438 | } |
| 1439 | case THUMBNAIL_TRANSITION_EXIT_SCALE_UP: { |
| 1440 | // Exiting app while the thumbnail is scaling up should fade or stay in place |
| 1441 | if (transit == TRANSIT_WALLPAPER_INTRA_OPEN) { |
| 1442 | // Fade out while bringing up selected activity. This keeps the |
| 1443 | // current activity from showing through a launching wallpaper |
| 1444 | // activity. |
| 1445 | a = new AlphaAnimation(1, 0); |
| 1446 | } else { |
| 1447 | // noop animation |
| 1448 | a = new AlphaAnimation(1, 1); |
| 1449 | } |
| 1450 | break; |
| 1451 | } |
| 1452 | case THUMBNAIL_TRANSITION_ENTER_SCALE_DOWN: { |
| 1453 | // Entering the other app, it should just be visible while we scale the thumbnail |
| 1454 | // down above it |
| 1455 | a = new AlphaAnimation(1, 1); |
| 1456 | break; |
| 1457 | } |
| 1458 | case THUMBNAIL_TRANSITION_EXIT_SCALE_DOWN: { |
| 1459 | // Exiting the current app, the app should scale down with the thumbnail |
| 1460 | float scaleW = thumbWidth / appWidth; |
| 1461 | float scaleH = thumbHeight / appHeight; |
| 1462 | Animation scale = new ScaleAnimation(1, scaleW, 1, scaleH, |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 1463 | computePivot(mTmpRect.left, scaleW), |
| 1464 | computePivot(mTmpRect.top, scaleH)); |
Winson Chung | 399f620 | 2014-03-19 10:47:20 -0700 | [diff] [blame] | 1465 | |
| 1466 | Animation alpha = new AlphaAnimation(1, 0); |
| 1467 | |
| 1468 | AnimationSet set = new AnimationSet(true); |
| 1469 | set.addAnimation(scale); |
| 1470 | set.addAnimation(alpha); |
| 1471 | set.setZAdjustment(Animation.ZORDER_TOP); |
| 1472 | a = set; |
| 1473 | break; |
| 1474 | } |
| 1475 | default: |
| 1476 | throw new RuntimeException("Invalid thumbnail transition state"); |
| 1477 | } |
| 1478 | |
| 1479 | return prepareThumbnailAnimation(a, appWidth, appHeight, transit); |
| 1480 | } |
| 1481 | |
Filip Gruszczynski | 541f92c | 2015-10-25 17:15:06 -0700 | [diff] [blame] | 1482 | private Animation createRelaunchAnimation(Rect containingFrame, Rect contentInsets) { |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 1483 | getDefaultNextAppTransitionStartRect(mTmpFromClipRect); |
| 1484 | final int left = mTmpFromClipRect.left; |
| 1485 | final int top = mTmpFromClipRect.top; |
| 1486 | mTmpFromClipRect.offset(-left, -top); |
Filip Gruszczynski | 541f92c | 2015-10-25 17:15:06 -0700 | [diff] [blame] | 1487 | // TODO: Isn't that strange that we ignore exact position of the containingFrame? |
| 1488 | mTmpToClipRect.set(0, 0, containingFrame.width(), containingFrame.height()); |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 1489 | AnimationSet set = new AnimationSet(true); |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 1490 | float fromWidth = mTmpFromClipRect.width(); |
| 1491 | float toWidth = mTmpToClipRect.width(); |
| 1492 | float fromHeight = mTmpFromClipRect.height(); |
Filip Gruszczynski | 2dfcf84 | 2015-10-25 13:40:47 -0700 | [diff] [blame] | 1493 | // While the window might span the whole display, the actual content will be cropped to the |
| 1494 | // system decoration frame, for example when the window is docked. We need to take into |
| 1495 | // account the visible height when constructing the animation. |
| 1496 | float toHeight = mTmpToClipRect.height() - contentInsets.top - contentInsets.bottom; |
| 1497 | int translateAdjustment = 0; |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 1498 | if (fromWidth <= toWidth && fromHeight <= toHeight) { |
| 1499 | // The final window is larger in both dimensions than current window (e.g. we are |
| 1500 | // maximizing), so we can simply unclip the new window and there will be no disappearing |
| 1501 | // frame. |
| 1502 | set.addAnimation(new ClipRectAnimation(mTmpFromClipRect, mTmpToClipRect)); |
| 1503 | } else { |
| 1504 | // The disappearing window has one larger dimension. We need to apply scaling, so the |
| 1505 | // first frame of the entry animation matches the old window. |
| 1506 | set.addAnimation(new ScaleAnimation(fromWidth / toWidth, 1, fromHeight / toHeight, 1)); |
Filip Gruszczynski | 2dfcf84 | 2015-10-25 13:40:47 -0700 | [diff] [blame] | 1507 | // We might not be going exactly full screen, but instead be aligned under the status |
| 1508 | // bar using cropping. We still need to account for the cropped part, which will also |
| 1509 | // be scaled. |
| 1510 | translateAdjustment = (int) (contentInsets.top * fromHeight / toHeight); |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 1511 | } |
| 1512 | |
Filip Gruszczynski | 2dfcf84 | 2015-10-25 13:40:47 -0700 | [diff] [blame] | 1513 | // We animate the translation from the old position of the removed window, to the new |
| 1514 | // position of the added window. The latter might not be full screen, for example docked for |
| 1515 | // docked windows. |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 1516 | TranslateAnimation translate = new TranslateAnimation(left - containingFrame.left, |
Filip Gruszczynski | 2dfcf84 | 2015-10-25 13:40:47 -0700 | [diff] [blame] | 1517 | 0, top - containingFrame.top - translateAdjustment, 0); |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 1518 | set.addAnimation(translate); |
| 1519 | set.setDuration(DEFAULT_APP_TRANSITION_DURATION); |
Filip Gruszczynski | e95b0ae | 2015-09-30 10:55:33 -0700 | [diff] [blame] | 1520 | set.setZAdjustment(Animation.ZORDER_TOP); |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 1521 | return set; |
| 1522 | } |
| 1523 | |
Jorim Jaggi | c554b77 | 2015-06-04 16:07:57 -0700 | [diff] [blame] | 1524 | /** |
| 1525 | * @return true if and only if the first frame of the transition can be skipped, i.e. the first |
| 1526 | * frame of the transition doesn't change the visuals on screen, so we can start |
| 1527 | * directly with the second one |
| 1528 | */ |
| 1529 | boolean canSkipFirstFrame() { |
| 1530 | return mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM |
| 1531 | && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1532 | && mNextAppTransitionType != NEXT_TRANSIT_TYPE_CLIP_REVEAL |
| 1533 | && mNextAppTransition != TRANSIT_KEYGUARD_GOING_AWAY; |
Jorim Jaggi | c554b77 | 2015-06-04 16:07:57 -0700 | [diff] [blame] | 1534 | } |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1535 | |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 1536 | RemoteAnimationController getRemoteAnimationController() { |
| 1537 | return mRemoteAnimationController; |
| 1538 | } |
| 1539 | |
Filip Gruszczynski | 541f92c | 2015-10-25 17:15:06 -0700 | [diff] [blame] | 1540 | /** |
| 1541 | * |
| 1542 | * @param frame These are the bounds of the window when it finishes the animation. This is where |
| 1543 | * the animation must usually finish in entrance animation, as the next frame will |
| 1544 | * display the window at these coordinates. In case of exit animation, this is |
| 1545 | * where the animation must start, as the frame before the animation is displaying |
| 1546 | * the window at these bounds. |
| 1547 | * @param insets Knowing where the window will be positioned is not enough. Some parts of the |
| 1548 | * window might be obscured, usually by the system windows (status bar and |
| 1549 | * navigation bar) and we use content insets to convey that information. This |
| 1550 | * usually affects the animation aspects vertically, as the system decoration is |
| 1551 | * at the top and the bottom. For example when we animate from full screen to |
| 1552 | * recents, we want to exclude the covered parts, because they won't match the |
| 1553 | * thumbnail after the last frame is executed. |
| 1554 | * @param surfaceInsets In rare situation the surface is larger than the content and we need to |
| 1555 | * know about this to make the animation frames match. We currently use |
| 1556 | * this for freeform windows, which have larger surfaces to display |
| 1557 | * shadows. When we animate them from recents, we want to match the content |
| 1558 | * to the recents thumbnail and hence need to account for the surface being |
| 1559 | * bigger. |
| 1560 | */ |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 1561 | Animation loadAnimation(LayoutParams lp, int transit, boolean enter, int uiMode, |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 1562 | int orientation, Rect frame, Rect displayFrame, Rect insets, |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 1563 | @Nullable Rect surfaceInsets, @Nullable Rect stableInsets, boolean isVoiceInteraction, |
| 1564 | boolean freeform, int taskId) { |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1565 | Animation a; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1566 | if (isKeyguardGoingAwayTransit(transit) && enter) { |
| 1567 | a = loadKeyguardExitAnimation(transit); |
| 1568 | } else if (transit == TRANSIT_KEYGUARD_OCCLUDE) { |
| 1569 | a = null; |
| 1570 | } else if (transit == TRANSIT_KEYGUARD_UNOCCLUDE && !enter) { |
| 1571 | a = loadAnimationRes(lp, com.android.internal.R.anim.wallpaper_open_exit); |
| 1572 | } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_OPEN |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1573 | || transit == TRANSIT_TASK_OPEN |
| 1574 | || transit == TRANSIT_TASK_TO_FRONT)) { |
| 1575 | a = loadAnimationRes(lp, enter |
| 1576 | ? com.android.internal.R.anim.voice_activity_open_enter |
| 1577 | : com.android.internal.R.anim.voice_activity_open_exit); |
| 1578 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, |
| 1579 | "applyAnimation voice:" |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 1580 | + " anim=" + a + " transit=" + appTransitionToString(transit) |
| 1581 | + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3)); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1582 | } else if (isVoiceInteraction && (transit == TRANSIT_ACTIVITY_CLOSE |
| 1583 | || transit == TRANSIT_TASK_CLOSE |
| 1584 | || transit == TRANSIT_TASK_TO_BACK)) { |
| 1585 | a = loadAnimationRes(lp, enter |
| 1586 | ? com.android.internal.R.anim.voice_activity_close_enter |
| 1587 | : com.android.internal.R.anim.voice_activity_close_exit); |
| 1588 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, |
| 1589 | "applyAnimation voice:" |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 1590 | + " anim=" + a + " transit=" + appTransitionToString(transit) |
| 1591 | + " isEntrance=" + enter + " Callers=" + Debug.getCallers(3)); |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 1592 | } else if (transit == TRANSIT_ACTIVITY_RELAUNCH) { |
Filip Gruszczynski | 541f92c | 2015-10-25 17:15:06 -0700 | [diff] [blame] | 1593 | a = createRelaunchAnimation(frame, insets); |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 1594 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, |
| 1595 | "applyAnimation:" |
| 1596 | + " anim=" + a + " nextAppTransition=" + mNextAppTransition |
| 1597 | + " transit=" + appTransitionToString(transit) |
| 1598 | + " Callers=" + Debug.getCallers(3)); |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1599 | } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM) { |
| 1600 | a = loadAnimationRes(mNextAppTransitionPackage, enter ? |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1601 | mNextAppTransitionEnter : mNextAppTransitionExit); |
| 1602 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, |
| 1603 | "applyAnimation:" |
| 1604 | + " anim=" + a + " nextAppTransition=ANIM_CUSTOM" |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 1605 | + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1606 | + " Callers=" + Debug.getCallers(3)); |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 1607 | } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE) { |
| 1608 | a = loadAnimationRes(mNextAppTransitionPackage, mNextAppTransitionInPlace); |
| 1609 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, |
| 1610 | "applyAnimation:" |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 1611 | + " anim=" + a + " nextAppTransition=ANIM_CUSTOM_IN_PLACE" |
| 1612 | + " transit=" + appTransitionToString(transit) |
| 1613 | + " Callers=" + Debug.getCallers(3)); |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 1614 | } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL) { |
Jorim Jaggi | 8fe7e0a | 2016-02-12 19:43:39 -0800 | [diff] [blame] | 1615 | a = createClipRevealAnimationLocked(transit, enter, frame, displayFrame); |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 1616 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, |
| 1617 | "applyAnimation:" |
| 1618 | + " anim=" + a + " nextAppTransition=ANIM_CLIP_REVEAL" |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 1619 | + " transit=" + appTransitionToString(transit) |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 1620 | + " Callers=" + Debug.getCallers(3)); |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 1621 | } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_SCALE_UP) { |
Filip Gruszczynski | 541f92c | 2015-10-25 17:15:06 -0700 | [diff] [blame] | 1622 | a = createScaleUpAnimationLocked(transit, enter, frame); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1623 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, |
| 1624 | "applyAnimation:" |
| 1625 | + " anim=" + a + " nextAppTransition=ANIM_SCALE_UP" |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 1626 | + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1627 | + " Callers=" + Debug.getCallers(3)); |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 1628 | } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP || |
| 1629 | mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN) { |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1630 | mNextAppTransitionScaleUp = |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 1631 | (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP); |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1632 | a = createThumbnailEnterExitAnimationLocked(getThumbnailTransitionState(enter), |
Filip Gruszczynski | 541f92c | 2015-10-25 17:15:06 -0700 | [diff] [blame] | 1633 | frame, transit, taskId); |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1634 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) { |
| 1635 | String animName = mNextAppTransitionScaleUp ? |
| 1636 | "ANIM_THUMBNAIL_SCALE_UP" : "ANIM_THUMBNAIL_SCALE_DOWN"; |
| 1637 | Slog.v(TAG, "applyAnimation:" |
| 1638 | + " anim=" + a + " nextAppTransition=" + animName |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 1639 | + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1640 | + " Callers=" + Debug.getCallers(3)); |
| 1641 | } |
| 1642 | } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP || |
| 1643 | mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN) { |
| 1644 | mNextAppTransitionScaleUp = |
| 1645 | (mNextAppTransitionType == NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP); |
| 1646 | a = createAspectScaledThumbnailEnterExitAnimationLocked( |
Winson | b202476 | 2016-04-05 17:32:30 -0700 | [diff] [blame] | 1647 | getThumbnailTransitionState(enter), uiMode, orientation, transit, frame, |
Matthew Ng | 43db6d2 | 2017-06-27 15:29:39 -0700 | [diff] [blame] | 1648 | insets, surfaceInsets, stableInsets, freeform, taskId); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1649 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) { |
| 1650 | String animName = mNextAppTransitionScaleUp ? |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1651 | "ANIM_THUMBNAIL_ASPECT_SCALE_UP" : "ANIM_THUMBNAIL_ASPECT_SCALE_DOWN"; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1652 | Slog.v(TAG, "applyAnimation:" |
| 1653 | + " anim=" + a + " nextAppTransition=" + animName |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 1654 | + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1655 | + " Callers=" + Debug.getCallers(3)); |
| 1656 | } |
Tony Mak | 83546a8 | 2018-01-22 13:56:20 +0000 | [diff] [blame] | 1657 | } else if (mNextAppTransitionType == NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS && enter) { |
Jorim Jaggi | 98a9d20 | 2018-03-26 16:17:07 +0200 | [diff] [blame^] | 1658 | a = loadAnimationRes("android", |
| 1659 | com.android.internal.R.anim.task_open_enter_cross_profile_apps); |
Tony Mak | 089c35e | 2017-12-18 20:34:14 +0000 | [diff] [blame] | 1660 | Slog.v(TAG, |
| 1661 | "applyAnimation NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS:" |
| 1662 | + " anim=" + a + " transit=" + appTransitionToString(transit) |
Jorim Jaggi | 98a9d20 | 2018-03-26 16:17:07 +0200 | [diff] [blame^] | 1663 | + " isEntrance=true" + " Callers=" + Debug.getCallers(3)); |
| 1664 | } else if (transit == TRANSIT_TRANSLUCENT_ACTIVITY_OPEN && enter) { |
| 1665 | a = loadAnimationRes("android", |
| 1666 | com.android.internal.R.anim.activity_translucent_open_enter); |
| 1667 | Slog.v(TAG, |
| 1668 | "applyAnimation TRANSIT_TRANSLUCENT_ACTIVITY_OPEN:" |
| 1669 | + " anim=" + a + " transit=" + appTransitionToString(transit) |
| 1670 | + " isEntrance=true" + " Callers=" + Debug.getCallers(3)); |
| 1671 | } else if (transit == TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE && !enter) { |
| 1672 | a = loadAnimationRes("android", |
| 1673 | com.android.internal.R.anim.activity_translucent_close_exit); |
| 1674 | Slog.v(TAG, |
| 1675 | "applyAnimation TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE:" |
| 1676 | + " anim=" + a + " transit=" + appTransitionToString(transit) |
| 1677 | + " isEntrance=false" + " Callers=" + Debug.getCallers(3)); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1678 | } else { |
| 1679 | int animAttr = 0; |
| 1680 | switch (transit) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1681 | case TRANSIT_ACTIVITY_OPEN: |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1682 | animAttr = enter |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 1683 | ? WindowAnimation_activityOpenEnterAnimation |
| 1684 | : WindowAnimation_activityOpenExitAnimation; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1685 | break; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1686 | case TRANSIT_ACTIVITY_CLOSE: |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1687 | animAttr = enter |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 1688 | ? WindowAnimation_activityCloseEnterAnimation |
| 1689 | : WindowAnimation_activityCloseExitAnimation; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1690 | break; |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 1691 | case TRANSIT_DOCK_TASK_FROM_RECENTS: |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1692 | case TRANSIT_TASK_OPEN: |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1693 | animAttr = enter |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 1694 | ? WindowAnimation_taskOpenEnterAnimation |
| 1695 | : WindowAnimation_taskOpenExitAnimation; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1696 | break; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1697 | case TRANSIT_TASK_CLOSE: |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1698 | animAttr = enter |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 1699 | ? WindowAnimation_taskCloseEnterAnimation |
| 1700 | : WindowAnimation_taskCloseExitAnimation; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1701 | break; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1702 | case TRANSIT_TASK_TO_FRONT: |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1703 | animAttr = enter |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 1704 | ? WindowAnimation_taskToFrontEnterAnimation |
| 1705 | : WindowAnimation_taskToFrontExitAnimation; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1706 | break; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1707 | case TRANSIT_TASK_TO_BACK: |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1708 | animAttr = enter |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 1709 | ? WindowAnimation_taskToBackEnterAnimation |
| 1710 | : WindowAnimation_taskToBackExitAnimation; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1711 | break; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1712 | case TRANSIT_WALLPAPER_OPEN: |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1713 | animAttr = enter |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 1714 | ? WindowAnimation_wallpaperOpenEnterAnimation |
| 1715 | : WindowAnimation_wallpaperOpenExitAnimation; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1716 | break; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1717 | case TRANSIT_WALLPAPER_CLOSE: |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1718 | animAttr = enter |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 1719 | ? WindowAnimation_wallpaperCloseEnterAnimation |
| 1720 | : WindowAnimation_wallpaperCloseExitAnimation; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1721 | break; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1722 | case TRANSIT_WALLPAPER_INTRA_OPEN: |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1723 | animAttr = enter |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 1724 | ? WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 1725 | : WindowAnimation_wallpaperIntraOpenExitAnimation; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1726 | break; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1727 | case TRANSIT_WALLPAPER_INTRA_CLOSE: |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1728 | animAttr = enter |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 1729 | ? WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 1730 | : WindowAnimation_wallpaperIntraCloseExitAnimation; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1731 | break; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1732 | case TRANSIT_TASK_OPEN_BEHIND: |
| 1733 | animAttr = enter |
| 1734 | ? WindowAnimation_launchTaskBehindSourceAnimation |
Craig Mautner | 3b2cd1d | 2014-08-25 14:25:54 -0700 | [diff] [blame] | 1735 | : WindowAnimation_launchTaskBehindTargetAnimation; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1736 | } |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1737 | a = animAttr != 0 ? loadAnimationAttr(lp, animAttr) : null; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1738 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, |
| 1739 | "applyAnimation:" |
| 1740 | + " anim=" + a |
| 1741 | + " animAttr=0x" + Integer.toHexString(animAttr) |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 1742 | + " transit=" + appTransitionToString(transit) + " isEntrance=" + enter |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1743 | + " Callers=" + Debug.getCallers(3)); |
| 1744 | } |
| 1745 | return a; |
| 1746 | } |
| 1747 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1748 | private Animation loadKeyguardExitAnimation(int transit) { |
| 1749 | if ((mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_NO_ANIMATION) != 0) { |
| 1750 | return null; |
| 1751 | } |
| 1752 | final boolean toShade = |
| 1753 | (mNextAppTransitionFlags & TRANSIT_FLAG_KEYGUARD_GOING_AWAY_TO_SHADE) != 0; |
| 1754 | return mService.mPolicy.createHiddenByKeyguardExit( |
| 1755 | transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER, toShade); |
| 1756 | } |
| 1757 | |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 1758 | int getAppStackClipMode() { |
Matthew Ng | bf1d985 | 2017-03-14 12:23:09 -0700 | [diff] [blame] | 1759 | // When dismiss keyguard animation occurs, clip before the animation to prevent docked |
| 1760 | // app from showing beyond the divider |
| 1761 | if (mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY |
| 1762 | || mNextAppTransition == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER) { |
| 1763 | return STACK_CLIP_BEFORE_ANIM; |
| 1764 | } |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 1765 | return mNextAppTransition == TRANSIT_ACTIVITY_RELAUNCH |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 1766 | || mNextAppTransition == TRANSIT_DOCK_TASK_FROM_RECENTS |
Jorim Jaggi | 1f458fb | 2016-03-25 17:36:37 -0700 | [diff] [blame] | 1767 | || mNextAppTransitionType == NEXT_TRANSIT_TYPE_CLIP_REVEAL |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 1768 | ? STACK_CLIP_NONE |
| 1769 | : STACK_CLIP_AFTER_ANIM; |
| 1770 | } |
| 1771 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1772 | public int getTransitFlags() { |
| 1773 | return mNextAppTransitionFlags; |
| 1774 | } |
| 1775 | |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1776 | void postAnimationCallback() { |
| 1777 | if (mNextAppTransitionCallback != null) { |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 1778 | mService.mH.sendMessage(mService.mH.obtainMessage(H.DO_ANIMATION_CALLBACK, |
| 1779 | mNextAppTransitionCallback)); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1780 | mNextAppTransitionCallback = null; |
| 1781 | } |
| 1782 | } |
| 1783 | |
| 1784 | void overridePendingAppTransition(String packageName, int enterAnim, int exitAnim, |
Filip Gruszczynski | d143142 | 2015-09-08 11:18:54 -0700 | [diff] [blame] | 1785 | IRemoteCallback startedCallback) { |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 1786 | if (canOverridePendingAppTransition()) { |
Jorim Jaggi | 6519399 | 2015-11-23 16:49:59 -0800 | [diff] [blame] | 1787 | clear(); |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 1788 | mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1789 | mNextAppTransitionPackage = packageName; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1790 | mNextAppTransitionEnter = enterAnim; |
| 1791 | mNextAppTransitionExit = exitAnim; |
| 1792 | postAnimationCallback(); |
| 1793 | mNextAppTransitionCallback = startedCallback; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1794 | } |
| 1795 | } |
| 1796 | |
| 1797 | void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth, |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 1798 | int startHeight) { |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 1799 | if (canOverridePendingAppTransition()) { |
Jorim Jaggi | 6519399 | 2015-11-23 16:49:59 -0800 | [diff] [blame] | 1800 | clear(); |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 1801 | mNextAppTransitionType = NEXT_TRANSIT_TYPE_SCALE_UP; |
Winson | 4c3fecd | 2016-07-13 12:29:48 -0700 | [diff] [blame] | 1802 | putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1803 | postAnimationCallback(); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1804 | } |
| 1805 | } |
| 1806 | |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 1807 | void overridePendingAppTransitionClipReveal(int startX, int startY, |
| 1808 | int startWidth, int startHeight) { |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 1809 | if (canOverridePendingAppTransition()) { |
Jorim Jaggi | 6519399 | 2015-11-23 16:49:59 -0800 | [diff] [blame] | 1810 | clear(); |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 1811 | mNextAppTransitionType = NEXT_TRANSIT_TYPE_CLIP_REVEAL; |
Filip Gruszczynski | 7248c56 | 2015-11-09 13:05:40 -0800 | [diff] [blame] | 1812 | putDefaultNextAppTransitionCoordinates(startX, startY, startWidth, startHeight, null); |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 1813 | postAnimationCallback(); |
Chet Haase | 10e23ab | 2015-02-11 15:08:38 -0800 | [diff] [blame] | 1814 | } |
| 1815 | } |
| 1816 | |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 1817 | void overridePendingAppTransitionThumb(GraphicBuffer srcThumb, int startX, int startY, |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1818 | IRemoteCallback startedCallback, boolean scaleUp) { |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 1819 | if (canOverridePendingAppTransition()) { |
Jorim Jaggi | 6519399 | 2015-11-23 16:49:59 -0800 | [diff] [blame] | 1820 | clear(); |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 1821 | mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP |
| 1822 | : NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1823 | mNextAppTransitionScaleUp = scaleUp; |
Filip Gruszczynski | 7248c56 | 2015-11-09 13:05:40 -0800 | [diff] [blame] | 1824 | putDefaultNextAppTransitionCoordinates(startX, startY, 0, 0, srcThumb); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1825 | postAnimationCallback(); |
| 1826 | mNextAppTransitionCallback = startedCallback; |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1827 | } |
| 1828 | } |
| 1829 | |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 1830 | void overridePendingAppTransitionAspectScaledThumb(GraphicBuffer srcThumb, int startX, int startY, |
Winson Chung | 2e7f3bd | 2014-09-05 13:17:22 +0200 | [diff] [blame] | 1831 | int targetWidth, int targetHeight, IRemoteCallback startedCallback, boolean scaleUp) { |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 1832 | if (canOverridePendingAppTransition()) { |
Jorim Jaggi | 6519399 | 2015-11-23 16:49:59 -0800 | [diff] [blame] | 1833 | clear(); |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1834 | mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP |
| 1835 | : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN; |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1836 | mNextAppTransitionScaleUp = scaleUp; |
Filip Gruszczynski | 7248c56 | 2015-11-09 13:05:40 -0800 | [diff] [blame] | 1837 | putDefaultNextAppTransitionCoordinates(startX, startY, targetWidth, targetHeight, |
| 1838 | srcThumb); |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1839 | postAnimationCallback(); |
| 1840 | mNextAppTransitionCallback = startedCallback; |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 1841 | } |
| 1842 | } |
| 1843 | |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 1844 | void overridePendingAppTransitionMultiThumb(AppTransitionAnimationSpec[] specs, |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 1845 | IRemoteCallback onAnimationStartedCallback, IRemoteCallback onAnimationFinishedCallback, |
| 1846 | boolean scaleUp) { |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 1847 | if (canOverridePendingAppTransition()) { |
Jorim Jaggi | 6519399 | 2015-11-23 16:49:59 -0800 | [diff] [blame] | 1848 | clear(); |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 1849 | mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP |
| 1850 | : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN; |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 1851 | mNextAppTransitionScaleUp = scaleUp; |
Jorim Jaggi | 4310241 | 2015-11-11 16:28:37 +0100 | [diff] [blame] | 1852 | if (specs != null) { |
| 1853 | for (int i = 0; i < specs.length; i++) { |
| 1854 | AppTransitionAnimationSpec spec = specs[i]; |
| 1855 | if (spec != null) { |
| 1856 | mNextAppTransitionAnimationsSpecs.put(spec.taskId, spec); |
| 1857 | if (i == 0) { |
| 1858 | // In full screen mode, the transition code depends on the default spec |
| 1859 | // to be set. |
| 1860 | Rect rect = spec.rect; |
| 1861 | putDefaultNextAppTransitionCoordinates(rect.left, rect.top, |
Winson Chung | aa7fa01 | 2017-05-24 15:50:06 -0700 | [diff] [blame] | 1862 | rect.width(), rect.height(), spec.buffer); |
Jorim Jaggi | 4310241 | 2015-11-11 16:28:37 +0100 | [diff] [blame] | 1863 | } |
Filip Gruszczynski | d143142 | 2015-09-08 11:18:54 -0700 | [diff] [blame] | 1864 | } |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 1865 | } |
| 1866 | } |
| 1867 | postAnimationCallback(); |
Filip Gruszczynski | 1a5203d | 2015-10-29 17:43:49 -0700 | [diff] [blame] | 1868 | mNextAppTransitionCallback = onAnimationStartedCallback; |
| 1869 | mAnimationFinishedCallback = onAnimationFinishedCallback; |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 1870 | } |
| 1871 | } |
| 1872 | |
Jorim Jaggi | 2f7d292 | 2015-10-29 13:08:29 +0100 | [diff] [blame] | 1873 | void overridePendingAppTransitionMultiThumbFuture( |
| 1874 | IAppTransitionAnimationSpecsFuture specsFuture, IRemoteCallback callback, |
| 1875 | boolean scaleUp) { |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 1876 | if (canOverridePendingAppTransition()) { |
Jorim Jaggi | 6519399 | 2015-11-23 16:49:59 -0800 | [diff] [blame] | 1877 | clear(); |
Jorim Jaggi | 2f7d292 | 2015-10-29 13:08:29 +0100 | [diff] [blame] | 1878 | mNextAppTransitionType = scaleUp ? NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP |
| 1879 | : NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN; |
Jorim Jaggi | 2f7d292 | 2015-10-29 13:08:29 +0100 | [diff] [blame] | 1880 | mNextAppTransitionAnimationsSpecsFuture = specsFuture; |
| 1881 | mNextAppTransitionScaleUp = scaleUp; |
Jorim Jaggi | 7cc7b08 | 2015-11-10 16:06:54 +0100 | [diff] [blame] | 1882 | mNextAppTransitionFutureCallback = callback; |
Jorim Jaggi | 2f7d292 | 2015-10-29 13:08:29 +0100 | [diff] [blame] | 1883 | } |
| 1884 | } |
| 1885 | |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 1886 | void overridePendingAppTransitionRemote(RemoteAnimationAdapter remoteAnimationAdapter) { |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 1887 | if (isTransitionSet()) { |
Jorim Jaggi | 6519399 | 2015-11-23 16:49:59 -0800 | [diff] [blame] | 1888 | clear(); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 1889 | mNextAppTransitionType = NEXT_TRANSIT_TYPE_REMOTE; |
| 1890 | mRemoteAnimationController = new RemoteAnimationController(mService, |
| 1891 | remoteAnimationAdapter, mService.mH); |
| 1892 | } |
| 1893 | } |
| 1894 | |
| 1895 | void overrideInPlaceAppTransition(String packageName, int anim) { |
| 1896 | if (canOverridePendingAppTransition()) { |
| 1897 | clear(); |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 1898 | mNextAppTransitionType = NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE; |
| 1899 | mNextAppTransitionPackage = packageName; |
| 1900 | mNextAppTransitionInPlace = anim; |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 1901 | } |
| 1902 | } |
| 1903 | |
Jorim Jaggi | 2f7d292 | 2015-10-29 13:08:29 +0100 | [diff] [blame] | 1904 | /** |
Tony Mak | 089c35e | 2017-12-18 20:34:14 +0000 | [diff] [blame] | 1905 | * @see {@link #NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS} |
| 1906 | */ |
| 1907 | void overridePendingAppTransitionStartCrossProfileApps() { |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 1908 | if (canOverridePendingAppTransition()) { |
Tony Mak | 089c35e | 2017-12-18 20:34:14 +0000 | [diff] [blame] | 1909 | clear(); |
| 1910 | mNextAppTransitionType = NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS; |
| 1911 | postAnimationCallback(); |
| 1912 | } |
| 1913 | } |
| 1914 | |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 1915 | private boolean canOverridePendingAppTransition() { |
| 1916 | // Remote animations always take precedence |
| 1917 | return isTransitionSet() && mNextAppTransitionType != NEXT_TRANSIT_TYPE_REMOTE; |
| 1918 | } |
| 1919 | |
Tony Mak | 089c35e | 2017-12-18 20:34:14 +0000 | [diff] [blame] | 1920 | /** |
Jorim Jaggi | 2f7d292 | 2015-10-29 13:08:29 +0100 | [diff] [blame] | 1921 | * If a future is set for the app transition specs, fetch it in another thread. |
| 1922 | */ |
| 1923 | private void fetchAppTransitionSpecsFromFuture() { |
| 1924 | if (mNextAppTransitionAnimationsSpecsFuture != null) { |
| 1925 | mNextAppTransitionAnimationsSpecsPending = true; |
| 1926 | final IAppTransitionAnimationSpecsFuture future |
| 1927 | = mNextAppTransitionAnimationsSpecsFuture; |
| 1928 | mNextAppTransitionAnimationsSpecsFuture = null; |
Jorim Jaggi | ed410b6 | 2017-05-05 15:16:14 +0200 | [diff] [blame] | 1929 | mDefaultExecutor.execute(() -> { |
| 1930 | AppTransitionAnimationSpec[] specs = null; |
| 1931 | try { |
| 1932 | Binder.allowBlocking(future.asBinder()); |
| 1933 | specs = future.get(); |
| 1934 | } catch (RemoteException e) { |
| 1935 | Slog.w(TAG, "Failed to fetch app transition specs: " + e); |
Jorim Jaggi | 2f7d292 | 2015-10-29 13:08:29 +0100 | [diff] [blame] | 1936 | } |
Jorim Jaggi | ed410b6 | 2017-05-05 15:16:14 +0200 | [diff] [blame] | 1937 | synchronized (mService.mWindowMap) { |
| 1938 | mNextAppTransitionAnimationsSpecsPending = false; |
| 1939 | overridePendingAppTransitionMultiThumb(specs, |
| 1940 | mNextAppTransitionFutureCallback, null /* finishedCallback */, |
| 1941 | mNextAppTransitionScaleUp); |
| 1942 | mNextAppTransitionFutureCallback = null; |
Jorim Jaggi | ed410b6 | 2017-05-05 15:16:14 +0200 | [diff] [blame] | 1943 | } |
| 1944 | mService.requestTraversal(); |
Jorim Jaggi | 2f7d292 | 2015-10-29 13:08:29 +0100 | [diff] [blame] | 1945 | }); |
| 1946 | } |
| 1947 | } |
| 1948 | |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1949 | @Override |
| 1950 | public String toString() { |
Wale Ogunwale | 8ebc82a | 2015-05-13 15:27:12 -0700 | [diff] [blame] | 1951 | return "mNextAppTransition=" + appTransitionToString(mNextAppTransition); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 1952 | } |
| 1953 | |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1954 | /** |
| 1955 | * Returns the human readable name of a window transition. |
| 1956 | * |
| 1957 | * @param transition The window transition. |
| 1958 | * @return The transition symbolic name. |
| 1959 | */ |
| 1960 | public static String appTransitionToString(int transition) { |
| 1961 | switch (transition) { |
| 1962 | case TRANSIT_UNSET: { |
| 1963 | return "TRANSIT_UNSET"; |
| 1964 | } |
| 1965 | case TRANSIT_NONE: { |
| 1966 | return "TRANSIT_NONE"; |
| 1967 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1968 | case TRANSIT_ACTIVITY_OPEN: { |
| 1969 | return "TRANSIT_ACTIVITY_OPEN"; |
| 1970 | } |
| 1971 | case TRANSIT_ACTIVITY_CLOSE: { |
| 1972 | return "TRANSIT_ACTIVITY_CLOSE"; |
| 1973 | } |
| 1974 | case TRANSIT_TASK_OPEN: { |
| 1975 | return "TRANSIT_TASK_OPEN"; |
| 1976 | } |
| 1977 | case TRANSIT_TASK_CLOSE: { |
| 1978 | return "TRANSIT_TASK_CLOSE"; |
| 1979 | } |
| 1980 | case TRANSIT_TASK_TO_FRONT: { |
| 1981 | return "TRANSIT_TASK_TO_FRONT"; |
| 1982 | } |
| 1983 | case TRANSIT_TASK_TO_BACK: { |
| 1984 | return "TRANSIT_TASK_TO_BACK"; |
| 1985 | } |
| 1986 | case TRANSIT_WALLPAPER_CLOSE: { |
| 1987 | return "TRANSIT_WALLPAPER_CLOSE"; |
| 1988 | } |
| 1989 | case TRANSIT_WALLPAPER_OPEN: { |
| 1990 | return "TRANSIT_WALLPAPER_OPEN"; |
| 1991 | } |
| 1992 | case TRANSIT_WALLPAPER_INTRA_OPEN: { |
| 1993 | return "TRANSIT_WALLPAPER_INTRA_OPEN"; |
| 1994 | } |
| 1995 | case TRANSIT_WALLPAPER_INTRA_CLOSE: { |
| 1996 | return "TRANSIT_WALLPAPER_INTRA_CLOSE"; |
| 1997 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1998 | case TRANSIT_TASK_OPEN_BEHIND: { |
| 1999 | return "TRANSIT_TASK_OPEN_BEHIND"; |
| 2000 | } |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 2001 | case TRANSIT_ACTIVITY_RELAUNCH: { |
| 2002 | return "TRANSIT_ACTIVITY_RELAUNCH"; |
| 2003 | } |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 2004 | case TRANSIT_DOCK_TASK_FROM_RECENTS: { |
| 2005 | return "TRANSIT_DOCK_TASK_FROM_RECENTS"; |
| 2006 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2007 | case TRANSIT_KEYGUARD_GOING_AWAY: { |
| 2008 | return "TRANSIT_KEYGUARD_GOING_AWAY"; |
| 2009 | } |
| 2010 | case TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER: { |
| 2011 | return "TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER"; |
| 2012 | } |
| 2013 | case TRANSIT_KEYGUARD_OCCLUDE: { |
| 2014 | return "TRANSIT_KEYGUARD_OCCLUDE"; |
| 2015 | } |
| 2016 | case TRANSIT_KEYGUARD_UNOCCLUDE: { |
| 2017 | return "TRANSIT_KEYGUARD_UNOCCLUDE"; |
| 2018 | } |
Jorim Jaggi | 98a9d20 | 2018-03-26 16:17:07 +0200 | [diff] [blame^] | 2019 | case TRANSIT_TRANSLUCENT_ACTIVITY_OPEN: { |
| 2020 | return "TRANSIT_TRANSLUCENT_ACTIVITY_OPEN"; |
| 2021 | } |
| 2022 | case TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE: { |
| 2023 | return "TRANSIT_TRANSLUCENT_ACTIVITY_CLOSE"; |
| 2024 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2025 | default: { |
| 2026 | return "<UNKNOWN>"; |
| 2027 | } |
| 2028 | } |
| 2029 | } |
| 2030 | |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 2031 | private String appStateToString() { |
| 2032 | switch (mAppTransitionState) { |
| 2033 | case APP_STATE_IDLE: |
| 2034 | return "APP_STATE_IDLE"; |
| 2035 | case APP_STATE_READY: |
| 2036 | return "APP_STATE_READY"; |
| 2037 | case APP_STATE_RUNNING: |
| 2038 | return "APP_STATE_RUNNING"; |
| 2039 | case APP_STATE_TIMEOUT: |
| 2040 | return "APP_STATE_TIMEOUT"; |
| 2041 | default: |
| 2042 | return "unknown state=" + mAppTransitionState; |
| 2043 | } |
| 2044 | } |
| 2045 | |
| 2046 | private String transitTypeToString() { |
| 2047 | switch (mNextAppTransitionType) { |
| 2048 | case NEXT_TRANSIT_TYPE_NONE: |
| 2049 | return "NEXT_TRANSIT_TYPE_NONE"; |
| 2050 | case NEXT_TRANSIT_TYPE_CUSTOM: |
| 2051 | return "NEXT_TRANSIT_TYPE_CUSTOM"; |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 2052 | case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE: |
| 2053 | return "NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE"; |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 2054 | case NEXT_TRANSIT_TYPE_SCALE_UP: |
| 2055 | return "NEXT_TRANSIT_TYPE_SCALE_UP"; |
| 2056 | case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP: |
| 2057 | return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP"; |
| 2058 | case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN: |
| 2059 | return "NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN"; |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 2060 | case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP: |
| 2061 | return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP"; |
| 2062 | case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: |
| 2063 | return "NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN"; |
Tony Mak | 64b8d56 | 2017-12-28 17:44:02 +0000 | [diff] [blame] | 2064 | case NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS: |
| 2065 | return "NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS"; |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 2066 | default: |
| 2067 | return "unknown type=" + mNextAppTransitionType; |
| 2068 | } |
| 2069 | } |
| 2070 | |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 2071 | void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 2072 | final long token = proto.start(fieldId); |
| 2073 | proto.write(APP_TRANSITION_STATE, mAppTransitionState); |
| 2074 | proto.write(LAST_USED_APP_TRANSITION, mLastUsedAppTransition); |
| 2075 | proto.end(token); |
| 2076 | } |
| 2077 | |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 2078 | @Override |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 2079 | public void dump(PrintWriter pw, String prefix) { |
| 2080 | pw.print(prefix); pw.println(this); |
| 2081 | pw.print(prefix); pw.print("mAppTransitionState="); pw.println(appStateToString()); |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 2082 | if (mNextAppTransitionType != NEXT_TRANSIT_TYPE_NONE) { |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 2083 | pw.print(prefix); pw.print("mNextAppTransitionType="); |
| 2084 | pw.println(transitTypeToString()); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 2085 | } |
| 2086 | switch (mNextAppTransitionType) { |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 2087 | case NEXT_TRANSIT_TYPE_CUSTOM: |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 2088 | pw.print(prefix); pw.print("mNextAppTransitionPackage="); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 2089 | pw.println(mNextAppTransitionPackage); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 2090 | pw.print(prefix); pw.print("mNextAppTransitionEnter=0x"); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 2091 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 2092 | pw.print(" mNextAppTransitionExit=0x"); |
| 2093 | pw.println(Integer.toHexString(mNextAppTransitionExit)); |
| 2094 | break; |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 2095 | case NEXT_TRANSIT_TYPE_CUSTOM_IN_PLACE: |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 2096 | pw.print(prefix); pw.print("mNextAppTransitionPackage="); |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 2097 | pw.println(mNextAppTransitionPackage); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 2098 | pw.print(prefix); pw.print("mNextAppTransitionInPlace=0x"); |
Winson Chung | 044d529 | 2014-11-06 11:05:19 -0800 | [diff] [blame] | 2099 | pw.print(Integer.toHexString(mNextAppTransitionInPlace)); |
| 2100 | break; |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 2101 | case NEXT_TRANSIT_TYPE_SCALE_UP: { |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 2102 | getDefaultNextAppTransitionStartRect(mTmpRect); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 2103 | pw.print(prefix); pw.print("mNextAppTransitionStartX="); |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 2104 | pw.print(mTmpRect.left); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 2105 | pw.print(" mNextAppTransitionStartY="); |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 2106 | pw.println(mTmpRect.top); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 2107 | pw.print(prefix); pw.print("mNextAppTransitionStartWidth="); |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 2108 | pw.print(mTmpRect.width()); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 2109 | pw.print(" mNextAppTransitionStartHeight="); |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 2110 | pw.println(mTmpRect.height()); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 2111 | break; |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 2112 | } |
Craig Mautner | 9a29a5d | 2012-12-27 19:03:40 -0800 | [diff] [blame] | 2113 | case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_UP: |
| 2114 | case NEXT_TRANSIT_TYPE_THUMBNAIL_SCALE_DOWN: |
Winson Chung | a4ccb86 | 2014-08-22 15:26:27 -0700 | [diff] [blame] | 2115 | case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_UP: |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 2116 | case NEXT_TRANSIT_TYPE_THUMBNAIL_ASPECT_SCALE_DOWN: { |
| 2117 | pw.print(prefix); pw.print("mDefaultNextAppTransitionAnimationSpec="); |
| 2118 | pw.println(mDefaultNextAppTransitionAnimationSpec); |
| 2119 | pw.print(prefix); pw.print("mNextAppTransitionAnimationsSpecs="); |
| 2120 | pw.println(mNextAppTransitionAnimationsSpecs); |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 2121 | pw.print(prefix); pw.print("mNextAppTransitionScaleUp="); |
| 2122 | pw.println(mNextAppTransitionScaleUp); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 2123 | break; |
Filip Gruszczynski | 170192a | 2015-08-16 17:46:34 -0700 | [diff] [blame] | 2124 | } |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 2125 | } |
| 2126 | if (mNextAppTransitionCallback != null) { |
Dianne Hackborn | ae6688b | 2015-02-11 17:02:41 -0800 | [diff] [blame] | 2127 | pw.print(prefix); pw.print("mNextAppTransitionCallback="); |
| 2128 | pw.println(mNextAppTransitionCallback); |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 2129 | } |
Chong Zhang | 60091a9 | 2016-07-27 17:52:45 -0700 | [diff] [blame] | 2130 | if (mLastUsedAppTransition != TRANSIT_NONE) { |
| 2131 | pw.print(prefix); pw.print("mLastUsedAppTransition="); |
| 2132 | pw.println(appTransitionToString(mLastUsedAppTransition)); |
| 2133 | pw.print(prefix); pw.print("mLastOpeningApp="); |
| 2134 | pw.println(mLastOpeningApp); |
| 2135 | pw.print(prefix); pw.print("mLastClosingApp="); |
| 2136 | pw.println(mLastClosingApp); |
| 2137 | } |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 2138 | } |
Amith Yamasani | 4befbec | 2013-07-10 16:18:01 -0700 | [diff] [blame] | 2139 | |
| 2140 | public void setCurrentUser(int newUserId) { |
| 2141 | mCurrentUserId = newUserId; |
| 2142 | } |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 2143 | |
| 2144 | /** |
| 2145 | * @return true if transition is not running and should not be skipped, false if transition is |
| 2146 | * already running |
| 2147 | */ |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 2148 | boolean prepareAppTransitionLocked(@TransitionType int transit, boolean alwaysKeepCurrent, |
| 2149 | @TransitionFlags int flags, boolean forceOverride) { |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 2150 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Prepare app transition:" |
| 2151 | + " transit=" + appTransitionToString(transit) |
| 2152 | + " " + this |
| 2153 | + " alwaysKeepCurrent=" + alwaysKeepCurrent |
| 2154 | + " Callers=" + Debug.getCallers(3)); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2155 | if (forceOverride || isKeyguardTransit(transit) || !isTransitionSet() |
| 2156 | || mNextAppTransition == TRANSIT_NONE) { |
| 2157 | setAppTransition(transit, flags); |
Jorim Jaggi | a69243a | 2017-06-15 15:10:38 -0400 | [diff] [blame] | 2158 | } |
| 2159 | // We never want to change from a Keyguard transit to a non-Keyguard transit, as our logic |
| 2160 | // relies on the fact that we always execute a Keyguard transition after preparing one. |
| 2161 | else if (!alwaysKeepCurrent && !isKeyguardTransit(transit)) { |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 2162 | if (transit == TRANSIT_TASK_OPEN && isTransitionEqual(TRANSIT_TASK_CLOSE)) { |
| 2163 | // Opening a new task always supersedes a close for the anim. |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2164 | setAppTransition(transit, flags); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 2165 | } else if (transit == TRANSIT_ACTIVITY_OPEN |
| 2166 | && isTransitionEqual(TRANSIT_ACTIVITY_CLOSE)) { |
| 2167 | // Opening a new activity always supersedes a close for the anim. |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2168 | setAppTransition(transit, flags); |
Jorim Jaggi | cecf424 | 2018-02-21 18:46:53 +0100 | [diff] [blame] | 2169 | } else if (isTaskTransit(transit) && isActivityTransit(mNextAppTransition)) { |
| 2170 | // Task animations always supersede activity animations, because if we have both, it |
| 2171 | // usually means that activity transition were just trampoline activities. |
| 2172 | setAppTransition(transit, flags); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 2173 | } |
| 2174 | } |
| 2175 | boolean prepared = prepare(); |
| 2176 | if (isTransitionSet()) { |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 2177 | mService.mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 2178 | mService.mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, APP_TRANSITION_TIMEOUT_MS); |
Filip Gruszczynski | 24966d4 | 2015-09-05 15:00:00 -0700 | [diff] [blame] | 2179 | } |
| 2180 | return prepared; |
| 2181 | } |
Winson | b202476 | 2016-04-05 17:32:30 -0700 | [diff] [blame] | 2182 | |
| 2183 | /** |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2184 | * @return true if {@param transit} is representing a transition in which Keyguard is going |
| 2185 | * away, false otherwise |
| 2186 | */ |
| 2187 | public static boolean isKeyguardGoingAwayTransit(int transit) { |
| 2188 | return transit == TRANSIT_KEYGUARD_GOING_AWAY |
| 2189 | || transit == TRANSIT_KEYGUARD_GOING_AWAY_ON_WALLPAPER; |
| 2190 | } |
| 2191 | |
| 2192 | private static boolean isKeyguardTransit(int transit) { |
| 2193 | return isKeyguardGoingAwayTransit(transit) || transit == TRANSIT_KEYGUARD_OCCLUDE |
| 2194 | || transit == TRANSIT_KEYGUARD_UNOCCLUDE; |
| 2195 | } |
| 2196 | |
Jorim Jaggi | 98a9d20 | 2018-03-26 16:17:07 +0200 | [diff] [blame^] | 2197 | static boolean isTaskTransit(int transit) { |
| 2198 | return isTaskOpenTransit(transit) |
Jorim Jaggi | cecf424 | 2018-02-21 18:46:53 +0100 | [diff] [blame] | 2199 | || transit == TRANSIT_TASK_CLOSE |
Jorim Jaggi | cecf424 | 2018-02-21 18:46:53 +0100 | [diff] [blame] | 2200 | || transit == TRANSIT_TASK_TO_BACK |
Jorim Jaggi | cecf424 | 2018-02-21 18:46:53 +0100 | [diff] [blame] | 2201 | || transit == TRANSIT_TASK_IN_PLACE; |
| 2202 | } |
| 2203 | |
Jorim Jaggi | 98a9d20 | 2018-03-26 16:17:07 +0200 | [diff] [blame^] | 2204 | private static boolean isTaskOpenTransit(int transit) { |
| 2205 | return transit == TRANSIT_TASK_OPEN |
| 2206 | || transit == TRANSIT_TASK_OPEN_BEHIND |
| 2207 | || transit == TRANSIT_TASK_TO_FRONT; |
| 2208 | } |
| 2209 | |
| 2210 | static boolean isActivityTransit(int transit) { |
Jorim Jaggi | cecf424 | 2018-02-21 18:46:53 +0100 | [diff] [blame] | 2211 | return transit == TRANSIT_ACTIVITY_OPEN |
| 2212 | || transit == TRANSIT_ACTIVITY_CLOSE |
| 2213 | || transit == TRANSIT_ACTIVITY_RELAUNCH; |
| 2214 | } |
| 2215 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2216 | /** |
Manu Cornet | d737680 | 2017-01-13 13:44:07 -0800 | [diff] [blame] | 2217 | * @return whether the transition should show the thumbnail being scaled down. |
| 2218 | */ |
| 2219 | private boolean shouldScaleDownThumbnailTransition(int uiMode, int orientation) { |
Sid Soundararajan | 0e88d32 | 2017-03-07 15:37:30 -0800 | [diff] [blame] | 2220 | return mGridLayoutRecentsEnabled |
Manu Cornet | d737680 | 2017-01-13 13:44:07 -0800 | [diff] [blame] | 2221 | || orientation == Configuration.ORIENTATION_PORTRAIT; |
| 2222 | } |
Craig Mautner | 164d4bb | 2012-11-26 13:51:23 -0800 | [diff] [blame] | 2223 | } |