Skip to content

Commit 5db56ee

Browse files
Migrate snippets
1 parent 73f8d5e commit 5db56ee

22 files changed

Lines changed: 694 additions & 792 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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.
22

3-
```java
4-
DataCaptureContext dataCaptureContext = DataCaptureContext.forLicenseKey("-- ENTER YOUR SCANDIT LICENSE KEY HERE --");
3+
```kotlin
4+
val dataCaptureContext = DataCaptureContext.forLicenseKey("-- ENTER YOUR SCANDIT LICENSE KEY HERE --")
55
```

docs/sdks/android/add-sdk.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,4 @@ Check [the official provider documentation](https://developer.android.com/guide/
149149

150150
import OSSLicense from '../../partials/_third-party-licenses.mdx';
151151

152-
<OSSLicense/>
152+
<OSSLicense/>

docs/sdks/android/barcode-capture/configure-barcode-symbologies.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import EnableSymbologies from '../../../partials/configure-symbologies/_enable-s
2121

2222
The following code shows how to enable scanning Code 128 codes for Barcode Capture:
2323

24-
```java
25-
BarcodeCaptureSettings settings = new BarcodeCaptureSettings();
26-
settings.enableSymbology(Symbology.CODE128, true);
24+
```kotlin
25+
val settings = BarcodeCaptureSettings()
26+
settings.enableSymbology(Symbology.CODE128, true)
2727
```
2828

2929
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
4040

4141
The below code shows how to change the active symbol count for Code 128 to read codes with 6, 7 and 8 symbols.
4242

43-
```java
44-
BarcodeCaptureSettings settings = new BarcodeCaptureSettings();
45-
SymbologySettings symbologySettings = settings.getSymbologySettings(Symbology.CODE128);
46-
HashSet<Short> activeSymbolCounts = new HashSet<>(Arrays.asList(new Short[] { 6, 7, 8}));
47-
symbologySettings.setActiveSymbolCounts(activeSymbolCounts);
43+
```kotlin
44+
val settings = BarcodeCaptureSettings()
45+
val symbologySettings = settings.getSymbologySettings(Symbology.CODE128)
46+
val activeSymbolCounts = mutableSetOf<Short>(6, 7, 8)
47+
symbologySettings.activeSymbolCounts = activeSymbolCounts
4848
```
4949

5050
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
6161

6262
The following code shows how to enable color-inverted reading for Code 128:
6363

64-
```java
65-
BarcodeCaptureSettings settings = new BarcodeCaptureSettings();
66-
SymbologySettings symbologySettings = settings.getSymbologySettings(Symbology.CODE128);
67-
symbologySettings.setColorInvertedEnabled(true);
64+
```kotlin
65+
val settings = BarcodeCaptureSettings()
66+
val symbologySettings = settings.getSymbologySettings(Symbology.CODE128)
67+
symbologySettings.isColorInvertedEnabled = true
6868
```
6969

7070
## Enforce Checksums
@@ -75,10 +75,10 @@ When enabling a checksum you have to make sure that the data of your codes conta
7575

7676
You can enforce a specific checksum by setting it through `SymbologySettings.checksums`:
7777

78-
```java
79-
BarcodeCaptureSettings settings = new BarcodeCaptureSettings();
80-
SymbologySettings symbologySettings = settings.getSymbologySettings(Symbology.CODE39);
81-
symbologySettings.setChecksums(EnumSet.of(Checksum.MOD43));
78+
```kotlin
79+
val settings = BarcodeCaptureSettings()
80+
val symbologySettings = settings.getSymbologySettings(Symbology.CODE39)
81+
symbologySettings.checksums = setOf(Checksum.MOD43)
8282
```
8383

8484
## Enable Symbology-Specific Extensions
@@ -91,10 +91,10 @@ To enable/disable a symbology extension, use `SymbologySettings.setExtensionEnab
9191

9292
The following code shows how to enable the full ASCII extension for Code 39.
9393

94-
```java
95-
BarcodeCaptureSettings settings = new BarcodeCaptureSettings();
96-
SymbologySettings symbologySettings = settings.getSymbologySettings(Symbology.CODE39);
97-
symbologySettings.setExtensionEnabled("full_ascii", true);
94+
```kotlin
95+
val settings = BarcodeCaptureSettings()
96+
val symbologySettings = settings.getSymbologySettings(Symbology.CODE39)
97+
symbologySettings.setExtensionEnabled("full_ascii", true)
9898
```
9999

100100
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.

docs/sdks/android/barcode-capture/get-started.md

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@ Barcode scanning is orchestrated by the [BarcodeCapture data capture mode](https
5656

5757
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).
5858

59-
```java
60-
BarcodeCaptureSettings settings = new BarcodeCaptureSettings();
61-
settings.enableSymbology(Symbology.CODE128, true);
62-
settings.enableSymbology(Symbology.CODE39, true);
63-
settings.enableSymbology(Symbology.QR, true);
64-
settings.enableSymbology(Symbology.EAN8, true);
65-
settings.enableSymbology(Symbology.UPCE, true);
66-
settings.enableSymbology(Symbology.EAN13_UPCA, true);
59+
```kotlin
60+
val settings = BarcodeCaptureSettings().apply {
61+
enableSymbology(Symbology.CODE128, true)
62+
enableSymbology(Symbology.CODE39, true)
63+
enableSymbology(Symbology.QR, true)
64+
enableSymbology(Symbology.EAN8, true)
65+
enableSymbology(Symbology.UPCE, true)
66+
enableSymbology(Symbology.EAN13_UPCA, true)
67+
}
6768
```
6869

6970
:::note
@@ -72,8 +73,8 @@ If you are not disabling barcode capture immediately after having scanned the fi
7273

7374
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:
7475

75-
```java
76-
barcodeCapture = BarcodeCapture.forDataCaptureContext(dataCaptureContext, settings);
76+
```kotlin
77+
barcodeCapture = BarcodeCapture.forDataCaptureContext(dataCaptureContext, settings)
7778
```
7879

7980
## Register the Barcode Capture Listener
@@ -82,22 +83,21 @@ To get informed whenever a new code has been recognized, add a [BarcodeCaptureLi
8283

8384
First conform to the `BarcodeCaptureListener` interface. For example:
8485

85-
```java
86-
@Override
87-
public void onBarcodeScanned(
88-
@NonNull BarcodeCapture barcodeCapture,
89-
@NonNull BarcodeCaptureSession session,
90-
@NonNull FrameData frameData
86+
```kotlin
87+
override fun onBarcodeScanned(
88+
barcodeCapture: BarcodeCapture,
89+
session: BarcodeCaptureSession,
90+
frameData: FrameData
9191
) {
92-
Barcode recognizedBarcode = session.getNewlyRecognizedBarcode();
92+
val recognizedBarcodes = session.newlyRecognizedBarcode
9393
// Do something with the barcodes. See Rejecting Barcodes, below, for an example.
9494
}
9595
```
9696

9797
Then add the listener:
9898

99-
```java
100-
barcodeCapture.addListener(this);
99+
```kotlin
100+
barcodeCapture.addListener(this)
101101
```
102102

103103
### Rejecting Barcodes
@@ -106,11 +106,11 @@ To prevent scanning unwanted codes, you can reject them by adding the desired lo
106106

107107
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:
108108

109-
```java
109+
```kotlin
110110
...
111-
if (barcode.getData() == null || !barcode.getData().startsWith("09:")) {
112-
overlay.setBrush(Brush.transparent());
113-
return;
111+
if (barcode.data == null || !barcode.data.startsWith("09:")) {
112+
overlay.brush = Brush.transparent()
113+
return
114114
}
115115
...
116116
```
@@ -125,30 +125,25 @@ In Android, the user must explicitly grant permission for each app to access cam
125125

126126
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:
127127

128-
```java
129-
CameraSettings cameraSettings = BarcodeCapture.createRecommendedCameraSettings();
128+
```kotlin
129+
val cameraSettings = BarcodeCapture.createRecommendedCameraSettings()
130130

131131
// Depending on the use case further camera settings adjustments can be made here.
132132

133-
Camera camera = Camera.getDefaultCamera();
134-
135-
if (camera != null) {
136-
camera.applySettings(cameraSettings);
137-
}
133+
val camera = Camera.getDefaultCamera()
134+
camera?.applySettings(cameraSettings)
138135
```
139136

140137
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)
141138

142-
```java
143-
dataCaptureContext.setFrameSource(camera);
139+
```kotlin
140+
dataCaptureContext.frameSource = camera
144141
```
145142

146143
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):
147144

148-
```java
149-
if (camera != null) {
150-
camera.switchToDesiredState(FrameSourceState.ON);
151-
}
145+
```kotlin
146+
camera?.switchToDesiredState(FrameSourceState.ON)
152147
```
153148

154149
:::note
@@ -161,15 +156,15 @@ When using the built-in camera as frame source, you may want to display the came
161156

162157
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:
163158

164-
```java
165-
DataCaptureView dataCaptureView = DataCaptureView.newInstance(this, dataCaptureContext);
166-
setContentView(dataCaptureView);
159+
```kotlin
160+
val dataCaptureView = DataCaptureView.newInstance(this, dataCaptureContext)
161+
setContentView(dataCaptureView)
167162
```
168163

169164
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:
170165

171-
```java
172-
BarcodeCaptureOverlay overlay = BarcodeCaptureOverlay.newInstance(barcodeCapture, dataCaptureView);
166+
```kotlin
167+
val overlay = BarcodeCaptureOverlay.newInstance(barcodeCapture, dataCaptureView)
173168
```
174169

175170
## Disabling Barcode Capture

docs/sdks/android/barcode-generator.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,23 @@ With the context you can then instantiate a [`BarcodeGeneratorBuilder`](https://
3737

3838
You can configure the colors used in the resulting image:
3939

40-
```java
41-
DataCaptureContext dataCaptureContext = DataCaptureContext.forLicenseKey(licenseKey);
42-
BarcodeGenerator.Code128BarcodeGeneratorBuilder builder = BarcodeGenerator.code128BarcodeGeneratorBuilder(dataCaptureContext)
40+
```kotlin
41+
val dataCaptureContext = DataCaptureContext.forLicenseKey(licenseKey)
42+
val builder = BarcodeGenerator.code128BarcodeGeneratorBuilder(dataCaptureContext)
4343
.withBackgroundColor(Color.WHITE)
44-
.withForegroundColor(Color.BLACK);
44+
.withForegroundColor(Color.BLACK)
4545
```
4646

4747
When the builder is configured get the `BarcodeGenerator` and try to generate the image:
4848

49-
```java
49+
```kotlin
5050
try {
51-
BarcodeGenerator generator = builder.build();
52-
Bitmap image = generator.generate(dataString, 200);
51+
val generator = builder.build()
52+
val image = generator.generate(dataString, 200)
5353
// Use the image
54-
} catch (Exception exception) {
54+
} catch (exception: Exception) {
5555
// Handle the error
56-
exception.printStackTrace();
56+
exception.printStackTrace()
5757
}
5858
```
5959

@@ -67,26 +67,26 @@ With the context you can then instantiate a [`QRCodeBarcodeGeneratorBuilder`](ht
6767

6868
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).
6969

70-
```java
71-
DataCaptureContext dataCaptureContext = DataCaptureContext.forLicenseKey(licenseKey);
72-
BarcodeGenerator.QrCodeBarcodeGeneratorBuilder builder = new BarcodeGenerator.QrCodeBarcodeGeneratorBuilder(dataCaptureContext)
70+
```kotlin
71+
val dataCaptureContext = DataCaptureContext.forLicenseKey(licenseKey)
72+
val builder = BarcodeGenerator.QrCodeBarcodeGeneratorBuilder(dataCaptureContext)
7373
.withBackgroundColor(Color.WHITE)
7474
.withForegroundColor(Color.BLACK)
7575
.withErrorCorrectionLevel(QrCodeErrorCorrectionLevel.MEDIUM)
76-
.withVersionNumber(4);
76+
.withVersionNumber(4)
7777
```
7878

7979
When the builder is configured get the `BarcodeGenerator` and try to generate the image:
8080

81-
```java
81+
```kotlin
8282
try {
83-
BarcodeGenerator generator = builder.build();
84-
Bitmap image = generator.generate(dataString, 200);
83+
val generator = builder.build()
84+
val image = generator.generate(dataString, 200)
8585
// Use the image
86-
} catch (Exception exception) {
86+
} catch (exception: Exception) {
8787
// Handle the error
88-
exception.printStackTrace();
88+
exception.printStackTrace()
8989
}
9090
```
9191

92-
See the complete [API reference](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/barcode-generator.html) for more information.
92+
See the complete [API reference](https://docs.scandit.com/data-capture-sdk/android/barcode-capture/api/barcode-generator.html) for more information.

0 commit comments

Comments
 (0)