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.daiv.android.twitter.ui.drawer_activities.DrawerActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_activity, menu); // Get the SearchView and set the searchable configuration SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); try {/*w w w . ja v a 2 s .c o m*/ searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView(); // Assumes current activity is the searchable activity searchView.setIconifiedByDefault(true); // Do not iconify the widget; expand it by default int searchImgId = getResources().getIdentifier("android:id/search_button", null, null); ImageView view = (ImageView) searchView.findViewById(searchImgId); view.setImageResource(settings.theme == AppSettings.THEME_LIGHT ? R.drawable.ic_action_search_light : R.drawable.ic_action_search_dark); } catch (Exception e) { } try { Field searchField = SearchView.class.getDeclaredField("mCloseButton"); searchField.setAccessible(true); closeBtn = (ImageView) searchField.get(searchView); int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null); EditText searchPlate = (EditText) searchView.findViewById(searchPlateId); searchPlate.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean b) { if (!b) { closeBtn.callOnClick(); } } }); } catch (Exception e) { } return super.onCreateOptionsMenu(menu); }
From source file:org.totschnig.myexpenses.fragment.CategoryList.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { ManageCategories ctx = (ManageCategories) getActivity(); if (ctx == null) return;// ww w .j a v a 2 s . c om if (!ctx.helpVariant.equals(ManageCategories.HelpVariant.distribution)) { inflater.inflate(R.menu.search, menu); SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); MenuItem searchMenuItem = menu.findItem(R.id.search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem); searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName())); //searchView.setIconifiedByDefault(true); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { if (TextUtils.isEmpty(newText)) { mFilter = ""; mImportButton.setVisibility(View.VISIBLE); } else { mFilter = Utils.esacapeSqlLikeExpression(Utils.normalize(newText)); // if a filter results in an empty list, // we do not want to show the setup default categories button mImportButton.setVisibility(View.GONE); } collapseAll(); mManager.restartLoader(SORTABLE_CURSOR, null, CategoryList.this); return true; } }); } }
From source file:com.klinker.android.twitter.activities.drawer_activities.DrawerActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_activity, menu); // Get the SearchView and set the searchable configuration SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); try {/*from www. j av a 2 s . c o m*/ searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView(); // Assumes current activity is the searchable activity searchView .setSearchableInfo(searchManager.getSearchableInfo(new ComponentName(this, SearchPager.class))); searchView.setIconifiedByDefault(true); // Do not iconify the widget; expand it by default int searchImgId = getResources().getIdentifier("android:id/search_button", null, null); ImageView view = (ImageView) searchView.findViewById(searchImgId); view.setImageResource(settings.theme == AppSettings.THEME_LIGHT ? R.drawable.ic_action_search_light : R.drawable.ic_action_search_dark); } catch (Exception e) { } try { Field searchField = SearchView.class.getDeclaredField("mCloseButton"); searchField.setAccessible(true); closeBtn = (ImageView) searchField.get(searchView); int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null); EditText searchPlate = (EditText) searchView.findViewById(searchPlateId); searchPlate.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean b) { if (!b) { closeBtn.callOnClick(); } } }); } catch (Exception e) { } return super.onCreateOptionsMenu(menu); }
From source file:com.android.launcher2.Launcher.java
/** * Starts the global search activity. This code is a copied from SearchManager */// w w w. j a v a 2s . c o m public void startGlobalSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); if (globalSearchActivity == null) { Log.w(TAG, "No global search activity found."); return; } Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setComponent(globalSearchActivity); // Make sure that we have a Bundle to put source in if (appSearchData == null) { appSearchData = new Bundle(); } else { appSearchData = new Bundle(appSearchData); } // Set source to package name of app that starts global search, if not set already. if (!appSearchData.containsKey("source")) { appSearchData.putString("source", getPackageName()); } intent.putExtra(SearchManager.APP_DATA, appSearchData); if (!TextUtils.isEmpty(initialQuery)) { intent.putExtra(SearchManager.QUERY, initialQuery); } if (selectInitialQuery) { intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery); } intent.setSourceBounds(sourceBounds); try { startActivity(intent); } catch (ActivityNotFoundException ex) { Log.e(TAG, "Global search activity not found: " + globalSearchActivity); } }
From source file:com.android.soma.Launcher.java
/** * Starts the global search activity. This code is a copied from SearchManager *///from w w w. j av a 2 s. com private void startGlobalSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); if (globalSearchActivity == null) { Log.w(TAG, "No global search activity found."); return; } Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setComponent(globalSearchActivity); // Make sure that we have a Bundle to put source in if (appSearchData == null) { appSearchData = new Bundle(); } else { appSearchData = new Bundle(appSearchData); } // Set source to package name of app that starts global search, if not set already. if (!appSearchData.containsKey("source")) { appSearchData.putString("source", getPackageName()); } intent.putExtra(SearchManager.APP_DATA, appSearchData); if (!TextUtils.isEmpty(initialQuery)) { intent.putExtra(SearchManager.QUERY, initialQuery); } if (selectInitialQuery) { intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery); } intent.setSourceBounds(sourceBounds); try { startActivity(intent); } catch (ActivityNotFoundException ex) { Log.e(TAG, "Global search activity not found: " + globalSearchActivity); } }
From source file:com.android.launcher2.Launcher.java
/** * Event handler for the voice button/*w ww . j av a 2 s. co m*/ * * @param v The view that was clicked. */ public void onClickVoiceButton(View v) { v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); try { final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); ComponentName activityName = searchManager.getGlobalSearchActivity(); Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (activityName != null) { intent.setPackage(activityName.getPackageName()); } startActivity(null, intent, "onClickVoiceButton"); } catch (ActivityNotFoundException e) { Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivitySafely(null, intent, "onClickVoiceButton"); } }
From source file:com.klinker.android.launcher.launcher3.Launcher.java
/** * Starts the global search activity. This code is a copied from SearchManager *///from w ww .j a v a2 s. co m private void startGlobalSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); if (globalSearchActivity == null) { Log.w(TAG, "No global search activity found."); return; } Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setComponent(globalSearchActivity); // Make sure that we have a Bundle to put source in if (appSearchData == null) { appSearchData = new Bundle(); } else { appSearchData = new Bundle(appSearchData); } // Set source to package name of app that starts global search if not set already. if (!appSearchData.containsKey("source")) { appSearchData.putString("source", getPackageName()); } intent.putExtra(SearchManager.APP_DATA, appSearchData); if (!TextUtils.isEmpty(initialQuery)) { intent.putExtra(SearchManager.QUERY, initialQuery); } if (selectInitialQuery) { intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery); } intent.setSourceBounds(sourceBounds); try { startActivity(intent); } catch (ActivityNotFoundException ex) { Log.e(TAG, "Global search activity not found: " + globalSearchActivity); } }
From source file:com.android.launcher3.Launcher.java
/** * Starts the global search activity. This code is a copied from SearchManager */// w w w. java 2s. c om public void startGlobalSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); if (globalSearchActivity == null) { Log.w(TAG, "No global search activity found."); return; } Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setComponent(globalSearchActivity); // Make sure that we have a Bundle to put source in if (appSearchData == null) { appSearchData = new Bundle(); } else { appSearchData = new Bundle(appSearchData); } // Set source to package name of app that starts global search if not set already. if (!appSearchData.containsKey("source")) { appSearchData.putString("source", getPackageName()); } intent.putExtra(SearchManager.APP_DATA, appSearchData); if (!TextUtils.isEmpty(initialQuery)) { intent.putExtra(SearchManager.QUERY, initialQuery); } if (selectInitialQuery) { intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery); } intent.setSourceBounds(sourceBounds); try { startActivity(intent); } catch (ActivityNotFoundException ex) { Log.e(TAG, "Global search activity not found: " + globalSearchActivity); } }
From source file:com.android.soma.Launcher.java
public void startVoice() { try {/*from www.j ava2 s .c o m*/ final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); ComponentName activityName = searchManager.getGlobalSearchActivity(); Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (activityName != null) { intent.setPackage(activityName.getPackageName()); } startActivity(null, intent, "onClickVoiceButton"); } catch (ActivityNotFoundException e) { Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivitySafely(null, intent, "onClickVoiceButton"); } }
From source file:com.android.launcher2.Launcher.java
private boolean updateGlobalSearchIcon() { final View searchButtonContainer = findViewById(R.id.search_button_container); final ImageView searchButton = (ImageView) findViewById(R.id.search_button); final View voiceButtonContainer = findViewById(R.id.voice_button_container); final View voiceButton = findViewById(R.id.voice_button); final View voiceButtonProxy = findViewById(R.id.voice_button_proxy); final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); ComponentName activityName = searchManager.getGlobalSearchActivity(); if (activityName != null) { int coi = getCurrentOrientationIndexForGlobalIcons(); sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo, TOOLBAR_SEARCH_ICON_METADATA_NAME); if (sGlobalSearchIcon[coi] == null) { sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo, TOOLBAR_ICON_METADATA_NAME); }/*w ww .j a v a 2s . c o m*/ if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE); searchButton.setVisibility(View.VISIBLE); invalidatePressedFocusedStates(searchButtonContainer, searchButton); return true; } else { // We disable both search and voice search when there is no global search provider if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE); if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE); searchButton.setVisibility(View.GONE); voiceButton.setVisibility(View.GONE); if (voiceButtonProxy != null) { voiceButtonProxy.setVisibility(View.GONE); } return false; } }