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