List of usage examples for android.view.inputmethod InputConnection commitText
boolean commitText(CharSequence text, int newCursorPosition);
From source file:com.volosyukivan.WiFiInputMethod.java
private void keyDel(InputConnection conn) { if (pressedKeys.contains(KeyEvent.KEYCODE_SHIFT_LEFT)) { cut(conn);//from w w w. ja va2s . c o m return; } conn.deleteSurroundingText(0, 1); conn.commitText("", 0); }
From source file:com.volosyukivan.WiFiInputMethod.java
boolean setText(String text) { // FIXME: need feedback if the input was lost InputConnection conn = getCurrentInputConnection(); if (conn == null) { // Debug.d("connection closed"); return false; }/* w ww . j a v a 2 s .co m*/ conn.beginBatchEdit(); // FIXME: hack conn.deleteSurroundingText(100000, 100000); conn.commitText(text, text.length()); conn.endBatchEdit(); return true; }
From source file:net.zhdev.ctrlvkeyboard.CtrlVKeyboard.java
/** * Inserts text in the current focused text editor if possible and if it is a valid one. * * @param text the text to be inserted * @param clearBefore whether the text editor should be cleared before inserting the text * @param endWithAction whether the IME action should be performed at the end * @return {@code true} if the text was inserted and the actions performed, {@code false} * otherwise//from w w w . ja va 2 s .co m */ private boolean type(String text, boolean clearBefore, boolean endWithAction) { boolean result = false; if (text == null) { text = ""; } EditorInfo info = getCurrentInputEditorInfo(); if (info != null) { // If the view accepts text as input if ((info.inputType & EditorInfo.TYPE_MASK_CLASS) != EditorInfo.TYPE_NULL) { InputConnection ic = getCurrentInputConnection(); if (ic != null) { boolean enterShouldHaveAction = true; ic.beginBatchEdit(); if (endWithAction) { enterShouldHaveAction = (info.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) == 0; if (!enterShouldHaveAction) { text += "\n"; } } if (clearBefore) { ic.deleteSurroundingText(Integer.MAX_VALUE, Integer.MAX_VALUE); } ic.commitText(text, 1); result = ic.endBatchEdit(); if (result && endWithAction && enterShouldHaveAction) { result = ic.performEditorAction(info.imeOptions & EditorInfo.IME_MASK_ACTION); } } } } return result; }
From source file:com.googlecode.eyesfree.brailleback.BrailleIME.java
private boolean handleBrailleKeyInternal(int dots) { // TODO: Support more than computer braille. This means that // there's not a 1:1 correspondence between a cell and a character, // so requires more book-keeping. BrailleTranslator translator = getCurrentBrailleTranslator(); InputConnection ic = getCurrentInputConnection(); if (translator == null || ic == null) { LogUtils.log(this, Log.WARN, "missing translator %s or IC %s", translator, ic); return false; }/* w ww . jav a2 s . c o m*/ CharSequence text = translator.backTranslate(new byte[] { (byte) dots }); if (!TextUtils.isEmpty(text)) { return ic.commitText(text, 1); } return true; }
From source file:org.kde.kdeconnect.Plugins.RemoteKeyboardPlugin.RemoteKeyboardPlugin.java
private boolean handleVisibleKey(String key, boolean shift, boolean ctrl, boolean alt) { // Log.d("RemoteKeyboardPlugin", "Handling visible key " + key + " shift=" + shift + " ctrl=" + ctrl + " alt=" + alt + " " + key.equalsIgnoreCase("c") + " " + key.length()); if (key.isEmpty()) return false; InputConnection inputConn = RemoteKeyboardService.instance.getCurrentInputConnection(); if (inputConn == null) return false; // ctrl+c/v/x if (key.equalsIgnoreCase("c") && ctrl) { return inputConn.performContextMenuAction(android.R.id.copy); } else if (key.equalsIgnoreCase("v") && ctrl) return inputConn.performContextMenuAction(android.R.id.paste); else if (key.equalsIgnoreCase("x") && ctrl) return inputConn.performContextMenuAction(android.R.id.cut); else if (key.equalsIgnoreCase("a") && ctrl) return inputConn.performContextMenuAction(android.R.id.selectAll); // Log.d("RemoteKeyboardPlugin", "Committing visible key '" + key + "'"); inputConn.commitText(key, key.length()); return true;/*from w w w.j av a2s. com*/ }
From source file:com.volosyukivan.WiFiInputMethod.java
void receivedChar(int code) { wakeLock.acquire();/* ww w . j av a 2s . c o m*/ wakeLock.release(); InputConnection conn = getCurrentInputConnection(); if (conn == null) { // Debug.d("connection closed"); return; } if (pressedKeys.contains(KEY_CONTROL)) { switch (code) { case 'a': case 'A': selectAll(conn); return; case 'x': case 'X': cut(conn); return; case 'c': case 'C': copy(conn); return; case 'v': case 'V': paste(conn); return; } } String text = null; if (code >= 0 && code <= 65535) { text = new String(new char[] { (char) code }); } else { int HI_SURROGATE_START = 0xD800; int LO_SURROGATE_START = 0xDC00; int hi = ((code >> 10) & 0x3FF) - 0x040 | HI_SURROGATE_START; int lo = LO_SURROGATE_START | (code & 0x3FF); text = new String(new char[] { (char) hi, (char) lo }); } conn.commitText(text, 1); }
From source file:research.sg.edu.edapp.kb.KbSoftKeyboard.java
public void onText(CharSequence text) { InputConnection ic = getCurrentInputConnection(); if (ic == null) return;//from w w w . jav a 2s.c o m ic.beginBatchEdit(); if (mComposing.length() > 0) { commitTyped(ic); } ic.commitText(text, 0); ic.endBatchEdit(); updateShiftKeyState(getCurrentInputEditorInfo()); }
From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java
/** * Helper function to commit any text being composed in to the editor. *///from www .j a va 2 s.c om private void commitTyped(InputConnection inputConnection) { if (mComposing.length() > 0) { inputConnection.commitText(mComposing, mComposing.length()); mComposing.setLength(0); updateCandidates(); } }
From source file:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (volumeButtons && !vbListenerPause) { InputConnection ic = getCurrentInputConnection(); if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { ic.commitText("", -1); } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { ic.commitText("", 2); }/*from w ww .java 2 s. c o m*/ return true; } else { return super.onKeyDown(keyCode, event); } }
From source file:com.yek.keyboard.anysoftkeyboard.AnySoftKeyboard.java
public void onText(Keyboard.Key key, CharSequence text) { Logger.d(TAG, "onText: '%s'", text); InputConnection ic = getCurrentInputConnection(); if (ic == null) return;// www .java2 s .c o m ic.beginBatchEdit(); abortCorrectionAndResetPredictionState(false); ic.commitText(text, 1); mJustAddedAutoSpace = false; mCommittedWord = text; mUndoCommitCursorPosition = UNDO_COMMIT_WAITING_TO_RECORD_POSITION; TextEntryState.acceptedDefault(text); ic.endBatchEdit(); setSuggestions(mSuggest.getNextSuggestions(mCommittedWord, false), false, false, false); }