Java Code Examples for android.view.inputmethod.InputConnection#commitText()
The following examples show how to use
android.view.inputmethod.InputConnection#commitText() .
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: LatinIME.java From hackerskeyboard with Apache License 2.0 | 6 votes |
private void doubleSpace() { // if (!mAutoPunctuate) return; if (mCorrectionMode == Suggest.CORRECTION_NONE) return; final InputConnection ic = getCurrentInputConnection(); if (ic == null) return; CharSequence lastThree = ic.getTextBeforeCursor(3, 0); if (lastThree != null && lastThree.length() == 3 && Character.isLetterOrDigit(lastThree.charAt(0)) && lastThree.charAt(1) == ASCII_SPACE && lastThree.charAt(2) == ASCII_SPACE) { ic.beginBatchEdit(); ic.deleteSurroundingText(2, 0); ic.commitText(". ", 1); ic.endBatchEdit(); updateShiftKeyState(getCurrentInputEditorInfo()); mJustAddedAutoSpace = true; } }
Example 2
Source File: InputMethodService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Send the given UTF-16 character to the current input connection. Most * characters will be delivered simply by calling * {@link InputConnection#commitText InputConnection.commitText()} with * the character; some, however, may be handled different. In particular, * the enter character ('\n') will either be delivered as an action code * or a raw key event, as appropriate. Consider this as a convenience * method for IMEs that do not have a full implementation of actions; a * fully complying IME will decide of the right action for each event and * will likely never call this method except maybe to handle events coming * from an actual hardware keyboard. * * @param charCode The UTF-16 character code to send. */ public void sendKeyChar(char charCode) { switch (charCode) { case '\n': // Apps may be listening to an enter key to perform an action if (!sendDefaultEditorAction(true)) { sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER); } break; default: // Make sure that digits go through any text watcher on the client side. if (charCode >= '0' && charCode <= '9') { sendDownUpKeyEvents(charCode - '0' + KeyEvent.KEYCODE_0); } else { InputConnection ic = getCurrentInputConnection(); if (ic != null) { ic.commitText(String.valueOf(charCode), 1); } } break; } }
Example 3
Source File: LatinIME.java From hackerskeyboard with Apache License 2.0 | 6 votes |
private void sendTab() { InputConnection ic = getCurrentInputConnection(); boolean tabHack = isConnectbot() && mConnectbotTabHack; // FIXME: tab and ^I don't work in connectbot, hackish workaround if (tabHack) { if (mModAlt) { // send ESC prefix ic.commitText(Character.toString((char) 27), 1); } ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_I)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_I)); } else { sendModifiedKeyDownUp(KeyEvent.KEYCODE_TAB); } }
Example 4
Source File: BrailleIME.java From brailleback with Apache License 2.0 | 6 votes |
/** * Updates the composing text and commits it to the editor. Returns * {@code true} if the pending braille dots could be translated into text, * otherwise {@code false}. */ private boolean finishComposingText(@NonNull BrailleTranslator translator, @NonNull InputConnection ic) { if (mComposingBraille.position() == 0) { return true; } String text = translator.backTranslate(getComposingBrailleArray()); mComposingBraille.clear(); // Commit the final text if we could translate; otherwise, clear the // composing text. if (TextUtils.isEmpty(text)) { ic.commitText("", 1); return false; } else { return ic.commitText(text, 1); } }
Example 5
Source File: LatinIME.java From hackerskeyboard with Apache License 2.0 | 6 votes |
private void reswapPeriodAndSpace() { final InputConnection ic = getCurrentInputConnection(); if (ic == null) return; CharSequence lastThree = ic.getTextBeforeCursor(3, 0); if (lastThree != null && lastThree.length() == 3 && lastThree.charAt(0) == ASCII_PERIOD && lastThree.charAt(1) == ASCII_SPACE && lastThree.charAt(2) == ASCII_PERIOD) { ic.beginBatchEdit(); ic.deleteSurroundingText(3, 0); ic.commitText(" ..", 1); ic.endBatchEdit(); updateShiftKeyState(getCurrentInputEditorInfo()); } }
Example 6
Source File: IMEService.java From TVRemoteIME with GNU General Public License v2.0 | 6 votes |
private boolean commitText(String text){ InputConnection ic = getCurrentInputConnection(); boolean flag = false; if (ic != null){ if(Environment.needDebug) { Environment.debug(TAG, "commitText:" + text); } if(text.length() > 1 && ic.beginBatchEdit()){ flag = ic.commitText(text, 1); ic.endBatchEdit(); }else{ flag = ic.commitText(text, 1); } } return flag; }
Example 7
Source File: LatinIME.java From hackerskeyboard with Apache License 2.0 | 6 votes |
/** * Commits the chosen word to the text field and saves it for later * retrieval. * * @param suggestion * the suggestion picked by the user to be committed to the text * field * @param correcting * whether this is due to a correction of an existing word. */ private void pickSuggestion(CharSequence suggestion, boolean correcting) { LatinKeyboardView inputView = mKeyboardSwitcher.getInputView(); int shiftState = getShiftState(); if (shiftState == Keyboard.SHIFT_LOCKED || shiftState == Keyboard.SHIFT_CAPS_LOCKED) { suggestion = suggestion.toString().toUpperCase(); // all UPPERCASE } InputConnection ic = getCurrentInputConnection(); if (ic != null) { rememberReplacedWord(suggestion); ic.commitText(suggestion, 1); } saveWordInHistory(suggestion); mPredicting = false; mCommittedLength = suggestion.length(); ((LatinKeyboard) inputView.getKeyboard()).setPreferredLetters(null); // If we just corrected a word, then don't show punctuations if (!correcting) { setNextSuggestions(); } updateShiftKeyState(getCurrentInputEditorInfo()); }
Example 8
Source File: BrailleIME.java From brailleback with Apache License 2.0 | 5 votes |
/** * Updates the composing text based on the braille dots composed thus far, * and maintains the composing state of the editor. * Returns {@code true} if the current string of braille dots could be * translated into text, otherwise {@code false}. */ private boolean updateComposingText(@NonNull BrailleTranslator translator, @NonNull InputConnection ic) { if (mComposingBraille.position() == 0) { return ic.commitText("", 1); } String text = translator.backTranslate(getComposingBrailleArray()); if (TextUtils.isEmpty(text)) { return ic.setComposingText("\u00A0", 1); } else { return ic.setComposingText(text, 1); } }
Example 9
Source File: AdbIME.java From SoloPi with Apache License 2.0 | 5 votes |
@Subscriber(value = @Param(value = IME_MESSAGE, sticky = false), thread = RunningThread.MAIN_THREAD) public boolean inputText(String text) { if (text != null) { InputConnection ic = getCurrentInputConnection(); if (ic != null) { ic.commitText(text, 1); return true; } } return false; }
Example 10
Source File: SoftKeyboard.java From AndroidKeyboard with GNU General Public License v3.0 | 5 votes |
public void onText(CharSequence text) { InputConnection ic = getCurrentInputConnection(); if (ic == null) return; ic.beginBatchEdit(); if (mComposing.length() > 0) { commitTyped(ic); } ic.commitText(text, 0); ic.endBatchEdit(); updateShiftKeyState(getCurrentInputEditorInfo()); }
Example 11
Source File: SoftKeyboard.java From AndroidKeyboard with GNU General Public License v3.0 | 5 votes |
/** * Helper function to commit any text being composed in to the editor. */ private void commitTyped(InputConnection inputConnection) { if (mComposing.length() > 0) { inputConnection.commitText(mComposing, mComposing.length()); mComposing.setLength(0); updateCandidates(); } }
Example 12
Source File: Pathfinder.java From sinovoice-pathfinder with MIT License | 5 votes |
/** * Helper function to commit any text being composed in to the editor. */ private void commitTyped(InputConnection inputConnection) { if (mComposing.length() > 0) { inputConnection.commitText(mComposing, mComposing.length()); mComposing.setLength(0); updateCandidates(); } }
Example 13
Source File: InputMethodService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * @hide */ public void onExtractedSetSpan(Object span, int start, int end, int flags) { InputConnection conn = getCurrentInputConnection(); if (conn != null) { if (!conn.setSelection(start, end)) return; CharSequence text = conn.getSelectedText(InputConnection.GET_TEXT_WITH_STYLES); if (text instanceof Spannable) { ((Spannable) text).setSpan(span, 0, text.length(), flags); conn.setComposingRegion(start, end); conn.commitText(text, 1); } } }
Example 14
Source File: InputMethodService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * @hide */ public void onExtractedReplaceText(int start, int end, CharSequence text) { InputConnection conn = getCurrentInputConnection(); if (conn != null) { conn.setComposingRegion(start, end); conn.commitText(text, 1); } }
Example 15
Source File: AdbIME.java From SoloPi with Apache License 2.0 | 5 votes |
@Subscriber(value = @Param(value = IME_CHARS, sticky = false), thread = RunningThread.MAIN_THREAD) public boolean inputChars(int[] chars) { if (chars != null) { String msg = new String(chars, 0, chars.length); InputConnection ic = getCurrentInputConnection(); if (ic != null){ ic.commitText(msg, 1); return true; } } return false; }
Example 16
Source File: AdbIME.java From SoloPi with Apache License 2.0 | 5 votes |
@Subscriber(value = @Param(value = IME_SEARCH_MESSAGE, sticky = false), thread = RunningThread.MAIN_THREAD) public boolean inputSearchText(String text) { if (text != null) { InputConnection ic = getCurrentInputConnection(); if (ic != null) { ic.commitText(text, 1); // 需要额外点击发送 EditorInfo editorInfo = getCurrentInputEditorInfo(); if (editorInfo != null) { int options = editorInfo.imeOptions; final int actionId = options & EditorInfo.IME_MASK_ACTION; switch (actionId) { case EditorInfo.IME_ACTION_SEARCH: sendDefaultEditorAction(true); break; case EditorInfo.IME_ACTION_GO: sendDefaultEditorAction(true); break; case EditorInfo.IME_ACTION_SEND: sendDefaultEditorAction(true); break; default: ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER)); } } return true; } } return false; }
Example 17
Source File: LatinIME.java From hackerskeyboard with Apache License 2.0 | 4 votes |
private void sendSpecialKey(int code) { if (!isConnectbot()) { commitTyped(getCurrentInputConnection(), true); sendModifiedKeyDownUp(code); return; } // TODO(klausw): properly support xterm sequences for Ctrl/Alt modifiers? // See http://slackware.osuosl.org/slackware-12.0/source/l/ncurses/xterm.terminfo // and the output of "$ infocmp -1L". Support multiple sets, and optional // true numpad keys? if (ESC_SEQUENCES == null) { ESC_SEQUENCES = new HashMap<Integer, String>(); CTRL_SEQUENCES = new HashMap<Integer, Integer>(); // VT escape sequences without leading Escape ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_HOME, "[1~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_END, "[4~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_PAGE_UP, "[5~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_PAGE_DOWN, "[6~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F1, "OP"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F2, "OQ"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F3, "OR"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F4, "OS"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F5, "[15~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F6, "[17~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F7, "[18~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F8, "[19~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F9, "[20~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F10, "[21~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F11, "[23~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F12, "[24~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FORWARD_DEL, "[3~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_INSERT, "[2~"); // Special ConnectBot hack: Ctrl-1 to Ctrl-0 for F1-F10. CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F1, KeyEvent.KEYCODE_1); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F2, KeyEvent.KEYCODE_2); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F3, KeyEvent.KEYCODE_3); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F4, KeyEvent.KEYCODE_4); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F5, KeyEvent.KEYCODE_5); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F6, KeyEvent.KEYCODE_6); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F7, KeyEvent.KEYCODE_7); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F8, KeyEvent.KEYCODE_8); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F9, KeyEvent.KEYCODE_9); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F10, KeyEvent.KEYCODE_0); // Natively supported by ConnectBot // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_UP, "OA"); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_DOWN, "OB"); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_LEFT, "OD"); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_RIGHT, "OC"); // No VT equivalents? // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_CENTER, ""); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_SYSRQ, ""); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_BREAK, ""); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_NUM_LOCK, ""); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_SCROLL_LOCK, ""); } InputConnection ic = getCurrentInputConnection(); Integer ctrlseq = null; if (mConnectbotTabHack) { ctrlseq = CTRL_SEQUENCES.get(code); } String seq = ESC_SEQUENCES.get(code); if (ctrlseq != null) { if (mModAlt) { // send ESC prefix for "Alt" ic.commitText(Character.toString((char) 27), 1); } ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, ctrlseq)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, ctrlseq)); } else if (seq != null) { if (mModAlt) { // send ESC prefix for "Alt" ic.commitText(Character.toString((char) 27), 1); } // send ESC prefix of escape sequence ic.commitText(Character.toString((char) 27), 1); ic.commitText(seq, 1); } else { // send key code, let connectbot handle it sendDownUpKeyEvents(code); } handleModifierKeysUp(false, false); }
Example 18
Source File: IMEService.java From Puff-Android with MIT License | 4 votes |
@Override public void onKey(int primaryCode, int[] keyCodes) { InputConnection ic = getCurrentInputConnection(); switch(primaryCode){ case PuffKeyboardView.KEYCODE_EDIT : Intent intent = new Intent(this, DialogAcctList.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_CLEAR_TASK); getApplicationContext().startActivity(intent); stopSelf(); break; case -11 : ic.commitText(account, 1); account = ""; break; case -12: ic.commitText(password, 1); password = ""; break; case -13: ic.commitText(additional, 1); additional = ""; break; case Keyboard.KEYCODE_DONE: ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER)); break; case Keyboard.KEYCODE_DELETE: ic.deleteSurroundingText(1, 0); break; case Keyboard.KEYCODE_MODE_CHANGE: if(kv.getKeyboard() == symbolKeyboard || kv.getKeyboard() == symsftKeyboard) { currentKeyboard = normalKeyboard; } else { currentKeyboard = symbolKeyboard; } kv.setKeyboard(currentKeyboard); break; case Keyboard.KEYCODE_SHIFT: // if (kv.getKeyboard() == normalKeyboard) { // caps = !caps; // normalKeyboard.setShifted(caps); // kv.invalidateAllKeys(); // } if(currentKeyboard == shiftKeyboard) { currentKeyboard = normalKeyboard; } else { currentKeyboard = shiftKeyboard; } kv.setKeyboard(currentKeyboard); break; case Keyboard.KEYCODE_ALT: if (kv.getKeyboard() == symbolKeyboard) { currentKeyboard = symsftKeyboard; } else { currentKeyboard = symbolKeyboard; } kv.setKeyboard(currentKeyboard); break; case -886 : Toast.makeText(IMEService.this, "close", Toast.LENGTH_SHORT).show(); break ; default: char code = (char)primaryCode; if (caps) { code = Character.toUpperCase(code); } ic.commitText(String.valueOf(code),1); break; } VibrateUtil.getStaticInstance(this).tick(); }
Example 19
Source File: KeyboardCandidateActivity.java From mongol-library with MIT License | 4 votes |
private void addSpace() { InputConnection ic = imeContainer.getInputConnection(); if (ic == null) return; ic.commitText(" ", 1); }
Example 20
Source File: ImeDataSourceHelper.java From Chimee with MIT License | 4 votes |
private void addSpace() { InputConnection ic = getInputConnection(); if (ic == null) return; ic.commitText(" ", 1); }