Bug 1007645 - Don't use opacity filter on suggested sites' background (r=mfinkle)
authorLucas Rocha <lucasr@mozilla.com>
Fri, 09 May 2014 16:40:02 +0100
changeset 182351 191d414062112ec3606becd7167ef6b2c690c3f1
parent 182350 92c4779c8f45e0733aa48d8a8f38518b9ecda6d1
child 182352 007380afa681e1dcca4a9d29068eff49a9945a90
push id26758
push userryanvm@gmail.com
push dateFri, 09 May 2014 19:37:26 +0000
treeherdermozilla-central@007380afa681 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs1007645
milestone32.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 1007645 - Don't use opacity filter on suggested sites' background (r=mfinkle)
mobile/android/base/home/TopSitesGridItemView.java
mobile/android/base/home/TopSitesThumbnailView.java
--- a/mobile/android/base/home/TopSitesGridItemView.java
+++ b/mobile/android/base/home/TopSitesGridItemView.java
@@ -34,17 +34,17 @@ public class TopSitesGridItemView extend
     private static final int[] STATE_EMPTY = { android.R.attr.state_empty };
 
     private static final ScaleType SCALE_TYPE_FAVICON   = ScaleType.CENTER;
     private static final ScaleType SCALE_TYPE_RESOURCE  = ScaleType.CENTER;
     private static final ScaleType SCALE_TYPE_THUMBNAIL = ScaleType.CENTER_CROP;
 
     // Child views.
     private final TextView mTitleView;
-    private final ImageView mThumbnailView;
+    private final TopSitesThumbnailView mThumbnailView;
 
     // Data backing this view.
     private String mTitle;
     private String mUrl;
     private String mFaviconURL;
 
     private boolean mThumbnailSet;
 
@@ -66,17 +66,17 @@ public class TopSitesGridItemView extend
     }
 
     public TopSitesGridItemView(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
 
         LayoutInflater.from(context).inflate(R.layout.top_sites_grid_item_view, this);
 
         mTitleView = (TextView) findViewById(R.id.title);
-        mThumbnailView = (ImageView) findViewById(R.id.thumbnail);
+        mThumbnailView = (TopSitesThumbnailView) findViewById(R.id.thumbnail);
     }
 
     /**
      * {@inheritDoc}
      */
     @Override
     public int[] onCreateDrawableState(int extraSpace) {
         final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
@@ -281,17 +281,18 @@ public class TopSitesGridItemView extend
         if (faviconURL != null) {
             mFaviconURL = faviconURL;
         }
 
         mThumbnailView.setScaleType(SCALE_TYPE_FAVICON);
         mThumbnailView.setImageBitmap(favicon);
 
         if (mFaviconURL != null) {
-            mThumbnailView.setBackgroundColor(Favicons.getFaviconColor(mFaviconURL));
+            final int bgColor = Favicons.getFaviconColor(mFaviconURL);
+            mThumbnailView.setBackgroundColorWithOpacityFilter(bgColor);
         }
     }
 
     /**
      * Update the title shown by this view. If both title and url
      * are empty, mark the state as STATE_EMPTY and show a default text.
      */
     private void updateTitleView() {
--- a/mobile/android/base/home/TopSitesThumbnailView.java
+++ b/mobile/android/base/home/TopSitesThumbnailView.java
@@ -83,20 +83,32 @@ public class TopSitesThumbnailView exten
 
         if (getBackground() == null) {
             sBorderPaint.setStrokeWidth(mStrokeWidth);
             canvas.drawRect(0, 0, getWidth(), getHeight(), sBorderPaint);
         }
     }
 
     /**
+     * Sets the background color with a filter to reduce the color opacity.
+     *
+     * @param color the color filter to apply over the drawable.
+     */
+    public void setBackgroundColorWithOpacityFilter(int color) {
+        setBackgroundColor(color & COLOR_FILTER);
+    }
+
+    /**
      * Sets the background to a Drawable by applying the specified color as a filter.
      *
      * @param color the color filter to apply over the drawable.
      */
     @Override
     public void setBackgroundColor(int color) {
-        int colorFilter = color == 0 ? DEFAULT_COLOR : color & COLOR_FILTER;
+        if (color == 0) {
+            color = DEFAULT_COLOR;
+        }
+
         Drawable drawable = getResources().getDrawable(R.drawable.top_sites_thumbnail_bg);
-        drawable.setColorFilter(colorFilter, Mode.SRC_ATOP);
+        drawable.setColorFilter(color, Mode.SRC_ATOP);
         setBackgroundDrawable(drawable);
     }
 }