Java Code Examples for android.view.inputmethod.InputMethodManager#isActive()

The following examples show how to use android.view.inputmethod.InputMethodManager#isActive() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DatePickerSpinnerDelegate.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void updateInputState() {
    // Make sure that if the user changes the value and the IME is active
    // for one of the inputs if this widget, the IME is closed. If the user
    // changed the value via the IME and there is a next input the IME will
    // be shown, otherwise the user chose another means of changing the
    // value and having the IME up makes no sense.
    InputMethodManager inputMethodManager = InputMethodManager.peekInstance();
    if (inputMethodManager != null) {
        if (inputMethodManager.isActive(mYearSpinnerInput)) {
            mYearSpinnerInput.clearFocus();
            inputMethodManager.hideSoftInputFromWindow(mDelegator.getWindowToken(), 0);
        } else if (inputMethodManager.isActive(mMonthSpinnerInput)) {
            mMonthSpinnerInput.clearFocus();
            inputMethodManager.hideSoftInputFromWindow(mDelegator.getWindowToken(), 0);
        } else if (inputMethodManager.isActive(mDaySpinnerInput)) {
            mDaySpinnerInput.clearFocus();
            inputMethodManager.hideSoftInputFromWindow(mDelegator.getWindowToken(), 0);
        }
    }
}
 
Example 2
Source File: TimePickerSpinnerDelegate.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void updateInputState() {
    // Make sure that if the user changes the value and the IME is active
    // for one of the inputs if this widget, the IME is closed. If the user
    // changed the value via the IME and there is a next input the IME will
    // be shown, otherwise the user chose another means of changing the
    // value and having the IME up makes no sense.
    InputMethodManager inputMethodManager = InputMethodManager.peekInstance();
    if (inputMethodManager != null) {
        if (inputMethodManager.isActive(mHourSpinnerInput)) {
            mHourSpinnerInput.clearFocus();
            inputMethodManager.hideSoftInputFromWindow(mDelegator.getWindowToken(), 0);
        } else if (inputMethodManager.isActive(mMinuteSpinnerInput)) {
            mMinuteSpinnerInput.clearFocus();
            inputMethodManager.hideSoftInputFromWindow(mDelegator.getWindowToken(), 0);
        } else if (inputMethodManager.isActive(mAmPmSpinnerInput)) {
            mAmPmSpinnerInput.clearFocus();
            inputMethodManager.hideSoftInputFromWindow(mDelegator.getWindowToken(), 0);
        }
    }
}
 
Example 3
Source File: PinViewBaseHelper.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Keyboard back button
 */
@Override
public boolean dispatchKeyEventPreIme(KeyEvent event) {

    if (mKeyboardMandatory) {
        if (getContext() != null) {
            InputMethodManager imm = (InputMethodManager) getContext()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);

            if (imm.isActive() && event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
                setImeVisibility(true);
                return true;
            }
        }
    }
    return super.dispatchKeyEventPreIme(event);
}
 
Example 4
Source File: AndroidUtilities.java    From KrGallery with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isKeyboardShowed(View view) {
    if (view == null) {
        return false;
    }
    try {
        InputMethodManager inputManager = (InputMethodManager) view.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        return inputManager.isActive(view);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
 
Example 5
Source File: SystemUtils.java    From Tok-Android with GNU General Public License v3.0 5 votes vote down vote up
public static void hideSoftKeyBoard(Activity activity) {
    try {
        InputMethodManager imm =
            (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null && imm.isActive() && activity.getCurrentFocus() != null) {
            imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
                InputMethodManager.HIDE_NOT_ALWAYS);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 6
Source File: CreatePinDialogFragment.java    From nano-wallet-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onClickClose(View view) {
    InputMethodManager input = (InputMethodManager) binding.pinEntry.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    if (input != null && input.isActive()) {
        input.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
    }
    dismiss();
}
 
Example 7
Source File: ScreenUtils.java    From PlayTogether with Apache License 2.0 5 votes vote down vote up
/**
 * 隐藏软键盘
 */
public static void hideKeyboard(Context context)
{
	Activity activity = (Activity) context;
	if (activity != null)
	{
		InputMethodManager imm = (InputMethodManager) activity
						.getSystemService(Context.INPUT_METHOD_SERVICE);
		if (imm.isActive() && activity.getCurrentFocus() != null)
		{
			imm.hideSoftInputFromWindow(activity.getCurrentFocus()
							.getWindowToken(), 0);
		}
	}
}
 
Example 8
Source File: InputTools.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
public static boolean KeyBoard(EditText edittext)
{
    boolean bool = false;
    InputMethodManager imm = ( InputMethodManager ) edittext.getContext( ).getSystemService( Context.INPUT_METHOD_SERVICE );
    if ( imm.isActive( ) )
    {
        bool = true;
    }
    return bool;

}
 
Example 9
Source File: CommonUtils.java    From kAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 隐藏键盘
 *
 * @param ctx
 * @param v
 * @return
 */
public static boolean hideSoftInputFromWindow(Context ctx, View v) {
    InputMethodManager imm = (InputMethodManager) ctx
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm.isActive()) {
        imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        return true;
    }
    return false;
}
 
Example 10
Source File: AndroidUtilities.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static void hideKeyboard(View view) {
    if (view == null) {
        return;
    }
    try {
        InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (!imm.isActive()) {
            return;
        }
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    } catch (Exception e) {
        FileLog.e(e);
    }
}
 
Example 11
Source File: CommonUtils.java    From sealtalk-android with MIT License 5 votes vote down vote up
/**
 * 显示软键盘
 * @param activity
 */
public static void showKeyboard(Activity activity) {
	if(activity != null){
		InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
		if(!imm.isActive()){
			imm.showSoftInputFromInputMethod(activity.getCurrentFocus().getWindowToken(), 0);
		}
	}
}
 
Example 12
Source File: EditNotePresenter.java    From SuperNote with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void closeKeyboard(View view) {
    InputMethodManager manager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    if (manager.isActive()) {
        manager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
}
 
Example 13
Source File: AppKeyBoardMgr.java    From AndroidWallet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 输入法是否显示
 */
public static boolean isKeybord(EditText edittext) {
    boolean bool = false;
    InputMethodManager inputMethodManager = (InputMethodManager)
        edittext.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputMethodManager.isActive()) {
        bool = true;
    }
    return bool;
}
 
Example 14
Source File: SearchEditText.java    From SprintNBA with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    pressSearch = (keyCode == KeyEvent.KEYCODE_ENTER);
    if (pressSearch && listener != null) {
        /*隐藏软键盘*/
        InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm.isActive()) {
            imm.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0);
        }
        listener.onSearchClick(v);
    }
    return false;
}
 
Example 15
Source File: NumberPicker.java    From ticdesign with Apache License 2.0 5 votes vote down vote up
/**
 * Hides the soft input if it is active for the input text.
 */
private void hideSoftInput() {
    InputMethodManager inputMethodManager = getValidInputMethodManager();
    if (inputMethodManager != null && inputMethodManager.isActive(mInputText)) {
        inputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0);
        if (mHasSelectorWheel) {
            mInputText.setVisibility(View.INVISIBLE);
        }
    }
}
 
Example 16
Source File: ViewUtils.java    From Mover with Apache License 2.0 5 votes vote down vote up
public static void hideKeyboard(View view) {
    if (view == null) {
        return;
    }
    InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    if (!imm.isActive()) {
        return;
    }
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
 
Example 17
Source File: NumberPicker.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Hides the soft input if it is active for the input text.
 */
private void hideSoftInput() {
    InputMethodManager inputMethodManager = InputMethodManager.peekInstance();
    if (inputMethodManager != null && inputMethodManager.isActive(mInputText)) {
        inputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0);
    }
    if (mHasSelectorWheel) {
        mInputText.setVisibility(View.INVISIBLE);
    }
}
 
Example 18
Source File: InputTools.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
public static void HideKeyboard(View v)
{
    InputMethodManager imm = ( InputMethodManager ) v.getContext( ).getSystemService( Context.INPUT_METHOD_SERVICE );
    if ( imm.isActive( ) ) {
        imm.hideSoftInputFromWindow( v.getApplicationWindowToken( ) , 0 );

    }
}
 
Example 19
Source File: SystemUtils.java    From Tok-Android with GNU General Public License v3.0 5 votes vote down vote up
public static void openSoftKeyBoard(Activity activity) {
    try {
        InputMethodManager imm =
            (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm.isActive() && activity.getCurrentFocus() != null) {
            imm.showSoftInput(activity.getCurrentFocus(), 0);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 20
Source File: InputMethodUtils.java    From AndroidBase with Apache License 2.0 4 votes vote down vote up
public static boolean isActive(Context context) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    return imm.isActive();
}