android.view.inputmethod.EditorInfo#IME_MASK_ACTION源码实例Demo

下面列出了android.view.inputmethod.EditorInfo#IME_MASK_ACTION 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Indic-Keyboard   文件: EditorInfoCompatUtils.java
public static String imeActionName(final int imeOptions) {
    final int actionId = imeOptions & EditorInfo.IME_MASK_ACTION;
    switch (actionId) {
    case EditorInfo.IME_ACTION_UNSPECIFIED:
        return "actionUnspecified";
    case EditorInfo.IME_ACTION_NONE:
        return "actionNone";
    case EditorInfo.IME_ACTION_GO:
        return "actionGo";
    case EditorInfo.IME_ACTION_SEARCH:
        return "actionSearch";
    case EditorInfo.IME_ACTION_SEND:
        return "actionSend";
    case EditorInfo.IME_ACTION_NEXT:
        return "actionNext";
    case EditorInfo.IME_ACTION_DONE:
        return "actionDone";
    case EditorInfo.IME_ACTION_PREVIOUS:
        return "actionPrevious";
    default:
        return "actionUnknown(" + actionId + ")";
    }
}
 
源代码2 项目: android_9.0.0_r45   文件: InputMethodService.java
/**
 * 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;
}
 
源代码3 项目: android_9.0.0_r45   文件: InputMethodService.java
/**
 * Return text that can be used as a button label for the given
 * {@link EditorInfo#imeOptions EditorInfo.imeOptions}.  Returns null
 * if there is no action requested.  Note that there is no guarantee that
 * the returned text will be relatively short, so you probably do not
 * want to use it as text on a soft keyboard key label.
 *
 * @param imeOptions The value from {@link EditorInfo#imeOptions EditorInfo.imeOptions}.
 *
 * @return Returns a label to use, or null if there is no action.
 */
public CharSequence getTextForImeAction(int imeOptions) {
    switch (imeOptions&EditorInfo.IME_MASK_ACTION) {
        case EditorInfo.IME_ACTION_NONE:
            return null;
        case EditorInfo.IME_ACTION_GO:
            return getText(com.android.internal.R.string.ime_action_go);
        case EditorInfo.IME_ACTION_SEARCH:
            return getText(com.android.internal.R.string.ime_action_search);
        case EditorInfo.IME_ACTION_SEND:
            return getText(com.android.internal.R.string.ime_action_send);
        case EditorInfo.IME_ACTION_NEXT:
            return getText(com.android.internal.R.string.ime_action_next);
        case EditorInfo.IME_ACTION_DONE:
            return getText(com.android.internal.R.string.ime_action_done);
        case EditorInfo.IME_ACTION_PREVIOUS:
            return getText(com.android.internal.R.string.ime_action_previous);
        default:
            return getText(com.android.internal.R.string.ime_action_default);
    }
}
 
源代码4 项目: android_9.0.0_r45   文件: InputMethodService.java
/**
 * Return a drawable resource id that can be used as a button icon for the given
 * {@link EditorInfo#imeOptions EditorInfo.imeOptions}.
 *
 * @param imeOptions The value from @link EditorInfo#imeOptions EditorInfo.imeOptions}.
 *
 * @return Returns a drawable resource id to use.
 */
@DrawableRes
private int getIconForImeAction(int imeOptions) {
    switch (imeOptions&EditorInfo.IME_MASK_ACTION) {
        case EditorInfo.IME_ACTION_GO:
            return com.android.internal.R.drawable.ic_input_extract_action_go;
        case EditorInfo.IME_ACTION_SEARCH:
            return com.android.internal.R.drawable.ic_input_extract_action_search;
        case EditorInfo.IME_ACTION_SEND:
            return com.android.internal.R.drawable.ic_input_extract_action_send;
        case EditorInfo.IME_ACTION_NEXT:
            return com.android.internal.R.drawable.ic_input_extract_action_next;
        case EditorInfo.IME_ACTION_DONE:
            return com.android.internal.R.drawable.ic_input_extract_action_done;
        case EditorInfo.IME_ACTION_PREVIOUS:
            return com.android.internal.R.drawable.ic_input_extract_action_previous;
        default:
            return com.android.internal.R.drawable.ic_input_extract_action_return;
    }
}
 
源代码5 项目: buddycloud-android   文件: TypefacedEditText.java
@Override
	public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
	    InputConnection connection = super.onCreateInputConnection(outAttrs);
	    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;
//	    }
	    
	    if ((outAttrs.imeOptions&EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) {
	        outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION;
	    }
	    return connection;
	}
 
源代码6 项目: Silence   文件: ComposeText.java
public void setTransport(TransportOption transport) {
  final String enterKeyType = SilencePreferences.getEnterKeyType(getContext());
  final boolean isIncognito = SilencePreferences.isIncognitoKeyboardEnabled(getContext());

  int imeOptions = (getImeOptions() & ~EditorInfo.IME_MASK_ACTION) | EditorInfo.IME_ACTION_SEND;
  int inputType  = getInputType();

  if (isLandscape()) setImeActionLabel(transport.getComposeHint(), EditorInfo.IME_ACTION_SEND);
  else               setImeActionLabel(null, 0);

  inputType  = enterKeyType.equals("emoji")
             ? inputType | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE
             : inputType & ~InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE;

  setInputType(inputType);
  setImeOptions(imeOptions);
  setHint(transport.getComposeHint(),
          transport.getSimName().isPresent()
              ? getContext().getString(R.string.conversation_activity__via_sim_name, transport.getSimName().get())
              : null);
}
 
源代码7 项目: talk-android   文件: TextChipsEditView.java
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    InputConnection connection = super.onCreateInputConnection(outAttrs);
    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;
    }
    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;
}
 
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    //Override normal multiline text handling of enter/done and force a done button
    TokenInputConnection connection = new TokenInputConnection(super.onCreateInputConnection(outAttrs), true);
    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;
    }
    if ((outAttrs.imeOptions&EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) {
        outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION;
    }
    return connection;
}
 
源代码9 项目: ChipsLibrary   文件: 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;
    }
  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;
  }
 
源代码10 项目: FirefoxReality   文件: KeyboardWidget.java
private void handleDone() {
    if (mComposingDisplayText.length() > 0) {
        // Finish current composing
        mComposingText = "";
        postInputCommand(() -> {
            displayComposingText(StringUtils.removeSpaces(mComposingDisplayText), ComposingAction.FINISH);
            postUICommand(this::updateCandidates);
        });
        return;
    }
    final InputConnection connection = mInputConnection;
    final int action = mEditorInfo.imeOptions & EditorInfo.IME_MASK_ACTION;
    postInputCommand(() -> connection.performEditorAction(action));

    boolean hide = (action == EditorInfo.IME_ACTION_DONE) || (action == EditorInfo.IME_ACTION_GO) ||
            (action == EditorInfo.IME_ACTION_SEARCH) || (action == EditorInfo.IME_ACTION_SEND);

    if (hide && mFocusedView != null) {
        mFocusedView.clearFocus();
    }
}
 
源代码11 项目: FirefoxReality   文件: BaseKeyboard.java
@Override
public String getEnterKeyText(int aIMEOptions, String aComposingText) {
    Locale locale = getLocale();
    switch (aIMEOptions & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION)) {
        case EditorInfo.IME_ACTION_GO:
            return StringUtils.getStringByLocale(mContext, R.string.keyboard_go_label, locale);
        case EditorInfo.IME_ACTION_NEXT:
            return StringUtils.getStringByLocale(mContext, R.string.keyboard_next_label, locale);
        case EditorInfo.IME_ACTION_SEARCH:
            return StringUtils.getStringByLocale(mContext, R.string.keyboard_search_label, locale);
        case EditorInfo.IME_ACTION_SEND:
            return StringUtils.getStringByLocale(mContext, R.string.keyboard_send_label, locale);
        default:
            return StringUtils.getStringByLocale(mContext, R.string.keyboard_enter_label, locale);
    }
}
 
public static String imeActionName(final int imeOptions) {
    final int actionId = imeOptions & EditorInfo.IME_MASK_ACTION;
    switch (actionId) {
    case EditorInfo.IME_ACTION_UNSPECIFIED:
        return "actionUnspecified";
    case EditorInfo.IME_ACTION_NONE:
        return "actionNone";
    case EditorInfo.IME_ACTION_GO:
        return "actionGo";
    case EditorInfo.IME_ACTION_SEARCH:
        return "actionSearch";
    case EditorInfo.IME_ACTION_SEND:
        return "actionSend";
    case EditorInfo.IME_ACTION_NEXT:
        return "actionNext";
    case EditorInfo.IME_ACTION_DONE:
        return "actionDone";
    case EditorInfo.IME_ACTION_PREVIOUS:
        return "actionPrevious";
    default:
        return "actionUnknown(" + actionId + ")";
    }
}
 
源代码13 项目: SoloPi   文件: AdbIME.java
@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;
}
 
源代码14 项目: BaldPhone   文件: BaldKeyboard.java
protected void imeOptionsChanged(int imeOptions) {
    final int relevantImeOptions = imeOptions & EditorInfo.IME_MASK_ACTION;
    if (BaldInputMethodService.defaultEditorActionExists(imeOptions)) {
        switch (relevantImeOptions) {
            case IME_ACTION_SEARCH:
                tv_enter.setText(R.string.search);
                iv_enter.setImageResource(R.drawable.search_on_button);
                break;
            case IME_ACTION_DONE:
                tv_enter.setText(R.string.done);
                iv_enter.setImageResource(R.drawable.check_on_button);
                break;
            case IME_ACTION_GO:
                tv_enter.setText(R.string.go);
                iv_enter.setImageResource(R.drawable.check_on_button);
                break;
            case IME_ACTION_SEND:
                tv_enter.setText(R.string.send);
                iv_enter.setImageResource(R.drawable.send_on_button);
                break;
            case IME_ACTION_NEXT:
                tv_enter.setText(R.string.next);
                iv_enter.setImageResource(R.drawable.arrow_end_on_background);
                break;
            //should never be here
            case IME_ACTION_NONE:
            case IME_ACTION_UNSPECIFIED:
            default:
                tv_enter.setText(R.string.enter);
                iv_enter.setImageResource(R.drawable.enter_on_keyboard);
                break;
        }
    } else {
        tv_enter.setText(R.string.enter);
        iv_enter.setImageResource(R.drawable.enter_on_keyboard);
    }

}
 
源代码15 项目: java-n-IDE-for-Android   文件: LatinKeyboard.java
/**
 * This looks at the ime options given by the current editor, to set the
 * appropriate label on the keyboard's enter key (if it has one).
 */
void setImeOptions(Resources res, int options) {
    if (mEnterKey == null) {
        return;
    }

    int valnorm = KeyEvent.KEYCODE_ENTER;

    switch (options & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION)) {
        case EditorInfo.IME_ACTION_GO:
            mEnterKey.iconPreview = null;
            mEnterKey.icon = null;
            mEnterKey.codes = NORMAL_ENTER;
            mEnterKey.label = res.getText(R.string.label_go_key);
            break;
        case EditorInfo.IME_ACTION_NEXT:
            mEnterKey.iconPreview = null;
            mEnterKey.icon = null;
            mEnterKey.codes = NORMAL_ENTER;
            mEnterKey.label = res.getText(R.string.label_next_key);
            break;
        case EditorInfo.IME_ACTION_SEARCH:
            mEnterKey.icon = res.getDrawable(R.drawable.sym_keyboard_search);
            mEnterKey.codes = NORMAL_ENTER;
            mEnterKey.label = null;
            break;
        case EditorInfo.IME_ACTION_SEND:
            mEnterKey.iconPreview = null;
            mEnterKey.icon = null;
            mEnterKey.codes = NORMAL_ENTER;
            mEnterKey.label = res.getText(R.string.label_send_key);
            break;
        default:
            mEnterKey.icon = res.getDrawable(R.drawable.sym_keyboard_return);
            mEnterKey.label = null;
            mEnterKey.codes = TERMINAL_ENTER;
            break;
    }
}
 
源代码16 项目: simple-keyboard   文件: InputTypeUtils.java
public static int getImeOptionsActionIdFromEditorInfo(final EditorInfo editorInfo) {
    if ((editorInfo.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) {
        return EditorInfo.IME_ACTION_NONE;
    } else if (editorInfo.actionLabel != null) {
        return IME_ACTION_CUSTOM_LABEL;
    } else {
        // Note: this is different from editorInfo.actionId, hence "ImeOptionsActionId"
        return editorInfo.imeOptions & EditorInfo.IME_MASK_ACTION;
    }
}
 
源代码17 项目: kboard   文件: KBoard.java
public void setImeOptions(Resources res, int options) {
    if (mEnterKey == null) {
        return;
    }

    switch (options&(EditorInfo.IME_MASK_ACTION|EditorInfo.IME_FLAG_NO_ENTER_ACTION)) {
        case EditorInfo.IME_ACTION_GO:
            mEnterKey.iconPreview = null;
            mEnterKey.icon = null;
            mEnterKey.label = res.getText(R.string.label_keyboard_key_go);
            break;
        case EditorInfo.IME_ACTION_NEXT:
            mEnterKey.iconPreview = null;
            mEnterKey.icon = null;
            mEnterKey.label = res.getText(R.string.label_keyboard_key_next);
            break;
        case EditorInfo.IME_ACTION_SEARCH:
            mEnterKey.icon = res.getDrawable(R.drawable.sym_keyboard_search);
            mEnterKey.label = null;
            break;
        case EditorInfo.IME_ACTION_SEND:
            mEnterKey.iconPreview = null;
            mEnterKey.icon = null;
            mEnterKey.label = res.getText(R.string.label_keyboard_key_send);
            break;
        default:
            mEnterKey.icon = res.getDrawable(R.drawable.sym_keyboard_return);
            mEnterKey.label = null;
            break;
    }
}
 
源代码18 项目: AOSP-Kayboard-7.1.2   文件: InputTypeUtils.java
public static int getImeOptionsActionIdFromEditorInfo(final EditorInfo editorInfo) {
    if ((editorInfo.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) {
        return EditorInfo.IME_ACTION_NONE;
    } else if (editorInfo.actionLabel != null) {
        return IME_ACTION_CUSTOM_LABEL;
    } else {
        // Note: this is different from editorInfo.actionId, hence "ImeOptionsActionId"
        return editorInfo.imeOptions & EditorInfo.IME_MASK_ACTION;
    }
}
 
源代码19 项目: AndroidKeyboard   文件: LatinKeyboard.java
/**
 * This looks at the ime options given by the current editor, to set the
 * appropriate label on the keyboard's enter key (if it has one).
 */
void setImeOptions(Resources res, int options) {
    if (mEnterKey == null) {
        return;
    }
    switch (options&(EditorInfo.IME_MASK_ACTION|EditorInfo.IME_FLAG_NO_ENTER_ACTION)) {
        case EditorInfo.IME_ACTION_GO:
            mEnterKey.iconPreview = null;
            mEnterKey.icon = null;
            mEnterKey.label = res.getText(R.string.label_go_key);
            break;
        case EditorInfo.IME_ACTION_NEXT:
            mEnterKey.iconPreview = null;
            mEnterKey.icon = null;
            mEnterKey.label = res.getText(R.string.label_next_key);
            break;
        case EditorInfo.IME_ACTION_SEARCH:
            mEnterKey.icon = res.getDrawable(R.drawable.ic_search_45dp);
            mEnterKey.label = null;
            break;
        case EditorInfo.IME_ACTION_SEND:
            mEnterKey.iconPreview = null;
            mEnterKey.icon = null;
            mEnterKey.label = res.getText(R.string.label_send_key);
            break;
        default:
            mEnterKey.icon = res.getDrawable(R.drawable.ic_check_circle_45dp);
            mEnterKey.label = null;
            break;
    }
}
 
源代码20 项目: hackerskeyboard   文件: LatinKeyboard.java
void setImeOptions(Resources res, int mode, int options) {
    mMode = mode;
    // TODO should clean up this method
    if (mEnterKey != null) {
        // Reset some of the rarely used attributes.
        mEnterKey.popupCharacters = null;
        mEnterKey.popupResId = 0;
        mEnterKey.text = null;
        switch (options&(EditorInfo.IME_MASK_ACTION|EditorInfo.IME_FLAG_NO_ENTER_ACTION)) {
            case EditorInfo.IME_ACTION_GO:
                mEnterKey.iconPreview = null;
                mEnterKey.icon = null;
                mEnterKey.label = res.getText(R.string.label_go_key);
                break;
            case EditorInfo.IME_ACTION_NEXT:
                mEnterKey.iconPreview = null;
                mEnterKey.icon = null;
                mEnterKey.label = res.getText(R.string.label_next_key);
                break;
            case EditorInfo.IME_ACTION_DONE:
                mEnterKey.iconPreview = null;
                mEnterKey.icon = null;
                mEnterKey.label = res.getText(R.string.label_done_key);
                break;
            case EditorInfo.IME_ACTION_SEARCH:
                mEnterKey.iconPreview = res.getDrawable(
                        R.drawable.sym_keyboard_feedback_search);
                mEnterKey.icon = res.getDrawable(R.drawable.sym_keyboard_search);
                mEnterKey.label = null;
                break;
            case EditorInfo.IME_ACTION_SEND:
                mEnterKey.iconPreview = null;
                mEnterKey.icon = null;
                mEnterKey.label = res.getText(R.string.label_send_key);
                break;
            default:
                // Keep Return key in IM mode, we have a dedicated smiley key.
                mEnterKey.iconPreview = res.getDrawable(
                        R.drawable.sym_keyboard_feedback_return);
                mEnterKey.icon = res.getDrawable(R.drawable.sym_keyboard_return);
                mEnterKey.label = null;
                break;
        }
        // Set the initial size of the preview icon
        if (mEnterKey.iconPreview != null) {
            setDefaultBounds(mEnterKey.iconPreview);
        }
    }
}