Java Code Examples for android.view.inputmethod.InputConnection#getSelectedText()
The following examples show how to use
android.view.inputmethod.InputConnection#getSelectedText() .
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: 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 2
Source File: KeyboardSelectorWidget.java From Android-Keyboard with Apache License 2.0 | 5 votes |
private void updateStatus() { InputConnection ic = getCurrentIC(); if (ic == null) { return; } CharSequence cs = ic.getSelectedText(0); boolean hasSelection = !TextUtils.isEmpty(cs); boolean hasClipData = ClipManager.getInstance().hasClipData(); updateSelectAllStatus(hasSelection); updateCopyStatus(hasSelection); updatePasteStatus(hasClipData); updateDeleteStatus(hasSelection || !TextUtils.isEmpty(ic.getTextBeforeCursor(1, 0))); }
Example 3
Source File: CtrlInputAction.java From remotekeyboard with Apache License 2.0 | 5 votes |
/** * use ROT13 to scramble the contents of the editor */ private void scramble(InputConnection con) { char[] buffer = null; CharSequence selected = con.getSelectedText(0); if (selected != null) { buffer = selected.toString().toCharArray(); } else { ExtractedText txt = con.getExtractedText(new ExtractedTextRequest(), 0); if (txt == null) { return; } buffer = txt.text.toString().toCharArray(); if (buffer.length == 0) return; } // char[] buffer = con.getSelectedText(0).toString().toCharArray(); // //con.getExtractedText(new // ExtractedTextRequest(),0).text.toString().toCharArray(); for (int i = 0; i < buffer.length; i++) { if (buffer[i] >= 'a' && buffer[i] <= 'm') buffer[i] += 13; else if (buffer[i] >= 'A' && buffer[i] <= 'M') buffer[i] += 13; else if (buffer[i] >= 'n' && buffer[i] <= 'z') buffer[i] -= 13; else if (buffer[i] >= 'N' && buffer[i] <= 'Z') buffer[i] -= 13; } if (selected == null) { con.setComposingRegion(0, buffer.length); } con.setComposingText(new String(buffer), 1); con.finishComposingText(); }
Example 4
Source File: ImeContainer.java From mongol-library with MIT License | 4 votes |
private boolean hasSelection() { InputConnection ic = getInputConnection(); CharSequence selection = ic.getSelectedText(0); return selection != null && selection.length() > 0; }
Example 5
Source File: RemoteKeyboardService.java From remotekeyboard with Apache License 2.0 | 4 votes |
@Override public void onPress(int primaryCode) { // SEE: res/xml/keyboarddef.xml for the definitions. switch (primaryCode) { case 0: { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showInputMethodPicker(); break; } case 1: { /* * Intent intent = new Intent(this, SettingsActivity.class); * intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); * startActivity(intent); */ break; } case 2: { try { InputConnection con = getCurrentInputConnection(); CharSequence txt = con.getSelectedText(0); if (txt == null) { txt = getCurrentInputConnection().getExtractedText( new ExtractedTextRequest(), 0).text; } TelnetEditorShell.self.showText(txt + ""); Toast.makeText(this, R.string.msg_sent, Toast.LENGTH_SHORT).show(); } catch (Exception exp) { Toast.makeText(this, R.string.err_noclient, Toast.LENGTH_SHORT) .show(); } break; } case 3: { try { if (TelnetEditorShell.self != null) { TelnetEditorShell.self.disconnect(); Toast.makeText(this, R.string.msg_client_disconnected, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, R.string.err_noclient, Toast.LENGTH_SHORT) .show(); } } catch (Exception e) { } } } }