Example usage for android.view.inputmethod EditorInfo IME_ACTION_SEARCH

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

Introduction

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

Prototype

int IME_ACTION_SEARCH

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

Click Source Link

Document

Bits of #IME_MASK_ACTION : the action key performs a "search" operation, taking the user to the results of searching for the text they have typed (in whatever context is appropriate).

Usage

From source file:com.arlib.floatingsearchview.FloatingSearchView.java

/**
 * Sets whether the the button with the search icon
 * will appear in the soft-keyboard or not.
 *
 * <p>Notice that if this is set to false,
 * {@link OnSearchListener#onSearchAction()} onSearchAction}, will
 * not get called.</p>/* w ww  .  ja va 2s  .  c om*/
 *
 * @param show to show the search button in
 *             the soft-keyboard.
 */
public void setShowSearchKey(boolean show) {
    mShowSearchKey = show;
    if (show)
        mSearchInput.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    else
        mSearchInput.setImeOptions(EditorInfo.IME_ACTION_NONE);
}

From source file:com.ywesee.amiko.MainActivity.java

/**
 *
 *//* w w  w . ja v  a  2 s  .  c  o m*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    // Inflate the menu. Add items to the action bar if present.
    getMenuInflater().inflate(R.menu.actionbar, menu);

    mSearchItem = menu.findItem(R.id.menu_search);
    mSearchItem.expandActionView();
    mSearchItem.setVisible(true);
    mSearch = (EditText) mSearchItem.getActionView().findViewById(R.id.search_box);
    if (!Utilities.isTablet(this)) {
        float textSize = 16.0f; // in [sp] = scaled pixels
        mSearch.setTextSize(textSize);
    }
    mSearch.setFocusable(true);

    if (mSearch != null) {
        if (mSearchInteractions == false)
            mSearch.setHint(getString(R.string.search) + " " + mActionName);
        else
            mSearch.setHint(getString(R.string.search) + " " + getString(R.string.interactions_search));
    }

    mSearchHitsCntView = (TextView) mSearchItem.getActionView().findViewById(R.id.hits_counter);
    mSearchHitsCntView.setVisibility(View.GONE);

    mSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE) {
                if (mCurrentView == mSuggestView) {
                    // Hide keyboard
                    hideSoftKeyboard(500);
                } else if (mCurrentView == mShowView) {
                    // Searches forward
                    mWebView.findNext(true);
                }
                return true;
            }
            return false;
        }
    });

    mSearch.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                showSoftKeyboard(100);
            }
        }
    });

    mSearch.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showSoftKeyboard(100);
            if (!mSQLiteDBInitialized) {
                runOnUiThread(new Runnable() {
                    public void run() {
                        showDownloadAlert(0);
                    }
                });
            }
        }
    });

    // Action listener for search_box
    mSearch.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // Do nothing
        }

        @Override
        public void onTextChanged(CharSequence cs, int start, int before, int count) {
            // Do nothing
        }

        @Override
        public void afterTextChanged(Editable s) {
            String text = mSearch.getText().toString();
            if (text.length() > 0) {
                if (!mSQLiteDBInitialized) {
                    runOnUiThread(new Runnable() {
                        public void run() {
                            showDownloadAlert(0);
                        }
                    });
                    return;
                }
            }
            if (!mRestoringState) {
                if (text.length() > 0)
                    performSearch(text);
            }
            mDelete.setVisibility(s.length() > 0 ? View.VISIBLE : View.GONE);
        }
    });

    mDelete = (Button) mSearchItem.getActionView().findViewById(R.id.delete);
    mDelete.setVisibility(mSearch.getText().length() > 0 ? View.VISIBLE : View.GONE);

    mDelete.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mSearch.length() > 0)
                mSearch.getText().clear();
            if (mCurrentView == mShowView) {
                mSearchHitsCntView.setVisibility(View.GONE);
                mWebView.clearMatches();
            } else if (mCurrentView == mSuggestView) {
                showSoftKeyboard(300);
            }
        }
    });

    return true;
}

From source file:com.arlib.floatingsearchview.FloatingSearchView.java

/**
 * Sets whether the the button with the search icon
 * will appear in the soft-keyboard or not.
 *
 * @param show to show the search button in
 *             the soft-keyboard.//from w ww .j a v  a 2 s .co m
 */
public void setShowSearchKey(boolean show) {
    mShowSearchKey = show;
    if (show) {
        mSearchInput.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    } else {
        mSearchInput.setImeOptions(EditorInfo.IME_ACTION_NONE);
    }
}

From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java

public void initSearchbar() {
    final ListView searchListView = (ListView) mainArView.findViewById(R.id.ar_mixview_search_list);

    searchbar = (LinearLayout) mainArView.findViewById(R.id.ar_mixview_searchbar);
    hideSearchbar = (Button) mainArView.findViewById(R.id.ar_mixview_hide_searchbar);
    searchBtn = (Button) mainArView.findViewById(R.id.ar_mixview_search);
    searchBtn.setOnClickListener(new View.OnClickListener() {
        @Override//from   w w  w  .ja va  2 s  .  c o  m
        public void onClick(View view) {
            parentButtonView.setVisibility(View.GONE);
            searchbar.setVisibility(View.VISIBLE);
        }
    });
    hideSearchbar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            searchbar.setVisibility(View.GONE);
            parentButtonView.setVisibility(View.VISIBLE);
        }
    });

    searchText = (EditText) mainArView.findViewById(R.id.ar_mixview_search_text);
    searchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, android.view.KeyEvent event) {
            switch (actionId) {
            case EditorInfo.IME_ACTION_SEARCH:
                String queryString = searchText.getText().toString();
                Intent intent = new Intent(context, SearchKeywordListActivity.class);
                intent.putExtra("searchName", queryString);
                InputMethodManager imm = (InputMethodManager) context
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(mainArView.getWindowToken(), 0);
                mainArView.setVisibility(View.GONE);
                ((Activity) context).startActivityForResult(intent, SEARCH_LIST);
                break;
            default:
                Toast.makeText(context, "", Toast.LENGTH_LONG).show();
                return false;
            }
            return true;
        }
    });

    TextWatcher watcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(final CharSequence charSequence, int i, int i1, int i2) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    String queryString = searchText.getText().toString();
                    try {
                        List<ARMarker> searchList = null;
                        String encodedQueryString = URLEncoder.encode(queryString, "UTF-8");

                        String tempCallbackUrl = "http://ac.map.naver.com/ac?q=" + encodedQueryString
                                + "&st=10&r_lt=10&r_format=json";
                        String rawData = new NaverHttpHandler().execute(tempCallbackUrl).get();
                        Log.i("rawData", rawData);

                        JSONObject root = new JSONObject(rawData);
                        JSONArray dataArray = root.getJSONArray("items");
                        JSONArray locationData = dataArray.getJSONArray(0);

                        Log.i("dataArray", locationData.toString());

                        final ArrayList<String> list = new ArrayList<>();
                        for (int index = 0; index < locationData.length(); index++)
                            list.add(locationData.getString(index).substring(2,
                                    locationData.getString(index).length() - 2));

                        ((Activity) context).runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                SearchViewAdapter adapter = new SearchViewAdapter(inflater);
                                adapter.setDataList(list);
                                adapter.setCurrentText(charSequence.toString());
                                searchListView.setAdapter(adapter);
                                searchListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                                    @Override
                                    public void onItemClick(AdapterView<?> adapterView, View view, int i,
                                            long l) {
                                        String queryString = list.get(i);
                                        searchText.setText(queryString);
                                    }
                                });
                            }
                        });
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    } catch (ExecutionException e) {
                        e.printStackTrace();
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    };
    searchText.addTextChangedListener(watcher);
}

From source file:com.skytree.epubtest.BookViewActivity.java

public void makeSearchBox() {
    int boxColor = Color.rgb(241, 238, 229);
    int innerBoxColor = Color.rgb(246, 244, 239);
    int inlineColor = Color.rgb(133, 105, 75);

    RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); // width,height
    searchBox = new SkyBox(this);
    searchBox.setBoxColor(boxColor);/*  w w w  .  j av a  2 s .co  m*/
    searchBox.setArrowHeight(ps(25));
    searchBox.setArrowDirection(false);
    param.leftMargin = ps(50);
    param.topMargin = ps(400);
    param.width = ps(400);
    param.height = ps(300);
    searchBox.setLayoutParams(param);
    searchBox.setArrowDirection(false);

    searchEditor = new EditText(this);
    this.setFrame(searchEditor, ps(20), ps(20), ps(400 - 140), ps(50));
    searchEditor.setTextSize(15f);
    searchEditor.setEllipsize(TruncateAt.END);
    searchEditor.setBackgroundColor(innerBoxColor);
    Drawable icon = getResources().getDrawable(R.drawable.search2x);

    Bitmap bitmap = ((BitmapDrawable) icon).getBitmap();
    Drawable fd = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(bitmap, ps(28), ps(28), true));
    searchEditor.setCompoundDrawablesWithIntrinsicBounds(fd, null, null, null);
    RoundRectShape rrs = new RoundRectShape(
            new float[] { ps(15), ps(15), ps(15), ps(15), ps(15), ps(15), ps(15), ps(15) }, null, null);
    SkyDrawable sd = new SkyDrawable(rrs, innerBoxColor, inlineColor, 2);
    searchEditor.setBackgroundDrawable(sd);
    searchEditor.setHint(getString(R.string.searchhint));
    searchEditor.setPadding(ps(20), ps(5), ps(10), ps(5));
    searchEditor.setLines(1);
    searchEditor.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchEditor.setSingleLine();
    searchEditor.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_GO
                    || actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_NEXT) {
                String key = searchEditor.getText().toString();
                if (key != null && key.length() > 1) {
                    showIndicator();
                    clearSearchBox(1);
                    makeFullScreen();
                    rv.searchKey(key);
                }
            }
            return false;
        }
    });
    searchBox.contentView.addView(searchEditor);

    Button cancelButton = new Button(this);
    this.setFrame(cancelButton, ps(290), ps(20), ps(90), ps(50));
    cancelButton.setText(getString(R.string.cancel));
    cancelButton.setId(3001);
    RoundRectShape crs = new RoundRectShape(
            new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null);
    SkyDrawable cd = new SkyDrawable(crs, innerBoxColor, inlineColor, 2);
    cancelButton.setBackgroundDrawable(cd);
    cancelButton.setTextSize(12);
    cancelButton.setOnClickListener(listener);
    cancelButton.setOnTouchListener(new ButtonHighlighterOnTouchListener(cancelButton));

    searchBox.contentView.addView(cancelButton);

    searchScrollView = new ScrollView(this);
    RoundRectShape rvs = new RoundRectShape(
            new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null);
    SkyDrawable rd = new SkyDrawable(rvs, innerBoxColor, inlineColor, 2);
    searchScrollView.setBackgroundDrawable(rd);
    this.setFrame(searchScrollView, ps(20), ps(100), ps(360), ps(200));
    this.searchBox.contentView.addView(searchScrollView);

    searchResultView = new LinearLayout(this);
    searchResultView.setOrientation(LinearLayout.VERTICAL);
    searchScrollView.addView(searchResultView,
            new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    this.ePubView.addView(searchBox);
    this.hideSearchBox();
}

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

@NonNull
private CharSequence guessLabelForKey(int keyCode) {
    switch (keyCode) {
    case KeyCodes.ENTER:
        switch (mKeyboardActionType) {
        case EditorInfo.IME_ACTION_DONE:
            return getContext().getText(R.string.label_done_key);
        case EditorInfo.IME_ACTION_GO:
            return getContext().getText(R.string.label_go_key);
        case EditorInfo.IME_ACTION_NEXT:
            return getContext().getText(R.string.label_next_key);
        case 0x00000007:// API 11: EditorInfo.IME_ACTION_PREVIOUS:
            return getContext().getText(R.string.label_previous_key);
        case EditorInfo.IME_ACTION_SEARCH:
            return getContext().getText(R.string.label_search_key);
        case EditorInfo.IME_ACTION_SEND:
            return getContext().getText(R.string.label_send_key);
        default://  w  w w.  j a va  2  s  . c o m
            return "";
        }
    case KeyCodes.KEYBOARD_MODE_CHANGE:
        if (mKeyboard instanceof GenericKeyboard)
            return guessLabelForKey(KeyCodes.MODE_ALPHABET);
        else
            return guessLabelForKey(KeyCodes.MODE_SYMOBLS);
    case KeyCodes.MODE_ALPHABET:
        return mNextAlphabetKeyboardName;
    case KeyCodes.MODE_SYMOBLS:
        return mNextSymbolsKeyboardName;
    case KeyCodes.TAB:
        return getContext().getText(R.string.label_tab_key);
    case KeyCodes.MOVE_HOME:
        return getContext().getText(R.string.label_home_key);
    case KeyCodes.MOVE_END:
        return getContext().getText(R.string.label_end_key);
    case KeyCodes.ARROW_DOWN:
        return "";
    case KeyCodes.ARROW_LEFT:
        return "";
    case KeyCodes.ARROW_RIGHT:
        return "";
    case KeyCodes.ARROW_UP:
        return "";
    default:
        return "";
    }
}

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

private Drawable getIconForKeyCode(int keyCode) {
    Drawable icon = getDrawableForKeyCode(keyCode);
    // maybe a drawable state is required
    if (icon != null) {
        switch (keyCode) {
        case KeyCodes.ENTER:
            Logger.d(TAG, "Action key action ID is %d", mKeyboardActionType);
            switch (mKeyboardActionType) {
            case EditorInfo.IME_ACTION_DONE:
                icon.setState(mDrawableStatesProvider.DRAWABLE_STATE_ACTION_DONE);
                break;
            case EditorInfo.IME_ACTION_GO:
                icon.setState(mDrawableStatesProvider.DRAWABLE_STATE_ACTION_GO);
                break;
            case EditorInfo.IME_ACTION_SEARCH:
                icon.setState(mDrawableStatesProvider.DRAWABLE_STATE_ACTION_SEARCH);
                break;
            case EditorInfo.IME_ACTION_NONE:
            case EditorInfo.IME_ACTION_UNSPECIFIED:
                icon.setState(mDrawableStatesProvider.DRAWABLE_STATE_ACTION_NORMAL);
                break;
            }//from   w w  w.j ava2  s  .  c o  m
            break;
        case KeyCodes.SHIFT:
            if (mKeyboard.isShiftLocked())
                icon.setState(mDrawableStatesProvider.DRAWABLE_STATE_MODIFIER_LOCKED);
            else if (mKeyboard.isShifted())
                icon.setState(mDrawableStatesProvider.DRAWABLE_STATE_MODIFIER_PRESSED);
            else
                icon.setState(mDrawableStatesProvider.DRAWABLE_STATE_MODIFIER_NORMAL);
            break;
        case KeyCodes.CTRL:
            if (mKeyboard.isControl())
                icon.setState(mDrawableStatesProvider.DRAWABLE_STATE_MODIFIER_PRESSED);
            else
                icon.setState(mDrawableStatesProvider.DRAWABLE_STATE_MODIFIER_NORMAL);
            break;
        }
    }
    return icon;
}

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

private CharSequence guessLabelForKey(int keyCode) {
    switch (keyCode) {
    case KeyCodes.ENTER:
        switch (mKeyboardActionType) {
        case EditorInfo.IME_ACTION_DONE:
            return getContext().getText(R.string.label_done_key);
        case EditorInfo.IME_ACTION_GO:
            return getContext().getText(R.string.label_go_key);
        case EditorInfo.IME_ACTION_NEXT:
            return getContext().getText(R.string.label_next_key);
        case 0x00000007:// API 11: EditorInfo.IME_ACTION_PREVIOUS:
            return getContext().getText(R.string.label_previous_key);
        case EditorInfo.IME_ACTION_SEARCH:
            return getContext().getText(R.string.label_search_key);
        case EditorInfo.IME_ACTION_SEND:
            return getContext().getText(R.string.label_send_key);
        default:/*  w w  w .j a  v a  2 s.  c  om*/
            return "";
        }
    case KeyCodes.KEYBOARD_MODE_CHANGE:
        if (mSwitcher.isAlphabetMode())
            return guessLabelForKey(KeyCodes.MODE_SYMOBLS);
        else
            return guessLabelForKey(KeyCodes.MODE_ALPHABET);
    case KeyCodes.MODE_ALPHABET:
        String langKeyText = null;
        if (mSwitcher != null)//should show the next keyboard label, not a generic one.
            langKeyText = mSwitcher.peekNextAlphabetKeyboard();
        if (langKeyText == null)
            return getResources().getString(R.string.change_lang_regular);
        else
            return langKeyText;
    case KeyCodes.MODE_SYMOBLS:
        String symKeyText = null;
        if (mSwitcher != null)//should show the next keyboard label, not a generic one.
            symKeyText = mSwitcher.peekNextSymbolsKeyboard();
        if (symKeyText == null)
            return getResources().getString(R.string.change_symbols_regular);
        else
            return symKeyText;
    case KeyCodes.TAB:
        return getContext().getText(R.string.label_tab_key);
    case KeyCodes.MOVE_HOME:
        return getContext().getText(R.string.label_home_key);
    case KeyCodes.MOVE_END:
        return getContext().getText(R.string.label_end_key);
    case KeyCodes.ARROW_DOWN:
        return "\u2193";
    case KeyCodes.ARROW_LEFT:
        return "\u2190";
    case KeyCodes.ARROW_RIGHT:
        return "\u2192";
    case KeyCodes.ARROW_UP:
        return "\u2191";
    default:
        return null;
    }
}

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

private Drawable getIconForKeyCode(int keyCode) {
    Drawable icon = mKeysIcons.get(keyCode);

    if (icon == null) {
        // building needed icon
        Log.d(TAG, "Building icon for key-code %d", keyCode);
        DrawableBuilder builder = mKeysIconBuilders.get(keyCode);
        if (builder == null)
            return null;
        icon = builder.buildDrawable();//  w  ww .ja v a2s .  co  m
        mKeysIcons.put(keyCode, icon);
        Log.d(TAG, "Current drawable cache size is %d", mKeysIcons.size());
    }
    // maybe a drawable state is required
    if (icon != null) {
        switch (keyCode) {
        case KeyCodes.ENTER:
            Log.d(TAG, "Action key action ID is %d", mKeyboardActionType);
            switch (mKeyboardActionType) {
            case EditorInfo.IME_ACTION_DONE:
                icon.setState(mDrawableStatesProvider.DRAWABLE_STATE_ACTION_DONE);
                break;
            case EditorInfo.IME_ACTION_GO:
                icon.setState(mDrawableStatesProvider.DRAWABLE_STATE_ACTION_GO);
                break;
            case EditorInfo.IME_ACTION_SEARCH:
                icon.setState(mDrawableStatesProvider.DRAWABLE_STATE_ACTION_SEARCH);
                break;
            case EditorInfo.IME_ACTION_NONE:
            case EditorInfo.IME_ACTION_UNSPECIFIED:
                icon.setState(mDrawableStatesProvider.DRAWABLE_STATE_ACTION_NORMAL);
                break;
            }
            break;
        case KeyCodes.SHIFT:
            if (mKeyboard.isShiftLocked())
                icon.setState(mDrawableStatesProvider.DRAWABLE_STATE_MODIFIER_LOCKED);
            else if (mKeyboard.isShifted())
                icon.setState(mDrawableStatesProvider.DRAWABLE_STATE_MODIFIER_PRESSED);
            else
                icon.setState(mDrawableStatesProvider.DRAWABLE_STATE_MODIFIER_NORMAL);
            break;
        case KeyCodes.CTRL:
            if (mKeyboard.isControl())
                icon.setState(mDrawableStatesProvider.DRAWABLE_STATE_MODIFIER_PRESSED);
            else
                icon.setState(mDrawableStatesProvider.DRAWABLE_STATE_MODIFIER_NORMAL);
            break;
        }
    }
    return icon;
}