0
0
mirror of https://github.com/markusfisch/BinaryEye.git synced 2024-09-20 03:52:16 +02:00

Convert charset for PDF417 in an extension

And run it from PickActivity too to apply this conversion when
scanning from still images too.
This commit is contained in:
Markus Fisch 2022-09-29 18:39:01 +02:00
parent b634370a0b
commit 1b6b1cefe3
2 changed files with 21 additions and 13 deletions

View File

@ -461,18 +461,7 @@ class CameraActivity : AppCompatActivity() {
frameOrientation
)?.let { result ->
if (result.text != ignoreNext) {
if (result.barcodeFormat == BarcodeFormat.PDF_417 && result.text != null) {
val iso88591Text = result.text.toByteArray(Charset.forName("ISO-8859-1"))
val utf8Text = String(iso88591Text, Charset.forName("UTF-8"))
postResult(Result(utf8Text,
result.rawBytes,
result.numBits,
result.resultPoints,
result.barcodeFormat,
result.timestamp))
} else {
postResult(result)
}
postResult(result.redact())
decoding = false
}
}
@ -790,6 +779,25 @@ class CameraActivity : AppCompatActivity() {
}
}
fun Result.redact() = if (
barcodeFormat == BarcodeFormat.PDF_417 &&
text != null
) {
Result(
String(
text.toByteArray(Charset.forName("ISO-8859-1")),
Charset.forName("UTF-8")
),
rawBytes,
numBits,
resultPoints,
barcodeFormat,
timestamp
)
} else {
this
}
fun showResult(
activity: Activity,
result: Result,

View File

@ -201,7 +201,7 @@ class PickActivity : AppCompatActivity() {
private fun showResult() {
val r = result
if (r != null) {
showResult(this, r, vibrator)
showResult(this, r.redact(), vibrator)
finish()
} else {
applicationContext.toast(R.string.no_barcode_found)