Fix isPropertyAnimating to include flings, and add tests.

Test: atest SystemUITests
Change-Id: Ic3cea392d1da6a7cbe2e2131f488f07196c22290
This commit is contained in:
Joshua Tsuji
2020-01-08 14:29:02 -05:00
parent fa5f53f589
commit bdb6b20a8a
2 changed files with 34 additions and 1 deletions

View File

@@ -495,7 +495,8 @@ class PhysicsAnimator<T> private constructor (val target: T) {
/** Returns whether the given property is animating. */
fun isPropertyAnimating(property: FloatPropertyCompat<in T>): Boolean {
return springAnimations[property]?.isRunning ?: false
return springAnimations[property]?.isRunning ?: false ||
flingAnimations[property]?.isRunning ?: false
}
/** Returns whether any of the given properties are animating. */

View File

@@ -19,6 +19,7 @@ import com.android.systemui.util.animation.PhysicsAnimatorTestUtils.verifyAnimat
import org.junit.After
import org.junit.Assert
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertTrue
import org.junit.Before
@@ -385,6 +386,37 @@ class PhysicsAnimatorTest : SysuiTestCase() {
anyFloat(), eq(true))
}
@Test
fun testIsPropertyAnimating() {
PhysicsAnimatorTestUtils.setAllAnimationsBlock(false)
testView.physicsAnimator
.spring(DynamicAnimation.TRANSLATION_X, 500f, springConfig)
.fling(DynamicAnimation.TRANSLATION_Y, 10f, flingConfig)
.spring(DynamicAnimation.TRANSLATION_Z, 1000f, springConfig)
.start()
// All of the properties we just started should be animating.
assertTrue(testView.physicsAnimator.isPropertyAnimating(DynamicAnimation.TRANSLATION_X))
assertTrue(testView.physicsAnimator.isPropertyAnimating(DynamicAnimation.TRANSLATION_Y))
assertTrue(testView.physicsAnimator.isPropertyAnimating(DynamicAnimation.TRANSLATION_Z))
// Block until x and y end.
PhysicsAnimatorTestUtils.blockUntilAnimationsEnd(testView.physicsAnimator,
DynamicAnimation.TRANSLATION_X, DynamicAnimation.TRANSLATION_Y)
// Verify that x and y are no longer animating, but that Z is (it's springing to 1000f).
assertFalse(testView.physicsAnimator.isPropertyAnimating(DynamicAnimation.TRANSLATION_X))
assertFalse(testView.physicsAnimator.isPropertyAnimating(DynamicAnimation.TRANSLATION_Y))
assertTrue(testView.physicsAnimator.isPropertyAnimating(DynamicAnimation.TRANSLATION_Z))
PhysicsAnimatorTestUtils.blockUntilAnimationsEnd(DynamicAnimation.TRANSLATION_Z)
assertFalse(testView.physicsAnimator.isPropertyAnimating(DynamicAnimation.TRANSLATION_X))
assertFalse(testView.physicsAnimator.isPropertyAnimating(DynamicAnimation.TRANSLATION_Y))
assertFalse(testView.physicsAnimator.isPropertyAnimating(DynamicAnimation.TRANSLATION_Z))
}
@Test
fun testExtensionProperty() {
testView