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