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