Fixed running on Android

This commit is contained in:
dankito 2022-03-13 23:25:49 +01:00
parent 4061206e34
commit f3292e38ae
6 changed files with 31 additions and 11 deletions

View File

@ -9,6 +9,9 @@ group = "net.codinux.banking.epcqrcode.android"
dependencies {
implementation(project(":EpcQrCode"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
implementation("androidx.core:core-ktx:1.2.0")
implementation("androidx.appcompat:appcompat:1.1.0")
implementation("androidx.constraintlayout:constraintlayout:1.1.3")

View File

@ -9,7 +9,7 @@ import com.google.android.material.textfield.TextInputEditText
import com.soywiz.korim.format.toAndroidBitmap
val EpcQrCode.image: Bitmap
val EpcQrCode.androidBitmap: Bitmap
get() = this.bitmap.toAndroidBitmap()

View File

@ -3,8 +3,13 @@ package net.codinux.banking.epcqrcode
import android.graphics.Bitmap
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Button
import kotlinx.android.synthetic.main.activity_main.*
import kotlin.concurrent.thread
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class MainActivity : AppCompatActivity() {
@ -14,7 +19,13 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)
btnGenerateQrCode.setOnClickListener { generateQrCode() }
findViewById<Button>(R.id.btnGenerateQrCode)?.setOnClickListener(object : View.OnClickListener { // don't know why Lambda is not working anymore
override fun onClick(p0: View?) {
generateQrCode()
}
})
}
@ -29,14 +40,14 @@ class MainActivity : AppCompatActivity() {
}
private fun generateQrCodeAsync(param: EpcQrCodeConfig, done: (Bitmap) -> Unit) {
thread {
GlobalScope.launch(Dispatchers.IO) {
val density = resources.displayMetrics.density
val config = EncodeToQrCodeConfig((EncodeToQrCodeConfig.DefaultWidth * density).toInt(), (EncodeToQrCodeConfig.DefaultHeight * density).toInt())
val epcQrCode = EpcQrCodeGenerator().generateEpcQrCode(param)
runOnUiThread {
done(epcQrCode.image)
withContext(Dispatchers.Main) {
done(epcQrCode.androidBitmap)
}
}
}

View File

@ -6,8 +6,8 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10")
classpath("com.android.tools.build:gradle:3.5.2")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
classpath("com.android.tools.build:gradle:4.0.2")
}
}

View File

@ -5,4 +5,10 @@ xcodeproj=./EpcQrCodeiOSApp
kotlinVersion=1.6.10
quarkusVersion=1.8.2.Final
coroutinesVersion=1.6.0
quarkusVersion=1.9.2.Final
android.useAndroidX=true

View File

@ -8,13 +8,13 @@ pluginManagement {
resolutionStrategy {
eachPlugin {
if (requested.id.namespace == "com.android" || requested.id.name == "kotlin-android-extensions") {
useModule("com.android.tools.build:gradle:3.5.2")
useModule("com.android.tools.build:gradle:4.0.2")
}
}
}
plugins {
id("io.quarkus") version "1.8.2.Final" // TODO: why doesn't he find quarkusVersion?
id("io.quarkus") version "1.9.2.Final" // TODO: why doesn't he find quarkusVersion?
}
}