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.activiti.android.ui.fragments.form.picker.IdmPickerFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (getArguments() != null) {
        onRetrieveParameters(getArguments());
    }/*  w  ww  . java 2  s  .  com*/

    // Create View
    setRootView(inflater.inflate(R.layout.fr_idm_picker, container, false));

    // Init list
    init(getRootView(), emptyListMessageId);
    gv.setChoiceMode(GridView.CHOICE_MODE_SINGLE);
    setListShown(true);

    searchView = UIUtils.setActionBarCustomView(getActivity(), R.layout.person_picker_header, true);

    View searchBack = searchView.findViewById(R.id.search_back);
    searchBack.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            getActivity().getSupportFragmentManager().popBackStackImmediate();
        }
    });

    if (keywords != null && !keywords.isEmpty()) {
        search(keywords);
    } else {
        // Speech to Text
        hasTextToSpeech = FeatureUtils.hasSpeechToText(getActivity());
        speechToText = (ImageButton) searchView.findViewById(R.id.search_microphone);
        if (hasTextToSpeech) {
            speechToText.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    speechToText();
                }
            });
        } else {
            speechToText.setVisibility(View.GONE);
        }

        searchAction = (ImageButton) searchView.findViewById(R.id.search_start);
        searchAction.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (searchForm.getText().length() > 0) {
                    keywords = searchForm.getText().toString();
                    search(keywords);
                } else {
                    // TODO Snackbar
                }
            }
        });
        searchAction.setVisibility(View.GONE);

        // Init form search
        searchForm = (EditText) searchView.findViewById(R.id.search_query);
        searchForm.requestFocus();
        UIUtils.showKeyboard(getActivity(), searchForm);
        searchForm.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
        searchForm.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if (s.length() == 0) {
                    searchAction.setVisibility(View.GONE);
                    if (hasTextToSpeech) {
                        speechToText.setVisibility(View.VISIBLE);
                    }
                } else {
                    speechToText.setVisibility(View.GONE);
                    searchAction.setVisibility(View.VISIBLE);
                }
            }
        });

        searchForm.setOnEditorActionListener(new OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (event != null && (event.getAction() == KeyEvent.ACTION_DOWN)
                        && ((actionId == EditorInfo.IME_ACTION_SEARCH)
                                || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
                                || (actionId == EditorInfo.IME_ACTION_DONE))) {
                    if (searchForm.getText().length() > 0) {
                        keywords = searchForm.getText().toString();
                        search(keywords);
                    } else {
                        // TODO Snackbar
                    }
                    return true;
                }
                return false;
            }
        });
    }

    if (getMode() == MODE_PICK) {
        Button cancel = UIUtils.initCancel(getRootView(), R.string.general_action_cancel);
        cancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (getDialog() != null) {
                    getDialog().dismiss();
                } else {
                    getFragmentManager().popBackStack();
                }
            }
        });
    } else {
        hide(R.id.validation_panel);
    }

    return getRootView();
}

From source file:org.alfresco.mobile.android.application.fragments.user.UserSearchFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (getDialog() != null) {
        getDialog().requestWindowFeature(Window.FEATURE_LEFT_ICON);
    }//from w  ww.ja  va  2  s .  com

    // Retrieve session object
    checkSession();

    if (getArguments() != null && getArguments().containsKey(ARGUMENT_MODE)) {
        fieldId = getArguments().getString(ARGUMENT_FIELD_ID);
        keywords = getArguments().getString(ARGUMENT_KEYWORD);
        title = getArguments().getString(ARGUMENT_TITLE);
        mode = getArguments().getInt(ARGUMENT_MODE);
        singleChoice = getArguments().getBoolean(ARGUMENT_SINGLE_CHOICE);
        String pickFragmentTag = getArguments().getString(ARGUMENT_FRAGMENT_TAG);
        fragmentPick = getFragmentManager().findFragmentByTag(pickFragmentTag);
        if (fragmentPick != null && fragmentPick instanceof UserPickerCallback) {
            selectedItems = ((UserPickerCallback) fragmentPick).retrieveSelection();
        } else if (fragmentPick instanceof onPickAuthorityFragment && fieldId != null) {
            selectedItems = ((onPickAuthorityFragment) fragmentPick).getPersonSelected(fieldId);
        }
    }

    // Create View
    setRootView(inflater.inflate(R.layout.app_pick_person, container, false));
    if (getSession() == null) {
        return getRootView();
    }

    // Init list
    init(getRootView(), R.string.person_not_found);
    gv.setChoiceMode(GridView.CHOICE_MODE_SINGLE);
    setListShown(true);

    if (keywords != null && !keywords.isEmpty()) {
        search(keywords);
        hide(R.id.search_form_group);
    } else {
        // Init form search
        searchForm = (EditText) viewById(R.id.search_query);
        searchForm.setImeOptions(EditorInfo.IME_ACTION_SEARCH);

        searchForm.setOnEditorActionListener(new OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (event != null && (event.getAction() == KeyEvent.ACTION_DOWN)
                        && ((actionId == EditorInfo.IME_ACTION_SEARCH)
                                || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER))) {
                    if (searchForm.getText().length() > 0) {
                        keywords = searchForm.getText().toString();
                        search(keywords);
                    } else {
                        AlfrescoNotificationManager.getInstance(getActivity())
                                .showLongToast(getString(R.string.search_form_hint));
                    }
                    return true;
                }
                return false;
            }
        });

        // Speech to Text
        Boolean hasTextToSpeech = ActionUtils.hasSpeechToText(getActivity());
        ImageButton speechToText = (ImageButton) viewById(R.id.search_microphone);
        if (hasTextToSpeech) {
            speechToText.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    speechToText();
                }
            });
        } else {
            hide(R.id.search_microphone);
        }
    }

    if (getMode() == MODE_PICK) {
        show(R.id.validation_panel);
        validation = UIUtils.initValidation(getRootView(), R.string.done);
        updatePickButton();
        validation.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                onSelect(selectedItems);
                if (getDialog() != null) {
                    getDialog().dismiss();
                } else {
                    getFragmentManager().popBackStack();
                }
            }
        });

        Button cancel = UIUtils.initCancel(getRootView(), R.string.cancel);
        cancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (getDialog() != null) {
                    getDialog().dismiss();
                } else {
                    getFragmentManager().popBackStack();
                }
            }
        });
    } else {
        hide(R.id.validation_panel);
    }

    return getRootView();
}

From source file:com.ysy.classpower_utils.search_view.OwnSearchViewLayout.java

@Override
protected void onFinishInflate() {
    mCollapsed = (ViewGroup) findViewById(xyz.sahildave.widget.R.id.search_box_collapsed);
    mSearchIcon = findViewById(xyz.sahildave.widget.R.id.search_magnifying_glass);
    mCollapsedSearchBox = findViewById(xyz.sahildave.widget.R.id.search_box_start_search);
    mCollapsedHintView = (TextView) findViewById(xyz.sahildave.widget.R.id.search_box_collapsed_hint);

    mExpanded = (ViewGroup) findViewById(xyz.sahildave.widget.R.id.search_expanded_root);
    mSearchEditText = (EditText) mExpanded.findViewById(xyz.sahildave.widget.R.id.search_expanded_edit_text);
    mBackButtonView = mExpanded.findViewById(xyz.sahildave.widget.R.id.search_expanded_back_button);
    mExpandedSearchIcon = findViewById(xyz.sahildave.widget.R.id.search_expanded_magnifying_glass);

    // Convert a long click into a click to expand the search box, and then long click on the
    // search view. This accelerates the long-press scenario for copy/paste.
    mCollapsedSearchBox.setOnLongClickListener(new OnLongClickListener() {
        @Override// ww w.  j a  va 2  s  .  c  o  m
        public boolean onLongClick(View view) {
            mCollapsedSearchBox.performClick();
            mSearchEditText.performLongClick();
            return false;
        }
    });

    mCollapsed.setOnClickListener(mSearchViewOnClickListener);
    mSearchIcon.setOnClickListener(mSearchViewOnClickListener);
    mCollapsedSearchBox.setOnClickListener(mSearchViewOnClickListener);

    mSearchEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                Utils.showInputMethod(v);
            } else {
                Utils.hideInputMethod(v);
            }
        }
    });
    mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                callSearchListener();
                Utils.hideInputMethod(v);
                return true;
            }
            return false;
        }
    });
    mSearchEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (mSearchEditText.getText().length() > 0) {
                if (mExpandedSearchIcon.getVisibility() != View.VISIBLE) {
                    Utils.fadeIn(mExpandedSearchIcon, ANIMATION_DURATION);
                }
            } else {
                Utils.fadeOut(mExpandedSearchIcon, ANIMATION_DURATION);
            }
            if (mSearchBoxListener != null)
                mSearchBoxListener.onTextChanged(s, start, before, count);
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            if (mSearchBoxListener != null)
                mSearchBoxListener.beforeTextChanged(s, start, count, after);
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (mSearchBoxListener != null)
                mSearchBoxListener.afterTextChanged(s);
        }
    });

    mBackButtonView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            collapse();
        }
    });

    mExpandedSearchIcon.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            callSearchListener();
            Utils.hideInputMethod(v);
        }
    });

    mCollapsedDrawable = new ColorDrawable(ContextCompat.getColor(getContext(), android.R.color.transparent));
    mExpandedDrawable = new ColorDrawable(
            ContextCompat.getColor(getContext(), xyz.sahildave.widget.R.color.default_color_expanded));
    mBackgroundTransition = new TransitionDrawable(new Drawable[] { mCollapsedDrawable, mExpandedDrawable });
    mBackgroundTransition.setCrossFadeEnabled(true);

    setBackground(mBackgroundTransition);
    Utils.setPaddingAll(OwnSearchViewLayout.this, 8);

    super.onFinishInflate();
}

From source file:com.jlabs.peepaid.searchviewlay.SearchViewLayout.java

@Override
protected void onFinishInflate() {
    mCollapsed = (ViewGroup) findViewById(R.id.search_box_collapsed);
    mSearchIcon = findViewById(R.id.search_magnifying_glass);
    mCollapsedSearchBox = findViewById(R.id.search_box_start_search);
    mCollapsedHintView = (TextView) findViewById(R.id.search_box_collapsed_hint);

    mExpanded = (ViewGroup) findViewById(R.id.search_expanded_root);
    mSearchEditText = (EditText) mExpanded.findViewById(R.id.search_expanded_edit_text);
    mBackButtonView = mExpanded.findViewById(R.id.search_expanded_back_button);
    mExpandedSearchIcon = findViewById(R.id.search_expanded_magnifying_glass);

    // Convert a long click into a click to expand the search box, and then long click on the
    // search view. This accelerates the long-press scenario for copy/paste.
    mCollapsedSearchBox.setOnLongClickListener(new OnLongClickListener() {
        @Override/*w  w w .j a  v a  2 s. c  o m*/
        public boolean onLongClick(View view) {
            mCollapsedSearchBox.performClick();
            mSearchEditText.performLongClick();
            return false;
        }
    });

    mCollapsed.setOnClickListener(mSearchViewOnClickListener);
    mSearchIcon.setOnClickListener(mSearchViewOnClickListener);
    mCollapsedSearchBox.setOnClickListener(mSearchViewOnClickListener);

    mSearchEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                Utils.showInputMethod(v);
            } else {
                Utils.hideInputMethod(v);
            }
        }
    });
    mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                callSearchListener();
                Utils.hideInputMethod(v);
                return true;
            }
            return false;
        }
    });
    mSearchEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (mSearchEditText.getText().length() > 0) {
                if (mExpandedSearchIcon.getVisibility() != View.VISIBLE) {
                    Utils.fadeIn(mExpandedSearchIcon, ANIMATION_DURATION);
                }
            } else {
                Utils.fadeOut(mExpandedSearchIcon, ANIMATION_DURATION);
            }
            if (mSearchBoxListener != null)
                mSearchBoxListener.onTextChanged(s, start, before, count);
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            if (mSearchBoxListener != null)
                mSearchBoxListener.beforeTextChanged(s, start, count, after);
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (mSearchBoxListener != null)
                mSearchBoxListener.afterTextChanged(s);
        }
    });

    mBackButtonView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            collapse();
        }
    });

    mExpandedSearchIcon.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            callSearchListener();
            Utils.hideInputMethod(v);
        }
    });

    mCollapsedDrawable = new ColorDrawable(
            ContextCompat.getColor(getContext(), R.color.default_color_expanded));
    mExpandedDrawable = new ColorDrawable(ContextCompat.getColor(getContext(), R.color.default_color_expanded));
    mBackgroundTransition = new TransitionDrawable(new Drawable[] { mCollapsedDrawable, mExpandedDrawable });
    mBackgroundTransition.setCrossFadeEnabled(true);

    setBackground(mBackgroundTransition);
    Utils.setPaddingAll(SearchViewLayout.this, 8);

    super.onFinishInflate();
}

From source file:com.akhbulatov.wordkeeper.ui.fragment.WordListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.fragment_word, menu);

    MenuItem searchItem = menu.findItem(R.id.menu_search_word);
    SearchView searchView = (SearchView) searchItem.getActionView();

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    searchView.setSearchableInfo(//from  w w  w.j  a v  a  2 s . c o  m
            searchManager.getSearchableInfo(new ComponentName(getActivity(), MainActivity.class)));
    searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            final Cursor cursor = mWordDbAdapter.getAll(sSortMode);
            final int column = cursor.getColumnIndex(WordEntry.COLUMN_NAME);
            if (newText.length() > 0) {
                mWordAdapter.swapCursor(new FilterCursorWrapper(cursor, newText, column));

                mTextEmptyWordList.setVisibility(View.GONE);
                if (mWordAdapter.getItemCount() == 0) {
                    String escapedNewText = TextUtils.htmlEncode(newText);
                    String formattedNoResults = String.format(getString(R.string.no_results_word),
                            escapedNewText);
                    CharSequence styledNoResults = Html.fromHtml(formattedNoResults);

                    mTextNoResultsWord.setText(styledNoResults);
                    mTextNoResultsWord.setVisibility(View.VISIBLE);
                } else {
                    mTextNoResultsWord.setVisibility(View.GONE);
                }
            } else {
                mWordAdapter.swapCursor(cursor);

                mTextNoResultsWord.setVisibility(View.GONE);
                if (mWordAdapter.getItemCount() == 0) {
                    mTextEmptyWordList.setVisibility(View.VISIBLE);
                }
            }
            return true;
        }
    });
}

From source file:com.akhbulatov.wordkeeper.ui.fragment.CategoryListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.fragment_category, menu);

    MenuItem searchItem = menu.findItem(R.id.menu_search_category);
    SearchView searchView = (SearchView) searchItem.getActionView();

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    searchView.setSearchableInfo(//from   w  ww.jav  a 2  s  .  c  o  m
            searchManager.getSearchableInfo(new ComponentName(getActivity(), MainActivity.class)));
    searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            final Cursor cursor = mCategoryDbAdapter.getAll();
            final int column = cursor.getColumnIndex(CategoryEntry.COLUMN_NAME);
            if (newText.length() > 0) {
                mCategoryAdapter.swapCursor(new FilterCursorWrapper(cursor, newText, column));

                if (mCategoryAdapter.getItemCount() == 0) {
                    String escapedNewText = TextUtils.htmlEncode(newText);
                    String formattedNoResults = String.format(getString(R.string.no_results_category),
                            escapedNewText);
                    CharSequence styledNoResults = Html.fromHtml(formattedNoResults);

                    mTextNoResultsCategory.setText(styledNoResults);
                    mTextNoResultsCategory.setVisibility(View.VISIBLE);
                } else {
                    mTextNoResultsCategory.setVisibility(View.GONE);
                }
            } else {
                mCategoryAdapter.swapCursor(cursor);
                mTextNoResultsCategory.setVisibility(View.GONE);
            }
            return true;
        }

        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }
    });
}

From source file:org.alfresco.mobile.android.application.fragments.search.SearchFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setRetainInstance(true);/*from w ww  .  ja  v  a  2 s . c om*/

    setRootView(inflater.inflate(R.layout.app_search_history, container, false));
    init(getRootView(), emptyListMessageId);

    // Folder path
    if (getArguments() != null && getArguments().containsKey(ARGUMENT_FOLDER)) {
        pathView = (TextView) viewById(R.id.search_path);
        show(R.id.search_path_panel);
        displayPathOption();
    } else {
        hide(R.id.search_path_panel);
    }

    // Search Icon
    searchIcon = (ImageView) viewById(R.id.search_icon);

    // Search Input
    searchForm = (EditText) viewById(R.id.search_query);
    searchForm.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchForm.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (event != null && (event.getAction() == KeyEvent.ACTION_DOWN)
                    && ((actionId == EditorInfo.IME_ACTION_SEARCH)
                            || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER))) {
                if (searchForm.getText().length() > 0) {
                    search(searchForm.getText().toString());
                    UIUtils.hideKeyboard(getActivity());
                } else {
                    AlfrescoNotificationManager.getInstance(getActivity())
                            .showLongToast(getString(R.string.search_form_hint));
                }
                return true;
            }
            return false;
        }
    });

    // Speech to Text
    Boolean hasTextToSpeech = ActionUtils.hasSpeechToText(getActivity());
    ImageButton speechToText = (ImageButton) viewById(R.id.search_microphone);
    if (hasTextToSpeech) {
        speechToText.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                speechToText();
            }
        });
    } else {
        hide(R.id.search_microphone);
    }

    return getRootView();
}

From source file:com.sft.blackcatapp.EnrollSchoolActivity.java

private void initData() {
    searchSchool.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchSchool.setOnEditorActionListener(new OnEditorActionListener() {

        @Override/*from  w  w  w.j a va 2  s  .c om*/
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                // ??
                ((InputMethodManager) searchSchool.getContext().getSystemService(Context.INPUT_METHOD_SERVICE))
                        .hideSoftInputFromWindow(EnrollSchoolActivity.this.getCurrentFocus().getWindowToken(),
                                InputMethodManager.HIDE_NOT_ALWAYS);

                // ?
                LogUtil.print("?");
                schoolname = searchSchool.getText().toString().trim();
                searchSchool(true);
                return true;
            }
            return false;
        }

    });
}

From source file:br.ufrgs.ufrgsmapas.libs.SearchBox.java

/**
 * Create a searchbox with params and a style
 * @param context Context/*from   ww w  . j a v a 2 s . c  o m*/
 * @param attrs Attributes
 * @param defStyle Style
 */
public SearchBox(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    inflate(context, R.layout.searchbox, this);
    this.searchOpen = false;
    this.isMic = true;
    this.materialMenu = (MaterialMenuView) findViewById(R.id.material_menu_button);
    this.logo = (TextView) findViewById(R.id.logo);
    this.search = (EditText) findViewById(R.id.search);
    this.results = (ListView) findViewById(R.id.results);
    this.context = context;
    this.pb = (ProgressBar) findViewById(R.id.pb);
    this.mic = (ImageView) findViewById(R.id.mic);
    this.drawerLogo = (ImageView) findViewById(R.id.drawer_logo);

    mCollator = Collator.getInstance(new Locale("pt", "BR"));
    mCollator.setStrength(Collator.PRIMARY);

    materialMenu.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (searchOpen) {
                toggleSearch();
            } else {
                if (menuListener != null)
                    menuListener.onMenuClick();
            }
        }

    });
    resultList = new ArrayList<SearchResult>();
    results.setAdapter(new SearchAdapter(context, resultList));
    animate = true;
    isVoiceRecognitionIntentSupported = isIntentAvailable(context,
            new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH));
    logo.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            toggleSearch();
        }

    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        RelativeLayout searchRoot = (RelativeLayout) findViewById(R.id.search_root);
        LayoutTransition lt = new LayoutTransition();
        lt.setDuration(100);
        searchRoot.setLayoutTransition(lt);
    }
    searchables = new ArrayList<SearchResult>();
    search.setOnEditorActionListener(new OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                search(getSearchText());
                return true;
            }
            return false;
        }
    });
    search.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                if (TextUtils.isEmpty(getSearchText())) {
                    toggleSearch();
                } else {
                    search(getSearchText());
                }
                return true;
            }
            return false;
        }
    });
    logoText = "Logo";
    micStateChanged();
    mic.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (voiceRecognitionListener != null) {
                voiceRecognitionListener.onClick();
            } else {
                micClick();
            }
        }
    });
}

From source file:com.dm.wallpaper.board.fragments.CategoryWallpapersFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.menu_wallpaper_search_sort, menu);
    MenuItem search = menu.findItem(R.id.menu_search);
    MenuItem sort = menu.findItem(R.id.menu_sort);

    int color = ColorHelper.getAttributeColor(getActivity(), R.attr.toolbar_icon);
    search.setIcon(DrawableHelper.getTintedDrawable(getActivity(), R.drawable.ic_toolbar_search, color));
    sort.setIcon(DrawableHelper.getTintedDrawable(getActivity(), R.drawable.ic_toolbar_sort, color));

    mSearchView = (SearchView) search.getActionView();
    mSearchView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_ACTION_SEARCH);
    mSearchView.setQueryHint(getActivity().getResources().getString(R.string.menu_search));
    mSearchView.setMaxWidth(Integer.MAX_VALUE);

    ViewHelper.setSearchViewTextColor(mSearchView, color);
    ViewHelper.setSearchViewBackgroundColor(mSearchView, Color.TRANSPARENT);
    ViewHelper.setSearchViewCloseIcon(mSearchView,
            DrawableHelper.getTintedDrawable(getActivity(), R.drawable.ic_toolbar_close, color));
    ViewHelper.setSearchViewSearchIcon(mSearchView, null);

    mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override//from  ww  w  .jav  a 2  s  . c om
        public boolean onQueryTextChange(String string) {
            filterSearch(string);
            return true;
        }

        @Override
        public boolean onQueryTextSubmit(String string) {
            mSearchView.clearFocus();
            return true;
        }
    });
}