FileDocCategorySizeDatePackage
ScrollerCompatTestBase.javaAPI DocAndroid 5.1 API2970Thu Mar 12 22:22:56 GMT 2015android.support.v4.widget

ScrollerCompatTestBase

public abstract class ScrollerCompatTestBase extends android.test.AndroidTestCase

Fields Summary
private static final boolean
DEBUG
private final String
TAG
private final int
mApiLevel
private ScrollerCompat
mScroller
Constructors Summary
public ScrollerCompatTestBase(int apiLevel)


       
        mApiLevel = apiLevel;
        TAG = "ScrollerCompatTest api:" + apiLevel;
    
Methods Summary
protected voidcreateScroller(android.view.animation.Interpolator interpolator)

        Constructor<ScrollerCompat> constructor = ScrollerCompat.class
                .getDeclaredConstructor(int.class, Context.class, Interpolator.class);
        constructor.setAccessible(true);
        mScroller = constructor.newInstance(mApiLevel, getContext(), interpolator);
    
public voidtestAbort()

        if (DEBUG) {
            Log.d(TAG, "testing abort");
        }
        createScroller(null);
        mScroller.fling(0, 0, 0, 10000,
                Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE);
        assertTrue("Scroller should have some offset", mScroller.computeScrollOffset());
        mScroller.abortAnimation();
        assertFalse("Scroller should clear offset after being aborted",
                mScroller.computeScrollOffset());
    
public voidtestTargetReached()

        if (DEBUG) {
            Log.d(TAG, "testing if target is reached");
        }
        createScroller(null);
        mScroller.fling(0, 0, 0, 1000,
                Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE);
        int target = mScroller.getFinalY();
        while (mScroller.computeScrollOffset()) {
            Thread.sleep(100);
        }
        assertEquals("given enough time, scroller should reach target position", target,
                mScroller.getCurrY());