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