public void hideSoftKeyboard ( EditText editText , boolean shouldSleepFirst , boolean shouldSleepAfter ) { InputMethodManager inputMethodManager ; Activity activity = activityUtils . getCurrentActivity ( shouldSleepFirst ) ; if ( activity == null ) { inputMethodManager = ( InputMethodManager ) instrumentation . getTargetContext ( ) . getSystemService ( Context . INPUT_METHOD_SERVICE ) ; } else { inputMethodManager = ( InputMethodManager ) activity . getSystemService ( Activity . INPUT_METHOD_SERVICE ) ; } if ( editText != null ) { inputMethodManager . hideSoftInputFromWindow ( editText . getWindowToken ( ) , 0 ) ; return ; } View focusedView = activity . getCurrentFocus ( ) ; if ( ! ( focusedView instanceof EditText ) ) { EditText freshestEditText = viewFetcher . getFreshestView ( viewFetcher . getCurrentViews ( EditText . class , true ) ) ; if ( freshestEditText != null ) { focusedView = freshestEditText ; } } if ( focusedView != null ) { inputMethodManager . hideSoftInputFromWindow ( focusedView . getWindowToken ( ) , 0 ) ; } if ( shouldSleepAfter ) { sleeper . sleep ( ) ; } }
Hides the soft keyboard