Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 19 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; |
| 20 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 21 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
| 22 | |
| 23 | import android.animation.Animator; |
| 24 | import android.animation.ValueAnimator; |
Winson Chung | baa7b72 | 2017-03-03 21:33:44 -0800 | [diff] [blame] | 25 | import android.content.Context; |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 26 | import android.graphics.Rect; |
Wale Ogunwale | 2ba7129 | 2016-05-05 09:16:47 -0700 | [diff] [blame] | 27 | import android.os.Handler; |
Robert Carr | f9aa2a9 | 2016-04-26 14:22:19 -0700 | [diff] [blame] | 28 | import android.os.IBinder; |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 29 | import android.os.Debug; |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 30 | import android.util.ArrayMap; |
| 31 | import android.util.Slog; |
Winson Chung | baa7b72 | 2017-03-03 21:33:44 -0800 | [diff] [blame] | 32 | import android.view.animation.AnimationUtils; |
| 33 | import android.view.animation.Interpolator; |
Robert Carr | f9aa2a9 | 2016-04-26 14:22:19 -0700 | [diff] [blame] | 34 | import android.view.WindowManagerInternal; |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Enables animating bounds of objects. |
| 38 | * |
| 39 | * In multi-window world bounds of both stack and tasks can change. When we need these bounds to |
| 40 | * change smoothly and not require the app to relaunch (e.g. because it handles resizes and |
| 41 | * relaunching it would cause poorer experience), these class provides a way to directly animate |
| 42 | * the bounds of the resized object. |
| 43 | * |
| 44 | * The object that is resized needs to implement {@link AnimateBoundsUser} interface. |
Wale Ogunwale | 2ba7129 | 2016-05-05 09:16:47 -0700 | [diff] [blame] | 45 | * |
| 46 | * NOTE: All calls to methods in this class should be done on the UI thread |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 47 | */ |
| 48 | public class BoundsAnimationController { |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 49 | private static final boolean DEBUG_LOCAL = false; |
| 50 | private static final boolean DEBUG = DEBUG_LOCAL || DEBUG_ANIM; |
| 51 | private static final String TAG = TAG_WITH_CLASS_NAME || DEBUG_LOCAL |
| 52 | ? "BoundsAnimationController" : TAG_WM; |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 53 | private static final int DEBUG_ANIMATION_SLOW_DOWN_FACTOR = 1; |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 54 | |
Winson Chung | baa7b72 | 2017-03-03 21:33:44 -0800 | [diff] [blame] | 55 | private static final int DEFAULT_TRANSITION_DURATION = 425; |
| 56 | |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 57 | // Only accessed on UI thread. |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 58 | private ArrayMap<AnimateBoundsUser, BoundsAnimator> mRunningAnimations = new ArrayMap<>(); |
| 59 | |
Wale Ogunwale | 2ba7129 | 2016-05-05 09:16:47 -0700 | [diff] [blame] | 60 | private final class AppTransitionNotifier |
| 61 | extends WindowManagerInternal.AppTransitionListener implements Runnable { |
Robert Carr | f9aa2a9 | 2016-04-26 14:22:19 -0700 | [diff] [blame] | 62 | |
Wale Ogunwale | 2ba7129 | 2016-05-05 09:16:47 -0700 | [diff] [blame] | 63 | public void onAppTransitionCancelledLocked() { |
| 64 | animationFinished(); |
| 65 | } |
| 66 | public void onAppTransitionFinishedLocked(IBinder token) { |
| 67 | animationFinished(); |
| 68 | } |
| 69 | private void animationFinished() { |
| 70 | if (mFinishAnimationAfterTransition) { |
| 71 | mHandler.removeCallbacks(this); |
| 72 | // This might end up calling into activity manager which will be bad since we have the |
| 73 | // window manager lock held at this point. Post a message to take care of the processing |
| 74 | // so we don't deadlock. |
| 75 | mHandler.post(this); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public void run() { |
| 81 | for (int i = 0; i < mRunningAnimations.size(); i++) { |
| 82 | final BoundsAnimator b = mRunningAnimations.valueAt(i); |
| 83 | b.onAnimationEnd(null); |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | private final Handler mHandler; |
Robert Carr | f9aa2a9 | 2016-04-26 14:22:19 -0700 | [diff] [blame] | 89 | private final AppTransition mAppTransition; |
Wale Ogunwale | 2ba7129 | 2016-05-05 09:16:47 -0700 | [diff] [blame] | 90 | private final AppTransitionNotifier mAppTransitionNotifier = new AppTransitionNotifier(); |
Winson Chung | baa7b72 | 2017-03-03 21:33:44 -0800 | [diff] [blame] | 91 | private final Interpolator mFastOutSlowInInterpolator; |
Robert Carr | f9aa2a9 | 2016-04-26 14:22:19 -0700 | [diff] [blame] | 92 | private boolean mFinishAnimationAfterTransition = false; |
| 93 | |
Winson Chung | baa7b72 | 2017-03-03 21:33:44 -0800 | [diff] [blame] | 94 | BoundsAnimationController(Context context, AppTransition transition, Handler handler) { |
Wale Ogunwale | 2ba7129 | 2016-05-05 09:16:47 -0700 | [diff] [blame] | 95 | mHandler = handler; |
Robert Carr | f9aa2a9 | 2016-04-26 14:22:19 -0700 | [diff] [blame] | 96 | mAppTransition = transition; |
| 97 | mAppTransition.registerListenerLocked(mAppTransitionNotifier); |
Winson Chung | baa7b72 | 2017-03-03 21:33:44 -0800 | [diff] [blame] | 98 | mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context, |
| 99 | com.android.internal.R.interpolator.fast_out_slow_in); |
Robert Carr | f9aa2a9 | 2016-04-26 14:22:19 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 102 | private final class BoundsAnimator extends ValueAnimator |
| 103 | implements ValueAnimator.AnimatorUpdateListener, ValueAnimator.AnimatorListener { |
| 104 | private final AnimateBoundsUser mTarget; |
Winson Chung | 84a3834 | 2016-11-08 16:15:10 -0800 | [diff] [blame] | 105 | private final Rect mFrom = new Rect(); |
| 106 | private final Rect mTo = new Rect(); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 107 | private final Rect mTmpRect = new Rect(); |
| 108 | private final Rect mTmpTaskBounds = new Rect(); |
Filip Gruszczynski | c17d8b7 | 2016-02-03 16:52:59 -0800 | [diff] [blame] | 109 | private final boolean mMoveToFullScreen; |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 110 | // True if this this animation was cancelled and will be replaced the another animation from |
| 111 | // the same {@link #AnimateBoundsUser} target. |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame^] | 112 | private boolean mSkipAnimationEnd; |
| 113 | // True if this animation replaced a previous animation of the same |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 114 | // {@link #AnimateBoundsUser} target. |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame^] | 115 | private final boolean mSkipAnimationStart; |
| 116 | // True if this animation is not replacing a previous animation, or if the previous |
| 117 | // animation is animating to a different fullscreen state than the current animation. |
| 118 | // We use this to ensure that we always provide a consistent set/order of callbacks when we |
| 119 | // transition to/from PiP. |
| 120 | private final boolean mAnimatingToNewFullscreenState; |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 121 | |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 122 | // Depending on whether we are animating from |
| 123 | // a smaller to a larger size |
| 124 | private final int mFrozenTaskWidth; |
| 125 | private final int mFrozenTaskHeight; |
| 126 | |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 127 | BoundsAnimator(AnimateBoundsUser target, Rect from, Rect to, boolean moveToFullScreen, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame^] | 128 | boolean replacingExistingAnimation, boolean animatingToNewFullscreenState) { |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 129 | super(); |
| 130 | mTarget = target; |
Winson Chung | 84a3834 | 2016-11-08 16:15:10 -0800 | [diff] [blame] | 131 | mFrom.set(from); |
| 132 | mTo.set(to); |
Filip Gruszczynski | c17d8b7 | 2016-02-03 16:52:59 -0800 | [diff] [blame] | 133 | mMoveToFullScreen = moveToFullScreen; |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame^] | 134 | mSkipAnimationStart = replacingExistingAnimation; |
| 135 | mAnimatingToNewFullscreenState = animatingToNewFullscreenState; |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 136 | addUpdateListener(this); |
| 137 | addListener(this); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 138 | |
| 139 | // If we are animating from smaller to larger, we want to change the task bounds |
| 140 | // to their final size immediately so we can use scaling to make the window |
| 141 | // larger. Likewise if we are going from bigger to smaller, we want to wait until |
| 142 | // the end so we don't have to upscale from the smaller finished size. |
| 143 | if (animatingToLargerSize()) { |
| 144 | mFrozenTaskWidth = mTo.width(); |
| 145 | mFrozenTaskHeight = mTo.height(); |
| 146 | } else { |
| 147 | mFrozenTaskWidth = mFrom.width(); |
| 148 | mFrozenTaskHeight = mFrom.height(); |
| 149 | } |
| 150 | } |
| 151 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame^] | 152 | @Override |
| 153 | public void onAnimationStart(Animator animation) { |
| 154 | if (DEBUG) Slog.d(TAG, "onAnimationStart: mTarget=" + mTarget |
| 155 | + " mSkipAnimationStart=" + mSkipAnimationStart); |
| 156 | mFinishAnimationAfterTransition = false; |
| 157 | mTmpRect.set(mFrom.left, mFrom.top, mFrom.left + mFrozenTaskWidth, |
| 158 | mFrom.top + mFrozenTaskHeight); |
| 159 | |
| 160 | // Ensure that we have prepared the target for animation before |
| 161 | // we trigger any size changes, so it can swap surfaces |
| 162 | // in to appropriate modes, or do as it wishes otherwise. |
| 163 | if (!mSkipAnimationStart) { |
| 164 | mTarget.onAnimationStart(mMoveToFullScreen); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 165 | } |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame^] | 166 | |
| 167 | // If we are animating to a new fullscreen state (either to/from fullscreen), then |
| 168 | // notify the target of the change with the new frozen task bounds |
| 169 | if (mAnimatingToNewFullscreenState) { |
| 170 | mTarget.updatePictureInPictureMode(mMoveToFullScreen ? null : mTo); |
| 171 | } |
| 172 | |
| 173 | // Immediately update the task bounds if they have to become larger, but preserve |
| 174 | // the starting position so we don't jump at the beginning of the animation. |
| 175 | if (animatingToLargerSize()) { |
| 176 | mTarget.setPinnedStackSize(mFrom, mTmpRect); |
| 177 | } |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | @Override |
| 181 | public void onAnimationUpdate(ValueAnimator animation) { |
| 182 | final float value = (Float) animation.getAnimatedValue(); |
| 183 | final float remains = 1 - value; |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 184 | mTmpRect.left = (int) (mFrom.left * remains + mTo.left * value + 0.5f); |
| 185 | mTmpRect.top = (int) (mFrom.top * remains + mTo.top * value + 0.5f); |
| 186 | mTmpRect.right = (int) (mFrom.right * remains + mTo.right * value + 0.5f); |
| 187 | mTmpRect.bottom = (int) (mFrom.bottom * remains + mTo.bottom * value + 0.5f); |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 188 | if (DEBUG) Slog.d(TAG, "animateUpdate: mTarget=" + mTarget + " mBounds=" |
| 189 | + mTmpRect + " from=" + mFrom + " mTo=" + mTo + " value=" + value |
| 190 | + " remains=" + remains); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 191 | |
Robert Carr | c729460 | 2016-05-13 11:32:05 -0700 | [diff] [blame] | 192 | mTmpTaskBounds.set(mTmpRect.left, mTmpRect.top, |
| 193 | mTmpRect.left + mFrozenTaskWidth, mTmpRect.top + mFrozenTaskHeight); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 194 | |
Robert Carr | c729460 | 2016-05-13 11:32:05 -0700 | [diff] [blame] | 195 | if (!mTarget.setPinnedStackSize(mTmpRect, mTmpTaskBounds)) { |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 196 | // Whoops, the target doesn't feel like animating anymore. Let's immediately finish |
| 197 | // any further animation. |
| 198 | animation.cancel(); |
| 199 | } |
| 200 | } |
| 201 | |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 202 | @Override |
| 203 | public void onAnimationEnd(Animator animation) { |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 204 | if (DEBUG) Slog.d(TAG, "onAnimationEnd: mTarget=" + mTarget |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame^] | 205 | + " mMoveToFullScreen=" + mMoveToFullScreen |
| 206 | + " mSkipAnimationEnd=" + mSkipAnimationEnd); |
Jaewan Kim | b003364 | 2016-04-22 18:41:37 +0900 | [diff] [blame] | 207 | |
Robert Carr | f9aa2a9 | 2016-04-26 14:22:19 -0700 | [diff] [blame] | 208 | // There could be another animation running. For example in the |
| 209 | // move to fullscreen case, recents will also be closing while the |
| 210 | // previous task will be taking its place in the fullscreen stack. |
| 211 | // we have to ensure this is completed before we finish the animation |
| 212 | // and take our place in the fullscreen stack. |
| 213 | if (mAppTransition.isRunning() && !mFinishAnimationAfterTransition) { |
| 214 | mFinishAnimationAfterTransition = true; |
| 215 | return; |
| 216 | } |
| 217 | |
Robert Carr | c729460 | 2016-05-13 11:32:05 -0700 | [diff] [blame] | 218 | finishAnimation(); |
| 219 | |
| 220 | mTarget.setPinnedStackSize(mTo, null); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame^] | 221 | if (mMoveToFullScreen && !mSkipAnimationEnd) { |
Filip Gruszczynski | c17d8b7 | 2016-02-03 16:52:59 -0800 | [diff] [blame] | 222 | mTarget.moveToFullscreen(); |
| 223 | } |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | @Override |
| 227 | public void onAnimationCancel(Animator animation) { |
| 228 | finishAnimation(); |
| 229 | } |
| 230 | |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 231 | @Override |
| 232 | public void cancel() { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame^] | 233 | mSkipAnimationEnd = true; |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 234 | if (DEBUG) Slog.d(TAG, "cancel: willReplace mTarget=" + mTarget); |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 235 | super.cancel(); |
| 236 | } |
| 237 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 238 | /** Returns true if the animation target is the same as the input bounds. */ |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame^] | 239 | boolean isAnimatingTo(Rect bounds) { |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 240 | return mTo.equals(bounds); |
| 241 | } |
| 242 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame^] | 243 | private boolean animatingToLargerSize() { |
| 244 | if (mFrom.width() * mFrom.height() > mTo.width() * mTo.height()) { |
| 245 | return false; |
| 246 | } |
| 247 | return true; |
| 248 | } |
| 249 | |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 250 | private void finishAnimation() { |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 251 | if (DEBUG) Slog.d(TAG, "finishAnimation: mTarget=" + mTarget |
| 252 | + " callers" + Debug.getCallers(2)); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame^] | 253 | if (!mSkipAnimationEnd) { |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 254 | mTarget.onAnimationEnd(); |
| 255 | } |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 256 | removeListener(this); |
| 257 | removeUpdateListener(this); |
| 258 | mRunningAnimations.remove(mTarget); |
| 259 | } |
| 260 | |
| 261 | @Override |
| 262 | public void onAnimationRepeat(Animator animation) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame^] | 263 | // Do nothing |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
| 267 | public interface AnimateBoundsUser { |
| 268 | /** |
| 269 | * Asks the target to directly (without any intermediate steps, like scheduling animation) |
| 270 | * resize its bounds. |
| 271 | * |
| 272 | * @return Whether the target still wants to be animated and successfully finished the |
| 273 | * operation. If it returns false, the animation will immediately be cancelled. The target |
| 274 | * should return false when something abnormal happened, e.g. it was completely removed |
| 275 | * from the hierarchy and is not valid anymore. |
| 276 | */ |
| 277 | boolean setSize(Rect bounds); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 278 | /** |
| 279 | * Behaves as setSize, but freezes the bounds of any tasks in the target at taskBounds, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame^] | 280 | * to allow for more flexibility during resizing. Only works for the pinned stack at the |
| 281 | * moment. |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 282 | */ |
| 283 | boolean setPinnedStackSize(Rect bounds, Rect taskBounds); |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 284 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame^] | 285 | /** |
| 286 | * Callback for the target to inform it that the animation has started, so it can do some |
| 287 | * necessary preparation. |
| 288 | */ |
Robert Carr | 7e4c90e | 2017-02-15 19:52:38 -0800 | [diff] [blame] | 289 | void onAnimationStart(boolean toFullscreen); |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 290 | |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 291 | /** |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame^] | 292 | * Callback for the target to inform it that the animation is going to a new fullscreen |
| 293 | * state and should update the picture-in-picture mode accordingly. |
| 294 | * |
| 295 | * @param targetStackBounds the target stack bounds we are animating to, can be null if |
| 296 | * we are animating to fullscreen |
| 297 | */ |
| 298 | void updatePictureInPictureMode(Rect targetStackBounds); |
| 299 | |
| 300 | /** |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 301 | * Callback for the target to inform it that the animation has ended, so it can do some |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 302 | * necessary cleanup. |
| 303 | */ |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 304 | void onAnimationEnd(); |
Filip Gruszczynski | c17d8b7 | 2016-02-03 16:52:59 -0800 | [diff] [blame] | 305 | |
| 306 | void moveToFullscreen(); |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 307 | } |
| 308 | |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 309 | void animateBounds(final AnimateBoundsUser target, Rect from, Rect to, int animationDuration, |
| 310 | boolean moveToFullscreen) { |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 311 | final BoundsAnimator existing = mRunningAnimations.get(target); |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 312 | final boolean replacing = existing != null; |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame^] | 313 | final boolean animatingToNewFullscreenState = (existing == null) || |
| 314 | (existing.mMoveToFullScreen != moveToFullscreen); |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 315 | |
| 316 | if (DEBUG) Slog.d(TAG, "animateBounds: target=" + target + " from=" + from + " to=" + to |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame^] | 317 | + " moveToFullscreen=" + moveToFullscreen + " replacing=" + replacing |
| 318 | + " animatingToNewFullscreenState=" + animatingToNewFullscreenState); |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 319 | |
Wale Ogunwale | ce14452 | 2016-02-05 22:51:01 -0800 | [diff] [blame] | 320 | if (replacing) { |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 321 | if (existing.isAnimatingTo(to)) { |
| 322 | // Just les the current animation complete if it has the same destination as the |
| 323 | // one we are trying to start. |
| 324 | if (DEBUG) Slog.d(TAG, "animateBounds: same destination as existing=" + existing |
| 325 | + " ignoring..."); |
| 326 | return; |
| 327 | } |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 328 | existing.cancel(); |
| 329 | } |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame^] | 330 | final BoundsAnimator animator = new BoundsAnimator(target, from, to, moveToFullscreen, |
| 331 | replacing, animatingToNewFullscreenState); |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 332 | mRunningAnimations.put(target, animator); |
| 333 | animator.setFloatValues(0f, 1f); |
Wale Ogunwale | e75a9ad | 2016-03-18 20:43:49 -0700 | [diff] [blame] | 334 | animator.setDuration((animationDuration != -1 ? animationDuration |
Winson Chung | baa7b72 | 2017-03-03 21:33:44 -0800 | [diff] [blame] | 335 | : DEFAULT_TRANSITION_DURATION) * DEBUG_ANIMATION_SLOW_DOWN_FACTOR); |
| 336 | animator.setInterpolator(mFastOutSlowInInterpolator); |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 337 | animator.start(); |
| 338 | } |
| 339 | } |