OSDN Git Service

Fixing icon badging being done on scaled bitmap size
authorSunny Goyal <sunnygoyal@google.com>
Fri, 8 Jan 2016 20:16:15 +0000 (12:16 -0800)
committerSunny Goyal <sunnygoyal@google.com>
Fri, 8 Jan 2016 20:16:15 +0000 (12:16 -0800)
Launcher already scales the bitmap during the icon creaiton. The
badging should be done based on the actual size

Bug: 26345646
Change-Id: I1b1f7ac736322ba10db9083d602eec221b99687a

src/com/android/launcher3/Utilities.java

index f9524a1..87c9262 100644 (file)
@@ -210,7 +210,7 @@ public final class Utilities {
         Bitmap bitmap = createIconBitmap(icon, context, scale);
         if (Utilities.ATLEAST_LOLLIPOP && user != null
                 && !UserHandleCompat.myUserHandle().equals(user)) {
-            BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap);
+            BitmapDrawable drawable = new FixedSizeBitmapDrawable(bitmap);
             Drawable badged = context.getPackageManager().getUserBadgedIcon(
                     drawable, user.getUser());
             if (badged instanceof BitmapDrawable) {
@@ -805,4 +805,26 @@ public final class Utilities {
         PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
         return ATLEAST_LOLLIPOP && powerManager.isPowerSaveMode();
     }
+
+    /**
+     * An extension of {@link BitmapDrawable} which returns the bitmap pixel size as intrinsic size.
+     * This allows the badging to be done based on the action bitmap size rather than
+     * the scaled bitmap size.
+     */
+    private static class FixedSizeBitmapDrawable extends BitmapDrawable {
+
+        public FixedSizeBitmapDrawable(Bitmap bitmap) {
+            super(null, bitmap);
+        }
+
+        @Override
+        public int getIntrinsicHeight() {
+            return getBitmap().getWidth();
+        }
+
+        @Override
+        public int getIntrinsicWidth() {
+            return getBitmap().getWidth();
+        }
+    }
 }