Merge "Clear listeners after animation" into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
7c08dcb5a9
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.systemui.shade
|
||||
|
||||
import android.animation.Animator
|
||||
import android.annotation.IdRes
|
||||
import android.app.StatusBarManager
|
||||
import android.content.res.Configuration
|
||||
@@ -175,9 +176,13 @@ class LargeScreenShadeHeaderController @Inject constructor(
|
||||
var shadeExpandedFraction = -1f
|
||||
set(value) {
|
||||
if (field != value) {
|
||||
val oldAlpha = header.alpha
|
||||
header.alpha = ShadeInterpolation.getContentAlpha(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 {
|
||||
updateVisibility()
|
||||
}
|
||||
.setListener(endAnimationListener)
|
||||
.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() {
|
||||
if (header is MotionLayout) {
|
||||
// Use resources.getXml instead of passing the resource id due to bug b/205018300
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.android.systemui.shade
|
||||
|
||||
import android.animation.Animator
|
||||
import android.animation.ValueAnimator
|
||||
import android.app.StatusBarManager
|
||||
import android.content.Context
|
||||
@@ -45,8 +46,8 @@ import org.mockito.Mock
|
||||
import org.mockito.Mockito.mock
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.Mockito.verifyZeroInteractions
|
||||
import org.mockito.Mockito.`when` as whenever
|
||||
import org.mockito.junit.MockitoJUnit
|
||||
import org.mockito.Mockito.`when` as whenever
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidTestingRunner::class)
|
||||
@@ -292,6 +293,34 @@ class LargeScreenShadeHeaderControllerTest : SysuiTestCase() {
|
||||
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
|
||||
fun demoMode_attachDemoMode() {
|
||||
val cb = argumentCaptor<DemoMode>()
|
||||
|
||||
Reference in New Issue
Block a user