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.weebly.opus1269.copyeverywhere.ui.main.MainActivity.java
/** * Initialize the {@link android.support.v7.view.menu.ActionMenuItemView} for search *//* w w w . j a v a2s . c om*/ private void setupSearch() { final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); final MenuItem searchItem = mMenu.findItem(R.id.action_search); final SearchView searchView = (SearchView) searchItem.getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setOnQueryTextListener(this); if (!TextUtils.isEmpty(mQueryString)) { // http://stackoverflow.com/a/32397014/4468645 searchView.post(new Runnable() { @Override public void run() { MenuItemCompat.expandActionView(searchItem); searchView.setQuery(mQueryString, true); } }); } }
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;/*ww w . j ava 2 s.co m*/ } 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:net.mypapit.mobile.myrepeater.RepeaterListActivity.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.display_map, menu); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { 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.setQueryHint("part of repeater callsign"); SearchView.OnQueryTextListener textChangeListener = new SearchView.OnQueryTextListener() { @Override/* w w w . j a v a2s .co m*/ public boolean onQueryTextSubmit(String searchText) { adapter.getFilter().filter(searchText); Log.d("MYRepeater", "search: " + searchText); adapter.notifyDataSetChanged(); return true; } @Override public boolean onQueryTextChange(String searchText) { // TODO Auto-generated method stub adapter.getFilter().filter(searchText); adapter.notifyDataSetChanged(); return true; } }; searchView.setOnQueryTextListener(textChangeListener); } return super.onCreateOptionsMenu(menu); }
From source file:gc.david.dfm.ui.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { Mint.leaveBreadcrumb("MainActivity::onCreateOptionsMenu"); // Inflate the options menu from XML final MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main, menu); // Expandir el EditText de la bsqueda a lo largo del ActionBar searchMenuItem = menu.findItem(R.id.action_search); final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem); // Configure the search info and add any event listeners 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); // Muestra el item de men de cargar si hay elementos en la BD final MenuItem loadItem = menu.findItem(R.id.action_load); // TODO hacerlo en segundo plano final List<Distance> allDistances = getApplicationDaoSession().loadAll(Distance.class); if (allDistances.size() == 0) { loadItem.setVisible(false);// www .j a v a2s. c om } return super.onCreateOptionsMenu(menu); }
From source file:com.cypress.cysmart.CommonFragments.ProfileScanningFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.clear();/*from w w w. jav a 2 s . c o m*/ inflater.inflate(R.menu.global, menu); MenuItem item = menu.findItem(R.id.graph); MenuItem log = menu.findItem(R.id.log); final MenuItem searchMenuItem = menu.findItem(R.id.search); item.setVisible(false); log.setVisible(true); SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); final SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName())); searchView.setIconifiedByDefault(false); SearchView.OnQueryTextListener textChangeListener = new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextChange(String newText) { // this is your adapter that will be filtered return true; } @Override public boolean onQueryTextSubmit(String query) { if (searchMenuItem != null) { searchMenuItem.collapseActionView(); // this is your adapter that will be filtered if (mLeDeviceListAdapter != null) { searchEnabled = true; searchDeviceList(query); } } return false; } }; searchView.setOnQueryTextListener(textChangeListener); searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean queryTextFocused) { if (!queryTextFocused) { searchMenuItem.collapseActionView(); searchView.setQuery("", false); } } }); super.onCreateOptionsMenu(menu, inflater); }
From source file:com.android.music.MusicBrowserActivity.java
/** * M: init search button, set on click listener and search dialog on dismiss * listener, disable search button/*from w w w.j a v a 2s .c om*/ * when search dialog has shown and enable it after dismiss search dialog. */ private void initSearchButton() { mSearchButton = (ImageButton) findViewById(R.id.search_menu_nowplaying); final View blankView = this.findViewById(R.id.blank_between_search_and_overflow); final View nowPlayingView = this.findViewById(R.id.nowplaying); if (mSearchButton != null) { mSearchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mOverflowMenuButton != null) { mOverflowMenuButton.setEnabled(false); } mSearchButton.setVisibility(View.GONE); onSearchRequested(); if (blankView.getVisibility() == View.VISIBLE) { blankView.setVisibility(View.GONE); } mSearchViewShowing = true; } }); SearchManager searchManager = (SearchManager) this.getSystemService(Context.SEARCH_SERVICE); searchManager.setOnDismissListener(new SearchManager.OnDismissListener() { @Override public void onDismiss() { if (mOverflowMenuButton != null) { mOverflowMenuButton.setEnabled(true); } mSearchButton.setVisibility(View.VISIBLE); if (nowPlayingView.getVisibility() != View.VISIBLE && !mHasMenukey) { blankView.setVisibility(View.VISIBLE); } mSearchViewShowing = false; InputMethodManager imm = (InputMethodManager) getApplicationContext() .getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { MusicLogUtils.d(TAG, "IIME getService failed"); } MusicLogUtils.d(TAG, "IME getService success"); if (imm != null) { MusicLogUtils.d(TAG, "Search Dialog hiding the IME"); imm.hideSoftInputFromWindow(mSearchButton.getWindowToken(), 0); } MusicLogUtils.d(TAG, "Search dialog on dismiss, enalbe search button"); } }); } }
From source file:com.cognizant.trumobi.PersonaLauncher.java
@Override protected void onResume() { PersonaLog.d("PersonaLauncher", "onResume of PersonaLauncher"); super.onResume(); if (shouldRestart()) return;/* ww w. ja v a 2 s . c om*/ //Badge updateBadgeCounts(); // ADW: Use custom settings to set the rotation /* * this.setRequestedOrientation( * PersonaAlmostNexusSettingsHelper.getDesktopRotation(this)? * ActivityInfo.SCREEN_ORIENTATION_USER * :ActivityInfo.SCREEN_ORIENTATION_NOSENSOR ); */ // ADW: Use custom settings to change number of columns (and rows for // SlidingGrid) depending on phone rotation int orientation = getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_PORTRAIT) { mAllAppsGrid.setNumColumns(PersonaAlmostNexusSettingsHelper.getColumnsPortrait(PersonaLauncher.this)); mAllAppsGrid.setNumRows(PersonaAlmostNexusSettingsHelper.getRowsPortrait(PersonaLauncher.this)); mAllAppsGrid.setPageHorizontalMargin( PersonaAlmostNexusSettingsHelper.getPageHorizontalMargin(PersonaLauncher.this)); } else { mAllAppsGrid.setNumColumns(PersonaAlmostNexusSettingsHelper.getColumnsLandscape(PersonaLauncher.this)); mAllAppsGrid.setNumRows(PersonaAlmostNexusSettingsHelper.getRowsLandscape(PersonaLauncher.this)); } // mWorkspace.setWallpaper(false); if (mRestoring) { startLoaders(); } // If this was a new intent (i.e., the mIsNewIntent flag got set to true // by // onNewIntent), then close the search dialog if needed, because it // probably // came from the user pressing 'home' (rather than, for example, // pressing 'back'). if (mIsNewIntent) { // Post to a handler so that this happens after the search dialog // tries to open // itself again. mWorkspace.post(new Runnable() { public void run() { // ADW: changed from using ISearchManager to use // SearchManager (thanks to PersonaLauncher+ source code) SearchManager searchManagerService = (SearchManager) PersonaLauncher.this .getSystemService(Context.SEARCH_SERVICE); try { searchManagerService.stopSearch(); } catch (Exception e) { PersonaLog.e(LOG_TAG, "error stopping search", e); } } }); } mIsNewIntent = false; }
From source file:com.vishwa.pinit.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_action_bar, menu); mMenu = menu;//from w ww. j a v a 2 s .c o m mSearchMenuItem = menu.findItem(R.id.action_search); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); mSearchView = (SearchView) mSearchMenuItem.getActionView(); mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); mSearchView.setQueryHint("Search for locations..."); mSearchView.setOnSuggestionListener(new OnSuggestionListener() { @Override public boolean onSuggestionSelect(int position) { return false; } @Override public boolean onSuggestionClick(int position) { CursorAdapter adapter = mSearchView.getSuggestionsAdapter(); Cursor cursor = adapter.getCursor(); if (cursor != null) { if (cursor.moveToPosition(position)) { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0); mSearchMenuItem.collapseActionView(); String geolocation = cursor .getString(cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID)); if (geolocation != null && !geolocation.isEmpty()) { double latitude = Double.parseDouble(geolocation.split(",")[0]); double longitude = Double.parseDouble(geolocation.split(",")[1]); LatLng geopoint = new LatLng(latitude, longitude); mMap.animateCamera( CameraUpdateFactory.newCameraPosition(new CameraPosition(geopoint, 17, 0, 0))); } } } return true; } }); mSearchView.setOnQueryTextListener(new OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { CursorAdapter adapter = mSearchView.getSuggestionsAdapter(); Cursor cursor = adapter.getCursor(); if (cursor != null) { if (cursor.moveToFirst()) { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0); mSearchMenuItem.collapseActionView(); String geolocation = cursor .getString(cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID)); if (geolocation != null && !geolocation.isEmpty()) { double latitude = Double.parseDouble(geolocation.split(",")[0]); double longitude = Double.parseDouble(geolocation.split(",")[1]); LatLng geopoint = new LatLng(latitude, longitude); mMap.animateCamera( CameraUpdateFactory.newCameraPosition(new CameraPosition(geopoint, 17, 0, 0))); } } } return true; } @Override public boolean onQueryTextChange(String newText) { return false; } }); if (!mHasInternet) { hideNonRefreshMenuItems(); } else { showNonRefreshMenuItems(); } return true; }
From source file:com.nadmm.airports.ActivityBase.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.mainmenu, menu); MenuItem settingsItem = menu.findItem(R.id.menu_settings); settingsItem.setVisible(getSelfNavDrawerItem() == NAVDRAWER_ITEM_INVALID); MenuItem searchItem = menu.findItem(R.id.menu_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setIconifiedByDefault(false); return super.onCreateOptionsMenu(menu); }
From source file:com.lgallardo.youtorrentcontroller.RefreshListener.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.main, menu); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); if (searchView != null) { searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default }//from ww w .j a v a 2s. c o m return true; }