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

ListItemRequestRectAboveThinFirstItemTest

public class ListItemRequestRectAboveThinFirstItemTest extends android.test.ActivityInstrumentationTestCase

Fields Summary
private android.widget.ListView
mListView
Constructors Summary
public ListItemRequestRectAboveThinFirstItemTest()

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

        super.setUp();
        mListView = getActivity().getListView();
    
public voidtestPreconditions()


        assertTrue("first child needs to be within fading edge height",
                mListView.getChildAt(0).getBottom() < mListView.getVerticalFadingEdgeLength());
        assertTrue("should be at least two visible children",
                mListView.getChildCount() >= 2);
    
public voidtestSecondItemRequestRectAboveTop()


        sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        assertEquals("selected position", 1, mListView.getSelectedItemPosition());

        final View second = mListView.getChildAt(1);
        final Rect rect = new Rect();
        second.getDrawingRect(rect);
        rect.offset(0, -2 * second.getBottom());

        getActivity().requestRectangleOnScreen(1, rect);
        getInstrumentation().waitForIdleSync();        

        assertEquals("top of first item",
                mListView.getListPaddingTop(), mListView.getChildAt(0).getTop());

    
public voidtestSecondToLastItemRequestRectBelowBottom()


        final int secondToLastPos = mListView.getCount() - 2;

        while (mListView.getSelectedItemPosition() < secondToLastPos) {
            sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        }
        assertEquals("selected position", secondToLastPos,
                mListView.getSelectedItemPosition());

        final View secondToLast = mListView.getSelectedView();
        final Rect rect = new Rect();
        secondToLast.getDrawingRect(rect);
        rect.offset(0,
                2 * (mListView.getBottom() - secondToLast.getTop()));

        final int secondToLastIndex = mListView.getChildCount() - 2;
        getActivity().requestRectangleOnScreen(secondToLastIndex, rect);
        getInstrumentation().waitForIdleSync();

        int listBottom = mListView.getHeight() - mListView.getPaddingBottom();
        assertEquals("bottom of last item should be at bottom of list",
                listBottom,
                mListView.getChildAt(mListView.getChildCount() - 1).getBottom());