QSLongPressEffect Animator initialized when called to START
Initializing the animator now happens in the action to START the effect.
This guarantees that the animator is created every time it is required
to start. With this, the long-press effect logic holds after device
rotations, which causes the view binder to re-launch the collector
coroutine, thereby setting the animator to null. This also removes the
INITIALIZE_ANIMATOR action, which saves an extra coroutine continuation
event.
Test: SystemUiRoboTests:QSLongPressEffectTest
Flag: ACONFIG quick_settings_visual_haptics_longpress TEAMFOOD
Bug: 337271048
Change-Id: I3f3ec5372e5b662aad4eab834518362e0a0b2a53
diff --git a/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffect.kt b/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffect.kt
index db2ec8f..ea8d7d7 100644
--- a/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffect.kt
+++ b/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffect.kt
@@ -189,7 +189,6 @@
durations?.get(1) ?: LongPressHapticBuilder.INVALID_DURATION,
effectDuration
)
- _postedActionType.value = ActionType.INITIALIZE_ANIMATOR
setState(State.IDLE)
return true
}
@@ -209,6 +208,5 @@
START_ANIMATOR,
REVERSE_ANIMATOR,
CANCEL_ANIMATOR,
- INITIALIZE_ANIMATOR,
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffectViewBinder.kt b/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffectViewBinder.kt
index c591af2..a79f4b0 100644
--- a/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffectViewBinder.kt
+++ b/packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffectViewBinder.kt
@@ -66,8 +66,32 @@
qsLongPressEffect.clearActionType()
}
QSLongPressEffect.ActionType.START_ANIMATOR -> {
- if (effectAnimator?.isRunning == false) {
- effectAnimator?.start()
+ if (effectAnimator?.isRunning != true) {
+ effectAnimator =
+ ValueAnimator.ofFloat(0f, 1f).apply {
+ this.duration =
+ qsLongPressEffect.effectDuration.toLong()
+ interpolator = AccelerateDecelerateInterpolator()
+
+ doOnStart {
+ qsLongPressEffect.handleAnimationStart()
+ }
+ addUpdateListener {
+ val value = animatedValue as Float
+ if (value == 0f) {
+ tile.bringToFront()
+ } else {
+ tile.updateLongPressEffectProperties(value)
+ }
+ }
+ doOnEnd {
+ qsLongPressEffect.handleAnimationComplete()
+ }
+ doOnCancel {
+ qsLongPressEffect.handleAnimationCancel()
+ }
+ start()
+ }
}
}
QSLongPressEffect.ActionType.REVERSE_ANIMATOR -> {
@@ -81,26 +105,6 @@
tile.resetLongPressEffectProperties()
effectAnimator?.cancel()
}
- QSLongPressEffect.ActionType.INITIALIZE_ANIMATOR -> {
- effectAnimator =
- ValueAnimator.ofFloat(0f, 1f).apply {
- this.duration =
- qsLongPressEffect.effectDuration.toLong()
- interpolator = AccelerateDecelerateInterpolator()
-
- doOnStart { qsLongPressEffect.handleAnimationStart() }
- addUpdateListener {
- val value = animatedValue as Float
- if (value == 0f) {
- tile.bringToFront()
- } else {
- tile.updateLongPressEffectProperties(value)
- }
- }
- doOnEnd { qsLongPressEffect.handleAnimationComplete() }
- doOnCancel { qsLongPressEffect.handleAnimationCancel() }
- }
- }
}
}
}