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