Example usage for android.content Context SEARCH_SERVICE

List of usage examples for android.content Context SEARCH_SERVICE

Introduction

In this page you can find the example usage for android.content Context SEARCH_SERVICE.

Prototype

String SEARCH_SERVICE

To view the source code for android.content Context SEARCH_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.app.SearchManager for handling searches.

Usage

From source file:com.fastbootmobile.encore.app.MainActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    if (!mNavigationDrawerFragment.isDrawerOpen()) {
        if ((mCurrentFragmentIndex + 1) != SECTION_AUTOMIX) {
            // Only show items in the action bar relevant to this screen
            // if the drawer is not showing. Otherwise, let the drawer
            // decide what to show in the action bar.
            getMenuInflater().inflate(R.menu.main, menu);
            SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);

            mSearchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
            mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
            mSearchView.setIconifiedByDefault(true);
            mSearchView.setQueryRefinementEnabled(true);
            mSearchView.setSubmitButtonEnabled(true);

            if (mCurrentFragmentIndex + 1 == SECTION_LISTEN_NOW) {
                menu.removeItem(R.id.action_search);
            }/*  w  w w  .ja  va2s . c  o  m*/

            mSearchView.setOnSearchClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    menu.findItem(R.id.action_cast).setVisible(false);
                    mNavigationDrawerFragment.setDrawerIndicatorEnabled(false);
                    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
                    mSearchView.requestFocus();
                    mToolbar.setBackgroundColor(getResources().getColor(R.color.primary));
                }
            });
            mSearchView.setOnCloseListener(new SearchView.OnCloseListener() {
                @Override
                public boolean onClose() {
                    if (Utils.hasJellyBeanMR1()) {
                        MenuItem item = menu.findItem(R.id.action_cast);
                        if (item != null) {
                            item.setVisible(true);
                        }
                    }

                    getSupportActionBar().setDisplayHomeAsUpEnabled(false);
                    mNavigationDrawerFragment.setDrawerIndicatorEnabled(true);
                    return false;
                }
            });

            // Setup cast button on 4.2+
            MenuItem castMenu = menu.findItem(R.id.action_cast);
            if (Utils.hasJellyBeanMR1()) {
                MediaRouteActionProvider mediaRouteActionProvider = (MediaRouteActionProvider) MenuItemCompat
                        .getActionProvider(castMenu);
                mediaRouteActionProvider.setRouteSelector(mCastModule.getSelector());
                castMenu.setVisible(true);
            } else {
                Log.w(TAG, "Api too low to show cast action");
                castMenu.setVisible(false);
            }

            // Offline mode
            mOfflineMenuItem = menu.findItem(R.id.action_offline_mode);
            ProviderAggregator aggregator = ProviderAggregator.getDefault();
            if (aggregator.hasNetworkConnectivity()) {
                mOfflineMenuItem.setChecked(aggregator.isOfflineMode());
            } else {
                mOfflineMenuItem.setEnabled(false);
            }
        }

        restoreActionBar();
        return true;
    }
    return super.onCreateOptionsMenu(menu);
}

From source file:com.benlinskey.greekreference.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Only show items in the action bar relevant to this screen if the drawer is not showing.
    // Otherwise, let the drawer decide what to show in the action bar.
    if (mNavigationDrawerFragment.isDrawerOpen()) {
        return super.onCreateOptionsMenu(menu);
    }/*from w w w  .  j  a v  a  2s. c om*/

    // Inflate the options menu from XML. We have to handle the menu here rather than in the
    // fragment so that we can hide them when the navigation drawer is open.
    if (mMode.isLexiconMode()) {
        getMenuInflater().inflate(R.menu.lexicon_menu, menu);
        setLexiconFavoriteIcon(menu);

        // Get the SearchView and set the searchable configuration.
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_search));
        //SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

        restoreActionBar();
        return super.onCreateOptionsMenu(menu);
    } else if (mMode.isSyntaxMode()) {
        getMenuInflater().inflate(R.menu.syntax_menu, menu);
        setSyntaxBookmarkIcon(menu);
        restoreActionBar();
        return super.onCreateOptionsMenu(menu);
    } else {
        throw new IllegalStateException("Invalid mode");
    }
}

From source file:com.ksharkapps.musicnow.ui.activities.AudioPlayerActivity.java

/**
 * {@inheritDoc}/* w ww. ja v a 2s  .c o  m*/
 */
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    // Search view
    getMenuInflater().inflate(R.menu.search, menu);

    MenuItem searchItem = menu.findItem(R.id.menu_search);
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    // Add voice search
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final SearchableInfo searchableInfo = searchManager.getSearchableInfo(getComponentName());
    searchView.setSearchableInfo(searchableInfo);
    // Perform the search
    if (searchView != null)
        searchView.setOnQueryTextListener(new OnQueryTextListener() {

            @Override
            public boolean onQueryTextSubmit(final String query) {
                // Open the search activity
                NavUtils.openSearch(AudioPlayerActivity.this, query);
                return true;
            }

            @Override
            public boolean onQueryTextChange(final String newText) {
                // Nothing to do
                return false;
            }
        });

    // Favorite action
    getMenuInflater().inflate(R.menu.favorite, menu);
    // Shuffle all
    getMenuInflater().inflate(R.menu.shuffle, menu);
    // Share, ringtone, and equalizer
    getMenuInflater().inflate(R.menu.audio_player, menu);
    // Settings
    getMenuInflater().inflate(R.menu.activity_base, menu);
    return true;
}

From source file:nl.mpcjanssen.simpletask.Simpletask.java

@Override
public boolean onCreateOptionsMenu(@NotNull final Menu menu) {
    MenuInflater inflater = getMenuInflater();
    if (m_app.isDarkActionbar()) {
        inflater.inflate(R.menu.main, menu);
    } else {//from   ww  w. j  a va 2 s.c  om
        inflater.inflate(R.menu.main_light, menu);
    }

    if (!m_app.fileStoreCanSync()) {
        MenuItem mItem = menu.findItem(R.id.sync);
        mItem.setVisible(false);
    }
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    searchView.setIconifiedByDefault(false);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        public boolean m_ignoreSearchChangeCallback;

        @Override
        public boolean onQueryTextSubmit(String query) {
            // Stupid searchview code will call onQueryTextChange callback
            // When the actionView collapse and the textview is reset
            // ugly global hack around this
            m_ignoreSearchChangeCallback = true;
            menu.findItem(R.id.search).collapseActionView();
            m_ignoreSearchChangeCallback = false;
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (!m_ignoreSearchChangeCallback) {
                if (mFilter == null) {
                    mFilter = new ActiveFilter();
                }
                mFilter.setSearch(newText);
                mFilter.saveInPrefs(TodoApplication.getPrefs());
                if (m_adapter != null) {
                    m_adapter.setFilteredTasks();
                }
            }
            return true;
        }
    });
    this.options_menu = menu;
    return super.onCreateOptionsMenu(menu);
}

From source file:app.cloud9.com.cloud9.NoticeBoard.java

public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar

    mMenu = menu;/*from  w w w.j  av  a2 s  .co  m*/
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.search, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchMenuItem = menu.findItem(R.id.search_notice);
    android.support.v7.widget.SearchView searchView = (android.support.v7.widget.SearchView) menu
            .findItem(R.id.search_notice).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(true);
    searchView.setMaxWidth(3800);
    SearchView.SearchAutoComplete theTextArea = (SearchView.SearchAutoComplete) searchView
            .findViewById(R.id.search_src_text);
    theTextArea.setTextColor(Color.WHITE);//or any color that you want

    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setSubmitButtonEnabled(true);
    searchView.setOnQueryTextListener(this);

    return true;

}

From source file:org.videolan.vlc.gui.MyFragment.java

/** Create menu from XML
 *///from   w w w. j a va2  s .  c  om
@TargetApi(Build.VERSION_CODES.FROYO)
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    mMenu = menu;
    /* Note: on Android 3.0+ with an action bar this method
     * is called while the view is created. This can happen
     * any time after onCreate.
     */
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.media_library, menu);

    if (AndroidUtil.isFroyoOrLater()) {
        SearchManager searchManager = (SearchManager) VLCApplication.getAppContext()
                .getSystemService(Context.SEARCH_SERVICE);
        mSearchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.ml_menu_search));
        mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        mSearchView.setQueryHint(getString(R.string.search_hint));
        SearchSuggestionsAdapter searchSuggestionsAdapter = new SearchSuggestionsAdapter(this, null);
        searchSuggestionsAdapter.setFilterQueryProvider(this);
        //  mSearchView.setIconifiedByDefault(false);//(?ture)
        //mSearchView.setSearchViewBackground(mSearchView);
        //setSearchViewBackground(mSearchView);
        mSearchView.setSuggestionsAdapter(searchSuggestionsAdapter);
    } else
        menu.findItem(R.id.ml_menu_search).setVisible(false);
    return super.onCreateOptionsMenu(menu);
}

From source file:edu.umbc.cs.ebiquity.mithril.parserapp.contentparsers.contacts.ContactsListFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override//from   ww w.j ava  2s. c  o  m
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    // Inflate the menu items
    inflater.inflate(R.menu.contact_list_menu, menu);
    // Locate the search item
    MenuItem searchItem = menu.findItem(R.id.menu_search);

    // In versions prior to Android 3.0, hides the search item to prevent additional
    // searches. In Android 3.0 and later, searching is done via a SearchView in the ActionBar.
    // Since the search doesn't create a new Activity to do the searching, the menu item
    // doesn't need to be turned off.
    if (mIsSearchResultView) {
        searchItem.setVisible(false);
    }

    // In version 3.0 and later, sets up and configures the ActionBar SearchView
    if (Utils.hasHoneycomb()) {

        // Retrieves the system search manager service
        final SearchManager searchManager = (SearchManager) getActivity()
                .getSystemService(Context.SEARCH_SERVICE);

        // Retrieves the SearchView from the search menu item
        final SearchView searchView = (SearchView) searchItem.getActionView();

        // Assign searchable info to SearchView
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

        // Set listeners for SearchView
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String queryText) {
                // Nothing needs to happen when the user submits the search string
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                // Called when the action bar search text has changed.  Updates
                // the search filter, and restarts the loader to do a new query
                // using the new search string.
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;

                // Don't do anything if the filter is empty
                if (mSearchTerm == null && newFilter == null) {
                    return true;
                }

                // Don't do anything if the new filter is the same as the current filter
                if (mSearchTerm != null && mSearchTerm.equals(newFilter)) {
                    return true;
                }

                // Updates current filter to new filter
                mSearchTerm = newFilter;

                // Restarts the loader. This triggers onCreateLoader(), which builds the
                // necessary content Uri from mSearchTerm.
                mSearchQueryChanged = true;
                if (ParserApplication.getQueryOrLoader() == ParserApplication.getContactButtonLoader()) {
                    /**
                     * If the query text changes for the contact search then the loader is restarted
                     */
                    getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                    //                       Toast.makeText(getActivity(), ParserApplication.getQueryOrLoader()
                    //                             +"and"+ParserApplication.getButtonLoader(), Toast.LENGTH_LONG).show();
                } else if (ParserApplication.getQueryOrLoader()
                        .equals(ParserApplication.getContactButtonQuery())) {
                    //                       Toast.makeText(getActivity(), ParserApplication.getQueryOrLoader(), Toast.LENGTH_LONG).show();
                    getData();
                }
                return true;
            }
        });

        if (Utils.hasICS()) {
            // This listener added in ICS
            searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
                @Override
                public boolean onMenuItemActionExpand(MenuItem menuItem) {
                    // Nothing to do when the action item is expanded
                    return true;
                }

                @Override
                public boolean onMenuItemActionCollapse(MenuItem menuItem) {
                    // When the user collapses the SearchView the current search string is
                    // cleared and the loader restarted.
                    if (!TextUtils.isEmpty(mSearchTerm)) {
                        onSelectionCleared();
                    }
                    mSearchTerm = null;
                    if (ParserApplication.getQueryOrLoader() == ParserApplication.getContactButtonLoader()) {
                        /**
                         * If the query text changes for the contact search then the loader is restarted
                         */
                        getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null,
                                ContactsListFragment.this);
                        //                           Toast.makeText(getActivity(), ParserApplication.getQueryOrLoader()
                        //                                 +"and"+ParserApplication.getButtonLoader(), Toast.LENGTH_LONG).show();
                    } else if (ParserApplication.getQueryOrLoader()
                            .equals(ParserApplication.getContactButtonQuery())) {
                        //                           Toast.makeText(getActivity(), ParserApplication.getQueryOrLoader(), Toast.LENGTH_LONG).show();
                        getData();
                    }
                    return true;
                }
            });
        }

        if (mSearchTerm != null) {
            // If search term is already set here then this fragment is
            // being restored from a saved state and the search menu item
            // needs to be expanded and populated again.

            // Stores the search term (as it will be wiped out by
            // onQueryTextChange() when the menu item is expanded).
            final String savedSearchTerm = mSearchTerm;

            // Expands the search menu item
            if (Utils.hasICS()) {
                searchItem.expandActionView();
            }

            // Sets the SearchView to the previous search string
            searchView.setQuery(savedSearchTerm, false);
        }
    }
}

From source file:org.awesomeapp.messenger.MainActivity.java

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

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    mSearchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_search));

    if (mSearchView != null) {
        mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        mSearchView.setIconifiedByDefault(false);

        SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
            public boolean onQueryTextChange(String query) {
                mConversationList.doSearch(query);
                return true;
            }// ww  w .j  av a  2 s.  co m

            public boolean onQueryTextSubmit(String query) {
                mConversationList.doSearch(query);

                return true;
            }
        };

        mSearchView.setOnQueryTextListener(queryTextListener);

        mSearchView.setOnCloseListener(new SearchView.OnCloseListener() {
            @Override
            public boolean onClose() {
                mConversationList.doSearch(null);
                return false;
            }
        });
    }

    MenuItem mItem = menu.findItem(R.id.menu_lock_reset);

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    if (!settings.contains(ImApp.PREFERENCE_KEY_TEMP_PASS))
        mItem.setVisible(true);

    return true;
}

From source file:de.tap.easy_xkcd.Activities.SearchResultsActivity.java

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

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false);
    MenuItem searchMenuItem = menu.findItem(R.id.action_search);

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override/* w w  w . j a  va2  s.c  o  m*/
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (task != null) {
                task.cancel(true);
            }
            task = new searchTask();
            task.execute(newText);
            return false;
        }
    });

    MenuItemCompat.setOnActionExpandListener(searchMenuItem, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            View view = getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(view, 0);
            }
            searchView.requestFocus();
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            View view = getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
            return true;
        }
    });
    return true;
}

From source file:com.dsdar.thosearoundme.util.ContactsListFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override/*from   ww w.  ja va  2 s  .  c om*/
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    // Inflate the menu items
    inflater.inflate(R.menu.contact_list_menu, menu);
    // Locate the search item
    MenuItem searchItem = menu.findItem(R.id.menu_search);

    // In versions prior to Android 3.0, hides the search item to prevent
    // additional
    // searches. In Android 3.0 and later, searching is done via a
    // SearchView in the ActionBar.
    // Since the search doesn't create a new Activity to do the searching,
    // the menu item
    // doesn't need to be turned off.
    if (mIsSearchResultView) {
        searchItem.setVisible(false);
    }

    // In version 3.0 and later, sets up and configures the ActionBar
    // SearchView
    if (Util.hasHoneycomb()) {

        // Retrieves the system search manager service
        final SearchManager searchManager = (SearchManager) getActivity()
                .getSystemService(Context.SEARCH_SERVICE);

        // Retrieves the SearchView from the search menu item
        final SearchView searchView = (SearchView) searchItem.getActionView();

        // Assign searchable info to SearchView
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

        // Set listeners for SearchView
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String queryText) {
                // Nothing needs to happen when the user submits the
                // search string
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                // Called when the action bar search text has
                // changed. Updates
                // the search filter, and restarts the loader to do
                // a new query
                // using the new search string.
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;

                // Don't do anything if the filter is empty
                if (mSearchTerm == null && newFilter == null) {
                    return true;
                }

                // Don't do anything if the new filter is the same
                // as the current filter
                if (mSearchTerm != null && mSearchTerm.equals(newFilter)) {
                    return true;
                }

                // Updates current filter to new filter
                mSearchTerm = newFilter;

                // Restarts the loader. This triggers
                // onCreateLoader(), which builds the
                // necessary content Uri from mSearchTerm.
                mSearchQueryChanged = true;
                getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                return true;
            }
        });

        if (Util.hasICS()) {
            // This listener added in ICS
            searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
                @Override
                public boolean onMenuItemActionExpand(MenuItem menuItem) {
                    // Nothing to do when the action item is
                    // expanded
                    return true;
                }

                @Override
                public boolean onMenuItemActionCollapse(MenuItem menuItem) {
                    // When the user collapses the SearchView the
                    // current search string is
                    // cleared and the loader restarted.
                    if (!TextUtils.isEmpty(mSearchTerm)) {
                        onSelectionCleared();
                    }
                    mSearchTerm = null;
                    getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                    return true;
                }
            });
        }

        if (mSearchTerm != null) {
            // If search term is already set here then this fragment is
            // being restored from a saved state and the search menu item
            // needs to be expanded and populated again.

            // Stores the search term (as it will be wiped out by
            // onQueryTextChange() when the menu item is expanded).
            final String savedSearchTerm = mSearchTerm;

            // Expands the search menu item
            if (Util.hasICS()) {
                searchItem.expandActionView();
            }

            // Sets the SearchView to the previous search string
            searchView.setQuery(savedSearchTerm, false);
        }
    }
}