Implemented native app
This commit is contained in:
parent
c47dacae12
commit
510e6bf1ce
|
@ -33,4 +33,76 @@ open class EpcQrCode(
|
|||
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
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
||||
}
|
|
@ -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)
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package net.codinux.banking.epcqrcode
|
||||
|
||||
|
||||
class NativeApp {
|
||||
|
||||
fun generateAndShowEpcQrCode(config: EpcQrCodeConfig) {
|
||||
val epcQrCode = EpcQrCodeGenerator().generateEpcQrCode(config, 40)
|
||||
|
||||
println(epcQrCode.qrCodeAsSmallString())
|
||||
}
|
||||
|
||||
}
|
|
@ -25,4 +25,5 @@ rootProject.name = "EpcQrCode"
|
|||
include(":EpcQrCode")
|
||||
include(":EpcQrCodeAndroidApp")
|
||||
include(":EpcQrCodeJavaFxApp")
|
||||
include(":EpcQrCodeNativeApp")
|
||||
include(":EpcQrCodeRest")
|
||||
|
|
Loading…
Reference in New Issue