Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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.systemui.pip; |
| 18 | |
| 19 | import android.animation.Animator; |
| 20 | import android.animation.ValueAnimator; |
| 21 | import android.annotation.IntDef; |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.graphics.Rect; |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 24 | import android.view.SurfaceControl; |
| 25 | import android.view.animation.AnimationUtils; |
| 26 | import android.view.animation.Interpolator; |
| 27 | |
| 28 | import com.android.internal.annotations.VisibleForTesting; |
| 29 | |
| 30 | import java.lang.annotation.Retention; |
| 31 | import java.lang.annotation.RetentionPolicy; |
| 32 | |
Hongwei Wang | ec3cb3c | 2020-03-09 10:43:21 -0700 | [diff] [blame] | 33 | import javax.inject.Inject; |
| 34 | |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 35 | /** |
| 36 | * Controller class of PiP animations (both from and to PiP mode). |
| 37 | */ |
| 38 | public class PipAnimationController { |
| 39 | private static final float FRACTION_START = 0f; |
| 40 | private static final float FRACTION_END = 1f; |
| 41 | |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 42 | public static final int ANIM_TYPE_BOUNDS = 0; |
| 43 | public static final int ANIM_TYPE_ALPHA = 1; |
| 44 | |
| 45 | @IntDef(prefix = { "ANIM_TYPE_" }, value = { |
| 46 | ANIM_TYPE_BOUNDS, |
| 47 | ANIM_TYPE_ALPHA |
| 48 | }) |
| 49 | @Retention(RetentionPolicy.SOURCE) |
| 50 | public @interface AnimationType {} |
| 51 | |
Hongwei Wang | 221fe3d | 2020-03-26 13:13:04 -0700 | [diff] [blame^] | 52 | public static final int TRANSITION_DIRECTION_NONE = 0; |
| 53 | public static final int TRANSITION_DIRECTION_SAME = 1; |
| 54 | public static final int TRANSITION_DIRECTION_TO_PIP = 2; |
| 55 | public static final int TRANSITION_DIRECTION_TO_FULLSCREEN = 3; |
Hongwei Wang | df8bb00 | 2020-03-03 17:41:02 -0800 | [diff] [blame] | 56 | |
| 57 | @IntDef(prefix = { "TRANSITION_DIRECTION_" }, value = { |
| 58 | TRANSITION_DIRECTION_NONE, |
| 59 | TRANSITION_DIRECTION_SAME, |
| 60 | TRANSITION_DIRECTION_TO_PIP, |
| 61 | TRANSITION_DIRECTION_TO_FULLSCREEN |
| 62 | }) |
| 63 | @Retention(RetentionPolicy.SOURCE) |
Hongwei Wang | 221fe3d | 2020-03-26 13:13:04 -0700 | [diff] [blame^] | 64 | public @interface TransitionDirection {} |
Hongwei Wang | df8bb00 | 2020-03-03 17:41:02 -0800 | [diff] [blame] | 65 | |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 66 | private final Interpolator mFastOutSlowInInterpolator; |
Hongwei Wang | ec3cb3c | 2020-03-09 10:43:21 -0700 | [diff] [blame] | 67 | private final PipSurfaceTransactionHelper mSurfaceTransactionHelper; |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 68 | |
| 69 | private PipTransitionAnimator mCurrentAnimator; |
| 70 | |
Hongwei Wang | ec3cb3c | 2020-03-09 10:43:21 -0700 | [diff] [blame] | 71 | @Inject |
| 72 | PipAnimationController(Context context, PipSurfaceTransactionHelper helper) { |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 73 | mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context, |
| 74 | com.android.internal.R.interpolator.fast_out_slow_in); |
Hongwei Wang | ec3cb3c | 2020-03-09 10:43:21 -0700 | [diff] [blame] | 75 | mSurfaceTransactionHelper = helper; |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 76 | } |
| 77 | |
Hongwei Wang | df8bb00 | 2020-03-03 17:41:02 -0800 | [diff] [blame] | 78 | @SuppressWarnings("unchecked") |
| 79 | PipTransitionAnimator getAnimator(SurfaceControl leash, |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 80 | Rect destinationBounds, float alphaStart, float alphaEnd) { |
| 81 | if (mCurrentAnimator == null) { |
| 82 | mCurrentAnimator = setupPipTransitionAnimator( |
Hongwei Wang | df8bb00 | 2020-03-03 17:41:02 -0800 | [diff] [blame] | 83 | PipTransitionAnimator.ofAlpha(leash, destinationBounds, alphaStart, alphaEnd)); |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 84 | } else if (mCurrentAnimator.getAnimationType() == ANIM_TYPE_ALPHA |
| 85 | && mCurrentAnimator.isRunning()) { |
| 86 | mCurrentAnimator.updateEndValue(alphaEnd); |
| 87 | } else { |
| 88 | mCurrentAnimator.cancel(); |
| 89 | mCurrentAnimator = setupPipTransitionAnimator( |
Hongwei Wang | df8bb00 | 2020-03-03 17:41:02 -0800 | [diff] [blame] | 90 | PipTransitionAnimator.ofAlpha(leash, destinationBounds, alphaStart, alphaEnd)); |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 91 | } |
| 92 | return mCurrentAnimator; |
| 93 | } |
| 94 | |
Hongwei Wang | df8bb00 | 2020-03-03 17:41:02 -0800 | [diff] [blame] | 95 | @SuppressWarnings("unchecked") |
| 96 | PipTransitionAnimator getAnimator(SurfaceControl leash, Rect startBounds, Rect endBounds) { |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 97 | if (mCurrentAnimator == null) { |
| 98 | mCurrentAnimator = setupPipTransitionAnimator( |
Hongwei Wang | df8bb00 | 2020-03-03 17:41:02 -0800 | [diff] [blame] | 99 | PipTransitionAnimator.ofBounds(leash, startBounds, endBounds)); |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 100 | } else if (mCurrentAnimator.getAnimationType() == ANIM_TYPE_BOUNDS |
| 101 | && mCurrentAnimator.isRunning()) { |
| 102 | mCurrentAnimator.setDestinationBounds(endBounds); |
| 103 | // construct new Rect instances in case they are recycled |
| 104 | mCurrentAnimator.updateEndValue(new Rect(endBounds)); |
| 105 | } else { |
| 106 | mCurrentAnimator.cancel(); |
| 107 | mCurrentAnimator = setupPipTransitionAnimator( |
Hongwei Wang | df8bb00 | 2020-03-03 17:41:02 -0800 | [diff] [blame] | 108 | PipTransitionAnimator.ofBounds(leash, startBounds, endBounds)); |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 109 | } |
| 110 | return mCurrentAnimator; |
| 111 | } |
| 112 | |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 113 | private PipTransitionAnimator setupPipTransitionAnimator(PipTransitionAnimator animator) { |
Hongwei Wang | ec3cb3c | 2020-03-09 10:43:21 -0700 | [diff] [blame] | 114 | animator.setSurfaceTransactionHelper(mSurfaceTransactionHelper); |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 115 | animator.setInterpolator(mFastOutSlowInInterpolator); |
| 116 | animator.setFloatValues(FRACTION_START, FRACTION_END); |
| 117 | return animator; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Additional callback interface for PiP animation |
| 122 | */ |
| 123 | public static class PipAnimationCallback { |
| 124 | /** |
| 125 | * Called when PiP animation is started. |
| 126 | */ |
Winson Chung | 5570147 | 2020-03-04 19:30:30 -0800 | [diff] [blame] | 127 | public void onPipAnimationStart(PipTransitionAnimator animator) {} |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 128 | |
| 129 | /** |
| 130 | * Called when PiP animation is ended. |
| 131 | */ |
Winson Chung | 5570147 | 2020-03-04 19:30:30 -0800 | [diff] [blame] | 132 | public void onPipAnimationEnd(SurfaceControl.Transaction tx, |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 133 | PipTransitionAnimator animator) {} |
| 134 | |
| 135 | /** |
| 136 | * Called when PiP animation is cancelled. |
| 137 | */ |
Winson Chung | 5570147 | 2020-03-04 19:30:30 -0800 | [diff] [blame] | 138 | public void onPipAnimationCancel(PipTransitionAnimator animator) {} |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Animator for PiP transition animation which supports both alpha and bounds animation. |
| 143 | * @param <T> Type of property to animate, either alpha (float) or bounds (Rect) |
| 144 | */ |
| 145 | public abstract static class PipTransitionAnimator<T> extends ValueAnimator implements |
| 146 | ValueAnimator.AnimatorUpdateListener, |
| 147 | ValueAnimator.AnimatorListener { |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 148 | private final SurfaceControl mLeash; |
| 149 | private final @AnimationType int mAnimationType; |
| 150 | private final Rect mDestinationBounds = new Rect(); |
| 151 | |
| 152 | private T mStartValue; |
| 153 | private T mEndValue; |
| 154 | private T mCurrentValue; |
| 155 | private PipAnimationCallback mPipAnimationCallback; |
Hongwei Wang | ec3cb3c | 2020-03-09 10:43:21 -0700 | [diff] [blame] | 156 | private PipSurfaceTransactionHelper.SurfaceControlTransactionFactory |
| 157 | mSurfaceControlTransactionFactory; |
| 158 | private PipSurfaceTransactionHelper mSurfaceTransactionHelper; |
Hongwei Wang | df8bb00 | 2020-03-03 17:41:02 -0800 | [diff] [blame] | 159 | private @TransitionDirection int mTransitionDirection; |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 160 | |
Hongwei Wang | df8bb00 | 2020-03-03 17:41:02 -0800 | [diff] [blame] | 161 | private PipTransitionAnimator(SurfaceControl leash, @AnimationType int animationType, |
| 162 | Rect destinationBounds, T startValue, T endValue) { |
Winson Chung | 5570147 | 2020-03-04 19:30:30 -0800 | [diff] [blame] | 163 | mLeash = leash; |
| 164 | mAnimationType = animationType; |
| 165 | mDestinationBounds.set(destinationBounds); |
| 166 | mStartValue = startValue; |
| 167 | mEndValue = endValue; |
| 168 | addListener(this); |
| 169 | addUpdateListener(this); |
| 170 | mSurfaceControlTransactionFactory = SurfaceControl.Transaction::new; |
Hongwei Wang | df8bb00 | 2020-03-03 17:41:02 -0800 | [diff] [blame] | 171 | mTransitionDirection = TRANSITION_DIRECTION_NONE; |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | @Override |
| 175 | public void onAnimationStart(Animator animation) { |
| 176 | mCurrentValue = mStartValue; |
Hongwei Wang | 09c1f04 | 2020-03-18 13:47:45 -0700 | [diff] [blame] | 177 | onStartTransaction(mLeash, newSurfaceControlTransaction()); |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 178 | if (mPipAnimationCallback != null) { |
Winson Chung | 5570147 | 2020-03-04 19:30:30 -0800 | [diff] [blame] | 179 | mPipAnimationCallback.onPipAnimationStart(this); |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | |
| 183 | @Override |
| 184 | public void onAnimationUpdate(ValueAnimator animation) { |
| 185 | applySurfaceControlTransaction(mLeash, newSurfaceControlTransaction(), |
| 186 | animation.getAnimatedFraction()); |
| 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public void onAnimationEnd(Animator animation) { |
| 191 | mCurrentValue = mEndValue; |
| 192 | final SurfaceControl.Transaction tx = newSurfaceControlTransaction(); |
Hongwei Wang | 09c1f04 | 2020-03-18 13:47:45 -0700 | [diff] [blame] | 193 | onEndTransaction(mLeash, tx); |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 194 | if (mPipAnimationCallback != null) { |
Winson Chung | 5570147 | 2020-03-04 19:30:30 -0800 | [diff] [blame] | 195 | mPipAnimationCallback.onPipAnimationEnd(tx, this); |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | |
| 199 | @Override |
| 200 | public void onAnimationCancel(Animator animation) { |
| 201 | if (mPipAnimationCallback != null) { |
Winson Chung | 5570147 | 2020-03-04 19:30:30 -0800 | [diff] [blame] | 202 | mPipAnimationCallback.onPipAnimationCancel(this); |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | |
| 206 | @Override public void onAnimationRepeat(Animator animation) {} |
| 207 | |
| 208 | @AnimationType int getAnimationType() { |
| 209 | return mAnimationType; |
| 210 | } |
| 211 | |
| 212 | PipTransitionAnimator<T> setPipAnimationCallback(PipAnimationCallback callback) { |
| 213 | mPipAnimationCallback = callback; |
| 214 | return this; |
| 215 | } |
| 216 | |
Hongwei Wang | df8bb00 | 2020-03-03 17:41:02 -0800 | [diff] [blame] | 217 | @TransitionDirection int getTransitionDirection() { |
| 218 | return mTransitionDirection; |
| 219 | } |
| 220 | |
| 221 | PipTransitionAnimator<T> setTransitionDirection(@TransitionDirection int direction) { |
| 222 | if (direction != TRANSITION_DIRECTION_SAME) { |
| 223 | mTransitionDirection = direction; |
| 224 | } |
| 225 | return this; |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | T getStartValue() { |
| 229 | return mStartValue; |
| 230 | } |
| 231 | |
| 232 | T getEndValue() { |
| 233 | return mEndValue; |
| 234 | } |
| 235 | |
| 236 | Rect getDestinationBounds() { |
| 237 | return mDestinationBounds; |
| 238 | } |
| 239 | |
| 240 | void setDestinationBounds(Rect destinationBounds) { |
| 241 | mDestinationBounds.set(destinationBounds); |
| 242 | } |
| 243 | |
| 244 | void setCurrentValue(T value) { |
| 245 | mCurrentValue = value; |
| 246 | } |
| 247 | |
Hongwei Wang | df8bb00 | 2020-03-03 17:41:02 -0800 | [diff] [blame] | 248 | boolean shouldApplyCornerRadius() { |
| 249 | return mTransitionDirection != TRANSITION_DIRECTION_TO_FULLSCREEN; |
| 250 | } |
| 251 | |
Hongwei Wang | 09c1f04 | 2020-03-18 13:47:45 -0700 | [diff] [blame] | 252 | boolean inScaleTransition() { |
| 253 | if (mAnimationType != ANIM_TYPE_BOUNDS) return false; |
| 254 | final int direction = getTransitionDirection(); |
| 255 | return direction != TRANSITION_DIRECTION_TO_FULLSCREEN |
| 256 | && direction != TRANSITION_DIRECTION_TO_PIP; |
| 257 | } |
| 258 | |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 259 | /** |
| 260 | * Updates the {@link #mEndValue}. |
| 261 | * |
| 262 | * NOTE: Do not forget to call {@link #setDestinationBounds(Rect)} for bounds animation. |
| 263 | * This is typically used when we receive a shelf height adjustment during the bounds |
| 264 | * animation. In which case we can update the end bounds and keep the existing animation |
| 265 | * running instead of cancelling it. |
| 266 | */ |
| 267 | void updateEndValue(T endValue) { |
| 268 | mEndValue = endValue; |
| 269 | mStartValue = mCurrentValue; |
| 270 | } |
| 271 | |
| 272 | SurfaceControl.Transaction newSurfaceControlTransaction() { |
| 273 | return mSurfaceControlTransactionFactory.getTransaction(); |
| 274 | } |
| 275 | |
| 276 | @VisibleForTesting |
Hongwei Wang | ec3cb3c | 2020-03-09 10:43:21 -0700 | [diff] [blame] | 277 | void setSurfaceControlTransactionFactory( |
| 278 | PipSurfaceTransactionHelper.SurfaceControlTransactionFactory factory) { |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 279 | mSurfaceControlTransactionFactory = factory; |
| 280 | } |
| 281 | |
Hongwei Wang | ec3cb3c | 2020-03-09 10:43:21 -0700 | [diff] [blame] | 282 | PipSurfaceTransactionHelper getSurfaceTransactionHelper() { |
| 283 | return mSurfaceTransactionHelper; |
| 284 | } |
| 285 | |
| 286 | void setSurfaceTransactionHelper(PipSurfaceTransactionHelper helper) { |
| 287 | mSurfaceTransactionHelper = helper; |
| 288 | } |
| 289 | |
Hongwei Wang | 09c1f04 | 2020-03-18 13:47:45 -0700 | [diff] [blame] | 290 | void onStartTransaction(SurfaceControl leash, SurfaceControl.Transaction tx) {} |
| 291 | |
| 292 | void onEndTransaction(SurfaceControl leash, SurfaceControl.Transaction tx) {} |
| 293 | |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 294 | abstract void applySurfaceControlTransaction(SurfaceControl leash, |
| 295 | SurfaceControl.Transaction tx, float fraction); |
| 296 | |
Hongwei Wang | df8bb00 | 2020-03-03 17:41:02 -0800 | [diff] [blame] | 297 | static PipTransitionAnimator<Float> ofAlpha(SurfaceControl leash, |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 298 | Rect destinationBounds, float startValue, float endValue) { |
Hongwei Wang | df8bb00 | 2020-03-03 17:41:02 -0800 | [diff] [blame] | 299 | return new PipTransitionAnimator<Float>(leash, ANIM_TYPE_ALPHA, |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 300 | destinationBounds, startValue, endValue) { |
| 301 | @Override |
| 302 | void applySurfaceControlTransaction(SurfaceControl leash, |
| 303 | SurfaceControl.Transaction tx, float fraction) { |
| 304 | final float alpha = getStartValue() * (1 - fraction) + getEndValue() * fraction; |
| 305 | setCurrentValue(alpha); |
Hongwei Wang | ec3cb3c | 2020-03-09 10:43:21 -0700 | [diff] [blame] | 306 | getSurfaceTransactionHelper().alpha(tx, leash, alpha); |
Hongwei Wang | 09c1f04 | 2020-03-18 13:47:45 -0700 | [diff] [blame] | 307 | tx.apply(); |
| 308 | } |
| 309 | |
| 310 | @Override |
| 311 | void onStartTransaction(SurfaceControl leash, SurfaceControl.Transaction tx) { |
| 312 | getSurfaceTransactionHelper() |
| 313 | .crop(tx, leash, getDestinationBounds()) |
| 314 | .round(tx, leash, shouldApplyCornerRadius()); |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 315 | tx.apply(); |
| 316 | } |
| 317 | }; |
| 318 | } |
| 319 | |
Hongwei Wang | df8bb00 | 2020-03-03 17:41:02 -0800 | [diff] [blame] | 320 | static PipTransitionAnimator<Rect> ofBounds(SurfaceControl leash, |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 321 | Rect startValue, Rect endValue) { |
| 322 | // construct new Rect instances in case they are recycled |
Hongwei Wang | df8bb00 | 2020-03-03 17:41:02 -0800 | [diff] [blame] | 323 | return new PipTransitionAnimator<Rect>(leash, ANIM_TYPE_BOUNDS, |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 324 | endValue, new Rect(startValue), new Rect(endValue)) { |
| 325 | private final Rect mTmpRect = new Rect(); |
| 326 | |
| 327 | private int getCastedFractionValue(float start, float end, float fraction) { |
| 328 | return (int) (start * (1 - fraction) + end * fraction + .5f); |
| 329 | } |
| 330 | |
| 331 | @Override |
| 332 | void applySurfaceControlTransaction(SurfaceControl leash, |
| 333 | SurfaceControl.Transaction tx, float fraction) { |
| 334 | final Rect start = getStartValue(); |
| 335 | final Rect end = getEndValue(); |
| 336 | mTmpRect.set( |
| 337 | getCastedFractionValue(start.left, end.left, fraction), |
| 338 | getCastedFractionValue(start.top, end.top, fraction), |
| 339 | getCastedFractionValue(start.right, end.right, fraction), |
| 340 | getCastedFractionValue(start.bottom, end.bottom, fraction)); |
| 341 | setCurrentValue(mTmpRect); |
Hongwei Wang | 09c1f04 | 2020-03-18 13:47:45 -0700 | [diff] [blame] | 342 | if (inScaleTransition()) { |
| 343 | getSurfaceTransactionHelper().scale(tx, leash, start, mTmpRect); |
| 344 | } else { |
| 345 | getSurfaceTransactionHelper().crop(tx, leash, mTmpRect); |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 346 | } |
| 347 | tx.apply(); |
| 348 | } |
Hongwei Wang | 09c1f04 | 2020-03-18 13:47:45 -0700 | [diff] [blame] | 349 | |
| 350 | @Override |
| 351 | void onStartTransaction(SurfaceControl leash, SurfaceControl.Transaction tx) { |
| 352 | getSurfaceTransactionHelper() |
| 353 | .alpha(tx, leash, 1f) |
| 354 | .round(tx, leash, shouldApplyCornerRadius()); |
| 355 | tx.apply(); |
| 356 | } |
| 357 | |
| 358 | @Override |
| 359 | void onEndTransaction(SurfaceControl leash, SurfaceControl.Transaction tx) { |
| 360 | if (!inScaleTransition()) return; |
| 361 | // NOTE: intentionally does not apply the transaction here. |
| 362 | // this end transaction should get executed synchronously with the final |
| 363 | // WindowContainerTransaction in task organizer |
| 364 | getSurfaceTransactionHelper().resetScale(tx, leash, getDestinationBounds()); |
| 365 | } |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 366 | }; |
| 367 | } |
| 368 | } |
Hongwei Wang | 85cf41f | 2020-01-15 15:14:47 -0800 | [diff] [blame] | 369 | } |