summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Roard <nicolas@android.com>2009-09-22 15:17:52 +0100
committerNicolas Roard <nicolas@android.com>2009-09-22 15:17:52 +0100
commit99b3ae1a384981f96fca5432f3d20bf4e8d13667 (patch)
tree9a74c0d60772dd7d5075382a7f5237ce22c8c97f
parentf4672127dba061c9d4d69a1139e9c8e43d740a49 (diff)
downloadpackages_apps_browser-99b3ae1a384981f96fca5432f3d20bf4e8d13667.zip
packages_apps_browser-99b3ae1a384981f96fca5432f3d20bf4e8d13667.tar.gz
packages_apps_browser-99b3ae1a384981f96fca5432f3d20bf4e8d13667.tar.bz2
Reimplement the settings to use async callbacks
-rw-r--r--src/com/android/browser/BrowserPreferencesPage.java29
-rw-r--r--src/com/android/browser/BrowserSettings.java33
-rw-r--r--src/com/android/browser/WebsiteSettingsActivity.java157
3 files changed, 142 insertions, 77 deletions
diff --git a/src/com/android/browser/BrowserPreferencesPage.java b/src/com/android/browser/BrowserPreferencesPage.java
index ec3561f..fb0b2ba 100644
--- a/src/com/android/browser/BrowserPreferencesPage.java
+++ b/src/com/android/browser/BrowserPreferencesPage.java
@@ -17,8 +17,9 @@
package com.android.browser;
import java.util.List;
-import java.util.Vector;
+import java.util.Map;
import java.util.Set;
+import java.util.Vector;
import android.content.Intent;
import android.net.Uri;
@@ -30,13 +31,14 @@ import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.util.Log;
import android.webkit.GeolocationPermissions;
+import android.webkit.ValueCallback;
import android.webkit.WebStorage;
import android.webkit.WebView;
public class BrowserPreferencesPage extends PreferenceActivity
implements Preference.OnPreferenceChangeListener {
- String TAG = "BrowserPreferencesPage";
+ private String LOGTAG = "BrowserPreferencesPage";
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -86,14 +88,23 @@ public class BrowserPreferencesPage extends PreferenceActivity
@Override
protected void onResume() {
super.onResume();
- PreferenceScreen websiteSettings = (PreferenceScreen)
+ final PreferenceScreen websiteSettings = (PreferenceScreen)
findPreference(BrowserSettings.PREF_WEBSITE_SETTINGS);
- Set webStorageOrigins = WebStorage.getInstance().getOrigins();
- Set geolocationOrigins =
- GeolocationPermissions.getInstance().getOrigins();
- websiteSettings.setEnabled(
- ((webStorageOrigins != null) && !webStorageOrigins.isEmpty()) ||
- ((geolocationOrigins != null) && !geolocationOrigins.isEmpty()));
+ websiteSettings.setEnabled(false);
+ WebStorage.getInstance().getOrigins(new ValueCallback<Map>() {
+ public void onReceiveValue(Map webStorageOrigins) {
+ if ((webStorageOrigins != null) && !webStorageOrigins.isEmpty()) {
+ websiteSettings.setEnabled(true);
+ }
+ }
+ });
+ GeolocationPermissions.getInstance().getOrigins(new ValueCallback<Set>() {
+ public void onReceiveValue(Set geolocationOrigins) {
+ if ((geolocationOrigins != null) && !geolocationOrigins.isEmpty()) {
+ websiteSettings.setEnabled(true);
+ }
+ }
+ });
}
@Override
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java
index 91b08a3..cb51b50 100644
--- a/src/com/android/browser/BrowserSettings.java
+++ b/src/com/android/browser/BrowserSettings.java
@@ -28,6 +28,7 @@ import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.webkit.CookieManager;
import android.webkit.GeolocationPermissions;
+import android.webkit.ValueCallback;
import android.webkit.WebView;
import android.webkit.WebViewDatabase;
import android.webkit.WebIconDatabase;
@@ -36,8 +37,9 @@ import android.webkit.WebStorage;
import android.preference.PreferenceManager;
import android.provider.Browser;
-import java.util.Set;
import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
import java.util.Observable;
/*
@@ -534,16 +536,25 @@ class BrowserSettings extends Observable {
}
private void maybeDisableWebsiteSettings(Context context) {
- Set webStorageOrigins = WebStorage.getInstance().getOrigins();
- Set geolocationOrigins =
- GeolocationPermissions.getInstance().getOrigins();
- if (((webStorageOrigins == null) || webStorageOrigins.isEmpty()) &&
- ((geolocationOrigins == null) || geolocationOrigins.isEmpty())) {
- PreferenceActivity activity = (PreferenceActivity) context;
- PreferenceScreen screen = (PreferenceScreen)
- activity.findPreference(BrowserSettings.PREF_WEBSITE_SETTINGS);
- screen.setEnabled(false);
- }
+ PreferenceActivity activity = (PreferenceActivity) context;
+ final PreferenceScreen screen = (PreferenceScreen)
+ activity.findPreference(BrowserSettings.PREF_WEBSITE_SETTINGS);
+ screen.setEnabled(false);
+ WebStorage.getInstance().getOrigins(new ValueCallback<Map>() {
+ public void onReceiveValue(Map webStorageOrigins) {
+ if ((webStorageOrigins != null) && !webStorageOrigins.isEmpty()) {
+ screen.setEnabled(true);
+ }
+ }
+ });
+
+ GeolocationPermissions.getInstance().getOrigins(new ValueCallback<Set>() {
+ public void onReceiveValue(Set geolocationOrigins) {
+ if ((geolocationOrigins != null) && !geolocationOrigins.isEmpty()) {
+ screen.setEnabled(true);
+ }
+ }
+ });
}
/*package*/ void clearDatabases(Context context) {
diff --git a/src/com/android/browser/WebsiteSettingsActivity.java b/src/com/android/browser/WebsiteSettingsActivity.java
index 640a32d..5d5fc09 100644
--- a/src/com/android/browser/WebsiteSettingsActivity.java
+++ b/src/com/android/browser/WebsiteSettingsActivity.java
@@ -35,6 +35,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.GeolocationPermissions;
+import android.webkit.ValueCallback;
import android.webkit.WebIconDatabase;
import android.webkit.WebStorage;
import android.widget.ArrayAdapter;
@@ -178,7 +179,7 @@ public class WebsiteSettingsActivity extends ListActivity {
R.drawable.usage_high);
mLocationIcon = BitmapFactory.decodeResource(getResources(),
R.drawable.location);
- populateOrigins();
+ askForOrigins();
}
/**
@@ -196,9 +197,7 @@ public class WebsiteSettingsActivity extends ListActivity {
site.addFeature(feature);
}
- public void populateOrigins() {
- clear();
-
+ public void askForOrigins() {
// Get the list of origins we want to display.
// All 'HTML 5 modules' (Database, Geolocation etc) form these
// origin strings using WebCore::SecurityOrigin::toString(), so it's
@@ -207,22 +206,37 @@ public class WebsiteSettingsActivity extends ListActivity {
// default for the protocol. Eg http://www.google.com and
// http://www.google.com:80 both record a port of 0 and hence
// toString() == 'http://www.google.com' for both.
- Set origins = WebStorage.getInstance().getOrigins();
- Map sites = new HashMap<String, Site>();
- if (origins != null) {
- Iterator<String> iter = origins.iterator();
- while (iter.hasNext()) {
- addFeatureToSite(sites, iter.next(), Site.FEATURE_WEB_STORAGE);
+
+ WebStorage.getInstance().getOrigins(new ValueCallback<Map>() {
+ public void onReceiveValue(Map origins) {
+ Map sites = new HashMap<String, Site>();
+ if (origins != null) {
+ Iterator<String> iter = origins.keySet().iterator();
+ while (iter.hasNext()) {
+ addFeatureToSite(sites, iter.next(), Site.FEATURE_WEB_STORAGE);
+ }
+ }
+ askForGeolocation(sites);
}
- }
- origins = GeolocationPermissions.getInstance().getOrigins();
- if (origins != null) {
- Iterator<String> iter = origins.iterator();
- while (iter.hasNext()) {
- addFeatureToSite(sites, iter.next(), Site.FEATURE_GEOLOCATION);
+ });
+ }
+
+ public void askForGeolocation(final Map sites) {
+ GeolocationPermissions.getInstance().getOrigins(new ValueCallback<Set>() {
+ public void onReceiveValue(Set origins) {
+ if (origins != null) {
+ Iterator<String> iter = origins.iterator();
+ while (iter.hasNext()) {
+ addFeatureToSite(sites, iter.next(), Site.FEATURE_GEOLOCATION);
+ }
+ }
+ populateIcons(sites);
+ populateOrigins(sites);
}
- }
+ });
+ }
+ public void populateIcons(Map sites) {
// Create a map from host to origin. This is used to add metadata
// (title, icon) for this origin from the bookmarks DB.
HashMap hosts = new HashMap<String, Set<Site> >();
@@ -276,16 +290,23 @@ public class WebsiteSettingsActivity extends ListActivity {
}
c.close();
+ }
+
+
+ public void populateOrigins(Map sites) {
+ clear();
// We can now simply populate our array with Site instances
- keys = sites.keySet();
- originIter = keys.iterator();
+ Set keys = sites.keySet();
+ Iterator<String> originIter = keys.iterator();
while (originIter.hasNext()) {
String origin = originIter.next();
Site site = (Site) sites.get(origin);
add(site);
}
+ notifyDataSetChanged();
+
if (getCount() == 0) {
finish(); // we close the screen
}
@@ -320,19 +341,43 @@ public class WebsiteSettingsActivity extends ListActivity {
public boolean backKeyPressed() {
if (mCurrentSite != null) {
mCurrentSite = null;
- populateOrigins();
- notifyDataSetChanged();
+ askForOrigins();
return true;
}
return false;
}
+ /**
+ * @hide
+ * Utility function
+ * Set the icon according to the usage
+ */
+ public void setIconForUsage(ImageView usageIcon, long usageInBytes) {
+ float usageInMegabytes = (float) usageInBytes / (1024.0F * 1024.0F);
+ usageIcon.setVisibility(View.VISIBLE);
+
+ // We set the correct icon:
+ // 0 < empty < 0.1MB
+ // 0.1MB < low < 3MB
+ // 3MB < medium < 6MB
+ // 6MB < high
+ if (usageInMegabytes <= 0.1) {
+ usageIcon.setImageBitmap(mUsageEmptyIcon);
+ } else if (usageInMegabytes > 0.1 && usageInMegabytes <= 3) {
+ usageIcon.setImageBitmap(mUsageLowIcon);
+ } else if (usageInMegabytes > 3 && usageInMegabytes <= 6) {
+ usageIcon.setImageBitmap(mUsageMediumIcon);
+ } else if (usageInMegabytes > 6) {
+ usageIcon.setImageBitmap(mUsageHighIcon);
+ }
+ }
+
public View getView(int position, View convertView, ViewGroup parent) {
View view;
- TextView title;
- TextView subtitle;
+ final TextView title;
+ final TextView subtitle;
ImageView icon;
- ImageView usageIcon;
+ final ImageView usageIcon;
ImageView locationIcon;
if (convertView == null) {
@@ -369,24 +414,13 @@ public class WebsiteSettingsActivity extends ListActivity {
if (site.hasFeature(Site.FEATURE_WEB_STORAGE)) {
String origin = site.getOrigin();
- long usageInBytes = WebStorage.getInstance().getUsageForOrigin(origin);
- float usageInMegabytes = (float) usageInBytes / (1024.0F * 1024.0F);
- usageIcon.setVisibility(View.VISIBLE);
-
- // We set the correct icon:
- // 0 < empty < 0.1MB
- // 0.1MB < low < 3MB
- // 3MB < medium < 6MB
- // 6MB < high
- if (usageInMegabytes <= 0.1) {
- usageIcon.setImageBitmap(mUsageEmptyIcon);
- } else if (usageInMegabytes > 0.1 && usageInMegabytes <= 3) {
- usageIcon.setImageBitmap(mUsageLowIcon);
- } else if (usageInMegabytes > 3 && usageInMegabytes <= 6) {
- usageIcon.setImageBitmap(mUsageMediumIcon);
- } else if (usageInMegabytes > 6) {
- usageIcon.setImageBitmap(mUsageHighIcon);
- }
+ WebStorage.getInstance().getUsageForOrigin(origin, new ValueCallback<Long>() {
+ public void onReceiveValue(Long value) {
+ if (value != null) {
+ setIconForUsage(usageIcon, value.longValue());
+ }
+ }
+ });
}
if (site.hasFeature(Site.FEATURE_GEOLOCATION)) {
@@ -399,18 +433,29 @@ public class WebsiteSettingsActivity extends ListActivity {
String origin = mCurrentSite.getOrigin();
switch (mCurrentSite.getFeatureByIndex(position)) {
case Site.FEATURE_WEB_STORAGE:
- long usageValue = WebStorage.getInstance().getUsageForOrigin(origin);
- String usage = sizeValueToString(usageValue) + " " + sMBStored;
-
- title.setText(R.string.webstorage_clear_data_title);
- subtitle.setText(usage);
+ WebStorage.getInstance().getUsageForOrigin(origin, new ValueCallback<Long>() {
+ public void onReceiveValue(Long value) {
+ if (value != null) {
+ String usage = sizeValueToString(value.longValue()) + " " + sMBStored;
+ title.setText(R.string.webstorage_clear_data_title);
+ subtitle.setText(usage);
+ }
+ }
+ });
break;
case Site.FEATURE_GEOLOCATION:
title.setText(R.string.geolocation_settings_page_title);
- boolean allowed = GeolocationPermissions.getInstance().getAllowed(origin);
- subtitle.setText(allowed ?
- R.string.geolocation_settings_page_summary_allowed :
- R.string.geolocation_settings_page_summary_not_allowed);
+ GeolocationPermissions.getInstance().getAllowed(origin, new ValueCallback<Boolean>() {
+ public void onReceiveValue(Boolean allowed) {
+ if (allowed != null) {
+ if (allowed.booleanValue()) {
+ subtitle.setText(R.string.geolocation_settings_page_summary_allowed);
+ } else {
+ subtitle.setText(R.string.geolocation_settings_page_summary_not_allowed);
+ }
+ }
+ }
+ });
break;
}
}
@@ -433,8 +478,7 @@ public class WebsiteSettingsActivity extends ListActivity {
public void onClick(DialogInterface dlg, int which) {
WebStorage.getInstance().deleteOrigin(mCurrentSite.getOrigin());
mCurrentSite = null;
- populateOrigins();
- notifyDataSetChanged();
+ askForOrigins();
}})
.setNegativeButton(R.string.webstorage_clear_data_dialog_cancel_button, null)
.setIcon(android.R.drawable.ic_dialog_alert)
@@ -449,8 +493,7 @@ public class WebsiteSettingsActivity extends ListActivity {
public void onClick(DialogInterface dlg, int which) {
GeolocationPermissions.getInstance().clear(mCurrentSite.getOrigin());
mCurrentSite = null;
- populateOrigins();
- notifyDataSetChanged();
+ askForOrigins();
}})
.setNegativeButton(R.string.geolocation_settings_page_dialog_cancel_button, null)
.setIcon(android.R.drawable.ic_dialog_alert)
@@ -515,8 +558,8 @@ public class WebsiteSettingsActivity extends ListActivity {
public void onClick(DialogInterface dlg, int which) {
WebStorage.getInstance().deleteAllData();
GeolocationPermissions.getInstance().clearAll();
- mAdapter.populateOrigins();
- mAdapter.notifyDataSetChanged();
+ mAdapter.askForOrigins();
+ finish();
}})
.setNegativeButton(R.string.website_settings_clear_all_dialog_cancel_button, null)
.setIcon(android.R.drawable.ic_dialog_alert)