Skip to content

Commit

Permalink
Bitmap.createBitmap: Ensure width, height > 0
Browse files Browse the repository at this point in the history
Fixes #966
  • Loading branch information
iSoron committed Jul 31, 2021
1 parent d0ef749 commit 705dfb9
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 705dfb9

Please sign in to comment.