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