Forcing pending app icons to be croped to the iconShape
Bug: 153761619
Test: Verified icon on device
Change-Id: Ie19f7705f8c9513a0a7f23dfa4272e84fed9901f
diff --git a/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java b/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java
index e7e47f2..4e1f25b 100644
--- a/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java
+++ b/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java
@@ -20,6 +20,7 @@
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
+import android.graphics.drawable.InsetDrawable;
import android.os.Build;
import android.os.Process;
import android.os.UserHandle;
@@ -152,6 +153,20 @@
return BitmapInfo.of(icon, extractColor(icon));
}
+ /**
+ * Creates an icon from the bitmap cropped to the current device icon shape
+ */
+ public BitmapInfo createShapedIconBitmap(Bitmap icon, UserHandle user) {
+ Drawable d = new FixedSizeBitmapDrawable(icon);
+ if (ATLEAST_OREO) {
+ float inset = AdaptiveIconDrawable.getExtraInsetFraction();
+ inset = inset / (1 + 2 * inset);
+ d = new AdaptiveIconDrawable(new ColorDrawable(Color.BLACK),
+ new InsetDrawable(d, inset, inset, inset, inset));
+ }
+ return createBadgedIconBitmap(d, user, true);
+ }
+
public BitmapInfo createBadgedIconBitmap(Drawable icon, UserHandle user,
boolean shrinkNonAdaptiveIcons) {
return createBadgedIconBitmap(icon, user, shrinkNonAdaptiveIcons, false, null);
diff --git a/iconloaderlib/src/com/android/launcher3/icons/cache/BaseIconCache.java b/iconloaderlib/src/com/android/launcher3/icons/cache/BaseIconCache.java
index 4c634cb..5587a64 100644
--- a/iconloaderlib/src/com/android/launcher3/icons/cache/BaseIconCache.java
+++ b/iconloaderlib/src/com/android/launcher3/icons/cache/BaseIconCache.java
@@ -396,7 +396,7 @@
}
if (icon != null) {
BaseIconFactory li = getIconFactory();
- entry.bitmap = li.createIconBitmap(icon);
+ entry.bitmap = li.createShapedIconBitmap(icon, user);
li.close();
}
if (!TextUtils.isEmpty(title) && entry.bitmap.icon != null) {