If we are unable to generate a barcode, just show nothing

1.2-legacy
Kevin Hester 2021-04-05 15:52:26 +08:00
rodzic 479f242e06
commit 0c70ae860e
2 zmienionych plików z 23 dodań i 15 usunięć

Wyświetl plik

@ -3,6 +3,7 @@ package com.geeksville.mesh.model
import android.graphics.Bitmap
import android.net.Uri
import android.util.Base64
import com.geeksville.android.Logging
import com.geeksville.mesh.AppOnlyProtos
import com.google.zxing.BarcodeFormat
import com.google.zxing.MultiFormatWriter
@ -11,7 +12,7 @@ import java.net.MalformedURLException
data class ChannelSet(
val protobuf: AppOnlyProtos.ChannelSet = AppOnlyProtos.ChannelSet.getDefaultInstance()
) {
) : Logging {
companion object {
const val prefix = "https://www.meshtastic.org/d/#"
@ -62,7 +63,8 @@ data class ChannelSet(
return Uri.parse("$p$enc")
}
fun getChannelQR(): Bitmap {
val qrCode
get(): Bitmap? = try {
val multiFormatWriter = MultiFormatWriter()
// We encode as UPPER case for the QR code URL because QR codes are more efficient for that special case
@ -74,6 +76,10 @@ data class ChannelSet(
192
)
val barcodeEncoder = BarcodeEncoder()
return barcodeEncoder.createBitmap(bitMatrix)
barcodeEncoder.createBitmap(bitMatrix)
} catch (ex: Throwable) {
errormsg("URL was too complex to render as barcode")
null
}
}

Wyświetl plik

@ -98,7 +98,9 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
// doesn't cache radioconfig writes.
binding.editableCheckbox.isEnabled = connected
binding.qrView.setImageBitmap(channels.getChannelQR())
val bitmap = channels.qrCode
if (bitmap != null)
binding.qrView.setImageBitmap(bitmap)
val modemConfig = channel.modemConfig
val channelOption = ChannelOption.fromConfig(modemConfig)