List of usage examples for android.app SearchManager getSearchableInfo
public SearchableInfo getSearchableInfo(ComponentName componentName)
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. *///w w w . ja va 2 s.c om 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.granita.tasks.TaskListActivity.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public void setupSearch(Menu menu) { // bail early on unsupported devices if (Build.VERSION.SDK_INT < 11) { return;/*from w ww. ja va 2 s. c om*/ } mSearchItem = menu.findItem(R.id.search); MenuItemCompat.setOnActionExpandListener(mSearchItem, new OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(MenuItem item) { // always allow expansion of the search action view return mCurrentPageId == R.id.task_group_search; } @Override public boolean onMenuItemActionCollapse(MenuItem item) { // return to previous view if (mPreviousPagePosition >= 0 && mCurrentPageId == R.id.task_group_search) { mViewPager.setCurrentItem(mPreviousPagePosition); mCurrentPageId = mPagerAdapter.getPageId(mPreviousPagePosition); } return mPreviousPagePosition >= 0 || mCurrentPageId != R.id.task_group_search; } }); SearchView searchView = (SearchView) MenuItemCompat.getActionView(mSearchItem); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); if (null != searchManager) { searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); } searchView.setQueryHint(getString(R.string.menu_search_hint)); searchView.setIconified(true); searchView.setOnQueryTextListener(new OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { // persist current search mSearchHistoryHelper.commitSearch(); mHandler.post(mSearchUpdater); return true; } @Override public boolean onQueryTextChange(String query) { if (mCurrentPageId != R.id.task_group_search) { return true; } mHandler.removeCallbacks(mSearchUpdater); if (query.length() > 0) { mSearchHistoryHelper.updateSearch(query); mHandler.postDelayed(mSearchUpdater, SEARCH_UPDATE_DELAY); } else { mSearchHistoryHelper.removeCurrentSearch(); mHandler.post(mSearchUpdater); } return true; } }); if (mAutoExpandSearchView) { mSearchItem.expandActionView(); } }
From source file:com.thatkawaiiguy.meleehandbook.activity.SearchResultsActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.searchactivity, menu); ComponentName cn = new ComponentName(this, SearchResultsActivity.class); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.searchview)); searchView.onActionViewExpanded();//from w w w.java 2 s. c o m if (Intent.ACTION_SEARCH.equals(getIntent().getAction())) { searchView.setQuery(getIntent().getStringExtra(SearchManager.QUERY).replaceAll("\\s+$", ""), false); searchView.setSearchableInfo(searchManager.getSearchableInfo(cn)); searchView.clearFocus(); } searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { if (!query.equals("")) search(query); searchView.clearFocus(); return false; } @Override public boolean onQueryTextChange(String newText) { if (!newText.equals("")) search(newText); return false; } }); return super.onCreateOptionsMenu(menu); }
From source file:com.timemachine.controller.ControllerActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu items for use in the action bar MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_activity_actions, menu); // Associate searchable configuration with the SearchView // Get the SearchView and set the searchable configuration SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); // Change the text color in the search view int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null); searchTextView = (TextView) searchView.findViewById(id); searchTextView.setHintTextColor(Color.parseColor("#80ffffff")); searchTextView.setTextColor(Color.parseColor("#ffffff")); return super.onCreateOptionsMenu(menu); }
From source file:cz.muni.fi.japanesedictionary.main.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { mMenu = menu;//from www . j av a 2s . c o m Log.i(LOG_TAG, "Inflating menu"); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); Log.i(LOG_TAG, "Setting menu "); getSupportActionBar().setDisplayShowTitleEnabled(false); // Place an action bar item for searching. MenuItem searchItem = menu.findItem(R.id.action_search); MenuItemCompat.expandActionView(searchItem); mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem); mSearchView.setOnQueryTextListener(this); mSearchView.setIconifiedByDefault(false); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); Log.i(LOG_TAG, "Setting query"); mSearchView.setQuery(mCurFilter, false); Log.i(LOG_TAG, "Setting query done"); return super.onCreateOptionsMenu(menu); }
From source file:mroza.forms.ChooseProgramActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { this.menu = menu; getMenuInflater().inflate(R.menu.choose_program_menu, menu); //Associate programs_searchable configuration with the SearchView SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); android.support.v7.widget.SearchView searchView = (android.support.v7.widget.SearchView) menu .findItem(R.id.action_search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); EditText searchPlate = (EditText) searchView .findViewById(android.support.v7.appcompat.R.id.search_src_text); searchPlate.setImeOptions(EditorInfo.IME_ACTION_SEARCH); searchPlate.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override/*from www .ja v a 2 s . co m*/ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { //On search or enter clicked if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_NULL) { if (v.getText().toString().equals("")) { refreshChildTableList(); clearSearchField(); clearFilters(true); enableShowAllButton(false); } } return false; } }); restoreSavedFilters(); return true; }
From source file:hr.foicore.varazdinlandmarksdemo.POIMapActivity.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.poi_map, menu); miSearch = menu.findItem(R.id.action_search); miDirections = menu.findItem(R.id.action_directions); miPlay = menu.findItem(R.id.action_play); String[] poiNames = new String[gmm.pois.size()]; for (int i = 0; i < gmm.pois.size(); i++) { poiNames[i] = gmm.pois.get(i).getName(); }/*from w w w . j av a 2 s.c o m*/ searchView = (ArrayAdapterSearchView) (SearchView) MenuItemCompat.getActionView(miSearch); mAdapter = new ArrayAdapter<String>(this, R.layout.dropdown_item, poiNames); searchView.setAdapter(mAdapter); searchView.setThreshold(1); // one letter is enough for auto complete searchView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // when clicked on suggested item SearchModule.searchGoogleMap(POIMapActivity.this, gmm.googleMap, gmm.pois, searchView, mAdapter.getItem(position).toString()); MenuItemCompat.collapseActionView(miSearch); } }); searchView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // when clicked on search view (e.g. search icon) searchView.showDropDown(); } }); searchView.setQueryHint(POIMapActivity.this.getResources().getString(R.string.search_hint)); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); if (null != searchView) { searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setIconifiedByDefault(false); } SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() { public boolean onQueryTextChange(String newText) { // some action if needed return true; } public boolean onQueryTextSubmit(String query) { // get entered query value and search SearchModule.searchGoogleMap(POIMapActivity.this, gmm.googleMap, gmm.pois, searchView, query); MenuItemCompat.collapseActionView(miSearch); return true; } }; searchView.setOnQueryTextListener(queryTextListener); return super.onCreateOptionsMenu(menu); // return true; }
From source file:ch.kanti_baden.pu_marc_14b.traffictimewaste.SORT_TYPE.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu_post_list, menu); // Disable create post button if user isn't logged in if (DatabaseLink.instance.isLoggedIn()) { MenuItem menuItem = menu.findItem(R.id.action_login); menuItem.setEnabled(false);//from w w w . j a v a 2s.c o m } else { MenuItem menuItem = menu.findItem(R.id.action_create); menuItem.setEnabled(false); Drawable icon = menuItem.getIcon(); icon.mutate().setColorFilter(Color.GRAY, PorterDuff.Mode.SRC_IN); menuItem.setIcon(icon); } // 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.setOnSearchClickListener(new View.OnClickListener() { @Override public void onClick(View v) { searchView.setTranslationX(500f); searchView.setAlpha(0f); searchView.animate().translationX(0); searchView.animate().alpha(1f); } }); // Assumes current activity is the searchable activity searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); return true; }
From source file:com.andrew.apollo.ui.activities.AudioPlayerActivity.java
/** * {@inheritDoc}//from www. j a v a2 s .c o m */ @Override public boolean onCreateOptionsMenu(final Menu menu) { // Search view getSupportMenuInflater().inflate(R.menu.search, menu); // Theme the search icon mResources.setSearchIcon(menu); final SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView(); // Add voice search final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); final SearchableInfo searchableInfo = searchManager.getSearchableInfo(getComponentName()); searchView.setSearchableInfo(searchableInfo); // Perform the search 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 getSupportMenuInflater().inflate(R.menu.favorite, menu); // Shuffle all getSupportMenuInflater().inflate(R.menu.shuffle, menu); // Share, ringtone, and equalizer getSupportMenuInflater().inflate(R.menu.audio_player, menu); // Settings getSupportMenuInflater().inflate(R.menu.activity_base, menu); return true; }
From source file:com.tct.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); //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 ADD-S mStarSwitch = menu.findItem(R.id.menu_star_toggle); if (mStarSwitch != null) { mSwitch = (Switch) mStarSwitch.getActionView().findViewById(R.id.star_toggle); mSwitch.setOnCheckedChangeListener(mController); }//www. j a v a2 s. c om //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 ADD-E 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()); /// TCT: The SearchableInfo may be customized by Email, and we need checking its validation. final String authority = getContext().getString(R.string.suggestions_authority); if (info != null && authority.equals(info.getSuggestAuthority())) { mSearchWidget.setSearchableInfo(info); mSearchWidget.setOnSuggestionListener(this); } //TS: Gantao 2016-01-25 EMAIL BUGFIX-1489887 ADD-S //Set focusable false in case always show the search suggestion mSearchWidget.setFocusable(false); //TS: Gantao 2016-01-25 EMAIL BUGFIX-1489887 ADD-E mSearchWidget.setOnQueryTextListener(this); // mSearchWidget.setOnSuggestionListener(this); mSearchWidget.setIconifiedByDefault(true); } } //[FEATURE]-Add-BEGIN by CDTS.zhonghua.tuo,05/21/2014,FR 670064 mLocalSearchItem = menu.findItem(R.id.local_search); mServiceSearchItem = menu.findItem(R.id.service_search); //[FEATURE]-Add-END by CDTS.zhonghua.tuo // the menu should be displayed if the mode is known return getMode() != ViewMode.UNKNOWN; }