android.content.SearchRecentSuggestionsProvider Java Examples

The following examples show how to use android.content.SearchRecentSuggestionsProvider. 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: SearchRecentSuggestions.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Although provider utility classes are typically static, this one must be constructed
 * because it needs to be initialized using the same values that you provided in your
 * {@link android.content.SearchRecentSuggestionsProvider}.
 *
 * @param authority This must match the authority that you've declared in your manifest.
 * @param mode You can use mode flags here to determine certain functional aspects of your
 * database.  Note, this value should not change from run to run, because when it does change,
 * your suggestions database may be wiped.
 *
 * @see android.content.SearchRecentSuggestionsProvider
 * @see android.content.SearchRecentSuggestionsProvider#setupSuggestions
 */
public SearchRecentSuggestions(Context context, String authority, int mode) {
    if (TextUtils.isEmpty(authority) ||
            ((mode & SearchRecentSuggestionsProvider.DATABASE_MODE_QUERIES) == 0)) {
        throw new IllegalArgumentException();
    }
    // unpack mode flags
    mTwoLineDisplay = (0 != (mode & SearchRecentSuggestionsProvider.DATABASE_MODE_2LINES));

    // saved values
    mContext = context;
    mAuthority = new String(authority);

    // derived values
    mSuggestionsUri = Uri.parse("content://" + mAuthority + "/suggestions");
}
 
Example #2
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 #3
Source File: SearchActivity.java    From custom-searchable with Apache License 2.0 6 votes vote down vote up
private void getManifestConfig () {
    try {
        Map<String, String> providers = ManifestParser.getProviderNameAndAuthority(this);

        OUTER: for (String key : providers.keySet()) {
            providerAuthority = providers.get(key).toString();
            providerName = key;

            if (Class.forName(providerName).getSuperclass().equals(SearchRecentSuggestionsProvider.class)) {
                isRecentSuggestionsProvider = Boolean.TRUE;

                break OUTER;
            } else {
                isRecentSuggestionsProvider = Boolean.FALSE;
            }
        }

        searchableActivity = ManifestParser.getSearchableActivity(this);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}