diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ScannerActivity.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ScannerActivity.kt index 2b53e1f9..67388c7f 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ScannerActivity.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ScannerActivity.kt @@ -19,6 +19,7 @@ import com.v2ray.ang.handler.MmkvManager import com.v2ray.ang.util.QRCodeDecoder import io.github.g00fy2.quickie.QRResult import io.github.g00fy2.quickie.ScanCustomCode +import io.github.g00fy2.quickie.config.BarcodeFormat import io.github.g00fy2.quickie.config.ScannerConfig class ScannerActivity : BaseActivity() { @@ -73,6 +74,7 @@ class ScannerActivity : BaseActivity() { setHapticSuccessFeedback(true) // enable (default) or disable haptic feedback when a barcode was detected setShowTorchToggle(true) // show or hide (default) torch/flashlight toggle button setShowCloseButton(true) // show or hide (default) close button + setBarcodeFormats(listOf(BarcodeFormat.QR_CODE)) } ) } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/util/QRCodeDecoder.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/util/QRCodeDecoder.kt index 446739b6..7f49ced6 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/util/QRCodeDecoder.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/util/QRCodeDecoder.kt @@ -65,9 +65,9 @@ object QRCodeDecoder { val qrReader = QRCodeReader() try { - qrReader.decode(BinaryBitmap(GlobalHistogramBinarizer(source)), mapOf(DecodeHintType.TRY_HARDER to true)).text + qrReader.decode(BinaryBitmap(GlobalHistogramBinarizer(source)), HINTS).text } catch (e: NotFoundException) { - qrReader.decode(BinaryBitmap(GlobalHistogramBinarizer(source.invert())), mapOf(DecodeHintType.TRY_HARDER to true)).text + qrReader.decode(BinaryBitmap(GlobalHistogramBinarizer(source.invert())), HINTS).text } }.getOrNull() } @@ -97,27 +97,9 @@ object QRCodeDecoder { } init { - val allFormats: List = arrayListOf( - BarcodeFormat.AZTEC, - BarcodeFormat.CODABAR, - BarcodeFormat.CODE_39, - BarcodeFormat.CODE_93, - BarcodeFormat.CODE_128, - BarcodeFormat.DATA_MATRIX, - BarcodeFormat.EAN_8, - BarcodeFormat.EAN_13, - BarcodeFormat.ITF, - BarcodeFormat.MAXICODE, - BarcodeFormat.PDF_417, - BarcodeFormat.QR_CODE, - BarcodeFormat.RSS_14, - BarcodeFormat.RSS_EXPANDED, - BarcodeFormat.UPC_A, - BarcodeFormat.UPC_E, - BarcodeFormat.UPC_EAN_EXTENSION - ) - HINTS[DecodeHintType.TRY_HARDER] = BarcodeFormat.QR_CODE - HINTS[DecodeHintType.POSSIBLE_FORMATS] = allFormats - HINTS[DecodeHintType.CHARACTER_SET] = Charsets.UTF_8 + // Keep decoding hints focused on QR codes and enable TRY_HARDER + UTF-8 charset for better success rate. + HINTS[DecodeHintType.TRY_HARDER] = true + HINTS[DecodeHintType.POSSIBLE_FORMATS] = listOf(BarcodeFormat.QR_CODE) + HINTS[DecodeHintType.CHARACTER_SET] = Charsets.UTF_8.name() } }