diff options
author | Pankaj Garg <pgarg@codeaurora.org> | 2015-06-03 18:13:24 -0700 |
---|---|---|
committer | jrizzoli <joey@cyanogenmoditalia.it> | 2015-08-28 13:15:45 +0200 |
commit | 32e1b940b71a96d55bd7b9cedf31fc4aacdbfec1 (patch) | |
tree | b988b99456730b9d3b0a48f8b197bff903e61803 /src/com/android/browser/preferences/WebsiteSettingsFragment.java | |
parent | 53ef89355c4cd8511d3dfc2bc5a336f7d60ad4a9 (diff) | |
download | android_packages_apps_Gello-32e1b940b71a96d55bd7b9cedf31fc4aacdbfec1.tar.gz android_packages_apps_Gello-32e1b940b71a96d55bd7b9cedf31fc4aacdbfec1.tar.bz2 android_packages_apps_Gello-32e1b940b71a96d55bd7b9cedf31fc4aacdbfec1.zip |
Security and Privacy UI
- new panel for site specific settings
- hooked up favicon to site settings
- new images for security icons
- revamped settings panels to match the new
ui layouts
Change-Id: I1e872ce353e66f78e2b0530901fcbb7de69e28b4
Diffstat (limited to 'src/com/android/browser/preferences/WebsiteSettingsFragment.java')
-rw-r--r-- | src/com/android/browser/preferences/WebsiteSettingsFragment.java | 695 |
1 files changed, 141 insertions, 554 deletions
diff --git a/src/com/android/browser/preferences/WebsiteSettingsFragment.java b/src/com/android/browser/preferences/WebsiteSettingsFragment.java index ad166357..7ffb5c17 100644 --- a/src/com/android/browser/preferences/WebsiteSettingsFragment.java +++ b/src/com/android/browser/preferences/WebsiteSettingsFragment.java @@ -25,18 +25,12 @@ import android.app.FragmentTransaction; import android.app.ListFragment; import android.content.Context; import android.content.DialogInterface; -import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; +import android.graphics.drawable.ColorDrawable; import android.net.Uri; -import android.os.AsyncTask; import android.os.Bundle; -import android.os.Parcel; -import android.os.Parcelable; -import android.preference.PreferenceActivity; -import android.util.Log; +import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; @@ -44,20 +38,21 @@ import android.view.ViewGroup; import android.webkit.ValueCallback; import android.widget.AdapterView; import android.widget.ArrayAdapter; +import android.widget.EditText; import android.widget.ImageView; import android.widget.TextView; import com.android.browser.R; import com.android.browser.WebStorageSizeManager; -import com.android.browser.platformsupport.BrowserContract.Bookmarks; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; import org.codeaurora.swe.GeolocationPermissions; +import org.codeaurora.swe.PermissionsServiceFactory; +import org.codeaurora.swe.WebRefiner; import org.codeaurora.swe.WebStorage; /** @@ -66,78 +61,24 @@ import org.codeaurora.swe.WebStorage; * and Geolocation. */ public class WebsiteSettingsFragment extends ListFragment implements OnClickListener { - - private static final String EXTRA_SITE = "site"; - private static final long MILLIS_PER_DAY = 86400000; - private String LOGTAG = "WebsiteSettingsActivity"; - private static String sMBStored = null; private SiteAdapter mAdapter = null; - private Site mSite = null; - - protected long geolocationPolicyExpiration; - protected boolean geolocationPolicyOriginAllowed; - static class Site implements Parcelable { + private class Site { private String mOrigin; private String mTitle; private Bitmap mIcon; - private int mFeatures; - - // These constants provide the set of features that a site may support - // They must be consecutive. To add a new feature, add a new FEATURE_XXX - // variable with value equal to the current value of FEATURE_COUNT, then - // increment FEATURE_COUNT. - final static int FEATURE_WEB_STORAGE = 0; - final static int FEATURE_GEOLOCATION = 1; - // The number of features available. - final static int FEATURE_COUNT = 2; public Site(String origin) { mOrigin = origin; mTitle = null; mIcon = null; - mFeatures = 0; - } - - public void addFeature(int feature) { - mFeatures |= (1 << feature); - } - - public void removeFeature(int feature) { - mFeatures &= ~(1 << feature); - } - - public boolean hasFeature(int feature) { - return (mFeatures & (1 << feature)) != 0; - } - - /** - * Gets the number of features supported by this site. - */ - public int getFeatureCount() { - int count = 0; - for (int i = 0; i < FEATURE_COUNT; ++i) { - count += hasFeature(i) ? 1 : 0; - } - return count; - } - - /** - * Gets the ID of the nth (zero-based) feature supported by this site. - * The return value is a feature ID - one of the FEATURE_XXX values. - * This is required to determine which feature is displayed at a given - * position in the list of features for this site. This is used both - * when populating the view and when responding to clicks on the list. - */ - public int getFeatureByIndex(int n) { - int j = -1; - for (int i = 0; i < FEATURE_COUNT; ++i) { - j += hasFeature(i) ? 1 : 0; - if (j == n) { - return i; - } - } - return -1; + PermissionsServiceFactory.getFavicon(origin, getActivity(), + new ValueCallback<Bitmap>() { + @Override + public void onReceiveValue(Bitmap value) { + mIcon = value; + } + }); } public String getOrigin() { @@ -165,41 +106,11 @@ public class WebsiteSettingsFragment extends ListFragment implements OnClickList } private String hideHttp(String str) { + if (str == null) + return null; Uri uri = Uri.parse(str); return "http".equals(uri.getScheme()) ? str.substring(7) : str; } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeString(mOrigin); - dest.writeString(mTitle); - dest.writeInt(mFeatures); - dest.writeParcelable(mIcon, flags); - } - - private Site(Parcel in) { - mOrigin = in.readString(); - mTitle = in.readString(); - mFeatures = in.readInt(); - mIcon = in.readParcelable(null); - } - - public static final Parcelable.Creator<Site> CREATOR - = new Parcelable.Creator<Site>() { - public Site createFromParcel(Parcel in) { - return new Site(in); - } - - public Site[] newArray(int size) { - return new Site[size]; - } - }; - } class SiteAdapter extends ArrayAdapter<Site> @@ -207,188 +118,69 @@ public class WebsiteSettingsFragment extends ListFragment implements OnClickList private int mResource; private LayoutInflater mInflater; private Bitmap mDefaultIcon; - private Bitmap mUsageEmptyIcon; - private Bitmap mUsageLowIcon; - private Bitmap mUsageHighIcon; - private Bitmap mLocationAllowedIcon; - private Bitmap mLocationDisallowedIcon; - private Site mCurrentSite; + private PermissionsServiceFactory.PermissionsService mPermServ; + private boolean mReady; 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); mDefaultIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_deco_favicon_normal); - mUsageEmptyIcon = BitmapFactory.decodeResource(getResources(), - R.drawable.ic_list_data_off); - mUsageLowIcon = BitmapFactory.decodeResource(getResources(), - R.drawable.ic_list_data_small); - mUsageHighIcon = BitmapFactory.decodeResource(getResources(), - R.drawable.ic_list_data_large); - mLocationAllowedIcon = BitmapFactory.decodeResource(getResources(), - R.drawable.ic_action_gps_on); - mLocationDisallowedIcon = BitmapFactory.decodeResource(getResources(), - R.drawable.ic_action_gps_off); - mCurrentSite = site; - if (mCurrentSite == null) { - askForOrigins(); - } - } - /** - * Adds the specified feature to the site corresponding to supplied - * origin in the map. Creates the site if it does not already exist. - */ - private void addFeatureToSite(Map<String, Site> sites, String origin, int feature) { - Site site = null; - if (sites.containsKey(origin)) { - site = (Site) sites.get(origin); - } else { - site = new Site(origin); - sites.put(origin, site); - } - site.addFeature(feature); + mReady = false; + askForOrigins(); } 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 - // safe to group origins here. Note that WebCore::SecurityOrigin - // uses 0 (which is not printed) for the port if the port is the - // 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. - - WebStorage.getInstance().getOrigins(new ValueCallback<Map>() { - public void onReceiveValue(Map origins) { - Map<String, Site> 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); - } - }); - } - - public void askForGeolocation(final Map<String, Site> sites) { - GeolocationPermissions.getInstance().getOrigins(new ValueCallback<Set<String> >() { - public void onReceiveValue(Set<String> 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<String, Site> sites) { - // Create a map from host to origin. This is used to add metadata - // (title, icon) for this origin from the bookmarks DB. We must do - // the DB access on a background thread. - new UpdateFromBookmarksDbTask(this.getContext(), sites).execute(); - } - - private class UpdateFromBookmarksDbTask extends AsyncTask<Void, Void, Void> { + if (mPermServ == null) { + PermissionsServiceFactory.getPermissionsService( + new ValueCallback<PermissionsServiceFactory.PermissionsService>() { + @Override + public void onReceiveValue( + PermissionsServiceFactory.PermissionsService value) { + mPermServ = value; + Map<String, Site> sites = new HashMap<>(); + + Set<String> origins = mPermServ.getOrigins(); + for (String origin : origins) { + if (!TextUtils.isEmpty(origin)) + sites.put(origin, new Site(origin)); + } - private Context mContext; - private boolean mDataSetChanged; - private Map<String, Site> mSites; + // Create a map from host to origin. This is used to add metadata + // (title, icon) for this origin from the bookmarks DB. We must do + // the DB access on a background thread. + //new UpdateFromBookmarksDbTask(ctx, sites).execute(); - public UpdateFromBookmarksDbTask(Context ctx, Map<String, Site> sites) { - mContext = ctx.getApplicationContext(); - mSites = sites; + populateOrigins(sites); + mReady = true; + } + } + ); } + } - protected Void doInBackground(Void... unused) { - HashMap<String, Set<Site>> hosts = new HashMap<String, Set<Site>>(); - Set<Map.Entry<String, Site>> elements = mSites.entrySet(); - Iterator<Map.Entry<String, Site>> originIter = elements.iterator(); - while (originIter.hasNext()) { - Map.Entry<String, Site> entry = originIter.next(); - Site site = entry.getValue(); - String host = Uri.parse(entry.getKey()).getHost(); - Set<Site> hostSites = null; - if (hosts.containsKey(host)) { - hostSites = (Set<Site>)hosts.get(host); - } else { - hostSites = new HashSet<Site>(); - hosts.put(host, hostSites); + public void deleteAllOrigins() { + if (mPermServ != null) { + Set<String> origins = mPermServ.getOrigins(); + String[] originArray = origins.toArray(new String[origins.size()]); + for (String origin : originArray) { + PermissionsServiceFactory.PermissionsService.OriginInfo info = + mPermServ.getOriginInfo(origin); + if (info != null) { + mPermServ.deleteOriginInfo(info); } - hostSites.add(site); } - // Check the bookmark DB. If we have data for a host used by any of - // our origins, use it to set their title and favicon - Cursor c = mContext.getContentResolver().query(Bookmarks.CONTENT_URI, - new String[] { Bookmarks.URL, Bookmarks.TITLE, Bookmarks.FAVICON }, - Bookmarks.IS_FOLDER + " == 0", null, null); - - if (c != null) { - if (c.moveToFirst()) { - int urlIndex = c.getColumnIndex(Bookmarks.URL); - int titleIndex = c.getColumnIndex(Bookmarks.TITLE); - int faviconIndex = c.getColumnIndex(Bookmarks.FAVICON); - do { - String url = c.getString(urlIndex); - String host = Uri.parse(url).getHost(); - if (hosts.containsKey(host)) { - String title = c.getString(titleIndex); - Bitmap bmp = null; - byte[] data = c.getBlob(faviconIndex); - if (data != null) { - bmp = BitmapFactory.decodeByteArray(data, 0, data.length); - } - Set matchingSites = (Set) hosts.get(host); - Iterator<Site> sitesIter = matchingSites.iterator(); - while (sitesIter.hasNext()) { - Site site = sitesIter.next(); - // We should only set the title if the bookmark is for the root - // (i.e. www.google.com), as website settings act on the origin - // as a whole rather than a single page under that origin. If the - // user has bookmarked a page under the root but *not* the root, - // then we risk displaying the title of that page which may or - // may not have any relevance to the origin. - if (url.equals(site.getOrigin()) || - (new String(site.getOrigin()+"/")).equals(url)) { - mDataSetChanged = true; - site.setTitle(title); - } - - if (bmp != null) { - mDataSetChanged = true; - site.setIcon(bmp); - } - } - } - } while (c.moveToNext()); - } - c.close(); - } - return null; - } - - protected void onPostExecute(Void unused) { - if (mDataSetChanged) { - notifyDataSetChanged(); + WebRefiner refiner = WebRefiner.getInstance(); + if (refiner != null) { + refiner.useGlobalRulesForDomains(originArray); } } } - - public void populateOrigins(Map<String, Site> sites) { + private void populateOrigins(Map<String, Site> sites) { clear(); // We can now simply populate our array with Site instances @@ -407,70 +199,12 @@ public class WebsiteSettingsFragment extends ListFragment implements OnClickList } } - public int getCount() { - if (mCurrentSite == null) { - return super.getCount(); - } - return mCurrentSite.getFeatureCount(); - } - - public String sizeValueToString(long bytes) { - // We display the size in MB, to 1dp, rounding up to the next 0.1MB. - // bytes should always be greater than zero. - if (bytes <= 0) { - Log.e(LOGTAG, "sizeValueToString called with non-positive value: " + bytes); - return "0"; - } - float megabytes = (float) bytes / (1024.0F * 1024.0F); - int truncated = (int) Math.ceil(megabytes * 10.0F); - float result = (float) (truncated / 10.0F); - return String.valueOf(result); - } - - /* - * 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; - 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); - // We set the correct icon: - // 0 < empty < 0.1MB - // 0.1MB < low < 5MB - // 5MB < high - if (usageInMegabytes <= 0.1) { - usageIcon.setImageBitmap(mUsageEmptyIcon); - } else if (usageInMegabytes > 0.1 && usageInMegabytes <= 5) { - usageIcon.setImageBitmap(mUsageLowIcon); - } else if (usageInMegabytes > 5) { - usageIcon.setImageBitmap(mUsageHighIcon); - } - } - @Override public View getView(int position, View convertView, ViewGroup parent) { View view; final TextView title; final TextView subtitle; final ImageView icon; - final ImageView usageIcon; - final ImageView locationIcon; - final ImageView featureIcon; if (convertView == null) { view = mInflater.inflate(mResource, parent, false); @@ -481,106 +215,30 @@ public class WebsiteSettingsFragment extends ListFragment implements OnClickList title = (TextView) view.findViewById(R.id.title); subtitle = (TextView) view.findViewById(R.id.subtitle); icon = (ImageView) view.findViewById(R.id.icon); - featureIcon = (ImageView) view.findViewById(R.id.feature_icon); - usageIcon = (ImageView) view.findViewById(R.id.usage_icon); - locationIcon = (ImageView) view.findViewById(R.id.location_icon); - usageIcon.setVisibility(View.GONE); - locationIcon.setVisibility(View.GONE); - - if (mCurrentSite == null) { - - Site site = getItem(position); - title.setText(site.getPrettyTitle()); - String subtitleText = site.getPrettyOrigin(); - if (subtitleText != null) { - title.setMaxLines(1); - title.setSingleLine(true); - subtitle.setVisibility(View.VISIBLE); - subtitle.setText(subtitleText); - } else { - subtitle.setVisibility(View.GONE); - title.setMaxLines(2); - title.setSingleLine(false); - } - - icon.setVisibility(View.VISIBLE); - usageIcon.setVisibility(View.INVISIBLE); - locationIcon.setVisibility(View.INVISIBLE); - featureIcon.setVisibility(View.GONE); - 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); - - String origin = site.getOrigin(); - if (site.hasFeature(Site.FEATURE_WEB_STORAGE)) { - WebStorage.getInstance().getUsageForOrigin(origin, new ValueCallback<Long>() { - public void onReceiveValue(Long value) { - if (value != null) { - setIconForUsage(usageIcon, value.longValue()); - usageIcon.setVisibility(View.VISIBLE); - } - } - }); - } - if (site.hasFeature(Site.FEATURE_GEOLOCATION)) { - locationIcon.setVisibility(View.VISIBLE); - GeolocationPermissions.getInstance().getAllowed(origin, new ValueCallback<Boolean>() { - public void onReceiveValue(Boolean allowed) { - if (allowed != null) { - if (allowed.booleanValue()) { - locationIcon.setImageBitmap(mLocationAllowedIcon); - } else { - locationIcon.setImageBitmap(mLocationDisallowedIcon); - } - } - } - }); - } + Site site = getItem(position); + title.setText(site.getPrettyTitle()); + String subtitleText = site.getPrettyOrigin(); + if (subtitleText != null) { + title.setMaxLines(1); + title.setSingleLine(true); + subtitle.setVisibility(View.VISIBLE); + subtitle.setText(subtitleText); } else { - icon.setVisibility(View.GONE); - locationIcon.setVisibility(View.GONE); - usageIcon.setVisibility(View.GONE); - featureIcon.setVisibility(View.VISIBLE); - String origin = mCurrentSite.getOrigin(); - switch (mCurrentSite.getFeatureByIndex(position)) { - case Site.FEATURE_WEB_STORAGE: - 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); - subtitle.setVisibility(View.VISIBLE); - setIconForUsage(featureIcon, value.longValue()); - } - } - }); - break; - case Site.FEATURE_GEOLOCATION: - title.setText(R.string.geolocation_settings_page_title); - 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); - featureIcon.setImageBitmap(mLocationAllowedIcon); - } else { - subtitle.setText(R.string.geolocation_settings_page_summary_not_allowed); - featureIcon.setImageBitmap(mLocationDisallowedIcon); - } - subtitle.setVisibility(View.VISIBLE); - } - } - }); - break; - } + subtitle.setVisibility(View.GONE); + title.setMaxLines(2); + title.setSingleLine(false); + } + + 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); return view; } @@ -589,142 +247,41 @@ public class WebsiteSettingsFragment extends ListFragment implements OnClickList View view, int position, long id) { - if (mCurrentSite != null) { - switch (mCurrentSite.getFeatureByIndex(position)) { - case Site.FEATURE_WEB_STORAGE: - new AlertDialog.Builder(getContext()) - .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()); - // If this site has no more features, then go back to the - // origins list. - mCurrentSite.removeFeature(Site.FEATURE_WEB_STORAGE); - if (mCurrentSite.getFeatureCount() == 0) { - finish(); - } - askForOrigins(); - notifyDataSetChanged(); - }}) - .setNegativeButton(R.string.webstorage_clear_data_dialog_cancel_button, null) - .setIconAttribute(android.R.attr.alertDialogIcon) - .show(); - break; - case Site.FEATURE_GEOLOCATION: - final AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); - final String origin = mCurrentSite.getOrigin(); - final GeolocationPermissions geolocationPermissions - = GeolocationPermissions.getInstance(); - - DialogInterface.OnClickListener alertDialogListener = - new AlertDialog.OnClickListener() { - public void onClick(DialogInterface dlg, int which) { - GeolocationPermissions geolocationPermissions = - GeolocationPermissions.getInstance(); - String origin = mCurrentSite.getOrigin(); - int selectedPosition = ((AlertDialog)dlg) - .getListView().getCheckedItemPosition(); - switch (selectedPosition) { - case 0: // Deny forever - geolocationPermissions.deny(origin); - break; - case 1: - // Allow for 24 hours - geolocationPermissions.allow(origin, - System.currentTimeMillis() + MILLIS_PER_DAY); - break; - case 2: // Allow forever - geolocationPermissions.allow(origin); - break; - case 3: // Always ask - geolocationPermissions.clear(origin); - mCurrentSite.removeFeature(Site.FEATURE_GEOLOCATION); - if (mCurrentSite.getFeatureCount() == 0) { - finish(); - } - break; - default: - break; - } - askForOrigins(); - notifyDataSetChanged(); - }}; - - builder.setTitle(String.format(getResources() - .getString(R.string.geolocation_settings_page_dialog_title), - "http".equals(Uri.parse(mCurrentSite.getOrigin()).getScheme()) ? - origin.substring(7) : origin )) - .setPositiveButton(R.string.geolocation_settings_page_dialog_ok_button, - alertDialogListener) - .setNegativeButton(R.string.geolocation_settings_page_dialog_cancel_button, null); - - switch(geolocationPermissions.getContentSetting(origin)) { - case BLOCK: - builder.setSingleChoiceItems(R.array.geolocation_settings_choices, - 0, null); - break; - case ALLOW_24H: - builder.setSingleChoiceItems(R.array.geolocation_settings_choices, - 1, null); - break; - case ALLOW: - builder.setSingleChoiceItems(R.array.geolocation_settings_choices, - 2, null); - break; - } - builder.show(); - } - } else { - Site site = (Site) view.getTag(); - Activity activity = getActivity(); - if (activity != null) { - Bundle args = new Bundle(); - args.putParcelable(EXTRA_SITE, site); - - FragmentManager fragmentManager = activity.getFragmentManager(); - FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); - - Fragment newFragment = new WebsiteSettingsFragment(); - newFragment.setArguments(args); - fragmentTransaction.replace(getId(), newFragment); - fragmentTransaction.addToBackStack(null); - fragmentTransaction.commit(); - } + Site site = (Site) view.getTag(); + Activity activity = getActivity(); + if (activity != null) { + Bundle args = new Bundle(); + args.putString(SiteSpecificPreferencesFragment.EXTRA_ORIGIN, site.getOrigin()); + + FragmentManager fragmentManager = activity.getFragmentManager(); + FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); + + Fragment newFragment = new SiteSpecificPreferencesFragment(); + newFragment.setArguments(args); + fragmentTransaction.replace(getId(), newFragment); + fragmentTransaction.addToBackStack(null); + fragmentTransaction.commit(); } } - - public Site currentSite() { - return mCurrentSite; - } } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.swe_website_settings, container, false); - Bundle args = getArguments(); - if (args != null) { - mSite = (Site) args.getParcelable(EXTRA_SITE); - } - if (mSite == null) { - View clear = view.findViewById(R.id.clear_all_button); - clear.setVisibility(View.VISIBLE); - clear.setOnClickListener(this); - } + View new_site = view.findViewById(R.id.add_new_site); + new_site.setVisibility(View.VISIBLE); + new_site.setOnClickListener(this); + View clear = view.findViewById(R.id.clear_all_button); + clear.setVisibility(View.VISIBLE); + clear.setOnClickListener(this); return view; } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - if (sMBStored == null) { - sMBStored = getString(R.string.webstorage_origin_summary_mb_stored); - } mAdapter = new SiteAdapter(getActivity(), R.layout.website_settings_row); - if (mSite != null) { - mAdapter.mCurrentSite = mSite; - } getListView().setAdapter(mAdapter); getListView().setOnItemClickListener(mAdapter); } @@ -738,6 +295,7 @@ public class WebsiteSettingsFragment extends ListFragment implements OnClickList bar.setTitle(R.string.pref_extras_website_settings); bar.setDisplayHomeAsUpEnabled(false); bar.setHomeButtonEnabled(false); + bar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.accent))); } } @@ -752,24 +310,53 @@ public class WebsiteSettingsFragment extends ListFragment implements OnClickList 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. + // Show the prompt to clear all origins of their data and geolocation permissions. new AlertDialog.Builder(getActivity()) - .setMessage(R.string.website_settings_clear_all_dialog_message) - .setPositiveButton(R.string.website_settings_clear_all_dialog_ok_button, + .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) { + mAdapter.deleteAllOrigins(); + WebStorage.getInstance().deleteAllData(); + GeolocationPermissions.getInstance().clearAll(); + if (GeolocationPermissions.isIncognitoCreated()) { + GeolocationPermissions.getIncognitoInstance().clearAll(); + } + WebStorageSizeManager.resetLastOutOfSpaceNotificationTime(); + mAdapter.askForOrigins(); + finish(); + } + }) + .setNegativeButton(R.string.website_settings_clear_all_dialog_cancel_button, null) + .setIconAttribute(android.R.attr.alertDialogIcon) + .show(); + break; + case R.id.add_new_site: + final EditText input = new EditText(getActivity()); + new AlertDialog.Builder(getActivity()) + .setTitle(R.string.website_settings_add_origin) + .setMessage(R.string.pref_security_origin_name) + .setView(input) + .setPositiveButton(R.string.pref_security_add, new AlertDialog.OnClickListener() { - public void onClick(DialogInterface dlg, int which) { - WebStorage.getInstance().deleteAllData(); - GeolocationPermissions.getInstance().clearAll(); - if (GeolocationPermissions.isIncognitoCreated()) { - GeolocationPermissions.getIncognitoInstance().clearAll(); - } - WebStorageSizeManager.resetLastOutOfSpaceNotificationTime(); - mAdapter.askForOrigins(); - finish(); + public void onClick(DialogInterface dialog, int whichButton) { + String origin = input.getText().toString(); + Bundle args = new Bundle(); + args.putString(SiteSpecificPreferencesFragment.EXTRA_SITE, + origin); + + FragmentTransaction fragmentTransaction = + getActivity().getFragmentManager().beginTransaction(); + + Fragment newFragment = new SiteSpecificPreferencesFragment(); + newFragment.setArguments(args); + fragmentTransaction.replace(getId(), newFragment); + fragmentTransaction.addToBackStack(null); + fragmentTransaction.commit(); }}) - .setNegativeButton(R.string.website_settings_clear_all_dialog_cancel_button, null) - .setIconAttribute(android.R.attr.alertDialogIcon) + .setNegativeButton(R.string.pref_security_cancel, null) .show(); + break; } } |