Index: chrome/android/java/src/org/chromium/chrome/browser/BookmarkUtils.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/BookmarkUtils.java b/chrome/android/java/src/org/chromium/chrome/browser/BookmarkUtils.java |
index fe43e3be164b80a0b7cc877c0bb0a1e781c4376d..815189b7f55caf859b3004bd43afd404c1c5143a 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/BookmarkUtils.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/BookmarkUtils.java |
@@ -10,10 +10,10 @@ import android.content.Intent; |
import android.graphics.Bitmap; |
import android.graphics.Canvas; |
import android.graphics.Color; |
-import android.graphics.LinearGradient; |
import android.graphics.Paint; |
import android.graphics.Path; |
import android.graphics.PorterDuff; |
+import android.graphics.PorterDuffColorFilter; |
import android.graphics.PorterDuffXfermode; |
import android.graphics.Rect; |
import android.graphics.RectF; |
@@ -38,7 +38,6 @@ public class BookmarkUtils { |
public static final String REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB = |
"REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB"; |
private static final int INSET_DIMENSION_FOR_TOUCHICON = 1; |
- private static final int SDK_VERSION_FOR_ACCESS_TO_METHODS = 15; |
/** |
* Creates an intent that will add a shortcut to the home screen. |
@@ -88,25 +87,22 @@ public class BookmarkUtils { |
int gValue, int bValue) { |
Bitmap bitmap = null; |
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
- final int iconDimension = am.getLauncherLargeIconSize(); |
+ final int iconSize = am.getLauncherLargeIconSize(); |
final int iconDensity = am.getLauncherLargeIconDensity(); |
try { |
- bitmap = Bitmap.createBitmap(iconDimension, iconDimension, Bitmap.Config.ARGB_8888); |
+ bitmap = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888); |
Canvas canvas = new Canvas(bitmap); |
- Rect iconBounds = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); |
if (favicon == null) { |
favicon = getBitmapFromResourceId(context, R.drawable.globe_favicon, iconDensity); |
rValue = gValue = bValue = DEFAULT_RGB_VALUE; |
} |
- final int smallestSide = iconDimension; |
+ final int smallestSide = iconSize; |
if (favicon.getWidth() >= smallestSide / 2 && favicon.getHeight() >= smallestSide / 2) { |
- drawTouchIconToCanvas(context, favicon, canvas, iconBounds); |
+ drawTouchIconToCanvas(context, favicon, canvas); |
} else { |
- Bitmap icon = getIconBackground(context, iconDensity); |
- if (icon != null) { |
- canvas.drawBitmap(icon, null, iconBounds, new Paint(Paint.ANTI_ALIAS_FLAG)); |
- } |
- drawFaviconToCanvas(context, favicon, canvas, iconBounds, rValue, gValue, bValue); |
+ drawWidgetBackgroundToCanvas(context, canvas, iconDensity, |
+ Color.rgb(rValue, gValue, bValue)); |
+ drawFaviconToCanvas(context, favicon, canvas); |
} |
canvas.setBitmap(null); |
} catch (OutOfMemoryError e) { |
@@ -115,22 +111,14 @@ public class BookmarkUtils { |
return bitmap; |
} |
- /** |
- * Get the icon background asset. |
- * @param context Context used to create the intent. |
- * @return Bitmap favicon background asset. |
- */ |
- private static Bitmap getIconBackground(Context context, int density) { |
- return getBitmapFromResourceId(context, R.mipmap.homescreen_bg, density); |
- } |
- |
private static Bitmap getBitmapFromResourceId(Context context, int id, int density) { |
Drawable drawable = null; |
- if (Build.VERSION.SDK_INT >= SDK_VERSION_FOR_ACCESS_TO_METHODS) { |
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { |
drawable = context.getResources().getDrawableForDensity(id, density); |
} else { |
drawable = context.getResources().getDrawable(id); |
} |
+ |
if (drawable instanceof BitmapDrawable) { |
BitmapDrawable bd = (BitmapDrawable) drawable; |
return bd.getBitmap(); |
@@ -144,10 +132,10 @@ public class BookmarkUtils { |
* @param context Context used to get resources. |
* @param touchIcon Touch icon bitmap. |
* @param canvas Canvas that holds the touch icon. |
- * @param iconBounds Rectangle bounds needed for adding rounded corners of the touch icon. |
*/ |
private static void drawTouchIconToCanvas( |
- Context context, Bitmap touchIcon, Canvas canvas, Rect iconBounds) { |
+ Context context, Bitmap touchIcon, Canvas canvas) { |
+ Rect iconBounds = new Rect(0, 0, canvas.getWidth(), canvas.getHeight()); |
Rect src = new Rect(0, 0, touchIcon.getWidth(), touchIcon.getHeight()); |
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); |
paint.setFilterBitmap(true); |
@@ -168,78 +156,10 @@ public class BookmarkUtils { |
* @param context Context used to create the intent. |
* @param favicon favicon bitmap. |
* @param canvas Canvas that holds the favicon. |
- * @param iconBounds Rectangle bounds needed to create the homescreen favicon. |
- * @param rValue Red component of the dominant favicon color. |
- * @param gValue Green component of the dominant favicon color. |
- * @param bValue Blue component of the dominant favicon color. |
*/ |
- private static void drawFaviconToCanvas(Context context, Bitmap favicon, |
- Canvas canvas, Rect iconBounds, int rValue, int gValue, int bValue) { |
- int colorStripWidth = context.getResources().getDimensionPixelSize( |
- R.dimen.favicon_colorstrip_width); |
- int colorStripHeight = context.getResources().getDimensionPixelSize( |
- R.dimen.favicon_colorstrip_height); |
- int colorStripPadding = context.getResources().getDimensionPixelSize( |
- R.dimen.favicon_colorstrip_padding); |
- int colorStripCornerRadii = context.getResources().getDimensionPixelSize( |
- R.dimen.favicon_colorstrip_corner_radii); |
- int foldSize = context.getResources().getDimensionPixelSize(R.dimen.favicon_fold_size); |
- int foldCornerRadii = context.getResources().getDimensionPixelSize( |
- R.dimen.favicon_fold_corner_radii); |
- int foldBorder = context.getResources().getDimensionPixelSize(R.dimen.favicon_fold_border); |
- int foldShadow = context.getResources().getDimensionPixelSize(R.dimen.favicon_fold_shadow); |
- int faviconSize = context.getResources().getDimensionPixelSize(R.dimen.favicon_size); |
- |
- float x1 = iconBounds.exactCenterX() - (colorStripWidth / 2.0f); |
- float x2 = x1 + colorStripWidth; |
- float y1 = iconBounds.height() - colorStripPadding; |
- float y2 = y1 - colorStripHeight; |
- int faviconColorAlpha100 = Color.argb(255, rValue, gValue, bValue); |
- Paint stripPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
- stripPaint.setColor(faviconColorAlpha100); |
- stripPaint.setStyle(Paint.Style.FILL); |
- Path stripPath = new Path(); |
- stripPath.moveTo(x1, y2); |
- stripPath.lineTo(x2, y2); |
- stripPath.lineTo(x2, y1 - colorStripCornerRadii); |
- stripPath.arcTo(new RectF(x2 - colorStripCornerRadii, y1 - colorStripCornerRadii, x2, y1), |
- 0, 90); |
- stripPath.lineTo(x1 + colorStripCornerRadii, y1); |
- stripPath.arcTo(new RectF(x1, y1 - colorStripCornerRadii, x1 + colorStripCornerRadii, y1), |
- 90, 90); |
- stripPath.lineTo(x1, y2); |
- canvas.drawPath(stripPath, stripPaint); |
- |
- float ax, ay, bx, by, cx, cy; |
- bx = ax = x2 - foldSize; |
- cx = x2; |
- ay = colorStripPadding; |
- by = cy = colorStripPadding + foldSize; |
- int blackAlpha10 = Color.argb((int) (255 * 0.10f), 0, 0, 0); |
- |
- Paint foldShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
- foldShadowPaint.setColor(Color.WHITE); |
- foldShadowPaint.setShadowLayer(1, 0, foldShadow, blackAlpha10); |
- int faviconColorAlpha60 = Color.argb((int) (255 * 0.60f), rValue, gValue, bValue); |
- Paint foldGradientPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
- foldGradientPaint.setShader(new LinearGradient(x2 - foldSize / 2.0f, |
- colorStripPadding + foldSize / 2.0f, x2 - foldSize, colorStripPadding + foldSize, |
- faviconColorAlpha60, faviconColorAlpha100, |
- android.graphics.Shader.TileMode.CLAMP)); |
- Path foldPath = new Path(); |
- foldPath.moveTo(ax, ay); |
- foldPath.lineTo(cx, cy); |
- foldPath.lineTo(bx + foldCornerRadii, by); |
- foldPath.arcTo(new RectF(bx, by - foldCornerRadii, bx + foldCornerRadii, by), 90, 90); |
- foldPath.lineTo(ax, ay); |
- canvas.drawPath(foldPath, foldShadowPaint); |
- canvas.drawPath(foldPath, foldGradientPaint); |
- int faviconColorAlpha80 = Color.argb((int) (255 * 0.80f), rValue, gValue, bValue); |
- Paint foldBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
- foldBorderPaint.setColor(faviconColorAlpha80); |
- foldBorderPaint.setStyle(Paint.Style.STROKE); |
- foldBorderPaint.setStrokeWidth(foldBorder); |
- canvas.drawPath(foldPath, foldBorderPaint); |
+ private static void drawFaviconToCanvas(Context context, Bitmap favicon, Canvas canvas) { |
+ Rect iconBounds = new Rect(0, 0, canvas.getWidth(), canvas.getHeight()); |
+ int faviconSize = iconBounds.width() / 3; |
newt (away)
2013/05/31 03:10:56
we might want to choose this value so that the fav
Kibeom Kim (inactive)
2013/05/31 06:38:03
Yeah actually I thought about that, but / 3 is als
newt (away)
2013/06/03 04:12:26
yea, that works out nicely. multiples of 8 should
|
try { |
Bitmap scaledFavicon = Bitmap.createScaledBitmap(favicon, faviconSize, faviconSize, |
true); |
@@ -250,4 +170,30 @@ public class BookmarkUtils { |
Log.w(TAG, "OutOfMemoryError while trying to draw bitmap on canvas."); |
} |
} |
+ |
+ /** |
+ * Draw document icon to canvas. |
+ * @param context Context used to get bitmap resources. |
+ * @param canvas Canvas that holds the document icon. |
+ * @param iconDensity Density information to get bitmap resources. |
+ * @param color Color for the document icon's folding and the bottom strip. |
+ * @return True if the document icon is drawn, false otherwise. |
+ */ |
+ private static boolean drawWidgetBackgroundToCanvas( |
newt (away)
2013/05/31 03:10:56
we don't use this return value anywhere. you could
Kibeom Kim (inactive)
2013/05/31 06:38:03
Done.
|
+ Context context, Canvas canvas, int iconDensity, int color) { |
+ Rect iconBounds = new Rect(0, 0, canvas.getWidth(), canvas.getHeight()); |
+ Bitmap icon = getBitmapFromResourceId(context, R.mipmap.bookmark_widget_bg, iconDensity); |
+ Bitmap icon_overlay = getBitmapFromResourceId(context, |
+ R.mipmap.bookmark_widget_bg_highlights, iconDensity); |
+ if (icon == null || icon_overlay == null) { |
+ Log.w(TAG, "Can't load R.mipmap.bookmark_widget_bg or " + |
+ "R.mipmap.bookmark_widget_bg_highlights."); |
+ return false; |
+ } |
+ Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG); |
+ canvas.drawBitmap(icon, null, iconBounds, paint); |
+ paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN)); |
newt (away)
2013/05/31 03:10:56
can you add a comment for lines 195-196? they're a
Kibeom Kim (inactive)
2013/05/31 06:38:03
Done.
|
+ canvas.drawBitmap(icon_overlay, null, iconBounds, paint); |
+ return true; |
+ } |
} |