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