protected IntentHandlerDelegate createIntentHandlerDelegate() { return new IntentHandlerDelegate() { @Override public void processWebSearchIntent(String query) { Intent searchIntent = new Intent(Intent.ACTION_WEB_SEARCH); searchIntent.putExtra(SearchManager.QUERY, query); startActivity(searchIntent); } @Override public void processUrlViewIntent(String url, String referer, String headers, TabOpenType tabOpenType, String externalAppId, int tabIdToBringToFront, boolean hasUserGesture, Intent intent) { } }; }
private Intent intentForDictionary(CharSequence word) { final SettingsModel settings = new SettingsModel(this); String dictPkg = settings.getPackageName(); String action = settings.getAction(); if (dictPkg != null && dictPkg.startsWith("livio.pack.lang.") && !Intent.ACTION_SEARCH.equals(action)) { PLog.v("DictionaryOnCopyService.launchDictionary(): Livio-specific workaround for action. package=%s", dictPkg); // Livio dictionaries support colordict's action, but somehow it only brings up the app without word lookup. // So here I use Livio's default action string action = Intent.ACTION_SEARCH; } Intent intent = new Intent(action); intent.setPackage(dictPkg); intent.putExtra(SearchManager.QUERY, word); // FLAG_ACTIVITY_NO_USER_ACTION is needed to make system back button work, i.e., // after dictionary is launched, pressing back button will go back to the previous app. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); return intent; }
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.nav, menu); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); searchMenuItem = menu.findItem(R.id.action_search); searchView = (SearchView) searchMenuItem.getActionView(); searchView.setSearchableInfo(searchManager. getSearchableInfo(getComponentName())); searchView.setSubmitButtonEnabled(true); return true; }
/** * - * Returns a widget with category {@link AppWidgetProviderInfo#WIDGET_CATEGORY_SEARCHBOX} * - * provided by the same package which is set to be global search activity. * - * If widgetCategory is not supported, or no such widget is found, returns the first widget * - * provided by the package. * - */ public static AppWidgetProviderInfo get(Context context) { SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE); ComponentName searchComponent = searchManager.getGlobalSearchActivity(); if (searchComponent == null) return null; String providerPkg = searchComponent.getPackageName(); AppWidgetProviderInfo defaultWidgetForSearchPackage = null; AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); for (AppWidgetProviderInfo info : appWidgetManager.getInstalledProviders()) { if (info.provider.getPackageName().equals(providerPkg) && info.configure == null) { if ((info.widgetCategory & AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX) != 0) { return info; } else if (defaultWidgetForSearchPackage == null) { defaultWidgetForSearchPackage = info; } } } return defaultWidgetForSearchPackage; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String query = getIntent().getStringExtra(SearchManager.QUERY); if (query != null) { SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SearchSuggestionProvider.AUTHORITY, SearchSuggestionProvider.MODE); suggestions.saveRecentQuery(query, null); Intent intent = new Intent(QueryReceiverActivity.this, SearchActivity.class); intent.putExtra(Constants.INTENT_EXTRA_NAME_QUERY, query); startActivityForResultWithoutTransition(QueryReceiverActivity.this, intent); } finish(); Util.disablePendingTransition(this); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String query = getIntent().getStringExtra(SearchManager.QUERY); if (query != null) { SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SearchSuggestionProvider.AUTHORITY, SearchSuggestionProvider.MODE); suggestions.saveRecentQuery(query, null); Intent intent = new Intent(VoiceQueryReceiverActivity.this, SearchActivity.class); intent.putExtra(Constants.INTENT_EXTRA_NAME_QUERY, query); intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true); startActivityForResultWithoutTransition(VoiceQueryReceiverActivity.this, intent); } finish(); Util.disablePendingTransition(this); }
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_menu, menu); // Get the SearchView and set the searchable configuration SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.search_btn).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.setMaxWidth(Integer.MAX_VALUE); searchView.requestFocus(1); //searchView.setSubmitButtonEnabled(true); return true; }
private void updateSearchSuggestion(String query) { // cursor ContentResolver contentResolver = getApplicationContext().getContentResolver(); String contentUri = "content://" + MySearchRecentSuggestions.AUTHORITY + '/' + SearchManager.SUGGEST_URI_PATH_QUERY; Uri uri = Uri.parse(contentUri); Cursor cursor = contentResolver.query(uri, null, null, new String[]{query}, null); // searchview content if (mSearchSuggestionAdapter == null) { // create adapter mSearchSuggestionAdapter = new SearchSuggestionAdapter(MainActivity.this, cursor); // set adapter mSearchView.setSuggestionsAdapter(mSearchSuggestionAdapter); } else { // refill adapter mSearchSuggestionAdapter.refill(MainActivity.this, cursor); // set adapter mSearchView.setSuggestionsAdapter(mSearchSuggestionAdapter); } }
@Override public boolean onCreateOptionsMenu(Menu menu) { try { // inflate the menu items for use in the action bar MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu_main_actionbar, menu); // Associate searchable configuration with the SearchView SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView(); searchView.setSearchableInfo( searchManager.getSearchableInfo(getComponentName())); }catch(Exception ex){ LogHelper.e(LOG_TAG, ex.getMessage()); }finally { return super.onCreateOptionsMenu(menu); } }
private void updateSpinnerState(Cursor cursor) { Bundle extras = cursor != null ? cursor.getExtras() : null; if (DBG) { Log.d(LOG_TAG, "updateSpinnerState - extra = " + (extras != null ? extras.getBoolean(SearchManager.CURSOR_EXTRA_KEY_IN_PROGRESS) : null)); } // Check if the Cursor indicates that the query is not complete and show the spinner if (extras != null && extras.getBoolean(SearchManager.CURSOR_EXTRA_KEY_IN_PROGRESS)) { // mSearchView.getWindow().getDecorView().post(mStartSpinnerRunnable); // TODO: return; } // If cursor is null or is done, stop the spinner // mSearchView.getWindow().getDecorView().post(mStopSpinnerRunnable); // TODO: }
/** * Cache columns. */ @Override public void changeCursor(Cursor c) { if (DBG) Log.d(LOG_TAG, "changeCursor(" + c + ")"); if (mClosed) { Log.w(LOG_TAG, "Tried to change cursor after adapter was closed."); if (c != null) c.close(); return; } try { super.changeCursor(c); if (c != null) { mText1Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1); mText2Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_2); mText2UrlCol = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_2_URL); mIconName1Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_ICON_1); mIconName2Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_ICON_2); mFlagsCol = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_FLAGS); } } catch (Exception e) { Log.e(LOG_TAG, "error changing cursor and caching columns", e); } }
private MatrixCursor createMatrixCursor(Cursor cursor, int cursorOrigin) { MatrixCursor matrixCursor = new MatrixCursor(suggestionsColumnNames, cursor.getCount()); MatrixCursor.RowBuilder builder; if (cursor.moveToFirst()) { do { builder = matrixCursor.newRow(); if (cursorOrigin == RECENT_SEARCH_ORIGIN) { builder.add(FindQuickSearchAdapter.HISTORY_ROW); builder.add(cursor.getString(cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_QUERY))); } else { builder.add(FindQuickSearchAdapter.DATABASE_ROW); builder.add(cursor.getString(cursor.getColumnIndex(DbContract.FarmaciasEntity.NAME))); } } while (cursor.moveToNext()); } cursor.close(); return matrixCursor; }
protected void searchWebFor(String... keys) { StringBuilder stringBuilder = new StringBuilder(); for (String key : keys) { stringBuilder.append(key); stringBuilder.append(" "); } Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, stringBuilder.toString()); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); }
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the options menu from XML MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.options_menu, menu); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); MenuItem searchMenuItem = menu.findItem(R.id.menu_search); SearchView searchView = (SearchView) searchMenuItem.getActionView(); searchView.setSearchableInfo(searchManager. getSearchableInfo(getComponentName())); searchView.setOnQueryTextListener(this); MenuItemCompat.setOnActionExpandListener(searchMenuItem, this); return true; }
private void setUpRecyclerView() { googleTrendAdapter = new FancyTrendAdapter(this, trendItemList, Constant.DEFAULT_ROW_NUMBER, new FancyTrendAdapter.OnItemClickListener() { @Override public void onItemClick(View v, String trend, int position) { if (!mVisible) { FancyTrendActivity.this.toggle(); FancyTrendActivity.this.delayedHide(AUTO_HIDE_DELAY_MILLIS); } else { if (fancyTrendPresenter.getClickBehavior() == SPUtils.ClickBehaviorItem.googleSearch) { //TODO:Use chrome tab to implement Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, trend); startActivity(intent); } else if (fancyTrendPresenter.getClickBehavior() == SPUtils.ClickBehaviorItem.singlecountry) { new MaterialDialog.Builder(FancyTrendActivity.this) .title(R.string.choose_country) .items(R.array.trend_country_name) .itemsCallback((dialog, view, which, text) -> { String code = Constant.getCountryCode(String.valueOf(text)); fancyTrendPresenter.retrieveSingleTrend(code, position); }) .show(); } } } }); trendRecycleView.setLayoutManager(new CustomGridLayoutManager(this, Constant.DEFAULT_COLUMN_NUMBER)); trendRecycleView.setAdapter(googleTrendAdapter); trendRecycleView.setHasFixedSize(true); }
@Override public String getType(@NonNull Uri uri) { switch (sUriMatcher.match(uri)) { // The application is querying the db for its own contents. case VIDEO_WITH_CATEGORY: return VideoContract.VideoEntry.CONTENT_TYPE; case VIDEO: return VideoContract.VideoEntry.CONTENT_TYPE; // The Android TV global search is querying our app for relevant content. case SEARCH_SUGGEST: return SearchManager.SUGGEST_MIME_TYPE; case REFRESH_SHORTCUT: return SearchManager.SHORTCUT_MIME_TYPE; // We aren't sure what is being asked of us. default: throw new UnsupportedOperationException("Unknown uri: " + uri); } }
@Override public void init() { // Get the intent, verify the action and get the query Intent intent = getIntent(); if (intent.getAction().equals(Intent.ACTION_SEARCH)) { String query = intent.getStringExtra(SearchManager.QUERY); try { mModel.retrieveDataById(query, this.getBaseContext()); } catch (GarbageCollectedException e) { Toast.makeText(this.getBaseContext(), "error : try to relaunch app", Toast.LENGTH_SHORT); } } else { Log.i(this.getClass().toString(), "pas dedans"); mModel.retrieveData(this.getBaseContext()); } }
private void handleWebSearchIntent(Intent intent) { String query = intent.getStringExtra(SearchManager.QUERY); if (TextUtils.isEmpty(query)) { Log.w(TAG, "Got search intent with no query."); return; } try { String searchUri = duckDuckGoBaseUrl + URLEncoder.encode(query, "UTF-8"); Intent launchDDGSearchIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(searchUri)); launchDDGSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(launchDDGSearchIntent); } catch (UnsupportedEncodingException e) { Log.w(TAG, "Error", e); } }
private void startLocalSearch(String SearchQuery) { Bundle bundle = new Bundle(); bundle.putBoolean(ARG_IS_GLOBAL_SEARCH, false); ArrayList<Integer> bookIds = new ArrayList<>(); bookIds.add(bookId); bundle.putIntegerArrayList(SearchResultFragment.ARG_SEARCHABLE_BOOKS, bookIds); bundle.putString(SearchManager.QUERY, SearchQuery); Fragment searchResultFragment = SearchResultFragment.newInstance(bundle); getSupportFragmentManager() .beginTransaction() .replace(R.id.search_result_fragment_containerr, searchResultFragment, SEARCH_FRAGMENT_TAG) .hide(searchResultFragment) .addToBackStack(ADD_SEARCH_FRAGMENT_BACK_STACK_ENTRY) .commit() ; getSupportFragmentManager() .beginTransaction() .show(searchResultFragment) .addToBackStack(SHOW_SEARCH_FRAGMENT_BACKSTACK_ENTRY) .commit(); }
public static void startGoogleSearchActivity(View view) { final Context context = view.getContext(); final SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE); if (searchManager == null) { return; } ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); if (globalSearchActivity == null) { return; } Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setComponent(globalSearchActivity); Bundle appSearchData = new Bundle(); appSearchData.putString("source", context.getPackageName()); intent.putExtra(SearchManager.APP_DATA, appSearchData); intent.setSourceBounds(getViewBounds(view)); try { context.startActivity(intent); } catch (ActivityNotFoundException ex) { ex.printStackTrace(); } }
/** * Builds up a UriMatcher for search suggestion and shortcut refresh queries. */ private static UriMatcher buildUriMatcher() { UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH); // to get definitions... matcher.addURI(AUTHORITY, "dictionary", SEARCH_WORDS); matcher.addURI(AUTHORITY, "dictionary/#", GET_WORD); // to get suggestions... matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, SEARCH_SUGGEST); matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", SEARCH_SUGGEST); /* The following are unused in this implementation, but if we include * {@link SearchManager#SUGGEST_COLUMN_SHORTCUT_ID} as a column in our suggestions table, we * could expect to receive refresh queries when a shortcutted suggestion is displayed in * Quick Search Box, in which case, the following Uris would be provided and we * would return a cursor with a single item representing the refreshed suggestion data. */ matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_SHORTCUT, REFRESH_SHORTCUT); matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_SHORTCUT + "/*", REFRESH_SHORTCUT); return matcher; }
/** * This method is required in order to query the supported types. * It's also useful in our own query() method to determine the type of Uri received. */ @Override public String getType(Uri uri) { switch (sURIMatcher.match(uri)) { case SEARCH_WORDS: return WORDS_MIME_TYPE; case GET_WORD: return DEFINITION_MIME_TYPE; case SEARCH_SUGGEST: return SearchManager.SUGGEST_MIME_TYPE; case REFRESH_SHORTCUT: return SearchManager.SHORTCUT_MIME_TYPE; default: throw new IllegalArgumentException("Unknown URL " + uri); } }
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.list_menu, menu); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setOnCloseListener(() -> { postOnResumeEvents.onNext(new GetPaginatedUsersEvent(viewState == null ? -1 : viewState.getLastId())); return false; }); eventObservable = eventObservable.mergeWith(RxSearchView.queryTextChanges(searchView) .filter(charSequence -> !charSequence.toString().isEmpty()) .map(query -> new SearchUsersEvent(query.toString())) .throttleLast(100, TimeUnit.MILLISECONDS) .debounce(200, TimeUnit.MILLISECONDS) .doOnEach(searchUsersEvent -> Log.d("SearchEvent", FIRED))); return super.onCreateOptionsMenu(menu); }
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); menu.add(0, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper) .setIcon(android.R.drawable.ic_menu_gallery) .setAlphabeticShortcut('W'); menu.add(0, MENU_SEARCH, 0, R.string.menu_search) .setIcon(android.R.drawable.ic_search_category_default) .setAlphabeticShortcut(SearchManager.MENU_KEY); menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings) .setIcon(android.R.drawable.ic_menu_preferences) .setIntent(new Intent(android.provider.Settings.ACTION_SETTINGS)); return true; }
/** * Returns a widget with category {@link AppWidgetProviderInfo#WIDGET_CATEGORY_SEARCHBOX} * provided by the same package which is set to be global search activity. * If widgetCategory is not supported, or no such widget is found, returns the first widget * provided by the package. */ public static AppWidgetProviderInfo getSearchWidgetProvider(Context context) { SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE); ComponentName searchComponent = searchManager.getGlobalSearchActivity(); if (searchComponent == null) return null; String providerPkg = searchComponent.getPackageName(); AppWidgetProviderInfo defaultWidgetForSearchPackage = null; AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); for (AppWidgetProviderInfo info : appWidgetManager.getInstalledProviders()) { if (info.provider.getPackageName().equals(providerPkg) && info.configure == null) { if ((info.widgetCategory & AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX) != 0) { return info; } else if (defaultWidgetForSearchPackage == null) { defaultWidgetForSearchPackage = info; } } } return defaultWidgetForSearchPackage; }
@Override public boolean onCreateOptionsMenu(final Menu menu) { MenuItem item = menu.add(R.string.search); if (ThemeManager.getInstance().isLightBackground()) item.setIcon(R.drawable.ic_search_black_24dp); else item.setIcon(R.drawable.ic_search_white_24dp); MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); searchView = new CustomSearchView(this); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setIconifiedByDefault(true); MenuItemCompat.setActionView(item, searchView); return true; }
private void handleIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); //use the query to search your data somehow // transactionHelper.getCurrent(). Snackbar.make(drawer, "Hello " + query, Snackbar.LENGTH_SHORT).show(); } }
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); if (searchManager != null && searchView != null) { searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setOnQueryTextListener(this); } return true; }
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_activity_home, menu); //init search in the toolbar SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); //listener for click in search button searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { startActivity(new Intent(HomeActivity.this, SearchActivity.class) .putExtra(AppConstants.General.SEARCH_TEXT, query)); return true; } @Override public boolean onQueryTextChange(String newText) { return false; } }); return true; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_searchable); Toolbar toolbar = findViewById(R.id.mainPageToolBar); setSupportActionBar(toolbar); if(getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setTitle("Search Results"); } mRecyclerView = findViewById(R.id.search_recyclerView); // use this setting to improve performance if you know that changes // in content do not change the layout size of the RecyclerView mRecyclerView.setHasFixedSize(true); // use a linear layout manager mLayoutManager = new LinearLayoutManager(this); mRecyclerView.setLayoutManager(mLayoutManager); // specify an adapter (see also next example) FirebaseApp.initializeApp(this); mFireBaseDatabase = FirebaseDatabase.getInstance(); mFirebaseAuth = FirebaseAuth.getInstance(); Intent intent = getIntent(); if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); doMySearch(query); } }
@Override public void bindView(View view, Context context, Cursor cursor) { // reference LinearLayout root = (LinearLayout) view; TextView titleTextView = (TextView) root.findViewById(R.id.search_suggestion_item_title); // content final int index = cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1); titleTextView.setText(cursor.getString(index)); }
@Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); query = getIntent().getStringExtra(SearchManager.QUERY); Intent intent = new Intent(this, ItemsActivity.class); intent.putExtra("searchKeyword", query); startActivity(intent); finish(); }
/** * Constructs an intent from the given information and the search dialog state. * * @param action Intent action. * @param data Intent data, or <code>null</code>. * @param extraData Data for {@link SearchManager#EXTRA_DATA_KEY} or <code>null</code>. * @param query Intent query, or <code>null</code>. * @param actionKey The key code of the action key that was pressed, * or {@link KeyEvent#KEYCODE_UNKNOWN} if none. * @param actionMsg The message for the action key that was pressed, * or <code>null</code> if none. * @return The intent. */ private Intent createIntent(String action, Uri data, String extraData, String query, int actionKey, String actionMsg) { // Now build the Intent Intent intent = new Intent(action); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // We need CLEAR_TOP to avoid reusing an old task that has other activities // on top of the one we want. We don't want to do this in in-app search though, // as it can be destructive to the activity stack. if (data != null) { intent.setData(data); } intent.putExtra(SearchManager.USER_QUERY, mUserQuery); if (query != null) { intent.putExtra(SearchManager.QUERY, query); } if (extraData != null) { intent.putExtra(SearchManager.EXTRA_DATA_KEY, extraData); } if (mAppSearchData != null) { intent.putExtra(SearchManager.APP_DATA, mAppSearchData); } if (actionKey != KeyEvent.KEYCODE_UNKNOWN) { intent.putExtra(SearchManager.ACTION_KEY, actionKey); intent.putExtra(SearchManager.ACTION_MSG, actionMsg); } intent.setComponent(mSearchable.getSearchActivity()); return intent; }
/** * When a particular suggestion has been selected, perform the various lookups required * to use the suggestion. This includes checking the cursor for suggestion-specific data, * and/or falling back to the XML for defaults; It also creates REST style Uri data when * the suggestion includes a data id. * * @param c The suggestions cursor, moved to the row of the user's selection * @param actionKey The key code of the action key that was pressed, * or {@link KeyEvent#KEYCODE_UNKNOWN} if none. * @param actionMsg The message for the action key that was pressed, * or <code>null</code> if none. * @return An intent for the suggestion at the cursor's position. */ private Intent createIntentFromSuggestion(Cursor c, int actionKey, String actionMsg) { try { // use specific action if supplied, or default action if supplied, or fixed default String action = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_ACTION); if (action == null) { action = mSearchable.getSuggestIntentAction(); } if (action == null) { action = Intent.ACTION_SEARCH; } // use specific data if supplied, or default data if supplied String data = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA); if (data == null) { data = mSearchable.getSuggestIntentData(); } // then, if an ID was provided, append it. if (data != null) { String id = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID); if (id != null) { data = data + "/" + Uri.encode(id); } } Uri dataUri = (data == null) ? null : Uri.parse(data); String query = getColumnString(c, SearchManager.SUGGEST_COLUMN_QUERY); String extraData = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA); return createIntent(action, dataUri, extraData, query, actionKey, actionMsg); } catch (RuntimeException e ) { int rowNum; try { // be really paranoid now rowNum = c.getPosition(); } catch (RuntimeException e2 ) { rowNum = -1; } Log.w(LOG_TAG, "Search suggestions cursor at row " + rowNum + " returned exception.", e); return null; } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); IntentFilter filter = new IntentFilter(Launcher.ACTION_APPWIDGET_HOST_RESET); filter.addAction(SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED); getActivity().registerReceiver(mRebindReceiver, filter); }
/** * Gets the text to show in the query field when a suggestion is selected. * * @param cursor The Cursor to read the suggestion data from. The Cursor should already * be moved to the suggestion that is to be read from. * @return The text to show, or <code>null</code> if the query should not be * changed when selecting this suggestion. */ @Override public CharSequence convertToString(Cursor cursor) { if (cursor == null) { return null; } String query = getColumnString(cursor, SearchManager.SUGGEST_COLUMN_QUERY); if (query != null) { return query; } return null; }
private static UriMatcher buildUriMatcher() { UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH); matcher.addURI(AUTHORITY, "quran/search", SEARCH_VERSES); matcher.addURI(AUTHORITY, "quran/search/*", SEARCH_VERSES); matcher.addURI(AUTHORITY, "quran/search/*/*", SEARCH_VERSES); matcher.addURI(AUTHORITY, "quran/verse/#/#", GET_VERSE); matcher.addURI(AUTHORITY, "quran/verse/*/#/#", GET_VERSE); matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, SEARCH_SUGGEST); matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", SEARCH_SUGGEST); return matcher; }
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); final SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search)); SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); return true; }