Code example for InputMethodManager

Methods: hideSoftInputFromWindow, isActive

0
    private void applyKeyboardShowHide(boolean autofocus) {
        final InputMethodManager imm = ((InputMethodManager) getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE));
        if (imm != null) {
            if(isDigit) {
                if(imm.isActive(this)) {
                    imm.hideSoftInputFromWindow(getApplicationWindowToken(), 0);
                } 
            }else if(autofocus) {
                imm.showSoftInput(this, 0);
            } 
        } 
    } 
 
    @Override 
    public void sendAccessibilityEventUnchecked(AccessibilityEvent event) {
        if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED) {
            // Since we're replacing the text every time we add or remove a 
            // character, only read the difference. (issue 5337550) 
            final int added = event.getAddedCount();
            final int removed = event.getRemovedCount();