List of usage examples for android.app SearchManager getSearchableInfo
public SearchableInfo getSearchableInfo(ComponentName componentName)
From source file:com.cuddlesoft.nori.SearchActivity.java
/** * Set up the action bar SearchView and its event handlers. * * @param menu Menu after being inflated in {@link #onCreateOptionsMenu(android.view.Menu)}. */// w w w. j ava2 s .co m private void setUpSearchView(Menu menu) { // Extract SearchView from the MenuItem object. searchMenuItem = menu.findItem(R.id.action_search); searchMenuItem.setVisible(searchClientSettings != null); searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem); // Set Searchable XML configuration. SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); // Set SearchView attributes. searchView.setFocusable(false); searchView.setQueryRefinementEnabled(true); // Set SearchView event listeners. searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { if (searchClientSettings != null) { // Prepare a intent to send to a new instance of this activity. Intent intent = new Intent(SearchActivity.this, SearchActivity.class); intent.setAction(Intent.ACTION_SEARCH); intent.putExtra(BUNDLE_ID_SEARCH_CLIENT_SETTINGS, searchClientSettings); intent.putExtra(BUNDLE_ID_SEARCH_QUERY, query); // Collapse the ActionView. This makes navigating through previous results using the back key less painful. MenuItemCompat.collapseActionView(searchMenuItem); // Start a new activity with the created Intent. startActivity(intent); } // Returns true to override the default behaviour and stop another search Intent from being sent. return true; } @Override public boolean onQueryTextChange(String newText) { // Returns false to perform the default action. return false; } }); searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() { @Override public boolean onSuggestionSelect(int position) { return onSuggestionClick(position); } @Override public boolean onSuggestionClick(int position) { if (searchClientSettings != null) { // Get the SearchView's suggestion adapter. CursorAdapter adapter = searchView.getSuggestionsAdapter(); // Get the suggestion at given position. Cursor c = adapter.getCursor(); c.moveToPosition(position); // Create and send a search intent. Intent intent = new Intent(SearchActivity.this, SearchActivity.class); intent.setAction(Intent.ACTION_SEARCH); intent.putExtra(BUNDLE_ID_SEARCH_CLIENT_SETTINGS, searchClientSettings); intent.putExtra(BUNDLE_ID_SEARCH_QUERY, c.getString(c.getColumnIndex(SearchSuggestionDatabase.COLUMN_NAME))); startActivity(intent); // Release native resources. c.close(); } // Return true to override default behaviour and prevent another intent from being sent. return true; } }); if (savedInstanceState != null) { // Restore state from saved instance state bundle (after screen rotation, app restored from background, etc.) if (savedInstanceState.containsKey(BUNDLE_ID_SEARCH_QUERY)) { // Restore search query from saved instance state. searchView.setQuery(savedInstanceState.getCharSequence(BUNDLE_ID_SEARCH_QUERY), false); } // Restore iconified/expanded search view state from saved instance state. if (savedInstanceState.getBoolean(BUNDLE_ID_SEARCH_VIEW_IS_EXPANDED, false)) { MenuItemCompat.expandActionView(searchMenuItem); // Restore focus state. if (!savedInstanceState.getBoolean(BUNDLE_ID_SEARCH_VIEW_IS_FOCUSED, false)) { searchView.clearFocus(); } } } else if (getIntent() != null && getIntent().getAction().equals(Intent.ACTION_SEARCH)) { // Set SearchView query string to match the one sent in the SearchIntent. searchView.setQuery(getIntent().getStringExtra(BUNDLE_ID_SEARCH_QUERY), false); } }
From source file:inc.bait.jubilee.ui.fragments.ContactsListFragment.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override/* w w w .j a v a 2s . com*/ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.contact_list_menu, menu); MenuItem searchItem = menu.findItem(R.id.menu_search); if (isSearchResultView) { searchItem.setVisible(false); } if (ApiHelper.hasHoneycomb()) { final SearchManager searchManager = (SearchManager) getActivity() .getSystemService(Context.SEARCH_SERVICE); final SearchView searchView = (SearchView) searchItem.getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName())); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String queryText) { return true; } @Override public boolean onQueryTextChange(String newText) { String newFilter = !TextUtils.isEmpty(newText) ? newText : null; if (searchString == null && newFilter == null) { return true; } if (searchString != null && searchString.equals(newFilter)) { return true; } searchString = newFilter; mSearchQueryChanged = true; getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this); return true; } }); if (ApiHelper.hasICS()) { searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(MenuItem menuItem) { return true; } @Override public boolean onMenuItemActionCollapse(MenuItem menuItem) { if (!TextUtils.isEmpty(searchString)) { onSelectionCleared(); } searchString = null; getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this); return true; } }); } if (searchString != null) { final String savedSearchTerm = searchString; // Expands the search menu item if (ApiHelper.hasICS()) { searchItem.expandActionView(); } searchView.setQuery(savedSearchTerm, false); } } }
From source file:uk.ac.hutton.ics.buntata.activity.NodeCatalogActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { /* Inflate the menu */ MenuInflater menuInflater = getMenuInflater(); menuInflater.inflate(R.menu.node_list_menu, menu); /* Find the search menu item */ final MenuItem searchItem = menu.findItem(R.id.action_search); /* Get the search manager */ SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); /* Get the actual search view */ final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); if (searchView != null) { DisplayMetrics displayMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); searchView.setMaxWidth(displayMetrics.widthPixels / 2); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setQueryHint(getString(R.string.search_node_name_hint)); /* Listen to submit events */ searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override//www. j av a 2s . c o m public boolean onQueryTextSubmit(String query) { /* Trim leading and trailing spaces that some keyboards will add */ query = query.trim(); 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() { filter(""); return false; } }); } return super.onCreateOptionsMenu(menu); }
From source file:com.kiwiteam.nomiddleman.LargeGroupActivity.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.global, menu); if (conn.isLogged()) { menu.findItem(R.id.account).setVisible(true); menu.findItem(R.id.signout).setVisible(true); } else {//from w ww. j a v a 2 s . c o m menu.findItem(R.id.account).setVisible(false); menu.findItem(R.id.signout).setVisible(false); } //initSearchView(menu); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); SearchableInfo searchableInfo = searchManager.getSearchableInfo(getComponentName()); searchView.setSearchableInfo(searchableInfo); return true; }
From source file:io.github.tjg1.nori.SearchActivity.java
/** * Set up the action bar SearchView and its event handlers. * * @param menu Menu after being inflated in {@link #onCreateOptionsMenu(android.view.Menu)}. *///from ww w . j av a 2 s . c om private void setUpSearchView(Menu menu) { // Extract SearchView from the MenuItem object. searchMenuItem = menu.findItem(R.id.action_search); searchMenuItem.setVisible(searchClientSettings != null); searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem); // Set Searchable XML configuration. SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); // Set SearchView attributes. searchView.setFocusable(false); searchView.setQueryRefinementEnabled(true); // Set submit action and allow empty queries. SearchView.SearchAutoComplete searchTextView = (SearchView.SearchAutoComplete) searchView .findViewById(R.id.search_src_text); searchTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { CharSequence query = textView.getText(); if (query != null && searchClientSettings != null) { // Prepare a intent to send to a new instance of this activity. Intent intent = new Intent(SearchActivity.this, SearchActivity.class); intent.setAction(Intent.ACTION_SEARCH); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(BUNDLE_ID_SEARCH_CLIENT_SETTINGS, searchClientSettings); intent.putExtra(BUNDLE_ID_SEARCH_QUERY, query.toString()); // Collapse the ActionView. This makes navigating through previous results using the back key less painful. MenuItemCompat.collapseActionView(searchMenuItem); // Start a new activity with the created Intent. startActivity(intent); } // Returns true to override the default behaviour and stop another search Intent from being sent. return true; } }); searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() { @Override public boolean onSuggestionSelect(int position) { return onSuggestionClick(position); } @Override public boolean onSuggestionClick(int position) { if (searchClientSettings != null) { // Get the SearchView's suggestion adapter. CursorAdapter adapter = searchView.getSuggestionsAdapter(); // Get the suggestion at given position. Cursor c = adapter.getCursor(); c.moveToPosition(position); // Create and send a search intent. Intent intent = new Intent(SearchActivity.this, SearchActivity.class); intent.setAction(Intent.ACTION_SEARCH); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(BUNDLE_ID_SEARCH_CLIENT_SETTINGS, searchClientSettings); intent.putExtra(BUNDLE_ID_SEARCH_QUERY, c.getString(c.getColumnIndex(SearchSuggestionDatabase.COLUMN_NAME))); startActivity(intent); // Release native resources. c.close(); } // Return true to override default behaviour and prevent another intent from being sent. return true; } }); if (savedInstanceState != null) { // Restore state from saved instance state bundle (after screen rotation, app restored from background, etc.) if (savedInstanceState.containsKey(BUNDLE_ID_SEARCH_QUERY)) { // Restore search query from saved instance state. searchView.setQuery(savedInstanceState.getCharSequence(BUNDLE_ID_SEARCH_QUERY), false); } // Restore iconified/expanded search view state from saved instance state. if (savedInstanceState.getBoolean(BUNDLE_ID_SEARCH_VIEW_IS_EXPANDED, false)) { MenuItemCompat.expandActionView(searchMenuItem); // Restore focus state. if (!savedInstanceState.getBoolean(BUNDLE_ID_SEARCH_VIEW_IS_FOCUSED, false)) { searchView.clearFocus(); } } } else if (getIntent() != null && getIntent().getAction().equals(Intent.ACTION_SEARCH)) { // Set SearchView query string to match the one sent in the SearchIntent. searchView.setQuery(getIntent().getStringExtra(BUNDLE_ID_SEARCH_QUERY), false); } }
From source file:com.foodie.app.Activity.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.home_actions, menu); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); MenuItem searchMenuItem = menu.findItem(R.id.id_action_search); SearchView searchView = null;// w w w. jav a 2 s. co m if (searchMenuItem != null) { searchView = (SearchView) searchMenuItem.getActionView(); } if (searchView != null) { searchView.setSearchableInfo(searchManager.getSearchableInfo(MainActivity.this.getComponentName())); } SearchView.SearchAutoComplete searchAutoComplete = (SearchView.SearchAutoComplete) searchView .findViewById(android.support.v7.appcompat.R.id.search_src_text); searchAutoComplete.setHintTextColor(Color.WHITE); searchAutoComplete.setTextColor(Color.WHITE); searchAutoComplete.setHint("?,,"); //? searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { //Toast.makeText(MainActivity.this,""+query,Toast.LENGTH_SHORT).show(); Intent intent = new Intent(MainActivity.this, SearchResultsActivity.class); intent.putExtra("query", query); startActivity(intent); return true; } @Override public boolean onQueryTextChange(String newText) { //Toast.makeText(MainActivity.this,""+newText,Toast.LENGTH_SHORT).show(); return false; } }); //?? View searchplate = (View) searchView.findViewById(android.support.v7.appcompat.R.id.search_plate); //searchplate.setBackgroundResource(R.drawable.ic_search_white_24dp); ImageView searchCloseIcon = (ImageView) searchView .findViewById(android.support.v7.appcompat.R.id.search_close_btn); searchCloseIcon.setImageResource(R.drawable.ic_close_white_24dp); ImageView voiceIcon = (ImageView) searchView .findViewById(android.support.v7.appcompat.R.id.search_voice_btn); voiceIcon.setImageResource(R.drawable.ic_settings_voice_white_24dp); //searchView.setSubmitButtonEnabled(true); // to enable submit button ImageView b = (ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_button); b.setImageResource(R.drawable.ic_search_white_24dp); //to change submit button icon ImageView searchIcon = (ImageView) searchView .findViewById(android.support.v7.appcompat.R.id.search_mag_icon); searchIcon.setImageResource(R.drawable.ic_search_white_24dp); switch (currentTab) { case 0: MenuItem miMap = menu.findItem(R.id.id_action_map); miMap.setVisible(false); break; case 1: MenuItem miSearch = menu.findItem(R.id.id_action_search); miSearch.setVisible(false); break; case 2: MenuItem mi1 = menu.findItem(R.id.id_action_map); mi1.setVisible(false); MenuItem mi2 = menu.findItem(R.id.id_action_search); mi2.setVisible(false); case 3: MenuItem mi3 = menu.findItem(R.id.id_action_map); mi3.setVisible(false); MenuItem mi4 = menu.findItem(R.id.id_action_search); mi4.setVisible(false); break; default: break; } return true; }
From source file:babbq.com.searchplace.SearchActivity.java
private void setupSearchView() { SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); // hint, inputType & ime options seem to be ignored from XML! Set in code searchView.setQueryHint(getString(R.string.search_hint)); searchView.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS); searchView.setImeOptions(searchView.getImeOptions() | EditorInfo.IME_ACTION_SEARCH | EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_FLAG_NO_FULLSCREEN); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override/*from www. j a va 2 s. c o m*/ public boolean onQueryTextSubmit(String query) { searchFor(query); return true; } @Override public boolean onQueryTextChange(String query) { if (TextUtils.isEmpty(query)) { clearResults(); } return true; } }); searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus && confirmSaveContainer.getVisibility() == View.VISIBLE) { hideSaveConfimation(); } } }); }
From source file:org.amahi.anywhere.fragment.ServerFilesFragment.java
private void setUpSearchView() { SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName())); searchView.setSubmitButtonEnabled(false); searchView.setOnQueryTextListener(this); }
From source file:com.ksharkapps.musicnow.ui.activities.SearchActivity.java
/** * {@inheritDoc}/*from w w w . j a va 2 s. 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); // Filter the list the user is looking it via SearchView mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem); if (mSearchView != null) mSearchView.setOnQueryTextListener(this); // Add voice search final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); final SearchableInfo searchableInfo = searchManager.getSearchableInfo(getComponentName()); mSearchView.setSearchableInfo(searchableInfo); return super.onCreateOptionsMenu(menu); }
From source file:ru.neverdark.phototools.azimuth.PluginActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { Log.enter();/* www .j a va 2s. c om*/ getMenuInflater().inflate(R.menu.main, menu); mMenuItemSearch = menu.findItem(R.id.item_search); mMenuItemTZ = menu.findItem(R.id.item_timeZone); mMenuSave = menu.findItem(R.id.item_saveLocation); if (Constants.PAID) { SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) MenuItemCompat.getActionView(mMenuItemSearch); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setIconifiedByDefault(true); searchView.setQueryHint(getString(R.string.search_hint)); searchView.setOnQueryTextListener(new QueryTextListener()); } else { MenuItemCompat.setActionView(mMenuItemSearch, null); } return true; }