Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java

Issue 2721043002: [NTP::Downloads] Scale up type based icons. (Closed)
Patch Set: dfalcantara@ comment. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java
index 11e61a3ffcca9aeb17cfc7c261c74546ef125b9a..f4c5c72e4ddffac7ee747c2136ce1de3a23852fd 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java
@@ -286,15 +286,33 @@ public class SnippetArticleViewHolder extends CardViewHolder implements Impressi
private void setThumbnailFromBitmap(Bitmap thumbnail) {
assert thumbnail != null && !thumbnail.isRecycled();
mThumbnailView.setScaleType(ImageView.ScaleType.CENTER_CROP);
+ mThumbnailView.setPadding(0, 0, 0, 0);
mThumbnailView.setBackground(null);
mThumbnailView.setImageBitmap(thumbnail);
mThumbnailView.setTint(null);
}
private void setThumbnailFromFileType(int fileType) {
- mThumbnailView.setScaleType(ImageView.ScaleType.CENTER);
+ mThumbnailView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
+
+ // The provided asset is 36dp, but the spec requires 32dp. Add padding to force the asset to
+ // be scaled down.
+ final int actualIconSizeDp = 36;
+ final int desiredIconSizeDp = 32;
+ Drawable icon = ApiCompatibilityUtils.getDrawable(mThumbnailView.getResources(),
+ DownloadUtils.getIconResId(fileType, DownloadUtils.ICON_SIZE_36_DP));
+
+ final int drawableSize = icon.getIntrinsicWidth();
+ assert icon.getIntrinsicHeight() == drawableSize;
+
+ final int viewSize = mThumbnailView.getResources().getDimensionPixelSize(
+ R.dimen.snippets_thumbnail_size);
+ final float scale = ((float) desiredIconSizeDp) / actualIconSizeDp;
+ final int padding = (int) (viewSize / 2f - drawableSize * scale / 2f);
+ mThumbnailView.setPadding(padding, padding, padding, padding);
+
mThumbnailView.setBackgroundColor(mIconBackgroundColor);
- mThumbnailView.setImageResource(DownloadUtils.getIconResId(fileType));
+ mThumbnailView.setImageDrawable(icon);
mThumbnailView.setTint(mIconForegroundColorList);
}
@@ -339,6 +357,7 @@ public class SnippetArticleViewHolder extends CardViewHolder implements Impressi
}
// Temporarily set placeholder and then fetch the thumbnail from a provider.
+ mThumbnailView.setPadding(0, 0, 0, 0);
mThumbnailView.setBackground(null);
mThumbnailView.setImageResource(R.drawable.ic_snippet_thumbnail_placeholder);
mThumbnailView.setTint(null);
@@ -384,6 +403,7 @@ public class SnippetArticleViewHolder extends CardViewHolder implements Impressi
new BitmapDrawable(mThumbnailView.getResources(), scaledThumbnail)};
TransitionDrawable transitionDrawable = new TransitionDrawable(layers);
mThumbnailView.setScaleType(ImageView.ScaleType.CENTER_CROP);
+ mThumbnailView.setPadding(0, 0, 0, 0);
mThumbnailView.setBackground(null);
mThumbnailView.setImageDrawable(transitionDrawable);
mThumbnailView.setTint(null);

Powered by Google App Engine
This is Rietveld 408576698