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

ListManagedCursorTest

public class ListManagedCursorTest extends android.test.ActivityInstrumentationTestCase
Tests restoring the scroll position in a list with a managed cursor.

Fields Summary
private ListManagedCursor
mActivity
private android.widget.ListView
mListView
Constructors Summary
public ListManagedCursorTest()

        super("com.android.frameworktest", ListManagedCursor.class);
    
Methods Summary
public intarrowScroll(android.app.Instrumentation inst)

        int count = mListView.getChildCount();

        for (int i = 0; i < count * 2; i++) {
            inst.sendCharacterSync(KeyEvent.KEYCODE_DPAD_DOWN);
        }
        inst.waitForIdleSync();

        int firstVisiblePosition = mListView.getFirstVisiblePosition();
        assertTrue("Arrow scroll did not happen", firstVisiblePosition > 0);
        assertTrue("List still in touch mode", !mListView.isInTouchMode());

        inst.sendCharacterSync(KeyEvent.KEYCODE_DPAD_CENTER);
        inst.waitForIdleSync();

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return firstVisiblePosition;
    
protected voidsetUp()

        super.setUp();

        mActivity = getActivity();
        mListView = getActivity().getListView();
    
public voidtestKeyScrolling()
Scroll the list using arrows, launch new activity, hit back, make sure we're still scrolled.

        Instrumentation inst = getInstrumentation();
        
        int firstVisiblePosition = arrowScroll(inst);
        
        inst.sendCharacterSync(KeyEvent.KEYCODE_BACK);
        inst.waitForIdleSync();
        
        assertTrue("List changed to touch mode", !mListView.isInTouchMode()); 
        assertTrue("List did not preserve scroll position", 
                firstVisiblePosition == mListView.getFirstVisiblePosition()); 
    
public voidtestKeyScrollingToTouchMode()
Scroll the list using arrows, launch new activity, change to touch mode, hit back, make sure we're still scrolled.

        Instrumentation inst = getInstrumentation();
        
        int firstVisiblePosition = arrowScroll(inst);
        
        TouchUtils.dragQuarterScreenUp(this);
        inst.sendCharacterSync(KeyEvent.KEYCODE_BACK);
        inst.waitForIdleSync();
        
        assertTrue("List did not change to touch mode", mListView.isInTouchMode()); 
        assertTrue("List did not preserve scroll position", 
                firstVisiblePosition == mListView.getFirstVisiblePosition()); 
    
public voidtestPreconditions()

        assertNotNull(mActivity);
        assertNotNull(mListView);
        
        assertEquals(0, mListView.getFirstVisiblePosition());
    
public voidtestTouchScrolling()
Scroll the list using touch, launch new activity, hit back, make sure we're still scrolled.

        Instrumentation inst = getInstrumentation();
        
       int firstVisiblePosition = touchScroll(inst);
        
        inst.sendCharacterSync(KeyEvent.KEYCODE_BACK);
        inst.waitForIdleSync();
        
        assertTrue("List not in touch mode", mListView.isInTouchMode()); 
        assertTrue("List did not preserve scroll position", 
                firstVisiblePosition == mListView.getFirstVisiblePosition()); 
    
public voidtestTouchScrollingToTrackballMode()
Scroll the list using touch, launch new activity, change to trackball mode, hit back, make sure we're still scrolled.

        Instrumentation inst = getInstrumentation();

        int firstVisiblePosition = touchScroll(inst);

        inst.sendCharacterSync(KeyEvent.KEYCODE_DPAD_DOWN);
        inst.waitForIdleSync();
        inst.sendCharacterSync(KeyEvent.KEYCODE_DPAD_DOWN);
        inst.waitForIdleSync();
        inst.sendCharacterSync(KeyEvent.KEYCODE_BACK);
        inst.waitForIdleSync();
        assertTrue("List not in trackball mode", !mListView.isInTouchMode());
        assertTrue("List did not preserve scroll position", firstVisiblePosition == mListView
                .getFirstVisiblePosition());
    
public inttouchScroll(android.app.Instrumentation inst)

        TouchUtils.dragQuarterScreenUp(this);
        inst.waitForIdleSync();
        TouchUtils.dragQuarterScreenUp(this);
        inst.waitForIdleSync();
        TouchUtils.dragQuarterScreenUp(this);
        inst.waitForIdleSync();
        TouchUtils.dragQuarterScreenUp(this);
        inst.waitForIdleSync();

        int firstVisiblePosition = mListView.getFirstVisiblePosition();
        assertTrue("Touch scroll did not happen", firstVisiblePosition > 0);
        assertTrue("List not in touch mode", mListView.isInTouchMode());

        TouchUtils.clickView(this, mListView.getChildAt(mListView.getChildCount() - 1));
        inst.waitForIdleSync();

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return firstVisiblePosition;