diff options
author | Leon Scroggins <scroggo@google.com> | 2009-06-12 17:51:22 -0400 |
---|---|---|
committer | Leon Scroggins <scroggo@google.com> | 2009-06-12 17:56:43 -0400 |
commit | 62b71f79a80e471bdb84bc06a88cd78a8162e3a5 (patch) | |
tree | d1c660b2e2905f2b1332d733ebe7e3eacee9685a /src/com/android/browser | |
parent | 0494cc618a6cf50a1e0c5bf4472a9fdccb1d7e91 (diff) | |
download | packages_apps_browser-62b71f79a80e471bdb84bc06a88cd78a8162e3a5.zip packages_apps_browser-62b71f79a80e471bdb84bc06a88cd78a8162e3a5.tar.gz packages_apps_browser-62b71f79a80e471bdb84bc06a88cd78a8162e3a5.tar.bz2 |
Honor the system setting of whether to show web suggestions.
Diffstat (limited to 'src/com/android/browser')
-rw-r--r-- | src/com/android/browser/BrowserProvider.java | 77 |
1 files changed, 63 insertions, 14 deletions
diff --git a/src/com/android/browser/BrowserProvider.java b/src/com/android/browser/BrowserProvider.java index d2f4a0a..bc73ab6 100644 --- a/src/com/android/browser/BrowserProvider.java +++ b/src/com/android/browser/BrowserProvider.java @@ -31,12 +31,15 @@ import android.content.SharedPreferences.Editor; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.database.AbstractCursor; +import android.database.ContentObserver; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.net.Uri; +import android.os.Handler; import android.preference.PreferenceManager; import android.provider.Browser; +import android.provider.Settings; import android.server.search.SearchableInfo; import android.text.TextUtils; import android.text.util.Regex; @@ -264,9 +267,65 @@ public class BrowserProvider extends ContentProvider { ed.commit(); } } + mShowWebSuggestionsSettingChangeObserver + = new ShowWebSuggestionsSettingChangeObserver(); + context.getContentResolver().registerContentObserver( + Settings.System.getUriFor( + Settings.System.SHOW_WEB_SUGGESTIONS), + true, mShowWebSuggestionsSettingChangeObserver); + updateShowWebSuggestions(); return true; } + /** + * This Observer will ensure that if the user changes the system + * setting of whether to display web suggestions, we will + * change accordingly. + */ + /* package */ class ShowWebSuggestionsSettingChangeObserver + extends ContentObserver { + public ShowWebSuggestionsSettingChangeObserver() { + super(new Handler()); + } + + @Override + public void onChange(boolean selfChange) { + updateShowWebSuggestions(); + } + } + + private ShowWebSuggestionsSettingChangeObserver + mShowWebSuggestionsSettingChangeObserver; + + // If non-null, then the system is set to show web suggestions, + // and this is the SearchableInfo to use to get them. + private SearchableInfo mSearchableInfo; + + /** + * Check the system settings to see whether web suggestions are + * allowed. If so, store the SearchableInfo to grab suggestions + * while the user is typing. + */ + private void updateShowWebSuggestions() { + mSearchableInfo = null; + Context context = getContext(); + if (Settings.System.getInt(context.getContentResolver(), + Settings.System.SHOW_WEB_SUGGESTIONS, + 1 /* default on */) == 1) { + Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); + intent.addCategory(Intent.CATEGORY_DEFAULT); + ResolveInfo info = context.getPackageManager().resolveActivity( + intent, PackageManager.MATCH_DEFAULT_ONLY); + if (info != null) { + ComponentName googleSearchComponent = + new ComponentName(info.activityInfo.packageName, + info.activityInfo.name); + mSearchableInfo = SearchManager.getSearchableInfo( + googleSearchComponent, false); + } + } + } + private void fixPicasaBookmark() { SQLiteDatabase db = mOpenHelper.getWritableDatabase(); Cursor cursor = db.rawQuery("SELECT _id FROM bookmarks WHERE " + @@ -598,21 +657,11 @@ public class BrowserProvider extends ContentProvider { } else { // get Google suggest if there is still space in the list if (myArgs != null && myArgs.length > 1 + && mSearchableInfo != null && c.getCount() < (MAX_SUGGESTION_SHORT_ENTRIES - 1)) { - Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); - intent.addCategory(Intent.CATEGORY_DEFAULT); - ResolveInfo info = getContext().getPackageManager().resolveActivity( - intent, PackageManager.MATCH_DEFAULT_ONLY); - if (info != null) { - ComponentName googleSearchComponent = - new ComponentName(info.activityInfo.packageName, - info.activityInfo.name); - SearchableInfo si = - SearchManager.getSearchableInfo(googleSearchComponent, false); - Cursor sc = SearchManager.getSuggestions( - getContext(), si, selectionArgs[0]); - return new MySuggestionCursor(c, sc, selectionArgs[0]); - } + Cursor sc = SearchManager.getSuggestions( + getContext(), mSearchableInfo, selectionArgs[0]); + return new MySuggestionCursor(c, sc, selectionArgs[0]); } return new MySuggestionCursor(c, null, selectionArgs[0]); } |