summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2010-11-29 16:01:11 -0800
committerJohn Reck <jreck@google.com>2010-11-30 09:53:08 -0800
commit10200795554ffeb16bf5662fd66ae6442c6f5cf0 (patch)
tree08b07d9ba15a6d423f82a0d3f2984aa98b50c510 /src/com/android/browser
parentc9d0fdde15f7cefb29a5eb3f659890b2c4917f82 (diff)
downloadpackages_apps_Browser-10200795554ffeb16bf5662fd66ae6442c6f5cf0.zip
packages_apps_Browser-10200795554ffeb16bf5662fd66ae6442c6f5cf0.tar.gz
packages_apps_Browser-10200795554ffeb16bf5662fd66ae6442c6f5cf0.tar.bz2
Changed WebsiteSettingsActivity to fragment
Bug: 3231307 Moved WebsiteSettingsActivity to a fragment Change-Id: If1fa56ab48167c004fb65c756f325e108f14fe8f
Diffstat (limited to 'src/com/android/browser')
-rw-r--r--src/com/android/browser/WebStorageSizeManager.java12
-rw-r--r--src/com/android/browser/preferences/AdvancedPreferencesFragment.java5
-rw-r--r--src/com/android/browser/preferences/WebsiteSettingsFragment.java (renamed from src/com/android/browser/WebsiteSettingsActivity.java)145
3 files changed, 89 insertions, 73 deletions
diff --git a/src/com/android/browser/WebStorageSizeManager.java b/src/com/android/browser/WebStorageSizeManager.java
index dcf2f8b..5f76f72 100644
--- a/src/com/android/browser/WebStorageSizeManager.java
+++ b/src/com/android/browser/WebStorageSizeManager.java
@@ -16,17 +16,19 @@
package com.android.browser;
+import com.android.browser.preferences.WebsiteSettingsFragment;
+
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.StatFs;
+import android.preference.PreferenceActivity;
import android.util.Log;
import android.webkit.WebStorage;
import java.io.File;
-import java.util.Set;
/**
@@ -82,7 +84,7 @@ import java.util.Set;
* the user can free some of the Web storage space by deleting all the data used
* by an origin.
*/
-class WebStorageSizeManager {
+public class WebStorageSizeManager {
// Logging flags.
private final static boolean LOGV_ENABLED = com.android.browser.Browser.LOGV_ENABLED;
private final static boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED;
@@ -346,7 +348,7 @@ class WebStorageSizeManager {
// Reset the notification time; we use this iff the user
// use clear all; we reset it to some time in the future instead
// of just setting it to -1, as the clear all method is asynchronous
- static void resetLastOutOfSpaceNotificationTime() {
+ public static void resetLastOutOfSpaceNotificationTime() {
mLastOutOfSpaceNotificationTime = System.currentTimeMillis() -
NOTIFICATION_INTERVAL + RESET_NOTIFICATION_INTERVAL;
}
@@ -403,7 +405,9 @@ class WebStorageSizeManager {
CharSequence text = mContext.getString(
R.string.webstorage_outofspace_notification_text);
long when = System.currentTimeMillis();
- Intent intent = new Intent(mContext, WebsiteSettingsActivity.class);
+ Intent intent = new Intent(mContext, BrowserPreferencesPage.class);
+ intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT,
+ WebsiteSettingsFragment.class.getName());
PendingIntent contentIntent =
PendingIntent.getActivity(mContext, 0, intent, 0);
Notification notification = new Notification(icon, title, when);
diff --git a/src/com/android/browser/preferences/AdvancedPreferencesFragment.java b/src/com/android/browser/preferences/AdvancedPreferencesFragment.java
index 59b6ce1..952e04a 100644
--- a/src/com/android/browser/preferences/AdvancedPreferencesFragment.java
+++ b/src/com/android/browser/preferences/AdvancedPreferencesFragment.java
@@ -18,9 +18,7 @@ package com.android.browser.preferences;
import com.android.browser.BrowserSettings;
import com.android.browser.R;
-import com.android.browser.WebsiteSettingsActivity;
-import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
@@ -44,8 +42,7 @@ public class AdvancedPreferencesFragment extends PreferenceFragment
PreferenceScreen websiteSettings = (PreferenceScreen) findPreference(
BrowserSettings.PREF_WEBSITE_SETTINGS);
- Intent intent = new Intent(getActivity(), WebsiteSettingsActivity.class);
- websiteSettings.setIntent(intent);
+ websiteSettings.setFragment(WebsiteSettingsFragment.class.getName());
}
/*
diff --git a/src/com/android/browser/WebsiteSettingsActivity.java b/src/com/android/browser/preferences/WebsiteSettingsFragment.java
index 95f8fb0..1965ffe 100644
--- a/src/com/android/browser/WebsiteSettingsActivity.java
+++ b/src/com/android/browser/preferences/WebsiteSettingsFragment.java
@@ -14,56 +14,62 @@
* limitations under the License.
*/
-package com.android.browser;
+package com.android.browser.preferences;
+
+import com.android.browser.R;
+import com.android.browser.WebStorageSizeManager;
import android.app.AlertDialog;
-import android.app.ListActivity;
+import android.app.FragmentTransaction;
+import android.app.ListFragment;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceFragment;
import android.provider.BrowserContract.Bookmarks;
import android.util.Log;
-import android.view.KeyEvent;
import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
+import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.GeolocationPermissions;
import android.webkit.ValueCallback;
-import android.webkit.WebIconDatabase;
import android.webkit.WebStorage;
-import android.widget.ArrayAdapter;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
+import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
+import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
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)
* and Geolocation.
*/
-public class WebsiteSettingsActivity extends ListActivity {
+public class WebsiteSettingsFragment extends ListFragment implements OnClickListener {
+ private static final String EXTRA_SITE = "site";
private String LOGTAG = "WebsiteSettingsActivity";
private static String sMBStored = null;
private SiteAdapter mAdapter = null;
+ private Site mSite = null;
- static class Site {
+ static class Site implements Serializable {
private String mOrigin;
private String mTitle;
private Bitmap mIcon;
@@ -169,6 +175,10 @@ public class WebsiteSettingsActivity extends ListActivity {
private Site mCurrentSite;
public SiteAdapter(Context context, int rsc) {
+ this(context, rsc, null);
+ }
+
+ public SiteAdapter(Context context, int rsc, Site site) {
super(context, rsc);
mResource = rsc;
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@@ -184,7 +194,10 @@ public class WebsiteSettingsActivity extends ListActivity {
R.drawable.ic_list_gps_on);
mLocationDisallowedIcon = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_list_gps_denied);
- askForOrigins();
+ mCurrentSite = site;
+ if (mCurrentSite == null) {
+ askForOrigins();
+ }
}
/**
@@ -409,6 +422,7 @@ public class WebsiteSettingsActivity extends ListActivity {
}
}
+ @Override
public View getView(int position, View convertView, ViewGroup parent) {
View view;
final TextView title;
@@ -434,7 +448,6 @@ public class WebsiteSettingsActivity extends ListActivity {
locationIcon.setVisibility(View.GONE);
if (mCurrentSite == null) {
- setTitle(getString(R.string.pref_extras_website_settings));
Site site = getItem(position);
title.setText(site.getPrettyTitle());
@@ -494,7 +507,6 @@ public class WebsiteSettingsActivity extends ListActivity {
locationIcon.setVisibility(View.GONE);
usageIcon.setVisibility(View.GONE);
featureIcon.setVisibility(View.VISIBLE);
- setTitle(mCurrentSite.getPrettyTitle());
String origin = mCurrentSite.getOrigin();
switch (mCurrentSite.getFeatureByIndex(position)) {
case Site.FEATURE_WEB_STORAGE:
@@ -551,7 +563,7 @@ public class WebsiteSettingsActivity extends ListActivity {
// origins list.
mCurrentSite.removeFeature(Site.FEATURE_WEB_STORAGE);
if (mCurrentSite.getFeatureCount() == 0) {
- mCurrentSite = null;
+ finish();
}
askForOrigins();
notifyDataSetChanged();
@@ -570,7 +582,7 @@ public class WebsiteSettingsActivity extends ListActivity {
GeolocationPermissions.getInstance().clear(mCurrentSite.getOrigin());
mCurrentSite.removeFeature(Site.FEATURE_GEOLOCATION);
if (mCurrentSite.getFeatureCount() == 0) {
- mCurrentSite = null;
+ finish();
}
askForOrigins();
notifyDataSetChanged();
@@ -581,8 +593,14 @@ public class WebsiteSettingsActivity extends ListActivity {
break;
}
} else {
- mCurrentSite = (Site) view.getTag();
- notifyDataSetChanged();
+ Site site = (Site) view.getTag();
+ PreferenceActivity activity = (PreferenceActivity) getActivity();
+ if (activity != null) {
+ Bundle args = new Bundle();
+ args.putSerializable(EXTRA_SITE, site);
+ activity.startPreferencePanel(WebsiteSettingsFragment.class.getName(), args, 0,
+ site.getPrettyTitle(), null, 0);
+ }
}
}
@@ -591,67 +609,64 @@ public class WebsiteSettingsActivity extends ListActivity {
}
}
- /**
- * 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
- }
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.website_settings, container, false);
+ Bundle args = getArguments();
+ if (args != null) {
+ mSite = (Site) args.getSerializable(EXTRA_SITE);
+ }
+ if (mSite == null) {
+ View clear = view.findViewById(R.id.clear_all_button);
+ clear.setVisibility(View.VISIBLE);
+ clear.setOnClickListener(this);
}
- return super.dispatchKeyEvent(event);
+ return view;
}
@Override
- protected void onCreate(Bundle icicle) {
- super.onCreate(icicle);
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
if (sMBStored == null) {
sMBStored = getString(R.string.webstorage_origin_summary_mb_stored);
}
- mAdapter = new SiteAdapter(this, R.layout.website_settings_row);
- setListAdapter(mAdapter);
+ mAdapter = new SiteAdapter(getActivity(), R.layout.website_settings_row);
+ if (mSite != null) {
+ mAdapter.mCurrentSite = mSite;
+ }
+ getListView().setAdapter(mAdapter);
getListView().setOnItemClickListener(mAdapter);
}
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.websitesettings, menu);
- return true;
- }
-
- @Override
- public boolean onPrepareOptionsMenu(Menu menu) {
- // If we are not on the sites list (rather on the page for a specific site) or
- // we aren't listing any sites hide the clear all button (and hence the menu).
- return mAdapter.currentSite() == null && mAdapter.getCount() > 0;
+ private void finish() {
+ PreferenceActivity activity = (PreferenceActivity) getActivity();
+ if (activity != null) {
+ activity.finishPreferencePanel(this, 0, null);
+ }
}
@Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.website_settings_menu_clear_all:
- // Show the prompt to clear all origins of their data and geolocation permissions.
- new AlertDialog.Builder(this)
- .setTitle(R.string.website_settings_clear_all_dialog_title)
- .setMessage(R.string.website_settings_clear_all_dialog_message)
- .setPositiveButton(R.string.website_settings_clear_all_dialog_ok_button,
- new AlertDialog.OnClickListener() {
- public void onClick(DialogInterface dlg, int which) {
- WebStorage.getInstance().deleteAllData();
- GeolocationPermissions.getInstance().clearAll();
- WebStorageSizeManager.resetLastOutOfSpaceNotificationTime();
- mAdapter.askForOrigins();
- finish();
- }})
- .setNegativeButton(R.string.website_settings_clear_all_dialog_cancel_button, null)
- .setIcon(android.R.drawable.ic_dialog_alert)
- .show();
- return true;
+ public void onClick(View v) {
+ switch (v.getId()) {
+ case R.id.clear_all_button:
+ // Show the prompt to clear all origins of their data and geolocation permissions.
+ new AlertDialog.Builder(getActivity())
+ .setTitle(R.string.website_settings_clear_all_dialog_title)
+ .setMessage(R.string.website_settings_clear_all_dialog_message)
+ .setPositiveButton(R.string.website_settings_clear_all_dialog_ok_button,
+ new AlertDialog.OnClickListener() {
+ public void onClick(DialogInterface dlg, int which) {
+ WebStorage.getInstance().deleteAllData();
+ GeolocationPermissions.getInstance().clearAll();
+ WebStorageSizeManager.resetLastOutOfSpaceNotificationTime();
+ mAdapter.askForOrigins();
+ finish();
+ }})
+ .setNegativeButton(R.string.website_settings_clear_all_dialog_cancel_button, null)
+ .setIcon(android.R.drawable.ic_dialog_alert)
+ .show();
+ break;
}
- return false;
}
}