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