FileDocCategorySizeDatePackage
FocusChangeWithInterestingRectHintTest.javaAPI DocAndroid 1.5 API4586Wed May 06 22:42:02 BST 2009com.android.frameworktest.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 com.android.frameworktest.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 com.android.frameworktest.util.InternalSelectionView
mLeftColumn
private com.android.frameworktest.util.InternalSelectionView
mMiddleColumn
private com.android.frameworktest.util.InternalSelectionView
mRightColumn
Constructors Summary
public FocusChangeWithInterestingRectHintTest()

        super("com.android.frameworktest", 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());
                }
           }
        }