FileDocCategorySizeDatePackage
ListScrollListenerTest.javaAPI DocAndroid 1.5 API3792Wed May 06 22:42:02 BST 2009com.android.frameworktest.listview

ListScrollListenerTest

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

Fields Summary
private ListScrollListener
mActivity
private android.widget.ListView
mListView
private int
mFirstVisibleItem
private int
mVisibleItemCount
private int
mTotalItemCount
Constructors Summary
public ListScrollListenerTest()


      
        super("com.android.frameworktest", ListScrollListener.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();
        mListView = getActivity().getListView();
        mListView.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(mListView);
        
        assertEquals(0, mFirstVisibleItem);
    
public voidtestTouchScrolling()

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