Skip to content

Commit 905738a

Browse files
author
alllexey
committed
Fill qr code with different color if error happens
1 parent a1fcd74 commit 905738a

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

app/src/main/java/me/alllexey123/itmowidgets/ui/widgets/QrCodeWidget.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class QrCodeWidget : AppWidgetProvider() {
3939

4040
val appWidgetManager = AppWidgetManager.getInstance(context)
4141
val views = RemoteViews(context.packageName, R.layout.qr_code_widget)
42-
val bitmap = renderer.renderEmpty(21 * PIXELS_PER_MODULE, PIXELS_PER_MODULE / 2F, dynamicColors)
42+
val bitmap = renderer.renderFull(21 * PIXELS_PER_MODULE, PIXELS_PER_MODULE / 2F, dynamicColors)
4343

4444
views.setImageViewBitmap(R.id.qr_code_image, bitmap)
4545

app/src/main/java/me/alllexey123/itmowidgets/util/QrBitmapRenderer.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,21 @@ class QrBitmapRenderer(
130130

131131
fun renderEmpty(side: Int, rounding: Float, dynamic: Boolean): Bitmap {
132132
val colors = getQrColors(dynamic)
133+
return renderFilled(side, rounding, colors.first, colors.first)
134+
}
135+
136+
fun renderFull(side: Int, rounding: Float, dynamic: Boolean): Bitmap {
137+
val colors = getQrColors(dynamic)
138+
return renderFilled(side, rounding, colors.first, colors.second)
139+
}
140+
141+
fun renderFilled(side: Int, rounding: Float, bgColor: Int, fillColor: Int): Bitmap {
133142
val bitmap = createBitmap(side, side, Bitmap.Config.RGB_565)
134143
val canvas = Canvas(bitmap)
135-
canvas.drawColor(colors.first)
144+
canvas.drawColor(bgColor)
136145

137146
val paint = Paint().apply {
138-
color = colors.second
147+
color = fillColor
139148
isAntiAlias = true
140149
}
141150

0 commit comments

Comments
 (0)