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