Merge "Clear listeners after animation" into tm-qpr-dev

This commit is contained in:
Fabian Kozynski
2023-01-25 15:04:47 +00:00
committed by Android (Google) Code Review
2 changed files with 55 additions and 2 deletions

View File

@@ -16,6 +16,7 @@
package com.android.systemui.shade package com.android.systemui.shade
import android.animation.Animator
import android.annotation.IdRes import android.annotation.IdRes
import android.app.StatusBarManager import android.app.StatusBarManager
import android.content.res.Configuration import android.content.res.Configuration
@@ -175,9 +176,13 @@ class LargeScreenShadeHeaderController @Inject constructor(
var shadeExpandedFraction = -1f var shadeExpandedFraction = -1f
set(value) { set(value) {
if (field != value) { if (field != value) {
val oldAlpha = header.alpha
header.alpha = ShadeInterpolation.getContentAlpha(value) header.alpha = ShadeInterpolation.getContentAlpha(value)
field = value field = value
updateVisibility() if ((oldAlpha == 0f && header.alpha > 0f) ||
(oldAlpha > 0f && header.alpha == 0f)) {
updateVisibility()
}
} }
} }
@@ -336,9 +341,28 @@ class LargeScreenShadeHeaderController @Inject constructor(
.setUpdateListener { .setUpdateListener {
updateVisibility() updateVisibility()
} }
.setListener(endAnimationListener)
.start() .start()
} }
private val endAnimationListener = object : Animator.AnimatorListener {
override fun onAnimationCancel(animation: Animator?) {
clearListeners()
}
override fun onAnimationEnd(animation: Animator?) {
clearListeners()
}
override fun onAnimationRepeat(animation: Animator?) {}
override fun onAnimationStart(animation: Animator?) {}
private fun clearListeners() {
header.animate().setListener(null).setUpdateListener(null)
}
}
private fun loadConstraints() { private fun loadConstraints() {
if (header is MotionLayout) { if (header is MotionLayout) {
// Use resources.getXml instead of passing the resource id due to bug b/205018300 // Use resources.getXml instead of passing the resource id due to bug b/205018300

View File

@@ -1,5 +1,6 @@
package com.android.systemui.shade package com.android.systemui.shade
import android.animation.Animator
import android.animation.ValueAnimator import android.animation.ValueAnimator
import android.app.StatusBarManager import android.app.StatusBarManager
import android.content.Context import android.content.Context
@@ -45,8 +46,8 @@ import org.mockito.Mock
import org.mockito.Mockito.mock import org.mockito.Mockito.mock
import org.mockito.Mockito.verify import org.mockito.Mockito.verify
import org.mockito.Mockito.verifyZeroInteractions import org.mockito.Mockito.verifyZeroInteractions
import org.mockito.Mockito.`when` as whenever
import org.mockito.junit.MockitoJUnit import org.mockito.junit.MockitoJUnit
import org.mockito.Mockito.`when` as whenever
@SmallTest @SmallTest
@RunWith(AndroidTestingRunner::class) @RunWith(AndroidTestingRunner::class)
@@ -292,6 +293,34 @@ class LargeScreenShadeHeaderControllerTest : SysuiTestCase() {
assertThat(viewVisibility).isEqualTo(View.INVISIBLE) assertThat(viewVisibility).isEqualTo(View.INVISIBLE)
} }
@Test
fun animatorListenersClearedAtEnd() {
val animator = mock(ViewPropertyAnimator::class.java, Answers.RETURNS_SELF)
whenever(view.animate()).thenReturn(animator)
mLargeScreenShadeHeaderController.startCustomizingAnimation(show = true, 0L)
val listenerCaptor = argumentCaptor<Animator.AnimatorListener>()
verify(animator).setListener(capture(listenerCaptor))
listenerCaptor.value.onAnimationEnd(mock())
verify(animator).setListener(null)
verify(animator).setUpdateListener(null)
}
@Test
fun animatorListenersClearedOnCancel() {
val animator = mock(ViewPropertyAnimator::class.java, Answers.RETURNS_SELF)
whenever(view.animate()).thenReturn(animator)
mLargeScreenShadeHeaderController.startCustomizingAnimation(show = true, 0L)
val listenerCaptor = argumentCaptor<Animator.AnimatorListener>()
verify(animator).setListener(capture(listenerCaptor))
listenerCaptor.value.onAnimationCancel(mock())
verify(animator).setListener(null)
verify(animator).setUpdateListener(null)
}
@Test @Test
fun demoMode_attachDemoMode() { fun demoMode_attachDemoMode() {
val cb = argumentCaptor<DemoMode>() val cb = argumentCaptor<DemoMode>()