FileDocCategorySizeDatePackage
FocusChangeWithInterestingRectHintTest.javaAPI DocAndroid 5.1 API4535Thu Mar 12 22:22:12 GMT 2015android.widget.focus

FocusChangeWithInterestingRectHintTest

public class FocusChangeWithInterestingRectHintTest extends android.test.ActivityInstrumentationTestCase
{@link android.view.FocusFinder#findNextFocus(android.view.ViewGroup, android.view.View, int)} and {@link android.view.View#requestFocus(int, android.graphics.Rect)} work together to give a newly focused item a hint about the most interesting rectangle of the previously focused view. The view taking focus can use this to set an internal selection more appropriate using this rect. This tests that behavior using three adjacent {@link android.util.InternalSelectionView} that report interesting rects when giving up focus, and use interesting rects when taking focus to best select the internal row to show as selected.

Fields Summary
private android.util.InternalSelectionView
mLeftColumn
private android.util.InternalSelectionView
mMiddleColumn
private android.util.InternalSelectionView
mRightColumn
Constructors Summary
public FocusChangeWithInterestingRectHintTest()

        super("com.android.frameworks.coretests", AdjacentVerticalRectLists.class);
    
Methods Summary
public voidsetUp()

        super.setUp();
        mLeftColumn = getActivity().getLeftColumn();
        mMiddleColumn = getActivity().getMiddleColumn();
        mRightColumn = getActivity().getRightColumn();
    
public voidtestPreconditions()

        assertNotNull(mLeftColumn);
        assertNotNull(mMiddleColumn);
        assertNotNull(mRightColumn);
        assertTrue(mLeftColumn.hasFocus());
        assertTrue("need at least 3 rows", mLeftColumn.getNumRows() > 2);
        assertEquals(mLeftColumn.getNumRows(), mMiddleColumn.getNumRows());
        assertEquals(mMiddleColumn.getNumRows(), mRightColumn.getNumRows());
    
public voidtestSnakeBackAndForth()

        final int numRows = mLeftColumn.getNumRows();
        for (int row = 0; row < numRows; row++) {

            if ((row % 2) == 0) {
                assertEquals("row " + row + ": should be at left column",
                        row, mLeftColumn.getSelectedRow());

                sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT);
                assertTrue("row " + row + ": should be at middle column",
                        mMiddleColumn.hasFocus());
                assertEquals(row, mMiddleColumn.getSelectedRow());

                sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT);
                assertTrue("row " + row + ": should be at right column",
                        mRightColumn.hasFocus());
                assertEquals(row, mRightColumn.getSelectedRow());

                if (row < numRows - 1) {
                    sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
                    assertEquals(row + 1, mRightColumn.getSelectedRow());
                }
            } else {
                assertTrue("row " + row + ": should be at right column",
                        mRightColumn.hasFocus());

                sendKeys(KeyEvent.KEYCODE_DPAD_LEFT);
                assertTrue("row " + row + ": should be at middle column",
                        mMiddleColumn.hasFocus());
                assertEquals(row, mMiddleColumn.getSelectedRow());

                sendKeys(KeyEvent.KEYCODE_DPAD_LEFT);
                assertEquals("row " + row + ": should be at left column",
                        row, mLeftColumn.getSelectedRow());

                if (row < numRows - 1) {
                    sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
                    assertEquals(row + 1, mLeftColumn.getSelectedRow());
                }
           }
        }