Bug 808663 - Use large favicons in awesomebar if they're provided. r=bnicholson
authorWes Johnston <wjohnston@mozilla.com>
Thu, 15 Nov 2012 19:16:35 -0800
changeset 113470 2d3acb8280f143d5213316556ad48e28ca9fc491
parent 113469 fb9a1e6e2710992df1523373b415c973be617dff
child 113471 b28da95a6959ac60648cf9f07f94b01bf63836a5
push id18166
push userwjohnston@mozilla.com
push dateFri, 16 Nov 2012 03:16:55 +0000
treeherdermozilla-inbound@2d3acb8280f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson
bugs808663
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 808663 - Use large favicons in awesomebar if they're provided. r=bnicholson
mobile/android/base/awesomebar/AllPagesTab.java
mobile/android/base/awesomebar/AwesomeBarTab.java
mobile/android/base/resources/values/dimens.xml
--- a/mobile/android/base/awesomebar/AllPagesTab.java
+++ b/mobile/android/base/awesomebar/AllPagesTab.java
@@ -571,18 +571,23 @@ public class AllPagesTab extends Awesome
             Log.e(LOGTAG, "Error getting search engine JSON", e);
         }
 
         mCursorAdapter.notifyDataSetChanged();
         filterSuggestions(mSearchTerm);
     }
 
     private Bitmap getBitmapFromDataURI(String dataURI) {
-        byte[] raw = Base64.decode(dataURI.substring(22), Base64.DEFAULT);
-        return BitmapFactory.decodeByteArray(raw, 0, raw.length);
+        try {
+            byte[] raw = Base64.decode(dataURI.substring(22), Base64.DEFAULT);
+            return BitmapFactory.decodeByteArray(raw, 0, raw.length);
+        } catch(Exception ex) {
+            Log.i(LOGTAG, "exception while decoding bitmap: " + dataURI, ex);
+        }
+        return null;
     }
 
     private void showSuggestionsOptIn() {
         mSuggestionsOptInPrompt = LayoutInflater.from(mContext).inflate(R.layout.awesomebar_suggestion_prompt, (LinearLayout)getView(), false);
         ((TextView) mSuggestionsOptInPrompt.findViewById(R.id.suggestions_prompt_title))
                 .setText(getResources().getString(R.string.suggestions_prompt, mSearchEngines.get(0).name));
         mSuggestionsOptInPrompt.findViewById(R.id.suggestions_prompt_yes).setOnClickListener(new OnClickListener() {
             public void onClick(View v) {
--- a/mobile/android/base/awesomebar/AwesomeBarTab.java
+++ b/mobile/android/base/awesomebar/AwesomeBarTab.java
@@ -36,22 +36,26 @@ abstract public class AwesomeBarTab {
     protected View.OnTouchListener mListListener;
     private AwesomeBarTabs.OnUrlOpenListener mListener;
     private LayoutInflater mInflater = null;
     private ContentResolver mContentResolver = null;
     private Resources mResources;
     // FIXME: This value should probably come from a prefs key
     public static final int MAX_RESULTS = 100;
     protected Context mContext = null;
-    private static int sFaviconSize = -1;
+    private static int sFaviconSmallSize = -1;
+    private static int sFaviconLargeSize = -1;
 
     public AwesomeBarTab(Context context) {
         mContext = context;
-        if (sFaviconSize < 0) {
-            sFaviconSize = Math.round(mContext.getResources().getDimension(R.dimen.awesomebar_row_favicon_size));
+        if (sFaviconSmallSize < 0) {
+            sFaviconSmallSize = Math.round(mContext.getResources().getDimension(R.dimen.awesomebar_row_favicon_size_small));
+        }
+        if (sFaviconLargeSize < 0) {
+            sFaviconLargeSize = Math.round(mContext.getResources().getDimension(R.dimen.awesomebar_row_favicon_size_large));
         }
     }
 
     public void setListTouchListener(View.OnTouchListener listener) {
         mListListener = listener;
         if (mView != null)
             mView.setOnTouchListener(mListListener);
     }
@@ -100,19 +104,26 @@ abstract public class AwesomeBarTab {
             Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
             updateFavicon(faviconView, bitmap);
         }
     }
 
     protected void updateFavicon(ImageView faviconView, Bitmap bitmap) {
         if (bitmap == null) {
             faviconView.setImageDrawable(null);
+        } else if (bitmap.getWidth() > 16 || bitmap.getHeight() > 16) {
+            // If the icon is larger than 16px, scale it to sFaviconLargeSize and hide the background
+            bitmap = Bitmap.createScaledBitmap(bitmap, sFaviconLargeSize, sFaviconLargeSize, false);
+            faviconView.setImageBitmap(bitmap);
+            faviconView.setBackgroundResource(0);
         } else {
-            bitmap = Bitmap.createScaledBitmap(bitmap, sFaviconSize, sFaviconSize, false);
+            // If the icon is 16px or smaller, don't scale it up to full size
+            bitmap = Bitmap.createScaledBitmap(bitmap, sFaviconSmallSize, sFaviconSmallSize, false);
             faviconView.setImageBitmap(bitmap);
+            faviconView.setBackgroundResource(R.drawable.awesomebar_row_favicon_bg);
         }
     }
 
     protected void updateTitle(TextView titleView, Cursor cursor) {
         int titleIndex = cursor.getColumnIndexOrThrow(URLColumns.TITLE);
         String title = cursor.getString(titleIndex);
 
         // Use the URL instead of an empty title for consistency with the normal URL
--- a/mobile/android/base/resources/values/dimens.xml
+++ b/mobile/android/base/resources/values/dimens.xml
@@ -10,17 +10,18 @@
     <dimen name="abouthome_gutter_large">0dp</dimen>
     <dimen name="abouthome_icon_crop">-14dp</dimen>
     <dimen name="abouthome_icon_radius">2dp</dimen>
     <dimen name="abouthome_topsite_shadow_offset">2dp</dimen>
     <dimen name="autocomplete_min_width">200dp</dimen>
     <dimen name="autocomplete_row_height">32dp</dimen>
     <dimen name="awesomebar_header_row_height">20dp</dimen>
     <dimen name="awesomebar_row_height">48dp</dimen>
-    <dimen name="awesomebar_row_favicon_size">16dp</dimen>
+    <dimen name="awesomebar_row_favicon_size_small">16dp</dimen>
+    <dimen name="awesomebar_row_favicon_size_large">32dp</dimen>
     <dimen name="awesomebar_row_favicon_bg">32dp</dimen>
     <dimen name="awesomebar_row_favicon_bg_radius">1dp</dimen>
     <dimen name="awesomebar_tab_transparency_height">38dp</dimen>
     <dimen name="browser_toolbar_height">48dp</dimen>
     <dimen name="browser_toolbar_icon_width">36dp</dimen>
     <dimen name="browser_toolbar_lock_width">21.33dp</dimen>
     <dimen name="browser_toolbar_favicon_size">29.33dip</dimen>
     <dimen name="doorhanger_arrow_width">44dp</dimen>