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

ListOfItemsShorterThanScreenTest

public class ListOfItemsShorterThanScreenTest extends android.test.ActivityInstrumentationTestCase

Fields Summary
private android.widget.ListView
mListView
private com.android.frameworktest.listview.ListOfItemsShorterThanScreen
mActivity
Constructors Summary
public ListOfItemsShorterThanScreenTest()

        super("com.android.frameworktest", ListOfItemsShorterThanScreen.class);
    
Methods Summary
private intgetTopOfBottomFadingEdge()

        return mListView.getHeight() - (mListView.getVerticalFadingEdgeLength() + mListView.getListPaddingBottom());
    
protected voidsetUp()

        super.setUp();
        mActivity = getActivity();
        mListView = getActivity().getListView();
    
public voidtestMoveDownToItemRequiringScrolling()

        final int lastOnScreenItemIndex = mListView.getChildCount() - 1;
        final View lastItem = mListView.getChildAt(lastOnScreenItemIndex);
        assertTrue("last item should be partially off screen",
                lastItem.getBottom() > mListView.getBottom());
        assertEquals(mListView.getListPaddingTop(), mListView.getSelectedView().getTop());

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

        assertEquals(lastOnScreenItemIndex, mListView.getSelectedItemPosition());
        assertEquals(
                getTopOfBottomFadingEdge(),
                mListView.getSelectedView().getBottom());

        // there should be a peeking view

        // the current view isn't the last anymore...
        assertEquals(mListView.getSelectedView(), mListView.getChildAt(mListView.getChildCount() - 2));

        // peeking view is now last
        final TextView view = (TextView) mListView.getChildAt(mListView.getChildCount() - 1);
        assertEquals(mActivity.getValueAtPosition(lastOnScreenItemIndex + 1), view.getText());
        assertFalse(view.isSelected());
    
public voidtestMoveDownToOnScreenNextItem()

        final View next = mListView.getChildAt(1);
        assertFalse(next.isSelected());
        final int secondPosition = mListView.getSelectedView().getBottom();
        assertEquals("second item should be positioned item height pixels from top.",
                secondPosition,
                next.getTop());

        sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        assertEquals(1, mListView.getSelectedItemPosition());
        assertTrue(next.isSelected());
        assertEquals("next selected item shouldn't have moved",
                secondPosition,
                next.getTop());
    
public voidtestMoveUpToItemRequiringScrolling()

        // go down to one past last item, then back up to the second item.  this will
        // require scrolling to get it back on screen, and will need a peeking edge

        int numItemsOnScreen = mListView.getChildCount();
        for (int i = 0; i < numItemsOnScreen; i++) {
            sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        }
        for (int i = 0; i < numItemsOnScreen - 1; i++) {
            sendKeys(KeyEvent.KEYCODE_DPAD_UP);
        }

        assertEquals(1, mListView.getSelectedItemPosition());
        assertEquals("top should be just below vertical fading edge",
                mListView.getVerticalFadingEdgeLength() + mListView.getListPaddingTop(),
                mListView.getSelectedView().getTop());
    
public voidtestMoveUpToOnScreenItem()

        // move down one, then back up
        sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        sendKeys(KeyEvent.KEYCODE_DPAD_UP);
        assertEquals(0, mListView.getSelectedItemPosition());
    
public voidtestNoVerticalFadingEdgeWhenMovingToBottom()

        final int lastItemPosition = mListView.getAdapter().getCount() - 1;
        for (int i = 0; i < lastItemPosition; i++) {
            sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        }
        assertEquals(lastItemPosition, mListView.getSelectedItemPosition());

        assertEquals("bottom of last item should be just above padding; no fading edge.",
                mListView.getHeight() - mListView.getListPaddingBottom(),
                mListView.getSelectedView().getBottom());

    
public voidtestPreconditions()

        assertEquals(0, mListView.getSelectedItemPosition());
        assertTrue(mListView.getChildAt(0).isSelected());
        assertEquals(mListView.getListPaddingTop(), mListView.getSelectedView().getTop());
    
public voidtestPressDownWhenAlreadyAtBottom()

        final int lastItemPosition = mListView.getAdapter().getCount() - 1;
        for (int i = 0; i < lastItemPosition; i++) {
            sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        }
        assertEquals(lastItemPosition, mListView.getSelectedItemPosition());

        sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        assertEquals(lastItemPosition, mListView.getSelectedItemPosition());
    
public voidtestPressUpWhenAlreadyAtTop()

        sendKeys(KeyEvent.KEYCODE_DPAD_UP);

        assertEquals(0, mListView.getSelectedItemPosition());