From 5df0bd69c7e7331474c4876fc8d20a963b57f1ca Mon Sep 17 00:00:00 2001 From: David Teresi Date: Sat, 3 Jul 2021 20:43:24 -0400 Subject: [PATCH] Fix icon crop Rectangular icons were causing issues with the conversation icon display (probably an Android bug) and shortcut icons were being cropped in unnecessarily. --- .../java/im/vector/app/features/home/AvatarRenderer.kt | 1 + .../java/im/vector/app/features/home/ShortcutCreator.kt | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt b/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt index 787027e0e29..d22707bda03 100644 --- a/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt +++ b/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt @@ -171,6 +171,7 @@ class AvatarRenderer @Inject constructor(private val activeSessionHolder: Active .toBitmap(width = iconSize, height = iconSize)) } } + .apply(RequestOptions.centerCropTransform()) .submit(iconSize, iconSize) .get() } diff --git a/vector/src/main/java/im/vector/app/features/home/ShortcutCreator.kt b/vector/src/main/java/im/vector/app/features/home/ShortcutCreator.kt index 879efcaf196..b40666d1cf8 100644 --- a/vector/src/main/java/im/vector/app/features/home/ShortcutCreator.kt +++ b/vector/src/main/java/im/vector/app/features/home/ShortcutCreator.kt @@ -19,6 +19,7 @@ package im.vector.app.features.home import android.content.Context import android.content.pm.ShortcutInfo import android.graphics.Bitmap +import android.graphics.Canvas import android.os.Build import androidx.annotation.WorkerThread import androidx.core.content.pm.ShortcutInfoCompat @@ -46,7 +47,7 @@ class ShortcutCreator @Inject constructor( private val adaptiveIconOuterSides = dimensionConverter.dpToPx(adaptiveIconOuterSidesDp) private val iconSize by lazy { if (useAdaptiveIcon) { - adaptiveIconSize - adaptiveIconOuterSides + adaptiveIconSize - (adaptiveIconOuterSides * 2) } else { dimensionConverter.dpToPx(72) } @@ -80,7 +81,11 @@ class ShortcutCreator @Inject constructor( private fun Bitmap.toProfileImageIcon(): IconCompat { return if (useAdaptiveIcon) { - IconCompat.createWithAdaptiveBitmap(this) + val insetBmp = Bitmap.createBitmap(adaptiveIconSize, adaptiveIconSize, Bitmap.Config.ARGB_8888) + val canvas = Canvas(insetBmp) + canvas.drawBitmap(this, adaptiveIconOuterSides.toFloat(), adaptiveIconOuterSides.toFloat(), null) + + IconCompat.createWithAdaptiveBitmap(insetBmp) } else { IconCompat.createWithBitmap(this) }