Example usage for android.view.inputmethod EditorInfo IME_FLAG_NO_ENTER_ACTION

List of usage examples for android.view.inputmethod EditorInfo IME_FLAG_NO_ENTER_ACTION

Introduction

In this page you can find the example usage for android.view.inputmethod EditorInfo IME_FLAG_NO_ENTER_ACTION.

Prototype

int IME_FLAG_NO_ENTER_ACTION

To view the source code for android.view.inputmethod EditorInfo IME_FLAG_NO_ENTER_ACTION.

Click Source Link

Document

Flag of #imeOptions : used in conjunction with one of the actions masked by #IME_MASK_ACTION .

Usage

From source file:com.irccloud.android.ActionEditText.java

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    InputConnection ic = super.onCreateInputConnection(outAttrs);
    if (ic == null)
        return null;

    if (Build.VERSION.SDK_INT >= 19 && getEmojiEditTextHelper() != null)
        ic = getEmojiEditTextHelper().onCreateInputConnection(ic, outAttrs);

    outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS;
    outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NAVIGATE_NEXT;
    if (IRCCloudApplication.getInstance().getApplicationContext().getResources().getBoolean(R.bool.isTablet)
            || PreferenceManager/*from  w w w.  jav  a  2  s .c om*/
                    .getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext())
                    .getBoolean("kb_send", false)) {
        outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION;
        outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT;
    } else {
        outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_ENTER_ACTION;
    }
    if (PreferenceManager.getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext())
            .getBoolean("kb_caps", true)) {
        outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES;
    } else {
        outAttrs.inputType &= ~EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES;
    }
    EditorInfoCompat.setContentMimeTypes(outAttrs, new String[] { "image/*" });

    final InputConnectionCompat.OnCommitContentListener callback = new InputConnectionCompat.OnCommitContentListener() {
        @Override
        public boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags, Bundle opts) {
            // read and display inputContentInfo asynchronously
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1
                    && (flags & InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) {
                try {
                    inputContentInfo.requestPermission();
                } catch (Exception e) {
                    return false; // return false if failed
                }
            }

            if (imageListener != null) {
                boolean result = imageListener.onIMEImageReceived(inputContentInfo);
                inputContentInfo.releasePermission();
                return result;
            }
            return false;
        }
    };
    return InputConnectionCompat.createWrapper(ic, outAttrs, callback);
}

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  www  .  j  a  v a 2s.com*/
 */
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:org.connectbot.TerminalView.java

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_FLAG_NO_ENTER_ACTION
            | EditorInfo.IME_ACTION_NONE;
    outAttrs.inputType = EditorInfo.TYPE_NULL;
    return new BaseInputConnection(this, false) {
        @Override/* w ww  . j  a  va 2 s.com*/
        public boolean deleteSurroundingText(int leftLength, int rightLength) {
            if (rightLength == 0 && leftLength == 0) {
                return this.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
            }
            for (int i = 0; i < leftLength; i++) {
                this.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
            }
            // TODO: forward delete
            return true;
        }
    };
}

From source file:org.kde.kdeconnect.Plugins.RemoteKeyboardPlugin.RemoteKeyboardPlugin.java

private boolean handleSpecialKey(int key, boolean shift, boolean ctrl, boolean alt) {
    int keyEvent = specialKeyMap.get(key, 0);
    if (keyEvent == 0)
        return false;
    InputConnection inputConn = RemoteKeyboardService.instance.getCurrentInputConnection();
    //        Log.d("RemoteKeyboardPlugin", "Handling special key " + key + " translated to " + keyEvent + " shift=" + shift + " ctrl=" + ctrl + " alt=" + alt);

    // special sequences:
    if (ctrl && (keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT)) {
        // Ctrl + right -> next word
        ExtractedText extractedText = inputConn.getExtractedText(new ExtractedTextRequest(), 0);
        int pos = getCharPos(extractedText, ' ', keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT);
        if (pos == -1)
            pos = currentTextLength(extractedText);
        else/*from w  ww .j a  va2  s  .c om*/
            pos++;
        int startPos = pos;
        int endPos = pos;
        if (shift) { // Shift -> select word (otherwise jump)
            Pair<Integer, Integer> sel = currentSelection(extractedText);
            int cursor = currentCursorPos(extractedText);
            //                Log.d("RemoteKeyboardPlugin", "Selection (to right): " + sel.first + " / " + sel.second + " cursor: " + cursor);
            startPos = cursor;
            if (sel.first < cursor || // active selection from left to right -> grow
                    sel.first > sel.second) // active selection from right to left -> shrink
                startPos = sel.first;
        }
        inputConn.setSelection(startPos, endPos);
    } else if (ctrl && keyEvent == KeyEvent.KEYCODE_DPAD_LEFT) {
        // Ctrl + left -> previous word
        ExtractedText extractedText = inputConn.getExtractedText(new ExtractedTextRequest(), 0);
        int pos = getCharPos(extractedText, ' ', keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT);
        if (pos == -1)
            pos = 0;
        else
            pos++;
        int startPos = pos;
        int endPos = pos;
        if (shift) {
            Pair<Integer, Integer> sel = currentSelection(extractedText);
            int cursor = currentCursorPos(extractedText);
            //                Log.d("RemoteKeyboardPlugin", "Selection (to left): " + sel.first + " / " + sel.second + " cursor: " + cursor);
            startPos = cursor;
            if (cursor < sel.first || // active selection from right to left -> grow
                    sel.first < sel.second) // active selection from right to left -> shrink
                startPos = sel.first;
        }
        inputConn.setSelection(startPos, endPos);
    } else if (shift && (keyEvent == KeyEvent.KEYCODE_DPAD_LEFT || keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT
            || keyEvent == KeyEvent.KEYCODE_DPAD_UP || keyEvent == KeyEvent.KEYCODE_DPAD_DOWN
            || keyEvent == KeyEvent.KEYCODE_MOVE_HOME || keyEvent == KeyEvent.KEYCODE_MOVE_END)) {
        // Shift + up/down/left/right/home/end
        long now = SystemClock.uptimeMillis();
        inputConn.sendKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0));
        inputConn.sendKeyEvent(
                new KeyEvent(now, now, KeyEvent.ACTION_DOWN, keyEvent, 0, KeyEvent.META_SHIFT_LEFT_ON));
        inputConn.sendKeyEvent(
                new KeyEvent(now, now, KeyEvent.ACTION_UP, keyEvent, 0, KeyEvent.META_SHIFT_LEFT_ON));
        inputConn.sendKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0));
    } else if (keyEvent == KeyEvent.KEYCODE_NUMPAD_ENTER || keyEvent == KeyEvent.KEYCODE_ENTER) {
        // Enter key
        EditorInfo editorInfo = RemoteKeyboardService.instance.getCurrentInputEditorInfo();
        //            Log.d("RemoteKeyboardPlugin", "Enter: " + editorInfo.imeOptions);
        if (editorInfo != null
                && (((editorInfo.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) == 0) || ctrl)) { // Ctrl+Return overrides IME_FLAG_NO_ENTER_ACTION (FIXME: make configurable?)
            // check for special DONE/GO/etc actions first:
            int[] actions = { EditorInfo.IME_ACTION_GO, EditorInfo.IME_ACTION_NEXT, EditorInfo.IME_ACTION_SEND,
                    EditorInfo.IME_ACTION_SEARCH, EditorInfo.IME_ACTION_DONE }; // note: DONE should be last or we might hide the ime instead of "go"
            for (int i = 0; i < actions.length; i++) {
                if ((editorInfo.imeOptions & actions[i]) == actions[i]) {
                    //                        Log.d("RemoteKeyboardPlugin", "Enter-action: " + actions[i]);
                    inputConn.performEditorAction(actions[i]);
                    return true;
                }
            }
        } else {
            // else: fall back to regular Enter-event:
            //                Log.d("RemoteKeyboardPlugin", "Enter: normal keypress");
            inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyEvent));
            inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyEvent));
        }
    } else {
        // default handling:
        inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyEvent));
        inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyEvent));
    }

    return true;
}

From source file:com.android.ex.chips.RecipientEditTextView.java

@Override
public InputConnection onCreateInputConnection(final EditorInfo outAttrs) {
    final InputConnection connection = super.onCreateInputConnection(outAttrs);
    final int imeActions = outAttrs.imeOptions & EditorInfo.IME_MASK_ACTION;
    if ((imeActions & EditorInfo.IME_ACTION_DONE) != 0) {
        // clear the existing action
        outAttrs.imeOptions ^= imeActions;
        // set the DONE action
        outAttrs.imeOptions |= EditorInfo.IME_ACTION_DONE;
    }//from   w w  w.  j a va  2  s.  co m
    if ((outAttrs.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0)
        outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION;
    outAttrs.actionId = EditorInfo.IME_ACTION_DONE;
    outAttrs.actionLabel = getContext().getString(R.string.done);
    return connection;
}

From source file:com.googlecode.eyesfree.brailleback.BrailleIME.java

private boolean allowsDefaultAction() {
    EditorInfo ei = getCurrentInputEditorInfo();
    if (ei != null && (ei.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) == 0) {
        return true;
    }/*from   w w w  .j  ava2  s  . c  om*/
    return false;
}

From source file:org.thoughtcrime.securesms.ConversationActivity.java

private void initializeIme() {
    if (TextSecurePreferences.isEnterSendsEnabled(this)) {
        composeText.setInputType(composeText.getInputType() & ~InputType.TYPE_TEXT_FLAG_MULTI_LINE);
        composeText.setImeOptions(composeText.getImeOptions() & ~EditorInfo.IME_FLAG_NO_ENTER_ACTION);
    } else {//from  w  ww.j av a  2 s.c  o  m
        composeText.setInputType(composeText.getInputType() | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
        composeText.setImeOptions(composeText.getImeOptions() | EditorInfo.IME_FLAG_NO_ENTER_ACTION);
    }
    composeText.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEND) {
                sendMessage();
                return true;
            }
            return false;
        }
    });
}

From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardViewBase.java

public void setKeyboardActionType(final int imeOptions) {
    if ((imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0)
        //IME_FLAG_NO_ENTER_ACTION:
        // Flag of imeOptions: used in conjunction with one of the actions masked by IME_MASK_ACTION.
        // If this flag is not set, IMEs will normally replace the "enter" key with the action supplied.
        // This flag indicates that the action should not be available in-line as a replacement for the "enter" key.
        // Typically this is because the action has such a significant impact or is not recoverable enough
        // that accidentally hitting it should be avoided, such as sending a message.
        // Note that TextView will automatically set this flag for you on multi-line text views.
        mKeyboardActionType = EditorInfo.IME_ACTION_NONE;
    else//  w  w  w  . j a  v  a 2s . co m
        mKeyboardActionType = (imeOptions & EditorInfo.IME_MASK_ACTION);

    // setting the icon/text
    setSpecialKeysIconsAndLabels();
}

From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardBaseView.java

public void setKeyboardActionType(final int imeOptions) {
    Log.d(TAG, "setKeyboardActionType imeOptions:" + imeOptions + " action:"
            + (imeOptions & EditorInfo.IME_MASK_ACTION));
    if ((imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0)// this is
        // usually a
        // multi-line
        // edittext
        // box/*from w  w  w  .j a v a  2s.  c  o m*/
        mKeyboardActionType = EditorInfo.IME_ACTION_UNSPECIFIED;
    else
        mKeyboardActionType = (imeOptions & EditorInfo.IME_MASK_ACTION);

    // setting the icon/text
    setSpecialKeysIconsAndLabels();
}