FileDocCategorySizeDatePackage
ImfBaseTestCase.javaAPI DocAndroid 5.1 API5518Thu Mar 12 22:22:44 GMT 2015com.android.imftest.samples

ImfBaseTestCase

public abstract class ImfBaseTestCase extends android.test.InstrumentationTestCase

Fields Summary
public final long
WAIT_FOR_IME
public final int
IME_MIN_HEIGHT
public final int
IME_MAX_HEIGHT
protected android.view.inputmethod.InputMethodManager
mImm
protected T
mTargetActivity
protected boolean
mExpectAutoPop
private Class
mTargetActivityClass
Constructors Summary
public ImfBaseTestCase(Class activityClass)


       
        mTargetActivityClass = activityClass;
    
Methods Summary
public voiddestructiveCheckImeInitialState(android.view.View rootView, android.view.View servedView)

        int windowSoftInputMode = mTargetActivity.getWindow().getAttributes().softInputMode;
        int adjustMode = windowSoftInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
        if (mExpectAutoPop && adjustMode == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) {
            assertTrue(destructiveCheckImeUp(rootView, servedView));
        } else {
            assertFalse(destructiveCheckImeUp(rootView, servedView));
        }
    
public booleandestructiveCheckImeUp(android.view.View rootView, android.view.View servedView)

        int origHeight;
        int newHeight;

        origHeight = rootView.getHeight();

        // Tell the keyboard to go away.
        mImm.hideSoftInputFromWindow(servedView.getWindowToken(), 0);

        // Give it five seconds to adjust
        newHeight = rootView.getHeight();
        long timeoutTime = SystemClock.uptimeMillis() + WAIT_FOR_IME;
        while (Math.abs(newHeight - origHeight) < IME_MIN_HEIGHT && SystemClock.uptimeMillis() < timeoutTime) {
            newHeight = rootView.getHeight();
        }

        return (Math.abs(origHeight - newHeight) >= IME_MIN_HEIGHT);
    
voidpause(int millis)

        try {
            Thread.sleep(millis);
        } catch (InterruptedException e) {
        }
    
public voidsetUp()

        super.setUp();
        final String packageName = getInstrumentation().getTargetContext().getPackageName();
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
        mTargetActivity = launchActivityWithIntent(packageName, mTargetActivityClass, intent);
        // expect ime to auto pop up if device has no hard keyboard
        int keyboardType = mTargetActivity.getResources().getConfiguration().keyboard;
        mExpectAutoPop = (keyboardType  == Configuration.KEYBOARD_NOKEYS ||
                keyboardType == Configuration.KEYBOARD_UNDEFINED);

        mImm = InputMethodManager.getInstance();

        KeyguardManager keyguardManager =
            (KeyguardManager) getInstrumentation().getContext().getSystemService(
                    Context.KEYGUARD_SERVICE);
        keyguardManager.newKeyguardLock("imftest").disableKeyguard();
    
public voidverifyEditTextAdjustment(android.view.View editText, int rootViewHeight)


        int[] origLocation = new int[2];
        int[] newLocation = new int[2];

        // Tell the keyboard to go away.
        mImm.hideSoftInputFromWindow(editText.getWindowToken(), 0);

        // Bring the target EditText into focus.
        mTargetActivity.runOnUiThread(new Runnable() {
            public void run() {
                editText.requestFocus();
            }
        });

        // Get the original location of the EditText.
        editText.getLocationOnScreen(origLocation);

        // Tap the EditText to bring up the IME.
        sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);

        // Wait until the EditText pops above the IME or until we hit the timeout.
        editText.getLocationOnScreen(newLocation);
        long timeoutTime = SystemClock.uptimeMillis() + WAIT_FOR_IME;
        while (newLocation[1] > rootViewHeight - IME_MIN_HEIGHT && SystemClock.uptimeMillis() < timeoutTime) {
            editText.getLocationOnScreen(newLocation);
            pause(100);
        }

        assertTrue(newLocation[1] <= rootViewHeight - IME_MIN_HEIGHT);

        // Tell the keyboard to go away.
        mImm.hideSoftInputFromWindow(editText.getWindowToken(), 0);