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.
This commit is contained in:
David Teresi 2021-07-03 20:43:24 -04:00
parent 996b4e7a45
commit 5df0bd69c7
2 changed files with 8 additions and 2 deletions

View file

@ -171,6 +171,7 @@ class AvatarRenderer @Inject constructor(private val activeSessionHolder: Active
.toBitmap(width = iconSize, height = iconSize))
}
}
.apply(RequestOptions.centerCropTransform())
.submit(iconSize, iconSize)
.get()
}

View file

@ -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)
}