FileDocCategorySizeDatePackage
TouchModeFocusChangeTest.javaAPI DocAndroid 5.1 API3316Thu Mar 12 22:22:12 GMT 2015android.widget.touchmode

TouchModeFocusChangeTest

public class TouchModeFocusChangeTest extends android.test.ActivityInstrumentationTestCase
Make sure focus isn't kept by buttons when entering touch mode. When in touch mode and hitting the d-pad, we should leave touch mode and the top most focusable gets focus.

Fields Summary
private android.widget.layout.linear.LLOfButtons1
mActivity
private android.widget.Button
mFirstButton
Constructors Summary
public TouchModeFocusChangeTest()

        super("com.android.frameworks.coretests", LLOfButtons1.class);
    
Methods Summary
public voidDISABLE_testLeaveTouchModeWithDpadEvent()

        assertInTouchModeAfterClick(this, mFirstButton);

        assertTrue("should be in touch mode", mActivity.isInTouchMode());
        assertFalse("button should not have focus when touched",
                mFirstButton.isFocused());

        assertNotInTouchModeAfterKey(this, KeyEvent.KEYCODE_DPAD_RIGHT, mFirstButton);
        assertFalse("should be out of touch mode", mActivity.isInTouchMode());
        assertTrue("first button (the top most focusable) should have gained focus",
                mFirstButton.isFocused());
    
protected voidsetUp()

        super.setUp();

        mActivity = getActivity();
        mFirstButton = mActivity.getFirstButton();
    
public voidtestPreconditions()

        assertFalse("we should not be in touch mode", mActivity.isInTouchMode());
        assertTrue("top button should have focus", mFirstButton.isFocused());
    
public voidtestTouchButtonNotTakeFocus()

        assertInTouchModeAfterTap(this, mFirstButton);

        assertTrue("should be in touch mode", mActivity.isInTouchMode());
        assertFalse("button.isFocused",
                mFirstButton.isFocused());
        assertFalse("button.hasFocus",
                mFirstButton.hasFocus());
        assertNull("activity shouldn't have focus", mActivity.getCurrentFocus());
        assertFalse("linear layout should not have focus",
                mActivity.getLayout().hasFocus());

        assertTrue("button's onClickListener should have fired",
                mActivity.buttonClickListenerFired());