Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Make sure you have the latest stable version of [Android Studio](https://develop

2. There are 4 separate folders with standalone examples:

* **classic-components-example**: Example project for the Scanbot SDK Classic Components which allow for full customization.
* **classic-components-example**: Example project for the Scanbot SDK Classic Components which allow for full customization.
* **compose-custom-ui-example**: Example project for the Scanbot SDK Compose Custom Components which allow for full customization.
* **document-scanner-ready-to-use-ui-example:** Example project for the Scanbot Document Scanner SDK using our Ready-To-Use UI components.
* **data-capture-ready-to-use-ui-example**: Example project showcasing the Scanbot Data Capture Modules using our Ready-to-Use UI components.
Expand Down
11 changes: 11 additions & 0 deletions classic-components-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Scanbot SDK Classic Components examples

This project contains multiple standalone Android app modules demonstrating the Scanbot SDK Classic Components. Each module can be opened and run on its own. The only shared code lives in the `common` module.

## How to run a module

1. Open `scanbot-sdk-example-android/classic-components-example` in Android Studio.
2. Sync Gradle.
3. Choose one module in the **Run** configuration (each module is an `application`).
4. Add your Scanbot SDK license key in the module’s `ExampleApplication` or stay on demo mode.
5. Run the app on a device or emulator.
21 changes: 0 additions & 21 deletions classic-components-example/adjustable-filters/proguard-rules.pro

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import io.scanbot.sdk.imageprocessing.ParametricFilter
import kotlinx.coroutines.*

/**
Ths example uses new sdk APIs presented in Scanbot SDK v.8.x.x
Please, check the official documentation for more details:
This example uses the SDK APIs introduced in Scanbot SDK v8.x.x.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd remove the first "SDK" mention - it is clear that the API is from Scanbot SDK because it already says that in the second part of the sentence.
This example uses the APIs introduced in Scanbot SDK v8.x.x.

Please check the official documentation for more details:
Result API https://docs.scanbot.io/android/document-scanner-sdk/detailed-setup-guide/result-api/
ImageRef API https://docs.scanbot.io/android/document-scanner-sdk/detailed-setup-guide/image-ref-api/
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
/**
Ths example uses new sdk APIs presented in Scanbot SDK v.8.x.x
Please, check the official documentation for more details:
This example uses the SDK APIs introduced in Scanbot SDK v8.x.x.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd leave just one (the latter one) "SDK" abbreviation mention

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and the same comment in all other places like this

Please check the official documentation for more details:
Result API https://docs.scanbot.io/android/document-scanner-sdk/detailed-setup-guide/result-api/
ImageRef API https://docs.scanbot.io/android/document-scanner-sdk/detailed-setup-guide/image-ref-api/
*/
Expand Down Expand Up @@ -105,9 +105,16 @@ class MainActivity : AppCompatActivity() {

private suspend fun createAndScanDocumentPage(imageUri: Uri): String? {
val imageRef = withContext(Dispatchers.IO) {
val inputStream = contentResolver.openInputStream(imageUri)
?: throw Exception("Cannot open input stream from URI")
ImageRef.fromInputStream(inputStream)
contentResolver.openInputStream(imageUri)?.use { inputStream ->
ImageRef.fromInputStream(inputStream)
}
}
if (imageRef == null) {
withContext(Dispatchers.Main) {
Log.e(Const.LOG_TAG, "Cannot open input stream from URI: $imageUri")
showToast("Error opening selected image!")
}
return null
}

val sdk = ScanbotSDK(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@ import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updateLayoutParams
import io.scanbot.common.Result
import io.scanbot.common.onFailure
import io.scanbot.common.onSuccess
Expand Down Expand Up @@ -88,7 +83,11 @@ class BarcodeScannerViewActivity : AppCompatActivity() {
image: ImageRef,
captureInfo: CaptureInfo
) {
TODO("Not yet implemented")
image.toBitmap().onSuccess { bitmap ->
resultView.post {
resultView.setImageBitmap(bitmap)
}
}
}

override fun onSelectionOverlayBarcodeClicked(barcodeItem: BarcodeItem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
Ths example uses new sdk APIs presented in Scanbot SDK v.8.x.x
Please, check the official documentation for more details:
This example uses the SDK APIs introduced in Scanbot SDK v8.x.x.
Please check the official documentation for more details:
Result API https://docs.scanbot.io/android/document-scanner-sdk/detailed-setup-guide/result-api/
ImageRef API https://docs.scanbot.io/android/document-scanner-sdk/detailed-setup-guide/image-ref-api/
*/
Expand Down Expand Up @@ -101,14 +101,25 @@ class MainActivity : AppCompatActivity() {
binding.progressBar.isVisible = true
}

withContext(Dispatchers.Default) {
val inputStream = contentResolver.openInputStream(uri) ?: throw IllegalStateException("Cannot open input stream from URI: $uri")
val imageRef = ImageRef.fromInputStream(inputStream)
val imageRef = withContext(Dispatchers.IO) {
contentResolver.openInputStream(uri)?.use { inputStream ->
ImageRef.fromInputStream(inputStream)
}
}
if (imageRef == null) {
withContext(Dispatchers.Main) {
binding.progressBar.isVisible = false
showToast("Error opening selected image!")
Log.e(Const.LOG_TAG, "Cannot open input stream from URI: $uri")
}
return
}

withContext(Dispatchers.Default) {
val scanner = scanbotSdk.createBarcodeScanner().getOrThrow()
scanner.setConfiguration(scanner.copyCurrentConfiguration().copy().apply {
setBarcodeFormats(barcodeFormats = BarcodeTypeRepository.selectedTypes.toList())
} )
})
val result = scanner.run(imageRef).getOrNull()

BarcodeResultRepository.barcodeResultBundle = result?.let { BarcodeResultBundle(it, imageRef) }
Expand Down
2 changes: 1 addition & 1 deletion classic-components-example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ allprojects {

jvmToolchainVersion = 17

scanbotSdkVersion = "9.0.0.99-STAGING-SNAPSHOT"
scanbotSdkVersion = "9.0.0.108-STAGING-SNAPSHOT"

androidCoreKtxVersion = "1.6.0"
constraintLayoutVersion = "2.0.4"
Expand Down
17 changes: 0 additions & 17 deletions classic-components-example/camera-fragment/proguard-rules.pro

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
Ths example uses new sdk APIs presented in Scanbot SDK v.8.x.x
Please, check the official documentation for more details:
This example uses the SDK APIs introduced in Scanbot SDK v8.x.x.
Please check the official documentation for more details:
Result API https://docs.scanbot.io/android/document-scanner-sdk/detailed-setup-guide/result-api/
ImageRef API https://docs.scanbot.io/android/document-scanner-sdk/detailed-setup-guide/image-ref-api/
*/
Expand Down Expand Up @@ -115,12 +115,15 @@ class MainActivity : AppCompatActivity() {
}

val documentImage = withContext(Dispatchers.Default) {
catchWithResult {
// load the selected image:
val inputStream = contentResolver.openInputStream(imageUri)
?: throw IllegalStateException("Cannot open input stream from URI: $imageUri")
val image = ImageRef.fromInputStream(inputStream)
val image = contentResolver.openInputStream(imageUri)?.use { inputStream ->
ImageRef.fromInputStream(inputStream)
}
if (image == null) {
Comment on lines 117 to +121
Log.e(Const.LOG_TAG, "Cannot open input stream from URI: $imageUri")
return@withContext null
}

catchWithResult {
// create a new Document object with given image as original image:
val newDocument = scanbotSdk.documentApi.createDocument()
.getOrReturn() // can be handled with .getOrNull() if needed
Expand All @@ -144,6 +147,10 @@ class MainActivity : AppCompatActivity() {

withContext(Dispatchers.Main) {
progressBar.visibility = View.GONE
if (documentImage == null) {
this@MainActivity.showToast("Error opening selected image!")
return@withContext
}
// show Page's document image:
importResultImage.setImageBitmap(documentImage)
importResultImage.visibility = View.VISIBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import io.scanbot.sdk.ui.camera.ShutterButton
import io.scanbot.sdk.util.PolygonHelper

/**
Ths example uses new sdk APIs presented in Scanbot SDK v.8.x.x
Please, check the official documentation for more details:
This example uses the SDK APIs introduced in Scanbot SDK v8.x.x.
Please check the official documentation for more details:
Result API https://docs.scanbot.io/android/document-scanner-sdk/detailed-setup-guide/result-api/
ImageRef API https://docs.scanbot.io/android/document-scanner-sdk/detailed-setup-guide/image-ref-api/
*/
Expand All @@ -64,7 +64,7 @@ class MainActivity : AppCompatActivity(), DocumentScannerFrameHandler.ResultHand

askPermission()
setContentView(R.layout.activity_main)
supportActionBar!!.hide()
supportActionBar?.hide()
applyEdgeToEdge(this.findViewById(R.id.root_view))

cameraView = findViewById<View>(R.id.camera) as ScanbotCameraXView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ import io.scanbot.sdk.ui.camera.ShutterButton
import io.scanbot.sdk.util.PolygonHelper

/**
Ths example uses new sdk APIs presented in Scanbot SDK v.8.x.x
Please, check the official documentation for more details:
This example uses the SDK APIs introduced in Scanbot SDK v8.x.x.
Please check the official documentation for more details:
Result API https://docs.scanbot.io/android/document-scanner-sdk/detailed-setup-guide/result-api/
ImageRef API https://docs.scanbot.io/android/document-scanner-sdk/detailed-setup-guide/image-ref-api/
*/
Expand All @@ -63,13 +63,13 @@ class MainActivity : AppCompatActivity(), DocumentScannerFrameHandler.ResultHand
private var lastUserGuidanceHintTs = 0L
private var flashEnabled = false
private var autoSnappingEnabled = true
private val ignoreOrientationMistmatch = true
private val ignoreOrientationMismatch = true
override fun onCreate(savedInstanceState: Bundle?) {
supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_BAR_OVERLAY)
super.onCreate(savedInstanceState)
askPermission()
setContentView(R.layout.activity_main)
supportActionBar!!.hide()
supportActionBar?.hide()

applyEdgeToEdge(this.findViewById(R.id.root_view))
cameraView = findViewById<View>(R.id.camera) as ScanbotCameraXView
Expand All @@ -83,7 +83,7 @@ class MainActivity : AppCompatActivity(), DocumentScannerFrameHandler.ResultHand
// Please note: https://docs.scanbot.io/document-scanner-sdk/android/features/document-scanner/ui-components/
setConfiguration(copyCurrentConfiguration().apply {
parameters.apply {
this.ignoreOrientationMismatch = ignoreOrientationMistmatch
this.ignoreOrientationMismatch = ignoreOrientationMismatch
this.acceptedSizeScore = 75
this.acceptedAngleScore = 60
}
Expand Down Expand Up @@ -150,11 +150,11 @@ class MainActivity : AppCompatActivity(), DocumentScannerFrameHandler.ResultHand
)
}
}.onFailure { error ->
when(error){
is Result.InvalidLicenseError ->{
when (error) {
is Result.InvalidLicenseError -> {
Toast.makeText(this@MainActivity, "License is invalid: ${error.message}", Toast.LENGTH_LONG).show()
}
else -> {
else -> {
Toast.makeText(this@MainActivity, "${error.message}", Toast.LENGTH_LONG).show()
}
}
Expand Down Expand Up @@ -224,7 +224,7 @@ class MainActivity : AppCompatActivity(), DocumentScannerFrameHandler.ResultHand
}

DocumentDetectionStatus.OK_BUT_BAD_ASPECT_RATIO -> {
if (ignoreOrientationMistmatch) {
if (ignoreOrientationMismatch) {
userGuidanceHint.text = "Don't move"
// change polygon color to "OK"
polygonView.setFillColor(POLYGON_FILL_COLOR_OK)
Expand Down
21 changes: 0 additions & 21 deletions classic-components-example/check-scanner/proguard-rules.pro

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AutoSnappingCheckScannerActivity : AppCompatActivity() {
supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_BAR_OVERLAY)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_autosnapping_check_scanner)
supportActionBar!!.hide()
supportActionBar?.hide()
applyEdgeToEdge(this.findViewById(R.id.root_view))

cameraView = findViewById<ScanbotCameraXView>(R.id.camera).also { cameraView ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CheckScannerActivity : AppCompatActivity() {
supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_BAR_OVERLAY)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_check_scanner)
supportActionBar!!.hide()
supportActionBar?.hide()
applyEdgeToEdge(this.findViewById(R.id.root_view))

cameraView = findViewById<ScanbotCameraXView>(R.id.camera).also { cameraView ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CheckScannerResultActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_check_result)
supportActionBar!!.hide()
supportActionBar?.hide()
applyEdgeToEdge(this.findViewById(R.id.root_view))

val fieldsLayout = findViewById<LinearLayout>(R.id.check_result_fields_layout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
Ths example uses new sdk APIs presented in Scanbot SDK v.8.x.x
Please, check the official documentation for more details:
This example uses the SDK APIs introduced in Scanbot SDK v8.x.x.
Please check the official documentation for more details:
Result API https://docs.scanbot.io/android/document-scanner-sdk/detailed-setup-guide/result-api/
ImageRef API https://docs.scanbot.io/android/document-scanner-sdk/detailed-setup-guide/image-ref-api/
*/
Expand Down Expand Up @@ -77,10 +77,21 @@ class MainActivity : AppCompatActivity() {
private suspend fun scanCheck(uri: Uri) {
withContext(Dispatchers.Main) { binding.progressBar.isVisible = true }

val result = withContext(Dispatchers.Default) {
val inputStream = contentResolver.openInputStream(uri) ?: throw IllegalStateException("Cannot open input stream from URI: $uri")
val imageRef = ImageRef.fromInputStream(inputStream)
val imageRef = withContext(Dispatchers.IO) {
contentResolver.openInputStream(uri)?.use { inputStream ->
ImageRef.fromInputStream(inputStream)
}
}
if (imageRef == null) {
withContext(Dispatchers.Main) {
binding.progressBar.isVisible = false
showToast("Error opening selected image!")
Log.e(Const.LOG_TAG, "Cannot open input stream from URI: $uri")
}
return
}

val result = withContext(Dispatchers.Default) {
val scanner = scanbotSdk.createCheckScanner().getOrThrow()
scanner.run(imageRef).getOrNull()
}
Expand Down
Loading