FileDocCategorySizeDatePackage
GridScrollListenerTest.javaAPI DocAndroid 5.1 API3911Thu Mar 12 22:22:12 GMT 2015android.widget.gridview

GridScrollListenerTest

public class GridScrollListenerTest extends android.test.ActivityInstrumentationTestCase implements AbsListView.OnScrollListener

Fields Summary
private android.widget.gridview.GridScrollListener
mActivity
private android.widget.GridView
mGridView
private int
mFirstVisibleItem
private int
mVisibleItemCount
private int
mTotalItemCount
Constructors Summary
public GridScrollListenerTest()


      
        super("com.android.frameworks.coretests", GridScrollListener.class);
    
Methods Summary
public voidonScroll(android.widget.AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)

        mFirstVisibleItem = firstVisibleItem;
        mVisibleItemCount = visibleItemCount;
        mTotalItemCount = totalItemCount;
    
public voidonScrollStateChanged(android.widget.AbsListView view, int scrollState)

    
protected voidsetUp()

        super.setUp();

        mActivity = getActivity();
        mGridView = getActivity().getGridView();
        mGridView.setOnScrollListener(this);
    
public voidtestKeyScrolling()

        Instrumentation inst = getInstrumentation();
        
        int firstVisibleItem = mFirstVisibleItem;
        for (int i = 0; i < mVisibleItemCount * 2; i++) {
            inst.sendCharacterSync(KeyEvent.KEYCODE_DPAD_DOWN);
        }
        inst.waitForIdleSync();
        
        assertTrue("Arrow scroll did not happen", mFirstVisibleItem > firstVisibleItem);
        
        firstVisibleItem = mFirstVisibleItem;
        inst.sendCharacterSync(KeyEvent.KEYCODE_SPACE);
        inst.waitForIdleSync();
        
        assertTrue("Page scroll did not happen", mFirstVisibleItem > firstVisibleItem);
        
        firstVisibleItem = mFirstVisibleItem;
        KeyEvent down = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, 
                KeyEvent.KEYCODE_DPAD_DOWN, 0, KeyEvent.META_ALT_ON);
        KeyEvent up = new KeyEvent(0, 0, KeyEvent.ACTION_UP, 
                KeyEvent.KEYCODE_DPAD_DOWN, 0, KeyEvent.META_ALT_ON);
        inst.sendKeySync(down);
        inst.sendKeySync(up);
        inst.waitForIdleSync();
        
        assertTrue("Full scroll did not happen", mFirstVisibleItem > firstVisibleItem);
        assertEquals("Full scroll did not happen", mTotalItemCount, 
                mFirstVisibleItem + mVisibleItemCount);    
    
public voidtestPreconditions()

        assertNotNull(mActivity);
        assertNotNull(mGridView);
        
        assertEquals(0, mFirstVisibleItem);
    
public voidtestTouchScrolling()

        Instrumentation inst = getInstrumentation();
        
        int firstVisibleItem = mFirstVisibleItem;
        TouchUtils.dragQuarterScreenUp(this);
        TouchUtils.dragQuarterScreenUp(this);
        assertTrue("Touch scroll did not happen", mFirstVisibleItem > firstVisibleItem);