FileDocCategorySizeDatePackage
ListItemsExpandOnSelectionTest.javaAPI DocAndroid 1.5 API4402Wed May 06 22:42:02 BST 2009com.android.frameworktest.listview.arrowscroll

ListItemsExpandOnSelectionTest

public class ListItemsExpandOnSelectionTest extends android.test.ActivityInstrumentationTestCase

Fields Summary
private android.widget.ListView
mListView
private int
mListTop
private int
mListBottom
private int
mExpandedHeight
private int
mNormalHeight
Constructors Summary
public ListItemsExpandOnSelectionTest()

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

        super.setUp();
        mListView = getActivity().getListView();
        mListTop = mListView.getListPaddingTop();
        mListBottom = mListView.getHeight() - mListView.getListPaddingBottom();
        mExpandedHeight = mListView.getChildAt(0).getHeight();
        mNormalHeight = mListView.getChildAt(1).getHeight();
    
public voidtestMoveSelectionDownNotRequiringScroll()


        sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);

        assertEquals(1, mListView.getSelectedItemPosition());
        assertEquals("first item's top should not have shifted",
                mListTop, mListView.getChildAt(0).getTop());

    
public voidtestMoveSelectionDownRequiringScroll()

        int lastItemIndex = mListView.getChildCount() - 1;

        for(int i = 0; i < lastItemIndex; i++) {
            sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        }
        getInstrumentation().waitForIdleSync();

        assertEquals("list position", lastItemIndex, mListView.getSelectedItemPosition());
        assertEquals("expanded height", mExpandedHeight, mListView.getSelectedView().getHeight());
        assertEquals("should be above bottom fading edge",
                mListBottom - mListView.getVerticalFadingEdgeLength(),
                mListView.getSelectedView().getBottom());
    
public voidtestMoveSelectionUpNotRequiringScroll()

        sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);

        assertEquals(1, mListView.getSelectedItemPosition());
        final int oldBottom = mListView.getSelectedView().getBottom();

        sendKeys(KeyEvent.KEYCODE_DPAD_UP);

        assertEquals("bottom of 2nd itme should have stayed the same when " +
                "moving back up",
                oldBottom,
                mListView.getChildAt(1).getBottom());
    
public voidtestMoveSelectionUpRequiringScroll()

        int childrenPerScreen = mListView.getChildCount();

        // go down past last child on screen
        for(int i = 0; i < childrenPerScreen; i++) {
            sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        }

        // go back up to second to last
        for(int i = 0; i < childrenPerScreen - 1; i++) {
            sendKeys(KeyEvent.KEYCODE_DPAD_UP);
        }
        getInstrumentation().waitForIdleSync();

        assertEquals("list position", 1, mListView.getSelectedItemPosition());
        assertEquals("expanded height", mExpandedHeight, mListView.getSelectedView().getHeight());
        assertEquals("should be below top fading edge",
                mListTop + mListView.getVerticalFadingEdgeLength(),
                mListView.getSelectedView().getTop());
    
public voidtestPreconditions()

        assertEquals(0, mListView.getSelectedItemPosition());
        assertEquals("selected item should be 1.5 times taller than the others",
                mExpandedHeight, (int) (mNormalHeight * 1.5));