Example usage for android.view.inputmethod InputConnection clearMetaKeyStates

List of usage examples for android.view.inputmethod InputConnection clearMetaKeyStates

Introduction

In this page you can find the example usage for android.view.inputmethod InputConnection clearMetaKeyStates.

Prototype

boolean clearMetaKeyStates(int states);

Source Link

Document

Clear the given meta key pressed states in the given input connection.

Usage

From source file:org.pocketworkstation.pckeyboard.LatinIME.java

public void sendModifiableKeyChar(char ch) {
    // Support modified key events
    boolean modShift = isShiftMod();
    if ((modShift || mModCtrl || mModAlt || mModMeta) && ch > 0 && ch < 127) {
        InputConnection ic = getCurrentInputConnection();
        if (isConnectbot()) {
            if (mModAlt) {
                // send ESC prefix
                ic.commitText(Character.toString((char) 27), 1);
            }/*ww w.  j  a  v  a  2s  .  c  o m*/
            if (mModCtrl) {
                int code = ch & 31;
                if (code == 9) {
                    sendTab();
                } else {
                    ic.commitText(Character.toString((char) code), 1);
                }
            } else {
                ic.commitText(Character.toString(ch), 1);
            }
            handleModifierKeysUp(false, false);
            return;
        }

        // Non-ConnectBot

        // Restrict Shift modifier to ENTER and SPACE, supporting Shift-Enter etc.
        // Note that most special keys such as DEL or cursor keys aren't handled
        // by this charcode-based method.

        int combinedCode = asciiToKeyCode[ch];
        if (combinedCode > 0) {
            int code = combinedCode & KF_MASK;
            boolean shiftable = (combinedCode & KF_SHIFTABLE) > 0;
            boolean upper = (combinedCode & KF_UPPER) > 0;
            boolean letter = (combinedCode & KF_LETTER) > 0;
            boolean shifted = modShift && (upper || shiftable);
            if (letter && !mModCtrl && !mModAlt && !mModMeta) {
                // Try workaround for issue 179 where letters don't get upcased
                ic.commitText(Character.toString(ch), 1);
                handleModifierKeysUp(false, false);
            } else if ((ch == 'a' || ch == 'A') && mModCtrl) {
                // Special case for Ctrl-A to work around accidental select-all-then-replace.
                if (sKeyboardSettings.ctrlAOverride == 0) {
                    // Ignore Ctrl-A, treat Ctrl-Alt-A as Ctrl-A.
                    if (mModAlt) {
                        boolean isChordingAlt = mAltKeyState.isChording();
                        setModAlt(false);
                        sendModifiedKeyDownUp(code, shifted);
                        if (isChordingAlt)
                            setModAlt(true);
                    } else {
                        Toast.makeText(getApplicationContext(),
                                getResources().getString(R.string.toast_ctrl_a_override_info),
                                Toast.LENGTH_LONG).show();
                        // Clear the Ctrl modifier (and others)
                        sendModifierKeysDown(shifted);
                        sendModifierKeysUp(shifted);
                        return; // ignore the key
                    }

                } else if (sKeyboardSettings.ctrlAOverride == 1) {
                    // Clear the Ctrl modifier (and others)
                    sendModifierKeysDown(shifted);
                    sendModifierKeysUp(shifted);
                    return; // ignore the key
                } else {
                    // Standard Ctrl-A behavior.
                    sendModifiedKeyDownUp(code, shifted);
                }
            } else {
                sendModifiedKeyDownUp(code, shifted);
            }
            return;
        }
    }

    if (ch >= '0' && ch <= '9') {
        //WIP
        InputConnection ic = getCurrentInputConnection();
        ic.clearMetaKeyStates(KeyEvent.META_SHIFT_ON | KeyEvent.META_ALT_ON | KeyEvent.META_SYM_ON);
        //EditorInfo ei = getCurrentInputEditorInfo();
        //Log.i(TAG, "capsmode=" + ic.getCursorCapsMode(ei.inputType));
        //sendModifiedKeyDownUp(KeyEvent.KEYCODE_0 + ch - '0');
        //return;
    }

    // Default handling for anything else, including unmodified ENTER and SPACE.
    sendKeyChar(ch);
}