public static ViewAction closeSoftKeyboard() { return new ViewAction() { /** * The real {@link CloseKeyboardAction} instance. */ private final ViewAction mCloseSoftKeyboard = new CloseKeyboardAction(); @Override public Matcher<View> getConstraints() { return mCloseSoftKeyboard.getConstraints(); } @Override public String getDescription() { return mCloseSoftKeyboard.getDescription(); } @Override public void perform(final UiController uiController, final View view) { mCloseSoftKeyboard.perform(uiController, view); uiController.loopMainThreadForAtLeast(KEYBOARD_DISMISSAL_DELAY_MILLIS); } }; }
/** * Give keyboard time to close, to avoid java.lang.SecurityException * if hidden button is clicked next. */ static ViewAction closeSoftKeyboardWithDelay() { return new ViewAction() { /** * The delay time to allow the soft keyboard to dismiss. */ private static final long KEYBOARD_DISMISSAL_DELAY_MILLIS = 1000L; /** * The real {@link CloseKeyboardAction} instance. */ private final ViewAction mCloseSoftKeyboard = new CloseKeyboardAction(); @Override public Matcher<View> getConstraints() { return mCloseSoftKeyboard.getConstraints(); } @Override public String getDescription() { return mCloseSoftKeyboard.getDescription(); } @Override public void perform(final UiController uiController, final View view) { mCloseSoftKeyboard.perform(uiController, view); uiController.loopMainThreadForAtLeast(KEYBOARD_DISMISSAL_DELAY_MILLIS); } }; }