From 05e54fd0c487fb2112678eed409e00db481523c0 Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Tue, 6 Nov 2012 19:51:06 -0800 Subject: [PATCH] Bug 808663 - Use nearest neighbor scaling for favicons in awesomescreen. r=bnicholson --- mobile/android/base/BrowserToolbar.java | 8 ++++++-- mobile/android/base/awesomebar/AllPagesTab.java | 3 ++- mobile/android/base/awesomebar/AwesomeBarTab.java | 13 +++++++++++++ mobile/android/base/awesomebar/HistoryTab.java | 2 +- .../layout-land-v14/browser_toolbar.xml.in | 2 +- .../layout-land-v14/browser_toolbar_menu.xml.in | 2 +- .../layout-large-v11/browser_toolbar_menu.xml.in | 2 +- .../layout-xlarge-v11/browser_toolbar_menu.xml.in | 2 +- .../base/resources/layout/awesomebar_row.xml | 8 ++++---- .../base/resources/layout/browser_toolbar.xml.in | 2 +- .../resources/layout/browser_toolbar_menu.xml.in | 2 +- mobile/android/base/resources/values/dimens.xml | 2 ++ 12 files changed, 34 insertions(+), 14 deletions(-) diff --git a/mobile/android/base/BrowserToolbar.java b/mobile/android/base/BrowserToolbar.java index b140b84a509..754452952e7 100644 --- a/mobile/android/base/BrowserToolbar.java +++ b/mobile/android/base/BrowserToolbar.java @@ -97,6 +97,7 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory, private TranslateAnimation mTitleSlideRight; private int mCount; + private int mFaviconSize; private static final int TABS_CONTRACTED = 1; private static final int TABS_EXPANDED = 2; @@ -226,6 +227,7 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory, mFavicon.setOnClickListener(faviconListener); if (Build.VERSION.SDK_INT >= 16) mFavicon.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO); + mFaviconSize = Math.round(mActivity.getResources().getDimension(R.dimen.browser_toolbar_favicon_size)); mSiteSecurity = (ImageButton) mLayout.findViewById(R.id.site_security); mSiteSecurity.setOnClickListener(faviconListener); @@ -683,10 +685,12 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory, if (Tabs.getInstance().getSelectedTab().getState() == Tab.STATE_LOADING) return; - if (image != null) + if (image != null) { + image = Bitmap.createScaledBitmap(image, mFaviconSize, mFaviconSize, false); mFavicon.setImageBitmap(image); - else + } else { mFavicon.setImageResource(R.drawable.favicon); + } } public void setSecurityMode(String mode) { diff --git a/mobile/android/base/awesomebar/AllPagesTab.java b/mobile/android/base/awesomebar/AllPagesTab.java index 63deae5c7dc..4eabf2aa670 100644 --- a/mobile/android/base/awesomebar/AllPagesTab.java +++ b/mobile/android/base/awesomebar/AllPagesTab.java @@ -810,7 +810,8 @@ public class AllPagesTab extends AwesomeBarTab implements GeckoEventListener { private void displayFavicon(AwesomeEntryViewHolder viewHolder) { final String url = viewHolder.urlView.getText().toString(); Favicons favicons = GeckoApp.mAppContext.getFavicons(); - viewHolder.faviconView.setImageBitmap(favicons.getFaviconFromMemCache(url)); + Bitmap bitmap = favicons.getFaviconFromMemCache(url); + updateFavicon(viewHolder.faviconView, bitmap); } private void updateFavicons() { diff --git a/mobile/android/base/awesomebar/AwesomeBarTab.java b/mobile/android/base/awesomebar/AwesomeBarTab.java index 75d0492a185..b90daaf7628 100644 --- a/mobile/android/base/awesomebar/AwesomeBarTab.java +++ b/mobile/android/base/awesomebar/AwesomeBarTab.java @@ -41,9 +41,13 @@ abstract public class AwesomeBarTab { // 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; public AwesomeBarTab(Context context) { mContext = context; + if (sFaviconSize < 0) { + sFaviconSize = Math.round(mContext.getResources().getDimension(R.dimen.awesomebar_row_favicon_size)); + } } public void setListTouchListener(View.OnTouchListener listener) { @@ -94,6 +98,15 @@ abstract public class AwesomeBarTab { faviconView.setImageDrawable(null); } else { 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 { + bitmap = Bitmap.createScaledBitmap(bitmap, sFaviconSize, sFaviconSize, false); faviconView.setImageBitmap(bitmap); } } diff --git a/mobile/android/base/awesomebar/HistoryTab.java b/mobile/android/base/awesomebar/HistoryTab.java index 1fd39c7bf1c..4e486691317 100644 --- a/mobile/android/base/awesomebar/HistoryTab.java +++ b/mobile/android/base/awesomebar/HistoryTab.java @@ -173,7 +173,7 @@ public class HistoryTab extends AwesomeBarTab { viewHolder.faviconView.setImageDrawable(null); } else { Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length); - viewHolder.faviconView.setImageBitmap(bitmap); + updateFavicon(viewHolder.faviconView, bitmap); } Integer bookmarkId = (Integer) historyItem.get(Combined.BOOKMARK_ID); diff --git a/mobile/android/base/resources/layout-land-v14/browser_toolbar.xml.in b/mobile/android/base/resources/layout-land-v14/browser_toolbar.xml.in index 44d97e9b281..b1fab86088e 100644 --- a/mobile/android/base/resources/layout-land-v14/browser_toolbar.xml.in +++ b/mobile/android/base/resources/layout-land-v14/browser_toolbar.xml.in @@ -74,7 +74,7 @@ 32dp 20dp 48dp + 32dp 38dp 48dp 36dp 21.33dp + 29.33dip 44dp 6dp 108dp