New settings UI for HTML5
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 88c414b..10d7785 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -164,6 +164,10 @@
android:configChanges="orientation|keyboardHidden">
</activity>
+ <activity android:name="WebsiteSettingsActivity" android:label=""
+ android:configChanges="orientation|keyboardHidden">
+ </activity>
+
<activity android:name="GearsDialog" android:process=":dialog"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.Dialog">
diff --git a/res/layout/application.xml b/res/layout/application.xml
new file mode 100644
index 0000000..d8de265
--- /dev/null
+++ b/res/layout/application.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:drawingCacheQuality="auto"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center"
+ android:padding="0dip">
+
+ <ImageView android:id="@+id/icon"
+ android:layout_width="32px"
+ android:layout_height="32px"
+ android:padding="2dip" />
+
+ <TwoLineListItem
+ android:paddingTop="2dip"
+ android:paddingBottom="2dip"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="?android:attr/listPreferredItemHeight"
+ android:mode="twoLine">
+
+ <TextView android:id="@+id/title"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="6dip"
+ android:layout_marginTop="6dip"
+ android:textAppearance="?android:attr/textAppearanceLarge"/>
+
+ <TextView android:id="@+id/subtitle"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@+id/title"
+ android:layout_alignLeft="@+id/title"
+ android:textAppearance="?android:attr/textAppearanceSmall"/>
+
+ </TwoLineListItem>
+
+</LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8440314..3bdb0be 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -300,9 +300,9 @@
<!-- Settings label -->
<string name="pref_privacy_clear_cache">Clear cache</string>
<!-- Settings summary -->
- <string name="pref_privacy_clear_cache_summary">Delete all cached page content</string>
+ <string name="pref_privacy_clear_cache_summary">Clear locally cached content and databases</string>
<!-- Confirmation dialog message -->
- <string name="pref_privacy_clear_cache_dlg">The cache will be cleared.</string>
+ <string name="pref_privacy_clear_cache_dlg">Locally cached content and databases will be cleared.</string>
<!-- Settings label -->
<string name="pref_privacy_clear_cookies">Clear all cookie data</string>
<!-- Settings summary -->
@@ -327,6 +327,16 @@
<string name="pref_privacy_clear_passwords_summary">Clear all the saved passwords</string>
<!-- Confirmation dialog message -->
<string name="pref_privacy_clear_passwords_dlg">All saved passwords will be cleared.</string>
+ <!-- Settings label -->
+ <string name="pref_privacy_request_location">Enable location</string>
+ <!-- Settings summary -->
+ <string name="pref_privacy_request_location_summary">Allow sites to request access to your location</string>
+ <!-- Settings label -->
+ <string name="pref_privacy_clear_location_requests">Clear location access</string>
+ <!-- Settings summary -->
+ <string name="pref_privacy_clear_location_requests_summary">Clear location access for all websites</string>
+ <!-- Confirmation dialog message -->
+ <string name="pref_privacy_clear_location_requests_dlg">Clear all previous location requests</string>
<!-- Settings screen, section title -->
<string name="pref_security_title">Security settings</string>
<!-- Settings label -->
@@ -372,30 +382,9 @@
<!-- Settings summary -->
<string name="pref_extras_gears_enable_summary">Applications that extend browser functionality</string>
<!-- Settings label -->
- <string name="pref_extras_webstorage_settings">Local Storage</string>
+ <string name="pref_extras_website_settings">Website Settings</string>
<!-- Settings summary -->
- <string name="pref_extras_webstorage_settings_summary">Allow websites to store information on your phone</string>
- <!-- Settings label -->
- <string name="pref_extras_webstorage_enable">Enable Database Storage</string>
- <!-- Settings summary -->
- <string name="pref_extras_webstorage_enable_summary">Allow websites to store informatin in a local database</string>
- <!-- Settings label -->
- <string name="pref_extras_webstorage_set_location">Set Databases Location</string>
- <!-- Settings summary -->
- <string name="pref_extras_webstorage_set_location_summary">Define where the databases are stored</string>
- <!-- Settings label -->
- <string name="pref_extras_webstorage_set_quota">Set Default Quota</string>
- <!-- Settings summary -->
- <string name="pref_extras_webstorage_set_quota_summary">The amount of storage new websites can use without your permission</string>
- <!-- Settings label -->
- <string name="pref_extras_webstorage_manage_databases">Manage Databases</string>
- <!-- Settings summary -->
- <string name="pref_extras_webstorage_manage_databases_summary">Configure existing databases</string>
- <!-- Settings label -->
- <string name="pref_extras_webstorage_clear_databases">Clear All Existing Databases</string>
- <!-- Settings summary -->
- <string name="pref_extras_webstorage_clear_databases_summary">Clear all data stored in local databases</string>
- <string name="pref_extras_webstorage_clear_databases_dlg">All existing databases will be cleared</string>
+ <string name="pref_extras_website_settings_summary">View advanced settings for individual websites</string>
<!-- Settings label -->
<string name="pref_extras_gears_settings">Gears settings</string>
<!-- Settings summary -->
@@ -756,17 +745,15 @@
<!-- Used as a toast notification after the user close the html5 webstorage permission dialog -->
<string name="webstorage_notification">The quota for this site can be changed in the Local Storage section of the Browser settings</string>
<!-- Used in the Browser Settings -->
- <string name="webstorage_manage_quota_title">Manage Quota</string>
- <string name="webstorage_manage_quota_summary">Set a new size quota</string>
- <string name="webstorage_clear_data_title">Clear All Data</string>
+ <string name="webstorage_clear_data_title">Clear Stored Data</string>
<string name="webstorage_clear_data_summary">Remove all databases associated with this website</string>
<!-- Confirmation dialog when the user ask to clear all data for an origin -->
<string name="webstorage_clear_data_dialog_title">Clear All Data</string>
<string name="webstorage_clear_data_dialog_message">All stored data by this origin will be deleted</string>
+ <string name="webstorage_clear_data_dialog_ok_button">Clear All</string>
+ <string name="webstorage_clear_data_dialog_cancel_button">Cancel</string>
<!-- Strings used in the summary of origins -->
- <string name="webstorage_origin_summary_mb_used">MB used</string>
- <string name="webstorage_origin_summary_no_quota_left">no allowed quota left</string>
- <string name="webstorage_origin_summary_mb_left">MB left in the quota</string>
+ <string name="webstorage_origin_summary_mb_stored">MB stored on your phone</string>
<!-- Zoom-related strings --><skip />
<!-- Caption for a button that is shown when the zoom widget is showing. The button's action will switch to the zoom overview mode. -->
diff --git a/res/xml/browser_preferences.xml b/res/xml/browser_preferences.xml
index c5b6b24..f553e2b 100644
--- a/res/xml/browser_preferences.xml
+++ b/res/xml/browser_preferences.xml
@@ -126,6 +126,24 @@
android:dialogTitle="@string/clear"
android:dialogIcon="@android:drawable/ic_dialog_alert"/>
+ <!-- below preferences will be shown when html5 location is implemented -->
+ <!--
+
+ <CheckBoxPreference
+ android:key="request_location"
+ android:defaultValue="true"
+ android:title="@string/pref_privacy_request_location"
+ android:summary="@string/pref_privacy_request_location_summary" />
+
+ <com.android.browser.BrowserYesNoPreference
+ android:key="privacy_clear_location_requests"
+ android:title="@string/pref_privacy_clear_location_requests"
+ android:summary="@string/pref_privacy_clear_location_requests_summary"
+ android:dialogMessage="@string/pref_privacy_clear_location_requests_dlg"
+ android:dialogTitle="@string/clear"
+ android:dialogIcon="@android:drawable/ic_dialog_alert"/>
+ -->
+
</PreferenceCategory>
<PreferenceCategory
@@ -172,40 +190,9 @@
android:summary="@string/pref_extras_gears_settings_summary" />
<PreferenceScreen
- android:key="webstorage_settings"
- android:title="@string/pref_extras_webstorage_settings"
- android:summary="@string/pref_extras_webstorage_settings_summary">
-
- <CheckBoxPreference
- android:key="enable_database"
- android:defaultValue="true"
- android:title="@string/pref_extras_webstorage_enable"
- android:summary="@string/pref_extras_webstorage_enable_summary" />
-
- <ListPreference
- android:key="webstorage_default_quota"
- android:dependency="enable_database"
- android:title="@string/pref_extras_webstorage_set_quota"
- android:summary="@string/pref_extras_webstorage_set_quota_summary"
- android:entries="@array/webstorage_quota_entries"
- android:entryValues="@array/webstorage_quota_entries_values" />
-
- <PreferenceScreen
- android:key="webstorage_manage_databases"
- android:dependency="enable_database"
- android:title="@string/pref_extras_webstorage_manage_databases"
- android:summary="@string/pref_extras_webstorage_manage_databases_summary" />
-
- <com.android.browser.BrowserYesNoPreference
- android:key="webstorage_clear_databases"
- android:dependency="enable_database"
- android:title="@string/pref_extras_webstorage_clear_databases"
- android:summary="@string/pref_extras_webstorage_clear_databases_summary"
- android:dialogMessage="@string/pref_extras_webstorage_clear_databases_dlg"
- android:dialogTitle="@string/clear"
- android:dialogIcon="@android:drawable/ic_dialog_alert" />
-
- </PreferenceScreen>
+ android:key="website_settings"
+ android:title="@string/pref_extras_website_settings"
+ android:summary="@string/pref_extras_website_settings_summary" />
<com.android.browser.BrowserYesNoPreference
android:key="reset_default_preferences"
diff --git a/src/com/android/browser/BrowserPreferencesPage.java b/src/com/android/browser/BrowserPreferencesPage.java
index c6ce8a6..3a9505f 100644
--- a/src/com/android/browser/BrowserPreferencesPage.java
+++ b/src/com/android/browser/BrowserPreferencesPage.java
@@ -71,29 +71,25 @@
e.setOnPreferenceClickListener(this);
PreferenceScreen manageDatabases = (PreferenceScreen)
- findPreference(BrowserSettings.PREF_WEBSTORAGE_SETTINGS);
+ findPreference(BrowserSettings.PREF_WEBSITE_SETTINGS);
+ Intent intent = new Intent(this, WebsiteSettingsActivity.class);
+ manageDatabases.setIntent(intent);
+ }
- Preference clearDatabases =
- findPreference(BrowserSettings.PREF_WEBSTORAGE_CLEAR_ALL);
-
- Vector origins = WebStorage.getInstance().getOrigins();
+ /*
+ * We need to set the manageDatabases PreferenceScreen state
+ * in the onResume(), as the number of origins with databases
+ * could have changed after calling the WebsiteSettingsActivity.
+ */
+ @Override
+ protected void onResume() {
+ super.onResume();
+ PreferenceScreen manageDatabases = (PreferenceScreen)
+ findPreference(BrowserSettings.PREF_WEBSITE_SETTINGS);
manageDatabases.setEnabled(false);
- clearDatabases.setEnabled(false);
- if (origins != null) {
- if (origins.size() > 0) {
- manageDatabases.setEnabled(true);
- clearDatabases.setEnabled(true);
- }
- for (int i = 0; i < origins.size(); i++) {
- OriginSettings origin =
- new OriginSettings(this, (String) origins.get(i));
- PreferenceScreen screen =
- getPreferenceManager().createPreferenceScreen(this);
- origin.setScreen(screen);
- origin.setRootScreen(manageDatabases);
- origin.setup();
- manageDatabases.addPreference(screen);
- }
+ Vector origins = WebStorage.getInstance().getOrigins();
+ if ((origins != null) && (origins.size() > 0)) {
+ manageDatabases.setEnabled(true);
}
}
diff --git a/src/com/android/browser/BrowserQuotaPreference.java b/src/com/android/browser/BrowserQuotaPreference.java
deleted file mode 100644
index e635bb2..0000000
--- a/src/com/android/browser/BrowserQuotaPreference.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.browser;
-
-import android.preference.ListPreference;
-import android.content.Context;
-import android.preference.PreferenceScreen;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.View;
-import android.webkit.WebStorage;
-
-import java.util.Vector;
-
-/**
- * Utility class to display and manage the choosen quota
- * for an origin (HTML5 WebStorage feature)
- */
-class BrowserQuotaPreference extends ListPreference {
-
- private String TAG = "BrowserQuotaPreference";
- private OriginSettings mOrigin = null;
- private static long sOneMB = 1024 * 1024;
-
- // This is the constructor called by the inflater
- public BrowserQuotaPreference(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
-
- public BrowserQuotaPreference(Context context, OriginSettings origin) {
- super(context);
- mOrigin = origin;
- }
-
- /**
- * Find the minimum quota fitting the current usage
- * and only show larger quotas in the list
- */
- public void setQuotaList () {
- CharSequence[] entries = getEntries();
- CharSequence[] values = getEntryValues();
- Vector<CharSequence> listEntries = new Vector<CharSequence>();
- Vector<CharSequence> listValues = new Vector<CharSequence>();
- long usage = 0;
- if (mOrigin != null) {
- usage = mOrigin.getUsage();
- }
- for (int i = 0; i < values.length; i++) {
- long value = Long.parseLong(values[i].toString());
- value *= sOneMB; // the string array is expressed in MB
- if (value >= usage) {
- listEntries.add(entries[i]);
- listValues.add(values[i]);
- }
- }
- CharSequence[] newEntries = new CharSequence[listEntries.size()];
- CharSequence[] newValues = new CharSequence[listValues.size()];
- for (int i = 0; i < listEntries.size(); i++) {
- newEntries[i] = listEntries.get(i);
- newValues[i] = listValues.get(i);
- }
- setEntries(newEntries);
- setEntryValues(newValues);
- setValueIndex(0);
- }
-
- @Override
- protected View onCreateDialogView() {
- setQuotaList();
- return super.onCreateDialogView();
- }
-
- @Override
- protected void onDialogClosed(boolean positiveResult) {
- super.onDialogClosed(positiveResult);
- if (mOrigin == null) {
- return;
- }
- if (positiveResult) {
- long quota = Long.parseLong(getValue());
- quota *= sOneMB; // getValue() is in MB
- mOrigin.setQuota(quota);
- }
- }
-}
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java
index 5276ef9..2d2d39b 100644
--- a/src/com/android/browser/BrowserSettings.java
+++ b/src/com/android/browser/BrowserSettings.java
@@ -114,20 +114,13 @@
"privacy_clear_form_data";
public final static String PREF_CLEAR_PASSWORDS =
"privacy_clear_passwords";
- public final static String PREF_CLEAR_DATABASES =
- "webstorage_clear_databases";
- public final static String PREF_CLEAR_ALL_DATA =
- "webstorage_clear_all_data";
- public final static String PREF_MANAGE_QUOTA =
- "webstorage_manage_quota";
public final static String PREF_DEFAULT_QUOTA =
"webstorage_default_quota";
public final static String PREF_EXTRAS_RESET_DEFAULTS =
"reset_default_preferences";
public final static String PREF_DEBUG_SETTINGS = "debug_menu";
public final static String PREF_GEARS_SETTINGS = "gears_settings";
- public final static String PREF_WEBSTORAGE_SETTINGS = "webstorage_manage_databases";
- public final static String PREF_WEBSTORAGE_CLEAR_ALL = "webstorage_clear_databases";
+ public final static String PREF_WEBSITE_SETTINGS = "website_settings";
public final static String PREF_TEXT_SIZE = "text_size";
public final static String PREF_DEFAULT_TEXT_ENCODING =
"default_text_encoding";
@@ -491,7 +484,7 @@
// Remove all listed databases from the preferences
PreferenceActivity activity = (PreferenceActivity) context;
PreferenceScreen screen = (PreferenceScreen)
- activity.findPreference(BrowserSettings.PREF_WEBSTORAGE_SETTINGS);
+ activity.findPreference(BrowserSettings.PREF_WEBSITE_SETTINGS);
screen.removeAll();
screen.setEnabled(false);
}
diff --git a/src/com/android/browser/BrowserYesNoPreference.java b/src/com/android/browser/BrowserYesNoPreference.java
index 11a577b..ae93882 100644
--- a/src/com/android/browser/BrowserYesNoPreference.java
+++ b/src/com/android/browser/BrowserYesNoPreference.java
@@ -23,21 +23,11 @@
class BrowserYesNoPreference extends YesNoPreference {
- // This is used for the HTML5 pref UI, where we construct
- // BrowserYesNoPreference objects on the fly and where we need
- // to save the corresponding origin.
- OriginSettings mOrigin = null;
-
// This is the constructor called by the inflater
public BrowserYesNoPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
- public BrowserYesNoPreference(Context context, OriginSettings origin) {
- super(context);
- mOrigin = origin;
- }
-
@Override
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
@@ -48,6 +38,7 @@
Context context = getContext();
if (BrowserSettings.PREF_CLEAR_CACHE.equals(getKey())) {
BrowserSettings.getInstance().clearCache(context);
+ BrowserSettings.getInstance().clearDatabases(context);
} else if (BrowserSettings.PREF_CLEAR_COOKIES.equals(getKey())) {
BrowserSettings.getInstance().clearCookies(context);
} else if (BrowserSettings.PREF_CLEAR_HISTORY.equals(getKey())) {
@@ -56,12 +47,6 @@
BrowserSettings.getInstance().clearFormData(context);
} else if (BrowserSettings.PREF_CLEAR_PASSWORDS.equals(getKey())) {
BrowserSettings.getInstance().clearPasswords(context);
- } else if (BrowserSettings.PREF_CLEAR_DATABASES.equals(getKey())) {
- BrowserSettings.getInstance().clearDatabases(context);
- } else if (BrowserSettings.PREF_CLEAR_ALL_DATA.equals(getKey())) {
- if (mOrigin != null) {
- mOrigin.delete();
- }
} else if (BrowserSettings.PREF_EXTRAS_RESET_DEFAULTS.equals(
getKey())) {
BrowserSettings.getInstance().resetDefaultPreferences(context);
diff --git a/src/com/android/browser/OriginSettings.java b/src/com/android/browser/OriginSettings.java
deleted file mode 100644
index e80888a..0000000
--- a/src/com/android/browser/OriginSettings.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.browser;
-
-import android.content.Context;
-import android.preference.Preference;
-import android.preference.PreferenceActivity;
-import android.preference.PreferenceScreen;
-import android.util.Log;
-import android.webkit.WebStorage;
-
-/**
- * Manage the settings for an origin.
- * We use it to keep track of the HTML5 settings, i.e. database (webstorage).
- */
-class OriginSettings {
-
- private String TAG = "OriginSettings";
- private String mOrigin = null;
- private long mQuota = 0;
- private long mUsage = 0;
- private PreferenceScreen mInfoScreen;
- private PreferenceScreen mRootScreen;
- private PreferenceActivity mActivity;
-
- private static String sMBUsed = null;
- private static String sNoQuotaLeft = null;
- private static String sMBLeft = null;
-
- public OriginSettings(PreferenceActivity activity, String origin) {
- mOrigin = origin;
- mUsage = WebStorage.getInstance().getUsageForOrigin(mOrigin);
- mQuota = WebStorage.getInstance().getQuotaForOrigin(mOrigin);
- mActivity = activity;
- if (sMBUsed == null) {
- sMBUsed = mActivity.getString(
- R.string.webstorage_origin_summary_mb_used);
- sNoQuotaLeft = mActivity.getString(
- R.string.webstorage_origin_summary_no_quota_left);
- sMBLeft = mActivity.getString(
- R.string.webstorage_origin_summary_mb_left);
- }
- }
-
- public String getOrigin() {
- return mOrigin;
- }
-
- public long getQuota() {
- return mQuota;
- }
-
- public long getUsage() {
- return mUsage;
- }
-
- public void setScreen(PreferenceScreen screen) {
- mInfoScreen = screen;
- }
-
- public void setRootScreen(PreferenceScreen screen) {
- mRootScreen = screen;
- }
-
- private String sizeValueToString(long value) {
- float mb = (float) value / (1024.0F * 1024.0F);
- int val = (int) (mb * 10);
- float ret = (float) (val / 10.0F);
- if (ret <= 0) {
- return "0";
- }
- return String.valueOf(ret);
- }
-
- public void updateSummary() {
- String summary = sizeValueToString(mUsage) + " " + sMBUsed;
- if ((mQuota <= 0) || ((mQuota - mUsage) <= 0)) {
- summary += ", " + sNoQuotaLeft;
- } else {
- summary += " (" + sizeValueToString(mQuota - mUsage);
- summary += " " + sMBLeft + ")";
- }
- mInfoScreen.setSummary(summary);
- mActivity.onContentChanged();
- }
-
- public void setup() {
- mInfoScreen.setTitle(mOrigin);
- mInfoScreen.setKey(mOrigin);
- updateSummary();
-
- BrowserQuotaPreference manageSite = new BrowserQuotaPreference(mActivity, this);
- BrowserYesNoPreference clearAllData = new BrowserYesNoPreference(mActivity, this);
-
- manageSite.setTitle(R.string.webstorage_manage_quota_title);
- manageSite.setSummary(R.string.webstorage_manage_quota_summary);
- manageSite.setKey(BrowserSettings.PREF_MANAGE_QUOTA);
- manageSite.setEntries(R.array.webstorage_quota_entries);
- manageSite.setEntryValues(R.array.webstorage_quota_entries_values);
-
- clearAllData.setTitle(R.string.webstorage_clear_data_title);
- clearAllData.setSummary(R.string.webstorage_clear_data_summary);
- clearAllData.setKey(BrowserSettings.PREF_CLEAR_ALL_DATA);
- clearAllData.setDialogTitle(R.string.webstorage_clear_data_dialog_title);
- clearAllData.setDialogMessage(R.string.webstorage_clear_data_dialog_message);
- clearAllData.setDialogIcon(android.R.drawable.ic_dialog_alert);
-
- mInfoScreen.addPreference(manageSite);
- mInfoScreen.addPreference(clearAllData);
- }
-
- public void setQuota(long quota) {
- mQuota = quota;
- WebStorage.getInstance().setQuotaForOrigin(mOrigin, mQuota);
- mInfoScreen.getDialog().dismiss();
- updateSummary();
- }
-
- public void delete() {
- WebStorage.getInstance().deleteOrigin(mOrigin);
- mInfoScreen.removeAll();
- mRootScreen.removePreference(mInfoScreen);
- mInfoScreen.getDialog().dismiss();
- if (mRootScreen.getPreferenceCount() == 0) {
- mRootScreen.getDialog().dismiss();
- mRootScreen.setEnabled(false);
- Preference clearDatabases = mActivity.findPreference(
- BrowserSettings.PREF_WEBSTORAGE_CLEAR_ALL);
- clearDatabases.setEnabled(false);
- }
- }
-}
diff --git a/src/com/android/browser/WebsiteSettingsActivity.java b/src/com/android/browser/WebsiteSettingsActivity.java
new file mode 100644
index 0000000..7fea766
--- /dev/null
+++ b/src/com/android/browser/WebsiteSettingsActivity.java
@@ -0,0 +1,291 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.browser;
+
+import android.app.AlertDialog;
+import android.app.ListActivity;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.database.Cursor;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.net.Uri;
+import android.os.Bundle;
+import android.provider.Browser;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.webkit.WebIconDatabase;
+import android.webkit.WebStorage;
+import android.widget.ArrayAdapter;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.Vector;
+
+/**
+ * Manage the settings for an origin.
+ * We use it to keep track of the HTML5 settings, i.e. database (webstorage).
+ */
+public class WebsiteSettingsActivity extends ListActivity {
+
+ private String LOGTAG = "WebsiteSettingsActivity";
+ private static String sMBStored = null;
+ private SiteAdapter mAdapter = null;
+
+ class Site {
+ private String mOrigin;
+ private String mTitle;
+ private Bitmap mIcon;
+
+ public Site(String origin, String title, Bitmap icon) {
+ mOrigin = origin;
+ mTitle = title;
+ mIcon = icon;
+ }
+
+ public String getOrigin() {
+ return mOrigin;
+ }
+
+ public void setTitle(String title) {
+ mTitle = title;
+ }
+
+ public String getTitle() {
+ return mTitle;
+ }
+
+ public void setIcon(Bitmap icon) {
+ mIcon = icon;
+ }
+
+ public Bitmap getIcon() {
+ return mIcon;
+ }
+ }
+
+ class SiteAdapter extends ArrayAdapter<Site>
+ implements AdapterView.OnItemClickListener {
+ private int mResource;
+ private LayoutInflater mInflater;
+ private Bitmap mDefaultIcon;
+ private Site mCurrentSite;
+ private final static int STORED_DATA = 0;
+
+ public SiteAdapter(Context context, int rsc) {
+ super(context, rsc);
+ mResource = rsc;
+ mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ mDefaultIcon = BitmapFactory.decodeResource(getResources(),
+ R.drawable.ic_launcher_shortcut_browser_bookmark);
+ populateOrigins();
+ }
+
+ public void populateOrigins() {
+ clear();
+
+ // Get the list of origins we want to display
+ HashMap<String, Site> uris = new HashMap<String, Site>();
+ Vector origins = WebStorage.getInstance().getOrigins();
+ if (origins != null) {
+ for (int i = 0; i < origins.size(); i++) {
+ String origin = (String) origins.get(i);
+ Site site = new Site(origin, origin, null);
+ uris.put(Uri.parse(origin).getHost(), site);
+ }
+ }
+
+ // Check the bookmark db -- if one of our origin matches,
+ // we set its title and favicon
+ Cursor c = getContext().getContentResolver().query(Browser.BOOKMARKS_URI,
+ new String[] { Browser.BookmarkColumns.URL, Browser.BookmarkColumns.TITLE,
+ Browser.BookmarkColumns.FAVICON }, "bookmark = 1", null, null);
+
+ if ((c != null) && c.moveToFirst()) {
+ int urlIndex = c.getColumnIndex(Browser.BookmarkColumns.URL);
+ int titleIndex = c.getColumnIndex(Browser.BookmarkColumns.TITLE);
+ int faviconIndex = c.getColumnIndex(Browser.BookmarkColumns.FAVICON);
+ do {
+ String url = c.getString(urlIndex);
+ String host = Uri.parse(url).getHost();
+ if (uris.containsKey(host)) {
+ String title = c.getString(titleIndex);
+ Site site = uris.get(host);
+ site.setTitle(title);
+ byte[] data = c.getBlob(faviconIndex);
+ if (data != null) {
+ Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
+ if (bmp != null) {
+ site.setIcon(bmp);
+ }
+ }
+ }
+ } while (c.moveToNext());
+ }
+
+ // We can now simply populate our array with Site instances
+ Set keys = uris.keySet();
+ Iterator iter = keys.iterator();
+ while (iter.hasNext()) {
+ String origin = (String) iter.next();
+ Site site = uris.get(origin);
+ add(site);
+ }
+
+ if (getCount() == 0) {
+ finish(); // we close the screen
+ }
+ }
+
+ public int getCount() {
+ if (mCurrentSite == null) {
+ return super.getCount();
+ }
+ return 1; // db view
+ }
+
+ public String sizeValueToString(long value) {
+ float mb = (float) value / (1024.0F * 1024.0F);
+ int val = (int) (mb * 10);
+ float ret = (float) (val / 10.0F);
+ if (ret <= 0) {
+ return "0";
+ }
+ return String.valueOf(ret);
+ }
+
+ /*
+ * If we receive the back event and are displaying
+ * site's settings, we want to go back to the main
+ * list view. If not, we just do nothing (see
+ * dispatchKeyEvent() below).
+ */
+ public boolean backKeyPressed() {
+ if (mCurrentSite != null) {
+ mCurrentSite = null;
+ populateOrigins();
+ notifyDataSetChanged();
+ return true;
+ }
+ return false;
+ }
+
+ public View getView(int position, View convertView, ViewGroup parent) {
+ View view;
+ TextView title;
+ TextView subtitle;
+ ImageView icon;
+
+ if (convertView == null) {
+ view = mInflater.inflate(mResource, parent, false);
+ } else {
+ view = convertView;
+ }
+
+ title = (TextView) view.findViewById(R.id.title);
+ subtitle = (TextView) view.findViewById(R.id.subtitle);
+ icon = (ImageView) view.findViewById(R.id.icon);
+
+ if (mCurrentSite == null) {
+ Site site = getItem(position);
+ title.setText(site.getTitle());
+ subtitle.setText(site.getOrigin());
+ icon.setVisibility(View.VISIBLE);
+ Bitmap bmp = site.getIcon();
+ if (bmp == null) {
+ bmp = mDefaultIcon;
+ }
+ icon.setImageBitmap(bmp);
+ // We set the site as the view's tag,
+ // so that we can get it in onItemClick()
+ view.setTag(site);
+ } else {
+ icon.setVisibility(View.GONE);
+ if (position == STORED_DATA) {
+ String origin = mCurrentSite.getOrigin();
+ long usageValue = WebStorage.getInstance().getUsageForOrigin(origin);
+ String usage = sizeValueToString(usageValue) + " " + sMBStored;
+
+ title.setText(R.string.webstorage_clear_data_title);
+ subtitle.setText(usage);
+ }
+ }
+
+ return view;
+ }
+
+ public void onItemClick(AdapterView<?> parent,
+ View view,
+ int position,
+ long id) {
+ if (mCurrentSite != null) {
+ if (position == STORED_DATA) {
+ new AlertDialog.Builder(getContext())
+ .setTitle(R.string.webstorage_clear_data_dialog_title)
+ .setMessage(R.string.webstorage_clear_data_dialog_message)
+ .setPositiveButton(R.string.webstorage_clear_data_dialog_ok_button,
+ new AlertDialog.OnClickListener() {
+ public void onClick(DialogInterface dlg, int which) {
+ WebStorage.getInstance().deleteOrigin(mCurrentSite.getOrigin());
+ mCurrentSite = null;
+ populateOrigins();
+ notifyDataSetChanged();
+ }})
+ .setNegativeButton(R.string.webstorage_clear_data_dialog_cancel_button, null)
+ .setIcon(android.R.drawable.ic_dialog_alert)
+ .show();
+ }
+ } else {
+ mCurrentSite = (Site) view.getTag();
+ notifyDataSetChanged();
+ }
+ }
+ }
+
+ /**
+ * Intercepts the back key to immediately notify
+ * NativeDialog that we are done.
+ */
+ public boolean dispatchKeyEvent(KeyEvent event) {
+ if ((event.getKeyCode() == KeyEvent.KEYCODE_BACK)
+ && (event.getAction() == KeyEvent.ACTION_DOWN)) {
+ if ((mAdapter != null) && (mAdapter.backKeyPressed())){
+ return true; // event consumed
+ }
+ }
+ return super.dispatchKeyEvent(event);
+ }
+
+ @Override
+ protected void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ if (sMBStored == null) {
+ sMBStored = getString(R.string.webstorage_origin_summary_mb_stored);
+ }
+ mAdapter = new SiteAdapter(this, R.layout.application);
+ setListAdapter(mAdapter);
+ getListView().setOnItemClickListener(mAdapter);
+ }
+}