From 705dfb9cbdf3fb0fba5832bee96472617ea40133 Mon Sep 17 00:00:00 2001 From: "Alinson S. Xavier" Date: Sat, 31 Jul 2021 15:45:51 -0500 Subject: [PATCH] Bitmap.createBitmap: Ensure width, height > 0 Fixes #966 --- .../src/main/java/org/isoron/uhabits/widgets/BaseWidget.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/widgets/BaseWidget.kt b/uhabits-android/src/main/java/org/isoron/uhabits/widgets/BaseWidget.kt index dae6db9ce..bc9654529 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/widgets/BaseWidget.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/widgets/BaseWidget.kt @@ -32,6 +32,7 @@ import org.isoron.uhabits.core.commands.CommandRunner import org.isoron.uhabits.core.preferences.Preferences import org.isoron.uhabits.core.preferences.WidgetPreferences import org.isoron.uhabits.intents.PendingIntentFactory +import kotlin.math.max abstract class BaseWidget(val context: Context, val id: Int, val stacked: Boolean) { private val widgetPrefs: WidgetPreferences @@ -103,8 +104,8 @@ abstract class BaseWidget(val context: Context, val id: Int, val stacked: Boolea private fun getBitmapFromView(view: View): Bitmap { view.invalidate() - val width = view.measuredWidth - val height = view.measuredHeight + val width = max(1, view.measuredWidth) + val height = max(1, view.measuredHeight) val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) val canvas = Canvas(bitmap) view.draw(canvas)