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