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