FileDocCategorySizeDatePackage
AutoCompleteTextViewCallbacks.javaAPI DocAndroid 5.1 API5643Thu Mar 12 22:22:12 GMT 2015android.widget

AutoCompleteTextViewCallbacks

public class AutoCompleteTextViewCallbacks extends android.test.ActivityInstrumentationTestCase2

Fields Summary
private static final int
WAIT_TIME
Constructors Summary
public AutoCompleteTextViewCallbacks()


      
        super("com.android.frameworks.coretests", AutoCompleteTextViewSimple.class);
    
Methods Summary
public voidtestPopupEnterSelection()
Test that arrow-down into the popup calls the onSelected callback.

        final AutoCompleteTextViewSimple theActivity = getActivity();
        AutoCompleteTextView textView = theActivity.getTextView();
        final Instrumentation instrumentation = getInstrumentation();

        // focus and type
        textView.requestFocus();
        instrumentation.waitForIdleSync();
        sendKeys("A");

        textView.post(new Runnable() {
            public void run() {
                // prepare to move down into the popup
                theActivity.resetItemListeners();
            }
        });

        sendKeys("DPAD_DOWN");
        instrumentation.waitForIdleSync();
        // give UI time to settle
        Thread.sleep(WAIT_TIME);

        // now check for selection callbacks.
        assertFalse("onItemClick should not be called", theActivity.mItemClickCalled);
        assertTrue("onItemSelected should be called", theActivity.mItemSelectedCalled);
        assertEquals("onItemSelected position", 0, theActivity.mItemSelectedPosition);
        assertFalse("onNothingSelected should not be called", theActivity.mNothingSelectedCalled);

        textView.post(new Runnable() {
            public void run() {
                // try one more time - should move from 0 to 1
                theActivity.resetItemListeners();
            }
        });

        sendKeys("DPAD_DOWN");
        instrumentation.waitForIdleSync();        
        // give UI time to settle
        Thread.sleep(WAIT_TIME);

        // now check for selection callbacks.
        assertFalse("onItemClick should not be called", theActivity.mItemClickCalled);
        assertTrue("onItemSelected should be called", theActivity.mItemSelectedCalled);
        assertEquals("onItemSelected position", 1, theActivity.mItemSelectedPosition);
        assertFalse("onNothingSelected should not be called", theActivity.mNothingSelectedCalled);
    
public voidtestPopupLeaveSelection()
Test that arrow-up out of the popup calls the onNothingSelected callback

        final AutoCompleteTextViewSimple theActivity = getActivity();
        AutoCompleteTextView textView = theActivity.getTextView();
        final Instrumentation instrumentation = getInstrumentation();

        // focus and type
        textView.requestFocus();
        instrumentation.waitForIdleSync();
        sendKeys("A");
        instrumentation.waitForIdleSync();

        // move down into the popup
        sendKeys("DPAD_DOWN");
        instrumentation.waitForIdleSync();

        textView.post(new Runnable() {
            public void run() {
                // prepare to move down into the popup
                theActivity.resetItemListeners();
            }
        });

        sendKeys("DPAD_UP");
        instrumentation.waitForIdleSync();

        // now check for selection callbacks.
        assertFalse("onItemClick should not be called", theActivity.mItemClickCalled);
        assertFalse("onItemSelected should not be called", theActivity.mItemSelectedCalled);
        assertTrue("onNothingSelected should be called", theActivity.mNothingSelectedCalled);
    
public voidtestPopupNoSelection()
Test that the initial popup of the suggestions does not select anything.

        AutoCompleteTextViewSimple theActivity = getActivity();
        AutoCompleteTextView textView = theActivity.getTextView();
        final Instrumentation instrumentation = getInstrumentation();

        // focus and type
        textView.requestFocus();
        instrumentation.waitForIdleSync();
        sendKeys("A");
        instrumentation.waitForIdleSync();
        // give UI time to settle
        Thread.sleep(WAIT_TIME);

        // now check for selection callbacks.  Nothing should be clicked or selected.
        assertFalse("onItemClick should not be called", theActivity.mItemClickCalled);
        assertFalse("onItemSelected should not be called", theActivity.mItemSelectedCalled);

        // arguably, this should be "false", because we aren't deselecting - we shouldn't
        // really be calling it.  But it's not the end of the world, and we might wind up
        // breaking something if we change this.
        //assertTrue("onNothingSelected should be called", theActivity.mNothingSelectedCalled);