Java Code Examples for android.view.inputmethod.InputConnection#performEditorAction()
The following examples show how to use
android.view.inputmethod.InputConnection#performEditorAction() .
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 | 6 votes |
/** * Ask the input target to execute its default action via * {@link InputConnection#performEditorAction * InputConnection.performEditorAction()}. * * @param fromEnterKey If true, this will be executed as if the user had * pressed an enter key on the keyboard, that is it will <em>not</em> * be done if the editor has set {@link EditorInfo#IME_FLAG_NO_ENTER_ACTION * EditorInfo.IME_FLAG_NO_ENTER_ACTION}. If false, the action will be * sent regardless of how the editor has set that flag. * * @return Returns a boolean indicating whether an action has been sent. * If false, either the editor did not specify a default action or it * does not want an action from the enter key. If true, the action was * sent (or there was no input connection at all). */ public boolean sendDefaultEditorAction(boolean fromEnterKey) { EditorInfo ei = getCurrentInputEditorInfo(); if (ei != null && (!fromEnterKey || (ei.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) == 0) && (ei.imeOptions & EditorInfo.IME_MASK_ACTION) != EditorInfo.IME_ACTION_NONE) { // If the enter key was pressed, and the editor has a default // action associated with pressing enter, then send it that // explicit action instead of the key event. InputConnection ic = getCurrentInputConnection(); if (ic != null) { ic.performEditorAction(ei.imeOptions&EditorInfo.IME_MASK_ACTION); } return true; } return false; }
Example 2
Source File: BrailleIME.java From brailleback with Apache License 2.0 | 6 votes |
public boolean sendDefaultAction() { if (!allowsDefaultAction()) { return false; } EditorInfo ei = getCurrentInputEditorInfo(); InputConnection ic = getCurrentInputConnection(); if (ei == null || ic == null) { return false; } cancelComposingText(); int actionId = ei.actionId; if (actionId != 0) { return ic.performEditorAction(actionId); } else { return sendDefaultEditorAction(false); } }
Example 3
Source File: CtrlInputAction.java From remotekeyboard with Apache License 2.0 | 6 votes |
/** * Figure out how we are connected to the edittext and what it expects the * enter key to do. */ private void handleEnterKey(InputConnection con) { EditorInfo ei = myService.getCurrentInputEditorInfo(); if (ei != null && ((ei.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != EditorInfo.IME_FLAG_NO_ENTER_ACTION)) { int[] acts = { EditorInfo.IME_ACTION_DONE, EditorInfo.IME_ACTION_SEARCH, EditorInfo.IME_ACTION_GO, EditorInfo.IME_ACTION_NEXT }; for (int i : acts) { if ((ei.imeOptions & i) == i) { con.performEditorAction(i); return; } } } typeKey(con, KeyEvent.KEYCODE_ENTER); }
Example 4
Source File: AdbIME.java From SoloPi with Apache License 2.0 | 5 votes |
@Subscriber(value = @Param(value = IME_EDITORCODE, sticky = false), thread = RunningThread.MAIN_THREAD) public boolean inputEditorCode(int code) { if (code != -1) { InputConnection ic = getCurrentInputConnection(); if (ic != null) { ic.performEditorAction(code); return true; } } return false; }
Example 5
Source File: EditorAction.java From android-test with Apache License 2.0 | 5 votes |
@Override public void perform(UiController uiController, View view) { EditorInfo editorInfo = new EditorInfo(); InputConnection inputConnection = view.onCreateInputConnection(editorInfo); if (inputConnection == null) { throw new PerformException.Builder() .withActionDescription(this.toString()) .withViewDescription(HumanReadables.describe(view)) .withCause(new IllegalStateException("View does not support input methods")) .build(); } int actionId = editorInfo.actionId != 0 ? editorInfo.actionId : editorInfo.imeOptions & EditorInfo.IME_MASK_ACTION; if (actionId == EditorInfo.IME_ACTION_NONE) { throw new PerformException.Builder() .withActionDescription(this.getDescription()) .withViewDescription(HumanReadables.describe(view)) .withCause(new IllegalStateException("No available action on view")) .build(); } if (!inputConnection.performEditorAction(actionId)) { throw new PerformException.Builder() .withActionDescription(this.getDescription()) .withViewDescription(HumanReadables.describe(view)) .withCause( new RuntimeException( String.format( Locale.ROOT, "Failed to perform action %#x. Input connection no longer valid", actionId))) .build(); } }
Example 6
Source File: BaldInputMethodService.java From BaldPhone with Apache License 2.0 | 4 votes |
@Override public void onClick(View v) { final char actualCode = (char) v.getTag(); final InputConnection ic = getCurrentInputConnection(); final EditorInfo editorInfo = getCurrentInputEditorInfo(); switch (actualCode) { case BaldKeyboard.BACKSPACE: backspace(); break; case BaldKeyboard.SHIFT: try { ((BaldKeyboard.Capitalised) keyboard).setCaps(); } catch (Exception e) { Log.e(TAG, e.getMessage()); e.printStackTrace(); } break; case BaldKeyboard.ENTER: if (defaultEditorActionExists(editorInfo.imeOptions)) { ic.performEditorAction(editorInfo.imeOptions & EditorInfo.IME_MASK_ACTION); } else { sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER); } break; case BaldKeyboard.HIDE: hideWindow(); break; case BaldKeyboard.LANGUAGE: changeLanguage(keyboard.nextLanguage()); break; case BaldKeyboard.NUMBERS: changeLanguage(onNumbers ? lastLanguage : NumberKeyboard.LANGUAGE_ID); onNumbers = !onNumbers; break; case BaldKeyboard.SPEECH_TO_TEXT: startVoiceListening(); break; default: final String str = String.valueOf(actualCode); ic.commitText(str, 1); } }