Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bdb6b20a authored by Joshua Tsuji's avatar Joshua Tsuji
Browse files

Fix isPropertyAnimating to include flings, and add tests.

Test: atest SystemUITests
Change-Id: Ic3cea392d1da6a7cbe2e2131f488f07196c22290
parent fa5f53f5
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -495,7 +495,8 @@ class PhysicsAnimator<T> private constructor (val target: T) {


    /** Returns whether the given property is animating.  */
    /** Returns whether the given property is animating.  */
    fun isPropertyAnimating(property: FloatPropertyCompat<in T>): Boolean {
    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.  */
    /** Returns whether any of the given properties are animating.  */
+32 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ import com.android.systemui.util.animation.PhysicsAnimatorTestUtils.verifyAnimat
import org.junit.After
import org.junit.After
import org.junit.Assert
import org.junit.Assert
import org.junit.Assert.assertEquals
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertTrue
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Before
@@ -385,6 +386,37 @@ class PhysicsAnimatorTest : SysuiTestCase() {
                        anyFloat(), eq(true))
                        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
    @Test
    fun testExtensionProperty() {
    fun testExtensionProperty() {
        testView
        testView