FileDocCategorySizeDatePackage
GridTouchSetSelectionTest.javaAPI DocAndroid 1.5 API2615Wed May 06 22:42:02 BST 2009com.android.frameworktest.gridview.touch

GridTouchSetSelectionTest

public class GridTouchSetSelectionTest extends android.test.ActivityInstrumentationTestCase
Tests setting the selection in touch mode

Fields Summary
private com.android.frameworktest.gridview.GridSimple
mActivity
private android.widget.GridView
mGridView
Constructors Summary
public GridTouchSetSelectionTest()

        super("com.android.frameworktest", GridSimple.class);
    
Methods Summary
protected voidsetUp()

        super.setUp();

        mActivity = getActivity();
        mGridView = getActivity().getGridView();
    
public voidtestPreconditions()

        assertNotNull(mActivity);
        assertNotNull(mGridView);
    
public voidtestSetSelection()

        TouchUtils.dragQuarterScreenDown(this);
        TouchUtils.dragQuarterScreenUp(this);
        
        // Nothing should be selected
        assertEquals("Selection still available after touch", -1, 
                mGridView.getSelectedItemPosition());
        
        final int targetPosition = mGridView.getAdapter().getCount() / 2;
        
        mActivity.runOnUiThread(new Runnable() {
            public void run() {
                mGridView.setSelection(targetPosition);
            }
        });
        getInstrumentation().waitForIdleSync();
        
        boolean found = false;
        int childCount = mGridView.getChildCount();
        for (int i=0; i<childCount; i++) {
            View child = mGridView.getChildAt(i);
            if (child.getId() == targetPosition) {
                found = true;
                break;
            }
        }
        assertTrue("Selected item not visible in list", found);