Search in sources :

Example 61 with Button

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);
    }
}
Also used : Button(android.widget.Button) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 62 with Button

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;
}
Also used : Button(android.widget.Button)

Example 63 with Button

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);
}
Also used : Button(android.widget.Button) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 64 with Button

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;
}
Also used : Button(android.widget.Button)

Example 65 with Button

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);
}
Also used : Button(android.widget.Button) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

Button (android.widget.Button)1477 View (android.view.View)909 TextView (android.widget.TextView)609 OnClickListener (android.view.View.OnClickListener)275 Intent (android.content.Intent)200 LinearLayout (android.widget.LinearLayout)189 ImageView (android.widget.ImageView)146 EditText (android.widget.EditText)126 ListView (android.widget.ListView)112 AdapterView (android.widget.AdapterView)76 ViewGroup (android.view.ViewGroup)65 LayoutInflater (android.view.LayoutInflater)56 CompoundButton (android.widget.CompoundButton)53 ScrollView (android.widget.ScrollView)53 Test (org.junit.Test)51 Bundle (android.os.Bundle)49 CheckBox (android.widget.CheckBox)48 FrameLayout (android.widget.FrameLayout)47 AlertDialog (android.app.AlertDialog)45 ImageButton (android.widget.ImageButton)45