mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
we now generate real qr codes from the current channel
This commit is contained in:
parent
8c185a7718
commit
9a2c22d0f6
4 changed files with 72 additions and 2 deletions
|
|
@ -114,5 +114,9 @@ dependencies {
|
|||
// add SDKs for any other desired Firebase products
|
||||
// https://firebase.google.com/docs/android/setup#available-libraries
|
||||
|
||||
// barcode support
|
||||
implementation('com.google.zxing:core:3.4.0')
|
||||
implementation('com.journeyapps:zxing-android-embedded:3.2.0@aar')
|
||||
|
||||
implementation project(':geeksville-androidlib')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.geeksville.mesh.model
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.os.RemoteException
|
||||
import android.util.Base64
|
||||
import androidx.compose.mutableStateOf
|
||||
|
|
@ -9,9 +10,12 @@ import com.geeksville.android.Logging
|
|||
import com.geeksville.mesh.IMeshService
|
||||
import com.geeksville.mesh.MeshProtos
|
||||
import com.geeksville.mesh.ui.getInitials
|
||||
import com.google.zxing.BarcodeFormat
|
||||
import com.google.zxing.MultiFormatWriter
|
||||
import com.journeyapps.barcodescanner.BarcodeEncoder
|
||||
|
||||
/// FIXME - figure out how to merge this staate with the AppStatus Model
|
||||
object UIState: Logging {
|
||||
object UIState : Logging {
|
||||
|
||||
/// Kinda ugly - created in the activity but used from Compose - figure out if there is a cleaner way GIXME
|
||||
// lateinit var googleSignInClient: GoogleSignInClient
|
||||
|
|
@ -38,6 +42,15 @@ object UIState: Logging {
|
|||
return "https://www.meshtastic.org/c/$enc"
|
||||
}
|
||||
|
||||
val channelQR
|
||||
get(): Bitmap {
|
||||
val multiFormatWriter = MultiFormatWriter()
|
||||
|
||||
val bitMatrix = multiFormatWriter.encode(channelUrl, BarcodeFormat.QR_CODE, 192, 192);
|
||||
val barcodeEncoder = BarcodeEncoder()
|
||||
return barcodeEncoder.createBitmap(bitMatrix)
|
||||
}
|
||||
|
||||
// clean up all this nasty owner state management FIXME
|
||||
fun setOwner(context: Context, s: String? = null) {
|
||||
|
||||
|
|
|
|||
|
|
@ -225,6 +225,7 @@ class RadioInterfaceService : Service(), Logging {
|
|||
receivedPacketsLog.write(p)
|
||||
receivedPacketsLog.flush()
|
||||
}
|
||||
|
||||
broadcastReceivedFromRadio(
|
||||
this,
|
||||
p
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
package com.geeksville.mesh.ui
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.os.Build
|
||||
import androidx.compose.Composable
|
||||
import androidx.compose.ambient
|
||||
import androidx.ui.core.ContextAmbient
|
||||
import androidx.ui.core.Text
|
||||
import androidx.ui.foundation.Clickable
|
||||
import androidx.ui.foundation.DrawImage
|
||||
import androidx.ui.graphics.*
|
||||
import androidx.ui.graphics.colorspace.ColorSpace
|
||||
import androidx.ui.graphics.colorspace.ColorSpaces
|
||||
import androidx.ui.layout.*
|
||||
import androidx.ui.material.Button
|
||||
import androidx.ui.material.MaterialTheme
|
||||
|
|
@ -18,12 +23,56 @@ import com.geeksville.android.GeeksvilleApplication
|
|||
import com.geeksville.android.Logging
|
||||
import com.geeksville.android.toast
|
||||
import com.geeksville.mesh.R
|
||||
import com.geeksville.mesh.model.UIState
|
||||
|
||||
/// The Compose IDE preview doesn't like the protobufs
|
||||
data class Channel(val name: String, val num: Int)
|
||||
|
||||
object ChannelLog : Logging
|
||||
|
||||
/// Borrowed from Compose
|
||||
class AndroidImage(val bitmap: Bitmap) : Image {
|
||||
|
||||
/**
|
||||
* @see Image.width
|
||||
*/
|
||||
override val width: Int
|
||||
get() = bitmap.width
|
||||
|
||||
/**
|
||||
* @see Image.height
|
||||
*/
|
||||
override val height: Int
|
||||
get() = bitmap.height
|
||||
|
||||
override val config: ImageConfig get() = ImageConfig.Argb8888
|
||||
|
||||
/**
|
||||
* @see Image.colorSpace
|
||||
*/
|
||||
override val colorSpace: ColorSpace
|
||||
get() = ColorSpaces.Srgb
|
||||
|
||||
/**
|
||||
* @see Image.hasAlpha
|
||||
*/
|
||||
override val hasAlpha: Boolean
|
||||
get() = bitmap.hasAlpha()
|
||||
|
||||
/**
|
||||
* @see Image.nativeImage
|
||||
*/
|
||||
override val nativeImage: NativeImage
|
||||
get() = bitmap
|
||||
|
||||
/**
|
||||
* @see
|
||||
*/
|
||||
override fun prepareToDraw() {
|
||||
bitmap.prepareToDraw()
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ChannelContent(channel: Channel = Channel("Default", 7)) {
|
||||
val typography = MaterialTheme.typography()
|
||||
|
|
@ -37,7 +86,10 @@ fun ChannelContent(channel: Channel = Channel("Default", 7)) {
|
|||
)
|
||||
|
||||
Row(modifier = LayoutGravity.Center) {
|
||||
val image = imageResource(id = R.drawable.qrcode)
|
||||
// simulated qr code
|
||||
// val image = imageResource(id = R.drawable.qrcode)
|
||||
val image = AndroidImage(UIState.channelQR)
|
||||
|
||||
Container(modifier = LayoutGravity.Center + LayoutSize.Min(200.dp, 200.dp)) {
|
||||
DrawImage(image = image)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue