diff --git a/classic-components-example/adjustable-filters/src/main/java/io/scanbot/example/ExampleApplication.kt b/classic-components-example/adjustable-filters/src/main/java/io/scanbot/example/ExampleApplication.kt index cc53c9fd..3e901caa 100755 --- a/classic-components-example/adjustable-filters/src/main/java/io/scanbot/example/ExampleApplication.kt +++ b/classic-components-example/adjustable-filters/src/main/java/io/scanbot/example/ExampleApplication.kt @@ -53,7 +53,7 @@ class ExampleApplication : Application(), CoroutineScope { launch { // Clear all previously created documents in storage - ScanbotSDK(this@ExampleApplication).getSdkComponent()!!.provideDocumentStorage().deleteAll() + ScanbotSDK(this@ExampleApplication).documentApi.deleteAllDocuments() } } } diff --git a/classic-components-example/barcode-scanner/src/main/java/io/scanbot/example/ui/BarcodeResultActivity.kt b/classic-components-example/barcode-scanner/src/main/java/io/scanbot/example/ui/BarcodeResultActivity.kt index 9a045111..77ff2a08 100644 --- a/classic-components-example/barcode-scanner/src/main/java/io/scanbot/example/ui/BarcodeResultActivity.kt +++ b/classic-components-example/barcode-scanner/src/main/java/io/scanbot/example/ui/BarcodeResultActivity.kt @@ -55,7 +55,7 @@ class BarcodeResultActivity : AppCompatActivity() { BarcodeItemBinding.inflate(layoutInflater, binding.scannedItems, false) .also { item.sourceImage?.let { image -> - it.image.setImageBitmap(image.toBitmap()?.getOrNull()) + it.image.setImageBitmap(image.toBitmap().getOrNull()) } it.barcodeFormat.text = item.format.name it.docFormat.text = item.extractedDocument?.let { diff --git a/classic-components-example/build.gradle b/classic-components-example/build.gradle index f7795bde..7d45f113 100644 --- a/classic-components-example/build.gradle +++ b/classic-components-example/build.gradle @@ -15,7 +15,7 @@ allprojects { jvmToolchainVersion = 17 - scanbotSdkVersion = "8.0.0.61-STAGING-SNAPSHOT" + scanbotSdkVersion = "8.0.0.64-STAGING-SNAPSHOT" androidCoreKtxVersion = "1.6.0" constraintLayoutVersion = "2.0.4" diff --git a/classic-components-example/camera-fragment/src/main/java/io/scanbot/example/ExampleApplication.kt b/classic-components-example/camera-fragment/src/main/java/io/scanbot/example/ExampleApplication.kt index eafab0a2..e95e2c62 100755 --- a/classic-components-example/camera-fragment/src/main/java/io/scanbot/example/ExampleApplication.kt +++ b/classic-components-example/camera-fragment/src/main/java/io/scanbot/example/ExampleApplication.kt @@ -50,7 +50,7 @@ class ExampleApplication : Application(), CoroutineScope { launch { getAppStorageDir(this@ExampleApplication).deleteRecursively() - ScanbotSDK(this@ExampleApplication).getSdkComponent()!!.provideDocumentStorage().deleteAll() + ScanbotSDK(this@ExampleApplication).documentApi.deleteAllDocuments() } } } diff --git a/classic-components-example/camera-view-aspect-ratio-finder/src/main/java/io/scanbot/example/MainActivity.kt b/classic-components-example/camera-view-aspect-ratio-finder/src/main/java/io/scanbot/example/MainActivity.kt index c783f3fe..4ecce016 100755 --- a/classic-components-example/camera-view-aspect-ratio-finder/src/main/java/io/scanbot/example/MainActivity.kt +++ b/classic-components-example/camera-view-aspect-ratio-finder/src/main/java/io/scanbot/example/MainActivity.kt @@ -21,9 +21,11 @@ import io.scanbot.sdk.ScanbotSDK import io.scanbot.sdk.camera.* import io.scanbot.sdk.document.DocumentAutoSnappingController import io.scanbot.sdk.document.DocumentScannerFrameHandler +import io.scanbot.sdk.documentscanner.DocumentDetectionResult import io.scanbot.sdk.documentscanner.DocumentDetectionStatus import io.scanbot.sdk.documentscanner.DocumentScanner import io.scanbot.sdk.documentscanner.DocumentScannerParameters +import io.scanbot.sdk.documentscanner.DocumentScanningResult import io.scanbot.sdk.geometry.AspectRatio import io.scanbot.sdk.image.ImageRef import io.scanbot.sdk.imageprocessing.ScanbotSdkImageProcessor @@ -128,14 +130,14 @@ class MainActivity : AppCompatActivity(), DocumentScannerFrameHandler.ResultHand } override fun handle( - result: Result, + result: Result, frame: FrameHandler.Frame ): Boolean { // Here you are continuously notified about document scanning results. // For example, you can show a user guidance text depending on the current scanning status. result.onSuccess { value -> userGuidanceHint.post { - showUserGuidance(value.detectionStatus) + showUserGuidance(value.status) } } diff --git a/classic-components-example/camera-view/src/main/java/io/scanbot/example/MainActivity.kt b/classic-components-example/camera-view/src/main/java/io/scanbot/example/MainActivity.kt index f62f69bb..0cd1654d 100755 --- a/classic-components-example/camera-view/src/main/java/io/scanbot/example/MainActivity.kt +++ b/classic-components-example/camera-view/src/main/java/io/scanbot/example/MainActivity.kt @@ -31,6 +31,7 @@ import io.scanbot.sdk.camera.FrameHandler import io.scanbot.sdk.camera.PictureCallback import io.scanbot.sdk.document.DocumentAutoSnappingController import io.scanbot.sdk.document.DocumentScannerFrameHandler +import io.scanbot.sdk.documentscanner.DocumentDetectionResult import io.scanbot.sdk.documentscanner.DocumentDetectionStatus import io.scanbot.sdk.documentscanner.DocumentScanner import io.scanbot.sdk.image.ImageRef @@ -172,14 +173,14 @@ class MainActivity : AppCompatActivity(), DocumentScannerFrameHandler.ResultHand } override fun handle( - result: Result, + result: Result, frame: FrameHandler.Frame ): Boolean { // Here you are continuously notified about document scanning results. // For example, you can show a user guidance text depending on the current scanning status. result.onSuccess { data -> userGuidanceHint.post { - showUserGuidance(data.detectionStatus) + showUserGuidance(data.status) } } diff --git a/classic-components-example/check-scanner/src/main/java/io/scanbot/example/CheckScannerActivity.kt b/classic-components-example/check-scanner/src/main/java/io/scanbot/example/CheckScannerActivity.kt index 3275ebcc..d9cf7677 100644 --- a/classic-components-example/check-scanner/src/main/java/io/scanbot/example/CheckScannerActivity.kt +++ b/classic-components-example/check-scanner/src/main/java/io/scanbot/example/CheckScannerActivity.kt @@ -51,7 +51,7 @@ class CheckScannerActivity : AppCompatActivity() { frameHandler = attach(cameraView, checkScanner) frameHandler.addResultHandler { result, frame -> result.onSuccess { scanningResult -> - if (scanningResult?.status == CheckMagneticInkStripScanningStatus.SUCCESS) { + if (scanningResult.status == CheckMagneticInkStripScanningStatus.SUCCESS) { frameHandler.isEnabled = false startActivity( CheckScannerResultActivity.newIntent( diff --git a/classic-components-example/document-scanner/src/main/java/io/scanbot/example/DocumentCameraActivity.kt b/classic-components-example/document-scanner/src/main/java/io/scanbot/example/DocumentCameraActivity.kt index c1930456..266e13c0 100755 --- a/classic-components-example/document-scanner/src/main/java/io/scanbot/example/DocumentCameraActivity.kt +++ b/classic-components-example/document-scanner/src/main/java/io/scanbot/example/DocumentCameraActivity.kt @@ -72,7 +72,7 @@ class DocumentCameraActivity : AppCompatActivity() { // For example, you can show a user guidance text depending on the current scanning status. result.onSuccess { data -> userGuidanceHint.post { - showUserGuidance(data.detectionStatus) + showUserGuidance(data.status) } } false // typically you need to return false diff --git a/classic-components-example/document-scanner/src/main/java/io/scanbot/example/ExampleApplication.kt b/classic-components-example/document-scanner/src/main/java/io/scanbot/example/ExampleApplication.kt index 1d38e75f..d366bec5 100755 --- a/classic-components-example/document-scanner/src/main/java/io/scanbot/example/ExampleApplication.kt +++ b/classic-components-example/document-scanner/src/main/java/io/scanbot/example/ExampleApplication.kt @@ -49,7 +49,7 @@ class ExampleApplication : Application(), CoroutineScope { launch { // Clear all previously created documents in storage - ScanbotSDK(this@ExampleApplication).getSdkComponent()!!.provideDocumentStorage().deleteAll() + ScanbotSDK(this@ExampleApplication).documentApi.deleteAllDocuments() } } } diff --git a/classic-components-example/mrz-scanner/src/main/java/io/scanbot/example/MRZStillImageDetectionActivity.kt b/classic-components-example/mrz-scanner/src/main/java/io/scanbot/example/MRZStillImageDetectionActivity.kt index e8c05bff..74c1b4b1 100755 --- a/classic-components-example/mrz-scanner/src/main/java/io/scanbot/example/MRZStillImageDetectionActivity.kt +++ b/classic-components-example/mrz-scanner/src/main/java/io/scanbot/example/MRZStillImageDetectionActivity.kt @@ -70,8 +70,7 @@ class MrzStillImageScanningActivity : AppCompatActivity() { applyEdgeToEdge(findViewById(R.id.root_view)) docScannerResultLauncher = - registerForActivityResultOk(DocumentScannerActivity.ResultContract()) { resultEntity -> - val document = resultEntity.result!! + registerForActivityResultOk(DocumentScannerActivity.ResultContract()) { document -> page = document.pageAtIndex(0) ?: kotlin.run { Log.e(Const.LOG_TAG, "Error obtaining scanned page!") this@MrzStillImageScanningActivity.showToast("Error obtaining scanned page!") diff --git a/classic-components-example/ocr/src/main/java/io/scanbot/example/ExampleApplication.kt b/classic-components-example/ocr/src/main/java/io/scanbot/example/ExampleApplication.kt index 4fed3f42..54e8ca06 100755 --- a/classic-components-example/ocr/src/main/java/io/scanbot/example/ExampleApplication.kt +++ b/classic-components-example/ocr/src/main/java/io/scanbot/example/ExampleApplication.kt @@ -52,7 +52,7 @@ class ExampleApplication : Application(), CoroutineScope { launch { getAppStorageDir(this@ExampleApplication).deleteRecursively() // Clear all previously created documents in storage - ScanbotSDK(this@ExampleApplication).getSdkComponent()!!.provideDocumentStorage().deleteAll() + ScanbotSDK(this@ExampleApplication).documentApi.deleteAllDocuments() } } } diff --git a/data-capture-ready-to-use-ui-example/app/build.gradle b/data-capture-ready-to-use-ui-example/app/build.gradle index c35c2713..d4253766 100644 --- a/data-capture-ready-to-use-ui-example/app/build.gradle +++ b/data-capture-ready-to-use-ui-example/app/build.gradle @@ -74,7 +74,7 @@ dependencies { implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version") - def scanbotSdkVersion = "8.0.0.61-STAGING-SNAPSHOT" + def scanbotSdkVersion = "8.0.0.64-STAGING-SNAPSHOT" implementation("io.scanbot:sdk-package-4:$scanbotSdkVersion") implementation("io.scanbot:rtu-ui-v2-bundle:$scanbotSdkVersion") diff --git a/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/Application.kt b/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/Application.kt index b0e1bb5b..c3e0f753 100644 --- a/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/Application.kt +++ b/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/Application.kt @@ -86,7 +86,7 @@ class Application : Application(), CoroutineScope { launch { // Leaving as is to clean end-users' storage for next several app updates. - ScanbotSDK(this@Application).getSdkComponent()!!.provideDocumentStorage().deleteAll() + ScanbotSDK(this@Application).documentApi.deleteAllDocuments() SharingCopier.clear(this@Application) } } diff --git a/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/MainActivity.kt b/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/MainActivity.kt index 68b43256..4776cff3 100644 --- a/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/MainActivity.kt +++ b/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/MainActivity.kt @@ -7,6 +7,7 @@ import android.widget.Toast import androidx.activity.result.ActivityResultLauncher import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat +import io.scanbot.common.onSuccess import io.scanbot.example.databinding.* import io.scanbot.example.fragments.* import io.scanbot.example.util.* @@ -175,15 +176,15 @@ class MainActivity : AppCompatActivity() { init { creditCardUiResultLauncher = - registerForActivityResult(CreditCardScannerActivity.ResultContract()) { resultEntity: CreditCardScannerActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.creditCard?.let { + registerForActivityResult(CreditCardScannerActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { result -> + result.creditCard?.let { val creditCard = CreditCard(it) val cardNumber: String = creditCard.cardNumber.value.text val cardholderName: String = creditCard.cardholderName?.value?.text ?: "" val expiryDate: String? = creditCard.expiryDate?.value?.text Toast.makeText( - this, + this@MainActivity, "Card Number: $cardNumber, Cardholder Name: $cardholderName, Expiry Date: $expiryDate", Toast.LENGTH_LONG ).show() @@ -193,25 +194,20 @@ class MainActivity : AppCompatActivity() { mrzDefaultUiResultLauncher = registerForActivityResultOk(MrzScannerActivity.ResultContract()) { resultEntity -> - if (resultEntity.resultOk) { - resultEntity.result?.mrzDocument?.let { - showMrzDialog(it) - } + resultEntity.mrzDocument?.let { + showMrzDialog(it) } } textDataScannerResultLauncher = - registerForActivityResult(TextPatternScannerActivity.ResultContract()) { resultEntity: TextPatternScannerActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.rawText?.let { - Toast.makeText(this, it, Toast.LENGTH_LONG).show() - } + registerForActivityResultOk(TextPatternScannerActivity.ResultContract()) { resultEntity -> + resultEntity.rawText.let { + Toast.makeText(this, it, Toast.LENGTH_LONG).show() } } vinScannerResultLauncher = - registerForActivityResultOk(VinScannerActivity.ResultContract()) { resultEntity -> - val vinScanResult = resultEntity.result!! + registerForActivityResultOk(VinScannerActivity.ResultContract()) { vinScanResult -> Toast.makeText( this@MainActivity, "VIN Scanned: ${vinScanResult.textResult.rawText}", @@ -221,12 +217,12 @@ class MainActivity : AppCompatActivity() { dataExtractorResultLauncher = registerForActivityResultOk(DocumentDataExtractorActivity.ResultContract()) { resultEntity -> - handleDocumentDataExtractorResult(listOfNotNull(resultEntity.result)) + handleDocumentDataExtractorResult(listOfNotNull(resultEntity)) } checkScannerResultLauncher = registerForActivityResultOk(CheckScannerActivity.ResultContract()) { resultEntity -> - handleCheckScannerResult(resultEntity.result!!) + handleCheckScannerResult(resultEntity) } } } diff --git a/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/doc_code_snippet/cheque/CheckUiSnippet.kt b/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/doc_code_snippet/cheque/CheckUiSnippet.kt index 2c46798e..06ceb14c 100644 --- a/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/doc_code_snippet/cheque/CheckUiSnippet.kt +++ b/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/doc_code_snippet/cheque/CheckUiSnippet.kt @@ -18,6 +18,7 @@ import androidx.activity.result.ActivityResultLauncher import androidx.appcompat.app.AppCompatActivity import androidx.compose.ui.platform.ComposeView import io.scanbot.common.Result +import io.scanbot.common.onCancellation import io.scanbot.common.onFailure import io.scanbot.common.onSuccess import io.scanbot.example.* @@ -59,12 +60,25 @@ class StartCheckUiSnippet : AppCompatActivity() { // @Tag("Launching the scanner") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(CheckScannerActivity.ResultContract()) { resultEntity: CheckScannerActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.check?.let { + registerForActivityResult(CheckScannerActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { checkResult -> + checkResult.check?.let { // Here you can handle `check document` and present recognized Check information (routing number, account number, etc.) wrapCheck(it) } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -88,12 +102,25 @@ class CheckPaletteSnippet : AppCompatActivity() { // @Tag("Palette") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(CheckScannerActivity.ResultContract()) { resultEntity: CheckScannerActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.check?.let { + registerForActivityResult(CheckScannerActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { checkResult -> + checkResult.check?.let { // Here you can handle `check document` and present recognized Check information (routing number, account number, etc.) wrapCheck(it) } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -139,12 +166,25 @@ class CheckLocalizationSnippet : AppCompatActivity() { // @Tag("Localization") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(CheckScannerActivity.ResultContract()) { resultEntity: CheckScannerActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.check?.let { + registerForActivityResult(CheckScannerActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { checkResult -> + checkResult.check?.let { // Here you can handle `check document` and present recognized Check information (routing number, account number, etc.) wrapCheck(it) } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -176,12 +216,25 @@ class CheckIntroductionSnippet : AppCompatActivity() { // @Tag("Introduction") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(CheckScannerActivity.ResultContract()) { resultEntity: CheckScannerActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.check?.let { + registerForActivityResult(CheckScannerActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { checkResult -> + checkResult.check?.let { // Here you can handle `check document` and present recognized Check information (routing number, account number, etc.) wrapCheck(it) } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -241,12 +294,25 @@ class CheckUserGuidanceSnippet : AppCompatActivity() { // @Tag("User guidance") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(CheckScannerActivity.ResultContract()) { resultEntity: CheckScannerActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.check?.let { + registerForActivityResult(CheckScannerActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { checkResult -> + checkResult.check?.let { // Here you can handle `check document` and present recognized Check information (routing number, account number, etc.) wrapCheck(it) } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -295,12 +361,25 @@ class CheckTopBarSnippet : AppCompatActivity() { // @Tag("Top bar") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(CheckScannerActivity.ResultContract()) { resultEntity: CheckScannerActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.check?.let { + registerForActivityResult(CheckScannerActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { checkResult -> + checkResult.check?.let { // Here you can handle `check document` and present recognized Check information (routing number, account number, etc.) wrapCheck(it) } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -340,12 +419,25 @@ class CheckFinderSnippet : AppCompatActivity() { // @Tag("Finder overlay") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(CheckScannerActivity.ResultContract()) { resultEntity: CheckScannerActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.check?.let { + registerForActivityResult(CheckScannerActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { checkResult -> + checkResult.check?.let { // Here you can handle `check document` and present recognized Check information (routing number, account number, etc.) wrapCheck(it) } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -377,12 +469,25 @@ class CheckActionBarSnippet : AppCompatActivity() { // @Tag("Action bar") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(CheckScannerActivity.ResultContract()) { resultEntity: CheckScannerActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.check?.let { + registerForActivityResult(CheckScannerActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { checkResult -> + checkResult.check?.let { // Here you can handle `check document` and present recognized Check information (routing number, account number, etc.) wrapCheck(it) } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -434,12 +539,25 @@ class CheckScanningSnippet : AppCompatActivity() { // @Tag("Scanning") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(CheckScannerActivity.ResultContract()) { resultEntity: CheckScannerActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.check?.let { + registerForActivityResult(CheckScannerActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { checkResult -> + checkResult.check?.let { // Here you can handle `check document` and present recognized Check information (routing number, account number, etc.) wrapCheck(it) } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } diff --git a/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/doc_code_snippet/creditcard/CreditCardUiSnippet.kt b/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/doc_code_snippet/creditcard/CreditCardUiSnippet.kt index f77300a2..a8675016 100644 --- a/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/doc_code_snippet/creditcard/CreditCardUiSnippet.kt +++ b/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/doc_code_snippet/creditcard/CreditCardUiSnippet.kt @@ -16,6 +16,10 @@ import android.widget.Toast import androidx.activity.result.ActivityResultLauncher import androidx.appcompat.app.AppCompatActivity import androidx.compose.ui.platform.ComposeView +import io.scanbot.common.Result +import io.scanbot.common.onCancellation +import io.scanbot.common.onFailure +import io.scanbot.common.onSuccess import io.scanbot.example.* import io.scanbot.sdk.* import io.scanbot.sdk.creditcard.entity.* @@ -43,19 +47,32 @@ class StartCreditCardUiSnippet : AppCompatActivity() { // @Tag("Launching the scanner") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(CreditCardScannerActivity.ResultContract()) { resultEntity: CreditCardScannerActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.creditCard?.let { - val creditCard = CreditCard(it) + registerForActivityResult(CreditCardScannerActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { creditCardResult -> + creditCardResult.creditCard?.let { + val creditCard = CreditCard(creditCardResult.creditCard!!) val cardNumber: String = creditCard.cardNumber.value.text val cardholderName: String = creditCard.cardholderName?.value?.text ?: "" val expiryDate: String? = creditCard.expiryDate?.value?.text Toast.makeText( - this, + this@StartCreditCardUiSnippet, "Card Number: $cardNumber, Cardholder Name: $cardholderName, Expiry Date: $expiryDate", Toast.LENGTH_LONG ).show() } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -79,19 +96,32 @@ class CreditCardPaletteSnippet : AppCompatActivity() { // @Tag("Palette") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(CreditCardScannerActivity.ResultContract()) { resultEntity: CreditCardScannerActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.creditCard?.let { - val creditCard = CreditCard(it) + registerForActivityResult(CreditCardScannerActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { creditCardResult -> + creditCardResult.creditCard?.let { + val creditCard = CreditCard(creditCardResult.creditCard!!) val cardNumber: String = creditCard.cardNumber.value.text val cardholderName: String = creditCard.cardholderName?.value?.text ?: "" val expiryDate: String? = creditCard.expiryDate?.value?.text Toast.makeText( - this, + this@CreditCardPaletteSnippet, "Card Number: $cardNumber, Cardholder Name: $cardholderName, Expiry Date: $expiryDate", Toast.LENGTH_LONG ).show() } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -137,19 +167,32 @@ class CreditCardLocalizationSnippet : AppCompatActivity() { // @Tag("Localization") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(CreditCardScannerActivity.ResultContract()) { resultEntity: CreditCardScannerActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.creditCard?.let { - val creditCard = CreditCard(it) + registerForActivityResult(CreditCardScannerActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { creditCardResult -> + creditCardResult.creditCard?.let { + val creditCard = CreditCard(creditCardResult.creditCard!!) val cardNumber: String = creditCard.cardNumber.value.text val cardholderName: String = creditCard.cardholderName?.value?.text ?: "" val expiryDate: String? = creditCard.expiryDate?.value?.text Toast.makeText( - this, + this@CreditCardLocalizationSnippet, "Card Number: $cardNumber, Cardholder Name: $cardholderName, Expiry Date: $expiryDate", Toast.LENGTH_LONG ).show() } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -181,19 +224,32 @@ class CreditCardIntroductionSnippet : AppCompatActivity() { // @Tag("Introduction") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(CreditCardScannerActivity.ResultContract()) { resultEntity: CreditCardScannerActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.creditCard?.let { - val creditCard = CreditCard(it) + registerForActivityResult(CreditCardScannerActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { creditCardResult -> + creditCardResult.creditCard?.let { + val creditCard = CreditCard(creditCardResult.creditCard!!) val cardNumber: String = creditCard.cardNumber.value.text val cardholderName: String = creditCard.cardholderName?.value?.text ?: "" val expiryDate: String? = creditCard.expiryDate?.value?.text Toast.makeText( - this, + this@CreditCardIntroductionSnippet, "Card Number: $cardNumber, Cardholder Name: $cardholderName, Expiry Date: $expiryDate", Toast.LENGTH_LONG ).show() } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -253,19 +309,32 @@ class CreditCardUserGuidanceSnippet : AppCompatActivity() { // @Tag("User guidance") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(CreditCardScannerActivity.ResultContract()) { resultEntity: CreditCardScannerActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.creditCard?.let { - val creditCard = CreditCard(it) + registerForActivityResult(CreditCardScannerActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { creditCardResult -> + creditCardResult.creditCard?.let { + val creditCard = CreditCard(creditCardResult.creditCard!!) val cardNumber: String = creditCard.cardNumber.value.text val cardholderName: String = creditCard.cardholderName?.value?.text ?: "" val expiryDate: String? = creditCard.expiryDate?.value?.text Toast.makeText( - this, + this@CreditCardUserGuidanceSnippet, "Card Number: $cardNumber, Cardholder Name: $cardholderName, Expiry Date: $expiryDate", Toast.LENGTH_LONG ).show() } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -314,19 +383,32 @@ class CreditCardTopBarSnippet : AppCompatActivity() { // @Tag("Top bar") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(CreditCardScannerActivity.ResultContract()) { resultEntity: CreditCardScannerActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.creditCard?.let { - val creditCard = CreditCard(it) + registerForActivityResult(CreditCardScannerActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { creditCardResult -> + creditCardResult.creditCard?.let { + val creditCard = CreditCard(creditCardResult.creditCard!!) val cardNumber: String = creditCard.cardNumber.value.text val cardholderName: String = creditCard.cardholderName?.value?.text ?: "" val expiryDate: String? = creditCard.expiryDate?.value?.text Toast.makeText( - this, + this@CreditCardTopBarSnippet, "Card Number: $cardNumber, Cardholder Name: $cardholderName, Expiry Date: $expiryDate", Toast.LENGTH_LONG ).show() } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -366,19 +448,32 @@ class CreditCardFinderSnippet : AppCompatActivity() { // @Tag("Finder overlay") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(CreditCardScannerActivity.ResultContract()) { resultEntity: CreditCardScannerActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.creditCard?.let { - val creditCard = CreditCard(it) + registerForActivityResult(CreditCardScannerActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { creditCardResult -> + creditCardResult.creditCard?.let { + val creditCard = CreditCard(creditCardResult.creditCard!!) val cardNumber: String = creditCard.cardNumber.value.text val cardholderName: String = creditCard.cardholderName?.value?.text ?: "" val expiryDate: String? = creditCard.expiryDate?.value?.text Toast.makeText( - this, + this@CreditCardFinderSnippet, "Card Number: $cardNumber, Cardholder Name: $cardholderName, Expiry Date: $expiryDate", Toast.LENGTH_LONG ).show() } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -410,19 +505,32 @@ class CreditCardActionBarSnippet : AppCompatActivity() { // @Tag("Action bar") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(CreditCardScannerActivity.ResultContract()) { resultEntity: CreditCardScannerActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.creditCard?.let { - val creditCard = CreditCard(it) + registerForActivityResult(CreditCardScannerActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { creditCardResult -> + creditCardResult.creditCard?.let { + val creditCard = CreditCard(creditCardResult.creditCard!!) val cardNumber: String = creditCard.cardNumber.value.text val cardholderName: String = creditCard.cardholderName?.value?.text ?: "" val expiryDate: String? = creditCard.expiryDate?.value?.text Toast.makeText( - this, + this@CreditCardActionBarSnippet, "Card Number: $cardNumber, Cardholder Name: $cardholderName, Expiry Date: $expiryDate", Toast.LENGTH_LONG ).show() } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -474,19 +582,32 @@ class CreditCardScanningSnippet : AppCompatActivity() { // @Tag("Scanning") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(CreditCardScannerActivity.ResultContract()) { resultEntity: CreditCardScannerActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.creditCard?.let { - val creditCard = CreditCard(it) + registerForActivityResult(CreditCardScannerActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { creditCardResult -> + creditCardResult.creditCard?.let { + val creditCard = CreditCard(creditCardResult.creditCard!!) val cardNumber: String = creditCard.cardNumber.value.text val cardholderName: String = creditCard.cardholderName?.value?.text ?: "" val expiryDate: String? = creditCard.expiryDate?.value?.text Toast.makeText( - this, + this@CreditCardScanningSnippet, "Card Number: $cardNumber, Cardholder Name: $cardholderName, Expiry Date: $expiryDate", Toast.LENGTH_LONG ).show() } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } diff --git a/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/doc_code_snippet/data_extractor/DataExtractionUiSnippet.kt b/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/doc_code_snippet/data_extractor/DataExtractionUiSnippet.kt index 93224f19..db8a3fff 100644 --- a/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/doc_code_snippet/data_extractor/DataExtractionUiSnippet.kt +++ b/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/doc_code_snippet/data_extractor/DataExtractionUiSnippet.kt @@ -18,6 +18,10 @@ import androidx.appcompat.app.AppCompatActivity import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.ui.Modifier import androidx.compose.ui.platform.ComposeView +import io.scanbot.common.Result +import io.scanbot.common.onCancellation +import io.scanbot.common.onFailure +import io.scanbot.common.onSuccess import io.scanbot.example.* import io.scanbot.sdk.* import io.scanbot.sdk.documentdata.DocumentDataExtractorCommonConfiguration @@ -44,11 +48,24 @@ class StartDocumentDataExtractorUiSnippet : AppCompatActivity() { // @Tag("Launching the scanner") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(DocumentDataExtractorActivity.ResultContract()) { resultEntity: DocumentDataExtractorActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.document?.let { document -> + registerForActivityResult(DocumentDataExtractorActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { result -> + result?.document?.let { document -> wrapGenericDocument(document) } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -72,11 +89,24 @@ class DocumentDataExtractorPaletteSnippet : AppCompatActivity() { // @Tag("Palette") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(DocumentDataExtractorActivity.ResultContract()) { resultEntity: DocumentDataExtractorActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.document?.let { document -> + registerForActivityResult(DocumentDataExtractorActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { result -> + result?.document?.let { document -> wrapGenericDocument(document) } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -122,11 +152,24 @@ class DocumentDataExtractorLocalizationSnippet : AppCompatActivity() { // @Tag("Localization") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(DocumentDataExtractorActivity.ResultContract()) { resultEntity: DocumentDataExtractorActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.document?.let { document -> + registerForActivityResult(DocumentDataExtractorActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { result -> + result?.document?.let { document -> wrapGenericDocument(document) } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -158,11 +201,24 @@ class DocumentDataExtractorIntroductionSnippet : AppCompatActivity() { // @Tag("Introduction") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(DocumentDataExtractorActivity.ResultContract()) { resultEntity: DocumentDataExtractorActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.document?.let { document -> + registerForActivityResult(DocumentDataExtractorActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { result -> + result?.document?.let { document -> wrapGenericDocument(document) } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -222,11 +278,24 @@ class DocumentDataExtractorUserGuidanceSnippet : AppCompatActivity() { // @Tag("User guidance") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(DocumentDataExtractorActivity.ResultContract()) { resultEntity: DocumentDataExtractorActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.document?.let { document -> + registerForActivityResult(DocumentDataExtractorActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { result -> + result?.document?.let { document -> wrapGenericDocument(document) } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -266,11 +335,24 @@ class DocumentDataExtractorTopBarSnippet : AppCompatActivity() { // @Tag("Top bar") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(DocumentDataExtractorActivity.ResultContract()) { resultEntity: DocumentDataExtractorActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.document?.let { document -> + registerForActivityResult(DocumentDataExtractorActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { result -> + result?.document?.let { document -> wrapGenericDocument(document) } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -310,11 +392,24 @@ class DocumentDataExtractorFinderSnippet : AppCompatActivity() { // @Tag("Finder overlay") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(DocumentDataExtractorActivity.ResultContract()) { resultEntity: DocumentDataExtractorActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.document?.let { document -> + registerForActivityResult(DocumentDataExtractorActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { result -> + result?.document?.let { document -> wrapGenericDocument(document) } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -345,11 +440,24 @@ class DocumentDataExtractorActionBarSnippet : AppCompatActivity() { // @Tag("Action bar") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(DocumentDataExtractorActivity.ResultContract()) { resultEntity: DocumentDataExtractorActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.document?.let { document -> + registerForActivityResult(DocumentDataExtractorActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { result -> + result?.document?.let { document -> wrapGenericDocument(document) } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } @@ -401,11 +509,24 @@ class DocumentDataExtractorScanningSnippet : AppCompatActivity() { // @Tag("Scanning") val resultLauncher: ActivityResultLauncher = - registerForActivityResult(DocumentDataExtractorActivity.ResultContract()) { resultEntity: DocumentDataExtractorActivity.Result -> - if (resultEntity.resultOk) { - resultEntity.result?.document?.let { document -> + registerForActivityResult(DocumentDataExtractorActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { result -> + result?.document?.let { document -> wrapGenericDocument(document) } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } } diff --git a/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/doc_code_snippet/migration/RtuUi2DocumentSnippets.kt b/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/doc_code_snippet/migration/RtuUi2DocumentSnippets.kt index b7184337..d38136aa 100644 --- a/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/doc_code_snippet/migration/RtuUi2DocumentSnippets.kt +++ b/data-capture-ready-to-use-ui-example/app/src/main/java/io/scanbot/example/doc_code_snippet/migration/RtuUi2DocumentSnippets.kt @@ -19,6 +19,10 @@ import android.widget.Button import android.widget.ImageView import androidx.activity.result.ActivityResultLauncher import androidx.appcompat.app.AppCompatActivity +import io.scanbot.common.Result +import io.scanbot.common.onCancellation +import io.scanbot.common.onFailure +import io.scanbot.common.onSuccess import io.scanbot.example.R import io.scanbot.sdk.* import io.scanbot.sdk.common.* @@ -43,16 +47,29 @@ class MainActivityWithDocumentScannerRtuV2 : AppCompatActivity() { val previewImageView = findViewById(R.id.first_page_image_preview) documentScannerResultLauncher = - registerForActivityResultOk(io.scanbot.sdk.ui_v2.document.DocumentScannerActivity.ResultContract()) { - resultEntity: io.scanbot.sdk.ui_v2.document.DocumentScannerActivity.Result -> - val result: Document? = resultEntity.result - val pages: List? = result?.pages - pages?.get(0)?.let { + registerForActivityResult(DocumentScannerActivity.ResultContract()) { resultEntity -> + resultEntity.onSuccess { document -> + val pages: List = document.pages + pages.get(0).let { // in v2 you can access the image bitmap directly from the Page: val previewImage = it.documentPreviewImage previewImageView.setImageBitmap(previewImage) } + }.onCancellation { + // Indicates that the cancel button was tapped. Or screen is closed by other reason. + }.onFailure { + // Optional activity closing cause handling to understand the reason scanner result is not provided + when (it) { + is Result.InvalidLicenseError -> { + // indicate that the Scanbot SDK license is invalid + } + + else -> { + // Handle other errors + } + } } + } findViewById