Search in sources :

Example 31 with Button

use of android.widget.Button in project platform_frameworks_base by android.

the class ViewPropertyAnimatorTest method setUp.

/**
     * Sets up the fields used by each test. Subclasses must override this method to create
     * the protected mAnimator object used in all tests. Overrides must create that animator
     * and then call super.setup(), where further properties are set on that animator.
     * @throws Exception
     */
@Override
public void setUp() throws Exception {
    final BasicAnimatorActivity activity = getActivity();
    Button button = (Button) activity.findViewById(R.id.animatingButton);
    mAnimator = button.animate().x(100).y(100);
    super.setUp();
    // mListener is the main testing mechanism of this file. The asserts of each test
    // are embedded in the listener callbacks that it implements.
    mListener = new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animation) {
            // This should only be called on an animation that has not yet been started
            assertFalse(mStarted);
            assertTrue(mRunning);
            mStarted = true;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            // This should only be called on an animation that has been started and not
            // yet canceled or ended
            assertFalse(mCanceled);
            assertTrue(mRunning);
            assertTrue(mStarted);
            mCanceled = true;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            // This should only be called on an animation that has been started and not
            // yet ended
            assertTrue(mRunning);
            assertTrue(mStarted);
            mRunning = false;
            mStarted = false;
            super.onAnimationEnd(animation);
        }
    };
    mAnimator.setListener(mListener);
    mAnimator.setDuration(ANIM_DURATION);
    mFuture = new FutureWaiter();
    mRunning = false;
    mCanceled = false;
    mStarted = false;
}
Also used : ViewPropertyAnimator(android.view.ViewPropertyAnimator) Button(android.widget.Button)

Example 32 with Button

use of android.widget.Button in project platform_frameworks_base by android.

the class ListItemFocusablesFarApartTest method testPanWhenNextFocusableTooFarDown.

@MediumTest
public void testPanWhenNextFocusableTooFarDown() {
    int expectedTop = mListView.getChildAt(0).getTop();
    final Button topButton = (Button) getChildOfItem(0, 0);
    int counter = 0;
    while (getTopOfChildOfItem(0, 2) > mListBottom) {
        // just to make sure we never end up with an infinite loop
        if (counter > 5)
            fail("couldn't reach next button within " + counter + " downs");
        if (getBottomOfChildOfItem(0, 0) < mListTop) {
            assertFalse("after " + counter + " downs, top button not visible, should not have focus", topButton.isFocused());
            assertFalse("after " + counter + " downs, neither top button nor botom button visible, nothng within first list " + "item should have focus", mListView.getChildAt(0).hasFocus());
        } else {
            assertTrue("after " + counter + " downs, top button still visible, should have focus", topButton.isFocused());
        }
        assertEquals("after " + counter + " downs, " + "should have panned by max scroll amount", expectedTop, mListView.getChildAt(0).getTop());
        sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        expectedTop -= mListView.getMaxScrollAmount();
        counter++;
    }
    // at this point, the second button is visible on screen.
    // it should have focus
    assertTrue("second button should have focus", getChildOfItem(0, 2).isFocused());
}
Also used : Button(android.widget.Button) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 33 with Button

use of android.widget.Button in project platform_frameworks_base by android.

the class RequestFocus method onCreate.

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.focus_after_removal);
    // bottom right button starts with the focus.
    final Button bottomRightButton = (Button) findViewById(R.id.bottomRightButton);
    bottomRightButton.requestFocus();
    bottomRightButton.setText("I should have focus");
}
Also used : Button(android.widget.Button)

Example 34 with Button

use of android.widget.Button in project platform_frameworks_base by android.

the class RequestFocusTest method testOnFocusChangeCallbackOrderWhenClearingFocusOfFirstFocusable.

/**
     * This tests checks the case in which the first focusable View clears focus.
     * In such a case the framework tries to give the focus to another View starting
     * from the top. Hence, the framework will try to give focus to the view that
     * wants to clear its focus.
     *
     * @throws Exception If an error occurs.
     */
@UiThreadTest
public void testOnFocusChangeCallbackOrderWhenClearingFocusOfFirstFocusable() throws Exception {
    // Get the first focusable.
    Button clearingFocusButton = mTopLeftButton;
    Button gainingFocusButton = mTopLeftButton;
    // Make sure that the clearing focus View is the first focusable.
    View focusCandidate = clearingFocusButton.getRootView().getParent().focusSearch(null, View.FOCUS_FORWARD);
    assertSame("The clearing focus button is the first focusable.", clearingFocusButton, focusCandidate);
    assertSame("The gaining focus button is the first focusable.", gainingFocusButton, focusCandidate);
    // Focus the clearing focus button.
    clearingFocusButton.requestFocus();
    assertTrue(clearingFocusButton.hasFocus());
    // Register the invocation order checker.
    CombinedListeners mock = mock(CombinedListeners.class);
    clearingFocusButton.setOnFocusChangeListener(mock);
    gainingFocusButton.setOnFocusChangeListener(mock);
    clearingFocusButton.getViewTreeObserver().addOnGlobalFocusChangeListener(mock);
    // Try to clear focus.
    clearingFocusButton.clearFocus();
    // Check that no callback was invoked since focus did not move.
    InOrder inOrder = inOrder(mock);
    inOrder.verify(mock).onFocusChange(clearingFocusButton, false);
    inOrder.verify(mock).onGlobalFocusChanged(clearingFocusButton, gainingFocusButton);
    inOrder.verify(mock).onFocusChange(gainingFocusButton, true);
}
Also used : InOrder(org.mockito.InOrder) Button(android.widget.Button) View(android.view.View) UiThreadTest(android.test.UiThreadTest)

Example 35 with Button

use of android.widget.Button in project platform_frameworks_base by android.

the class VerticalFocusSearch method makeWide.

private Button makeWide(String label) {
    Button button = new MyButton(this);
    button.setText(label);
    button.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    return button;
}
Also used : Button(android.widget.Button) LinearLayout(android.widget.LinearLayout)

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