From 6fb258098c88a87b04ccf4b42755a8587f07b456 Mon Sep 17 00:00:00 2001 From: Sally Date: Thu, 28 Apr 2022 20:52:55 +0000 Subject: [PATCH] Follow up Androidx dynamic animation api change Refactor codes using DynamicAnimation Animation handler api codes for following up Androidx codes changes. Change needed to support AndroidX platform prebuilts, which include changes that fix a severe accessibility bug and setting. Bug: 167382784 Bug: 221303983 Test: build Change-Id: Ie75cc4068fa0b49816756650e900b7943f6c97d2 Merged-In: Iaa0e787675f53ac16cf61f2d2b6adae02ab55623 --- .../wm/shell/animation/PhysicsAnimator.kt | 38 +++++++++---------- .../wm/shell/pip/phone/PipMotionHelper.java | 11 ++---- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/animation/PhysicsAnimator.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/animation/PhysicsAnimator.kt index 255e4d2c0d442..b483fe03e80f6 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/animation/PhysicsAnimator.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/animation/PhysicsAnimator.kt @@ -19,12 +19,13 @@ package com.android.wm.shell.animation import android.util.ArrayMap import android.util.Log import android.view.View -import androidx.dynamicanimation.animation.AnimationHandler import androidx.dynamicanimation.animation.DynamicAnimation import androidx.dynamicanimation.animation.FlingAnimation import androidx.dynamicanimation.animation.FloatPropertyCompat +import androidx.dynamicanimation.animation.FrameCallbackScheduler import androidx.dynamicanimation.animation.SpringAnimation import androidx.dynamicanimation.animation.SpringForce + import com.android.wm.shell.animation.PhysicsAnimator.Companion.getInstance import java.lang.ref.WeakReference import java.util.WeakHashMap @@ -124,10 +125,10 @@ class PhysicsAnimator private constructor (target: T) { private var defaultFling: FlingConfig = globalDefaultFling /** - * AnimationHandler to use if it need custom AnimationHandler, if this is null, it will use - * the default AnimationHandler in the DynamicAnimation. + * FrameCallbackScheduler to use if it need custom FrameCallbackScheduler, if this is null, + * it will use the default FrameCallbackScheduler in the DynamicAnimation. */ - private var customAnimationHandler: AnimationHandler? = null + private var customScheduler: FrameCallbackScheduler? = null /** * Internal listeners that respond to DynamicAnimations updating and ending, and dispatch to @@ -454,11 +455,11 @@ class PhysicsAnimator private constructor (target: T) { } /** - * Set the custom AnimationHandler for all aniatmion in this animator. Set this with null for - * restoring to default AnimationHandler. + * Set the custom FrameCallbackScheduler for all aniatmion in this animator. Set this with null for + * restoring to default FrameCallbackScheduler. */ - fun setCustomAnimationHandler(handler: AnimationHandler) { - this.customAnimationHandler = handler + fun setCustomScheduler(scheduler: FrameCallbackScheduler) { + this.customScheduler = scheduler } /** Starts the animations! */ @@ -510,10 +511,9 @@ class PhysicsAnimator private constructor (target: T) { // springs) on this property before flinging. cancel(animatedProperty) - // Apply the custom animation handler if it not null + // Apply the custom animation scheduler if it not null val flingAnim = getFlingAnimation(animatedProperty, target) - flingAnim.animationHandler = - customAnimationHandler ?: flingAnim.animationHandler + flingAnim.scheduler = customScheduler ?: flingAnim.scheduler // Apply the configuration and start the animation. flingAnim.also { flingConfig.applyToAnimation(it) }.start() @@ -529,17 +529,16 @@ class PhysicsAnimator private constructor (target: T) { // Apply the configuration and start the animation. val springAnim = getSpringAnimation(animatedProperty, target) - // If customAnimationHander is exist and has not been set to the animation, + // If customScheduler is exist and has not been set to the animation, // it should set here. - if (customAnimationHandler != null && - springAnim.animationHandler != customAnimationHandler) { + if (customScheduler != null && + springAnim.scheduler != customScheduler) { // Cancel the animation before set animation handler if (springAnim.isRunning) { cancel(animatedProperty) } - // Apply the custom animation handler if it not null - springAnim.animationHandler = - customAnimationHandler ?: springAnim.animationHandler + // Apply the custom scheduler handler if it not null + springAnim.scheduler = customScheduler ?: springAnim.scheduler } // Apply the configuration and start the animation. @@ -597,10 +596,9 @@ class PhysicsAnimator private constructor (target: T) { } } - // Apply the custom animation handler if it not null + // Apply the custom animation scheduler if it not null val springAnim = getSpringAnimation(animatedProperty, target) - springAnim.animationHandler = - customAnimationHandler ?: springAnim.animationHandler + springAnim.scheduler = customScheduler ?: springAnim.scheduler // Apply the configuration and start the spring animation. springAnim.also { springConfig.applyToAnimation(it) }.start() diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java index fa0f0925a08ad..e9b6babfc5fa8 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java @@ -36,8 +36,7 @@ import android.os.Debug; import android.os.Looper; import android.view.Choreographer; -import androidx.dynamicanimation.animation.AnimationHandler; -import androidx.dynamicanimation.animation.AnimationHandler.FrameCallbackScheduler; +import androidx.dynamicanimation.animation.FrameCallbackScheduler; import com.android.internal.protolog.common.ProtoLog; import com.android.wm.shell.R; @@ -89,7 +88,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback, /** Coordinator instance for resolving conflicts with other floating content. */ private FloatingContentCoordinator mFloatingContentCoordinator; - private ThreadLocal mSfAnimationHandlerThreadLocal = + private ThreadLocal mSfSchedulerThreadLocal = ThreadLocal.withInitial(() -> { final Looper initialLooper = Looper.myLooper(); final FrameCallbackScheduler scheduler = new FrameCallbackScheduler() { @@ -105,8 +104,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback, return Looper.myLooper() == initialLooper; } }; - AnimationHandler handler = new AnimationHandler(scheduler); - return handler; + return scheduler; }); /** @@ -214,8 +212,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback, // Note: Needs to get the shell main thread sf vsync animation handler mTemporaryBoundsPhysicsAnimator = PhysicsAnimator.getInstance( mPipBoundsState.getMotionBoundsState().getBoundsInMotion()); - mTemporaryBoundsPhysicsAnimator.setCustomAnimationHandler( - mSfAnimationHandlerThreadLocal.get()); + mTemporaryBoundsPhysicsAnimator.setCustomScheduler(mSfSchedulerThreadLocal.get()); } @NonNull