diff options
| author | 2024-04-26 09:54:03 -0700 | |
|---|---|---|
| committer | 2024-04-26 09:59:29 -0700 | |
| commit | fd43a6cae4f2a80febf61473e62a42cbee9840ca (patch) | |
| tree | 8ca9b1f6c74eee1a07008ffb3611610fe19471c0 | |
| parent | dbf2dd623ba4754145067329e42d44892acf226a (diff) | |
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
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffect.kt | 2 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffectViewBinder.kt | 48 |
2 files changed, 26 insertions, 24 deletions
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 db2ec8f27cc5..ea8d7d778851 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 @@ constructor( durations?.get(1) ?: LongPressHapticBuilder.INVALID_DURATION, effectDuration ) - _postedActionType.value = ActionType.INITIALIZE_ANIMATOR setState(State.IDLE) return true } @@ -209,6 +208,5 @@ constructor( 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 c591af2ef09f..a79f4b030a15 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 @@ object QSLongPressEffectViewBinder { 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 @@ object QSLongPressEffectViewBinder { 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() } - } - } } } } |