Fields Summary |
---|
private android.widget.ScrollView | mScrollView |
private android.widget.Button | mClickToScrollFromAbove |
private android.widget.Button | mClickToScrollToUpperBlob |
private android.widget.TextView | mTopBlob |
private android.view.View | mChildToScrollTo |
private android.widget.TextView | mBottomBlob |
private android.widget.Button | mClickToScrollToBlobLowerBlob |
private android.widget.Button | mClickToScrollFromBelow |
Methods Summary |
---|
public static void | assertOnBottomEdgeOfScreen(android.view.View origin, android.view.View view)Assert that view overlaps the bottom edge of the screen
int[] xy = new int[2];
view.getLocationOnScreen(xy);
int[] xyRoot = new int[2];
origin.getLocationOnScreen(xyRoot);
int bottom = xy[1] + view.getHeight();
int bottomOfRoot = xyRoot[1] + origin.getHeight();
assertTrue(bottom > bottomOfRoot);
assertTrue(xy[1] < bottomOfRoot);
assertTrue(bottom > bottomOfRoot);
|
public static void | assertOnTopEdgeOfScreen(android.view.View origin, android.view.View view)Assert that view overlaps the bottom edge of the screen
int[] xy = new int[2];
view.getLocationOnScreen(xy);
int[] xyRoot = new int[2];
origin.getLocationOnScreen(xyRoot);
int bottom = xy[1] + view.getHeight();
int bottomOfRoot = xyRoot[1] + origin.getHeight();
assertTrue(bottom < bottomOfRoot);
assertTrue(bottom > xyRoot[1]);
assertTrue(xy[1] < xyRoot[1]);
|
private void | pressDownUntilViewInFocus(android.view.View view, int maxKeyPress)Press the down key until a particular view is in focus
int count = 0;
while(!view.hasFocus()) {
sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
getInstrumentation().waitForIdleSync();
// just in case...
if (++count > maxKeyPress) {
fail("couldn't move down to bottom button within "
+ maxKeyPress + " key presses.");
}
}
|
protected void | setUp()
super.setUp();
RequestRectangleVisible a = getActivity();
mScrollView = (ScrollView) a.findViewById(R.id.scrollView);
mClickToScrollFromAbove = (Button) a.findViewById(R.id.scrollToRectFromTop);
mClickToScrollToUpperBlob = (Button) a.findViewById(R.id.scrollToRectFromTop2);
mTopBlob = (TextView) a.findViewById(R.id.topBlob);
mChildToScrollTo = a.findViewById(R.id.childToMakeVisible);
mBottomBlob = (TextView) a.findViewById(R.id.bottomBlob);
mClickToScrollToBlobLowerBlob = (Button) a.findViewById(R.id.scrollToRectFromBottom2);
mClickToScrollFromBelow = (Button) a.findViewById(R.id.scrollToRectFromBottom);
|
public void | testPreconditions()
assertNotNull(mScrollView);
assertNotNull(mClickToScrollFromAbove);
assertNotNull(mClickToScrollToUpperBlob);
assertNotNull(mTopBlob);
assertNotNull(mChildToScrollTo);
assertNotNull(mBottomBlob);
assertNotNull(mClickToScrollToBlobLowerBlob);
assertNotNull(mClickToScrollFromBelow);
assertTrue("top blob needs to be taller than the screen for many of the "
+ "tests below to work.",
mTopBlob.getHeight() > mScrollView.getHeight());
assertTrue("bottom blob needs to be taller than the screen for many of the "
+ "tests below to work.",
mBottomBlob.getHeight() > mScrollView.getHeight());
assertTrue("top blob needs to be lower than the fading edge region",
mTopBlob.getTop() > mScrollView.getVerticalFadingEdgeLength());
|
public void | testScrollToOffScreenRectangleFromBottom()
// go to bottom button
pressDownUntilViewInFocus(mClickToScrollFromBelow, 10);
// view is off screen above
assertTrue(mClickToScrollFromBelow.hasFocus());
ViewAsserts.assertOffScreenAbove(mScrollView, mChildToScrollTo);
// click
sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
getInstrumentation().waitForIdleSync(); // wait for scrolling to finish
// on screen, positioned at top (with room for fading edge)
ViewAsserts.assertOnScreen(mScrollView, mChildToScrollTo);
ViewAsserts.assertHasScreenCoordinates(
mScrollView, mChildToScrollTo, 0, mScrollView.getVerticalFadingEdgeLength());
|
public void | testScrollToOffScreenRectangleFromTop()
// view is off screen
assertTrue(mClickToScrollFromAbove.hasFocus());
ViewAsserts.assertOffScreenBelow(mScrollView, mChildToScrollTo);
// click
sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
getInstrumentation().waitForIdleSync(); // wait for scrolling to finish
// should be on screen, positioned at the bottom (with room for
// fading edge)
ViewAsserts.assertOnScreen(mScrollView, mChildToScrollTo);
ViewAsserts.assertHasScreenCoordinates(
mScrollView, mChildToScrollTo,
0,
mScrollView.getHeight()
- mChildToScrollTo.getHeight()
- mScrollView.getVerticalFadingEdgeLength());
|
public void | testScrollToPartiallyOffScreenRectFromBottom()
pressDownUntilViewInFocus(mClickToScrollToBlobLowerBlob, 10);
// make sure the blob is indeed partially on screen above
assertOnTopEdgeOfScreen(mScrollView, mBottomBlob);
// click
sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
getInstrumentation().waitForIdleSync(); // wait for scrolling to finish
// blob should have moved so bottom of it is at bottom of screen
// with room for vertical fading edge
ViewAsserts.assertHasScreenCoordinates(
mScrollView, mBottomBlob,
0,
mScrollView.getHeight() - mBottomBlob.getHeight()
- mScrollView.getVerticalFadingEdgeLength());
|
public void | testScrollToPartiallyOffScreenRectFromTop()
pressDownUntilViewInFocus(mClickToScrollToUpperBlob, 4);
// make sure the blob is indeed partially on screen below
assertOnBottomEdgeOfScreen(mScrollView, mTopBlob);
// click
sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
getInstrumentation().waitForIdleSync(); // wait for scrolling to finish
// blob should have moved so top of it is at top of screen (with
// room for the vertical fading edge
ViewAsserts.assertHasScreenCoordinates(
mScrollView, mTopBlob, 0, mScrollView.getVerticalFadingEdgeLength());
|