FocusChangeWithInterestingRectHintTestpublic 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 void | setUp()
super.setUp();
mLeftColumn = getActivity().getLeftColumn();
mMiddleColumn = getActivity().getMiddleColumn();
mRightColumn = getActivity().getRightColumn();
| public void | testPreconditions()
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 void | testSnakeBackAndForth()
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());
}
}
}
|
|