From 152794b84cd885cd0f219dd6baf6f167c128eae4 Mon Sep 17 00:00:00 2001 From: Patrick Scott Date: Tue, 30 Mar 2010 13:57:29 -0400 Subject: [PATCH] Draw the touch icon better. Use the application icon size to get the correct dimensions. Copy the bitmap to the correct size and change the config to allow alpha. This doesn't fix the part of the bug that prefers precomposed over regular touch icons. That requires a change to frameworks/base. Bug: 2546984 Change-Id: Ifee474cd3540456383f84bf563bc92df63e0b010 --- src/com/android/browser/BrowserBookmarksPage.java | 31 ++++++++++++++++------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/com/android/browser/BrowserBookmarksPage.java b/src/com/android/browser/BrowserBookmarksPage.java index 1c58beb..7dd85aa 100644 --- a/src/com/android/browser/BrowserBookmarksPage.java +++ b/src/com/android/browser/BrowserBookmarksPage.java @@ -72,6 +72,7 @@ public class BrowserBookmarksPage extends Activity implements private boolean mCreateShortcut; private boolean mMostVisited; private View mEmptyView; + private int mIconSize; // XXX: There is no public string defining this intent so if Home changes // the value, we have to update this string. private static final String INSTALL_SHORTCUT = @@ -230,6 +231,10 @@ public class BrowserBookmarksPage extends Activity implements protected void onCreate(Bundle icicle) { super.onCreate(icicle); + // Grab the app icon size as a resource. + mIconSize = getResources().getDimensionPixelSize( + android.R.dimen.app_icon_size); + if (Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())) { mCreateShortcut = true; } @@ -441,26 +446,34 @@ public class BrowserBookmarksPage extends Activity implements i.putExtra(Intent.EXTRA_SHORTCUT_NAME, title); // Use the apple-touch-icon if available if (touchIcon != null) { - // Make a copy so we can modify the pixels. - Bitmap copy = touchIcon.copy(Bitmap.Config.ARGB_8888, true); - Canvas canvas = new Canvas(copy); + // Make a copy so we can modify the pixels. We can't use + // createScaledBitmap or copy since they will preserve the config + // and lose the ability to add alpha. + Bitmap bm = Bitmap.createBitmap(mIconSize, mIconSize, + Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(bm); + Rect src = new Rect(0, 0, touchIcon.getWidth(), + touchIcon.getHeight()); + Rect dest = new Rect(0, 0, bm.getWidth(), bm.getHeight()); + + // Paint used for scaling the bitmap and drawing the rounded rect. + Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); + paint.setFilterBitmap(true); + canvas.drawBitmap(touchIcon, src, dest, paint); // Construct a path from a round rect. This will allow drawing with // an inverse fill so we can punch a hole using the round rect. Path path = new Path(); path.setFillType(Path.FillType.INVERSE_WINDING); - RectF rect = new RectF(0, 0, touchIcon.getWidth(), - touchIcon.getHeight()); + RectF rect = new RectF(0, 0, bm.getWidth(), bm.getHeight()); rect.inset(1, 1); path.addRoundRect(rect, 8f, 8f, Path.Direction.CW); - // Construct a paint that clears the outside of the rectangle and - // draw. - Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); + // Reuse the paint and clear the outside of the rectangle. paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); canvas.drawPath(path, paint); - i.putExtra(Intent.EXTRA_SHORTCUT_ICON, copy); + i.putExtra(Intent.EXTRA_SHORTCUT_ICON, bm); } else { Bitmap favicon = getFavicon(position); if (favicon == null) { -- 2.11.0