private void handleIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); //set the text on the search view without submission searchView.setQuery(query, false); searchView.clearFocus(); //save search result SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, ArtistsSearchRecentSuggestionsProvider.AUTHORITY, ArtistsSearchRecentSuggestionsProvider.MODE); suggestions.saveRecentQuery(query, null); viewModel.query(query); //use the query to search your data somehow Toast.makeText(this, query, Toast.LENGTH_SHORT).show(); } }
private void setupClearSearchPreference() { Preference clearSearchPreference = findPreference(Constants.PREFERENCES_KEY_CLEAR_SEARCH_HISTORY); if (clearSearchPreference != null) { clearSearchPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { SearchRecentSuggestions suggestions = new SearchRecentSuggestions(getActivity(), SearchSuggestionProvider.AUTHORITY, SearchSuggestionProvider.MODE); suggestions.clearHistory(); Util.toast(getActivity(), R.string.settings_search_history_cleared); return false; } }); } }
@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 void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Utils.logD(LOG_TAG, "onCreate"); mSharedPreferences = new PreferencesManagerImp(getActivity().getApplicationContext()); mLocation = mSharedPreferences.getLocation(); if (savedInstanceState != null) { mRotation = true; } LoaderProvider loaderProvider = new LoaderProvider(getContext()); LoaderManager loaderManager = getLoaderManager(); Geocoder geocoder = new Geocoder(getActivity()); // loaderManager.enableDebugLogging(true); mPresenter = new FindPresenter(mLocation, loaderManager, loaderProvider, geocoder); setHasOptionsMenu(true); mRecentSearchSuggestions = new SearchRecentSuggestions(getContext(), RecentSuggestionsProvider.AUTHORITY, RecentSuggestionsProvider.MODE); mCompositeSubscription = new CompositeSubscription(); mActivityCoordinator = (CoordinatorLayout) getActivity().findViewById(R.id.coordinator); mSnackCoordinator = (CoordinatorLayout) getActivity().findViewById(R.id.coordinatorSnackContainer); }
@Override protected void onCreate(Bundle savedInstanceState) { if (getIntent().hasExtra(SearchManager.QUERY)) { mQuery = getIntent().getStringExtra(SearchManager.QUERY); } super.onCreate(savedInstanceState); if (!TextUtils.isEmpty(mQuery)) { getSupportActionBar().setSubtitle(mQuery); SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SearchRecentSuggestionsProvider.PROVIDER_AUTHORITY, SearchRecentSuggestionsProvider.MODE) { @Override public void saveRecentQuery(String queryString, String line2) { truncateHistory(getContentResolver(), MAX_RECENT_SUGGESTIONS - 1); super.saveRecentQuery(queryString, line2); } }; suggestions.saveRecentQuery(mQuery, null); } }
@Override public void onNewIntent(Intent intent) { if (DEBUG) Log.d(TAG, "New Intent: " + intent); String action = intent.getAction(); String query = intent.getStringExtra(SearchManager.QUERY); if (intent == null) { if (DEBUG) Log.d(TAG, "No intent to search, querying default."); executeSearchTask(query); } else if (Intent.ACTION_SEARCH.equals(action) && query != null) { if (DEBUG) Log.d(TAG, "onNewIntent received search intent and saving."); SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, VenueQuerySuggestionsProvider.AUTHORITY, VenueQuerySuggestionsProvider.MODE); suggestions.saveRecentQuery(query, null); executeSearchTask(query); } else { onSearchRequested(); } }
private void search(final String q) { if (!TextUtils.isEmpty(q)) { this.q = q; SearchRecentSuggestions suggestions = new SearchRecentSuggestions(getActivity(), SearchSuggestionProvider.AUTHORITY, SearchSuggestionProvider.MODE); suggestions.saveRecentQuery(this.q, null); switch (viewPager.getCurrentItem()) { case 0: ((SearchStatusFragment) getSearchWeiboFragment()).search(); break; case 1: ((SearchUserFragment) getSearchUserFragment()).search(); break; } } }
@Override public boolean onQueryTextSubmit(String query) { //Avoid bug: this is called twice in some devices (ACTION_UP and ACTION_DOWN) long actualSearchTime = Calendar.getInstance().getTimeInMillis(); if (actualSearchTime < lastSearchTime + 1000) return true; lastSearchTime = actualSearchTime; if (TextUtils.isEmpty(query)) { mAdapter.clearAll(); } else { lastQuery = query; SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, RecentSearchProvider.AUTHORITY, RecentSearchProvider.MODE); suggestions.saveRecentQuery(query, null); mAdapter.getFilter().filter(query); } return true; }
private void sendSearchIntent () { try { Intent sendIntent = new Intent(this, Class.forName(searchableActivity)); sendIntent.setAction(Intent.ACTION_SEARCH); sendIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); sendIntent.putExtra(SearchManager.QUERY, query); // If it is set one-line mode, directly saves the suggestion in the provider if (!CustomSearchableInfo.getIsTwoLineExhibition()) { SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, providerAuthority, SearchRecentSuggestionsProvider.DATABASE_MODE_QUERIES); suggestions.saveRecentQuery(query, null); } startActivity(sendIntent); finish(); } catch (ClassNotFoundException e) { e.printStackTrace(); } }
private Cursor queryRecentSuggestionsProvider () { Uri uri = Uri.parse("content://".concat(providerAuthority.concat("/suggestions"))); String[] selection; if (CustomSearchableInfo.getIsTwoLineExhibition()) { selection = SearchRecentSuggestions.QUERIES_PROJECTION_2LINE; } else { selection = SearchRecentSuggestions.QUERIES_PROJECTION_1LINE; } String[] selectionArgs = new String[] {"%" + query + "%"}; return SearchActivity.this.getContentResolver().query( uri, selection, "display1 LIKE ?", selectionArgs, "date DESC" ); }
@Override public boolean onOptionsItemSelected(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.action_clear_history: SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, MySuggestionProvider.AUTHORITY, MySuggestionProvider.MODE); suggestions.clearHistory(); return true; case R.id.action_search: onSearchRequested(); return true; case R.id.action_about: startActivity(new Intent(this, About.class)); return true; case R.id.action_update_yp: YellowPagesLoader.getInstance(this).fetchDataAsync(); return true; } return (super.onOptionsItemSelected(menuItem)); }
private void doSearchQuery(final Intent queryIntent, final String entryPoint) { // The search query is provided as an "extra" string in the query intent final String queryString = queryIntent.getStringExtra(SearchManager.QUERY); // Record the query string in the recent queries suggestions provider. SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SearchSuggestionProvider.AUTHORITY, SearchSuggestionProvider.MODE); suggestions.saveRecentQuery(queryString, null); // Do the actual search, write to searchResults field showDialog(SEARCH_DIALOG); MapQuestGeocoder geocoder = new MapQuestGeocoder(); geocoder.geocode(queryString, null, this, MAPQUEST_KEY); }
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); setIntent(intent); if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); if (!TextUtils.isEmpty(query)) { SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SearchRecipeSuggestionsProvider.AUTHORITY, SearchRecipeSuggestionsProvider.MODE); suggestions.saveRecentQuery(query, null); } recipeListFragment.setQuery(query); } }
@Override protected Dialog onCreateDialog(int id) { switch (id) { case CONFIRM_CLEAR_SEARCH_HISTORY_DIALOG: return new AlertDialog.Builder(PreferenceSim2Activity.this) .setTitle(R.string.confirm_clear_search_title) .setMessage(R.string.confirm_clear_search_text) .setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { SearchRecentSuggestions recent = ((MmsApp) getApplication()) .getRecentSuggestions(); if (recent != null) { recent.clearHistory(); } dialog.dismiss(); } }).setNegativeButton(android.R.string.cancel, null) .setIcon(android.R.drawable.ic_dialog_alert).create(); } return super.onCreateDialog(id); }
@Override protected Dialog onCreateDialog(int id) { switch (id) { case CONFIRM_CLEAR_SEARCH_HISTORY_DIALOG: return new AlertDialog.Builder(MessagingPreferenceActivity.this) .setTitle(R.string.confirm_clear_search_title) .setMessage(R.string.confirm_clear_search_text) .setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { SearchRecentSuggestions recent = ((MmsApp) getApplication()) .getRecentSuggestions(); if (recent != null) { recent.clearHistory(); } dialog.dismiss(); } }).setNegativeButton(android.R.string.cancel, null) .setIcon(android.R.drawable.ic_dialog_alert).create(); } return super.onCreateDialog(id); }
@Override protected Dialog onCreateDialog(int id) { switch (id) { case CONFIRM_CLEAR_SEARCH_HISTORY_DIALOG: return new AlertDialog.Builder(PreferenceSim1Activity.this) .setTitle(R.string.confirm_clear_search_title) .setMessage(R.string.confirm_clear_search_text) .setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { SearchRecentSuggestions recent = ((MmsApp) getApplication()) .getRecentSuggestions(); if (recent != null) { recent.clearHistory(); } dialog.dismiss(); } }).setNegativeButton(android.R.string.cancel, null) .setIcon(android.R.drawable.ic_dialog_alert).create(); } return super.onCreateDialog(id); }
private void handleIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { viewPager.setCurrentItem(TabPagerAdapter.ANIME_TAB, true); String query = intent.getStringExtra(SearchManager.QUERY); if (menuItemSearchView != null) { MenuItemCompat.collapseActionView(menuItemSearchView); } SearchRecentSuggestions suggestions = new SearchRecentSuggestions( this, SearchFriendsProvider.AUTHORITY, SearchFriendsProvider.MODE); suggestions.saveRecentQuery(query, null); // call method that handles the search request if (RequestHelper.isNetworkAvailable(FeedTabActivity.this)) { //startFeedRequests(query); notifyFragments(query); } else { Toast.makeText(this, R.string.no_network_connection_available, Toast.LENGTH_LONG).show(); } } }
@Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { final String key = preference.getKey(); if (KEY_CLEAR_SEARCH_HISTORY.equals(key)) { SearchRecentSuggestions suggestions = new SearchRecentSuggestions( getActivity(), Utils.getSearchAuthority(getActivity()), CalendarRecentSuggestionsProvider.MODE); suggestions.clearHistory(); Toast.makeText(getActivity(), R.string.search_history_cleared, Toast.LENGTH_SHORT).show(); return true; } else { return super.onPreferenceTreeClick(preferenceScreen, preference); } }
private void search(String searchQuery, Time goToTime) { // save query in recent queries SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, Utils.getSearchAuthority(this), CalendarRecentSuggestionsProvider.MODE); suggestions.saveRecentQuery(searchQuery, null); EventInfo searchEventInfo = new EventInfo(); searchEventInfo.eventType = EventType.SEARCH; searchEventInfo.query = searchQuery; searchEventInfo.viewType = ViewType.AGENDA; if (goToTime != null) { searchEventInfo.startTime = goToTime; } mController.sendEvent(this, searchEventInfo); mQuery = searchQuery; if (mSearchView != null) { mSearchView.setQuery(mQuery, false); mSearchView.clearFocus(); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: thread = null; finish(); return true; case R.id.action_clear: SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SuggestionProvider.AUTHORITY, SuggestionProvider.MODE); suggestions.clearHistory(); return true; default: return super.onOptionsItemSelected(item); } }
@Override protected Dialog onCreateDialog(int id) { switch (id) { case CONFIRM_CLEAR_SEARCH_HISTORY_DIALOG: return new AlertDialog.Builder(MessagingPreferenceActivity.this) .setTitle(R.string.confirm_clear_search_title) .setMessage(R.string.confirm_clear_search_text) .setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { SearchRecentSuggestions recent = ((MmsApp)getApplication()).getRecentSuggestions(); if (recent != null) { recent.clearHistory(); } dialog.dismiss(); } }) .setNegativeButton(android.R.string.cancel, null) .setIconAttribute(android.R.attr.alertDialogIcon) .create(); } return super.onCreateDialog(id); }
/** * Tests if search query is valid and internet connection is available. * Then starts a new search. * * @param query Query to search for */ protected void requestSearch(String query) { mQuery = query; if (query.length() < mMinLength) { final String text = String.format(getString(R.string.min_search_len), mMinLength); Utils.showToast(this, text); return; } /*if (!Utils.isConnected(this)) { showNoInternetLayout(); return; }*/ // Add query to recents SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, mAuthority, SearchRecentSuggestionsProvider.DATABASE_MODE_QUERIES); suggestions.saveRecentQuery(query, null); // Tell activity to start searching onStartSearch(query); }
@Override protected void onClick() { // Data has changed, notify so UI can be refreshed! SearchRecentSuggestions suggestions = new SearchRecentSuggestions(getContext(), SearchSuggestions.AUTHORITY, SearchSuggestions.MODE); suggestions.clearHistory(); Toast.makeText(getContext(), R.string.onSuggestionsCleared, Toast.LENGTH_SHORT).show(); notifyChanged(); }
@Override public void onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.action_delete) { SearchRecentSuggestions recentSuggestions = new SearchRecentSuggestions(getContext(), SearchableProvider.AUTHORITY, SearchableProvider.MODE); recentSuggestions.clearHistory(); view.showToast(getContext().getString(R.string.search_history_deleted)); } }
@Override public void run() { //Se a pesquisa não retornou nada, não salva a sugestão. //Esta verificação não conflitará com outras pesquisas pois está sendo executado na Thread de UI. if (entityListAdapter.getItemCount() == 0) { return; } SearchRecentSuggestions suggestions = new SearchRecentSuggestions(getActivity(), EntitySearchSuggestionsProvider.AUTHORITY, EntitySearchSuggestionsProvider.MODE); suggestions.saveRecentQuery(query, searchEntity); }
public void newIntent(Intent intent) { setIntent(intent); // search action if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SearchSuggestions.AUTHORITY, SearchSuggestions.MODE); suggestions.saveRecentQuery(query, null); fromSearch = true; queryString = query; } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.search: this.onSearchRequested(); break; case R.id.clear_search_sug: SearchRecentSuggestions suggestions = new SearchRecentSuggestions(context, SearchSuggestions.AUTHORITY, SearchSuggestions.MODE); suggestions.clearHistory(); Toast.makeText(context, R.string.clear_search_sug_ok, Toast.LENGTH_LONG).show(); break; case R.id.save: try { PrintWriter printWriter = new PrintWriter(fileAbsolutePath); printWriter.print(text.getText()); printWriter.close(); Toast.makeText(context,getString(R.string.saved_ok), Toast.LENGTH_SHORT).show(); if (isTextChanged()) { actionbar.setTitle(title); } break; } catch(Exception e){ //Log.e(TAG,"canot read file"); break; } case R.id.close: finish(); break; } return true; }
@Override public void onNewIntent(Intent intent) { if (intent != null) { String action = intent.getAction(); String query = intent.getStringExtra(SearchManager.QUERY); Log.i(TAG, "New Intent: action[" + action + "]."); if (!TextUtils.isEmpty(action)) { if (action.equals(Intent.ACTION_CREATE_SHORTCUT)) { Log.i(TAG, " action = create shortcut, user can click one of the current venues."); } else if (action.equals(Intent.ACTION_VIEW)) { if (!TextUtils.isEmpty(query)) { Log.i(TAG, " action = view, query term provided, prepopulating search."); startSearch(query, false, null, false); } else { Log.i(TAG, " action = view, but no query term provided, doing nothing."); } } else if (action.equals(Intent.ACTION_SEARCH) && !TextUtils.isEmpty(query)) { Log.i(TAG, " action = search, query term provided, executing search immediately."); SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, VenueQuerySuggestionsProvider.AUTHORITY, VenueQuerySuggestionsProvider.MODE); suggestions.saveRecentQuery(query, null); executeSearchTask(query); } } } }
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case R.id.action_settings_logged_in: startActivity(new Intent(this, LoginActivity.class)); return true; case R.id.action_settings_logged_out: custom_signout(); break; case R.id.clearSuggestion: SearchRecentSuggestions searchRecentSuggestions = new SearchRecentSuggestions(this, SearchableProvider.AUTHORITY,SearchableProvider.MODE); searchRecentSuggestions.clearHistory(); break; case R.id.action_settings_open_userProfile: startActivity(new Intent(this, UserProfileOwner.class)); break; case R.id.action_settings_main: startActivity(new Intent(this, SettingsActivity.class)); break; } return super.onOptionsItemSelected(item); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_searchable); noSearchResults = (TextView) findViewById(R.id.noSearchResultsTV); mToolbar = (Toolbar) findViewById(R.id.search_toolbar); searchRecyclerView = (RecyclerView) findViewById(R.id.searchRecyclerView); searchRecyclerView.setLayoutManager(new LinearLayoutManager(this)); setSupportActionBar(mToolbar); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); String query; // Get the intent, verify the action and get the query Intent intent = getIntent(); if (Intent.ACTION_SEARCH.equals(intent.getAction())) { query = intent.getStringExtra(SearchManager.QUERY); getSupportActionBar().setTitle(query); feedsArrayList = readAllPostForSearch(query); if (!feedsArrayList.isEmpty()) { searchRecyclerView.setVisibility(View.VISIBLE); noSearchResults.setVisibility(View.GONE); mComplexRecyclerViewAdapter = new ComplexRecyclerViewAdapter(this, feedsArrayList); searchRecyclerView.setAdapter(mComplexRecyclerViewAdapter); mComplexRecyclerViewAdapter.setFeed(feedsArrayList); }else { searchRecyclerView.setVisibility(View.GONE); noSearchResults.setText("No results found!"); noSearchResults.setVisibility(View.VISIBLE); } // Toast.makeText(this, query, Toast.LENGTH_SHORT).show(); SearchRecentSuggestions searchRecentSuggestions = new SearchRecentSuggestions(this, SearchableProvider.AUTHORITY, SearchableProvider.MODE); searchRecentSuggestions.saveRecentQuery(query, null); } }
private void saveQuery(String query) { if (TextUtils.isEmpty(query)) { return; } SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SearchProvider.AUTHORITY, SearchProvider.MODE); suggestions.saveRecentQuery(query, null); }
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.menu_clear_recent) { mAlertDialogBuilder .init(this) .setMessage(R.string.clear_search_history_confirm) .setNegativeButton(android.R.string.cancel, null) .setPositiveButton(android.R.string.ok, (dialog, which) -> new SearchRecentSuggestions(SettingsActivity.this, SearchRecentSuggestionsProvider.PROVIDER_AUTHORITY, SearchRecentSuggestionsProvider.MODE) .clearHistory()) .create() .show(); return true; } if (item.getItemId() == R.id.menu_reset) { mAlertDialogBuilder .init(this) .setMessage(R.string.reset_settings_confirm) .setNegativeButton(android.R.string.cancel, null) .setPositiveButton(android.R.string.ok, (dialog, which) -> { Preferences.reset(SettingsActivity.this); AppUtils.restart(SettingsActivity.this, false); }) .create() .show(); } if (item.getItemId() == R.id.menu_clear_drafts) { Preferences.clearDrafts(this); return true; } return super.onOptionsItemSelected(item); }
private void handleIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SearchSuggestionProvider.AUTHORITY, SearchSuggestionProvider.MODE); suggestions.saveRecentQuery(query, null); search(query); } }
public void hendleSearch(Intent intent){ if(Intent.ACTION_SEARCH.equalsIgnoreCase(intent.getAction())){ String query = intent.getStringExtra(SearchManager.QUERY); setTitle(query); SearchRecentSuggestions searchRecentSuggestions = new SearchRecentSuggestions(this, SearchableProvider.AUTHORITY, SearchableProvider.MODE); searchRecentSuggestions.saveRecentQuery(query,null); } }