am be9560db: Tidy up the website settings activity. This is mostly a cosmetic change. The only functional changes are to: 1) Not dismiss the site specific settings screen when a feature is removed if that site still has more features in use, and 2) Not use the title o

Merge commit 'be9560dbeb44338070170816b1ca45b2125b7ad9' into eclair-mr2-plus-aosp

* commit 'be9560dbeb44338070170816b1ca45b2125b7ad9':
  Tidy up the website settings activity. This is mostly a cosmetic change. The only functional changes are to:
diff --git a/res/layout/website_settings_row.xml b/res/layout/website_settings_row.xml
index 4901ff1..d916978 100644
--- a/res/layout/website_settings_row.xml
+++ b/res/layout/website_settings_row.xml
@@ -18,15 +18,16 @@
   android:drawingCacheQuality="auto"
   android:layout_width="fill_parent"
   android:layout_height="?android:attr/listPreferredItemHeight"
-  android:gravity="center"
+  android:gravity="center_vertical"
   android:padding="0dip">
 
   <ImageView android:id="@+id/icon"
-    android:layout_width="32dip"
-    android:layout_height="32dip"
-    android:layout_alignParentTop="true"
-    android:layout_alignParentLeft="true"
-    android:layout_alignParentBottom="true"
+    android:layout_width="20dip"
+    android:layout_height="20dip"
+    android:layout_marginLeft="18dip"
+    android:layout_marginRight="18dip"
+    android:layout_centerVertical="true"
+    android:background="@drawable/fav_icn_background"
     android:padding="2dip" />
 
   <LinearLayout android:id="@+id/features"
@@ -49,27 +50,37 @@
       android:layout_height="32dip"
       android:padding="2dip" />
 
+    <ImageView android:id="@+id/feature_icon"
+      android:layout_width="32dip"
+      android:layout_height="32dip"
+      android:padding="2dip"
+      android:layout_centerVertical="true"
+      android:layout_alignParentRight="true"
+      android:visibility="gone" />
   </LinearLayout>
 
-  <TextView android:id="@+id/title"
+  <LinearLayout
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
-    android:layout_alignParentTop="true"
+    android:layout_toRightOf="@id/icon"
+    android:layout_toLeftOf="@id/features"
+    android:layout_centerVertical="true"
     android:layout_alignWithParentIfMissing="true"
-    android:layout_toRightOf="@id/icon"
-    android:layout_toLeftOf="@id/features"
-    android:layout_marginLeft="6dip"
-    android:layout_marginTop="6dip"
-    android:textAppearance="?android:attr/textAppearanceLarge"/>
+    android:orientation="vertical">
 
-  <TextView android:id="@+id/subtitle"
-    android:layout_width="wrap_content"
-    android:layout_height="wrap_content"
-    android:layout_toRightOf="@id/icon"
-    android:layout_toLeftOf="@id/features"
-    android:layout_below="@id/title"
-    android:layout_alignLeft="@id/title"
-    android:layout_marginBottom="2dip"
-    android:textAppearance="?android:attr/textAppearanceSmall"/>
+    <TextView android:id="@+id/title"
+      android:layout_width="wrap_content"
+      android:layout_height="wrap_content"
+      android:textAppearance="?android:attr/textAppearanceMedium"
+      android:maxLines="2"
+      android:ellipsize="end" />
 
+    <TextView android:id="@+id/subtitle"
+      android:layout_width="wrap_content"
+      android:layout_height="wrap_content"
+      android:textAppearance="?android:attr/textAppearanceSmall"
+      android:visibility="gone"
+      android:singleLine="true"
+      android:ellipsize="end" />
+  </LinearLayout>
 </RelativeLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index a4b5b9f..cc9857a 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -429,7 +429,7 @@
     <!-- Settings label -->
     <string name="pref_extras_website_settings">Website settings</string>
     <!-- Settings summary -->
-    <string name="pref_extras_website_settings_summary">View advanced settings for individual websites</string>
+    <string name="pref_extras_website_settings_summary">Advanced settings for individual websites</string>
     <!-- Settings label -->
     <string name="pref_extras_reset_default">Reset to default</string>
     <!-- Settings summary -->
diff --git a/src/com/android/browser/WebsiteSettingsActivity.java b/src/com/android/browser/WebsiteSettingsActivity.java
index 7166b16..a04c46f 100644
--- a/src/com/android/browser/WebsiteSettingsActivity.java
+++ b/src/com/android/browser/WebsiteSettingsActivity.java
@@ -88,6 +88,10 @@
             mFeatures |= (1 << feature);
         }
 
+        public void removeFeature(int feature) {
+            mFeatures &= ~(1 << feature);
+        }
+
         public boolean hasFeature(int feature) {
             return (mFeatures & (1 << feature)) != 0;
         }
@@ -168,7 +172,7 @@
             mResource = rsc;
             mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
             mDefaultIcon = BitmapFactory.decodeResource(getResources(),
-                    R.drawable.ic_launcher_shortcut_browser_bookmark);
+                    R.drawable.app_web_browser_sm);
             mUsageEmptyIcon = BitmapFactory.decodeResource(getResources(),
                     R.drawable.ic_list_data_off);
             mUsageLowIcon = BitmapFactory.decodeResource(getResources(),
@@ -280,7 +284,16 @@
                         Iterator<Site> sitesIter = matchingSites.iterator();
                         while (sitesIter.hasNext()) {
                             Site site = sitesIter.next();
-                            site.setTitle(title);
+                            // 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)) {
+                                site.setTitle(title);
+                            }
                             if (bmp != null) {
                                 site.setIcon(bmp);
                             }
@@ -323,7 +336,7 @@
             // 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");
+                Log.e(LOGTAG, "sizeValueToString called with non-positive value: " + bytes);
                 return "0";
             }
             float megabytes = (float) bytes / (1024.0F * 1024.0F);
@@ -354,8 +367,6 @@
          */
         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 < 5MB
@@ -373,9 +384,10 @@
             View view;
             final TextView title;
             final TextView subtitle;
-            ImageView icon;
+            final ImageView icon;
             final ImageView usageIcon;
             final ImageView locationIcon;
+            final ImageView featureIcon;
 
             if (convertView == null) {
                 view = mInflater.inflate(mResource, parent, false);
@@ -386,6 +398,7 @@
             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);
@@ -396,10 +409,22 @@
 
                 Site site = getItem(position);
                 title.setText(site.getPrettyTitle());
-                subtitle.setText(site.getPrettyOrigin());
+                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;
@@ -415,6 +440,7 @@
                         public void onReceiveValue(Long value) {
                             if (value != null) {
                                 setIconForUsage(usageIcon, value.longValue());
+                                usageIcon.setVisibility(View.VISIBLE);
                             }
                         }
                     });
@@ -435,8 +461,11 @@
                     });
                 }
             } else {
-                setTitle(mCurrentSite.getPrettyTitle());
                 icon.setVisibility(View.GONE);
+                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:
@@ -446,6 +475,8 @@
                                     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());
                                 }
                             }
                         });
@@ -457,9 +488,12 @@
                                 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);
                                 }
                             }
                         });
@@ -484,8 +518,14 @@
                                                new AlertDialog.OnClickListener() {
                                 public void onClick(DialogInterface dlg, int which) {
                                     WebStorage.getInstance().deleteOrigin(mCurrentSite.getOrigin());
-                                    mCurrentSite = null;
+                                    // If this site has no more features, then go back to the
+                                    // origins list.
+                                    mCurrentSite.removeFeature(Site.FEATURE_WEB_STORAGE);
+                                    if (mCurrentSite.getFeatureCount() == 0) {
+                                        mCurrentSite = null;
+                                    }
                                     askForOrigins();
+                                    notifyDataSetChanged();
                                 }})
                             .setNegativeButton(R.string.webstorage_clear_data_dialog_cancel_button, null)
                             .setIcon(android.R.drawable.ic_dialog_alert)
@@ -499,8 +539,12 @@
                                                new AlertDialog.OnClickListener() {
                                 public void onClick(DialogInterface dlg, int which) {
                                     GeolocationPermissions.getInstance().clear(mCurrentSite.getOrigin());
-                                    mCurrentSite = null;
+                                    mCurrentSite.removeFeature(Site.FEATURE_GEOLOCATION);
+                                    if (mCurrentSite.getFeatureCount() == 0) {
+                                        mCurrentSite = null;
+                                    }
                                     askForOrigins();
+                                    notifyDataSetChanged();
                                 }})
                             .setNegativeButton(R.string.geolocation_settings_page_dialog_cancel_button, null)
                             .setIcon(android.R.drawable.ic_dialog_alert)