dynamic-animation/src/androidTest/java/androidx/dynamicanimation/tests/SpringTests.java
@Test
    public void testAllProperties() {
        final DynamicAnimation.ViewProperty[] properties = {
                DynamicAnimation.ALPHA, DynamicAnimation.TRANSLATION_X,
                DynamicAnimation.TRANSLATION_Y, DynamicAnimation.TRANSLATION_Z,
                DynamicAnimation.SCALE_X, DynamicAnimation.SCALE_Y, DynamicAnimation.ROTATION,
                DynamicAnimation.ROTATION_X, DynamicAnimation.ROTATION_Y,
                DynamicAnimation.X, DynamicAnimation.Y, DynamicAnimation.Z,
                DynamicAnimation.SCROLL_X, DynamicAnimation.SCROLL_Y,
        };

        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
            @Override
            public void run() {
                mView1.setAlpha(0f);
                mView1.setTranslationX(0f);
                mView1.setTranslationY(0f);
                ViewCompat.setTranslationZ(mView1, 0f);

                mView1.setScaleX(0f);
                mView1.setScaleY(0f);

                mView1.setRotation(0f);
                mView1.setRotationX(0f);
                mView1.setRotationY(0f);

                mView1.setX(0f);
                mView1.setY(0f);
                ViewCompat.setZ(mView1, 0f);

                mView1.setScrollX(0);
                mView1.setScrollY(0);
            }
        });

        final SpringAnimation[] anims = new SpringAnimation[properties.length];
        final DynamicAnimation.OnAnimationUpdateListener[] mockListeners =
                new DynamicAnimation.OnAnimationUpdateListener[properties.length];
        for (int i = 0; i < properties.length; i++) {
            anims[i] = new SpringAnimation(mView1, properties[i], 1);
            final int finalI = i;
            anims[i].addUpdateListener(
                    new DynamicAnimation.OnAnimationUpdateListener() {
                        boolean mIsFirstFrame = true;
                        @Override
                        public void onAnimationUpdate(DynamicAnimation animation, float value,
                                float velocity) {
                            if (mIsFirstFrame) {
                                assertEquals(value, 0f, 0f);
                            }
                            mIsFirstFrame = false;
                        }
                    });
            mockListeners[i] = mock(DynamicAnimation.OnAnimationUpdateListener.class);
            anims[i].addUpdateListener(mockListeners[i]);
        }

        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
            @Override
            public void run() {
                for (int i = properties.length - 1; i >= 0; i--) {
                    anims[i].start();
                }
            }
        });

        for (int i = 0; i < properties.length; i++) {
            int timeout = i == 0 ? 100 : 0;
            verify(mockListeners[i], timeout(timeout).atLeast(1)).onAnimationUpdate(
                    any(SpringAnimation.class), any(float.class), any(float.class));
        }

        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < properties.length; i++) {
                    anims[i].cancel();
                }
            }
        });
    }
/**
     * Makes sure all the properties getter works.
     */
Makes sure all the properties getter works.
Makes sure all the properties getter works .
@Test
    public void testAllProperties() {
        final DynamicAnimation.ViewProperty[] properties = {
                DynamicAnimation.ALPHA, DynamicAnimation.TRANSLATION_X,
                DynamicAnimation.TRANSLATION_Y, DynamicAnimation.TRANSLATION_Z,
                DynamicAnimation.SCALE_X, DynamicAnimation.SCALE_Y, DynamicAnimation.ROTATION,
                DynamicAnimation.ROTATION_X, DynamicAnimation.ROTATION_Y,
                DynamicAnimation.X, DynamicAnimation.Y, DynamicAnimation.Z,
                DynamicAnimation.SCROLL_X, DynamicAnimation.SCROLL_Y,
        };
        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
            @Override
            public void run() {
                mView1.setAlpha(0f);
                mView1.setTranslationX(0f);
                mView1.setTranslationY(0f);
                ViewCompat.setTranslationZ(mView1, 0f);
                mView1.setScaleX(0f);
                mView1.setScaleY(0f);
                mView1.setRotation(0f);
                mView1.setRotationX(0f);
                mView1.setRotationY(0f);
                mView1.setX(0f);
                mView1.setY(0f);
                ViewCompat.setZ(mView1, 0f);
                mView1.setScrollX(0);
                mView1.setScrollY(0);
            }
        });
        final SpringAnimation[] anims = new SpringAnimation[properties.length];
        final DynamicAnimation.OnAnimationUpdateListener[] mockListeners =
                new DynamicAnimation.OnAnimationUpdateListener[properties.length];
        for (int i = 0; i < properties.length; i++) {
            anims[i] = new SpringAnimation(mView1, properties[i], 1);
            final int finalI = i;
            anims[i].addUpdateListener(
                    new DynamicAnimation.OnAnimationUpdateListener() {
                        boolean mIsFirstFrame = true;
                        @Override
                        public void onAnimationUpdate(DynamicAnimation animation, float value,
                                float velocity) {
                            if (mIsFirstFrame) {
                                assertEquals(value, 0f, 0f);
                            }
                            mIsFirstFrame = false;
                        }
                    });
            mockListeners[i] = mock(DynamicAnimation.OnAnimationUpdateListener.class);
            anims[i].addUpdateListener(mockListeners[i]);
        }
        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
            @Override
            public void run() {
                for (int i = properties.length - 1; i >= 0; i--) {
                    anims[i].start();
                }
            }
        });
        for (int i = 0; i < properties.length; i++) {
            int timeout = i == 0 ? 100 : 0;
            verify(mockListeners[i], timeout(timeout).atLeast(1)).onAnimationUpdate(
                    any(SpringAnimation.class), any(float.class), any(float.class));
        }
        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < properties.length; i++) {
                    anims[i].cancel();
                }
            }
        });
    }
@ Test public void testAllProperties ( ) { final DynamicAnimation . ViewProperty [ ] properties = { DynamicAnimation . ALPHA , DynamicAnimation . TRANSLATION_X , DynamicAnimation . TRANSLATION_Y , DynamicAnimation . TRANSLATION_Z , DynamicAnimation . SCALE_X , DynamicAnimation . SCALE_Y , DynamicAnimation . ROTATION , DynamicAnimation . ROTATION_X , DynamicAnimation . ROTATION_Y , DynamicAnimation . X , DynamicAnimation . Y , DynamicAnimation . Z , DynamicAnimation . SCROLL_X , DynamicAnimation . SCROLL_Y , } ; InstrumentationRegistry . getInstrumentation ( ) . runOnMainSync ( new Runnable ( ) { @ Override public void run ( ) { mView1 . setAlpha ( 0f ) ; mView1 . setTranslationX ( 0f ) ; mView1 . setTranslationY ( 0f ) ; ViewCompat . setTranslationZ ( mView1 , 0f ) ; mView1 . setScaleX ( 0f ) ; mView1 . setScaleY ( 0f ) ; mView1 . setRotation ( 0f ) ; mView1 . setRotationX ( 0f ) ; mView1 . setRotationY ( 0f ) ; mView1 . setX ( 0f ) ; mView1 . setY ( 0f ) ; ViewCompat . setZ ( mView1 , 0f ) ; mView1 . setScrollX ( 0 ) ; mView1 . setScrollY ( 0 ) ; } } ) ; final SpringAnimation [ ] anims = new SpringAnimation [ properties . length ] ; final DynamicAnimation . OnAnimationUpdateListener [ ] mockListeners = new DynamicAnimation . OnAnimationUpdateListener [ properties . length ] ; for ( int i = 0 ; i < properties . length ; i ++ ) { anims [ i ] = new SpringAnimation ( mView1 , properties [ i ] , 1 ) ; final int finalI = i ; anims [ i ] . addUpdateListener ( new DynamicAnimation . OnAnimationUpdateListener ( ) { boolean mIsFirstFrame = true ; @ Override public void onAnimationUpdate ( DynamicAnimation animation , float value , float velocity ) { if ( mIsFirstFrame ) { assertEquals ( value , 0f , 0f ) ; } mIsFirstFrame = false ; } } ) ; mockListeners [ i ] = mock ( DynamicAnimation . OnAnimationUpdateListener . class ) ; anims [ i ] . addUpdateListener ( mockListeners [ i ] ) ; } InstrumentationRegistry . getInstrumentation ( ) . runOnMainSync ( new Runnable ( ) { @ Override public void run ( ) { for ( int i = properties . length - 1 ; i >= 0 ; i -- ) { anims [ i ] . start ( ) ; } } } ) ; for ( int i = 0 ; i < properties . length ; i ++ ) { int timeout = i == 0 ? 100 : 0 ; verify ( mockListeners [ i ] , timeout ( timeout ) . atLeast ( 1 ) ) . onAnimationUpdate ( any ( SpringAnimation . class ) , any ( float . class ) , any ( float . class ) ) ; } InstrumentationRegistry . getInstrumentation ( ) . runOnMainSync ( new Runnable ( ) { @ Override public void run ( ) { for ( int i = 0 ; i < properties . length ; i ++ ) { anims [ i ] . cancel ( ) ; } } } ) ; }
Makes sure all the properties getter works.
Makes sure all the properties getter works .