Java Code Examples for android.view.inputmethod.EditorInfo#IME_ACTION_SEARCH

The following examples show how to use android.view.inputmethod.EditorInfo#IME_ACTION_SEARCH . 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 vote down vote up
/**
 * 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);
    }
}
 
Example 2
Source File: EditorInfoCompatUtils.java    From simple-keyboard with Apache License 2.0 6 votes vote down vote up
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 + ")";
    }
}
 
Example 3
Source File: BrowserActivity.java    From Xndroid with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onEditorAction(TextView arg0, int actionId, KeyEvent arg2) {
    // hide the keyboard and search the web when the enter key
    // button is pressed
    if (actionId == EditorInfo.IME_ACTION_GO || actionId == EditorInfo.IME_ACTION_DONE
        || actionId == EditorInfo.IME_ACTION_NEXT
        || actionId == EditorInfo.IME_ACTION_SEND
        || actionId == EditorInfo.IME_ACTION_SEARCH
        || (arg2.getAction() == KeyEvent.KEYCODE_ENTER)) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(mSearch.getWindowToken(), 0);
        searchTheWeb(mSearch.getText().toString());
        final LightningView currentView = mTabsManager.getCurrentTab();
        if (currentView != null) {
            currentView.requestFocus();
        }
        return true;
    }
    return false;
}
 
Example 4
Source File: BaseKeyboard.java    From FirefoxReality with Mozilla Public License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example 5
Source File: SearchFragment.java    From marvel with MIT License 5 votes vote down vote up
@OnEditorAction(R.id.character)
boolean onEditorAction(EditText v, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_SEARCH || (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
        onShowClick(v);
        return true;
    }
    return false;
}
 
Example 6
Source File: AdbIME.java    From SoloPi with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 7
Source File: SelectableListToolbar.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_SEARCH) {
        UiUtils.hideKeyboard(v);
    }
    return false;
}
 
Example 8
Source File: KBoard.java    From kboard with GNU General Public License v3.0 5 votes vote down vote up
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;
    }
}
 
Example 9
Source File: AllAppsSearchBarController.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    // Skip if it's not the right action
    if (actionId != EditorInfo.IME_ACTION_SEARCH) {
        return false;
    }

    // Skip if the query is empty
    String query = v.getText().toString();
    if (query.isEmpty()) {
        return false;
    }
    return mLauncher.startActivitySafely(v, createMarketSearchIntent(query), null);
}
 
Example 10
Source File: ReactEditText.java    From react-native-GPay with MIT License 5 votes vote down vote up
private void updateImeOptions() {
  // Default to IME_ACTION_DONE
  int returnKeyFlag = EditorInfo.IME_ACTION_DONE;
  if (mReturnKeyType != null) {
    switch (mReturnKeyType) {
      case "go":
        returnKeyFlag = EditorInfo.IME_ACTION_GO;
        break;
      case "next":
        returnKeyFlag = EditorInfo.IME_ACTION_NEXT;
        break;
      case "none":
        returnKeyFlag = EditorInfo.IME_ACTION_NONE;
        break;
      case "previous":
        returnKeyFlag = EditorInfo.IME_ACTION_PREVIOUS;
        break;
      case "search":
        returnKeyFlag = EditorInfo.IME_ACTION_SEARCH;
        break;
      case "send":
        returnKeyFlag = EditorInfo.IME_ACTION_SEND;
        break;
      case "done":
        returnKeyFlag = EditorInfo.IME_ACTION_DONE;
        break;
    }
  }

  if (mDisableFullscreen) {
    setImeOptions(returnKeyFlag | EditorInfo.IME_FLAG_NO_FULLSCREEN);
  } else {
    setImeOptions(returnKeyFlag);
  }
}
 
Example 11
Source File: TextSearchFragment.java    From jellyfin-androidtv with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    // Detect keyboard "submit" actions
    if (actionId == EditorInfo.IME_ACTION_SEARCH)
        searchProvider.onQueryTextSubmit(v.getText().toString());

    // Return "false" to automatically close keyboard
    return false;
}
 
Example 12
Source File: KeyCodeDescriptionMapper.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a context-sensitive description of the "Enter" action key.
 *
 * @param context The package's context.
 * @param keyboard The keyboard on which the key resides.
 * @param key The key to describe.
 * @return Returns a context-sensitive description of the "Enter" action key.
 */
private static String getDescriptionForActionKey(final Context context, final Keyboard keyboard,
        final Key key) {
    final KeyboardId keyboardId = keyboard.mId;
    final int actionId = keyboardId.imeAction();
    final int resId;

    // Always use the label, if available.
    if (!TextUtils.isEmpty(key.getLabel())) {
        return key.getLabel().trim();
    }

    // Otherwise, use the action ID.
    switch (actionId) {
    case EditorInfo.IME_ACTION_SEARCH:
        resId = R.string.spoken_description_search;
        break;
    case EditorInfo.IME_ACTION_GO:
        resId = R.string.label_go_key;
        break;
    case EditorInfo.IME_ACTION_SEND:
        resId = R.string.label_send_key;
        break;
    case EditorInfo.IME_ACTION_NEXT:
        resId = R.string.label_next_key;
        break;
    case EditorInfo.IME_ACTION_DONE:
        resId = R.string.label_done_key;
        break;
    case EditorInfo.IME_ACTION_PREVIOUS:
        resId = R.string.label_previous_key;
        break;
    default:
        resId = R.string.spoken_description_return;
    }
    return context.getString(resId);
}
 
Example 13
Source File: LatinKeyboard.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 14
Source File: SearchActivity.java    From BmapLite with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_SEARCH || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
        mPage = 0;
        search();
        AppUtils.closeKeyboard(mEditSearch, this);
        return true;
    }
    return false;
}
 
Example 15
Source File: HomePageSearchFragment.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
    if (i == EditorInfo.IME_ACTION_SEARCH) {
        searchAndLocal();
    }
    return true;
}
 
Example 16
Source File: DefaultAppSearchController.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    // Skip if we disallow app-launch-on-enter
    if (!ALLOW_SINGLE_APP_LAUNCH) {
        return false;
    }
    // Skip if it's not the right action
    if (actionId != EditorInfo.IME_ACTION_SEARCH) {
        return false;
    }
    // Skip if there are more than one icon
    if (mApps.getNumFilteredApps() > 1) {
        return false;
    }
    // Otherwise, find the first icon, or fallback to the search-market-view and launch it
    List<AlphabeticalAppsList.AdapterItem> items = mApps.getAdapterItems();
    for (int i = 0; i < items.size(); i++) {
        AlphabeticalAppsList.AdapterItem item = items.get(i);
        switch (item.viewType) {
            case AllAppsGridAdapter.ICON_VIEW_TYPE:
            case AllAppsGridAdapter.SEARCH_MARKET_VIEW_TYPE:
                mAppsRecyclerView.getChildAt(i).performClick();
                mInputMethodManager.hideSoftInputFromWindow(
                        mContainerView.getWindowToken(), 0);
                return true;
        }
    }
    return false;
}
 
Example 17
Source File: PushFragment.java    From EosCommander with MIT License 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
    if (EditorInfo.IME_ACTION_SEND == actionId) {
        onPushAction();
        return true;
    }
    else
    if ( (EditorInfo.IME_ACTION_SEARCH == actionId ) && ( textView.getId() == R.id.et_contract_account) ){
        onContractEntered( mEtContract.getText().toString());
    }

    return false;
}
 
Example 18
Source File: SearchActivity.java    From android with MIT License 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_GO) {
        if (mAdapter.getCount() > 0) {
            onSearchItemSelected(mAdapter.getItem(0));
            return true;
        }
    }

    return false;
}
 
Example 19
Source File: AdapterInputConnection.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@VisibleForTesting
AdapterInputConnection(View view, ImeAdapter imeAdapter, EditorInfo outAttrs) {
    super(view, true);
    mInternalView = view;
    mImeAdapter = imeAdapter;
    mImeAdapter.setInputConnection(this);
    mSingleLine = true;
    outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN
            | EditorInfo.IME_FLAG_NO_EXTRACT_UI;
    outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT
            | EditorInfo.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT;

    if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeText) {
        // Normal text field
        outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT;
        outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
    } else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeTextArea ||
            imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeContentEditable) {
        // TextArea or contenteditable.
        outAttrs.inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE
                | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES
                | EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT;
        outAttrs.imeOptions |= EditorInfo.IME_ACTION_NONE;
        mSingleLine = false;
    } else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypePassword) {
        // Password
        outAttrs.inputType = InputType.TYPE_CLASS_TEXT
                | InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD;
        outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
    } else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeSearch) {
        // Search
        outAttrs.imeOptions |= EditorInfo.IME_ACTION_SEARCH;
    } else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeUrl) {
        // Url
        // TYPE_TEXT_VARIATION_URI prevents Tab key from showing, so
        // exclude it for now.
        outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
    } else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeEmail) {
        // Email
        outAttrs.inputType = InputType.TYPE_CLASS_TEXT
                | InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS;
        outAttrs.imeOptions |= EditorInfo.IME_ACTION_GO;
    } else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeTel) {
        // Telephone
        // Number and telephone do not have both a Tab key and an
        // action in default OSK, so set the action to NEXT
        outAttrs.inputType = InputType.TYPE_CLASS_PHONE;
        outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
    } else if (imeAdapter.getTextInputType() == ImeAdapter.sTextInputTypeNumber) {
        // Number
        outAttrs.inputType = InputType.TYPE_CLASS_NUMBER
                | InputType.TYPE_NUMBER_VARIATION_NORMAL;
        outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
    }
    outAttrs.initialSelStart = imeAdapter.getInitialSelectionStart();
    outAttrs.initialSelEnd = imeAdapter.getInitialSelectionEnd();
    mLastUpdateSelectionStart = imeAdapter.getInitialSelectionStart();
    mLastUpdateSelectionEnd = imeAdapter.getInitialSelectionEnd();
}
 
Example 20
Source File: LatinKeyboard.java    From hackerskeyboard with Apache License 2.0 4 votes vote down vote up
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);
        }
    }
}