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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/widget/RoundedIconGenerator.java

Issue 951553003: Update Bookmark widget icon design. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add icon null check Created 5 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
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/widget/RoundedIconGenerator.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/widget/RoundedIconGenerator.java b/chrome/android/java/src/org/chromium/chrome/browser/widget/RoundedIconGenerator.java
index a81d7d7b9dd750bd9a2f5828bf74471bbc59ef55..9a61f20c35586767225e7cd4e4727bf6ffaf946e 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/widget/RoundedIconGenerator.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/widget/RoundedIconGenerator.java
@@ -13,7 +13,6 @@ import android.graphics.Paint.FontMetrics;
import android.graphics.RectF;
import android.text.TextPaint;
import android.text.TextUtils;
-import android.util.DisplayMetrics;
import android.util.TypedValue;
import org.chromium.chrome.browser.UrlConstants;
@@ -42,19 +41,36 @@ public class RoundedIconGenerator {
* Constructs the generator and initializes the common members based on the display density.
*
* @param context The context used for initialization.
- * @param iconWidthDp The width of the generated icon.
- * @param iconHeightDp The height of the generated icon.
- * @param cornerRadiusDp The radius of the corners in the icon.
+ * @param iconWidthDp The width of the generated icon in dp.
+ * @param iconHeightDp The height of the generated icon in dp.
+ * @param cornerRadiusDp The radius of the corners in the icon in dp.
* @param backgroundColor Color at which the rounded rectangle should be drawn.
- * @param textSizeSp Size at which the text should be drawn.
+ * @param textSizeSp Size at which the text should be drawn in dp.
*/
public RoundedIconGenerator(Context context, int iconWidthDp, int iconHeightDp,
- int cornerRadiusDp, int backgroundColor, int textSizeSp) {
- DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
+ int cornerRadiusDp, int backgroundColor, int textSizeSp) {
+ this((int) (context.getResources().getDisplayMetrics().density * iconWidthDp),
+ (int) (context.getResources().getDisplayMetrics().density * iconHeightDp),
+ (int) (context.getResources().getDisplayMetrics().density * cornerRadiusDp),
+ backgroundColor,
+ TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, textSizeSp,
+ context.getResources().getDisplayMetrics()));
+ }
- mIconWidthPx = (int) (iconWidthDp * displayMetrics.density);
- mIconHeightPx = (int) (iconHeightDp * displayMetrics.density);
- mCornerRadiusPx = (int) (cornerRadiusDp * displayMetrics.density);
+ /**
+ * Constructs the generator and initializes the common members ignoring display density.
+ *
+ * @param iconWidthPx The width of the generated icon in pixels.
+ * @param iconHeightPx The height of the generated icon in pixels.
+ * @param cornerRadiusPx The radius of the corners in the icon in pixels.
+ * @param backgroundColor Color at which the rounded rectangle should be drawn.
+ * @param textSizePx Size at which the text should be drawn in pixels.
+ */
+ public RoundedIconGenerator(int iconWidthPx, int iconHeightPx, int cornerRadiusPx,
+ int backgroundColor, float textSizePx) {
+ mIconWidthPx = iconWidthPx;
+ mIconHeightPx = iconHeightPx;
+ mCornerRadiusPx = cornerRadiusPx;
mBackgroundRect = new RectF(0, 0, mIconWidthPx, mIconHeightPx);
@@ -64,8 +80,7 @@ public class RoundedIconGenerator {
mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
mTextPaint.setColor(Color.WHITE);
mTextPaint.setFakeBoldText(true);
- mTextPaint.setTextSize(TypedValue.applyDimension(
- TypedValue.COMPLEX_UNIT_SP, textSizeSp, displayMetrics));
+ mTextPaint.setTextSize(textSizePx);
FontMetrics textFontMetrics = mTextPaint.getFontMetrics();
mTextHeight = (float) Math.ceil(textFontMetrics.bottom - textFontMetrics.top);
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698