diff options
author | Bjorn Bringert <bringert@android.com> | 2010-09-13 17:41:40 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2010-09-13 17:41:40 -0700 |
commit | 8bf09b6200101c050af76118e1980ac2ccf2a0c5 (patch) | |
tree | df589f4dd1773cc07d0575adcc67e9b3dcb4934a /src/com/android/browser/BrowserProvider.java | |
parent | 23cbeb795fe865a5c64f275bf51217fb55363cc0 (diff) | |
parent | d26706538834e0ed58bf28f08d9a2885c0e7efcb (diff) | |
download | packages_apps_browser-8bf09b6200101c050af76118e1980ac2ccf2a0c5.zip packages_apps_browser-8bf09b6200101c050af76118e1980ac2ccf2a0c5.tar.gz packages_apps_browser-8bf09b6200101c050af76118e1980ac2ccf2a0c5.tar.bz2 |
am d2670653: Add user-selected search providers to browser
Merge commit 'd26706538834e0ed58bf28f08d9a2885c0e7efcb' into gingerbread
* commit 'd26706538834e0ed58bf28f08d9a2885c0e7efcb':
Add user-selected search providers to browser
Diffstat (limited to 'src/com/android/browser/BrowserProvider.java')
-rw-r--r-- | src/com/android/browser/BrowserProvider.java | 77 |
1 files changed, 12 insertions, 65 deletions
diff --git a/src/com/android/browser/BrowserProvider.java b/src/com/android/browser/BrowserProvider.java index 03e8de4..a7da246 100644 --- a/src/com/android/browser/BrowserProvider.java +++ b/src/com/android/browser/BrowserProvider.java @@ -16,10 +16,10 @@ package com.android.browser; +import com.android.browser.search.SearchEngine; + import android.app.SearchManager; -import android.app.SearchableInfo; import android.app.backup.BackupManager; -import android.content.ComponentName; import android.content.ContentProvider; import android.content.ContentResolver; import android.content.ContentUris; @@ -27,28 +27,21 @@ import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.content.UriMatcher; import android.content.SharedPreferences.Editor; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; +import android.content.UriMatcher; 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.os.Process; import android.preference.PreferenceManager; import android.provider.Browser; -import android.provider.Settings; import android.provider.Browser.BookmarkColumns; import android.speech.RecognizerResultsIntent; import android.text.TextUtils; import android.util.Log; import android.util.Patterns; -import android.util.TypedValue; - import java.io.File; import java.io.FilenameFilter; @@ -165,7 +158,7 @@ public class BrowserProvider extends ContentProvider { // optionally a trailing slash, all matched as separate groups. private static final Pattern STRIP_URL_PATTERN = Pattern.compile("^(http://)(.*?)(/$)?"); - private SearchManager mSearchManager; + private BrowserSettings mSettings; public BrowserProvider() { } @@ -366,59 +359,10 @@ public class BrowserProvider extends ContentProvider { ed.apply(); } } - mSearchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE); - mShowWebSuggestionsSettingChangeObserver - = new ShowWebSuggestionsSettingChangeObserver(); - context.getContentResolver().registerContentObserver( - Settings.System.getUriFor( - Settings.System.SHOW_WEB_SUGGESTIONS), - true, mShowWebSuggestionsSettingChangeObserver); - updateShowWebSuggestions(); + mSettings = BrowserSettings.getInstance(); 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) { - ComponentName webSearchComponent = mSearchManager.getWebSearchActivity(); - if (webSearchComponent != null) { - mSearchableInfo = mSearchManager.getSearchableInfo(webSearchComponent); - } - } - } - private void fixPicasaBookmark() { SQLiteDatabase db = mOpenHelper.getWritableDatabase(); Cursor cursor = db.rawQuery("SELECT _id FROM bookmarks WHERE " + @@ -875,12 +819,15 @@ public class BrowserProvider extends ContentProvider { || Patterns.WEB_URL.matcher(selectionArgs[0]).matches()) { return new MySuggestionCursor(c, null, ""); } else { - // get Google suggest if there is still space in the list + // get search suggestions if there is still space in the list if (myArgs != null && myArgs.length > 1 - && mSearchableInfo != null + && mSettings.getShowSearchSuggestions() && c.getCount() < (MAX_SUGGESTION_SHORT_ENTRIES - 1)) { - Cursor sc = mSearchManager.getSuggestions(mSearchableInfo, selectionArgs[0]); - return new MySuggestionCursor(c, sc, selectionArgs[0]); + SearchEngine searchEngine = mSettings.getSearchEngine(); + if (searchEngine != null && searchEngine.supportsSuggestions()) { + Cursor sc = searchEngine.getSuggestions(getContext(), selectionArgs[0]); + return new MySuggestionCursor(c, sc, selectionArgs[0]); + } } return new MySuggestionCursor(c, null, selectionArgs[0]); } |