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