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