[Android] Fix widgets cover sizing before cutting it
Nicolas Pomepuy
git at videolan.org
Wed May 18 09:57:56 UTC 2022
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri May 6 11:57:14 2022 +0200| [8d877772c6985eba0d2de8cbf70da7a628b91e28] | committer: Duncan McNamara
Fix widgets cover sizing before cutting it
> https://code.videolan.org/videolan/vlc-android/commit/8d877772c6985eba0d2de8cbf70da7a628b91e28
---
.../vlc-android/src/org/videolan/vlc/gui/helpers/BitmapUtil.kt | 9 +++++----
.../src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt | 10 +++++-----
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/BitmapUtil.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/BitmapUtil.kt
index 9c3b2b365..10d147764 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/BitmapUtil.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/BitmapUtil.kt
@@ -227,6 +227,7 @@ object BitmapUtil {
* Cut a [Bitmap] into a rounded rectangle
*
* @param bm the [Bitmap] to cut
+ * @param size the size of the returned bitmap
* @param radius the corner radius to use
* @param topLeft cut the top left corner?
* @param topRight cut the top right corner?
@@ -234,10 +235,10 @@ object BitmapUtil {
* @param bottomRight cut the bottom right corner?
* @return a rounded rectangle bitmap
*/
- fun roundedRectangleBitmap(bm: Bitmap, radius: Float = 12.dp.toFloat(), topLeft: Boolean = true, topRight: Boolean = true, bottomLeft: Boolean = true, bottomRight: Boolean = true): Bitmap {
+ fun roundedRectangleBitmap(bm: Bitmap, size:Int, radius: Float = 12.dp.toFloat(), topLeft: Boolean = true, topRight: Boolean = true, bottomLeft: Boolean = true, bottomRight: Boolean = true): Bitmap {
- val w: Int = bm.width
- val h: Int = bm.height
+ val w: Int = size
+ val h: Int = size
val bmOut = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888)
@@ -259,7 +260,7 @@ object BitmapUtil {
if (!bottomRight) canvas.drawRect(RectF(w.toFloat() - radius, h.toFloat() - radius, w.toFloat(),h.toFloat()), paint)
paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN)
- canvas.drawBitmap(bm, rect, rect, paint)
+ canvas.drawBitmap(bm, Rect(0, 0, bm.width, bm.height), rect, paint)
return bmOut
}
diff --git a/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt b/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
index 6dfecdcb4..5d43ad19e 100644
--- a/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
@@ -262,7 +262,7 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
if (forPreview) widgetCacheEntry.currentCover = "fake"
if (forPreview) {
displayCover(true, widgetType, views, context, widgetCacheEntry)
- views.setImageViewBitmap(R.id.cover, cutBitmapCover(widgetType, previewBitmap!!))
+ views.setImageViewBitmap(R.id.cover, cutBitmapCover(widgetType, previewBitmap!!, widgetCacheEntry))
} else if (playing && widgetCacheEntry.currentMedia?.artworkMrl != widgetCacheEntry.currentCover) {
widgetCacheEntry.currentCover = widgetCacheEntry.currentMedia?.artworkMrl
if (!widgetCacheEntry.currentMedia?.artworkMrl.isNullOrEmpty()) {
@@ -274,7 +274,7 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
runOnMainThread {
if (cover != null) {
if (cover.byteSize() < dm.widthPixels * dm.heightPixels * 6) {
- val finalBitmap = cutBitmapCover(widgetType, cover)
+ val finalBitmap = cutBitmapCover(widgetType, cover, widgetCacheEntry)
views.setImageViewBitmap(R.id.cover, finalBitmap)
if (widgetCacheEntry.widget.theme == 1) widgetCacheEntry.palette = Palette.from(cover).generate()
displayCover(true, widgetType, views, context, widgetCacheEntry)
@@ -370,12 +370,12 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
else -> false
}
- private fun cutBitmapCover(widgetType: WidgetType, cover: Bitmap): Bitmap =
+ private fun cutBitmapCover(widgetType: WidgetType, cover: Bitmap, widgetCacheEntry: WidgetCacheEntry): Bitmap =
when (widgetType) {
WidgetType.MICRO -> BitmapUtil.roundBitmap(cover)
WidgetType.PILL -> BitmapUtil.roundBitmap(cover)
- WidgetType.MINI -> BitmapUtil.roundedRectangleBitmap(cover, bottomRight = false, topRight = false)
- else -> cover
+ WidgetType.MINI -> BitmapUtil.roundedRectangleBitmap(cover, widgetCacheEntry.widget.height.dp, bottomRight = false, topRight = false)
+ WidgetType.MACRO -> BitmapUtil.roundedRectangleBitmap(cover, widgetCacheEntry.widget.width.dp)
}
private fun getFakeMedia(): MediaWrapper? {
More information about the Android
mailing list