android.provider.SearchRecentSuggestions Java Examples

The following examples show how to use android.provider.SearchRecentSuggestions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SearchableActivity.java    From Androzic with GNU General Public License v3.0 6 votes vote down vote up
@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);
	}
}
 
Example #2
Source File: RecipeItemListActivity.java    From android-recipes-app with Apache License 2.0 6 votes vote down vote up
@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);
	}

}
 
Example #3
Source File: SearchActivity.java    From materialistic with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #4
Source File: SearchHistoryProvider.java    From Varis-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Queries recent search data
 *
 * @param context Context
 * @param query   Query string
 * @return Cursor with found data or null
 */
public static Cursor queryRecentSearch(Context context, String query) {
    Uri uri = Uri.parse("content://".concat(SearchHistoryProvider.AUTHORITY.concat("/suggestions")));

    String[] selection = SearchRecentSuggestions.QUERIES_PROJECTION_1LINE;
    String[] selectionArgs = new String[]{"%" + query + "%"};

    Cursor cursor = context.getContentResolver().query(
            uri,
            selection,
            "display1 LIKE ?",
            selectionArgs,
            "date DESC"
    );

    return cursor;
}
 
Example #5
Source File: MainActivity.java    From Leaderboards with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #6
Source File: SearchActivity.java    From custom-searchable with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #7
Source File: SearchActivity.java    From custom-searchable with Apache License 2.0 6 votes vote down vote up
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"
    );
}
 
Example #8
Source File: SearchQueryResults.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Generic search handler.
 * 
 * In a "real" application, you would use the query string to select results from
 * your data source, and present a list of those results to the user.
 */
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);
    mQueryText.setText(queryString);
    
    // Record the query string in the recent queries suggestions provider.
    SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, 
            SearchSuggestionSampleProvider.AUTHORITY, SearchSuggestionSampleProvider.MODE);
    suggestions.saveRecentQuery(queryString, null);
    
    // If your application provides context data for its searches, 
    // you will receive it as an "extra" bundle in the query intent. 
    // The bundle can contain any number of elements, using any number of keys;
    // For this Api Demo we're just using a single string, stored using "demo key".
    final Bundle appData = queryIntent.getBundleExtra(SearchManager.APP_DATA);
    if (appData == null) {
        mAppDataText.setText("<no app data bundle>");
    }
    if (appData != null) {
        String testStr = appData.getString("demo_key");
        mAppDataText.setText((testStr == null) ? "<no app data>" : testStr);
    }
    
    // Report the method by which we were called.
    mDeliveredByText.setText(entryPoint);
}
 
Example #9
Source File: SearchableActivity.java    From Androzic with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState)
{
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_search);

	Toolbar toolbar = (Toolbar) findViewById(R.id.action_toolbar);
    setSupportActionBar(toolbar);

	getSupportActionBar().setDisplayHomeAsUpEnabled(true);
	getSupportActionBar().setHomeButtonEnabled(true);
	
    listView = (ListView) findViewById(android.R.id.list);

	finishHandler = new FinishHandler(this);

	if (Intent.ACTION_SEARCH.equals(getIntent().getAction()))
	{
		String query = getIntent().getStringExtra(SearchManager.QUERY);
		SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SuggestionProvider.AUTHORITY, SuggestionProvider.MODE);
		suggestions.saveRecentQuery(query, null);
	}

	adapter = new SearchResultsListAdapter(this, results);
	listView.setAdapter(adapter);
	listView.setOnItemClickListener(this);
	
	progressBar = (ProgressBar) findViewById(R.id.progressbar);
	
	handleIntent(getIntent());
}
 
Example #10
Source File: SearchMainActivity.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example #11
Source File: SearchMainActivity.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example #12
Source File: SearchActivity.java    From custom-searchable with Apache License 2.0 5 votes vote down vote up
private Cursor queryCustomSuggestionProvider () {
    Uri uri = Uri.parse("content://".concat(providerAuthority).concat("/suggestions/").concat(query));

    String[] selection = {"display1"};
    String[] selectionArgs = new String[] {"%" + query + "%"};

    return SearchActivity.this.getContentResolver().query(
            uri,
            SearchRecentSuggestions.QUERIES_PROJECTION_1LINE,
            "display1 LIKE ?",
            selectionArgs,
            "date DESC"
    );
}
 
Example #13
Source File: SettingsActivity.java    From materialistic with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #14
Source File: SearchActivity.java    From droidddle with Apache License 2.0 5 votes vote down vote up
private void saveQuery(String query) {
    if (TextUtils.isEmpty(query)) {
        return;
    }
    SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SearchProvider.AUTHORITY, SearchProvider.MODE);
    suggestions.saveRecentQuery(query, null);
}
 
Example #15
Source File: TagActivity.java    From droidddle with Apache License 2.0 5 votes vote down vote up
private void saveQuery(String query) {
    if (TextUtils.isEmpty(query)) {
        return;
    }
    SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, SearchProvider.AUTHORITY, SearchProvider.MODE);
    suggestions.saveRecentQuery(query, null);
}
 
Example #16
Source File: SearchEngineProvider.java    From mytracks with Apache License 2.0 4 votes vote down vote up
/**
 * Creates and returns a helper for adding recent queries or clearing the recent query history.
 */
public static SearchRecentSuggestions newHelper(Context context) {
  return new SearchRecentSuggestions(context, AUTHORITY, MODE);
}
 
Example #17
Source File: MediathekSearchSuggestionsProvider.java    From zapp with MIT License 4 votes vote down vote up
public static void deleteAllQueries(Context context) {
	SearchRecentSuggestions suggestions = new SearchRecentSuggestions(context, AUTHORITY, MODE);
	suggestions.clearHistory();
}
 
Example #18
Source File: MediathekSearchSuggestionsProvider.java    From zapp with MIT License 4 votes vote down vote up
public static void saveQuery(Context context, String query) {
	SearchRecentSuggestions suggestions = new SearchRecentSuggestions(context, AUTHORITY, MODE);
	suggestions.saveRecentQuery(query, null);
}
 
Example #19
Source File: SearchInvoke.java    From codeexamples-android with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Any application that implements search suggestions based on previous actions (such as
 * recent queries, page/items viewed, etc.) should provide a way for the user to clear the
 * history.  This gives the user a measure of privacy, if they do not wish for their recent
 * searches to be replayed by other users of the device (via suggestions).
 * 
 * This example shows how to clear the search history for apps that use 
 * android.provider.SearchRecentSuggestions.  If you have developed a custom suggestions
 * provider, you'll need to provide a similar API for clearing history.
 * 
 * In this sample app we call this method from a "Clear History" menu item.  You could also 
 * implement the UI in your preferences, or any other logical place in your UI.
 */
private void clearSearchHistory() {
    SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, 
            SearchSuggestionSampleProvider.AUTHORITY, SearchSuggestionSampleProvider.MODE);
    suggestions.clearHistory();
}