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