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