Implemented native app

This commit is contained in:
dankito 2022-03-14 02:14:02 +01:00
parent c47dacae12
commit 510e6bf1ce
5 changed files with 152 additions and 15 deletions

View File

@ -33,4 +33,76 @@ open class EpcQrCode(
this.bitmap = bitmap.scaled(heightAndWidth, heightAndWidth, true) this.bitmap = bitmap.scaled(heightAndWidth, heightAndWidth, true)
} }
open fun qrCodeAsString(): String {
val string = StringBuilder(bitmap.height * bitmap.width)
for (y in 1 until bitmap.height) {
for (x in 1 until bitmap.width) {
if (isBitSet(x, y)) {
string.append("██")
} else {
string.append(" ")
}
}
string.appendLine()
}
return string.toString()
}
open fun qrCodeAsSmallString(): String {
val string = StringBuilder(bitmap.height * bitmap.width)
for (y in 1 until bitmap.height - 1 step 2) {
for (x in 1 until bitmap.width) {
val currentRowBit = bitmap.getInt(x, y)
val nextRowBit = bitmap.getInt(x, y + 1)
if (currentRowBit == nextRowBit) {
if (isBitSet(currentRowBit)) {
string.append("")
} else {
string.append(" ")
}
} else {
if (isBitSet(currentRowBit)) {
string.append("")
} else {
string.append("")
}
}
}
string.appendLine()
}
if (bitmap.height % 2 == 0) { // if last row is odd
val y = bitmap.height - 1
for (x in 1 until bitmap.width) {
if (isBitSet(x, y)) {
string.append("")
} else {
string.append(" ")
}
}
string.appendLine()
}
return string.toString()
}
protected open fun isBitSet(x: Int, y: Int): Boolean {
val qrCodeBit = bitmap.getInt(x, y)
return isBitSet(qrCodeBit)
}
protected open fun isBitSet(qrCodeBitColorCode: Int): Boolean {
// black = -1, white = -16777216
return qrCodeBitColorCode < -1
}
} }

View File

@ -0,0 +1,37 @@
plugins {
kotlin("multiplatform")
}
kotlin {
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")
val nativeTarget = when {
hostOs == "Mac OS X" -> macosX64("native")
hostOs == "Linux" -> linuxX64("native")
isMingwX64 -> mingwX64("native")
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
}
nativeTarget.apply {
binaries {
executable {
baseName = "EpcQrCode"
entryPoint = "main"
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(project(":EpcQrCode"))
}
}
val nativeMain by getting
}
}

View File

@ -0,0 +1,15 @@
import net.codinux.banking.epcqrcode.EpcQrCodeConfig
import net.codinux.banking.epcqrcode.NativeApp
import platform.posix.exit
fun main(args: Array<String>) {
if (args.size < 3) {
println("Please enter recipient name, recipient IBAN, amount and an optional reference:\n./EpcQrCode.kexe \"Red cross\" BE72000000001616 \"50.00\" \"Urgency fund\"")
exit(0)
}
val config = EpcQrCodeConfig(args[0], args[1], args[2], if (args.size > 3) args[3] else null)
NativeApp().generateAndShowEpcQrCode(config)
}

View File

@ -0,0 +1,12 @@
package net.codinux.banking.epcqrcode
class NativeApp {
fun generateAndShowEpcQrCode(config: EpcQrCodeConfig) {
val epcQrCode = EpcQrCodeGenerator().generateEpcQrCode(config, 40)
println(epcQrCode.qrCodeAsSmallString())
}
}

View File

@ -1,21 +1,21 @@
pluginManagement { pluginManagement {
repositories { repositories {
gradlePluginPortal() gradlePluginPortal()
google() google()
jcenter() jcenter()
mavenCentral() mavenCentral()
} }
resolutionStrategy { resolutionStrategy {
eachPlugin { eachPlugin {
if (requested.id.namespace == "com.android" || requested.id.name == "kotlin-android-extensions") { if (requested.id.namespace == "com.android" || requested.id.name == "kotlin-android-extensions") {
useModule("com.android.tools.build:gradle:4.0.2") useModule("com.android.tools.build:gradle:4.0.2")
} }
}
} }
}
plugins { plugins {
id("io.quarkus") version "1.9.2.Final" // TODO: why doesn't he find quarkusVersion? id("io.quarkus") version "1.9.2.Final" // TODO: why doesn't he find quarkusVersion?
} }
} }
@ -25,4 +25,5 @@ rootProject.name = "EpcQrCode"
include(":EpcQrCode") include(":EpcQrCode")
include(":EpcQrCodeAndroidApp") include(":EpcQrCodeAndroidApp")
include(":EpcQrCodeJavaFxApp") include(":EpcQrCodeJavaFxApp")
include(":EpcQrCodeNativeApp")
include(":EpcQrCodeRest") include(":EpcQrCodeRest")