FileDocCategorySizeDatePackage
ListTouchBottomGravityManyTest.javaAPI DocAndroid 5.1 API5844Thu Mar 12 22:22:12 GMT 2015android.widget.listview.touch

ListTouchBottomGravityManyTest

public class ListTouchBottomGravityManyTest extends android.test.ActivityInstrumentationTestCase
Touch tests for a list where all of the items do not fit on the screen, and the list stacks from the bottom.

Fields Summary
private android.widget.listview.ListBottomGravityMany
mActivity
private android.widget.ListView
mListView
Constructors Summary
public ListTouchBottomGravityManyTest()

        super("com.android.frameworks.coretests", ListBottomGravityMany.class);
    
Methods Summary
protected voidsetUp()

        super.setUp();

        mActivity = getActivity();
        mListView = getActivity().getListView();
    
public voidtestLongScroll()

        View firstChild = mListView.getChildAt(0);
        if (firstChild.getTop() < mListView.getListPaddingTop()) {
            firstChild = mListView.getChildAt(1);
        }

        int firstTop = firstChild.getTop();

        int distance = TouchUtils.dragViewBy(this, firstChild, 
                Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 
                (int)(mActivity.getWindowManager().getDefaultDisplay().getHeight() * 0.75f));
        
        assertEquals("View scrolled to wrong position", firstTop
                + (distance - ViewConfiguration.getTouchSlop() - 1), firstChild.getTop());
    
public voidtestNoScroll()

        View firstChild = mListView.getChildAt(0);
        View lastChild = mListView.getChildAt(mListView.getChildCount() - 1);
        
        int lastTop = lastChild.getTop();
        
        TouchUtils.dragViewBy(this, firstChild, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL,
                0, ViewConfiguration.getTouchSlop());
        
        View newLastChild = mListView.getChildAt(mListView.getChildCount() - 1);
        
        assertEquals("View scrolled too early", lastTop, newLastChild.getTop());
        assertEquals("Wrong view in last position", mListView.getAdapter().getCount() - 1, 
                newLastChild.getId());
    
public voidtestPreconditions()

        assertNotNull(mActivity);
        assertNotNull(mListView);
        
        // Last item should be selected
        assertEquals(mListView.getAdapter().getCount() - 1, mListView.getSelectedItemPosition());
    
public voidtestPullDown()

     
        int originalCount = mListView.getChildCount();
        
        TouchUtils.scrollToTop(this, mListView);
        
        // Nothing should be selected
        assertEquals("Selection still available after touch", -1, 
                mListView.getSelectedItemPosition());
        
        View firstChild = mListView.getChildAt(0);
        
        assertEquals("Item zero not the first child in the list", 0, firstChild.getId());
        
        assertEquals("Item zero not at the top of the list", mListView.getListPaddingTop(),
                firstChild.getTop());
        
        assertTrue(String.format("Too many children created: %d expected no more than %d", 
                mListView.getChildCount(), originalCount + 1), 
                mListView.getChildCount() <= originalCount + 1);
    
public voidtestPushUp()

        TouchUtils.scrollToBottom(this, mListView);

        // Nothing should be selected
        assertEquals("Selection still available after touch", -1, 
                mListView.getSelectedItemPosition());

        View lastChild = mListView.getChildAt(mListView.getChildCount() - 1);

        assertEquals("List is not scrolled to the bottom", mListView.getAdapter().getCount() - 1,
                lastChild.getId());

        assertEquals("Last item is not touching the bottom edge", 
                mListView.getHeight() - mListView.getListPaddingBottom(), lastChild.getBottom());
    
public voidtestShortScroll()

        View firstChild = mListView.getChildAt(0);
        if (firstChild.getTop() < this.mListView.getListPaddingTop()) {
            firstChild = mListView.getChildAt(1);
        }
            
        View lastChild = mListView.getChildAt(mListView.getChildCount() - 1);
        
        int lastTop = lastChild.getTop();
        
        TouchUtils.dragViewBy(this, firstChild, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL,
                0, ViewConfiguration.getTouchSlop() + 1 + 10);
        
        View newLastChild = mListView.getChildAt(mListView.getChildCount() - 1);
        
        assertEquals("View scrolled to wrong position", lastTop, newLastChild.getTop() - 10);
        assertEquals("Wrong view in last position", mListView.getAdapter().getCount() - 1,
                newLastChild.getId());