Skip to content

Commit

Permalink
Fix icon crop
Browse files Browse the repository at this point in the history
Rectangular icons were causing issues with the conversation icon display
(probably an Android bug) and shortcut icons were being cropped in
unnecessarily.
  • Loading branch information
dkter committed Jul 4, 2021
1 parent 5b10279 commit 0eb0c77
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class AvatarRenderer @Inject constructor(private val activeSessionHolder: Active
.toBitmap(width = iconSize, height = iconSize))
}
}
.apply(RequestOptions.centerCropTransform())
.submit(iconSize, iconSize)
.get()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 0eb0c77

Please sign in to comment.