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