Bug 1242629 - Use our color palette for top sites "add a site" tiles
add flag for default border
MozReview-Commit-ID: 3Fc2dS6bphH
--- a/mobile/android/base/java/org/mozilla/gecko/home/TopSitesGridItemView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/TopSitesGridItemView.java
@@ -3,16 +3,18 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.home;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
+import android.support.annotation.DrawableRes;
+import android.support.v4.content.ContextCompat;
import android.support.v4.widget.TextViewCompat;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView.ScaleType;
import android.widget.RelativeLayout;
import android.widget.TextView;
@@ -138,18 +140,17 @@ public class TopSitesGridItemView extend
public void blankOut() {
mUrl = "";
mTitle = "";
updateType(TopSites.TYPE_BLANK);
updateTitleView();
cancelIconLoading();
ImageLoader.with(getContext()).cancelRequest(mThumbnailView);
- displayThumbnail(R.drawable.top_site_add);
-
+ displayThumbnail(R.drawable.top_site_add, ContextCompat.getColor(getContext(), R.color.about_page_header_grey));
}
public void markAsDirty() {
mIsDirty = true;
}
/**
* Updates the title, URL, and pinned state of this view.
@@ -217,21 +218,23 @@ public class TopSitesGridItemView extend
mOngoingIconRequest.cancel(true);
}
}
/**
* Display the thumbnail from a resource.
*
* @param resId Resource ID of the drawable to show.
+ * @param bgColor background color
*/
- public void displayThumbnail(int resId) {
+ public void displayThumbnail(@DrawableRes int resId, int bgColor) {
mThumbnailView.setScaleType(SCALE_TYPE_RESOURCE);
mThumbnailView.setImageResource(resId);
- mThumbnailView.setBackgroundColor(0x0);
+ mThumbnailView.setBackgroundColor(bgColor);
+ mThumbnailView.setDrawDefaultBorder(true);
mThumbnailSet = false;
}
/**
* Display the thumbnail from a bitmap.
*
* @param thumbnail The bitmap to show as thumbnail.
*/
@@ -243,27 +246,29 @@ public class TopSitesGridItemView extend
mThumbnailSet = true;
cancelIconLoading();
ImageLoader.with(getContext()).cancelRequest(mThumbnailView);
mThumbnailView.setScaleType(SCALE_TYPE_THUMBNAIL);
mThumbnailView.setImageBitmap(thumbnail, true);
mThumbnailView.setBackgroundDrawable(null);
+ mThumbnailView.setDrawDefaultBorder(true);
}
/**
* Display the thumbnail from a URL.
*
* @param imageUrl URL of the image to show.
* @param bgColor background color to use in the view.
*/
public void displayThumbnail(final String imageUrl, final int bgColor) {
mThumbnailView.setScaleType(SCALE_TYPE_URL);
mThumbnailView.setBackgroundColor(bgColor);
+ mThumbnailView.setDrawDefaultBorder(false);
mThumbnailSet = true;
ImageLoader.with(getContext())
.load(imageUrl)
.noFade()
.into(mThumbnailView);
}
--- a/mobile/android/base/java/org/mozilla/gecko/home/TopSitesThumbnailView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/TopSitesThumbnailView.java
@@ -30,16 +30,17 @@ public class TopSitesThumbnailView exten
// Default filter color for "Add a bookmark" views.
private final int mDefaultColor = ContextCompat.getColor(getContext(), R.color.top_site_default);
// Stroke width for the border.
private final float mStrokeWidth = getResources().getDisplayMetrics().density * 2;
// Paint for drawing the border.
private final Paint mBorderPaint;
+ private boolean mDrawBorder;
public TopSitesThumbnailView(Context context) {
this(context, null);
// A border will be drawn if needed.
setWillNotDraw(false);
}
@@ -64,17 +65,17 @@ public class TopSitesThumbnailView exten
/**
* {@inheritDoc}
*/
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
- if (getBackground() == null) {
+ if (mDrawBorder) {
mBorderPaint.setStrokeWidth(mStrokeWidth);
canvas.drawRect(0, 0, getWidth(), getHeight(), mBorderPaint);
}
}
/**
* Sets the background color with a filter to reduce the color opacity.
*
@@ -94,9 +95,13 @@ public class TopSitesThumbnailView exten
if (color == 0) {
color = mDefaultColor;
}
Drawable drawable = getResources().getDrawable(R.drawable.top_sites_thumbnail_bg);
drawable.setColorFilter(color, Mode.SRC_ATOP);
setBackgroundDrawable(drawable);
}
+
+ public void setDrawDefaultBorder(boolean drawDefaultBorder) {
+ this.mDrawBorder = drawDefaultBorder;
+ }
}