From 3b052182f8c6646bf0fab48f3e78ec988ccde9ea Mon Sep 17 00:00:00 2001 From: Juan Antonio Romero Date: Thu, 19 Feb 2026 11:40:53 +0100 Subject: [PATCH 1/2] Migrate snippets --- .../_create-data-capture-context-android.mdx | 4 +- docs/sdks/android/add-sdk.md | 2 +- docs/sdks/android/agents-android.md | 18 +- .../configure-barcode-symbologies.md | 40 ++-- .../android/barcode-capture/get-started.md | 77 ++++---- docs/sdks/android/barcode-generator.md | 38 ++-- .../android/barcode-selection/get-started.md | 75 ++++---- docs/sdks/android/id-capture/advanced.md | 22 +-- docs/sdks/android/id-capture/get-started.md | 132 ++++++------- docs/sdks/android/label-capture/advanced.md | 33 ++-- .../sdks/android/label-capture/get-started.md | 24 +-- .../label-capture/label-definitions.md | 49 +++-- .../sdks/android/matrixscan-ar/get-started.md | 102 +++++----- .../sdks/android/matrixscan-count/advanced.md | 79 ++++---- .../android/matrixscan-count/get-started.md | 74 ++++---- docs/sdks/android/matrixscan-find/advanced.md | 66 +++---- .../android/matrixscan-find/get-started.md | 87 ++++----- docs/sdks/android/matrixscan-pick/advanced.md | 63 +++--- .../android/matrixscan-pick/get-started.md | 179 +++++++++--------- docs/sdks/android/matrixscan/advanced.md | 150 +++++++-------- docs/sdks/android/matrixscan/get-started.md | 97 +++++----- docs/sdks/android/sparkscan/advanced.md | 19 +- docs/sdks/android/sparkscan/get-started.md | 67 ++++--- 23 files changed, 697 insertions(+), 800 deletions(-) diff --git a/docs/partials/get-started/_create-data-capture-context-android.mdx b/docs/partials/get-started/_create-data-capture-context-android.mdx index a1933099..2ebc7bd8 100644 --- a/docs/partials/get-started/_create-data-capture-context-android.mdx +++ b/docs/partials/get-started/_create-data-capture-context-android.mdx @@ -1,5 +1,5 @@ The first step to add capture capabilities to your application is to create a new [Data Capture Context](https://docs.scandit.com/data-capture-sdk/android/core/api/data-capture-context.html#class-scandit.datacapture.core.DataCaptureContext). The context expects a valid Scandit Data Capture SDK license key during construction. -```java -DataCaptureContext dataCaptureContext = DataCaptureContext.forLicenseKey("-- ENTER YOUR SCANDIT LICENSE KEY HERE --"); +```kotlin +val dataCaptureContext = DataCaptureContext.forLicenseKey("-- ENTER YOUR SCANDIT LICENSE KEY HERE --") ``` \ No newline at end of file diff --git a/docs/sdks/android/add-sdk.md b/docs/sdks/android/add-sdk.md index 0f22c044..32ecb1e5 100644 --- a/docs/sdks/android/add-sdk.md +++ b/docs/sdks/android/add-sdk.md @@ -149,4 +149,4 @@ Check [the official provider documentation](https://developer.android.com/guide/ import OSSLicense from '../../partials/_third-party-licenses.mdx'; - \ No newline at end of file + diff --git a/docs/sdks/android/agents-android.md b/docs/sdks/android/agents-android.md index 9075e030..d7b2518c 100644 --- a/docs/sdks/android/agents-android.md +++ b/docs/sdks/android/agents-android.md @@ -100,7 +100,7 @@ override fun onPause() { sparkView.onPause(); super.onPause() } // Listen for results sparkScan.addListener(object : SparkScanListener { override fun onBarcodeScanned(spark: SparkScan, session: SparkScanSession, data: FrameData?) { - val barcode = session.newlyRecognizedBarcode.firstOrNull() + val barcode = session.newlyRecognizedBarcode barcode?.let { /* handle on UI thread */ } } }) @@ -142,13 +142,10 @@ val overlay = BarcodeCaptureOverlay.newInstance(barcodeCapture, captureView) barcodeCapture.addListener(object : BarcodeCaptureListener { override fun onBarcodeScanned(mode: BarcodeCapture, session: BarcodeCaptureSession, data: FrameData?) { - val code = session.newlyRecognizedBarcodes.firstOrNull()?.data + val code = session.newlyRecognizedBarcode?.data // handle result } }) - -override fun onResume() { super.onResume(); captureView.onResume() } -override fun onPause() { captureView.onPause(); super.onPause() } ``` --- @@ -207,7 +204,7 @@ Typical flow: Kotlin sketch: ```kotlin -val labelSettings = LabelCaptureSettings(/* configure with your label definition */) +val labelSettings = LabelCaptureSettings.builder()/* configure with your label definition */.build() val labelCapture = LabelCapture.forDataCaptureContext(dataCaptureContext, labelSettings) val captureView = DataCaptureView.newInstance(context, dataCaptureContext) @@ -218,7 +215,7 @@ val validationOverlay = LabelCaptureValidationFlowOverlay.newInstance( labelCapture.addListener(object : LabelCaptureListener { override fun onLabelCaptured(capture: LabelCapture, session: LabelCaptureSession, data: FrameData?) { - val fields = session.newlyCapturedLabels.firstOrNull()?.fields + val fields = session.capturedLabels.firstOrNull()?.fields // Extract required field values } }) @@ -237,7 +234,7 @@ labelCapture.addListener(object : LabelCaptureListener { Kotlin outline: ```kotlin val idSettings = IdCaptureSettings().apply { - supportedDocuments = EnumSet.of(SupportedDocuments.IdentityCard, SupportedDocuments.DLVIZ) + acceptedDocuments = listOf(IdCard(IdCaptureRegion.ANY), DriverLicense(IdCaptureRegion.ANY)) // Configure sides/regions as required } val idCapture = IdCapture.forDataCaptureContext(dataCaptureContext, idSettings) @@ -246,8 +243,7 @@ val captureView = DataCaptureView.newInstance(context, dataCaptureContext) val overlay = IdCaptureOverlay.newInstance(idCapture, captureView) idCapture.addListener(object : IdCaptureListener { - override fun onIdCaptured(mode: IdCapture, session: IdCaptureSession, data: FrameData?) { - val capturedId = session.newlyCapturedId + override fun onIdCaptured(mode: IdCapture, id: CapturedId) { // Consume fields (name, DOB, document number, etc.) } }) @@ -321,4 +317,4 @@ import com.scandit.datacapture.label.* import com.scandit.datacapture.label.ui.* import com.scandit.datacapture.id.* import com.scandit.datacapture.id.ui.* -``` \ No newline at end of file +``` diff --git a/docs/sdks/android/barcode-capture/configure-barcode-symbologies.md b/docs/sdks/android/barcode-capture/configure-barcode-symbologies.md index f79be3ae..d2beee8a 100644 --- a/docs/sdks/android/barcode-capture/configure-barcode-symbologies.md +++ b/docs/sdks/android/barcode-capture/configure-barcode-symbologies.md @@ -21,9 +21,9 @@ import EnableSymbologies from '../../../partials/configure-symbologies/_enable-s The following code shows how to enable scanning Code 128 codes for Barcode Capture: -```java -BarcodeCaptureSettings settings = new BarcodeCaptureSettings(); -settings.enableSymbology(Symbology.CODE128, true); +```kotlin +val settings = BarcodeCaptureSettings() +settings.enableSymbology(Symbology.CODE128, true) ``` import CapturePresents from '../../../partials/configure-symbologies/_capture-presents.mdx' @@ -40,11 +40,11 @@ If you want to read codes that are shorter/longer than the specified default ran The below code shows how to change the active symbol count for Code 128 to read codes with 6, 7 and 8 symbols. -```java -BarcodeCaptureSettings settings = new BarcodeCaptureSettings(); -SymbologySettings symbologySettings = settings.getSymbologySettings(Symbology.CODE128); -HashSet activeSymbolCounts = new HashSet<>(Arrays.asList(new Short[] { 6, 7, 8})); -symbologySettings.setActiveSymbolCounts(activeSymbolCounts); +```kotlin +val settings = BarcodeCaptureSettings() +val symbologySettings = settings.getSymbologySettings(Symbology.CODE128) +val activeSymbolCounts = mutableSetOf(6, 7, 8) +symbologySettings.activeSymbolCounts = activeSymbolCounts ``` import CalculateSymbolCount from '../../../partials/configure-symbologies/_calculate-symbol-count.mdx' @@ -61,10 +61,10 @@ When you enable a symbology as described above, only dark-on-bright codes are en The following code shows how to enable color-inverted reading for Code 128: -```java -BarcodeCaptureSettings settings = new BarcodeCaptureSettings(); -SymbologySettings symbologySettings = settings.getSymbologySettings(Symbology.CODE128); -symbologySettings.setColorInvertedEnabled(true); +```kotlin +val settings = BarcodeCaptureSettings() +val symbologySettings = settings.getSymbologySettings(Symbology.CODE128) +symbologySettings.isColorInvertedEnabled = true ``` ## Enforce Checksums @@ -75,10 +75,10 @@ When enabling a checksum you have to make sure that the data of your codes conta You can enforce a specific checksum by setting it through `SymbologySettings.checksums`: -```java -BarcodeCaptureSettings settings = new BarcodeCaptureSettings(); -SymbologySettings symbologySettings = settings.getSymbologySettings(Symbology.CODE39); -symbologySettings.setChecksums(EnumSet.of(Checksum.MOD43)); +```kotlin +val settings = BarcodeCaptureSettings() +val symbologySettings = settings.getSymbologySettings(Symbology.CODE39) +symbologySettings.checksums = EnumSet.of(Checksum.MOD43) ``` ## Enable Symbology-Specific Extensions @@ -91,10 +91,10 @@ To enable/disable a symbology extension, use `SymbologySettings.setExtensionEnab The following code shows how to enable the full ASCII extension for Code 39. -```java -BarcodeCaptureSettings settings = new BarcodeCaptureSettings(); -SymbologySettings symbologySettings = settings.getSymbologySettings(Symbology.CODE39); -symbologySettings.setExtensionEnabled("full_ascii", true); +```kotlin +val settings = BarcodeCaptureSettings() +val symbologySettings = settings.getSymbologySettings(Symbology.CODE39) +symbologySettings.setExtensionEnabled("full_ascii", true) ``` This extension allows Code 39 to encode all 128 ASCII characters instead of only the 43 characters defined in the standard. The extension is disabled by default as it can lead to false reads when enabled. diff --git a/docs/sdks/android/barcode-capture/get-started.md b/docs/sdks/android/barcode-capture/get-started.md index 68541f02..0b03d4e7 100644 --- a/docs/sdks/android/barcode-capture/get-started.md +++ b/docs/sdks/android/barcode-capture/get-started.md @@ -56,14 +56,15 @@ Barcode scanning is orchestrated by the [BarcodeCapture data capture mode](https For this task, we setup barcode scanning for a small list of barcode types, called [symbologies](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/symbology.html#enum-scandit.datacapture.barcode.Symbology). The list of symbologies to enable is application specific. We recommend that you only enable the symbologies your application requires. If you are not familiar with the symbologies that are relevant for your use case, you can use [capture presets](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/capture-preset.html#enum-scandit.datacapture.barcode.CapturePreset) that are tailored for different verticals (for instance, retail, logistics, and so on). -```java -BarcodeCaptureSettings settings = new BarcodeCaptureSettings(); -settings.enableSymbology(Symbology.CODE128, true); -settings.enableSymbology(Symbology.CODE39, true); -settings.enableSymbology(Symbology.QR, true); -settings.enableSymbology(Symbology.EAN8, true); -settings.enableSymbology(Symbology.UPCE, true); -settings.enableSymbology(Symbology.EAN13_UPCA, true); +```kotlin +val settings = BarcodeCaptureSettings().apply { + enableSymbology(Symbology.CODE128, true) + enableSymbology(Symbology.CODE39, true) + enableSymbology(Symbology.QR, true) + enableSymbology(Symbology.EAN8, true) + enableSymbology(Symbology.UPCE, true) + enableSymbology(Symbology.EAN13_UPCA, true) +} ``` :::note @@ -72,8 +73,8 @@ If you are not disabling barcode capture immediately after having scanned the fi Next, create a [BarcodeCapture](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/barcode-capture.html#class-scandit.datacapture.barcode.BarcodeCapture) instance with the settings initialized in the previous step: -```java -barcodeCapture = BarcodeCapture.forDataCaptureContext(dataCaptureContext, settings); +```kotlin +val barcodeCapture = BarcodeCapture.forDataCaptureContext(dataCaptureContext, settings) ``` ## Register the Barcode Capture Listener @@ -82,22 +83,21 @@ To get informed whenever a new code has been recognized, add a [BarcodeCaptureLi First conform to the `BarcodeCaptureListener` interface. For example: -```java -@Override -public void onBarcodeScanned( - @NonNull BarcodeCapture barcodeCapture, - @NonNull BarcodeCaptureSession session, - @NonNull FrameData frameData +```kotlin +override fun onBarcodeScanned( + barcodeCapture: BarcodeCapture, + session: BarcodeCaptureSession, + frameData: FrameData ) { - Barcode recognizedBarcode = session.getNewlyRecognizedBarcode(); + val recognizedBarcodes = session.newlyRecognizedBarcode // Do something with the barcodes. See Rejecting Barcodes, below, for an example. } ``` Then add the listener: -```java -barcodeCapture.addListener(this); +```kotlin +barcodeCapture.addListener(this) ``` ### Rejecting Barcodes @@ -106,11 +106,11 @@ To prevent scanning unwanted codes, you can reject them by adding the desired lo The example below will only scan barcodes beginning with the digits `09` and ignore all others, using a transparent brush to distinguish a rejected barcode from a recognized one: -```java +```kotlin ... -if (barcode.getData() == null || !barcode.getData().startsWith("09:")) { - overlay.setBrush(Brush.transparent()); - return; +if (barcode.data == null || !barcode.data.startsWith("09:")) { + overlay.brush = Brush.transparent() + return } ... ``` @@ -125,30 +125,25 @@ In Android, the user must explicitly grant permission for each app to access cam When using the built-in camera there are recommended settings for each capture mode. These must be used to achieve the best performance and user experience for the respective mode. The following code shows how to get the recommended settings and create the camera: -```java -CameraSettings cameraSettings = BarcodeCapture.createRecommendedCameraSettings(); +```kotlin +val cameraSettings = BarcodeCapture.createRecommendedCameraSettings() // Depending on the use case further camera settings adjustments can be made here. -Camera camera = Camera.getDefaultCamera(); - -if (camera != null) { - camera.applySettings(cameraSettings); -} +val camera = Camera.getDefaultCamera() +camera?.applySettings(cameraSettings) ``` Because the frame source is configurable, the data capture context must be told which frame source to use. This is done with a call to [DataCaptureContext.setFrameSource()](https://docs.scandit.com/data-capture-sdk/android/core/api/data-capture-context.html#method-scandit.datacapture.core.DataCaptureContext.SetFrameSourceAsync) -```java -dataCaptureContext.setFrameSource(camera); +```kotlin +dataCaptureContext.setFrameSource(camera) ``` The camera is off by default and must be turned on. This is done by calling [FrameSource.switchToDesiredState()](https://docs.scandit.com/data-capture-sdk/android/core/api/frame-source.html#method-scandit.datacapture.core.IFrameSource.SwitchToDesiredStateAsync) with a value of [FrameSourceState.ON](https://docs.scandit.com/data-capture-sdk/android/core/api/frame-source.html#value-scandit.datacapture.core.FrameSourceState.On): -```java -if (camera != null) { - camera.switchToDesiredState(FrameSourceState.ON); -} +```kotlin +camera?.switchToDesiredState(FrameSourceState.ON) ``` :::note @@ -161,15 +156,15 @@ When using the built-in camera as frame source, you may want to display the came To do that, add a [DataCaptureView](https://docs.scandit.com/data-capture-sdk/android/core/api/ui/data-capture-view.html#class-scandit.datacapture.core.ui.DataCaptureView) to your view hierarchy: -```java -DataCaptureView dataCaptureView = DataCaptureView.newInstance(this, dataCaptureContext); -setContentView(dataCaptureView); +```kotlin +val dataCaptureView = DataCaptureView.newInstance(this, dataCaptureContext) +setContentView(dataCaptureView) ``` To visualize the results of barcode scanning, the following [overlay](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/barcode-capture-overlay.html#class-scandit.datacapture.barcode.ui.BarcodeCaptureOverlay) can be added: -```java -BarcodeCaptureOverlay overlay = BarcodeCaptureOverlay.newInstance(barcodeCapture, dataCaptureView); +```kotlin +val overlay = BarcodeCaptureOverlay.newInstance(barcodeCapture, dataCaptureView) ``` ## Disabling Barcode Capture diff --git a/docs/sdks/android/barcode-generator.md b/docs/sdks/android/barcode-generator.md index a08d367c..f8262cbe 100644 --- a/docs/sdks/android/barcode-generator.md +++ b/docs/sdks/android/barcode-generator.md @@ -37,23 +37,23 @@ With the context you can then instantiate a [`BarcodeGeneratorBuilder`](https:// You can configure the colors used in the resulting image: -```java -DataCaptureContext dataCaptureContext = DataCaptureContext.forLicenseKey(licenseKey); -BarcodeGenerator.Code128BarcodeGeneratorBuilder builder = BarcodeGenerator.code128BarcodeGeneratorBuilder(dataCaptureContext) +```kotlin +val dataCaptureContext = DataCaptureContext.forLicenseKey(licenseKey) +val builder = BarcodeGenerator.code128BarcodeGeneratorBuilder(dataCaptureContext) .withBackgroundColor(Color.WHITE) - .withForegroundColor(Color.BLACK); + .withForegroundColor(Color.BLACK) ``` When the builder is configured get the `BarcodeGenerator` and try to generate the image: -```java +```kotlin try { - BarcodeGenerator generator = builder.build(); - Bitmap image = generator.generate(dataString, 200); + val generator = builder.build() + val image = generator.generate(dataString, 200) // Use the image -} catch (Exception exception) { +} catch (exception: Exception) { // Handle the error - exception.printStackTrace(); + exception.printStackTrace() } ``` @@ -67,26 +67,26 @@ With the context you can then instantiate a [`QRCodeBarcodeGeneratorBuilder`](ht You can configure the colors used in the resulting image, and the two settings that can be configured for QR codes: [`QRCodeBarcodeGeneratorBuilder.errorCorrectionLevel`](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/barcode-generator-builder.html#method-scandit.datacapture.barcode.generator.QrCodeBarcodeGeneratorBuilder.WithErrorCorrectionLevel) and [`QRCodeBarcodeGeneratorBuilder.versionNumber`](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/barcode-generator-builder.html#method-scandit.datacapture.barcode.generator.QrCodeBarcodeGeneratorBuilder.WithVersionNumber). -```java -DataCaptureContext dataCaptureContext = DataCaptureContext.forLicenseKey(licenseKey); -BarcodeGenerator.QrCodeBarcodeGeneratorBuilder builder = new BarcodeGenerator.QrCodeBarcodeGeneratorBuilder(dataCaptureContext) +```kotlin +val dataCaptureContext = DataCaptureContext.forLicenseKey(licenseKey) +val builder = BarcodeGenerator.qrCodeBarcodeGeneratorBuilder(dataCaptureContext) .withBackgroundColor(Color.WHITE) .withForegroundColor(Color.BLACK) .withErrorCorrectionLevel(QrCodeErrorCorrectionLevel.MEDIUM) - .withVersionNumber(4); + .withVersionNumber(4) ``` When the builder is configured get the `BarcodeGenerator` and try to generate the image: -```java +```kotlin try { - BarcodeGenerator generator = builder.build(); - Bitmap image = generator.generate(dataString, 200); + val generator = builder.build() + val image = generator.generate(dataString, 200) // Use the image -} catch (Exception exception) { +} catch (exception: Exception) { // Handle the error - exception.printStackTrace(); + exception.printStackTrace() } ``` -See the complete [API reference](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/barcode-generator.html) for more information. \ No newline at end of file +See the complete [API reference](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/barcode-generator.html) for more information. diff --git a/docs/sdks/android/barcode-selection/get-started.md b/docs/sdks/android/barcode-selection/get-started.md index cc6df0f5..2a22f05a 100644 --- a/docs/sdks/android/barcode-selection/get-started.md +++ b/docs/sdks/android/barcode-selection/get-started.md @@ -60,12 +60,13 @@ Barcode selection is orchestrated by the [BarcodeSelection](https://docs.scandit For this task, we setup barcode scanning for a small list of different barcode types, called [symbologies](../barcode-symbologies.mdx). The list of symbologies to enable is highly application specific. It is recommended that you **only enable the list of symbologies your application requires**. -```java -BarcodeSelectionSettings settings = new BarcodeSelectionSettings(); -settings.enableSymbology(Symbology.QR, true); -settings.enableSymbology(Symbology.EAN8, true); -settings.enableSymbology(Symbology.UPCE, true); -settings.enableSymbology(Symbology.EAN13_UPCA, true); +```kotlin +val settings = BarcodeSelectionSettings().apply { + enableSymbology(Symbology.QR, true) + enableSymbology(Symbology.EAN8, true) + enableSymbology(Symbology.UPCE, true) + enableSymbology(Symbology.EAN13_UPCA, true) +} ``` ### Selection Types @@ -94,8 +95,8 @@ If you want to automatically select a barcode when it is the only one on screen, Next, create a `BarcodeSelection` instance with the settings initialized in the previous step: -```java -BarcodeSelection barcodeSelection = BarcodeSelection.forDataCaptureContext(dataCaptureContext, settings); +```kotlin +val barcodeSelection = BarcodeSelection.forDataCaptureContext(dataCaptureContext, settings) ``` ## Registering the Listener @@ -104,39 +105,35 @@ To get informed whenever a new code has been recognized, add a [BarcodeSelection First implement the `BarcodeSelectionListener` interface. For example: -```java -public class MyBarcodeSelectionListener implements BarcodeSelectionListener { - @Override - public void onObservationStarted(@NonNull BarcodeSelection barcodeSelection) { +```kotlin +class MyBarcodeSelectionListener: BarcodeSelectionListener { + override fun onObservationStarted(barcodeSelection: BarcodeSelection) { // Called when Barcode Selection is started. // We don't use this callback in this guide. } - @Override - public void onObservationStopped(@NonNull BarcodeSelection barcodeSelection) { + override fun onObservationStopped(barcodeSelection: BarcodeSelection) { // Called when Barcode Selection is stopped. // We don't use this callback in this guide. } - @Override - public void onSessionUpdated( - @NonNull BarcodeSelection barcodeSelection, - @NonNull BarcodeSelectionSession session, - @Nullable FrameData data + override fun onSessionUpdated( + barcodeSelection: BarcodeSelection, + session: BarcodeSelectionSession, + data: FrameData?, ) { // Called every new frame. // We don't use this callback in this guide. } - @Override - public void onSelectionUpdated( - @NonNull BarcodeSelection barcodeSelection, - @NonNull BarcodeSelectionSession session, - @Nullable FrameData frameData + override fun onSelectionUpdated( + barcodeSelection: BarcodeSelection, + session: BarcodeSelectionSession, + data: FrameData?, ) { - List newlySelectedBarcodes = session.getNewlySelectedBarcodes(); - List selectedBarcodes = session.getSelectedBarcodes(); - List newlyUnselectedBarcodes = session.getNewlyUnselectedBarcodes(); + val newlySelectedBarcodes = session.newlySelectedBarcodes + val selectedBarcodes = session.selectedBarcodes + val newlyUnselectedBarcodes = session.newlyUnselectedBarcodes // Do something with the retrieved barcodes. } } @@ -144,8 +141,8 @@ public class MyBarcodeSelectionListener implements BarcodeSelectionListener { Then add the listener to the `BarcodeSelection` instance: -```java -barcodeSelection.addListener(new MyBarcodeSelectionListener()); +```kotlin +barcodeSelection.addListener(MyBarcodeSelectionListener()) ``` ## Obtaining the Camera Instance and Set as Frame Source @@ -158,29 +155,25 @@ In Android, the user must explicitly grant permission for each app to access cam When using the built-in camera there are recommended settings for each capture mode. These must be used to achieve the best performance and user experience for the respective mode. The following couple of lines show how to get the recommended settings and create the camera from it: -```java -CameraSettings cameraSettings = BarcodeSelection.createRecommendedCameraSettings(); +```kotlin +val cameraSettings = BarcodeSelection.createRecommendedCameraSettings() // Depending on the use case further camera settings adjustments can be made here. -Camera camera = Camera.getDefaultCamera(); -if (camera != null) { - camera.applySettings(cameraSettings); -} +val camera = Camera.getDefaultCamera() +camera?.applySettings(cameraSettings) ``` Because the frame source is configurable, the data capture context must be told which frame source to use. This is done with a call to [DataCaptureContext.setFrameSource()](https://docs.scandit.com/data-capture-sdk/android/core/api/data-capture-context.html#method-scandit.datacapture.core.DataCaptureContext.SetFrameSourceAsync): -```java -dataCaptureContext.setFrameSource(camera); +```kotlin +dataCaptureContext.setFrameSource(camera) ``` The camera is off by default and must be turned on. This is done by calling [FrameSource.switchToDesiredState()](https://docs.scandit.com/data-capture-sdk/android/core/api/frame-source.html#method-scandit.datacapture.core.IFrameSource.SwitchToDesiredStateAsync) with a value of [FrameSourceState.ON](https://docs.scandit.com/data-capture-sdk/android/core/api/frame-source.html#value-scandit.datacapture.core.FrameSourceState.On): -```java -if (camera != null) { - camera.switchToDesiredState(FrameSourceState.ON); -} +```kotlin +camera?.switchToDesiredState(FrameSourceState.ON) ``` ## Disabling Barcode Selection diff --git a/docs/sdks/android/id-capture/advanced.md b/docs/sdks/android/id-capture/advanced.md index 4afcb173..33348aa4 100644 --- a/docs/sdks/android/id-capture/advanced.md +++ b/docs/sdks/android/id-capture/advanced.md @@ -16,8 +16,8 @@ There are several advanced configurations that can be used to customize the beha By default, ID Capture doesn’t extract data from the table on the back of European Driver Licenses. If you are interested in this data, you may enable the extraction by calling: -```java -settings.setDecodeBackOfEuropeanDrivingLicense(true); +```kotlin +settings.decodeBackOfEuropeanDrivingLicense = true ``` :::warning @@ -30,18 +30,18 @@ By default, data extracted from documents is anonymized according to local regul That means certain data from certain fields won’t be returned, even if it’s present on a document. You control the anonymization level with the following setting: -```java +```kotlin // Default value: -settings.setAnonymizationMode(IdAnonymizationMode.FIELDS_ONLY); +settings.anonymizationMode = IdAnonymizationMode.FIELDS_ONLY // Sensitive data is additionally covered with black boxes on returned images: -settings.setAnonymizationMode(IdAnonymizationMode.FIELDS_AND_IMAGES); +settings.anonymizationMode = IdAnonymizationMode.FIELDS_AND_IMAGES // Only images are anonymized: -settings.setAnonymizationMode(IdAnonymizationMode.IMAGES_ONLY); +settings.anonymizationMode = IdAnonymizationMode.IMAGES_ONLY // No anonymization: -settings.setAnonymizationMode(IdAnonymizationMode.NONE); +settings.anonymizationMode = IdAnonymizationMode.NONE ``` ## ID Images @@ -55,15 +55,15 @@ In the case of `FullDocumentScanner`, if the front & the back side of a document For the full frame of the document, you can use [`setShouldPassImageTypeToResult`](https://docs.scandit.com/data-capture-sdk/android/id-capture/api/id-capture-settings.html#method-scandit.datacapture.id.IdCaptureSettings.SetShouldPassImageTypeToResult) when creating the `IdCaptureSettings` object. This will pass the image type to the result, which you can then access in the `CapturedId` object. -```java +```kotlin // Holder's picture as printed on a document: -settings.setShouldPassImageTypeToResult(IdImageType.FACE, true); +settings.setShouldPassImageTypeToResult(IdImageType.FACE, true) // Cropped image of a document: -settings.setShouldPassImageTypeToResult(IdImageType.CROPPED_DOCUMENT, true); +settings.setShouldPassImageTypeToResult(IdImageType.CROPPED_DOCUMENT, true) // Full camera frame that contains the document: -settings.setShouldPassImageTypeToResult(IdImageType.FRAME, true); +settings.setShouldPassImageTypeToResult(IdImageType.FRAME, true) ``` ## Callbacks and Scanning Workflows diff --git a/docs/sdks/android/id-capture/get-started.md b/docs/sdks/android/id-capture/get-started.md index 04ae4581..d62f98db 100644 --- a/docs/sdks/android/id-capture/get-started.md +++ b/docs/sdks/android/id-capture/get-started.md @@ -80,14 +80,14 @@ import DataCaptureContextAndroid from '../../../partials/get-started/_create-dat Next, you need to create a new instance of the [Camera](https://docs.scandit.com/data-capture-sdk/android/core/api/camera.html#class-scandit.datacapture.core.Camera) class to indicate the camera to stream previews and to capture images. -```java -camera = Camera.getDefaultCamera(IdCapture.createRecommendedCameraSettings()); +```kotlin +val camera = Camera.getDefaultCamera(IdCapture.createRecommendedCameraSettings()) if (camera == null) { - throw new IllegalStateException("Failed to init camera!"); + throw IllegalStateException("Failed to init camera!") } -dataCaptureContext.setFrameSource(camera); +dataCaptureContext.setFrameSource(camera) ``` ## Configure the Capture Settings @@ -100,58 +100,53 @@ Check [IdCaptureDocumentType](https://docs.scandit.com/data-capture-sdk/android/ By default, [anonymized data](./advanced.md#configure-data-anonymization) is not returned in accordance with local regulations for specific documents. This setting can be disabled for testing purposes, but be sure to comply with local laws and requirements in production. ::: -```java -List acceptedDocuments = new ArrayList<>(); -List rejectedDocuments = new ArrayList<>(); - -// Documents from any region: -acceptedDocuments.add(new IdCard(IdCaptureRegion.ANY)); -// Only documents issued by a specific country: -acceptedDocuments.add(new IdCard(IdCaptureRegion.GERMANY)); -// Regional documents: -acceptedDocuments.add(new RegionSpecific(RegionSpecificSubtype.APEC_BUSINESS_TRAVEL_CARD)); -// Reject passports from certain regions: -rejectedDocuments.add(new Passport(IdCaptureRegion.CUBA)); - -IdCaptureSettings settings = new IdCaptureSettings(); -settings.setAcceptedDocuments(acceptedDocuments); -settings.setRejectedDocuments(rejectedDocuments); - -// To scan only one-sided documents and a given zone: -settings.setScanner(new IdCaptureScanner(new SingleSideScanner( - true, // barcode - true, // machineReadableZone - true // visualInspectionZone -), null)); - -// To scan both sides of the document: -settings.setScanner(new IdCaptureScanner(new FullDocumentScanner(), null)); +```kotlin +val settings = IdCaptureSettings().apply { + acceptedDocuments = listOf( + // Documents from any region + IdCard(IdCaptureRegion.ANY), + // Only documents issued by a specific country + IdCard(IdCaptureRegion.GERMANY), + // Regional documents + RegionSpecific(RegionSpecificSubtype.APEC_BUSINESS_TRAVEL_CARD), + ) + rejectedDocuments = listOf( + // Reject passports from certain regions: + Passport(IdCaptureRegion.CUBA), + ) + + // To scan only one-sided documents and a given zone: + scanner = IdCaptureScanner(SingleSideScanner( + barcode = true, + machineReadableZone = true, + visualInspectionZone = true, + )) + + // To scan both sides of the document: + scanner = IdCaptureScanner(FullDocumentScanner()) +} ``` Create a new ID Capture mode with the chosen settings: -```java -IdCapture idCapture = IdCapture.forDataCaptureContext(dataCaptureContext, settings); +```kotlin +val idCapture = IdCapture.forDataCaptureContext(dataCaptureContext, settings) ``` ## Implement a Listener To receive scan results, implement and [IdCaptureListener](https://docs.scandit.com/data-capture-sdk/android/id-capture/api/id-capture-listener.html#interface-scandit.datacapture.id.IIdCaptureListener). The listener provides two callbacks: `onIdCaptured` and `onIdRejected`. -```java -IdCaptureListener listener = new IdCaptureListener() { - @Override - public void onIdCaptured(@NonNull IdCapture idCapture, @NonNull CapturedId capturedId) { +```kotlin +idCapture.addListener(object : IdCaptureListener { + override fun onIdCaptured(idCapture: IdCapture, capturedId: CapturedId) { // Success! Handle extracted data here. } - - @Override - public void onIdRejected(@NonNull IdCapture idCapture, @Nullable CapturedId capturedId, @NonNull RejectionReason rejectionReason) { + + override fun onIdRejected(idCapture: IdCapture, capturedId: CapturedId?, rejectionReason: RejectionReason) { // Something went wrong. Inspect the reason to determine the follow-up action. } -}; - -idCapture.addListener(listener); +}) ``` ### Handling Success @@ -162,16 +157,15 @@ For more specific information, use its non-null result properties (e.g. [Capture On a successful scan you may read the extracted data from `CapturedId`: -```java -@Override -public void onIdCaptured(@NonNull IdCapture idCapture, @NonNull CapturedId capturedId) { - String fullName = capturedId.getFullName(); - DateResult dateOfBirth = capturedId.getDateOfBirth(); - DateResult dateOfExpiry = capturedId.getDateOfExpiry(); - String documentNumber = capturedId.getDocumentNumber(); +```kotlin +override fun onIdCaptured(idCapture: IdCapture, capturedId: CapturedId) { + val fullName = capturedId.fullName + val dateOfBirth = capturedId.dateOfBirth + val dateOfExpiry = capturedId.dateOfExpiry + val documentNumber = capturedId.documentNumber // Process data: - processData(fullName, dateOfBirth, dateOfExpiry, documentNumber); + processData(fullName, dateOfBirth, dateOfExpiry, documentNumber) } ``` :::tip @@ -184,15 +178,21 @@ The ID scanning process may fail for various reasons. Start from inspecting [`Re You may wish to implement the follow-up action based on the reason of failure: -```java -@Override -public void onIdRejected(@NonNull IdCapture idCapture, @Nullable CapturedId capturedId, @NonNull RejectionReason rejectionReason) { - if (rejectionReason == RejectionReason.TIMEOUT) { - // Ask the user to retry, or offer alternative input method. - } else if (rejectionReason == RejectionReason.DOCUMENT_EXPIRED) { - // Ask the user to provide alternative document. - } else if (rejectionReason == RejectionReason.HOLDER_UNDERAGE) { - // Reject the process. +```kotlin +override fun onIdRejected(idCapture: IdCapture, capturedId: CapturedId, rejectionReason: RejectionReason) { + when (rejectionReason) { + RejectionReason.TIMEOUT -> { + // Ask the user to retry, or offer alternative input method. + } + RejectionReason.DOCUMENT_EXPIRED -> { + // Ask the user to provide alternative document. + } + RejectionReason.HOLDER_UNDERAGE -> { + // Reject the process. + } + else -> { + // Deal with the default case. + } } } ``` @@ -203,15 +203,15 @@ When using the built-in camera as frame source, you may typically want to displa To do that, add a [DataCaptureView](https://docs.scandit.com/data-capture-sdk/android/core/api/ui/data-capture-view.html#class-scandit.datacapture.core.ui.DataCaptureView) to your view hierarchy: -```java -DataCaptureView dataCaptureView = DataCaptureView.newInstance(this, dataCaptureContext); -setContentView(dataCaptureView); +```kotlin +val dataCaptureView = DataCaptureView.newInstance(this, dataCaptureContext) +setContentView(dataCaptureView) ``` Then, add an instance of [IdCaptureOverlay](https://docs.scandit.com/data-capture-sdk/android/id-capture/api/ui/id-capture-overlay.html#class-scandit.datacapture.id.ui.IdCaptureOverlay) to the view: -```java -IdCaptureOverlay overlay = IdCaptureOverlay.newInstance(idCapture, dataCaptureView); +```kotlin +val overlay = IdCaptureOverlay.newInstance(idCapture, dataCaptureView) ``` The overlay chooses the displayed UI automatically, based on the selected [IdCaptureSettings](https://docs.scandit.com/data-capture-sdk/android/id-capture/api/id-capture-settings.html#class-scandit.datacapture.id.IdCaptureSettings). @@ -222,6 +222,6 @@ If you prefer to show a different UI or to temporarily hide it, set the appropri Finally, turn on the camera to start scanning: -```java -camera.switchToDesiredState(FrameSourceState.ON); +```kotlin +camera.switchToDesiredState(FrameSourceState.ON) ``` diff --git a/docs/sdks/android/label-capture/advanced.md b/docs/sdks/android/label-capture/advanced.md index d1932e57..91c06a60 100644 --- a/docs/sdks/android/label-capture/advanced.md +++ b/docs/sdks/android/label-capture/advanced.md @@ -28,10 +28,10 @@ overlay.listener = object : LabelCaptureBasicOverlayListener { override fun brushForField( overlay: LabelCaptureBasicOverlay, field: LabelField, - label: CapturedLabel + label: CapturedLabel, ): Brush? = when (field.name) { - "" -> Brush(Color.CYAN.withAlpha(128), Color.CYAN, 1f) - "" -> Brush(Color.GREEN.withAlpha(128), Color.GREEN, 1f) + "" -> Brush(Color.CYAN, Color.CYAN, 1f) + "" -> Brush(Color.GREEN, Color.GREEN, 1f) else -> Brush(Color.TRANSPARENT, Color.TRANSPARENT, 0f) } @@ -41,12 +41,12 @@ overlay.listener = object : LabelCaptureBasicOverlayListener { */ override fun brushForLabel( overlay: LabelCaptureBasicOverlay, - label: CapturedLabel + label: CapturedLabel, ): Brush? = null override fun onLabelTapped( overlay: LabelCaptureBasicOverlay, - label: CapturedLabel + label: CapturedLabel, ) { /* * Handle the user tap gesture on the label. @@ -121,26 +121,26 @@ advancedOverlay.listener = object : LabelCaptureAdvancedOverlayListener { // This method is called when a label is detected - we return null since we're only adding AR elements to specific fields, not the entire label override fun viewForCapturedLabel( overlay: LabelCaptureAdvancedOverlay, - capturedLabel: CapturedLabel + capturedLabel: CapturedLabel, ): View? = null // This defines where on the detected label the AR view would be anchored override fun anchorForCapturedLabel( overlay: LabelCaptureAdvancedOverlay, - capturedLabel: CapturedLabel + capturedLabel: CapturedLabel, ): Anchor = Anchor.CENTER // This defines the offset from the anchor point for the label's AR view override fun offsetForCapturedLabel( overlay: LabelCaptureAdvancedOverlay, capturedLabel: CapturedLabel, - view: View + view: View, ): PointWithUnit = PointWithUnit(0f, 0f, MeasureUnit.PIXEL) // This method is called when a field is detected in a label override fun viewForCapturedLabelField( overlay: LabelCaptureAdvancedOverlay, - labelField: LabelField + labelField: LabelField, ): View? { // We only want to create AR elements for expiry date fields that are text-based if (labelField.name.contains("expiry", ignoreCase = true) && labelField.type == LabelFieldType.TEXT) { @@ -178,14 +178,14 @@ advancedOverlay.listener = object : LabelCaptureAdvancedOverlayListener { // BOTTOM_CENTER places it right below the expiry date text for better visibility override fun anchorForCapturedLabelField( overlay: LabelCaptureAdvancedOverlay, - labelField: LabelField + labelField: LabelField, ): Anchor = Anchor.BOTTOM_CENTER // This defines the offset from the anchor point override fun offsetForCapturedLabelField( overlay: LabelCaptureAdvancedOverlay, labelField: LabelField, - view: View + view: View, ): PointWithUnit = PointWithUnit(0f, 22f, MeasureUnit.DIP) } ``` @@ -320,14 +320,14 @@ Validation flow uses a different overlay, the [LabelCaptureValidationFlowOverlay ```kotlin // Create the overlay -validationFlowOverlay = LabelCaptureValidationFlowOverlay.newInstance( +val validationFlowOverlay = LabelCaptureValidationFlowOverlay.newInstance( requireContext(), dataCaptureManager.getLabelCapture(), - view + view, ) // Set the listener to receive validation events -validationFlowOverlay?.listener = this +validationFlowOverlay.listener = this ``` @@ -352,8 +352,7 @@ validationFlowOverlay.setListener(this); ```kotlin // Configure the validation flow with custom settings -val validationSettings = LabelCaptureValidationFlowSettings.newInstance() -validationSettings.apply { +val validationSettings = LabelCaptureValidationFlowSettings.newInstance().apply { missingFieldsHintText = "Please add this field" standbyHintText = "No label detected, camera paused" validationHintText = "fields captured" // X/Y (X fields out of total Y) is shown in front of this string @@ -363,7 +362,7 @@ validationSettings.apply { } // Apply the settings to the overlay -validationFlowOverlay?.applySettings(validationSettings) +validationFlowOverlay.applySettings(validationSettings) ``` diff --git a/docs/sdks/android/label-capture/get-started.md b/docs/sdks/android/label-capture/get-started.md index 7538da03..de24a628 100644 --- a/docs/sdks/android/label-capture/get-started.md +++ b/docs/sdks/android/label-capture/get-started.md @@ -66,7 +66,7 @@ val settings = LabelCaptureSettings.builder() // Add a barcode field with the expected symbologies and pattern .addCustomBarcode() .setSymbologies(Symbology.EAN13_UPCA, Symbology.CODE128) - .setPattern("\\d{12,14}") + .setAnchorRegexes("\\d{12,14}") .buildFluent("") // Add a text field for capturing expiry dates .addExpiryDateText() @@ -134,7 +134,7 @@ labelCapture.addListener(object : LabelCaptureListener { override fun onSessionUpdated( mode: LabelCapture, session: LabelCaptureSession, - data: FrameData + data: FrameData, ) { /* * The session update callback is called for every processed frame. @@ -278,9 +278,9 @@ val dataCaptureView = DataCaptureView.newInstance(requireContext(), dataCaptureC */ val container = /* get your containing view here, e.g. with inflate or findViewById */ container.addView( - dataCaptureView, - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT + dataCaptureView, + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT, ) /* @@ -328,19 +328,19 @@ Next, you need to create a new instance of the [Camera](https://docs.scandit.com When initializing the camera, you can pass the recommended camera settings for Label Capture. -```java -camera = Camera.getDefaultCamera(LabelCapture.createRecommendedCameraSettings()); +```kotlin +val camera = Camera.getDefaultCamera(LabelCapture.createRecommendedCameraSettings()); if (camera == null) { - throw new IllegalStateException("Failed to init camera!"); + throw IllegalStateException("Failed to init camera!"); } -dataCaptureContext.setFrameSource(camera); +dataCaptureContext.setFrameSource(camera) ``` Once the Camera, DataCaptureContext, DataCaptureView and LabelCapture are initialized, you can switch on the camera to start capturing labels. Typically, this is done on resuming the view and when the user granted permission to use the camera, or once the user pressed continue scanning after handling a previous scan. -```java -camera.switchToDesiredState(FrameSourceState.ON); +```kotlin +camera.switchToDesiredState(FrameSourceState.ON) ``` ## Provide Feedback @@ -372,4 +372,4 @@ labelCapture.setFeedback(LabelCaptureFeedback.defaultFeedback()); :::note Audio feedback is only played if the device is not muted. -::: \ No newline at end of file +::: diff --git a/docs/sdks/android/label-capture/label-definitions.md b/docs/sdks/android/label-capture/label-definitions.md index 959f50e4..7350044b 100644 --- a/docs/sdks/android/label-capture/label-definitions.md +++ b/docs/sdks/android/label-capture/label-definitions.md @@ -36,10 +36,9 @@ Use the `LabelCaptureSettings` builder to configure a pre-built label definition ![Price Label Example](/img/slc/price-label.png) ```kotlin -val settings = - LabelCaptureSettings.builder() - .addLabel(LabelDefinition.createPriceCaptureDefinition("price-label")) - .build +val settings = LabelCaptureSettings.builder() + .addLabel(LabelDefinition.createPriceCaptureDefinition("price-label")) + .build() ``` ## Custom Labels @@ -77,19 +76,18 @@ This example shows how to create a custom label definition for a fish shipping b ![Fish Shipping Box Example](/img/slc/fish-shipping-box.png) ```kotlin -val settings = - LabelCaptureSettings.builder() - .addLabel() - .addCustomBarcode() - .setSymbologies(Symbology.CODE128) - .buildFluent("barcode-field") - .addCustomText() - .setAnchorRegexes("Batch") - .setValueRegexes("FZ\\d{5,10}") - .isOptional(true) - .buildFluent("batch-number-field") - .buildFluent("shipping-label") - .build +val settings = LabelCaptureSettings.builder() + .addLabel() + .addCustomBarcode() + .setSymbologies(Symbology.CODE128) + .buildFluent("barcode-field") + .addCustomText() + .setAnchorRegexes("Batch") + .setValueRegexes("FZ\\d{5,10}") + .isOptional(true) + .buildFluent("batch-number-field") + .buildFluent("shipping-label") +.build() ``` ### Pre-built Fields @@ -140,13 +138,12 @@ This example demonstrates how to configure a label definition for a hard disk dr ![Hard Disk Drive Label Example](/img/slc/hdd-label.png) ```kotlin -val settings = - LabelCaptureSettings.builder() - .addLabel() - .addSerialNumberBarcode() - .buildFluent("serial-number") - .addPartNumberBarcode() - .buildFluent("part-number") - .buildFluent("hdd-label") - .build +val settings = LabelCaptureSettings.builder() + .addLabel() + .addSerialNumberBarcode() + .buildFluent("serial-number") + .addPartNumberBarcode() + .buildFluent("part-number") + .buildFluent("hdd-label") +.build() ``` diff --git a/docs/sdks/android/matrixscan-ar/get-started.md b/docs/sdks/android/matrixscan-ar/get-started.md index d51f7b24..574fd9a3 100644 --- a/docs/sdks/android/matrixscan-ar/get-started.md +++ b/docs/sdks/android/matrixscan-ar/get-started.md @@ -53,15 +53,16 @@ The main entry point for the Barcode AR Mode is the `BarcodeAr` object. You can Here we configure it for tracking EAN13 codes, but you should change this to the correct symbologies for your use case. -```java -BarcodeArSettings settings = new BarcodeArSettings(); -settings.enableSymbology(Symbology.EAN13_UPCA, true); +```kotlin +val settings = BarcodeArSettings().apply { + enableSymbology(Symbology.EAN13_UPCA, true) +} ``` Then create the mode with the previously created settings: -```java -BarcodeAr barcodeAr = new BarcodeAr(dataCaptureContext, settings); +```kotlin +val barcodeAr = BarcodeAr(dataCaptureContext, settings) ``` ## Setup the `BarcodeArView` @@ -79,73 +80,71 @@ The `BarcodeArView` appearance can be customized through [`BarcodeArViewSettings * Zoom control visibility and its position * The size, colors, and styles of the highlights and annotations -```java -BarcodeArViewSettings viewSettings = new BarcodeArViewSettings(); -viewSettings.setHapticEnabled(false); -viewSettings.setSoundEnabled(false); -viewSettings.setDefaultCameraPosition(CameraPosition.USER_FACING); +```kotlin +val viewSettings = BarcodeArViewSettings().apply { + hapticEnabled = false + soundEnabled = false + defaultCameraPosition = CameraPosition.USER_FACING +} ``` Next, create a `BarcodeArView` instance with the Data Capture Context and the settings initialized in the previous step. The `BarcodeArView` is automatically added to the provided parent view. -```java -BarcodeArView barcodeArView = BarcodeArView(parentView, barcodeAr, dataCaptureContext, viewSettings); -barcodeArView.setShouldShowCameraSwitchControl(true); -barcodeArView.setShouldShowTorchControl(true); -barcodeArView.setShouldShowZoomControl(true); -barcodeArView.setCameraSwitchControlPosition(Anchor.TOP_RIGHT); -barcodeArView.setTorchControlPosition(Anchor.BOTTOM_RIGHT); -barcodeArView.setZoomControlPosition(Anchor.TOP_LEFT); +```kotlin +val barcodeArView = BarcodeArView(parentView, barcodeAr, dataCaptureContext, viewSettings).apply { + shouldShowCameraSwitchControl = true + shouldShowTorchControl = true + shouldShowZoomControl = true + cameraSwitchControlPosition = Anchor.TOP_RIGHT + torchControlPosition = Anchor.BOTTOM_RIGHT + zoomControlPosition = Anchor.TOP_LEFT +} ``` Configure the [`highlightProvider`](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/barcode-ar-view.html#property-scandit.datacapture.barcode.check.ui.BarcodeArView.HighlightProvider) and/or [`annotationProvider`](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/barcode-ar-view.html#property-scandit.datacapture.barcode.check.ui.BarcodeArView.AnnotationProvider). -```java -private class AnnotationProvider implements BarcodeArAnnotationProvider { +```kotlin +private class AnnotationProvider: BarcodeArAnnotationProvider { - @Override - public void annotationForBarcode(@NonNull Context context, @NonNull Barcode barcode, @NonNull Callback callback) { - BarcodeArStatusIconAnnotation annotation = new BarcodeArStatusIconAnnotation(context, barcode); - annotation.setText("Example annotation"); - callback.onData(annotation); + override fun annotationForBarcode(context: Context, barcode: Barcode, callback: Callback) { + val annotation = BarcodeArStatusIconAnnotation(context, barcode).apply { + text = "Example annotation" + } + callback.onData(annotation) } } -private class HighlightProvider implements BarcodeArHighlightProvider { +private class HighlightProvider: BarcodeArHighlightProvider { - @Override - public void highlightForBarcode(@NonNull Context context, @NonNull Barcode barcode, @NonNull Callback callback) { - callback.onData(new BarcodeArRectangleHighlight(context, barcode)); + override fun highlightForBarcode(context: Context, barcode: Barcode, callback: Callback) { + callback.onData(BarcodeArRectangleHighlight(context, barcode)) } } ``` And set them to the view: -```java -barcodeArView.setHighlightProvider(new HighlightProvider()); -barcodeArView.setAnnotationProvider(new AnnotationProvider()); +```kotlin +barcodeArView.highlightProvider = HighlightProvider() +barcodeArView.annotationProvider = AnnotationProvider() ``` Connect the `BarcodeArView` to the Android lifecycle. The view is dependent on calling `BarcodeArView.onPause()`, `BarcodeArView.onResume()`, and `BarcodeArView.onDestroy()` to set up the camera and its overlays properly. -```java -@Override -public void onResume() { - super.onResume(); - barcodeArView.onResume(); +```kotlin +override fun onResume() { + super.onResume() + barcodeArView.onResume() } -@Override -public void onPause() { - super.onPause(); - barcodeArView.onPause(); +override fun onPause() { + super.onPause() + barcodeArView.onPause() } -@Override -public void onDestroy() { - super.onDestroy(); - barcodeArView.onDestroy(); +override fun onDestroy() { + super.onDestroy(); + barcodeArView.onDestroy() } ``` @@ -153,19 +152,18 @@ public void onDestroy() { If you want a callback when a highlight is tapped, register a [BarcodeArViewUiListener](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/barcode-ar-view.html#interface-scandit.datacapture.barcode.check.ui.IBarcodeArViewUiListener). -```java -barcodeArView.setUiListener(new BarcodeArViewUiListener() { - @Override - public void onHighlightForBarcodeTapped(@NonNull BarcodeAr barcodeAr, @NonNull Barcode barcode, @NonNull BarcodeArHighlight highlight, @NonNull View highlightView) { +```kotlin +barcodeArView.uiListener = object : BarcodeArViewUiListener { + override fun onHighlightForBarcodeTapped(barcodeAr: BarcodeAr, barcode: Barcode, highlight: BarcodeArHighlight, highlightView: View) { // handle tap } -}); +} ``` ## Start Searching With everything configured, you can now start searching for items. This is done by calling `barcodeArView.start()`. -```java -barcodeArView.start(); +```kotlin +barcodeArView.start() ``` diff --git a/docs/sdks/android/matrixscan-count/advanced.md b/docs/sdks/android/matrixscan-count/advanced.md index e100b18d..8469e070 100644 --- a/docs/sdks/android/matrixscan-count/advanced.md +++ b/docs/sdks/android/matrixscan-count/advanced.md @@ -18,11 +18,12 @@ There is a function to set a list of expected barcodes if you are scanning again When scanning against a list, the UI will also show red icons to mark scanned barcodes that aren’t present on the list. To set the list of expected barcodes, use the following code: -```java -List targetBarcodes = new ArrayList<>(); -targetBarcodes.add(TargetBarcode.create("data", 1)); -BarcodeCountCaptureList captureList = BarcodeCountCaptureList.create(this, targetBarcodes); -barcodeCount.setBarcodeCountCaptureList(captureList); +```kotlin +val targetBarcodes = listOf( + TargetBarcode.create("data", 1) +) +val captureList = BarcodeCountCaptureList.create(this, targetBarcodes) +barcodeCount.setBarcodeCountCaptureList(captureList) ``` ## Barcode Count Status @@ -53,8 +54,8 @@ It can be difficult to reach the shutter button if the smart device is attached You can enable a floating shutter button that can be positioned by the end user in a more ergonomically suitable position: -```java -barcodeCountView.setShouldShowFloatingShutterButton(true); +```kotlin +barcodeCountView.shouldShowFloatingShutterButton = true ``` ## Filtering @@ -63,23 +64,23 @@ If there several types of barcodes on your label you may want to scan only one o For example, you might want to scan only Code 128 barcodes and no PDF417 barcodes. You can do this by setting the following: -```java -BarcodeCountSettings settings = new BarcodeCountSettings(); -settings.enableSymbologies(enabledSymbologies); +```kotlin +val settings = BarcodeCountSettings().apply { + enableSymbologies(enabledSymbologies) +} -Set excludedSymbologies = new HashSet<>(); -excludedSymbologies.add(Symbology.PDF417); -BarcodeFilterSettings filterSettings = settings.getFilterSettings(); -filterSettings.setExcludedSymbologies(excludedSymbologies); +val excludedSymbologies = setOf(Symbology.PDF417) +val filterSettings = settings.filterSettings +filterSettings.excludedSymbologies = excludedSymbologies ``` Or to exclude all the barcodes starting with 4 numbers: -```java -BarcodeCountSettings settings = new BarcodeCountSettings(); +```kotlin +val settings = BarcodeCountSettings() -BarcodeFilterSettings filterSettings = settings.getFilterSettings(); -filterSettings.setExcludedCodesRegex("^1234.*"); +val filterSettings = settings.filterSettings +filterSettings.excludedCodesRegex = "^1234.*" ``` By default the filters applied to the relevant barcodes are transparent, but you can use [`BarcodeFilterHighlightSettings`](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/barcode-filter-highlight-settings.html#barcode-filter-highlight-settings) to change the color and level of transparency. @@ -92,8 +93,8 @@ There are situations in which the user may find it helpful to clean up their scr For this you can enable the “Clear screen” button: -```java -barcodeCountView.setShouldShowClearHighlightsButton(true); +```kotlin +barcodeCountView.shouldShowClearHighlightsButton = true ``` ## Customizing the AR Overlays @@ -102,16 +103,12 @@ MatrixScan Count comes with recommended and user-tested AR overlays. However, if The methods [BarcodeCountViewListener.brushForRecognizedBarcode()](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/barcode-count-view-listener.html#method-scandit.datacapture.barcode.count.ui.IBarcodeCountViewListener.BrushForRecognizedBarcode) and [BarcodeCountViewListener.brushForUnrecognizedBarcode()](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/barcode-count-view-listener.html#method-scandit.datacapture.barcode.count.ui.IBarcodeCountViewListener.BrushForUnrecognizedBarcode) are invoked every time a new recognized or unrecognized barcode appears. These can be used to set a brush that will be used to highlight that specific barcode in the overlay. Keep in mind that these methods are relevant only when using the style [BarcodeCountViewStyle.DOT](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/barcode-count-view.html#value-scandit.datacapture.barcode.count.ui.BarcodeCountViewStyle.Dot). -```java -@Nullable -@Override -public Brush brushForRecognizedBarcode(@NonNull BarcodeCountView view, @NonNull TrackedBarcode trackedBarcode) { +```kotlin +override fun brushForRecognizedBarcode(view: BarcodeCountView, trackedBarcode: TrackedBarcode): Brush? { // Return a custom brush } -@Nullable -@Override -public Brush brushForRecognizedBarcodeNotInList(@NonNull BarcodeCountView view, @NonNull TrackedBarcode trackedBarcode) { +override fun brushForRecognizedBarcodeNotInList(view: BarcodeCountView, trackedBarcode: TrackedBarcode): Brush? { // Return a custom brush } ``` @@ -120,20 +117,12 @@ public Brush brushForRecognizedBarcodeNotInList(@NonNull BarcodeCountView view, If you want to be notified when a user taps on an overlay, you need to implement the [BarcodeCountViewListener.onRecognizedBarcodeTapped()](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/barcode-count-view-listener.html#method-scandit.datacapture.barcode.count.ui.IBarcodeCountViewListener.OnRecognizedBarcodeTapped) and [BarcodeCountViewListener.onUnrecognizedBarcodeTapped()](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/barcode-count-view-listener.html#method-scandit.datacapture.barcode.count.ui.IBarcodeCountViewListener.OnUnrecognizedBarcodeTapped) methods. -```java -@Override -public void onRecognizedBarcodeTapped( - @NonNull BarcodeCountView view, - @NonNull TrackedBarcode trackedBarcode -) { +```kotlin +override fun onRecognizedBarcodeTapped(view: BarcodeCountView, trackedBarcode: TrackedBarcode) { // Do something with the tapped barcode } -@Override -public void onRecognizedBarcodeNotInListTapped( - @NonNull BarcodeCountView view, - @NonNull TrackedBarcode trackedBarcode -) { +override fun onRecognizedBarcodeNotInListTapped(view: BarcodeCountView, trackedBarcode: TrackedBarcode) { // Do something with the tapped barcode } ``` @@ -144,15 +133,15 @@ The UI is an integral part of MatrixScan Count and we do not recommend that you To disable buttons: -```java -barcodeCountView.setShouldShowListButton(false); -barcodeCountView.setShouldShowExitButton(false); -barcodeCountView.setShouldShowShutterButton(false); +```kotlin +barcodeCountView.shouldShowListButton = false +barcodeCountView.shouldShowExitButton = false +barcodeCountView.shouldShowShutterButton = false ``` To disable feedback and hints: -```java -barcodeCountView.setShouldShowUserGuidanceView(false); -barcodeCountView.setShouldShowHints(false); +```kotlin +barcodeCountView.shouldShowUserGuidanceView = false +barcodeCountView.shouldShowHints = false ``` diff --git a/docs/sdks/android/matrixscan-count/get-started.md b/docs/sdks/android/matrixscan-count/get-started.md index 3aa62c3f..6f0dd79b 100644 --- a/docs/sdks/android/matrixscan-count/get-started.md +++ b/docs/sdks/android/matrixscan-count/get-started.md @@ -59,40 +59,41 @@ The main entry point for the Barcode Count Mode is the `BarcodeCount` object. It Here we set up Barcode Count for tracking EAN13 codes, however you must change this to the appropriate symbologies for your use case. If you are sure that your environment has only unique barcodes, you can also enable `BarcodeCountSettings.expectsOnlyUniqueBarcodes`. This option improves scanning performance as long as you are sure that no duplicates are present. -```java -BarcodeCountSettings settings = new BarcodeCountSettings(); -settings.setSymbologyEnabled(Symbology.EAN13_UPCA, true); +```kotlin +val settings = BarcodeCountSettings().apply { + setSymbologyEnabled(Symbology.EAN13_UPCA, true) +} ``` Next, create a `BarcodeCount` instance with the Data Capture Context and the settings initialized in the previous step: -```java -BarcodeCount barcodeCount = BarcodeCount.forDataCaptureContext(dataCaptureContext, settings); +```kotlin +val barcodeCount = BarcodeCount.forDataCaptureContext(dataCaptureContext, settings) ``` ## Camera Instance And Set Frame Source Our recommended camera settings should be used to achieve the best performance and user experience. The following code shows how to get the recommended settings for MatrixScan Count and create the camera from it: -```java -CameraSettings cameraSettings = BarcodeCount.createRecommendedCameraSettings(); +```kotlin +val cameraSettings = BarcodeCount.createRecommendedCameraSettings() -Camera camera = Camera.getDefaultCamera(cameraSettings); +val camera = Camera.getDefaultCamera(cameraSettings) ``` Because the frame source is configurable the data capture context must be told which frame source to use. This is done with a call to [`DataCaptureContext.setFrameSource()`](https://docs.scandit.com/data-capture-sdk/android/core/api/data-capture-context.html#method-scandit.datacapture.core.DataCaptureContext.SetFrameSourceAsync): -```java -dataCaptureContext.setFrameSource(camera); +```kotlin +dataCaptureContext.setFrameSource(camera) ``` ## Registering the Listener To keep track of the barcodes that have been scanned, implement the [BarcodeCountListener](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/barcode-count-listener.html#interface-scandit.datacapture.barcode.count.IBarcodeCountListener) interface and register the listener. -```java +```kotlin // Register self as a listener to monitor the barcode count session. -barcodeCount.addListener(this); +barcodeCount.addListener(this) ``` [`BarcodeCountListener.onScan()`](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/barcode-count-listener.html#method-scandit.datacapture.barcode.count.IBarcodeCountListener.OnScan) is called when the scan phase has finished and results can be retrieved from [`BarcodeCountSession`](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/barcode-count-session.html#class-scandit.datacapture.barcode.count.BarcodeCountSession). @@ -103,8 +104,8 @@ MatrixScan Count’s built-in AR user interface includes buttons and overlays th Add a `BarcodeCountView` to your view hierarchy: -```java -BarcodeCountView view = BarcodeCountView.newInstance(context, dataCaptureView, barcodeCount); +```kotlin +val barcodeCountView = BarcodeCountView.newInstance(context, captureView, barcodeCount) ``` ## Configuring the Camera for Scanning View @@ -113,17 +114,15 @@ The camera is not automatically turned on when you are in a scanning view. You n Similarly `BarcodeCount` should also be enabled and disabled. For example, you should switch off the camera when the `BarcodeCountView` is not visible and switch on the camera when the `BarcodeCountView` is visible. For example: -```java -@Override -protected void onPause() { - camera.switchToDesiredState(FrameSourceState.OFF); - super.onPause(); +```kotlin +override fun onPause() { + camera.switchToDesiredState(FrameSourceState.OFF) + super.onPause() } -@Override -protected void onResume() { - super.onResume(); - camera.switchToDesiredState(FrameSourceState.ON); +override fun onResume() { + super.onResume() + camera.switchToDesiredState(FrameSourceState.ON) } ``` @@ -133,14 +132,13 @@ The values captured as part of the scanning process are part of the session, and We recommend you store the values to present a list, for example when the user taps the list icon. To do this, make a copy of [`BarcodeCountSession.recognizedBarcodes`](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/barcode-count-session.html#property-scandit.datacapture.barcode.count.BarcodeCountSession.RecognizedBarcodes): -```java -@Override -public void onScan( - @NonNull BarcodeCount mode, - @NonNull BarcodeCountSession session, - @NonNull FrameData data +```kotlin +override fun onScan( + mode: BarcodeCount, + session: BarcodeCountSession, + data: FrameData, ) { - List allRecognizedBarcodes = session.getRecognizedBarcodes(); + val allRecognizedBarcodes = session.recognizedBarcodes } ``` @@ -150,26 +148,20 @@ When the scanning process is over, you need to reset the mode to make it ready f To reset Barcode Count’s scanning process, call the `BarcodeCount.reset` method: -```java -barcodeCount.reset(); +```kotlin +barcodeCount.reset() ``` ## List and Exit Callbacks The UI includes two icons (buttons): “List” and “Exit”. The SDK provides the callbacks so you can add the desired action when those icons are tapped by the user: -```java -@Override -public void onListButtonTapped( - @NonNull BarcodeCountView view -) { +```kotlin +override fun onListButtonTapped() { // Show the current progress but the order is not completed } -@Override -public void onExitButtonTapped( - @NonNull BarcodeCountView view -) { +override fun onExitButtonTapped(view: BarcodeCountView) { // The order is completed } ``` diff --git a/docs/sdks/android/matrixscan-find/advanced.md b/docs/sdks/android/matrixscan-find/advanced.md index e5720bba..94ee0bde 100644 --- a/docs/sdks/android/matrixscan-find/advanced.md +++ b/docs/sdks/android/matrixscan-find/advanced.md @@ -18,46 +18,40 @@ You may want more fine-grained knowledge over the different events happening dur To do this, you can directly register a [`BarcodeFindListener`](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/barcode-find-listener.html#interface-scandit.datacapture.barcode.find.IBarcodeFindListener) on the mode itself, keeping in mind that these listeners are called from a background thread. -```java -barcodeFind.addListener(new BarcodeFindListener() { - @Override - public void onSearchPaused(@NonNull Set foundItems) { +```kotlin +barcodeFind.addListener(object : BarcodeFindListener() { + override fun onSearchPaused(foundItems: Set) { // The mode was paused } - @Override - public void onSearchStarted() { + override fun onSearchStarted() { // The mode was started } - @Override - public void onSearchStopped(@NonNull Set foundItems) { + override fun onSearchStopped(foundItems: Set) { // The mode was stopped after the finish button was clicked } -}); +}) ``` ## Multiple criteria You can assign different brushes to each BarcodeFindItem, so they appear visually different to the end user. This can be used to make some items stand out more, or to help the user mentally group certain items together. -```java -Brush availableBrush = new Brush(Color.GREEN, Color.GREEN, 1f); -Brush expiredBrush = new Brush(Color.RED, Color.RED, 1f); - -Set items = new HashSet<>(); -items.add( - new BarcodeFindItem( - new BarcodeFindItemSearchOptions("9783598215438", availableBrush), - new BarcodeFindItemContent("Mini Screwdriver Set", "(6-Piece)", null) - ) -); -items.add( - new BarcodeFindItem( - new BarcodeFindItemSearchOptions("9783598215414", expiredBrush), - null - ) -); +```kotlin +val availableBrush = Brush(Color.GREEN, Color.GREEN, 1f) +val expiredBrush = Brush(Color.RED, Color.RED, 1f) + +val items = setOf( + BarcodeFindItem( + BarcodeFindItemSearchOptions("9783598215438", availableBrush), + BarcodeFindItemContent("Mini Screwdriver Set", "(6-Piece)", null), + ), + BarcodeFindItem( + BarcodeFindItemSearchOptions("9783598215414", expiredBrush), + null, + ), +) ``` ## Set up a transformation @@ -66,19 +60,17 @@ Sometimes, the barcode data needs to be transformed. For example, if the barcode First implement the [BarcodeFindTransformer](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/barcode-find-transformer.html#interface-scandit.datacapture.barcode.find.IBarcodeFindTransformer) interface. For example, if you want to only consider the first 5 characters: -```java -class Transformer implements BarcodeFindTransformer { - @Override - public String transformBarcodeData(String data) { - return data.substring(0, 5); - } +```kotlin +class Transformer: BarcodeFindTransformer { + override fun transformBarcodeData(data: String?): String? = + data?.substring(0, 5) } ``` Then the transformer needs to be set so it can be used by MatrixScan Find: -```java -barcodeFind.setTransformer(new Transformer()); +```kotlin +barcodeFind.setTransformer(Transformer()) ``` ## UI Customization @@ -93,8 +85,8 @@ The `BarcodeFindView` by default shows a set of UI elements, any of which can be Each of these elements can be shown or hidden as needed. For example: -```java -barcodeFindView.setShouldShowCarousel(false); -barcodeFindView.setShouldShowProgressBar(true); +```kotlin +barcodeFindView.shouldShowCarousel = false +barcodeFindView.shouldShowProgressBar = true // … ``` diff --git a/docs/sdks/android/matrixscan-find/get-started.md b/docs/sdks/android/matrixscan-find/get-started.md index 828a6010..3b33423f 100644 --- a/docs/sdks/android/matrixscan-find/get-started.md +++ b/docs/sdks/android/matrixscan-find/get-started.md @@ -57,34 +57,32 @@ The main entry point for the Barcode Find Mode is the `BarcodeFind` object. You Here we configure it for tracking EAN13 codes, but you should change this to the correct symbologies for your use case. -```java -BarcodeFindSettings settings = new BarcodeFindSettings(); -settings.setSymbologyEnabled(Symbology.EAN13_UPCA, true); +```kotlin +val settings = BarcodeFindSettings().apply { + setSymbologyEnabled(Symbology.EAN13_UPCA, true) +} ``` Next, create the list of items that will be actively searched for. We will also attach some optional information to the first item that can be used by the `BarcodeFindView` to display extra information: -```java -Set items = new HashSet<>(); -items.add( - new BarcodeFindItem( - new BarcodeFindItemSearchOptions("9783598215438"), - new BarcodeFindItemContent("Mini Screwdriver Set", "(6-Piece)", null) - ) -); -items.add( - new BarcodeFindItem( - new BarcodeFindItemSearchOptions("9783598215414"), - null // Item information is optional, used for display only - ) -); +```kotlin +val items = setOf( + BarcodeFindItem( + BarcodeFindItemSearchOptions("9783598215438"), + BarcodeFindItemContent("Mini Screwdriver Set", "(6-Piece)", null), + ), + BarcodeFindItem( + BarcodeFindItemSearchOptions("9783598215414"), + null, // Item information is optional, used for display only + ), +) ``` Finally, create a `BarcodeFind` instance with the Data Capture Context and the settings initialized in the previous step: -```java -BarcodeFind barcodeFind = new BarcodeFind(settings); -barcodeFind.setItemList(items); +```kotlin +val barcodeFind = BarcodeFind(settings) +barcodeFind.setItemList(items) ``` ## Setup the `BarcodeFindView` @@ -93,34 +91,32 @@ MatrixScan Find’s built-in AR user interface includes buttons and overlays tha The `BarcodeFindView` appearance can be customized through [`BarcodeFindViewSettings`](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/barcode-find-view-settings.html#class-scandit.datacapture.barcode.find.ui.BarcodeFindViewSettings) to match your application’s look and feel. For example, you can change the color of the dots that are overlaid on top of the items that are found and enable sound and haptic alerts. -```java -BarcodeFindViewSettings viewSettings = new BarcodeFindViewSettings( - Color.GREEN, // inListItemColor - Color.RED, // notInListItemColor - true, // soundEnabled - true // hapticEnabled -); +```kotlin +val viewSettings = BarcodeFindViewSettings( + inListItemColor = Color.GREEN, + notInListItemColor = Color.RED, + soundEnabled = true, + hapticEnabled = true, +) ``` Next, create a `BarcodeFindView` instance with the Data Capture Context and the settings initialized in the previous step. The `BarcodeFindView` is automatically added to the provided parent view. -```java -BarcodeFindView barcodeFindView = BarcodeFindView.newInstance(parentView, dataCaptureContext, barcodeFind, viewSettings); +```kotlin +val barcodeFindView = BarcodeFindView.newInstance(parentView, dataCaptureContext, barcodeFind, viewSettings) ``` Connect the `BarcodeFindView` to the Android lifecycle. The view is dependent on calling `BarcodeFindView.onPause()` and `BarcodeFindView.onResume()` to set up the camera and its overlays properly. -```java -@Override -public void onResume() { - super.onResume(); - barcodeFindView.onResume(); +```kotlin +override fun onResume() { + super.onResume() + barcodeFindView.onResume() } -@Override -public void onPause() { - super.onPause(); - barcodeFindView.onPause(); +override fun onPause() { + super.onPause() + barcodeFindView.onPause() } ``` @@ -132,21 +128,20 @@ Register a [BarcodeFindViewUiListener](https://docs.scandit.com/data-capture-sdk In this tutorial, we will then navigate back to the previous screen to finish the find session. -```java -barcodeFindView.setListener(new BarcodeFindViewUiListener() { - @Override - public void onFinishButtonTapped(@NonNull Set foundItems) { - requireActivity().onBackPressed(); +```kotlin +barcodeFindView.setListener(object : BarcodeFindViewUiListener { + override fun onFinishButtonTapped(foundItems: Set) { + requireActivity().onBackPressed() } -}); +}) ``` ## Start Searching With everything configured, you can now start searching for items. This is done by calling `barcodeFindView.startSearching()`. -```java -barcodeFindView.startSearching(); +```kotlin +barcodeFindView.startSearching() ``` This is the equivalent of pressing the Play button programmatically. It will start the search process, turn on the camera, and hide the item carousel. diff --git a/docs/sdks/android/matrixscan-pick/advanced.md b/docs/sdks/android/matrixscan-pick/advanced.md index 8665ae52..18461047 100644 --- a/docs/sdks/android/matrixscan-pick/advanced.md +++ b/docs/sdks/android/matrixscan-pick/advanced.md @@ -16,45 +16,38 @@ MatrixScan Pick is optimized by default for efficiency, accuracy, and a seamless You can register a [`BarcodePickListener`](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/barcode-pick-listener.html) on the mode, which can be used to get updates about the scanned items with each frame. -```java -barcodePick.addListener(new BarcodePickListener() { - @Override - public void onSessionUpdated(@NonNull BarcodePick barcodePick, @NonNull BarcodePickSession session) { +```kotlin +barcodePick.addListener(object : BarcodePickListener { + override fun onSessionUpdated(barcodePick: BarcodePick, session: BarcodePickSession) { // This callback will be invoked on a background thread every frame. the session object contains // updated the newly tracked items. } - @Override - public void onObservationStarted(@NonNull BarcodePick barcodePick) {} + override fun onObservationStarted(barcodePick: BarcodePick) {} - @Override - public void onObservationStopped(@NonNull BarcodePick barcodePick) {} -}); + override fun onObservationStopped(barcodePick: BarcodePick) {} +}) ``` ## BarcodePickScanning Listener You can register a [`BarcodePickScanningListener`](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/barcode-pick-scanning-listener.html) on the mode, which can be used to listen to every time the pick state changes. -```java -barcodePick.addScanningListener(new BarcodePickScanningListener() { - @Override - public void onScanningSessionUpdated(@NonNull BarcodePick barcodePick, @NonNull BarcodePickScanningSession session) { +```kotlin +barcodePick.addScanningListener(object : BarcodePickScanningListener { + override fun onScanningSessionUpdated(barcodePick: BarcodePick, session: BarcodePickScanningSession) { // This callback will be invoked on a background thread every time the picked state of some item changes. // The session object contains the list of picked and scanned items. } - @Override - public void onScanningSessionCompleted(@NonNull BarcodePick barcodePick, @NonNull BarcodePickScanningSession session) { + override fun onScanningSessionCompleted(barcodePick: BarcodePick, session: BarcodePickScanningSession) { // This callback is invoked when all the registered items needing picking have been picked. } - @Override - public void onObservationStarted(@NonNull BarcodePick barcodePick) {} + override fun onObservationStarted(barcodePick: BarcodePick) {} - @Override - public void onObservationStopped(@NonNull BarcodePick barcodePick) {} -}); + override fun onObservationStopped(barcodePick: BarcodePick) {} +}) ``` ## BarcodePickView Listener @@ -63,38 +56,32 @@ You may want more fine-grained knowledge over the different events happening dur To do this, you can directly register a [`BarcodePickViewListener`](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/barcode-pick-view-listener.html) on the mode itself, keeping in mind that these listeners are called from a background thread. -```java -barcodePickView.setListener(new BarcodePickViewListener() { - @Override - public void onStopped(@NonNull BarcodePickView view) {} +```kotlin +barcodePickView.listener = object : BarcodePickViewListener { + override fun onStopped(view: BarcodePickView) {} - @Override - public void onPaused(@NonNull BarcodePickView view) {} + override fun onPaused(view: BarcodePickView) {} - @Override - public void onFreezed(@NonNull BarcodePickView view) {} + override fun onFreezed(view: BarcodePickView) {} - @Override - public void onStarted(@NonNull BarcodePickView view) {} -}); + override fun onStarted(view: BarcodePickView) {} +} ``` ## BarcodePickAction Listener You can also register a [`BarcodePickActionListener`](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/barcode-pick-action-listener.html) on the mode, which can be used to reject specific pick/unpick actions. -```java -barcodePickView.addActionListener(new BarcodePickActionListener() { - @Override - public void onPick(@NonNull String itemData, @NonNull BarcodePickActionCallback callback) { +```kotlin +barcodePickView.addActionListener(object : BarcodePickActionListener { + override fun onPick(itemData: String, callback: BarcodePickActionCallback) { // Perform the needed checks, and invoke callback.onFinish(true/false) to allow/reject // the current pick action } - @Override - public void onUnpick(@NonNull String itemData, @NonNull BarcodePickActionCallback callback) { + override fun onUnpick(itemData: String, callback: BarcodePickActionCallback) { // Perform the needed checks, and invoke callback.onFinish(true/false) to allow/reject // the current unpick action } -}); +}) ``` diff --git a/docs/sdks/android/matrixscan-pick/get-started.md b/docs/sdks/android/matrixscan-pick/get-started.md index c008a974..07075184 100644 --- a/docs/sdks/android/matrixscan-pick/get-started.md +++ b/docs/sdks/android/matrixscan-pick/get-started.md @@ -53,86 +53,85 @@ The main entry point for the Barcode Pick Mode is the `BarcodePick` object. You Here we configure it for tracking EAN13 codes, but you should change this to the correct symbologies for your use case. -```java -BarcodePickSettings settings = new BarcodePickSettings(); -settings.enableSymbology(Symbology.EAN13_UPCA, true); +```kotlin +val settings = BarcodePickSettings().apply { + enableSymbology(Symbology.EAN13_UPCA, true) +} ``` Then you have to create the product provider for the Barcode Pick mode. This provider is responsible for providing the items that should be highlighted in the AR view. Note that in this example we are using a hardcoded list of items, but in a real-world scenario, you would fetch this list from your backend. -```java -List productDatabase = new ArrayList<>(); - productDatabase.add( - new ProductDatabaseEntry( - /*product identifier*/"product_1", - /*quantity to pick*/2, - /*items for the product*/new HashSet() {{ - add("9783598215438"); - add("9783598215414"); - add("9783598215441"); - add("9783598215412"); - }}) - ); - productDatabase.add( - new ProductDatabaseEntry( - /*product identifier*/"product_2", - /*quantity to pick*/3, - /*items for the product*/new HashSet() {{ - add("9783598215471"); - add("9783598215481"); - add("9783598215458"); - add("9783598215498"); - add("9783598215421"); - }}) - ); - - // Map the database products to create the Scandit product provider input. - Set items = new HashSet<>(); - for (ProductDatabaseEntry productDatabaseEntry : productDatabase) { - items.add( - new BarcodePickProduct( - productDatabaseEntry.productIdentifier, - productDatabaseEntry.quantityToPick - ) - ); +```kotlin +val productDatabase = listOf( + ProductDatabaseEntry( + /*product identifier*/"product_1", + /*quantity to pick*/2, + /*items for the product*/setOf { + "9783598215438", + "9783598215414", + "9783598215441", + "9783598215412", + } + ), + ProductDatabaseEntry( + /*product identifier*/"product_2", + /*quantity to pick*/3, + /*items for the product*/setOf { + "9783598215471", + "9783598215481", + "9783598215458", + "9783598215498", + "9783598215421", } + ), +) + +// Map the database products to create the Scandit product provider input. +val items = mutableSetOf() +productDatabase.forEach { productDatabaseEntry -> + items.add( + BarcodePickProduct( + productDatabaseEntry.productIdentifier, + productDatabaseEntry.quantityToPick, + ) + ) +} - // Finally, create the product provider itself - BarcodePickProductProvider productProvider = new BarcodePickAsyncMapperProductProvider( - items, - new BarcodePickAsyncMapperProductProviderCallback() { - @Override - public void productIdentifierForItems( - @NonNull List itemsData, - @NonNull BarcodePickProductProviderCallback callback - ) { - ArrayList results = new ArrayList<>(); - - // Use the scanned itemsData list to retrieve the identifier of the product they belong to. - // This should be an async query in real world scenarios if there are a lot of products/items to loop. - for (String itemData : itemsData) { - for (ProductDatabaseEntry entry : productDatabase) { - if (entry.items.contains(itemData)) { - results.add( - new BarcodePickProductProviderCallbackItem( - /*item data*/itemData, - /*product identifier*/entry.productIdentifier - ) - ); - break; - } - } +// Finally, create the product provider itself +val productProvider = BarcodePickAsyncMapperProductProvider( + items, + object : BarcodePickAsyncMapperProductProviderCallback { + override fun productIdentifierForItems( + itemsData: List, + callback: BarcodePickProductProviderCallback, + ) { + val results = mutableListOf() + + // Use the scanned itemsData list to retrieve the identifier of the product they belong to. + // This should be an async query in real world scenarios if there are a lot of products/items to loop. + itemsData.forEach { itemData -> + for (entry in productDatabase) { + if (entry.items.contains(itemData)) { + results.add( + BarcodePickProductProviderCallbackItem( + /*item data*/itemData, + /*product identifier*/entry.productIdentifier + ) + ) + break } - callback.onData(results); } } - ); + callback.onData(results) + } + } +) ``` Create the mode with the previously created settings: -```java -BarcodePick mode = new BarcodePick(dataCaptureContext, settings, productProvider); +```kotlin +val barcodePick = BarcodePick(dataCaptureContext, settings, productProvider) ``` ## Setup the `BarcodePickView` @@ -150,36 +149,33 @@ The `BarcodePickView` appearance can be customized through [`BarcodePickViewSett * Zoom button * Loading Dialog -```java -BarcodePickViewSettings viewSettings = new BarcodePickViewSettings(); +```kotlin +val viewSettings = BarcodePickViewSettings() // ... ``` Next, create a `BarcodePickView` instance with the Data Capture Context and the settings initialized in the previous step. The `BarcodePickView` is automatically added to the provided parent view. -```java -BarcodePickView barcodePickView = BarcodePickView.newInstance(parentView, dataCaptureContext, mode, viewSettings); +```kotlin +val barcodePickView = BarcodePickView.newInstance(parentView, dataCaptureContext, barcodePick, viewSettings) ``` Connect the `BarcodePickView` to the Android lifecycle. The view is dependent on calling `BarcodePickView.onPause()`, `BarcodePickView.onResume()`, and `BarcodePickView.onDestroy()` to set up the camera and its overlays properly. -```java -@Override -public void onResume() { - super.onResume(); - barcodePickView.onResume(); +```kotlin +override fun onResume() { + super.onResume() + barcodePickView.onResume() } -@Override -public void onPause() { - super.onPause(); - barcodePickView.onPause(); +override fun onPause() { + super.onPause() + barcodePickView.onPause() } -@Override -public void onDestroyView() { - super.onDestroyView(); - barcodePickView.onDestroy(); +override fun onDestroy() { + super.onDestroy(); + barcodePickView.onDestroy() } ``` @@ -191,21 +187,20 @@ Register a [BarcodePickViewUiListener](https://docs.scandit.com/data-capture-sdk In this tutorial, we will then navigate back to the previous screen to finish the find session. -```java -barcodePickView.setUiListener(new BarcodePickViewUiListener() { - @Override - public void onFinishButtonTapped(@NonNull BarcodePickView view) { - requireActivity().onBackPressed(); +```kotlin +barcodePickView.uiListener = object : BarcodePickViewUiListener { + override fun onFinishButtonTapped(view: BarcodePickView) { + requireActivity().onBackPressed() } -}); +} ``` ## Start Searching With everything configured, you can now start searching for items. This is done by calling `barcodePickView.start()`. -```java -barcodePickView.start(); +```kotlin +barcodePickView.start() ``` This is the equivalent of pressing the Play button programmatically. It will start the search process, turn on the camera, and hide the item carousel. diff --git a/docs/sdks/android/matrixscan/advanced.md b/docs/sdks/android/matrixscan/advanced.md index 22725054..5b704000 100644 --- a/docs/sdks/android/matrixscan/advanced.md +++ b/docs/sdks/android/matrixscan/advanced.md @@ -29,8 +29,8 @@ This example describes the steps to add a view above each barcode showing its co First, create a new instance of `BarcodeBatchAdvancedOverlay` and add it to your `DataCaptureView`: -```java -BarcodeBatchAdvancedOverlay overlay = BarcodeBatchAdvancedOverlay.newInstance(barcodeBatch, dataCaptureView); +```kotlin +val overlay = BarcodeBatchAdvancedOverlay.newInstance(barcodeBatch, dataCaptureView) ``` There are two ways to proceed from here: @@ -51,53 +51,38 @@ For this option, keep in mind that: * [BarcodeBatchAdvancedOverlayListener.anchorForTrackedBarcode()](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/barcode-batch-advanced-overlay-listener.html#method-scandit.datacapture.barcode.batch.ui.IBarcodeBatchAdvancedOverlayListener.AnchorForTrackedBarcode) asks how to anchor the view to the barcode through Anchor. Be aware that it anchors the view’s center to the anchor point. To achieve anchoring the top of the view or the bottom etc. you need to set an offset as explained in the next point. * [BarcodeBatchAdvancedOverlayListener.offsetForTrackedBarcode()](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/barcode-batch-advanced-overlay-listener.html#method-scandit.datacapture.barcode.batch.ui.IBarcodeBatchAdvancedOverlayListener.OffsetForTrackedBarcode) asks for an offset that is applied on the already anchored view. This offset is expressed through a [PointWithUnit](https://docs.scandit.com/data-capture-sdk/android/core/api/common.html#struct-scandit.datacapture.core.PointWithUnit). -```java -@Nullable -@Override -public View viewForTrackedBarcode( - @NonNull BarcodeBatchAdvancedOverlay overlay, - @NonNull TrackedBarcode trackedBarcode -) { - // Create and return the view you want to show for this tracked barcode. - // You can also return null, to have no view for this barcode. - TextView textView = new TextView(this); - textView.setBackgroundColor(Color.WHITE); - textView.setLayoutParams( - new ViewGroup.LayoutParams( - ViewGroup.LayoutParams.WRAP_CONTENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ) - ); - textView.setText(trackedBarcode.getBarcode().getData()); - return textView; -} - -@NonNull -@Override -public Anchor anchorForTrackedBarcode( - @NonNull BarcodeBatchAdvancedOverlay overlay, - @NonNull TrackedBarcode trackedBarcode -) { - // As we want the view to be above the barcode, we anchor the view's center to the top-center of the barcode quadrilateral. - // Use the function 'offsetForTrackedBarcode' below to adjust the position of the view by providing an offset. - return Anchor.TOP_CENTER; +```kotlin +// Create and return the view you want to show for this tracked barcode. You can also return null, to have no view for this barcode. +fun viewForTrackedBarcode( + overlay: BarcodeBatchAdvancedOverlay, + trackedBarcode: TrackedBarcode, +): View = TextView(this).apply { + setBackgroundColor(Color.WHITE) + layoutParams = ViewGroup.LayoutParams( + ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.WRAP_CONTENT, + ) + text = trackedBarcode.barcode.data } -@NonNull -@Override -public PointWithUnit offsetForTrackedBarcode( - @NonNull BarcodeBatchAdvancedOverlay overlay, - @NonNull TrackedBarcode trackedBarcode, - @NonNull View view -) { - // This is the offset that will be applied to the view. - // You can use MeasureUnit.FRACTION to give a measure relative to the view itself, the sdk will take care of transforming this into pixel size. - // We now center horizontally and move up the view to make sure it's centered and above the barcode quadrilateral by half of the view's height. - return new PointWithUnit( - new FloatWithUnit(0f, MeasureUnit.FRACTION), - new FloatWithUnit(-1f, MeasureUnit.FRACTION) - ); -} +// As we want the view to be above the barcode, we anchor the view's center to the top-center of the barcode quadrilateral. +// Use the function 'offsetForTrackedBarcode' below to adjust the position of the view by providing an offset. +fun anchorForTrackedBarcode( + overlay: BarcodeBatchAdvancedOverlay, + trackedBarcode: TrackedBarcode, +): Anchor = Anchor.TOP_CENTER + +// This is the offset that will be applied to the view. +// You can use MeasureUnit.FRACTION to give a measure relative to the view itself, the sdk will take care of transforming this into pixel size. +// We now center horizontally and move up the view to make sure it's centered and above the barcode quadrilateral by half of the view's height. +fun offsetForTrackedBarcode( + overlay: BarcodeBatchAdvancedOverlay, + trackedBarcode: TrackedBarcode, + view: View, +): PointWithUnit = PointWithUnit( + FloatWithUnit(0f, MeasureUnit.FRACTION), + FloatWithUnit(-1f, MeasureUnit.FRACTION), +) ``` ### Using the Setters @@ -110,38 +95,37 @@ From here you can create the view you want to display, and then call: * [BarcodeBatchAdvancedOverlay.setAnchorForTrackedBarcode()](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/barcode-batch-advanced-overlay.html#method-scandit.datacapture.barcode.batch.ui.BarcodeBatchAdvancedOverlay.SetAnchorForTrackedBarcode) * [BarcodeBatchAdvancedOverlay.setOffsetForTrackedBarcode()](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/barcode-batch-advanced-overlay.html#method-scandit.datacapture.barcode.batch.ui.BarcodeBatchAdvancedOverlay.SetOffsetForTrackedBarcode) -```java -@Override -public void onSessionUpdated( - @NonNull BarcodeBatch mode, - @NonNull BarcodeBatchSession session, - @NonNull FrameData data +```kotlin +fun onSessionUpdated( + mode: BarcodeBatch, + session: BarcodeBatchSession, + data: FrameData, ) { // Be careful, this function is not invoked on the main thread! - runOnUiThread(() -> { - for (TrackedBarcode trackedBarcode : session.getAddedTrackedBarcodes()) { - TextView textView = new TextView(this); - textView.setBackgroundColor(Color.WHITE); - textView.setLayoutParams( - new ViewGroup.LayoutParams( + runOnUiThread { + session.addedTrackedBarcodes.forEach { trackedBarcode -> + val textView = TextView(this).apply { + setBackgroundColor(Color.WHITE) + layoutParams = ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT ) - ); - textView.setText(trackedBarcode.getBarcode().getData()); - overlay.setViewForTrackedBarcode(trackedBarcode, textView); + text = trackedBarcode.barcode.data + } + overlay.setViewForTrackedBarcode(trackedBarcode, textView) overlay.setAnchorForTrackedBarcode( - trackedBarcode, Anchor.TOP_CENTER - ); + trackedBarcode, + Anchor.TOP_CENTER, + ) overlay.setOffsetForTrackedBarcode( trackedBarcode, - new PointWithUnit( - new FloatWithUnit(0f, MeasureUnit.FRACTION), - new FloatWithUnit(-1f, MeasureUnit.FRACTION) + PointWithUnit( + FloatWithUnit(0f, MeasureUnit.FRACTION), + FloatWithUnit(-1f, MeasureUnit.FRACTION), ) - ); + ) } - }); + } } ``` @@ -159,30 +143,28 @@ If you do not want to use the overlay, it is also possible to add augmented real The frame coordinates from `TrackedBarcode.location` need to be mapped to view coordinates, using [DataCaptureView.mapFrameQuadrilateralToView()](https://docs.scandit.com/data-capture-sdk/android/core/api/ui/data-capture-view.html#method-scandit.datacapture.core.ui.DataCaptureView.MapFrameQuadrilateralToView). ::: -```java -@Override -public void onSessionUpdated( - @NonNull BarcodeBatch mode, - @NonNull final BarcodeBatchSession session, - @NonNull FrameData data +```kotlin +fun onSessionUpdated( + mode: BarcodeBatch, + session: BarcodeBatchSession, + data: FrameData, ) { // Be careful, this function is not invoked on the main thread! - runOnUiThread(() -> { - for (int lostTrackIdentifier : session.getRemovedTrackedBarcodes()) { + runOnUiThread { + session.removedTrackedBarcodes.forEach { lostTrackIdentifier -> // You now know the identifier of the tracked barcode that has been lost. Usually here you would remove the views associated. } - for (TrackedBarcode trackedBarcode : session.getAddedTrackedBarcodes()) { - + session.addedTrackedBarcodes.forEach { trackedBarcode -> // Fixed identifier for the tracked barcode. - Integer trackingIdentifier = trackedBarcode.getIdentifier(); + val trackingIdentifier = trackedBarcode.identifier // Current location of the tracked barcode. - Quadrilateral location = trackedBarcode.getLocation(); - Quadrilateral quadrilateral = dataCaptureView.mapFrameQuadrilateralToView(location); + val location = trackedBarcode.location + val quadrilateral = dataCaptureView.mapFrameQuadrilateralToView(location) - // You now know this new tracking's identifier and location. Usually here you would create and show the views. + // You now know this tracking's identifier and location. Usually here you would create and show the views. } - }); + } } ``` diff --git a/docs/sdks/android/matrixscan/get-started.md b/docs/sdks/android/matrixscan/get-started.md index bd9a75a6..e0af7c64 100644 --- a/docs/sdks/android/matrixscan/get-started.md +++ b/docs/sdks/android/matrixscan/get-started.md @@ -60,15 +60,16 @@ Typically you do not need to implement to a `BarcodeBatchListener`, instead you For this task, we setup Barcode Batch for tracking QR codes: -```java -BarcodeBatchSettings settings = new BarcodeBatchSettings(); -settings.enableSymbology(Symbology.QR, true); +```kotlin +val settings = BarcodeBatchSettings().apply { + enableSymbology(Symbology.QR, true) +} ``` Next, create a `BarcodeBatch` instance with the data capture context and the settings initialized in the previous steps: -```java -BarcodeBatch barcodeBatch = BarcodeBatch.forDataCaptureContext(dataCaptureContext, settings); +```kotlin +val barcodeBatch = BarcodeBatch.forDataCaptureContext(dataCaptureContext, settings) ``` ## Use the Built-in Camera @@ -83,29 +84,25 @@ When using the built-in camera there are recommended settings for each capture m The following lines show how to get the recommended settings and create the camera from it: -```java -CameraSettings cameraSettings = BarcodeBatch.createRecommendedCameraSettings(); +```kotlin +val cameraSettings = BarcodeBatch.createRecommendedCameraSettings() // Depending on the use case further camera settings adjustments can be made here. -Camera camera = Camera.getDefaultCamera(); -if (camera != null) { - camera.applySettings(cameraSettings, null); -} +val camera = Camera.getDefaultCamera() +camera?.applySettings(cameraSettings, null) ``` Because the frame source is configurable, the data capture context must be told which frame source to use. This is done with a call to [DataCaptureContext.setFrameSource()](https://docs.scandit.com/data-capture-sdk/android/core/api/data-capture-context.html#method-scandit.datacapture.core.DataCaptureContext.SetFrameSourceAsync): -```java -dataCaptureContext.setFrameSource(camera); +```kotlin +dataCaptureContext.setFrameSource(camera) ``` The camera is off by default and must be turned on. This is done by calling [FrameSource.switchToDesiredState()](https://docs.scandit.com/data-capture-sdk/android/core/api/frame-source.html#method-scandit.datacapture.core.IFrameSource.SwitchToDesiredStateAsync) with a value of [FrameSourceState.ON](https://docs.scandit.com/data-capture-sdk/android/core/api/frame-source.html#value-scandit.datacapture.core.FrameSourceState.On): -```java -if (camera != null) { - camera.switchToDesiredState(FrameSourceState.ON); -} +```kotlin +camera?.switchToDesiredState(FrameSourceState.ON) ``` ## Visualize the Scan Process @@ -114,37 +111,34 @@ When using the built-in camera as frame source, you typically want to display th To do that, add a [DataCaptureView](https://docs.scandit.com/data-capture-sdk/android/core/api/ui/data-capture-view.html#class-scandit.datacapture.core.ui.DataCaptureView) to your view hierarchy: -```java -DataCaptureView dataCaptureView = DataCaptureView.newInstance(this, dataCaptureContext); -setContentView(dataCaptureView); +```kotlin +val dataCaptureView = DataCaptureView.newInstance(this, dataCaptureContext) +setContentView(dataCaptureView) ``` To visualize the results of Barcode Batch, first you need to add the following [overlay](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/barcode-batch-basic-overlay.html#class-scandit.datacapture.barcode.batch.ui.BarcodeBatchBasicOverlay): -```java -BarcodeBatchBasicOverlay overlay = BarcodeBatchBasicOverlay.newInstance(barcodeBatch, dataCaptureView); +```kotlin +val overlay = BarcodeBatchBasicOverlay.newInstance(barcodeBatch, dataCaptureView) ``` Once the overlay has been added, you must conform to the [BarcodeBatchBasicOverlayListener](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/barcode-batch-basic-overlay-listener.html#interface-scandit.datacapture.barcode.batch.ui.IBarcodeBatchBasicOverlayListener) interface. The method [BarcodeBatchBasicOverlayListener.brushForTrackedBarcode()](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/barcode-batch-basic-overlay-listener.html#method-scandit.datacapture.barcode.batch.ui.IBarcodeBatchBasicOverlayListener.BrushForTrackedBarcode) is invoked every time a new tracked barcode appears and it can be used to set a brush used to highlight that specific barcode in the [overlay](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/barcode-batch-basic-overlay.html#class-scandit.datacapture.barcode.batch.ui.BarcodeBatchBasicOverlay). -```java -@Nullable -@Override -public Brush brushForTrackedBarcode( - @NonNull BarcodeBatchBasicOverlay overlay, - @NonNull TrackedBarcode trackedBarcode -) { +```kotlin +override fun brushForTrackedBarcode( + overlay: BarcodeBatchBasicOverlay, + trackedBarcode: TrackedBarcode, +): Brush { // Return a custom Brush based on the tracked barcode. } ``` If you want to make the highlights tappable, you need to implement the [BarcodeBatchBasicOverlayListener.onTrackedBarcodeTapped()] method. -```java -@Override -public void onTrackedBarcodeTapped( - @NonNull BarcodeBatchBasicOverlay overlay, - @NonNull TrackedBarcode trackedBarcode +```kotlin +override fun onTrackedBarcodeTapped( + overlay: BarcodeBatchBasicOverlay, + trackedBarcode: TrackedBarcode, ) { // A tracked barcode was tapped. } @@ -158,36 +152,33 @@ Here, we use the default [Feedback](https://docs.scandit.com/data-capture-sdk/an First, we create a feedback and release it after it is no longer used, to avoid resources being unnecessarily held. -```java -Feedback feedback = Feedback.defaultFeedback(); +```kotlin +val feedback = Feedback.defaultFeedback() ``` Next, use this `feedback` in a `BarcodeBatchListener`: -```java -public class FeedbackListener implements BarcodeBatchListener { - Feedback feedback = Feedback.defaultFeedback(); - - @Override - public void onObservationStarted(@NonNull BarcodeBatch barcodeBatch) { +```kotlin +class FeedbackListener: BarcodeBatchListener { + val feedback = Feedback.defaultFeedback() + + override fun onObservationStarted(barcodeBatch: BarcodeBatch) { // Called when Barcode Batch is started. // We don't use this callback in this guide. } - @Override - public void onObservationStopped(@NonNull BarcodeBatch barcodeBatch) { + override fun onObservationStopped(barcodeBatch: BarcodeBatch) { // Called when Barcode Batch is stopped. // We don't use this callback in this guide. } - @Override - public void onSessionUpdated( - @NonNull BarcodeBatch mode, - @NonNull BarcodeBatchSession session, - @NonNull FrameData data + override fun onSessionUpdated( + mode: BarcodeBatch, + session: BarcodeBatchSession, + data: FrameData, ) { - if (!session.getAddedTrackedBarcodes().isEmpty()) { - feedback.emit(); + if (session.addedTrackedBarcodes.isNotEmpty()) { + feedback.emit() } } } @@ -197,8 +188,8 @@ public class FeedbackListener implements BarcodeBatchListener { As the last step, register the listener responsible for emitting the feedback with the `BarcodeBatch` instance. -```java -barcodeBatch.addListener(new FeedbackListener()); +```kotlin +barcodeBatch.addListener(FeedbackListener()) ``` ## Disable Barcode Batch diff --git a/docs/sdks/android/sparkscan/advanced.md b/docs/sdks/android/sparkscan/advanced.md index 3d1cdda5..d19efe33 100644 --- a/docs/sdks/android/sparkscan/advanced.md +++ b/docs/sdks/android/sparkscan/advanced.md @@ -38,23 +38,20 @@ You can customize: To emit an error, you have to implement a [`SparkScanFeedbackDelegate`](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/spark-scan-feedback-delegate.html#interface-scandit.datacapture.barcode.spark.feedback.ISparkScanFeedbackDelegate) and set it to the `SparkScanView`: -```java -sparkScanView.setFeedbackDelegate(this); +```kotlin +sparkScanView.feedbackDelegate = this ``` In the [`SparkScanFeedbackDelegate.getFeedbackForBarcode()`](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/spark-scan-feedback-delegate.html#method-scandit.datacapture.barcode.spark.feedback.ISparkScanFeedbackDelegate.GetFeedbackForBarcode) you can then return an error or a success feedback: -```java -@Nullable -@Override -public SparkScanBarcodeFeedback getFeedbackForBarcode(@NonNull Barcode barcode) { +```kotlin +override fun getFeedbackForBarcode(barcode: Barcode): SparkScanBarcodeFeedback? = if (isValidBarcode(barcode)) { - return new SparkScanBarcodeFeedback.Success(); + SparkScanBarcodeFeedback.Success() } else { - return new SparkScanBarcodeFeedback.Error("This code should not have been scanned", - TimeInterval.seconds(60f)); + SparkScanBarcodeFeedback.Error("This code should not have been scanned", + TimeInterval.seconds(60f)) } -} ``` @@ -121,4 +118,4 @@ The preview behavior determines how the camera preview behaves when the scanner | Behavior | Description | | -------------- | -------------------------- | | **Default** | Preview fades away when the scanner is off. This lets the user check important information displayed by the app and reduces battery consumption. | -| **Persistent** | Preview remains visible, but darkened, even when the scanner is off. This is useful for scenarios where you want to select a barcode (among many) or need to look through the preview at all times (to ensure the right scan) - especially if used in conjunction with the target mode. | \ No newline at end of file +| **Persistent** | Preview remains visible, but darkened, even when the scanner is off. This is useful for scenarios where you want to select a barcode (among many) or need to look through the preview at all times (to ensure the right scan) - especially if used in conjunction with the target mode. | diff --git a/docs/sdks/android/sparkscan/get-started.md b/docs/sdks/android/sparkscan/get-started.md index 688e5b5f..3e4bae53 100644 --- a/docs/sdks/android/sparkscan/get-started.md +++ b/docs/sdks/android/sparkscan/get-started.md @@ -48,8 +48,8 @@ import InternalDependencies from '../../../partials/get-started/_internal-deps.m The first step to add capture capabilities to your application is to create a new Data Capture Context. The context expects a valid Scandit Data Capture SDK license key during construction. -```java -DataCaptureContext dataCaptureContext = DataCaptureContext.forLicenseKey("-- ENTER YOUR SCANDIT LICENSE KEY HERE --"); +```kotlin +val dataCaptureContext = DataCaptureContext.forLicenseKey("-- ENTER YOUR SCANDIT LICENSE KEY HERE --") ``` ## Configure the SparkScan Mode @@ -58,17 +58,17 @@ The SparkScan Mode is configured through SparkScanSettings and allows you to reg For this tutorial, we set up SparkScan for scanning EAN13 codes. You can change this to the correct symbologies for your use case (for instance, Code 128, Code 39…). -```java -SparkScanSettings settings = new SparkScanSettings(); -HashSet symbologies = new HashSet<>(); -symbologies.add(Symbology.EAN13_UPCA); -settings.enableSymbologies(symbologies); +```kotlin +val settings = SparkScanSettings().apply { + val symbologies = setOf(Symbology.EAN13_UPCA) + enableSymbologies(symbologies) +} ``` Next, create a SparkScan instance with the settings initialized in the previous step: -```java -SparkScan sparkScan = new SparkScan(settings); +```kotlin +val sparkScan = SparkScan(settings) ``` ## Create the SparkScan View @@ -77,8 +77,8 @@ The SparkScan built-in user interface includes the camera preview and scanning U The [`SparkScanView`](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/spark-scan-view.html) appearance can be customized through [`SparkScanViewSettings`](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/ui/spark-scan-view-settings.html). -```java -SparkScanViewSettings viewSettings = new SparkScanViewSettings(); +```kotlin +val viewSettings = SparkScanViewSettings() // setup the desired appearance settings by updating the fields in the object above ``` @@ -86,25 +86,23 @@ By adding a `SparkScanView`, the scanning interface (camera preview and scanning Construct a new SparkScan view. The SparkScan view is automatically added to the provided parentView: -```java -SparkScanView sparkScanView = SparkScanView.newInstance(parentView, dataCaptureContext, sparkScan, viewSettings); +```kotlin +val sparkScanView = SparkScanView.newInstance(parentView, dataCaptureContext, sparkScan, viewSettings) ``` See the [SparkScan Workflow Options](./advanced.md#workflow-options) section for more information. Additionally, make sure to call `sparkScanView.onPause()` and `sparkScanView.onResume()` in your Fragment/Activity `onPause` and `onResume` callbacks. You have to call these for the correct functioning of the `SparkScanView`. -```java -@Override -protected void onPause() { - sparkScanView.onPause(); - super.onPause(); +```kotlin +override fun onPause() { + sparkScanView.onPause() + super.onPause() } -@Override -protected void onResume() { - sparkScanView.onResume(); - super.onResume(); +override fun onResume() { + sparkScanView.onResume() + super.onResume() } ``` @@ -112,9 +110,9 @@ protected void onResume() { To keep track of the barcodes that have been scanned, implement the [SparkScanListener](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/spark-scan-listener.html#interface-scandit.datacapture.barcode.spark.ISparkScanListener) interface and register the listener to the SparkScan mode. -```java +```kotlin // Register self as a listener to monitor the spark scan session. -sparkScan.addListener(this); +sparkScan.addListener(this) ``` [SparkScanListener.onBarcodeScanned()](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/spark-scan-listener.html#method-scandit.datacapture.barcode.spark.ISparkScanListener.OnBarcodeScanned) is called when a new barcode has been scanned. This result can be retrieved from the first object in the provided barcodes list: [SparkScanSession.newlyRecognizedBarcode](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/spark-scan-session.html#property-scandit.datacapture.barcode.spark.SparkScanSession.NewlyRecognizedBarcode). @@ -123,21 +121,22 @@ sparkScan.addListener(this); Note that this list only contains one barcode entry. ::: -```java -@Override -public void onBarcodeScanned( - @NonNull SparkScan sparkScan, @NonNull SparkScanSession session, @Nullable FrameData data -) { +```kotlin +override fun onBarcodeScanned( + sparkScan: SparkScan, + session: SparkScanSession, + data: FrameData?, +){ // Gather the recognized barcode - Barcode barcode = session.getNewlyRecognizedBarcode(); + val barcode = session.newlyRecognizedBarcode // This method is invoked from a recognition internal thread. // Run the specified action in the UI thread to update the internal barcode list. - runOnUiThread(() -> { + runOnUiThread { // Update the internal list and the UI with the barcode retrieved above - this.latestBarcode = barcode; - }); -} + this.latestBarcode = barcode + } + } ``` ## Scan Some Barcodes From e680b71716522e4c117d8106432a4cab72f70152 Mon Sep 17 00:00:00 2001 From: Juan Antonio Romero <133760645+JuanRomero-Scandit@users.noreply.github.com> Date: Mon, 23 Feb 2026 06:49:16 +0100 Subject: [PATCH 2/2] MR fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Benoît Vermont --- docs/sdks/android/label-capture/get-started.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/sdks/android/label-capture/get-started.md b/docs/sdks/android/label-capture/get-started.md index de24a628..ec8debd8 100644 --- a/docs/sdks/android/label-capture/get-started.md +++ b/docs/sdks/android/label-capture/get-started.md @@ -329,9 +329,9 @@ Next, you need to create a new instance of the [Camera](https://docs.scandit.com When initializing the camera, you can pass the recommended camera settings for Label Capture. ```kotlin -val camera = Camera.getDefaultCamera(LabelCapture.createRecommendedCameraSettings()); +val camera = Camera.getDefaultCamera(LabelCapture.createRecommendedCameraSettings()) if (camera == null) { - throw IllegalStateException("Failed to init camera!"); + throw IllegalStateException("Failed to init camera!") } dataCaptureContext.setFrameSource(camera) ```