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:gc.david.dfm.ui.activity.MainActivity.java

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

    searchMenuItem = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) searchMenuItem.getActionView();
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    // Indicamos que la activity actual sea la buscadora
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setSubmitButtonEnabled(false);
    searchView.setQueryRefinementEnabled(true);
    searchView.setIconifiedByDefault(true);

    // TODO: 16.01.17 move this to presenter
    final MenuItem loadItem = menu.findItem(R.id.action_load);
    loadDistancesUseCase.execute(new LoadDistancesUseCase.Callback() {
        @Override// ww  w. j av a  2s  .c o  m
        public void onDistanceListLoaded(final List<Distance> distanceList) {
            if (distanceList.isEmpty()) {
                loadItem.setVisible(false);
            }
        }

        @Override
        public void onError() {
            loadItem.setVisible(false);
        }
    });

    menu.findItem(R.id.action_crash).setVisible(!isReleaseBuild());

    return super.onCreateOptionsMenu(menu);
}

From source file:com.atwal.wakeup.battery.util.Utilities.java

/**
 * Returns a widget with category {@link AppWidgetProviderInfo#WIDGET_CATEGORY_SEARCHBOX}
 * provided by the same package which is set to be global search activity.
 * If widgetCategory is not supported, or no such widget is found, returns the first widget
 * provided by the package./*from ww w . j a  v  a 2  s .c o m*/
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static AppWidgetProviderInfo getSearchWidgetProvider(Context context) {
    SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
    ComponentName searchComponent = searchManager.getGlobalSearchActivity();
    if (searchComponent == null)
        return null;
    String providerPkg = searchComponent.getPackageName();

    AppWidgetProviderInfo defaultWidgetForSearchPackage = null;

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    for (AppWidgetProviderInfo info : appWidgetManager.getInstalledProviders()) {
        if (info.provider.getPackageName().equals(providerPkg)) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                if ((info.widgetCategory & AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX) != 0) {
                    return info;
                } else if (defaultWidgetForSearchPackage == null) {
                    defaultWidgetForSearchPackage = info;
                }
            } else {
                return info;
            }
        }
    }
    return defaultWidgetForSearchPackage;
}

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

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override/*from  w  ww.j  ava 2  s .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 (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,
                        MemberAddContactsListFragment.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,
                            MemberAddContactsListFragment.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);
        }
    }
}

From source file:de.sourcestream.movieDB.MainActivity.java

/**
 * Initialize the contents of the Activity's standard options menu.
 * This is only called once, the first time the options menu is displayed.
 *
 * @param menu the options menu in which we place our items.
 * @return You must return true for the menu to be displayed; if you return false it will not be shown.
 *///ww  w . ja  va  2  s  .c o m
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    searchViewItem = menu.findItem(R.id.search);
    searchView = (SearchView) MenuItemCompat.getActionView(searchViewItem);

    searchView.setQueryHint(getResources().getString(R.string.search_hint));
    searchView.setOnQueryTextListener(searchViewOnQueryTextListener);
    searchView.setOnSuggestionListener(searchSuggestionListener);

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

    String[] from = { SearchManager.SUGGEST_COLUMN_ICON_1, SearchManager.SUGGEST_COLUMN_TEXT_1,
            SearchManager.SUGGEST_COLUMN_TEXT_2 };
    int[] to = { R.id.posterPath, R.id.title, R.id.info };
    searchAdapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.suggestionrow, null, from, to,
            0) {
        @Override
        public void changeCursor(Cursor cursor) {
            super.swapCursor(cursor);
        }
    };
    searchViewItemC.setSuggestionsAdapter(searchAdapter);

    MenuItemCompat.setOnActionExpandListener(searchViewItem, onSearchViewItemExpand);

    return true;
}

From source file:com.vuze.android.remote.activity.TorrentViewActivity.java

@TargetApi(Build.VERSION_CODES.FROYO)
private void setupSearchView_Froyo(SearchView mSearchView) {
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    if (searchManager != null) {
        mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    }//from www  . jav  a2 s.c om
}

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    // Get the SearchView and set the searchable configuration
    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);
    searchMenuItem = menu.findItem(R.id.action_search);

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override//from  w  w  w  .jav a 2s  .  com
        public boolean onQueryTextSubmit(String query) {
            MenuItem searchMenuItem = getSearchMenuItem();
            searchMenuItem.collapseActionView();
            searchView.setQuery("", false);
            //Hide Keyboard
            View view = MainActivity.this.getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
            return false;
        }

        @Override
        public boolean onQueryTextChange(String 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;
        }
    });
    if (prefHelper.hideDonate())
        menu.findItem(R.id.action_donate).setVisible(false);
    return true;
}

From source file:com.dycody.android.idealnote.ListFragment.java

/**
 * SearchView initialization. It's a little complex because it's not using SearchManager but is implementing on its
 * own.//ww w. ja v  a2s.  c om
 */
@SuppressLint("NewApi")
private void initSearchView(final Menu menu) {

    // Prevents some mysterious NullPointer on app fast-switching
    if (mainActivity == null)
        return;

    // Save item as class attribute to make it collapse on drawer opening
    searchMenuItem = menu.findItem(R.id.menu_search);

    // Associate searchable configuration with the SearchView
    SearchManager searchManager = (SearchManager) mainActivity.getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_search));
    searchView.setSearchableInfo(searchManager.getSearchableInfo(mainActivity.getComponentName()));
    searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);

    // Expands the widget hiding other actionbar icons
    searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> setActionItemsVisibility(menu, hasFocus));

    MenuItemCompat.setOnActionExpandListener(searchMenuItem, new MenuItemCompat.OnActionExpandListener() {

        boolean searchPerformed = false;

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            // Reinitialize notes list to all notes when search is collapsed
            searchQuery = null;
            if (searchLayout.getVisibility() == View.VISIBLE) {
                toggleSearchLabel(false);
            }
            mainActivity.getIntent().setAction(Intent.ACTION_MAIN);
            initNotesList(mainActivity.getIntent());
            mainActivity.supportInvalidateOptionsMenu();
            return true;
        }

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {

            searchView.setOnQueryTextListener(new OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String arg0) {

                    return prefs.getBoolean("settings_instant_search", false);
                }

                @Override
                public boolean onQueryTextChange(String pattern) {

                    if (prefs.getBoolean("settings_instant_search", false) && searchLayout != null
                            && searchPerformed && mFragment.isAdded()) {
                        searchTags = null;
                        searchQuery = pattern;
                        NoteLoaderTask.getInstance().execute("getNotesByPattern", pattern);
                        return true;
                    } else {
                        searchPerformed = true;
                        return false;
                    }
                }
            });
            return true;
        }
    });
}

From source file:at.ac.tuwien.detlef.activities.MainActivity.java

/**
 * Get the {@link SearchView} and set the {@link SearchableInfo}
 * configuration for the {@link EpisodeListFragment#getFilter() episode
 * keyword filter}./*w  ww.jav  a  2  s.  com*/
 */
private void setSearchManager() {
    String tmptag = "searchmanager";
    Log.d(tmptag, "setSearchManager()");

    if (menu.findItem(R.id.menu_search) == null) {
        Log.d(tmptag, "is null");
        return;
    }

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

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

    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(true);
    searchView.setOnQueryTextListener(new EpisodeSearchQueryTextListener(getEpisodeListFragment()));
}

From source file:com.dmsl.anyplace.UnifiedNavigationActivity.java

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

    // ****************************************** Search View
    // ***************************************************************** /
    // Associate searchable configuration with the SearchView
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setQueryHint("Search outdoor");
    searchView.setAddStatesFromChildren(true);

    // set query change listener
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override/*from  w  w w  .j  av  a  2s.c o  m*/
        public boolean onQueryTextChange(final String newText) {
            // return false; // false since we do not handle this call

            if (newText == null || newText.trim().length() < 1) {
                if (mSuggestionsTask != null && !mSuggestionsTask.isCancelled()) {
                    mSuggestionsTask.cancel(true);
                }
                searchView.setSuggestionsAdapter(null);
                return true;
            }

            if (mSuggestionsTask != null) {
                mSuggestionsTask.cancel(true);
            }

            if (searchType == SearchTypes.INDOOR_MODE) {
                if (!userData.isFloorSelected()) {
                    List<IPoisClass> places = new ArrayList<IPoisClass>(1);
                    PoisModel pm = new PoisModel();
                    pm.name = "Load a building first ...";
                    places.add(pm);
                    Cursor cursor = AnyPlaceSeachingHelper.prepareSearchViewCursor(places);
                    showSearchResult(cursor);
                    return true;
                }
            }

            GeoPoint gp = userData.getLatestUserPosition();

            mSuggestionsTask = new AnyplaceSuggestionsTask(
                    new AnyplaceSuggestionsTask.AnyplaceSuggestionsListener() {
                        @Override
                        public void onSuccess(String result, List<? extends IPoisClass> pois) {
                            showSearchResult(AnyPlaceSeachingHelper.prepareSearchViewCursor(pois, newText));
                        }

                        @Override
                        public void onErrorOrCancel(String result) {
                            Log.d("AnyplaceSuggestions", result);
                        }

                        @Override
                        public void onUpdateStatus(String string, Cursor cursor) {
                            showSearchResult(cursor);
                        }

                    }, UnifiedNavigationActivity.this, searchType,
                    (gp == null) ? new GeoPoint(csLat, csLon) : gp, newText);
            mSuggestionsTask.execute(null, null);

            // we return true to avoid caling the provider set in the xml
            return true;
        }

        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }
    });
    searchView.setSubmitButtonEnabled(true);
    searchView.setQueryRefinementEnabled(false);

    // ****************************************** Select building
    // ***************************************************************** /
    // Select building and floor to start navigating and positioning
    final SubMenu subMenuPlace = menu.addSubMenu("Select Building");
    final MenuItem sPlace = subMenuPlace.getItem();
    sPlace.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    sPlace.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            // start the activity where the user can select the FROM and TO
            // pois he wants to navigate
            GeoPoint gp = userData.getLatestUserPosition();
            loadSelectBuildingActivity(gp, false);
            return true;
        }
    });

    // ********************************** CLEAR NAVIGATION
    // *********************************************** /
    final SubMenu subMenuResetNav = menu.addSubMenu("Clear Navigation");
    final MenuItem ResetNav = subMenuResetNav.getItem();
    ResetNav.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    ResetNav.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            clearLastNavigationInfo();
            return true;
        }
    });

    // ***********************Load Ayplace Logger
    // ************************************** /
    final SubMenu subMenuLoadLogger = menu.addSubMenu("Show Logger");
    final MenuItem LoadLogger = subMenuLoadLogger.getItem();
    LoadLogger.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    LoadLogger.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent intent = new Intent(getApplicationContext(), AnyplaceLoggerActivity.class);
            startActivity(intent);
            return true;
        }
    });

    // ****************************************** preferences
    // ********************************************** /
    final SubMenu subMenuPreferences = menu.addSubMenu("Preferences");
    final MenuItem prefsMenu = subMenuPreferences.getItem();
    prefsMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    prefsMenu.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent i = new Intent(UnifiedNavigationActivity.this, AnyplacePrefs.class);
            startActivityForResult(i, PREFERENCES_ACTIVITY_RESULT);
            return true;
        }
    });

    // ****************************************** about
    // ********************************************** /
    final SubMenu subMenuAbout = menu.addSubMenu("About");
    final MenuItem about = subMenuAbout.getItem();
    about.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    about.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            startActivity(new Intent(UnifiedNavigationActivity.this, AnyplaceAboutActivity.class));
            return true;
        }
    });

    // ****************************************** exit
    // ********************************************** /
    final SubMenu subMenuExit = menu.addSubMenu("Exit");
    final MenuItem Exit = subMenuExit.getItem();
    Exit.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    Exit.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            finish();
            return true;
        }
    });

    /***************************************** END OF MAIN MENU ***************************************************************/

    return super.onCreateOptionsMenu(menu);
}

From source file:com.paramonod.kikos.MainActivity.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);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_settings));
    System.out.println(searchView);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override/* ww w  .ja va  2  s. c  om*/
        public boolean onQueryTextSubmit(String query) {
            Menu menu = bottomNavigationView.getMenu();
            Menu mm = navigationView.getMenu();
            FragmentManager fragmentManager = MainActivity.this.getSupportFragmentManager();
            List<Fragment> fragments = fragmentManager.getFragments();
            Fragment f = null;
            System.out.println(fragments);
            if (fragments != null) {
                for (Fragment fragment : fragments) {
                    if (fragment != null && fragment.isVisible())
                        f = fragment;
                    System.out.println(f);
                }
            }
            if (f instanceof CardContentFragment) {
                main.searchListener(query, 2);

            }
            if (f instanceof CategoryContentFragment) {
                main.searchListener(query, 1);

            }
            if (f instanceof MapViewFragment) {
                main.searchListener(query, 0);

            }
            if (f instanceof ListContentFragment) {
                main.searchListener(query, 3);
            }
            if (mm.getItem(1).isChecked()) {
                main.searchListener(query, 3);
            } else
                for (int i = 0; i < bottomNavigationView.getMenu().size(); i++) {
                    MenuItem menuItem = menu.getItem(i);
                    if (menuItem.isChecked()) {
                        main.searchListener(query, i);
                    }
                }

            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });

    return super.onCreateOptionsMenu(menu);
}