Skip to content

Commit 5d6d860

Browse files
update to internal commit 39cf79eb
1 parent 0121c49 commit 5d6d860

File tree

5 files changed

+123
-77
lines changed

5 files changed

+123
-77
lines changed

programming/android/api-reference/barcode-scanner/barcode-scanner-config.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class BarcodeScannerConfig
3030
| [`setTemplateFilePath`](#settemplatefilepath) | Sets the parameters template for the Barcode Reader via a local JSON file path. |
3131
| [`setBarcodeFormats`](#setbarcodeformats) | Sets the barcode format(s) to read. |
3232
| [`setScanRegion`](#setscanregion) | Sets a scan region where only the barcodes located in the scan region can be decoded. |
33-
| [`setTorchButtonVisible`](#settorchbuttonvisible) | Sets whether to display the torch button when scanning or not. Uses can click the torch button to turn on/off the torch. |
33+
| [`setTorchButtonVisible`](#settorchbuttonvisible) | Sets whether to display the torch button when scanning or not. |
3434
| [`setBeepEnabled`](#setbeepenabled) | Sets whether to trigger a beep sound when a barcode is detected. |
3535
| [`setScanLaserVisible`](#setscanlaservisible) | Sets whether to display a scan laser when scanning. |
3636
| [`setAutoZoomEnabled`](#setautozoomenabled) | Sets whether to enable the auto-zoom feature when scanning. |
@@ -95,7 +95,7 @@ void setScanRegion(DSRect scanRegion);
9595

9696
### setTorchButtonVisible
9797

98-
Sets whether to display the torch button when scanning. Uses can click the torch button to turn on/off the torch.
98+
Sets whether to display the torch button when scanning. User can click the torch button to turn on/off the torch.
9999

100100
```java
101101
void setTorchButtonVisible(boolean torchButtonVisible);
@@ -191,7 +191,7 @@ A combined value of [`EnumBarcodeFormat`]({{ site.dcvb_enumerations }}barcode-re
191191

192192
### getScanRegion
193193

194-
Get the scan region.
194+
Returns the scan region.
195195

196196
```java
197197
DSRect getScanRegion();

programming/android/user-guide.md

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,37 @@ The first thing that we are going to do is to create a fresh new project. Here a
108108

109109
Add the SDK to your new project. Please read [Add the SDK](#add-the-sdk) section for more details.
110110

111-
## Step 3: Initialize the License
111+
## Step 3: Get Prepare for the Layout File
112+
113+
Open your **activity_main.xml** and replace it with the following code. In the layout file, we prepared 2 UI elements:
114+
115+
- A "Start Scanning" button for opening the scanner view.
116+
- A `TextView` for displaying the barcode decoding result.
117+
118+
```xml
119+
<?xml version="1.0" encoding="utf-8"?>
120+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
121+
android:layout_width="match_parent"
122+
android:layout_height="match_parent"
123+
android:gravity="center"
124+
android:orientation="vertical">
125+
126+
<Button
127+
android:id="@+id/btn_navigate"
128+
android:layout_width="wrap_content"
129+
android:layout_height="wrap_content"
130+
android:text="Start Scanning" />
131+
132+
<TextView
133+
android:id="@+id/tv_result"
134+
android:layout_width="wrap_content"
135+
android:layout_height="wrap_content"
136+
android:textSize="20sp"
137+
android:text=""/>
138+
</LinearLayout>
139+
```
140+
141+
## Step 4: Initialize the License
112142

113143
The first step in code configuration is to include a valid license in the `BarcodeScannerConfig` object, which is used when launching the scanner.
114144

@@ -173,7 +203,7 @@ class MainActivity : AppCompatActivity() {
173203
>- You can request a 30-day trial license via the [Request a Trial License](https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=guide&package=ios){:target="_blank"} link.
174204
>- If you download the <a href="https://www.dynamsoft.com/barcode-reader/downloads/?utm_source=docs#mobile" target="_blank">Installation Package</a>, it comes with a 30-day trial license by default.
175205
176-
## Step 4: Implementing the Barcode Scanner
206+
## Step 5: Implementing the Barcode Scanner
177207

178208
Now that the Barcode Scanner is configured and the license has been set, it is time to implement the actions (via the `launcher`) to take when a barcode is scanned. Once the launcher is called, the Barcode Scanner opens the camera and begins the decoding process.
179209

@@ -234,33 +264,6 @@ class MainActivity : AppCompatActivity() {
234264
}
235265
```
236266

237-
## Step 5: Configure your layout file
238-
239-
Open your **activity_main.xml** and replace it with the following code:
240-
241-
```xml
242-
<?xml version="1.0" encoding="utf-8"?>
243-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
244-
android:layout_width="match_parent"
245-
android:layout_height="match_parent"
246-
android:gravity="center"
247-
android:orientation="vertical">
248-
249-
<Button
250-
android:id="@+id/btn_navigate"
251-
android:layout_width="wrap_content"
252-
android:layout_height="wrap_content"
253-
android:text="Start Scanning" />
254-
255-
<TextView
256-
android:id="@+id/tv_result"
257-
android:layout_width="wrap_content"
258-
android:layout_height="wrap_content"
259-
android:textSize="20sp"
260-
android:text=""/>
261-
</LinearLayout>
262-
```
263-
264267
## Step 6: Configure the Barcode Scanner (optional)
265268

266269
This next step, although optional, is highly recommended to help achieve a more smooth-looking and intuitive UI. In this setup we will configure the visibility of the torch button as well as the close button. In addition, a scan region will be defined that will limit the reading region of the Barcode Scanner to the specified dimensions. To do this, we are going back to the `BarcodeScannerConfig` object we used to define the license, and will make use of some of the other parameters available in the `BarcodeScannerConfig` class.
@@ -271,6 +274,7 @@ This next step, although optional, is highly recommended to help achieve a more
271274
>
272275
>1.
273276
```java
277+
import com.dynamsoft.dbr.EnumBarcodeFormat
274278
public class MainActivity extends AppCompatActivity {
275279
private ActivityResultLauncher<BarcodeScannerConfig> launcher;
276280
@Override
@@ -298,6 +302,7 @@ public class MainActivity extends AppCompatActivity {
298302
```
299303
2.
300304
```kotlin
305+
import com.dynamsoft.dbr.EnumBarcodeFormat
301306
class MainActivity : AppCompatActivity() {
302307
private lateinit var launcher: ActivityResultLauncher<BarcodeScannerConfig>
303308
override fun onCreate(savedInstanceState: Bundle?) {

programming/objectivec-swift/api-reference/barcode-scanner/barcode-scanner-config.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ breadcrumbText: BarcodeScannerConfig
2929
class BarcodeScannerConfig : NSObject
3030
```
3131

32-
## Methods
33-
34-
| Method | Description |
35-
| ------ | ----------- |
36-
| [`license`](#license) | Sets or returns the license key for the Barcode Reader. |
37-
| [`templateFilePath`](#templatefilepath) | Sets or returns the local JSON file path that will configure the parameters template for the Barcode Reader. |
38-
| [`barcodeFormats`](#barcodeformats) | Sets or returns the barcode format(s) to read. |
39-
| [`scanRegion`](#scanregion) | Sets or returns the scan region where only the barcodes located in the scan region can be decoded. |
40-
| [`isTorchButtonVisible`](#istorchbuttonvisible) | Sets or returns whether or not the torch button is visible. |
41-
| [`isBeepEnabled`](#isbeepenabled) | Sets or returns whether the beep sound is enabled when a barcode is found. |
42-
| [`isScanLaserVisible`](#isscanlaservisible) | Sets or returns whether or not the scan laser is visible. |
43-
| [`isAutoZoomEnabled`](#isautozoomenabled) | Sets or returns whether or not the auto-zoom feature of the Camera Enhancer is enabled. |
44-
| [`isCloseButtonVisible`](#isclosebuttonvisible) | Sets or returns whether or not the close button is visible. |
32+
## Properties
33+
34+
| Property | Type | Description |
35+
| -------- | ---- | ----------- |
36+
| [`license`](#license) | *NSString \** | Sets or returns the license key for the Barcode Reader. |
37+
| [`templateFilePath`](#templatefilepath) | *NSString \** | Sets or returns the local JSON file path that will configure the parameters template for the Barcode Reader. |
38+
| [`barcodeFormats`](#barcodeformats) | *DSBarcodeFormat* | Sets or returns the barcode format(s) to read. |
39+
| [`scanRegion`](#scanregion) | *DSRect \** | Sets or returns the scan region where only the barcodes located in the scan region can be decoded. |
40+
| [`isTorchButtonVisible`](#istorchbuttonvisible) | *BOOL* | Sets or returns whether or not the torch button is visible. |
41+
| [`isBeepEnabled`](#isbeepenabled) | *BOOL* | Sets or returns whether the beep sound is enabled when a barcode is found. |
42+
| [`isScanLaserVisible`](#isscanlaservisible) | *BOOL* | Sets or returns whether or not the scan laser is visible. |
43+
| [`isAutoZoomEnabled`](#isautozoomenabled) | *BOOL* | Sets or returns whether or not the auto-zoom feature of the Camera Enhancer is enabled. |
44+
| [`isCloseButtonVisible`](#isclosebuttonvisible) | *BOOL* | Sets or returns whether or not the close button is visible. |
4545

4646
### license
4747

@@ -121,7 +121,7 @@ var scanRegion: DSRect { get set }
121121

122122
### isTorchButtonVisible
123123

124-
Sets or returns a boolean indicating whether or not the torch button is visible.
124+
Sets or returns a boolean indicating whether or not the torch button is visible. User can click the torch button to turn on/off the torch.
125125

126126
<div class="sample-code-prefix"></div>
127127
>- Objective-C

programming/objectivec-swift/api-reference/barcode-scanner/barcode-scanner-view-controller.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,47 @@ breadcrumbText: BarcodeScannerViewController
2929
class BarcodeScannerViewController: UIViewController
3030
```
3131

32+
## Properties
33+
34+
| Property | Type | Description |
35+
| -------- | ---- | ----------- |
36+
| [`config`](#config) | *DSBarcodeScannerConfig \** | Sets or returns the barcode scanner configurations. |
37+
| [`onScannedResult`](#onscannedresult) | *void (^)(DSMRZScanResult *)* | A property that holds a Block. The block is a callback that takes a single parameter of type `DSMRZScanResult` and returns no value. |
38+
39+
### config
40+
41+
Sets or returns the barcode scanner configurations of type [`DSMRZScannerConfig`](barcode-scanner-config.md).
42+
43+
<div class="sample-code-prefix"></div>
44+
>- Objective-C
45+
>- Swift
46+
>
47+
>1.
48+
```objc
49+
@property (nonatomic, strong, readwrite) DSMRZScannerConfig * config
50+
```
51+
1.
52+
```swift
53+
var config: BarcodeScannerConfig = .init()
54+
```
55+
56+
### onScannedResult
57+
58+
A property that holds a Block. The block is a callback that takes a single parameter of type [`DSMRZScanResult`](barcode-scan-result.md) and returns no value.
59+
60+
<div class="sample-code-prefix"></div>
61+
>- Objective-C
62+
>- Swift
63+
>
64+
>1.
65+
```objc
66+
@property (nonatomic, copy, readwrite) void (^)(DSMRZScanResult *) onScannedResult
67+
```
68+
1.
69+
```swift
70+
var onScannedResult: ((BarcodeScanResult) -> Void)?
71+
```
72+
3273
## How to Use
3374

3475
<div class="sample-code-prefix"></div>

programming/objectivec-swift/user-guide.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ The first major step in code configuration is to include a valid license in the
172172
setup()
173173
}
174174
@objc func buttonTapped() {
175-
let vc = BarcodeScannerViewController()
176-
let config = BarcodeScannerConfig()
177-
config.license = "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9"
178-
vc.config = config
175+
let vc = BarcodeScannerViewController()
176+
let config = BarcodeScannerConfig()
177+
config.license = "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9"
178+
vc.config = config
179179
}
180180
func setup() {
181181
button.backgroundColor = .black
@@ -240,27 +240,27 @@ Each result comes with a `DSResultStatus` that can be one of *finished*, *cancel
240240
vc.onScannedResult = ^(DSBarcodeScanResult *result) {
241241
switch (result.resultStatus) {
242242
case DSResultStatusFinished: {
243-
dispatch_async(dispatch_get_main_queue(), ^{
244-
NSString *format = result.barcodes.firstObject.formatString ?: @"";
245-
NSString *text = result.barcodes.firstObject.text ?: @"";
246-
weakSelf.label.text = [NSString stringWithFormat:@"Result:\nFormat: %@\nText: %@", format, text];
247-
});
248-
break;
243+
dispatch_async(dispatch_get_main_queue(), ^{
244+
NSString *format = result.barcodes.firstObject.formatString ?: @"";
245+
NSString *text = result.barcodes.firstObject.text ?: @"";
246+
weakSelf.label.text = [NSString stringWithFormat:@"Result:\nFormat: %@\nText: %@", format, text];
247+
});
248+
break;
249249
}
250250
case DSResultStatusCanceled: {
251-
dispatch_async(dispatch_get_main_queue(), ^{
252-
weakSelf.label.text = @"Scan canceled";
253-
});
254-
break;
251+
dispatch_async(dispatch_get_main_queue(), ^{
252+
weakSelf.label.text = @"Scan canceled";
253+
});
254+
break;
255255
}
256256
case DSResultStatusException: {
257-
dispatch_async(dispatch_get_main_queue(), ^{
258-
weakSelf.label.text = result.errorString;
259-
});
260-
break;
257+
dispatch_async(dispatch_get_main_queue(), ^{
258+
weakSelf.label.text = result.errorString;
259+
});
260+
break;
261261
}
262262
default:
263-
break;
263+
break;
264264
}
265265
dispatch_async(dispatch_get_main_queue(), ^{
266266
[weakSelf.navigationController popViewControllerAnimated:YES];
@@ -287,26 +287,26 @@ class ViewController: UIViewController {
287287
switch result.resultStatus {
288288
/* if the result is valid, display it in the label */
289289
case .finished:
290-
DispatchQueue.main.async {
291-
let format = result.barcodes?.first?.formatString ?? ""
292-
self.label.text = "Result:\nFormat: " + (format) + "\n" + "Text: " + (result.barcodes?.first?.text ?? "")
293-
}
290+
DispatchQueue.main.async {
291+
let format = result.barcodes?.first?.formatString ?? ""
292+
self.label.text = "Result:\nFormat: " + (format) + "\n" + "Text: " + (result.barcodes?.first?.text ?? "")
293+
}
294294
/* if the scan operation is canceled by the user */
295295
case .canceled:
296-
DispatchQueue.main.async {
297-
self.label.text = "Scan canceled"
298-
}
296+
DispatchQueue.main.async {
297+
self.label.text = "Scan canceled"
298+
}
299299
/* if an error occurs during capture, display the error string in the label */
300300
case .exception:
301-
DispatchQueue.main.async {
302-
self.label.text = result.errorString
303-
}
301+
DispatchQueue.main.async {
302+
self.label.text = result.errorString
303+
}
304304
@unknown default:
305-
break
305+
break
306306
}
307307
/* return back to the home page to display the result/cancel message/error string */
308308
DispatchQueue.main.async {
309-
self.navigationController?.popViewController(animated: true)
309+
self.navigationController?.popViewController(animated: true)
310310
}
311311
}
312312
/* when the button is clicked, hide the navigation bar and push the newly created BarcodeScannerViewController to the main view */

0 commit comments

Comments
 (0)