FileDocCategorySizeDatePackage
StateListAnimatorTest.javaAPI DocAndroid 5.1 API4518Thu Mar 12 22:22:12 GMT 2015android.animation

StateListAnimatorTest

public class StateListAnimatorTest extends android.test.ActivityInstrumentationTestCase2

Fields Summary
Constructors Summary
public StateListAnimatorTest()

        super(BasicAnimatorActivity.class);
    
Methods Summary
protected voidsetUp()

        super.setUp();
    
public voidtestAttachDetach()

        View view = new View(getActivity());
        final AtomicInteger setStateCount = new AtomicInteger(0);
        StateListAnimator stateListAnimator = new StateListAnimator() {
            @Override
            public void setState(int[] state) {
                setStateCount.incrementAndGet();
                super.setState(state);
            }
        };
        view.setStateListAnimator(stateListAnimator);
        assertNotNull("State list animator should have a reference to view even if it is detached",
                stateListAnimator.getTarget());
        ViewGroup viewGroup = (ViewGroup) getActivity().findViewById(android.R.id.content);
        int preSetStateCount = setStateCount.get();
        viewGroup.addView(view);
        assertTrue("When view is attached, state list drawable's setState should be called",
                preSetStateCount < setStateCount.get());

        StateListAnimator stateListAnimator2 = new StateListAnimator();
        view.setStateListAnimator(stateListAnimator2);
        assertNull("When a new state list animator is assigned, previous one should be detached",
                stateListAnimator.getTarget());
        assertNull("Any running animator should be removed on detach",
                stateListAnimator.getRunningAnimator());
        assertEquals("The new state list animator should be attached to the view",
                view, stateListAnimator2.getTarget());
        viewGroup.removeView(view);
        assertNotNull("When view is detached from window, state list animator should still keep the"
                        + " reference",
                stateListAnimator2.getTarget());
    
public voidtestInflateFromAnimator()

        StateListAnimator stateListAnimator = AnimatorInflater
                .loadStateListAnimator(getActivity(), R.anim.test_state_anim);
        assertNotNull("A state list animator should be returned", stateListAnimator);
        assertEquals("State list animator should have three items", 3,
                stateListAnimator.getTuples().size());
    
public voidtestStateListLoading()

        StateListAnimator stateListAnimator = AnimatorInflater
                .loadStateListAnimator(getActivity(), R.anim.test_state_anim);
        assertNotNull("A state list animator should be returned", stateListAnimator);
        assertEquals("Steate list animator should have two items", 3,
                stateListAnimator.getTuples().size());
        StateListAnimator.Tuple tuple1 = stateListAnimator.getTuples().get(0);
        assertEquals("first tuple should have one state", 1, tuple1.getSpecs().length);
        assertEquals("first spec in tuple 1 should be pressed",
                com.android.internal.R.attr.state_pressed, tuple1.getSpecs()[0]);

        StateListAnimator.Tuple tuple2 = stateListAnimator.getTuples().get(1);
        assertEquals("Second tuple should have two specs", 2, tuple2.getSpecs().length);
        assertTrue("Tuple two should match the expected state",
                StateSet.stateSetMatches(tuple2.getSpecs(),
                new int[]{-com.android.internal.R.attr.state_pressed,
                com.android.internal.R.attr.state_enabled}));