FileDocCategorySizeDatePackage
ListButtonsDiagonalAcrossItemsTest.javaAPI DocAndroid 5.1 API3931Thu Mar 12 22:22:12 GMT 2015android.widget.listview.focus

ListButtonsDiagonalAcrossItemsTest

public class ListButtonsDiagonalAcrossItemsTest extends android.test.ActivityInstrumentationTestCase
Test that ListView will override default behavior of focus searching to make sure going right and left doesn't change selection

Fields Summary
private android.widget.Button
mLeftButton
private android.widget.Button
mCenterButton
private android.widget.Button
mRightButton
private android.widget.ListView
mListView
Constructors Summary
public ListButtonsDiagonalAcrossItemsTest()

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

        super.setUp();

        mLeftButton = getActivity().getLeftButton();
        mCenterButton = getActivity().getCenterButton();
        mRightButton = getActivity().getRightButton();

        mListView = getActivity().getListView();
    
public voidtestGoingLeftDoesNotChangeSelection()

        sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        assertEquals("list view postion", 1, mListView.getSelectedItemPosition());
        assertTrue("mCenterButton.isFocused()", mCenterButton.isFocused());

        sendKeys(KeyEvent.KEYCODE_DPAD_LEFT);
        assertEquals("selected position shouldn't have changed",
                1,
                mListView.getSelectedItemPosition());
        assertTrue("center should still be focused", mCenterButton.isFocused());
    
public voidtestGoingRightDoesNotChangeSelection()

        sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT);

        assertEquals("selected position shouldn't have changed",
                0,
                mListView.getSelectedItemPosition());
        assertTrue("left should still be focused", mLeftButton.isFocused());
    
public voidtestPreconditions()

        final ListView lv = mListView;
        assertEquals("num children", 3, lv.getChildCount());

        assertEquals("selected position", 0, lv.getSelectedItemPosition());
        assertTrue("left button focused", mLeftButton.isFocused());

        assertTrue("left left of center",
                mLeftButton.getRight()
                        < mCenterButton.getLeft());

        assertTrue("center left of right",
                mCenterButton.getRight()
                        < mRightButton.getLeft());

        assertEquals("focus search right from left button should be center button",
            mCenterButton,
            FocusFinder.getInstance().findNextFocus(mListView, mLeftButton, View.FOCUS_RIGHT));
        assertEquals("focus search right from center button should be right button",
            mRightButton,
            FocusFinder.getInstance().findNextFocus(mListView, mCenterButton, View.FOCUS_RIGHT));
        assertEquals("focus search left from centr button should be left button",
            mLeftButton,
            FocusFinder.getInstance().findNextFocus(mListView, mCenterButton, View.FOCUS_LEFT));