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