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
|
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,11 +176,15 @@ 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
|
||||||
|
if ((oldAlpha == 0f && header.alpha > 0f) ||
|
||||||
|
(oldAlpha > 0f && header.alpha == 0f)) {
|
||||||
updateVisibility()
|
updateVisibility()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expansion fraction of the QQS <-> QS animation.
|
* Expansion fraction of the QQS <-> QS animation.
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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>()
|
||||||
|
|||||||
Reference in New Issue
Block a user