Migrate statusbar chip animators to androidx

Migrating the statusbar chip animators to androidx allows us to write more sophisticated tests for these animations. (See separate CL for Test implementations)

Bug: 197638244
Test: Separate CL (ag/20982130)
Change-Id: I28dfe358f6f89fc8f7899d7d5761925d91681fad
This commit is contained in:
Johannes Gallmann
2023-01-10 16:11:28 +01:00
parent bd502db502
commit feb2df3c3c
7 changed files with 56 additions and 47 deletions

View File

@@ -16,7 +16,7 @@
package com.android.systemui.statusbar.events
import android.animation.Animator
import androidx.core.animation.Animator
import android.annotation.UiThread
import android.graphics.Point
import android.graphics.Rect

View File

@@ -16,10 +16,6 @@
package com.android.systemui.statusbar.events
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.AnimatorSet
import android.animation.ValueAnimator
import android.content.Context
import android.graphics.Rect
import android.view.ContextThemeWrapper
@@ -30,6 +26,10 @@ import android.view.View.MeasureSpec.AT_MOST
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.widget.FrameLayout
import androidx.core.animation.Animator
import androidx.core.animation.AnimatorListenerAdapter
import androidx.core.animation.AnimatorSet
import androidx.core.animation.ValueAnimator
import com.android.systemui.R
import com.android.systemui.statusbar.phone.StatusBarContentInsetsProvider
import com.android.systemui.statusbar.window.StatusBarWindowController
@@ -144,7 +144,7 @@ class SystemEventChipAnimationController @Inject constructor(
}
finish.addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator?) {
override fun onAnimationEnd(animation: Animator) {
animationWindowView.removeView(currentAnimatedView!!.view)
}
})
@@ -157,7 +157,7 @@ class SystemEventChipAnimationController @Inject constructor(
duration = 9.frames
interpolator = STATUS_CHIP_WIDTH_TO_DOT_KEYFRAME_1
addUpdateListener {
updateAnimatedViewBoundsWidth(it.animatedValue as Int)
updateAnimatedViewBoundsWidth(animatedValue as Int)
}
}
@@ -166,7 +166,7 @@ class SystemEventChipAnimationController @Inject constructor(
duration = 20.frames
interpolator = STATUS_CHIP_WIDTH_TO_DOT_KEYFRAME_2
addUpdateListener {
updateAnimatedViewBoundsWidth(it.animatedValue as Int)
updateAnimatedViewBoundsWidth(animatedValue as Int)
}
}
@@ -179,7 +179,7 @@ class SystemEventChipAnimationController @Inject constructor(
duration = 6.frames
interpolator = STATUS_CHIP_HEIGHT_TO_DOT_KEYFRAME_1
addUpdateListener {
updateAnimatedViewBoundsHeight(it.animatedValue as Int, chipVerticalCenter)
updateAnimatedViewBoundsHeight(animatedValue as Int, chipVerticalCenter)
}
}
@@ -188,7 +188,7 @@ class SystemEventChipAnimationController @Inject constructor(
duration = 15.frames
interpolator = STATUS_CHIP_HEIGHT_TO_DOT_KEYFRAME_2
addUpdateListener {
updateAnimatedViewBoundsHeight(it.animatedValue as Int, chipVerticalCenter)
updateAnimatedViewBoundsHeight(animatedValue as Int, chipVerticalCenter)
}
}
@@ -233,7 +233,7 @@ class SystemEventChipAnimationController @Inject constructor(
interpolator = STATUS_BAR_X_MOVE_OUT
addUpdateListener {
currentAnimatedView?.apply {
updateAnimatedViewBoundsWidth(it.animatedValue as Int)
updateAnimatedViewBoundsWidth(animatedValue as Int)
}
}
}

View File

@@ -16,14 +16,14 @@
package com.android.systemui.statusbar.events
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.AnimatorSet
import androidx.core.animation.Animator
import androidx.core.animation.AnimatorSet
import android.annotation.IntDef
import android.os.Process
import android.provider.DeviceConfig
import android.util.Log
import android.view.animation.PathInterpolator
import androidx.core.animation.AnimatorListenerAdapter
import androidx.core.animation.PathInterpolator
import com.android.systemui.Dumpable
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Main
@@ -185,7 +185,7 @@ open class SystemStatusAnimationScheduler @Inject constructor(
"Expected: 500, actual: ${animSet.totalDuration}")
}
animSet.addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator?) {
override fun onAnimationEnd(animation: Animator) {
animationState = RUNNING_CHIP_ANIM
}
})
@@ -195,7 +195,7 @@ open class SystemStatusAnimationScheduler @Inject constructor(
val animSet2 = collectFinishAnimations()
animationState = ANIMATING_OUT
animSet2.addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator?) {
override fun onAnimationEnd(animation: Animator) {
animationState = if (hasPersistentDot) {
SHOWING_PERSISTENT_DOT
} else {

View File

@@ -21,9 +21,6 @@ import static android.app.StatusBarManager.DISABLE_SYSTEM_INFO;
import static com.android.systemui.statusbar.StatusBarState.KEYGUARD;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.ContentObserver;
@@ -36,13 +33,16 @@ import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.core.animation.Animator;
import androidx.core.animation.AnimatorListenerAdapter;
import androidx.core.animation.ValueAnimator;
import com.android.keyguard.CarrierTextController;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
import com.android.keyguard.logging.KeyguardLogger;
import com.android.systemui.R;
import com.android.systemui.animation.Interpolators;
import com.android.systemui.animation.InterpolatorsAndroidX;
import com.android.systemui.battery.BatteryMeterViewController;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.plugins.log.LogLevel;
@@ -166,7 +166,8 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
private final ValueAnimator.AnimatorUpdateListener mAnimatorUpdateListener =
animation -> {
mKeyguardStatusBarAnimateAlpha = (float) animation.getAnimatedValue();
mKeyguardStatusBarAnimateAlpha =
(float) ((ValueAnimator) animation).getAnimatedValue();
updateViewState();
};
@@ -434,7 +435,7 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
anim.addUpdateListener(mAnimatorUpdateListener);
anim.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD);
anim.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
anim.setInterpolator(InterpolatorsAndroidX.LINEAR_OUT_SLOW_IN);
anim.start();
}
@@ -445,7 +446,7 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
anim.addUpdateListener(mAnimatorUpdateListener);
anim.setStartDelay(startDelay);
anim.setDuration(duration);
anim.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
anim.setInterpolator(InterpolatorsAndroidX.LINEAR_OUT_SLOW_IN);
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {

View File

@@ -23,7 +23,6 @@ import static android.app.StatusBarManager.DISABLE_SYSTEM_INFO;
import static com.android.systemui.statusbar.events.SystemStatusAnimationSchedulerKt.IDLE;
import static com.android.systemui.statusbar.events.SystemStatusAnimationSchedulerKt.SHOWING_PERSISTENT_DOT;
import android.animation.Animator;
import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.app.Fragment;
@@ -43,6 +42,7 @@ import android.view.ViewStub;
import android.widget.LinearLayout;
import androidx.annotation.VisibleForTesting;
import androidx.core.animation.Animator;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.Dumpable;

View File

@@ -16,9 +16,9 @@
package com.android.systemui.statusbar.phone.fragment
import android.animation.Animator
import android.animation.AnimatorSet
import android.animation.ValueAnimator
import androidx.core.animation.Animator
import androidx.core.animation.AnimatorSet
import androidx.core.animation.ValueAnimator
import android.content.res.Resources
import android.view.View
import com.android.systemui.R
@@ -46,15 +46,19 @@ class StatusBarSystemEventAnimator(
R.dimen.ongoing_appops_chip_animation_out_status_bar_translation_x)
override fun onSystemEventAnimationBegin(): Animator {
val moveOut = ValueAnimator.ofFloat(0f, 1f).setDuration(23.frames)
moveOut.interpolator = STATUS_BAR_X_MOVE_OUT
moveOut.addUpdateListener { animation: ValueAnimator ->
animatedView.translationX = -(translationXIn * animation.animatedValue as Float)
val moveOut = ValueAnimator.ofFloat(0f, 1f).apply {
duration = 23.frames
interpolator = STATUS_BAR_X_MOVE_OUT
addUpdateListener {
animatedView.translationX = -(translationXIn * animatedValue as Float)
}
}
val alphaOut = ValueAnimator.ofFloat(1f, 0f).setDuration(8.frames)
alphaOut.interpolator = null
alphaOut.addUpdateListener { animation: ValueAnimator ->
animatedView.alpha = animation.animatedValue as Float
val alphaOut = ValueAnimator.ofFloat(1f, 0f).apply {
duration = 8.frames
interpolator = null
addUpdateListener {
animatedView.alpha = animatedValue as Float
}
}
val animSet = AnimatorSet()
@@ -64,17 +68,21 @@ class StatusBarSystemEventAnimator(
override fun onSystemEventAnimationFinish(hasPersistentDot: Boolean): Animator {
animatedView.translationX = translationXOut.toFloat()
val moveIn = ValueAnimator.ofFloat(1f, 0f).setDuration(23.frames)
moveIn.startDelay = 7.frames
moveIn.interpolator = STATUS_BAR_X_MOVE_IN
moveIn.addUpdateListener { animation: ValueAnimator ->
animatedView.translationX = translationXOut * animation.animatedValue as Float
val moveIn = ValueAnimator.ofFloat(1f, 0f).apply {
duration = 23.frames
startDelay = 7.frames
interpolator = STATUS_BAR_X_MOVE_IN
addUpdateListener {
animatedView.translationX = translationXOut * animatedValue as Float
}
}
val alphaIn = ValueAnimator.ofFloat(0f, 1f).setDuration(5.frames)
alphaIn.startDelay = 11.frames
alphaIn.interpolator = null
alphaIn.addUpdateListener { animation: ValueAnimator ->
animatedView.alpha = animation.animatedValue as Float
val alphaIn = ValueAnimator.ofFloat(0f, 1f).apply {
duration = 5.frames
startDelay = 11.frames
interpolator = null
addUpdateListener {
animatedView.alpha = animatedValue as Float
}
}
val animatorSet = AnimatorSet()

View File

@@ -32,7 +32,6 @@ import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import android.animation.Animator;
import android.app.Fragment;
import android.app.StatusBarManager;
import android.content.Context;
@@ -45,6 +44,7 @@ import android.view.View;
import android.view.ViewPropertyAnimator;
import android.widget.FrameLayout;
import androidx.core.animation.Animator;
import androidx.test.filters.SmallTest;
import com.android.keyguard.KeyguardUpdateMonitor;