-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
androidApp: Initial support for tickets [2/3]
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
- Loading branch information
1 parent
e61d787
commit 09cd734
Showing
4 changed files
with
160 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
androidApp/src/main/java/app/opass/ccip/android/utils/QrImageAnalyzer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 OPass | ||
* SPDX-License-Identifier: GPL-3.0-only | ||
*/ | ||
|
||
package app.opass.ccip.android.utils | ||
|
||
import android.util.Log | ||
import androidx.camera.core.ImageAnalysis | ||
import androidx.camera.core.ImageProxy | ||
import com.google.zxing.BarcodeFormat | ||
import com.google.zxing.Result | ||
import com.google.zxing.client.result.ResultParser | ||
import zxingcpp.BarcodeReader | ||
|
||
class QrImageAnalyzer(onTokenFound: (token: String) -> Unit = {}): ImageAnalysis.Analyzer { | ||
|
||
private val reader = BarcodeReader().apply { | ||
options.tryRotate = true | ||
} | ||
|
||
override fun analyze(image: ImageProxy) { | ||
image.use { | ||
reader.read(image).firstOrNull()?.let { rawResult -> | ||
if (rawResult.format != BarcodeReader.Format.QR_CODE || rawResult.text.isNullOrBlank()) return | ||
|
||
val result = Result( | ||
rawResult.text, | ||
rawResult.bytes, | ||
null, | ||
BarcodeFormat.QR_CODE | ||
) | ||
val parsedResult = ResultParser.parseResult(result) | ||
Log.d("AAYUSH", "TOKEN: ${parsedResult.displayResult}, ${rawResult.text}") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters