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