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:com.miz.mizuu.fragments.MovieLibraryFragment.java

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

    menu.findItem(R.id.random).setVisible(mMovieLoader.getType() != MovieLibraryType.COLLECTIONS);

    if (mMovieLoader.getType() == MovieLibraryType.COLLECTIONS) {
        menu.findItem(R.id.sort).setVisible(false);
        menu.findItem(R.id.filters).setVisible(false);
    }//w w  w. j  a  v a2  s.c o  m

    MenuItemCompat.setOnActionExpandListener(menu.findItem(R.id.search_textbox), new OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            onSearchViewCollapsed();
            return true;
        }
    });

    mSearchView = (SearchView) menu.findItem(R.id.search_textbox).getActionView();
    mSearchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            if (newText.length() > 0) {
                mMovieLoader.search(newText);
                showProgressBar();
            } else {
                onSearchViewCollapsed();
            }
            return true;
        }

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

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:ua.boberproduction.bbr.BaseActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);

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

    searchView = null;//from www .jav a2  s.  c o m
    if (searchItem != null) {
        searchView = (SearchView) searchItem.getActionView();
    }
    if (searchView != null) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(this.getComponentName()));

        searchView.setIconified(true);
        searchView.clearFocus();
        searchView.onActionViewCollapsed();
    }

    // if user activated God Mode, hide the 'remove ads' menu option..
    if (Ad.getGodModeStatus(this)) {
        MenuItem item = menu.findItem(R.id.action_remove_ads);
        item.setVisible(false);
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:com.paranoid.gerrit.GerritControllerActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.gerrit_instances_menu, menu);
    this.mMenu = menu;

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(true);
    // Let the change list fragment handle queries directly.
    searchView.setOnQueryTextListener(mChangeList);
    searchView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override//w w w .  j a v a  2 s  .c  o m
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                int oldRight, int oldBottom) {
            SearchView view = (SearchView) v;
            if (view.isIconified()) {
                mMenu.findItem(R.id.menu_team_instance).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
                mMenu.findItem(R.id.menu_projects).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
            } else {
                mMenu.findItem(R.id.menu_team_instance).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
                mMenu.findItem(R.id.menu_projects).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
            }
        }
    });

    setupSearchQuery();
    return true;
}

From source file:au.com.cybersearch2.classyfy.MainActivity.java

/**
 * Create search view SearchableInfo (xml/searchable.xml) and IconifiedByDefault (false)
 * @param menu Menu object/* ww w  . j ava 2s  .  c o  m*/
 */
protected void createSearchView(Menu menu) {
    /** Get the action view of the menu item whose id is action_search */

    // Associate searchable configuration (in res/xml/searchable.xml with the SearchView
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchMenuItem = menu.findItem(R.id.action_search);
    if (searchMenuItem == null)
        throw new IllegalStateException("Search menu item not found in main menu");
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
    if (searchView == null)
        throw new IllegalStateException("SearchView not found in main menu");
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
}

From source file:com.smedic.tubtub.Pane.java

/**
 * Options menu in action bar/*from   w  w  w  . ja v  a 2s .co m*/
 *
 * @param menu
 * @return
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);

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

    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    if (searchView != null) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    }

    //suggestions
    final CursorAdapter suggestionAdapter = new SimpleCursorAdapter(this, suggestions, null,
            new String[] { SearchManager.SUGGEST_COLUMN_TEXT_1 }, new int[] { android.R.id.text1 }, 0);
    final List<String> suggestions = new ArrayList<>();

    searchView.setSuggestionsAdapter(suggestionAdapter);

    searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
        @Override
        public boolean onSuggestionSelect(int position) {
            return false;
        }

        @Override
        public boolean onSuggestionClick(int position) {
            searchView.setQuery(suggestions.get(position), false);
            searchView.clearFocus();

            Intent suggestionIntent = new Intent(Intent.ACTION_SEARCH);
            suggestionIntent.putExtra(SearchManager.QUERY, suggestions.get(position));
            handleIntent(suggestionIntent);

            return true;
        }
    });

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String s) {
            return false; //if true, no new intent is started
        }

        @Override
        public boolean onQueryTextChange(final String query) {
            // check network connection. If not available, do not query.
            // this also disables onSuggestionClick triggering
            if (query.length() > 2) { //make suggestions after 3rd letter
                if (networkConf.isNetworkAvailable()) {
                    suggestionLoader(suggestions, suggestionAdapter, query).forceLoad();
                    return true;
                }
            }
            return false;
        }
    });

    return true;
}

From source file:com.miz.mizuu.fragments.TvShowLibraryFragment.java

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

    MenuItemCompat.setOnActionExpandListener(menu.findItem(R.id.search_textbox), new OnActionExpandListener() {
        @Override/*from   w ww .ja  v  a  2s.  c  o m*/
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            onSearchViewCollapsed();
            return true;
        }
    });

    mSearchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.search_textbox));
    mSearchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            if (newText.length() > 0) {
                mTvShowLoader.search(newText);
                showProgressBar();
            } else {
                onSearchViewCollapsed();
            }
            return true;
        }

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

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    ComponentName cn = new ComponentName(getActivity(), TvShowActorSearchActivity.class);
    mSearchView.setSearchableInfo(searchManager.getSearchableInfo(cn));

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.android.mail.ui.ActionBarController.java

public boolean onCreateOptionsMenu(Menu menu) {
    mEmptyTrashItem = menu.findItem(R.id.empty_trash);
    mEmptySpamItem = menu.findItem(R.id.empty_spam);
    mSearch = menu.findItem(R.id.search);

    if (mSearch != null) {
        mSearchWidget = (SearchView) MenuItemCompat.getActionView(mSearch);
        MenuItemCompat.setOnActionExpandListener(mSearch, this);
        SearchManager searchManager = (SearchManager) mActivity.getActivityContext()
                .getSystemService(Context.SEARCH_SERVICE);
        if (searchManager != null && mSearchWidget != null) {
            SearchableInfo info = searchManager.getSearchableInfo(mActivity.getComponentName());
            mSearchWidget.setSearchableInfo(info);
            mSearchWidget.setOnQueryTextListener(this);
            mSearchWidget.setOnSuggestionListener(this);
            mSearchWidget.setIconifiedByDefault(true);
        }/* ww w. j  ava2s .  com*/
    }

    // the menu should be displayed if the mode is known
    return getMode() != ViewMode.UNKNOWN;
}

From source file:com.berniesanders.fieldthebern.MainActivity.java

private void setupSearchMenu(Menu menu) {
    // Inflate the options menu from XML
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_main, menu);
    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
    searchView.setBackgroundColor(bernieDarkBlue);
}

From source file:com.misczak.joinmybridge.PhoneBookFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

    inflater.inflate(R.menu.fragment_phonebook, menu);

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

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    ComponentName name = getActivity().getComponentName();
    SearchableInfo searchInfo = searchManager.getSearchableInfo(name);

    searchView.setSearchableInfo(searchInfo);

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override/*from   w  w w .ja va2  s. c  o m*/
        public boolean onQueryTextSubmit(String s) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String s) {

            filterString = s;
            adapter.getFilter().filter(s);
            return true;
        }
    });

    searchView.setOnCloseListener(new SearchView.OnCloseListener() {

        @Override
        public boolean onClose() {
            adapter.notifyDataSetChanged();
            return false;
        }
    });

}

From source file:com.klinker.android.twitter.activities.drawer_activities.discover.trends.SearchedTrendsActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.search_activity, menu);

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(true); // Do not iconify the widget; expand it by default

    int searchImgId = getResources().getIdentifier("android:id/search_button", null, null);
    ImageView view = (ImageView) searchView.findViewById(searchImgId);
    view.setImageResource(settings.theme == AppSettings.THEME_LIGHT ? R.drawable.ic_action_search_light
            : R.drawable.ic_action_search_dark);

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