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/BrowserSettings.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/BrowserSettings.java')
-rw-r--r-- | src/com/android/browser/BrowserSettings.java | 64 |
1 files changed, 60 insertions, 4 deletions
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java index fbfe608..73b648b 100644 --- a/src/com/android/browser/BrowserSettings.java +++ b/src/com/android/browser/BrowserSettings.java @@ -17,14 +17,22 @@ package com.android.browser; +import com.android.browser.search.SearchEngine; +import com.android.browser.search.SearchEngines; + import android.app.ActivityManager; +import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; +import android.database.ContentObserver; +import android.os.Handler; import android.preference.PreferenceActivity; import android.preference.PreferenceScreen; +import android.provider.Settings; +import android.util.Log; import android.webkit.CookieManager; import android.webkit.GeolocationPermissions; import android.webkit.ValueCallback; @@ -71,6 +79,8 @@ class BrowserSettings extends Observable { private boolean openInBackground; private String defaultTextEncodingName; private String homeUrl = ""; + private SearchEngine searchEngine; + private boolean showSearchSuggestions; private boolean autoFitPage; private boolean landscapeOnly; private boolean loadsPageInOverviewMode; @@ -121,6 +131,8 @@ class BrowserSettings extends Observable { public final static String PREF_CLEAR_COOKIES = "privacy_clear_cookies"; public final static String PREF_CLEAR_HISTORY = "privacy_clear_history"; public final static String PREF_HOMEPAGE = "homepage"; + public final static String PREF_SEARCH_ENGINE = "search_engine"; + public final static String PREF_SHOW_SEARCH_SUGGESTIONS = "show_search_suggestions"; public final static String PREF_CLEAR_FORM_DATA = "privacy_clear_form_data"; public final static String PREF_CLEAR_PASSWORDS = @@ -246,7 +258,7 @@ class BrowserSettings extends Observable { * stored in this BrowserSettings object. This will update all * observers of this object. */ - public void loadFromDb(Context ctx) { + public void loadFromDb(final Context ctx) { SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(ctx); // Set the default value for the Application Caches path. @@ -278,17 +290,41 @@ class BrowserSettings extends Observable { pageCacheCapacity = 1; } - // Load the defaults from the xml + final ContentResolver cr = ctx.getContentResolver(); + cr.registerContentObserver( + Settings.System.getUriFor(Settings.System.SHOW_WEB_SUGGESTIONS), false, + new ContentObserver(new Handler()) { + @Override + public void onChange(boolean selfChange) { + SharedPreferences p = + PreferenceManager.getDefaultSharedPreferences(ctx); + updateShowWebSuggestions(cr, p); + } + }); + updateShowWebSuggestions(cr, p); + + // Load the defaults from the xml // This call is TOO SLOW, need to manually keep the defaults // in sync //PreferenceManager.setDefaultValues(ctx, R.xml.browser_preferences); - syncSharedPreferences(p); + syncSharedPreferences(ctx, p); } - /* package */ void syncSharedPreferences(SharedPreferences p) { + /* package */ void syncSharedPreferences(Context ctx, SharedPreferences p) { homeUrl = p.getString(PREF_HOMEPAGE, homeUrl); + String searchEngineName = p.getString(PREF_SEARCH_ENGINE, null); + if (searchEngine == null || !searchEngine.getName().equals(searchEngineName)) { + if (searchEngine != null) { + searchEngine.close(); + } + searchEngine = SearchEngines.get(ctx, searchEngineName); + } + Log.i(TAG, "Selected search engine: " + searchEngine); + showSearchSuggestions = p.getBoolean(PREF_SHOW_SEARCH_SUGGESTIONS, true); + // Persist to system settings + saveShowWebSuggestions(ctx.getContentResolver()); loadsImagesAutomatically = p.getBoolean("load_images", loadsImagesAutomatically); @@ -377,10 +413,30 @@ class BrowserSettings extends Observable { update(); } + private void saveShowWebSuggestions(ContentResolver cr) { + int value = showSearchSuggestions ? 1 : 0; + Settings.System.putInt(cr, Settings.System.SHOW_WEB_SUGGESTIONS, value); + } + + private void updateShowWebSuggestions(ContentResolver cr, SharedPreferences p) { + showSearchSuggestions = + Settings.System.getInt(cr, + Settings.System.SHOW_WEB_SUGGESTIONS, 1) == 1; + p.edit().putBoolean(PREF_SHOW_SEARCH_SUGGESTIONS, showSearchSuggestions).commit(); + } + public String getHomePage() { return homeUrl; } + public SearchEngine getSearchEngine() { + return searchEngine; + } + + public boolean getShowSearchSuggestions() { + return showSearchSuggestions; + } + public String getJsFlags() { return jsFlags; } |