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