Bug 882365: Add a border to TopBookmarkItemView if its showing a thumbnail. [r=lucasr]
authorSriram Ramasubramanian <sriram@mozilla.com>
Wed, 19 Jun 2013 13:04:08 -0700
changeset 143347 e2a28f0025f10afb9e5adf1c249b8855f8868200
parent 143346 f154de5f5ef71070b4052a93bf22e3f43f5897d8
child 143348 42c9ee1b0a158b5970d89f00c831827bf5cf99ef
push id25130
push userlrocha@mozilla.com
push dateWed, 21 Aug 2013 09:41:27 +0000
treeherdermozilla-central@b2486721572e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr
bugs882365
milestone24.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 882365: Add a border to TopBookmarkItemView if its showing a thumbnail. [r=lucasr]
mobile/android/base/home/BookmarkThumbnailView.java
--- a/mobile/android/base/home/BookmarkThumbnailView.java
+++ b/mobile/android/base/home/BookmarkThumbnailView.java
@@ -4,16 +4,18 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.home;
 
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.ThumbnailHelper;
 
 import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Paint;
 import android.graphics.PorterDuff.Mode;
 import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
 import android.widget.ImageView;
 
 /**
  * A height constrained ImageView to show thumbnails of top bookmarks.
  */
@@ -21,18 +23,37 @@ public class BookmarkThumbnailView exten
     private static final String LOGTAG = "GeckoBookmarkThumbnailView";
 
     // 27.34% opacity filter for the dominant color.
     private static final int COLOR_FILTER = 0x46FFFFFF;
 
     // Default filter color for "Add a bookmark" views.
     private static final int DEFAULT_COLOR = 0x46ECF0F3;
 
+    // Border for thumbnails.
+    private boolean mShowBorder = true;
+
+    // Stroke width for the border.
+    private final float mStrokeWidth = getResources().getDisplayMetrics().density * 2;
+
+    // Paint for drawing the border.
+    private static Paint sBorderPaint;
+
+    // Initializing the static border paint.
+    static {
+        sBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
+        sBorderPaint.setColor(0xFFCFD9E1);
+        sBorderPaint.setStyle(Paint.Style.STROKE);
+    }
+
     public BookmarkThumbnailView(Context context) {
         this(context, null);
+
+        // A border will be drawn if needed.
+        setWillNotDraw(false);
     }
 
     public BookmarkThumbnailView(Context context, AttributeSet attrs) {
         this(context, attrs, R.attr.bookmarkThumbnailViewStyle);
     }
 
     public BookmarkThumbnailView(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
@@ -52,20 +73,34 @@ public class BookmarkThumbnailView exten
 
         // Force the height based on the aspect ratio.
         final int width = getMeasuredWidth();
         final int height = (int) (width * ThumbnailHelper.THUMBNAIL_ASPECT_RATIO);
         setMeasuredDimension(width, height);
     }
 
     /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void onDraw(Canvas canvas) {
+        super.onDraw(canvas);
+
+        if (mShowBorder) {
+            sBorderPaint.setStrokeWidth(mStrokeWidth);
+            canvas.drawRect(0, 0, getWidth(), getHeight(), sBorderPaint);
+        }
+    }
+
+    /**
      * 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;
         Drawable drawable = getResources().getDrawable(R.drawable.favicon_bg);
         drawable.setColorFilter(colorFilter, Mode.SRC_ATOP);
         setBackgroundDrawable(drawable);
+        mShowBorder = false;
     }
 }