FileDocCategorySizeDatePackage
TouchModeFocusableTest.javaAPI DocAndroid 5.1 API3433Thu Mar 12 22:22:12 GMT 2015android.widget.touchmode

TouchModeFocusableTest

public class TouchModeFocusableTest extends android.test.ActivityInstrumentationTestCase
Some views, like edit texts, can keep and gain focus even when in touch mode.

Fields Summary
private android.widget.EditText
mEditText
private android.widget.Button
mButton
Constructors Summary
public TouchModeFocusableTest()

        super("com.android.frameworks.coretests", LLEditTextThenButton.class);
    
Methods Summary
protected voidsetUp()

        super.setUp();

        mEditText = getActivity().getEditText();
        mButton = getActivity().getButton();
    
public voidtestClickButtonEditTextKeepsFocus()

        assertInTouchModeAfterTap(this, mButton);
        assertTrue("should be in touch mode", mButton.isInTouchMode());
        assertTrue("edit text should still have focus", mEditText.isFocused());
    
public voidtestClickEditTextGivesItFocus()

        // go down to button
        sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        assertTrue("button should have focus", mButton.isFocused());

        assertInTouchModeAfterClick(this, mEditText);
        assertTrue("clicking edit text should have entered touch mode", mButton.isInTouchMode());
        assertTrue("clicking edit text should have given it focus", mEditText.isFocused());
    
public voidtestEnterTouchModeGivesFocusBackToFocusableInTouchMode()

        sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);

        assertTrue("button should have focus",
                mButton.isFocused());
        
        assertInTouchModeAfterClick(this, mButton);
        assertTrue("should be in touch mode", mButton.isInTouchMode());
        assertNull("nothing should have focus", getActivity().getCurrentFocus());
        assertFalse("layout should not have focus",
                getActivity().getLayout().hasFocus());
    
public voidtestPreconditions()

        assertFalse("should not be in touch mode to start off", mButton.isInTouchMode());
        assertTrue("edit text should have focus", mEditText.isFocused());
        assertTrue("edit text should be focusable in touch mode", mEditText.isFocusableInTouchMode());