List of usage examples for android.content Context SEARCH_SERVICE
String SEARCH_SERVICE
To view the source code for android.content Context SEARCH_SERVICE.
Click Source Link
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// w w w . jav a2 s . 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:br.com.mybaby.contatos.ContactsListFragment.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override// w ww . j a v a 2 s. c o m public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { // Inflate the menu items inflater.inflate(R.menu.contatos_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); } } }
From source file:com.forktech.cmerge.ui.ContactsListFragment.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override//from w w w .j a va2 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 (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) MenuItemCompat.getActionView(searchItem); // 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; mAdapter.setSearchTerm(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 (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; // mAdapter.setSearchTerm(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 (Utils.hasICS()) { searchItem.expandActionView(); } // Sets the SearchView to the previous search string searchView.setQuery(savedSearchTerm, false); } } }
From source file:com.example.lowviscam.GalleryActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu items for use in the action bar MenuInflater inflater = getMenuInflater(); if (isLight == true) { inflater.inflate(R.menu.gallery, menu); } else {/* w ww . ja v a 2 s . c o m*/ inflater.inflate(R.menu.gallery_dark, menu); } // Get the SearchView and set the searchable configuration SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.action_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.setSubmitButtonEnabled(true); searchView.setOnQueryTextListener(new OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { search(query); // First image toast String firstResult; if (numSearchResults == 0) { firstResult = "No results found for " + query + "."; } else { firstResult = "The first image result is titled " + tagList[0]; } SpannableString s = new SpannableString(firstResult); s.setSpan(new TypefaceSpan(GalleryActivity.this, "APHont-Regular_q15c.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); Toast.makeText(GalleryActivity.this, s, Toast.LENGTH_LONG).show(); return true; } @Override public boolean onQueryTextChange(String newText) { if (TextUtils.isEmpty(newText)) { search(""); } return true; } public void search(String query) { // hide keyboard InputMethodManager inputManager = (InputMethodManager) GalleryActivity.this .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(GalleryActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); // Fetch the {@link LayoutInflater} service so that new views can be created LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); // Find the {@link GridView} that was already defined in the XML layout GridView gridView = (GridView) findViewById(R.id.grid); try { gridView.setAdapter(new CouponAdapter(inflater, createSearchedCoupons(query))); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); return true; //return super.onCreateOptionsMenu(menu); }
From source file:bf.io.openshop.ux.MainActivity.java
/** * Prepare toolbar search view. Invoke search suggestions and handle search queries. * * @param searchItem corresponding menu item. *//*from w w w .ja v a 2 s . c o m*/ private void prepareSearchView(@NonNull final MenuItem searchItem) { final SearchView searchView = (SearchView) searchItem.getActionView(); searchView.setSubmitButtonEnabled(true); SearchManager searchManager = (SearchManager) MainActivity.this.getSystemService(Context.SEARCH_SERVICE); searchView.setSearchableInfo(searchManager.getSearchableInfo(MainActivity.this.getComponentName())); SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() { public boolean onQueryTextChange(String newText) { Timber.d("Search query text changed to: %s", newText); showSearchSuggestions(newText, searchView); return false; } public boolean onQueryTextSubmit(String query) { // Submit search query and hide search action view. onSearchSubmitted(query); searchView.setQuery("", false); searchView.setIconified(true); searchItem.collapseActionView(); return true; } }; searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() { @Override public boolean onSuggestionSelect(int position) { return false; } @Override public boolean onSuggestionClick(int position) { // Submit search suggestion query and hide search action view. MatrixCursor c = (MatrixCursor) searchSuggestionsAdapter.getItem(position); onSearchSubmitted(c.getString(1)); searchView.setQuery("", false); searchView.setIconified(true); searchItem.collapseActionView(); return true; } }); searchView.setOnQueryTextListener(queryTextListener); }
From source file:com.packetsender.android.MainActivity.java
private void setupSearchView(MenuItem searchItem) { //searchItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); if (searchManager != null) { List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch(); SearchableInfo info = searchManager.getSearchableInfo(getComponentName()); for (SearchableInfo inf : searchables) { if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) { info = inf;//from w ww .jav a2 s . c om } } mSearchView.setSearchableInfo(info); } mSearchView.setOnQueryTextListener(this); }
From source file:uk.ac.hutton.ics.buntata.activity.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { /* Inflate the menu */ MenuInflater menuInflater = getMenuInflater(); menuInflater.inflate(R.menu.main_menu, menu); /* Find the search menu item */ final MenuItem searchItem = menu.findItem(R.id.action_search); /* Get the search manager */ SearchManager searchManager = (SearchManager) MainActivity.this.getSystemService(Context.SEARCH_SERVICE); /* Get the actual search view */ searchView = (SearchView) MenuItemCompat.getActionView(searchItem); if (searchView != null) { DisplayMetrics displayMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); final MenuItem barcodeItem = menu.findItem(R.id.action_scan_barcode); searchView.setMaxWidth(displayMetrics.widthPixels / 2); searchView.setSearchableInfo(searchManager.getSearchableInfo(MainActivity.this.getComponentName())); searchView.setQueryHint(getString(R.string.search_query_hint)); /* Listen to submit events */ searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override/*w w w . java 2 s. c om*/ public boolean onQueryTextSubmit(String query) { /* Trim leading and trailing spaces that some keyboards will add */ query = query.trim(); MainActivity.this.query = query; filter(query); searchView.clearFocus(); return false; } @Override public boolean onQueryTextChange(String s) { /* Close the search field when the search string is empty */ if (StringUtils.isEmpty(s)) { searchView.setIconified(true); searchView.clearFocus(); } return false; } }); searchView.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { MainActivity.this.query = null; filter(""); barcodeItem.setVisible(false); return false; } }); searchView.setOnSearchClickListener(new View.OnClickListener() { @Override public void onClick(View view) { barcodeItem.setVisible(true); } }); } return super.onCreateOptionsMenu(menu); }
From source file:com.example.contactslist.ui.ContactsListFragment.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override// w w w . ja v a2s . 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; /*Uri uri; Cursor[] atomic = new Cursor[phoneNumbers.length]; for(int i=0; i<phoneNumbers.length; i++){ uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumbers[i])); atomic[i] = getActivity().getContentResolver().query(uri, ContactsQuery.PROJECTION, null, null, ContactsQuery.SORT_ORDER); } Cursor extendedCursor = new MergeCursor(atomic);*/ /* Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; String[] projection = new String[] {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER}; String SELECTION = ContactsContract.CommonDataKinds.Phone.NUMBER + " LIKE '%9986395899' OR " + ContactsContract.CommonDataKinds.Phone.NUMBER + " LIKE '%997%'"; Cursor people = getActivity().getContentResolver().query(uri, ContactsQuery.PROJECTION, SELECTION, null, null); mAdapter.swapCursor(people);*/ getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this); 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; 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 (Utils.hasICS()) { searchItem.expandActionView(); } // Sets the SearchView to the previous search string searchView.setQuery(savedSearchTerm, false); } } }
From source file:org.kontalk.ui.ConversationsActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.conversation_list_menu, menu); // search/*from ww w . j a v a 2s .c o m*/ mSearchMenu = menu.findItem(R.id.menu_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(mSearchMenu); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); // LayoutParams.MATCH_PARENT does not work, use a big value instead searchView.setMaxWidth(1000000); mDeleteAllMenu = menu.findItem(R.id.menu_delete_all); // offline mode mOfflineMenu = menu.findItem(R.id.menu_offline); // trigger manually onDatabaseChanged(); updateOffline(); return true; }
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); }//from www . j a va2s . 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); }