diff options
author | Svetoslav Ganov <svetoslavganov@google.com> | 2012-01-25 17:00:26 -0800 |
---|---|---|
committer | Svetoslav Ganov <svetoslavganov@google.com> | 2012-01-25 17:05:04 -0800 |
commit | 36a561b4ee35911fd6594c1592aab134be22f0f7 (patch) | |
tree | 50971568b34a113f4e0bcd8feb5c1bf727205df2 /core/tests | |
parent | 08a9e9f20abebf3ba47139dd225da1d0fef8ee84 (diff) | |
download | frameworks_base-36a561b4ee35911fd6594c1592aab134be22f0f7.zip frameworks_base-36a561b4ee35911fd6594c1592aab134be22f0f7.tar.gz frameworks_base-36a561b4ee35911fd6594c1592aab134be22f0f7.tar.bz2 |
Fixing failing focus tests
Change-Id: I3df6a72f6340cbf2e42ce4913e28471e9358088b
Diffstat (limited to 'core/tests')
4 files changed, 42 insertions, 21 deletions
diff --git a/core/tests/coretests/src/android/util/InternalSelectionView.java b/core/tests/coretests/src/android/util/InternalSelectionView.java index babf38d..a0fb0f1 100644 --- a/core/tests/coretests/src/android/util/InternalSelectionView.java +++ b/core/tests/coretests/src/android/util/InternalSelectionView.java @@ -36,6 +36,11 @@ import android.util.AttributeSet; * entire width of the view. The height of the view is divided evenly among * the rows. * + * Note: If the height of the view does not divide exactly to the number of rows, + * the last row's height is inflated with the remainder. For example, if the + * view height is 22 and there are two rows, the height of the first row is + * 10 and the second 22. + * * Notice what this view does to be a good citizen w.r.t its internal selection: * 1) calls {@link View#requestRectangleOnScreen} each time the selection changes due to * internal navigation. @@ -138,9 +143,6 @@ public class InternalSelectionView extends View { @Override protected void onDraw(Canvas canvas) { - - int rowHeight = getRowHeight(); - int rectTop = mPaddingTop; int rectLeft = mPaddingLeft; int rectRight = getWidth() - mPaddingRight; @@ -149,6 +151,8 @@ public class InternalSelectionView extends View { mPainter.setColor(Color.BLACK); mPainter.setAlpha(0x20); + int rowHeight = getRowHeight(i); + // draw background rect mTempRect.set(rectLeft, rectTop, rectRight, rectTop + rowHeight); canvas.drawRect(mTempRect, mPainter); @@ -178,12 +182,19 @@ public class InternalSelectionView extends View { } } - private int getRowHeight() { - return (getHeight() - mPaddingTop - mPaddingBottom) / mNumRows; + private int getRowHeight(int row) { + final int availableHeight = getHeight() - mPaddingTop - mPaddingBottom; + final int desiredRowHeight = availableHeight / mNumRows; + if (row < mNumRows - 1) { + return desiredRowHeight; + } else { + final int residualHeight = availableHeight % mNumRows; + return desiredRowHeight + residualHeight; + } } public void getRectForRow(Rect rect, int row) { - final int rowHeight = getRowHeight(); + final int rowHeight = getRowHeight(row); final int top = mPaddingTop + row * rowHeight; rect.set(mPaddingLeft, top, @@ -197,10 +208,7 @@ public class InternalSelectionView extends View { requestRectangleOnScreen(mTempRect); } - - /* (non-Javadoc) - * @see android.view.KeyEvent.Callback#onKeyDown(int, android.view.KeyEvent) - */ + @Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch(event.getKeyCode()) { case KeyEvent.KEYCODE_DPAD_UP: diff --git a/core/tests/coretests/src/android/widget/focus/ListOfInternalSelectionViews.java b/core/tests/coretests/src/android/widget/focus/ListOfInternalSelectionViews.java index 6518341..53b866c 100644 --- a/core/tests/coretests/src/android/widget/focus/ListOfInternalSelectionViews.java +++ b/core/tests/coretests/src/android/widget/focus/ListOfInternalSelectionViews.java @@ -17,6 +17,7 @@ package android.widget.focus; import android.app.Activity; +import android.graphics.Point; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; @@ -110,7 +111,10 @@ public class ListOfInternalSelectionViews extends Activity { @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); - mScreenHeight = getWindowManager().getDefaultDisplay().getHeight(); + + Point size = new Point(); + getWindowManager().getDefaultDisplay().getSize(size); + mScreenHeight = size.y; Bundle extras = getIntent().getExtras(); if (extras != null) { diff --git a/core/tests/coretests/src/android/widget/focus/RequestFocusTest.java b/core/tests/coretests/src/android/widget/focus/RequestFocusTest.java index 909a8c9..a78b0c9 100644 --- a/core/tests/coretests/src/android/widget/focus/RequestFocusTest.java +++ b/core/tests/coretests/src/android/widget/focus/RequestFocusTest.java @@ -90,7 +90,7 @@ public class RequestFocusTest extends ActivityInstrumentationTestCase<RequestFoc fail("requestFocus from wrong thread should raise exception."); } catch (AndroidRuntimeException e) { // Expected. The actual exception is not public, so we can't catch it. - assertEquals("android.view.ViewAncestor$CalledFromWrongThreadException", + assertEquals("android.view.ViewRootImpl$CalledFromWrongThreadException", e.getClass().getName()); } } diff --git a/core/tests/coretests/src/android/widget/focus/ScrollingThroughListOfFocusablesTest.java b/core/tests/coretests/src/android/widget/focus/ScrollingThroughListOfFocusablesTest.java index eb9192a..795e09c 100644 --- a/core/tests/coretests/src/android/widget/focus/ScrollingThroughListOfFocusablesTest.java +++ b/core/tests/coretests/src/android/widget/focus/ScrollingThroughListOfFocusablesTest.java @@ -20,10 +20,9 @@ import android.graphics.Rect; import android.test.InstrumentationTestCase; import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.MediumTest; +import android.util.InternalSelectionView; import android.view.KeyEvent; import android.widget.ListView; -import android.widget.focus.ListOfInternalSelectionViews; -import android.util.InternalSelectionView; /** @@ -51,6 +50,10 @@ public class ScrollingThroughListOfFocusablesTest extends InstrumentationTestCas mNumRowsPerItem, // 5 internally selectable rows per item mScreenHeightFactor)); // each item is 5 / 4 screen height tall mListView = mActivity.getListView(); + // Make sure we have some fading edge regardless of ListView style. + mListView.setVerticalFadingEdgeEnabled(true); + mListView.setFadingEdgeLength(10); + ensureNotInTouchMode(); } @Override @@ -67,12 +70,12 @@ public class ScrollingThroughListOfFocusablesTest extends InstrumentationTestCas assertEquals(mNumRowsPerItem, mActivity.getNumRowsPerItem()); } - // TODO: needs to be adjusted to pass on non-HVGA displays - // @MediumTest + @MediumTest public void testScrollingDownInFirstItem() throws Exception { for (int i = 0; i < mNumRowsPerItem; i++) { assertEquals(0, mListView.getSelectedItemPosition()); + InternalSelectionView view = mActivity.getSelectedView(); assertInternallySelectedRowOnScreen(view, i); @@ -90,13 +93,12 @@ public class ScrollingThroughListOfFocusablesTest extends InstrumentationTestCas mListView.getSelectedView(); // 1 pixel tolerance in case height / 4 is not an even number - final int fadingEdge = mListView.getBottom() - mListView.getVerticalFadingEdgeLength(); + final int bottomFadingEdgeTop = + mListView.getBottom() - mListView.getVerticalFadingEdgeLength(); assertTrue("bottom of view should be just above fading edge", - view.getBottom() >= fadingEdge - 1 && - view.getBottom() <= fadingEdge); + view.getBottom() == bottomFadingEdgeTop); } - // make sure fading edge is the expected view { assertEquals("should be a second view visible due to the fading edge", @@ -109,7 +111,6 @@ public class ScrollingThroughListOfFocusablesTest extends InstrumentationTestCas } } - @MediumTest public void testScrollingToSecondItem() throws Exception { @@ -223,4 +224,12 @@ public class ScrollingThroughListOfFocusablesTest extends InstrumentationTestCas assertTrue("bottom of row " + row + " should be on sreen", mTempRect.bottom < mActivity.getScreenHeight()); } + + private void ensureNotInTouchMode() { + // If in touch mode inject a DPAD down event to exit that mode. + if (mListView.isInTouchMode()) { + sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); + getInstrumentation().waitForIdleSync(); + } + } } |