use of android.widget.Button in project platform_frameworks_base by android.
the class ScrollViewButtonsAndLabels method onCreate.
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.scrollview_linear_layout);
// estimated ratio to get enough buttons so a couple are off screen
int screenHeight = getWindowManager().getDefaultDisplay().getHeight();
mNumGroups = screenHeight / 30;
mScrollView = (ScrollView) findViewById(R.id.scrollView);
mLinearLayout = (LinearLayout) findViewById(R.id.layout);
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
for (int i = 0; i < mNumGroups; i++) {
// want button to be first and last
if (i > 0) {
TextView textView = new TextView(this);
textView.setText("Text View " + i);
mLinearLayout.addView(textView, p);
}
Button button = new Button(this);
button.setText("Button " + (i + 1));
mLinearLayout.addView(button, p);
}
}
use of android.widget.Button in project platform_frameworks_base by android.
the class ScrollViewButtonsAndLabelsTest method findFirstButtonOffScreenTop2Bottom.
// search from top to bottom for the first button off screen
private int findFirstButtonOffScreenTop2Bottom() {
int[] origin = { 0, 0 };
mScrollView.getLocationOnScreen(origin);
int screenHeight = mScrollView.getHeight();
for (int i = 0; i < getActivity().getNumButtons(); i++) {
int[] buttonLoc = { 0, 0 };
Button button = getActivity().getButton(i);
button.getLocationOnScreen(buttonLoc);
if (buttonLoc[1] - origin[1] > screenHeight) {
return i;
}
}
fail("couldn't find first button off screen");
// this won't execute, but the compiler needs it
return -1;
}
use of android.widget.Button in project platform_frameworks_base by android.
the class ScrollViewButtonsAndLabelsTest method testArrowScrollDownOffScreenVerticalFadingEdge.
// moving down to something off screen should move the element
// onto the screen just above the vertical fading edge
@LargeTest
public void testArrowScrollDownOffScreenVerticalFadingEdge() {
int offScreenIndex = findFirstButtonOffScreenTop2Bottom();
Button firstButtonOffScreen = getActivity().getButton(offScreenIndex);
for (int i = 0; i < offScreenIndex; i++) {
sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
}
getInstrumentation().waitForIdleSync();
assertTrue(firstButtonOffScreen.hasFocus());
assertTrue("the button we've moved to off screen must not be the last " + "button in the scroll view for this test to work (since we " + "are expecting the fading edge to be there).", offScreenIndex < getActivity().getNumButtons());
// now we are at the first button off screen
int[] buttonLoc = { 0, 0 };
firstButtonOffScreen.getLocationOnScreen(buttonLoc);
int buttonBottom = buttonLoc[1] + firstButtonOffScreen.getHeight();
int verticalFadingEdgeLength = mScrollView.getVerticalFadingEdgeLength();
assertEquals("bottom of button should be verticalFadingEdgeLength " + "above the bottom of the screen", buttonBottom, mScreenBottom - verticalFadingEdgeLength);
}
use of android.widget.Button in project platform_frameworks_base by android.
the class ScrollViewButtonsAndLabelsTest method findFirstButtonOffScreenBottom2Top.
private int findFirstButtonOffScreenBottom2Top() {
int[] origin = { 0, 0 };
mScrollView.getLocationOnScreen(origin);
for (int i = getActivity().getNumButtons() - 1; i >= 0; i--) {
int[] buttonLoc = { 0, 0 };
Button button = getActivity().getButton(i);
button.getLocationOnScreen(buttonLoc);
if (buttonLoc[1] < 0) {
return i;
}
}
fail("couldn't find first button off screen");
// this won't execute, but the compiler needs it
return -1;
}
use of android.widget.Button in project platform_frameworks_base by android.
the class ScrollViewButtonsAndLabelsTest method testArrowScrollDownToBottomElementOnScreen.
// there should be no offset for vertical fading edge
// if the item is the last one on screen
@LargeTest
public void testArrowScrollDownToBottomElementOnScreen() {
int numGroups = getActivity().getNumButtons();
Button lastButton = getActivity().getButton(numGroups - 1);
assertEquals("button needs to be at the very bottom of the layout for " + "this test to work", mLinearLayout.getHeight(), lastButton.getBottom());
// move down to last button
for (int i = 0; i < numGroups; i++) {
sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
}
getInstrumentation().waitForIdleSync();
assertTrue("last button should have focus", lastButton.hasFocus());
int[] buttonLoc = { 0, 0 };
lastButton.getLocationOnScreen(buttonLoc);
int buttonBottom = buttonLoc[1] + lastButton.getHeight();
assertEquals("button should be at very bottom of screen", mScreenBottom, buttonBottom);
}
Aggregations