Example usage for android.app SearchManager getSearchableInfo

List of usage examples for android.app SearchManager getSearchableInfo

Introduction

In this page you can find the example usage for android.app SearchManager getSearchableInfo.

Prototype

public SearchableInfo getSearchableInfo(ComponentName componentName) 

Source Link

Document

Gets information about a searchable activity.

Usage

From source file:io.plaidapp.ui.SearchActivity.java

private void setupSearchView() {
    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    // hint, inputType & ime options seem to be ignored from XML! Set in code
    searchView.setQueryHint(getString(R.string.search_hint));
    searchView.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
    searchView.setImeOptions(searchView.getImeOptions() | EditorInfo.IME_ACTION_SEARCH
            | EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_FLAG_NO_FULLSCREEN);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override/*from   www.j a va  2s.  c om*/
        public boolean onQueryTextSubmit(String query) {
            searchFor(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String query) {
            if (TextUtils.isEmpty(query)) {
                clearResults();
            }
            return true;
        }
    });
    searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus && confirmSaveContainer.getVisibility() == View.VISIBLE) {
                hideSaveConfimation();
            }
        }
    });
}

From source file:ru.lizaalert.common.ui.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the options menu from XML
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.yp_menu, menu);

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem item = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) item.getActionView();

    // Assumes current activity is the searchable activity
    assert searchView != null;
    assert searchManager != null;
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    //        searchView.setIconifiedByDefault(false);

    return true;//  w  ww.j a  va 2 s. c  o  m
}

From source file:com.phicdy.mycuration.ui.TopActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final MenuItem searchMenuItem = menu.findItem(R.id.search);
    searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
        @Override// w w  w . jav a 2  s .c  o m
        public void onFocusChange(View view, boolean queryTextFocused) {
            if (!queryTextFocused) {
                searchMenuItem.collapseActionView();
                searchView.setQuery("", false);
            }
        }
    });
    SearchView.SearchAutoComplete searchAutoComplete = (SearchView.SearchAutoComplete) searchView
            .findViewById(android.support.v7.appcompat.R.id.search_src_text);
    searchAutoComplete.setTextColor(getResources().getColor(R.color.text_primary));
    searchAutoComplete.setHintTextColor(getResources().getColor(R.color.text_primary));
    return true;
}

From source file:at.flack.activity.NewFbContactActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.new_contact, menu);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchMenuItem = menu.findItem(R.id.search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
    searchView.setIconifiedByDefault(false);
    searchView.setIconified(false);/*from   w  ww .j a v  a  2s .  c o m*/
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setSubmitButtonEnabled(true);
    searchView.setOnQueryTextListener(this);
    return true;
}

From source file:com.scrachx.foodfacts.checker.ui.main.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.main, menu);

    // Associate searchable configuration with the SearchView
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchMenuItem = menu.findItem(R.id.action_search);
    mSearchView = (SearchView) searchMenuItem.getActionView();
    mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    MenuItemCompat.setOnActionExpandListener(searchMenuItem, new MenuItemCompat.OnActionExpandListener() {
        @Override/* w  ww.java 2s.c  o  m*/
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.fragment_container);

            // Not replace if no search has been done (no switch of fragment)
            if (currentFragment instanceof SearchFragment) {
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.fragment_container, SearchFragment.newInstance(), SearchFragment.TAG)
                        .commit();
            }

            return true;
        }
    });

    return true;
}

From source file:org.openmrs.client.activities.FindPatientsSearchActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*from  w w w  .  j  av  a 2s  .  c o m*/
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.find_patients_menu, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);

    SearchView findPatientView;

    mFindPatientMenuItem = menu.findItem(R.id.actionSearch);
    if (OpenMRS.getInstance().isRunningHoneycombVersionOrHigher()) {
        findPatientView = (SearchView) mFindPatientMenuItem.getActionView();
    } else {
        findPatientView = (SearchView) MenuItemCompat.getActionView(mFindPatientMenuItem);
    }

    SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
    findPatientView.setSearchableInfo(info);
    findPatientView.setIconifiedByDefault(false);
    return true;
}

From source file:com.itude.mobile.mobbl.core.view.components.tabbar.MBDefaultActionBarBuilder.java

@Override
public void fillActionBar(ActionBar actionBar, Menu menu) {
    _actionBar = actionBar;//from  w w w  .j  a v a 2 s  .  c  o  m
    _menu = menu;

    List<MBToolDefinition> tools = MBMetadataService.getInstance().getTools();

    for (MBToolDefinition def : tools) {
        if (def.isPreConditionValid()) {
            String localizedTitle = MBLocalizationService.getInstance().getTextForKey(def.getTitle());
            MenuItem menuItem = menu.add(Menu.NONE, def.getName().hashCode(), tools.indexOf(def),
                    localizedTitle);

            Drawable image = null;
            if (def.getIcon() != null) {
                image = MBResourceService.getInstance().getImageByID(def.getIcon());
                menuItem.setIcon(image);
            }

            MenuItemCompat.setShowAsAction(menuItem, getMenuItemActionFlags(def));

            if ("REFRESH".equals(def.getType())) {
                _refreshToolDef = def;
            } else if ("SEARCH".equals(def.getType())) {
                final SearchView searchView = new SearchView(_context);
                searchView.setTag(def);
                searchView.setOnQueryTextFocusChangeListener(new OnFocusChangeListener() {
                    @Override
                    public void onFocusChange(View v, boolean hasFocus) {
                        if (hasFocus) {
                            Object tag = v.getTag();
                            if (tag instanceof MBToolDefinition) {
                                MBToolDefinition toolDef = (MBToolDefinition) tag;
                                if (toolDef.getOutcomeName() != null) {
                                    handleOutcome(toolDef);
                                }
                            }
                        } else {
                            searchView.setIconified(true);
                        }
                    }
                });

                changeSearchImage(image, searchView);

                SearchManager searchManager = (SearchManager) _context.getSystemService(Context.SEARCH_SERVICE);

                searchView.setSearchableInfo(
                        searchManager.getSearchableInfo(MBViewManager.getInstance().getComponentName()));

                MenuItemCompat.setActionView(menuItem, searchView);
            }
        }
    }
    if (actionBar != null) {
        populateActionBar(actionBar);
    }
}

From source file:com.terracom.mumbleclient.channel.ChannelListFragment.java

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

    MenuItem searchItem = menu.findItem(R.id.menu_search);
    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);

    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
        @Override/*from  ww  w . j a  va2 s .co  m*/
        public boolean onSuggestionSelect(int i) {
            return false;
        }

        @Override
        public boolean onSuggestionClick(int i) {
            CursorWrapper cursor = (CursorWrapper) searchView.getSuggestionsAdapter().getItem(i);
            int typeColumn = cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA);
            int dataIdColumn = cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_DATA);
            String itemType = cursor.getString(typeColumn);
            int itemId = cursor.getInt(dataIdColumn);
            if (ChannelSearchProvider.INTENT_DATA_CHANNEL.equals(itemType)) {
                try {
                    if (getService().getSessionChannel().getId() != itemId) {
                        getService().joinChannel(itemId);
                    } else {
                        scrollToChannel(itemId);
                    }
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
                return true;
            } else if (ChannelSearchProvider.INTENT_DATA_USER.equals(itemType)) {
                scrollToUser(itemId);
                return true;
            }
            return false;
        }
    });
}

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(//  w  ww .j a  v  a 2 s.c  om
            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:org.openmrs.mobile.activities.FindActiveVisitsActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override//from w w w  .ja  v  a  2  s  .c o m
public boolean onCreateOptionsMenu(Menu menu) {
    this.getSupportActionBar()
            .setSubtitle(getString(R.string.dashboard_logged_as, OpenMRS.getInstance().getUsername()));
    getMenuInflater().inflate(R.menu.find_patients_menu, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);

    SearchView findVisitView;

    mFindVisitItem = menu.findItem(R.id.actionSearch);
    mFindVisitItem.getIcon().setAlpha(ApplicationConstants.ENABLED_ICON_ALPHA);
    if (OpenMRS.getInstance().isRunningHoneycombVersionOrHigher()) {
        findVisitView = (SearchView) mFindVisitItem.getActionView();
    } else {
        findVisitView = (SearchView) MenuItemCompat.getActionView(mFindVisitItem);
    }

    SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
    findVisitView.setSearchableInfo(info);
    return true;
}