FileDocCategorySizeDatePackage
GridScrollListenerTest.javaAPI DocAndroid 1.5 API3926Wed May 06 22:42:02 BST 2009com.android.frameworktest.gridview

GridScrollListenerTest

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

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


      
        super("com.android.frameworktest", 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);