react-native-scanbot-barcode-scanner-sdk 3.2.1-beta3 → 3.2.1-beta4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ObjectMapper.java +22 -6
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ScanbotBarcodeSdkModule.java +46 -68
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/barcode/ScanbotBarcodeDetectorAdditionalConfigBuilder.java +36 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/barcode/ScanbotBarcodeDetectorConfigBuilder.java +45 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraViewFragment.java +23 -28
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraViewManager.java +1 -1
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/filters/ReactBarcodeExtensionsFilter.java +59 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/BitmapHelper.java +30 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/JSONUtils.java +286 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/LogUtils.java +40 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/ResponseUtils.java +41 -0
- package/ios/ScanbotBarcodeSdk.m +33 -41
- package/ios/Utils/BarcodeMapping.h +50 -13
- package/package.json +1 -1
|
@@ -21,6 +21,14 @@ public final class ObjectMapper {
|
|
|
21
21
|
|
|
22
22
|
private static Map<String, Map<String, String>> enumMappings;
|
|
23
23
|
|
|
24
|
+
/*
|
|
25
|
+
* Properties listed here will be skipped by the Object Mapper
|
|
26
|
+
*/
|
|
27
|
+
private final static String[] kIgnoredProperties = new String[] {
|
|
28
|
+
"engineMode",
|
|
29
|
+
"barcodeFilter"
|
|
30
|
+
};
|
|
31
|
+
|
|
24
32
|
public static void map(ReadableMap source, Object target)
|
|
25
33
|
throws IllegalAccessException, InvocationTargetException {
|
|
26
34
|
map(source.toHashMap(), target);
|
|
@@ -30,7 +38,7 @@ public final class ObjectMapper {
|
|
|
30
38
|
ObjectMapper.enumMappings = enumMappings;
|
|
31
39
|
}
|
|
32
40
|
|
|
33
|
-
@SuppressWarnings("unchecked")
|
|
41
|
+
@SuppressWarnings({"unchecked", "SuspiciousMethodCalls", "rawtypes", "ConstantConditions"})
|
|
34
42
|
private static void map(final Map<String, Object> source, final Object target)
|
|
35
43
|
throws IllegalAccessException, InvocationTargetException {
|
|
36
44
|
final Class cls = target.getClass();
|
|
@@ -59,11 +67,7 @@ public final class ObjectMapper {
|
|
|
59
67
|
continue;
|
|
60
68
|
}
|
|
61
69
|
|
|
62
|
-
if (
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if ("barcodeFilter".equals(prop)) {
|
|
70
|
+
if (shouldIgnoreProperty(prop)) {
|
|
67
71
|
continue;
|
|
68
72
|
}
|
|
69
73
|
|
|
@@ -104,10 +108,13 @@ public final class ObjectMapper {
|
|
|
104
108
|
if (setterName.contains("Color")) {
|
|
105
109
|
value = Color.parseColor((String) value);
|
|
106
110
|
} else if (paramType == int.class) {
|
|
111
|
+
assert value instanceof Number;
|
|
107
112
|
value = ((Number)value).intValue();
|
|
108
113
|
} else if (paramType == float.class) {
|
|
114
|
+
assert value instanceof Number;
|
|
109
115
|
value = ((Number) value).floatValue();
|
|
110
116
|
} else if (paramType == double.class) {
|
|
117
|
+
assert value instanceof Number;
|
|
111
118
|
value = ((Number) value).doubleValue();
|
|
112
119
|
} else if (paramType.isEnum()) {
|
|
113
120
|
value = Enum.valueOf(paramType, (String) value);
|
|
@@ -118,4 +125,13 @@ public final class ObjectMapper {
|
|
|
118
125
|
}
|
|
119
126
|
}
|
|
120
127
|
}
|
|
128
|
+
|
|
129
|
+
private static boolean shouldIgnoreProperty(final String propertyKey) {
|
|
130
|
+
for(String property: kIgnoredProperties) {
|
|
131
|
+
if (property.equals(propertyKey)) {
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
121
137
|
}
|
package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ScanbotBarcodeSdkModule.java
CHANGED
|
@@ -29,33 +29,34 @@ import java.io.File;
|
|
|
29
29
|
import java.io.IOException;
|
|
30
30
|
import java.util.ArrayList;
|
|
31
31
|
import java.util.HashMap;
|
|
32
|
+
import java.util.List;
|
|
32
33
|
import java.util.Map;
|
|
33
34
|
import java.util.concurrent.ExecutorService;
|
|
34
35
|
import java.util.concurrent.Executors;
|
|
35
36
|
|
|
37
|
+
import io.scanbot.barcodesdk.plugin.reactnative.barcode.ScanbotBarcodeDetectorConfigBuilder;
|
|
38
|
+
import io.scanbot.barcodesdk.plugin.reactnative.utils.JSONUtils;
|
|
39
|
+
import io.scanbot.barcodesdk.plugin.reactnative.utils.LogUtils;
|
|
40
|
+
import io.scanbot.barcodesdk.plugin.reactnative.utils.ResponseUtils;
|
|
36
41
|
import io.scanbot.sap.SdkLicenseInfo;
|
|
37
42
|
import io.scanbot.sdk.barcode.ScanbotBarcodeDetector;
|
|
38
43
|
import io.scanbot.sdk.barcode.entity.BarcodeDocumentFormat;
|
|
39
44
|
import io.scanbot.sdk.barcode.entity.BarcodeFormat;
|
|
40
45
|
import io.scanbot.sdk.barcode.entity.BarcodeItem;
|
|
41
|
-
import io.scanbot.sdk.barcode.entity.BarcodeScannerAdditionalConfigBuilder;
|
|
42
|
-
import io.scanbot.sdk.barcode.entity.BarcodeScannerConfigBuilder;
|
|
43
46
|
import io.scanbot.sdk.barcode.entity.BarcodeScanningResult;
|
|
47
|
+
import io.scanbot.sdk.barcode.entity.EngineMode;
|
|
44
48
|
import io.scanbot.sdk.barcode_scanner.ScanbotBarcodeScannerSDK;
|
|
45
49
|
import io.scanbot.sdk.barcode_scanner.ScanbotBarcodeScannerSDKInitializer;
|
|
46
50
|
import io.scanbot.sdk.ui.barcode_scanner.view.barcode.BarcodeScannerActivity;
|
|
47
51
|
import io.scanbot.sdk.ui.barcode_scanner.view.barcode.batch.BatchBarcodeScannerActivity;
|
|
48
52
|
import io.scanbot.sdk.ui.view.barcode.batch.configuration.BatchBarcodeScannerConfiguration;
|
|
49
|
-
import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeExtensionsFilter;
|
|
50
53
|
import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeFilter;
|
|
51
54
|
import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeScannerAdditionalConfiguration;
|
|
52
55
|
import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeScannerConfiguration;
|
|
53
56
|
import io.scanbot.sdk.ui.view.base.configuration.CameraOrientationMode;
|
|
54
57
|
import kotlin.Unit;
|
|
55
|
-
import kotlin.jvm.functions.Function1;
|
|
56
58
|
|
|
57
59
|
import android.app.Activity;
|
|
58
|
-
import android.util.Log;
|
|
59
60
|
|
|
60
61
|
|
|
61
62
|
public class ScanbotBarcodeSdkModule extends ReactContextBaseJavaModule implements ActivityEventListener {
|
|
@@ -170,62 +171,37 @@ public class ScanbotBarcodeSdkModule extends ReactContextBaseJavaModule implemen
|
|
|
170
171
|
if (rejectIfUninitialized(promise)) {
|
|
171
172
|
return;
|
|
172
173
|
}
|
|
173
|
-
this.threadPool.execute(
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
String imageUri = options.getString("imageFileUri");
|
|
177
|
-
final ArrayList<BarcodeFormat> barcodeFormats = JSONUtils.extractBarcodeFormats(options);
|
|
178
|
-
final ArrayList<BarcodeDocumentFormat> barcodeDocumentFormats = JSONUtils.extractBarcodeDocumentFormats(options);
|
|
179
|
-
|
|
180
|
-
final Bitmap bitmap = MediaStore.Images.Media.getBitmap(getReactApplicationContext().getContentResolver(), Uri.parse(imageUri));
|
|
181
|
-
final ScanbotBarcodeScannerSDK sdk = new ScanbotBarcodeScannerSDK(getReactApplicationContext());
|
|
182
|
-
final ScanbotBarcodeDetector detector = sdk.createBarcodeDetector();
|
|
183
|
-
|
|
184
|
-
detector.modifyConfig(new Function1<BarcodeScannerConfigBuilder, Unit>() {
|
|
185
|
-
@Override
|
|
186
|
-
public Unit invoke(BarcodeScannerConfigBuilder barcodeScannerConfigBuilder) {
|
|
187
|
-
if (!barcodeFormats.isEmpty()) {
|
|
188
|
-
barcodeScannerConfigBuilder.setBarcodeFormats(barcodeFormats);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (!barcodeDocumentFormats.isEmpty()) {
|
|
192
|
-
barcodeScannerConfigBuilder.setAcceptedDocumentFormats(barcodeDocumentFormats);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// Additional Configuration
|
|
196
|
-
barcodeScannerConfigBuilder.modifyAdditionalConfig(new Function1<BarcodeScannerAdditionalConfigBuilder, Unit>() {
|
|
197
|
-
@Override
|
|
198
|
-
public Unit invoke(BarcodeScannerAdditionalConfigBuilder barcodeScannerAdditionalConfigBuilder) {
|
|
199
|
-
|
|
200
|
-
if (options.hasKey("minimumTextLength")) {
|
|
201
|
-
barcodeScannerAdditionalConfigBuilder.setMinimumTextLength(options.getInt("minimumTextLength"));
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (options.hasKey("maximumTextLength")) {
|
|
205
|
-
barcodeScannerAdditionalConfigBuilder.setMaximumTextLength(options.getInt("maximumTextLength"));
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (options.hasKey("minimum1DBarcodesQuietZone")) {
|
|
209
|
-
barcodeScannerAdditionalConfigBuilder.setMinimum1DQuietZoneSize(options.getInt("minimum1DBarcodesQuietZone"));
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return Unit.INSTANCE;
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
return Unit.INSTANCE;
|
|
217
|
-
}
|
|
218
|
-
});
|
|
174
|
+
this.threadPool.execute(() -> {
|
|
175
|
+
try {
|
|
176
|
+
final String imageUri = options.getString("imageFileUri");
|
|
219
177
|
|
|
220
|
-
|
|
178
|
+
final Bitmap bitmap = MediaStore.Images.Media.getBitmap(getReactApplicationContext().getContentResolver(), Uri.parse(imageUri));
|
|
179
|
+
final ScanbotBarcodeScannerSDK sdk = new ScanbotBarcodeScannerSDK(getReactApplicationContext());
|
|
221
180
|
|
|
222
|
-
|
|
223
|
-
jsonResult.putString("imageFileUri", imageUri);
|
|
224
|
-
promise.resolve(jsonResult);
|
|
181
|
+
final ScanbotBarcodeDetector detector = sdk.createBarcodeDetector();
|
|
225
182
|
|
|
226
|
-
|
|
227
|
-
|
|
183
|
+
detector.modifyConfig(new ScanbotBarcodeDetectorConfigBuilder(options));
|
|
184
|
+
|
|
185
|
+
final BarcodeScanningResult result = detector.detectFromBitmap(bitmap, 0);
|
|
186
|
+
WritableMap jsonResult;
|
|
187
|
+
|
|
188
|
+
final boolean shouldFilterBarcodes = options.hasKey("barcodeFilter");
|
|
189
|
+
if (shouldFilterBarcodes) {
|
|
190
|
+
final BarcodeFilter barcodeFilter = JSONUtils.extractBarcodeFilter(options);
|
|
191
|
+
if (barcodeFilter == null) {
|
|
192
|
+
throw new IllegalArgumentException("Invalid Barcode Filter specified in JSON configuration: " + options.getString("barcodeFilter"));
|
|
193
|
+
}
|
|
194
|
+
final List<BarcodeItem> barcodeItems = JSONUtils.getBarcodeItemsFromResultWithFilter(result, barcodeFilter);
|
|
195
|
+
jsonResult = jsonResultFromBarcodeScannerResult(barcodeItems);
|
|
196
|
+
} else {
|
|
197
|
+
jsonResult = jsonResultFromBarcodeScannerResult(result);
|
|
228
198
|
}
|
|
199
|
+
|
|
200
|
+
jsonResult.putString("imageFileUri", imageUri);
|
|
201
|
+
promise.resolve(jsonResult);
|
|
202
|
+
|
|
203
|
+
} catch (Exception ex) {
|
|
204
|
+
promise.reject(ex);
|
|
229
205
|
}
|
|
230
206
|
});
|
|
231
207
|
}
|
|
@@ -402,25 +378,27 @@ public class ScanbotBarcodeSdkModule extends ReactContextBaseJavaModule implemen
|
|
|
402
378
|
}
|
|
403
379
|
}
|
|
404
380
|
|
|
405
|
-
private static WritableMap jsonResultFromBarcodeScannerResult(
|
|
381
|
+
private static WritableMap jsonResultFromBarcodeScannerResult(List<BarcodeItem> barcodeItems) {
|
|
406
382
|
final WritableArray barcodes = Arguments.createArray();
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
barcode.putString("textWithExtension", barcodeItem.getTextWithExtension());
|
|
414
|
-
barcodes.pushMap(barcode);
|
|
415
|
-
}
|
|
383
|
+
for (BarcodeItem barcodeItem : barcodeItems) {
|
|
384
|
+
final WritableMap barcode = Arguments.createMap();
|
|
385
|
+
barcode.putString("type", barcodeItem.getBarcodeFormat().name());
|
|
386
|
+
barcode.putString("text", barcodeItem.getText());
|
|
387
|
+
barcode.putString("textWithExtension", barcodeItem.getTextWithExtension());
|
|
388
|
+
barcodes.pushMap(barcode);
|
|
416
389
|
}
|
|
417
|
-
|
|
418
390
|
final WritableMap result = Arguments.createMap();
|
|
419
391
|
result.putString("status", "OK");
|
|
420
392
|
result.putArray("barcodes", barcodes);
|
|
421
393
|
return result;
|
|
422
394
|
}
|
|
423
395
|
|
|
396
|
+
private static WritableMap jsonResultFromBarcodeScannerResult(BarcodeScanningResult barcodeResult) {
|
|
397
|
+
return jsonResultFromBarcodeScannerResult(
|
|
398
|
+
barcodeResult != null ? barcodeResult.getBarcodeItems() : new ArrayList<>()
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
|
|
424
402
|
@NotNull
|
|
425
403
|
@Contract(pure = true)
|
|
426
404
|
private static String descriptionFromLicenseStatus(@NotNull io.scanbot.sap.Status status) {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
package io.scanbot.barcodesdk.plugin.reactnative.barcode;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
4
|
+
|
|
5
|
+
import io.scanbot.barcodesdk.plugin.reactnative.utils.JSONUtils;
|
|
6
|
+
import io.scanbot.sdk.barcode.entity.BarcodeScannerAdditionalConfig;
|
|
7
|
+
import io.scanbot.sdk.barcode.entity.BarcodeScannerAdditionalConfigBuilder;
|
|
8
|
+
import kotlin.Unit;
|
|
9
|
+
import kotlin.jvm.functions.Function1;
|
|
10
|
+
|
|
11
|
+
class ScanbotBarcodeDetectorAdditionalConfigBuilder implements Function1<BarcodeScannerAdditionalConfigBuilder, Unit> {
|
|
12
|
+
|
|
13
|
+
final ReadableMap options;
|
|
14
|
+
|
|
15
|
+
public ScanbotBarcodeDetectorAdditionalConfigBuilder(final ReadableMap options) {
|
|
16
|
+
this.options = options;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@Override
|
|
20
|
+
public Unit invoke(BarcodeScannerAdditionalConfigBuilder builder) {
|
|
21
|
+
final BarcodeScannerAdditionalConfig config = JSONUtils.extractBarcodeScannerAdditionalConfig(options);
|
|
22
|
+
if (config == null) {
|
|
23
|
+
return Unit.INSTANCE;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
builder.setLowPowerMode(config.getLowPowerMode());
|
|
27
|
+
builder.setMinimumTextLength(config.getMinimumTextLength());
|
|
28
|
+
builder.setMaximumTextLength(config.getMaximumTextLength());
|
|
29
|
+
builder.setMinimum1DQuietZoneSize(config.getMinimum1DQuietZoneSize());
|
|
30
|
+
builder.setStripCheckDigits(config.getStripCheckDigits());
|
|
31
|
+
builder.setGs1DecodingEnabled(config.getGs1DecodingEnabled());
|
|
32
|
+
builder.setMsiPlesseyChecksumAlgorithms(config.getMsiPlesseyChecksumAlgorithms());
|
|
33
|
+
|
|
34
|
+
return Unit.INSTANCE;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
package io.scanbot.barcodesdk.plugin.reactnative.barcode;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
4
|
+
|
|
5
|
+
import java.util.ArrayList;
|
|
6
|
+
|
|
7
|
+
import io.scanbot.barcodesdk.plugin.reactnative.utils.JSONUtils;
|
|
8
|
+
import io.scanbot.sdk.barcode.entity.BarcodeDocumentFormat;
|
|
9
|
+
import io.scanbot.sdk.barcode.entity.BarcodeFormat;
|
|
10
|
+
import io.scanbot.sdk.barcode.entity.BarcodeScannerConfigBuilder;
|
|
11
|
+
import io.scanbot.sdk.barcode.entity.EngineMode;
|
|
12
|
+
import kotlin.Unit;
|
|
13
|
+
import kotlin.jvm.functions.Function1;
|
|
14
|
+
|
|
15
|
+
public class ScanbotBarcodeDetectorConfigBuilder implements Function1<BarcodeScannerConfigBuilder, Unit> {
|
|
16
|
+
|
|
17
|
+
final ReadableMap options;
|
|
18
|
+
|
|
19
|
+
public ScanbotBarcodeDetectorConfigBuilder(final ReadableMap options) {
|
|
20
|
+
this.options = options;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Override
|
|
24
|
+
public Unit invoke(BarcodeScannerConfigBuilder barcodeScannerConfigBuilder) {
|
|
25
|
+
final ArrayList<BarcodeFormat> barcodeFormats = JSONUtils.extractBarcodeFormats(options);
|
|
26
|
+
final ArrayList<BarcodeDocumentFormat> barcodeDocumentFormats = JSONUtils.extractBarcodeDocumentFormats(options);
|
|
27
|
+
|
|
28
|
+
if (!barcodeFormats.isEmpty()) {
|
|
29
|
+
barcodeScannerConfigBuilder.setBarcodeFormats(barcodeFormats);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!barcodeDocumentFormats.isEmpty()) {
|
|
33
|
+
barcodeScannerConfigBuilder.setAcceptedDocumentFormats(barcodeDocumentFormats);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Engine Mode
|
|
37
|
+
final EngineMode engineMode = JSONUtils.extractEngineMode(options);
|
|
38
|
+
barcodeScannerConfigBuilder.setEngineMode(engineMode);
|
|
39
|
+
|
|
40
|
+
// Additional Configuration
|
|
41
|
+
barcodeScannerConfigBuilder.modifyAdditionalConfig(new ScanbotBarcodeDetectorAdditionalConfigBuilder(options));
|
|
42
|
+
|
|
43
|
+
return Unit.INSTANCE;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -25,7 +25,8 @@ import org.jetbrains.annotations.NotNull;
|
|
|
25
25
|
import java.util.Collections;
|
|
26
26
|
import java.util.List;
|
|
27
27
|
|
|
28
|
-
import io.scanbot.barcodesdk.plugin.reactnative.
|
|
28
|
+
import io.scanbot.barcodesdk.plugin.reactnative.barcode.ScanbotBarcodeDetectorConfigBuilder;
|
|
29
|
+
import io.scanbot.barcodesdk.plugin.reactnative.utils.JSONUtils;
|
|
29
30
|
import io.scanbot.barcodesdk.plugin.reactnative.R;
|
|
30
31
|
import io.scanbot.barcodesdk.plugin.reactnative.components.EventEmitter;
|
|
31
32
|
import io.scanbot.barcodesdk.plugin.reactnative.components.common.ScanbotComponentFrameLayout;
|
|
@@ -133,34 +134,28 @@ public class ScanbotBarcodeCameraViewFragment extends Fragment implements Barcod
|
|
|
133
134
|
userDefinedCameraZoomFactor = configuration.getCameraZoomFactor();
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
|
-
barcodeDetector.modifyConfig(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
ab.setGs1DecodingEnabled(config.getGs1DecodingEnabled());
|
|
157
|
-
ab.setMinimum1DQuietZoneSize(config.getMinimum1DQuietZoneSize());
|
|
158
|
-
return Unit.INSTANCE;
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
return Unit.INSTANCE;
|
|
137
|
+
barcodeDetector.modifyConfig(b -> {
|
|
138
|
+
if(!configuration.barcodeFormats.isEmpty()) {
|
|
139
|
+
b.setBarcodeFormats(configuration.barcodeFormats);
|
|
140
|
+
}
|
|
141
|
+
if(!configuration.acceptedDocumentFormats.isEmpty()) {
|
|
142
|
+
b.setAcceptedDocumentFormats(configuration.acceptedDocumentFormats);
|
|
143
|
+
}
|
|
144
|
+
b.setEngineMode(configuration.engineMode);
|
|
145
|
+
|
|
146
|
+
if(configuration.additionalConfiguration != null) {
|
|
147
|
+
b.modifyAdditionalConfig(ab -> {
|
|
148
|
+
final BarcodeScannerAdditionalConfig config = configuration.additionalConfiguration;
|
|
149
|
+
ab.setMinimumTextLength(config.getMinimumTextLength());
|
|
150
|
+
ab.setMaximumTextLength(config.getMaximumTextLength());
|
|
151
|
+
ab.setMsiPlesseyChecksumAlgorithms(config.getMsiPlesseyChecksumAlgorithms());
|
|
152
|
+
ab.setStripCheckDigits(config.getStripCheckDigits());
|
|
153
|
+
ab.setGs1DecodingEnabled(config.getGs1DecodingEnabled());
|
|
154
|
+
ab.setMinimum1DQuietZoneSize(config.getMinimum1DQuietZoneSize());
|
|
155
|
+
return Unit.INSTANCE;
|
|
156
|
+
});
|
|
163
157
|
}
|
|
158
|
+
return Unit.INSTANCE;
|
|
164
159
|
});
|
|
165
160
|
}
|
|
166
161
|
|
|
@@ -20,7 +20,7 @@ import com.facebook.react.uimanager.annotations.ReactProp;
|
|
|
20
20
|
|
|
21
21
|
import java.util.Map;
|
|
22
22
|
|
|
23
|
-
import io.scanbot.barcodesdk.plugin.reactnative.JSONUtils;
|
|
23
|
+
import io.scanbot.barcodesdk.plugin.reactnative.utils.JSONUtils;
|
|
24
24
|
import io.scanbot.barcodesdk.plugin.reactnative.ObjectMapper;
|
|
25
25
|
import io.scanbot.barcodesdk.plugin.reactnative.R;
|
|
26
26
|
import io.scanbot.barcodesdk.plugin.reactnative.components.EventEmitter;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
package io.scanbot.barcodesdk.plugin.reactnative.filters;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import java.util.Map;
|
|
6
|
+
|
|
7
|
+
import io.scanbot.sdk.barcode.entity.BarcodeItem;
|
|
8
|
+
import io.scanbot.sdk.barcode.entity.BarcodeMetadataKey;
|
|
9
|
+
import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeFilter;
|
|
10
|
+
|
|
11
|
+
public class ReactBarcodeExtensionsFilter extends BarcodeFilter {
|
|
12
|
+
|
|
13
|
+
public enum Type {
|
|
14
|
+
WithExtension,
|
|
15
|
+
WithEAN2Extension,
|
|
16
|
+
WithEAN5Extension
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
private final Type filterType;
|
|
20
|
+
|
|
21
|
+
public ReactBarcodeExtensionsFilter(Type filterType) {
|
|
22
|
+
this.filterType = filterType;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Override
|
|
26
|
+
public boolean acceptsBarcode(@NonNull BarcodeItem barcodeItem) {
|
|
27
|
+
if (!super.acceptsBarcode(barcodeItem)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
final String extension = getExtensionOrEmpty(barcodeItem);
|
|
32
|
+
if(extension.equals("")) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
switch(this.filterType) {
|
|
37
|
+
case WithExtension:
|
|
38
|
+
return true;
|
|
39
|
+
case WithEAN2Extension:
|
|
40
|
+
return extension.trim().length() == 2;
|
|
41
|
+
case WithEAN5Extension:
|
|
42
|
+
return extension.trim().length() == 5;
|
|
43
|
+
default:
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private static String getExtensionOrEmpty(final BarcodeItem barcodeItem)
|
|
49
|
+
{
|
|
50
|
+
final Map<BarcodeMetadataKey, String> metadata = barcodeItem.getMetadata();
|
|
51
|
+
|
|
52
|
+
if (!metadata.containsKey(BarcodeMetadataKey.UpcEanExtension)
|
|
53
|
+
) {
|
|
54
|
+
return "";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return metadata.get(BarcodeMetadataKey.UpcEanExtension);
|
|
58
|
+
}
|
|
59
|
+
}
|
package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/BitmapHelper.java
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Scanbot Barcode Scanner SDK React Native Plugin
|
|
3
|
+
Copyright (c) 2020 doo GmbH. All rights reserved.
|
|
4
|
+
https://scanbot.io/sdk
|
|
5
|
+
*/
|
|
6
|
+
package io.scanbot.barcodesdk.plugin.reactnative.utils;
|
|
7
|
+
|
|
8
|
+
import android.content.Context;
|
|
9
|
+
import android.graphics.Bitmap;
|
|
10
|
+
import android.net.Uri;
|
|
11
|
+
|
|
12
|
+
import java.io.File;
|
|
13
|
+
import java.io.FileOutputStream;
|
|
14
|
+
import java.io.IOException;
|
|
15
|
+
|
|
16
|
+
import io.scanbot.barcodesdk.plugin.reactnative.StorageUtils;
|
|
17
|
+
|
|
18
|
+
public class BitmapHelper {
|
|
19
|
+
public static File storeImageAsFile(final Bitmap image, final int quality, final Context context) throws IOException {
|
|
20
|
+
final File pictureFile = StorageUtils.generateRandomPluginStorageFile("jpg", context);
|
|
21
|
+
final FileOutputStream fos = new FileOutputStream(pictureFile);
|
|
22
|
+
image.compress(Bitmap.CompressFormat.JPEG, quality, fos);
|
|
23
|
+
fos.close();
|
|
24
|
+
return pictureFile;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public static Uri storeImage(final Bitmap image, final int quality, final Context context) throws IOException {
|
|
28
|
+
return Uri.fromFile(storeImageAsFile(image, quality, context));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Scanbot Barcode Scanner SDK React Native Plugin
|
|
3
|
+
Copyright (c) 2020 doo GmbH. All rights reserved.
|
|
4
|
+
https://scanbot.io/sdk
|
|
5
|
+
*/
|
|
6
|
+
package io.scanbot.barcodesdk.plugin.reactnative.utils;
|
|
7
|
+
|
|
8
|
+
import android.graphics.PointF;
|
|
9
|
+
import android.util.Log;
|
|
10
|
+
|
|
11
|
+
import androidx.annotation.NonNull;
|
|
12
|
+
import androidx.annotation.Nullable;
|
|
13
|
+
|
|
14
|
+
import com.facebook.react.bridge.Arguments;
|
|
15
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
16
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
17
|
+
import com.facebook.react.bridge.WritableArray;
|
|
18
|
+
import com.facebook.react.bridge.WritableMap;
|
|
19
|
+
import com.facebook.react.bridge.WritableNativeMap;
|
|
20
|
+
|
|
21
|
+
import org.jetbrains.annotations.NotNull;
|
|
22
|
+
|
|
23
|
+
import java.util.ArrayList;
|
|
24
|
+
import java.util.EnumSet;
|
|
25
|
+
import java.util.List;
|
|
26
|
+
import java.util.Objects;
|
|
27
|
+
|
|
28
|
+
import io.scanbot.barcodesdk.plugin.reactnative.filters.ReactBarcodeExtensionsFilter;
|
|
29
|
+
import io.scanbot.sdk.barcode.entity.BarcodeDocumentFormat;
|
|
30
|
+
import io.scanbot.sdk.barcode.entity.BarcodeFormat;
|
|
31
|
+
import io.scanbot.sdk.barcode.entity.BarcodeItem;
|
|
32
|
+
import io.scanbot.sdk.barcode.entity.BarcodeScannerAdditionalConfig;
|
|
33
|
+
import io.scanbot.sdk.barcode.entity.BarcodeScanningResult;
|
|
34
|
+
import io.scanbot.sdk.barcode.entity.EngineMode;
|
|
35
|
+
import io.scanbot.sdk.barcode.entity.MSIPlesseyChecksumAlgorithm;
|
|
36
|
+
import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeFilter;
|
|
37
|
+
import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeScannerAdditionalConfiguration;
|
|
38
|
+
import io.scanbot.sdk.ui.view.base.configuration.CameraOrientationMode;
|
|
39
|
+
|
|
40
|
+
public final class JSONUtils {
|
|
41
|
+
|
|
42
|
+
private JSONUtils() {}
|
|
43
|
+
|
|
44
|
+
public static class WritableMapBuilder {
|
|
45
|
+
|
|
46
|
+
private final WritableNativeMap _writableMap = new WritableNativeMap();
|
|
47
|
+
|
|
48
|
+
public WritableMapBuilder putBoolean(@NonNull String key, boolean value) {
|
|
49
|
+
_writableMap.putBoolean(key, value);
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public WritableMapBuilder putDouble(@NonNull String key, double value) {
|
|
54
|
+
_writableMap.putDouble(key, value);
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public WritableMapBuilder putInt(@NonNull String key, int value) {
|
|
59
|
+
_writableMap.putInt(key, value);
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public WritableMapBuilder putNull(@NonNull String key) {
|
|
64
|
+
_writableMap.putNull(key);
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public WritableMapBuilder putString(@NonNull String key, @Nullable String value) {
|
|
69
|
+
_writableMap.putString(key, value);
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public WritableMapBuilder putMap(@NonNull String key, @Nullable ReadableMap value) {
|
|
74
|
+
_writableMap.putMap(key, value);
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public WritableMapBuilder putArray(@NonNull String key, @Nullable ReadableArray value) {
|
|
79
|
+
_writableMap.putArray(key, value);
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public WritableMap build() {
|
|
84
|
+
return this._writableMap;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public static WritableArray sdkPolygonToWritableArray(final List<PointF> polygon) {
|
|
89
|
+
WritableArray points = Arguments.createArray();
|
|
90
|
+
if (polygon != null) {
|
|
91
|
+
for (final PointF p: polygon) {
|
|
92
|
+
WritableMap pointRecord = Arguments.createMap();
|
|
93
|
+
pointRecord.putDouble("x", p.x);
|
|
94
|
+
pointRecord.putDouble("y", p.y);
|
|
95
|
+
points.pushMap(pointRecord);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return points;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public static ArrayList<BarcodeFormat> extractBarcodeFormats(@NotNull ReadableMap configuration) {
|
|
102
|
+
ArrayList<BarcodeFormat> nativeBarcodeFormats = new ArrayList<>();
|
|
103
|
+
if (configuration.hasKey("barcodeFormats")) {
|
|
104
|
+
ReadableArray barcodeFormats = configuration.getArray("barcodeFormats");
|
|
105
|
+
if (barcodeFormats != null) {
|
|
106
|
+
for (int i = 0; i < barcodeFormats.size(); ++i) {
|
|
107
|
+
nativeBarcodeFormats.add(BarcodeFormat.valueOf(barcodeFormats.getString(i)));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return nativeBarcodeFormats;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public static ArrayList<BarcodeDocumentFormat> extractBarcodeDocumentFormats(final ReadableMap configuration) {
|
|
115
|
+
ArrayList<BarcodeDocumentFormat> nativeBarcodeDocumentFormats = new ArrayList<>();
|
|
116
|
+
ArrayList<String> barcodeDocumentFormats = JSONUtils.getStringArrayListFromMap(configuration, "acceptedDocumentFormats");
|
|
117
|
+
|
|
118
|
+
for (String format : barcodeDocumentFormats) {
|
|
119
|
+
nativeBarcodeDocumentFormats.add(BarcodeDocumentFormat.valueOf(format));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return nativeBarcodeDocumentFormats;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public static @Nullable CameraOrientationMode extractCameraOrientationMode(final ReadableMap configuration) {
|
|
126
|
+
if (configuration.hasKey("allowedInterfaceOrientations")) {
|
|
127
|
+
String orientation = configuration.getString("allowedInterfaceOrientations");
|
|
128
|
+
if (orientation == null) {
|
|
129
|
+
orientation = "NONE";
|
|
130
|
+
}
|
|
131
|
+
switch (orientation) {
|
|
132
|
+
case "NONE":
|
|
133
|
+
break;
|
|
134
|
+
case "PORTRAIT":
|
|
135
|
+
case "PORTRAIT_UPSIDE_DOWN":
|
|
136
|
+
return CameraOrientationMode.PORTRAIT;
|
|
137
|
+
case "LANDSCAPE_LEFT":
|
|
138
|
+
case "LANDSCAPE_RIGHT":
|
|
139
|
+
case "LANDSCAPE":
|
|
140
|
+
return CameraOrientationMode.LANDSCAPE;
|
|
141
|
+
default:
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
public static @Nullable BarcodeScannerAdditionalConfig extractBarcodeScannerAdditionalConfig(final ReadableMap configuration) {
|
|
150
|
+
boolean changed = false;
|
|
151
|
+
|
|
152
|
+
int minimumTextLength = BarcodeScannerAdditionalConfig.DEFAULT_MIN_TEXT_LENGTH;
|
|
153
|
+
if (configuration.hasKey("minimumTextLength")) {
|
|
154
|
+
minimumTextLength = configuration.getInt("minimumTextLength");
|
|
155
|
+
changed = true;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
int maximumTextLength = BarcodeScannerAdditionalConfig.DEFAULT_MAX_TEXT_LENGTH;
|
|
159
|
+
if (configuration.hasKey("maximumTextLength")) {
|
|
160
|
+
maximumTextLength = configuration.getInt("maximumTextLength");
|
|
161
|
+
changed = true;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
int minimum1DQuietZoneSize = BarcodeScannerAdditionalConfig.DEFAULT_MIN_1D_QUIET_ZONE_SIZE;
|
|
165
|
+
if (configuration.hasKey("minimum1DBarcodesQuietZone")) {
|
|
166
|
+
minimum1DQuietZoneSize = configuration.getInt("minimum1DBarcodesQuietZone");
|
|
167
|
+
changed = true;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
boolean gs1DecodingEnabled = BarcodeScannerAdditionalConfig.DEFAULT_GS1_DECODING_ENABLED;
|
|
171
|
+
if (configuration.hasKey("gs1DecodingEnabled")) {
|
|
172
|
+
gs1DecodingEnabled = configuration.getBoolean("gs1DecodingEnabled");
|
|
173
|
+
changed = true;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
EnumSet<MSIPlesseyChecksumAlgorithm> msiPlesseyChecksumAlgorithms =
|
|
177
|
+
BarcodeScannerAdditionalConfig.Companion.getDEFAULT_MSI_PLESSEY_CHECKSUM_ALGORITHMS();
|
|
178
|
+
if (configuration.hasKey("msiPlesseyChecksumAlgorithm")) {
|
|
179
|
+
msiPlesseyChecksumAlgorithms.clear();
|
|
180
|
+
String algorithm = configuration.getString("msiPlesseyChecksumAlgorithm");
|
|
181
|
+
msiPlesseyChecksumAlgorithms.add(MSIPlesseyChecksumAlgorithm.valueOf(algorithm));
|
|
182
|
+
changed = true;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
boolean stripCheckDigits = BarcodeScannerAdditionalConfig.DEFAULT_STRIP_CHECK_DIGITS;
|
|
186
|
+
if (configuration.hasKey("stripCheckDigits")) {
|
|
187
|
+
stripCheckDigits = configuration.getBoolean("stripCheckDigits");
|
|
188
|
+
changed = true;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
boolean lowPowerMode = BarcodeScannerAdditionalConfig.DEFAULT_LOW_POWER_MODE;
|
|
192
|
+
if (configuration.hasKey("lowPowerMode")) {
|
|
193
|
+
lowPowerMode = configuration.getBoolean("lowPowerMode");
|
|
194
|
+
changed = true;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return changed ? new BarcodeScannerAdditionalConfig(
|
|
198
|
+
minimumTextLength,
|
|
199
|
+
maximumTextLength,
|
|
200
|
+
minimum1DQuietZoneSize,
|
|
201
|
+
gs1DecodingEnabled,
|
|
202
|
+
msiPlesseyChecksumAlgorithms,
|
|
203
|
+
stripCheckDigits,
|
|
204
|
+
lowPowerMode
|
|
205
|
+
) : null;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
public static @Nullable BarcodeScannerAdditionalConfiguration extractBarcodeScannerAdditionalConfiguration(final ReadableMap configuration) {
|
|
209
|
+
final BarcodeScannerAdditionalConfig config = extractBarcodeScannerAdditionalConfig(configuration);
|
|
210
|
+
return config != null ? new BarcodeScannerAdditionalConfiguration(
|
|
211
|
+
config.getMinimumTextLength(),
|
|
212
|
+
config.getMaximumTextLength(),
|
|
213
|
+
config.getMinimum1DQuietZoneSize(),
|
|
214
|
+
config.getGs1DecodingEnabled(),
|
|
215
|
+
config.getMsiPlesseyChecksumAlgorithms(),
|
|
216
|
+
config.getStripCheckDigits(),
|
|
217
|
+
config.getLowPowerMode()
|
|
218
|
+
) : null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
public static BarcodeFilter extractBarcodeFilter(final ReadableMap options) {
|
|
222
|
+
if (!options.hasKey("barcodeFilter")) {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
final String filterType = options.getString("barcodeFilter");
|
|
226
|
+
try {
|
|
227
|
+
final ReactBarcodeExtensionsFilter.Type type =
|
|
228
|
+
ReactBarcodeExtensionsFilter.Type.valueOf(filterType);
|
|
229
|
+
return new ReactBarcodeExtensionsFilter(type);
|
|
230
|
+
}
|
|
231
|
+
catch (IllegalArgumentException exception) {
|
|
232
|
+
final String errMsg = String.format("The value passed in 'barcodeFilter' (%s) does not exist", filterType);
|
|
233
|
+
Log.e("SCANBOT_SDK", errMsg);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
public static List<BarcodeItem> getBarcodeItemsFromResultWithFilter(BarcodeScanningResult result, BarcodeFilter filter) {
|
|
240
|
+
if (result == null) {
|
|
241
|
+
return new ArrayList<>();
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
final List<BarcodeItem> filteredBarcodeItems = new ArrayList<>();
|
|
245
|
+
for (BarcodeItem barcodeItem : result.getBarcodeItems()) {
|
|
246
|
+
if (!filter.acceptsBarcode(barcodeItem)) { continue; }
|
|
247
|
+
filteredBarcodeItems.add(barcodeItem);
|
|
248
|
+
}
|
|
249
|
+
return filteredBarcodeItems;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
public static ArrayList<String> getStringArrayListFromMap(final ReadableMap configuration, final String key) {
|
|
253
|
+
ArrayList<String> out = new ArrayList<>();
|
|
254
|
+
if(!configuration.hasKey(key)) {
|
|
255
|
+
return out;
|
|
256
|
+
}
|
|
257
|
+
ReadableArray nullable = configuration.getArray(key);
|
|
258
|
+
if (nullable != null) {
|
|
259
|
+
ArrayList<Object> objects = nullable.toArrayList();
|
|
260
|
+
for (Object obj : objects) {
|
|
261
|
+
try { out.add(Objects.toString(obj)); }
|
|
262
|
+
catch (ClassCastException ignored) {}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return out;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
public static EngineMode extractEngineMode(ReadableMap configuration) {
|
|
269
|
+
if (!configuration.hasKey("engineMode")) {
|
|
270
|
+
return EngineMode.NextGen;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
String mode = configuration.getString("engineMode");
|
|
274
|
+
if ("LEGACY".equals(mode)) {
|
|
275
|
+
return EngineMode.Legacy;
|
|
276
|
+
}
|
|
277
|
+
return EngineMode.NextGen;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
public static boolean getBoolOrFalse(final ReadableMap map, final String key) {
|
|
281
|
+
if (!map.hasKey(key)) {
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
return map.getBoolean(key);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Scanbot Barcode Scanner SDK React Native Plugin
|
|
3
|
+
Copyright (c) 2020 doo GmbH. All rights reserved.
|
|
4
|
+
https://scanbot.io/sdk
|
|
5
|
+
*/
|
|
6
|
+
package io.scanbot.barcodesdk.plugin.reactnative.utils;
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
import android.util.Log;
|
|
10
|
+
|
|
11
|
+
public final class LogUtils {
|
|
12
|
+
|
|
13
|
+
// global static loggingEnabled flag (set on ScanbotSdkPlugin.initializeSdk(..))
|
|
14
|
+
private static boolean loggingEnabled = false;
|
|
15
|
+
|
|
16
|
+
private LogUtils() {}
|
|
17
|
+
|
|
18
|
+
public static synchronized void setLoggingEnabled(final boolean flag) {
|
|
19
|
+
loggingEnabled = flag;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public static synchronized boolean isLoggingEnabled() {
|
|
23
|
+
return loggingEnabled;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public static void debugLog(final String logTag, final String msg) {
|
|
27
|
+
if (loggingEnabled) {
|
|
28
|
+
Log.d(logTag, msg);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public static void errorLog(final String logTag, final String msg) {
|
|
33
|
+
Log.e(logTag, msg);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public static void errorLog(final String logTag, final String msg, final Throwable e) {
|
|
37
|
+
Log.e(logTag, msg, e);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/ResponseUtils.java
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Scanbot Barcode Scanner SDK React Native Plugin
|
|
3
|
+
Copyright (c) 2020 doo GmbH. All rights reserved.
|
|
4
|
+
https://scanbot.io/sdk
|
|
5
|
+
*/
|
|
6
|
+
package io.scanbot.barcodesdk.plugin.reactnative.utils;
|
|
7
|
+
|
|
8
|
+
import android.view.View;
|
|
9
|
+
|
|
10
|
+
import com.facebook.react.bridge.Arguments;
|
|
11
|
+
import com.facebook.react.bridge.Promise;
|
|
12
|
+
import com.facebook.react.bridge.ReactContext;
|
|
13
|
+
import com.facebook.react.bridge.WritableMap;
|
|
14
|
+
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|
15
|
+
|
|
16
|
+
public class ResponseUtils {
|
|
17
|
+
|
|
18
|
+
public static void successMessageJson(final String msg, final Promise promise) {
|
|
19
|
+
final WritableMap response = Arguments.createMap();
|
|
20
|
+
response.putString("status", "OK");
|
|
21
|
+
response.putString("message", msg);
|
|
22
|
+
promise.resolve(response);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public static void successCanceled(final Promise promise) {
|
|
26
|
+
final WritableMap response = Arguments.createMap();
|
|
27
|
+
response.putString("status", "CANCELED");
|
|
28
|
+
promise.resolve(response);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public static void errorMessageJson(final String msg, final Promise promise) {
|
|
32
|
+
final WritableMap response = Arguments.createMap();
|
|
33
|
+
response.putString("error", msg);
|
|
34
|
+
promise.reject(msg);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public static void sendReactEvent(String eventName, WritableMap event, View view) {
|
|
38
|
+
final ReactContext reactContext = (ReactContext)view.getContext();
|
|
39
|
+
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(view.getId(), eventName, event);
|
|
40
|
+
}
|
|
41
|
+
}
|
package/ios/ScanbotBarcodeSdk.m
CHANGED
|
@@ -40,13 +40,13 @@ RCT_EXPORT_METHOD(initializeSdk:(NSDictionary *)configuration
|
|
|
40
40
|
{
|
|
41
41
|
[ObjectMapper setEnumerationMapping:@{
|
|
42
42
|
@"barcodeImageGenerationType": @{
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
@"NONE": @(SBSDKBarcodeImageGenerationTypeNone),
|
|
44
|
+
@"VIDEO_FRAME": @(SBSDKBarcodeImageGenerationTypeFromVideoFrame),
|
|
45
|
+
@"CAPTURED_IMAGE" :@(SBSDKBarcodeImageGenerationTypeCapturedImage),
|
|
46
46
|
},
|
|
47
47
|
@"engineMode": @{
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
@"LEGACY": @(SBSDKBarcodeEngineModeLegacy),
|
|
49
|
+
@"NEXT_GEN": @(SBSDKBarcodeEngineModeNextGen)
|
|
50
50
|
},
|
|
51
51
|
@"allowedInterfaceOrientations": @{
|
|
52
52
|
@"NONE": @(UIInterfaceOrientationMaskAll),
|
|
@@ -120,35 +120,24 @@ RCT_EXPORT_METHOD(startBarcodeScanner:(NSDictionary*)configuration
|
|
|
120
120
|
SBSDKUIBarcodeScannerUIConfiguration* uiConfig = [[SBSDKUIBarcodeScannerUIConfiguration alloc] init];
|
|
121
121
|
SBSDKUIBarcodeScannerBehaviorConfiguration* behaviorConfig = [[SBSDKUIBarcodeScannerBehaviorConfiguration alloc] init];
|
|
122
122
|
SBSDKUIBarcodeScannerTextConfiguration* textConfig = [[SBSDKUIBarcodeScannerTextConfiguration alloc] init];
|
|
123
|
-
SBSDKBarcodeAdditionalParameters* additionalParameters = [[SBSDKBarcodeAdditionalParameters alloc] init];
|
|
124
123
|
|
|
125
124
|
@try {
|
|
126
125
|
[ObjectMapper populateInstance:uiConfig fromDictionary:configuration];
|
|
127
126
|
[ObjectMapper populateInstance:behaviorConfig fromDictionary:configuration];
|
|
128
127
|
[ObjectMapper populateInstance:textConfig fromDictionary:configuration];
|
|
129
|
-
[ObjectMapper populateInstance:additionalParameters fromDictionary:configuration];
|
|
130
128
|
}
|
|
131
129
|
@catch (NSException* ex) {
|
|
132
130
|
reject(@"Property error", [ex reason], nil);
|
|
133
131
|
return;
|
|
134
132
|
}
|
|
135
133
|
|
|
136
|
-
// Need to manually extract because of naming disparity between iOS and Android
|
|
137
|
-
// Also, it is nullable, 'true' by default, so we wrap it in an NSNumber
|
|
138
|
-
NSNumber* gs1Decoding = [configuration objectForKey:@"gs1DecodingEnabled"];
|
|
139
|
-
if (gs1Decoding != nil) {
|
|
140
|
-
additionalParameters.enableGS1Decoding = [gs1Decoding boolValue];
|
|
141
|
-
}
|
|
142
|
-
|
|
143
134
|
// Barcode Filter (at the moment used for UPC Extension filters)
|
|
144
135
|
SBSDKUIBarcodeFilter* barcodeFilter = extractBarcodeFilter(configuration);
|
|
145
136
|
if (barcodeFilter != nil) {
|
|
146
137
|
behaviorConfig.barcodeFilter = barcodeFilter;
|
|
147
138
|
}
|
|
148
139
|
|
|
149
|
-
additionalParameters
|
|
150
|
-
|
|
151
|
-
behaviorConfig.additionalParameters = additionalParameters;
|
|
140
|
+
behaviorConfig.additionalParameters = extractAdditionalParameters(configuration);
|
|
152
141
|
|
|
153
142
|
NSArray* machineCodeTypes = extractBarcodeTypesFromConfiguration(configuration);
|
|
154
143
|
NSArray* acceptedDocumentTypes = extractBarcodeDocumentTypesFromConfiguration(configuration);
|
|
@@ -184,47 +173,34 @@ RCT_EXPORT_METHOD(closeBarcodeScanner:(RCTPromiseResolveBlock)resolve
|
|
|
184
173
|
RCT_EXPORT_METHOD(startBatchBarcodeScanner:(NSDictionary*)configuration
|
|
185
174
|
withResolver:(RCTPromiseResolveBlock)resolve
|
|
186
175
|
withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
SBSDKUIBarcodesBatchScannerTextConfiguration *text =
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
[[SBSDKUIBarcodesBatchScannerBehaviorConfiguration alloc] init];
|
|
193
|
-
SBSDKBarcodeAdditionalParameters* additionalParameters = [[SBSDKBarcodeAdditionalParameters alloc] init];
|
|
194
|
-
|
|
176
|
+
|
|
177
|
+
SBSDKUIBarcodesBatchScannerUIConfiguration *ui = [[SBSDKUIBarcodesBatchScannerUIConfiguration alloc] init];
|
|
178
|
+
SBSDKUIBarcodesBatchScannerTextConfiguration *text = [[SBSDKUIBarcodesBatchScannerTextConfiguration alloc] init];
|
|
179
|
+
SBSDKUIBarcodesBatchScannerBehaviorConfiguration *behavior = [[SBSDKUIBarcodesBatchScannerBehaviorConfiguration alloc] init];
|
|
180
|
+
|
|
195
181
|
@try {
|
|
196
182
|
[ObjectMapper populateInstance:ui fromDictionary:configuration];
|
|
197
183
|
[ObjectMapper populateInstance:behavior fromDictionary:configuration];
|
|
198
184
|
[ObjectMapper populateInstance:text fromDictionary:configuration];
|
|
199
|
-
[ObjectMapper populateInstance:additionalParameters fromDictionary:configuration];
|
|
200
185
|
}
|
|
201
186
|
@catch (NSException* ex) {
|
|
202
187
|
reject(@"Property error", [ex reason], nil);
|
|
203
188
|
return;
|
|
204
189
|
}
|
|
205
|
-
|
|
206
|
-
// Need to manully extract because of naming disparity between iOS and Android
|
|
207
|
-
// Also, it is nullable, 'true' by default, so we wrap it in an NSNumber
|
|
208
|
-
NSNumber* gs1Decoding = [configuration objectForKey:@"gs1DecodingEnabled"];
|
|
209
|
-
if (gs1Decoding != nil) {
|
|
210
|
-
additionalParameters.enableGS1Decoding = [gs1Decoding boolValue];
|
|
211
|
-
}
|
|
212
|
-
|
|
190
|
+
|
|
213
191
|
// Barcode Filter (at the moment used for UPC Extension filters)
|
|
214
192
|
SBSDKUIBarcodeFilter* barcodeFilter = extractBarcodeFilter(configuration);
|
|
215
193
|
if (barcodeFilter != nil) {
|
|
216
194
|
behavior.barcodeFilter = barcodeFilter;
|
|
217
195
|
}
|
|
218
196
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
behavior.additionalDetectionParameters = additionalParameters;
|
|
222
|
-
|
|
197
|
+
behavior.additionalDetectionParameters = extractAdditionalParameters(configuration);
|
|
198
|
+
|
|
223
199
|
SBSDKUIBarcodesBatchScannerConfiguration *config = [[SBSDKUIBarcodesBatchScannerConfiguration alloc]
|
|
224
200
|
initWithUIConfiguration:ui
|
|
225
201
|
textConfiguration:text
|
|
226
202
|
behaviorConfiguration:behavior];
|
|
227
|
-
|
|
203
|
+
|
|
228
204
|
NSArray* machineCodeTypes = extractBarcodeTypesFromConfiguration(configuration);
|
|
229
205
|
NSArray* acceptedDocumentTypes = extractBarcodeDocumentTypesFromConfiguration(configuration);
|
|
230
206
|
|
|
@@ -270,16 +246,32 @@ RCT_EXPORT_METHOD(detectBarcodesOnImage:(NSDictionary *)configuration
|
|
|
270
246
|
return;
|
|
271
247
|
}
|
|
272
248
|
|
|
273
|
-
NSArray* barcodeTypes = [ScanbotBarcodeSdk extractBarcodeTypesFromConfiguration:configuration];
|
|
274
|
-
|
|
275
249
|
runInBackground(^{
|
|
250
|
+
|
|
251
|
+
NSArray* barcodeTypes = [ScanbotBarcodeSdk extractBarcodeTypesFromConfiguration:configuration];
|
|
276
252
|
SBSDKBarcodeScanner* barcodeScanner = [[SBSDKBarcodeScanner alloc] initWithTypes:barcodeTypes];
|
|
253
|
+
|
|
254
|
+
NSArray* barcodeDocumentTypes = extractBarcodeDocumentTypesFromConfiguration(configuration);
|
|
255
|
+
[barcodeScanner setAcceptedDocumentTypes: barcodeDocumentTypes];
|
|
256
|
+
|
|
257
|
+
SBSDKBarcodeEngineMode engineMode = extractEngineMode(configuration);
|
|
258
|
+
[barcodeScanner setEngineMode:engineMode];
|
|
259
|
+
|
|
260
|
+
SBSDKBarcodeAdditionalParameters* additionalParameters = extractAdditionalParameters(configuration);
|
|
261
|
+
[barcodeScanner setAdditionalParameters:additionalParameters];
|
|
262
|
+
|
|
277
263
|
UIImage* image = [ScanbotStorageUtils loadImage:imageUri];
|
|
278
264
|
if (!image) {
|
|
279
265
|
[self reportErrorWithMessage:@"Image could not be loaded." reject:reject];
|
|
280
266
|
return;
|
|
281
267
|
}
|
|
282
268
|
NSArray<SBSDKBarcodeScannerResult *> *barcodeResults = [barcodeScanner detectBarCodesOnImage:image];
|
|
269
|
+
|
|
270
|
+
SBSDKUIBarcodeFilter* barcodeFilter = extractBarcodeFilter(configuration);
|
|
271
|
+
if (barcodeFilter != nil) {
|
|
272
|
+
barcodeResults = filterBarcodeResults(barcodeResults, barcodeFilter);
|
|
273
|
+
}
|
|
274
|
+
|
|
283
275
|
resolve(@{
|
|
284
276
|
@"status": @"OK",
|
|
285
277
|
@"barcodes": jsonFromBarcodeResults(barcodeResults),
|
|
@@ -87,6 +87,22 @@ static inline NSArray<NSDictionary<NSString*, NSObject*>*>* jsonFromMappedBarcod
|
|
|
87
87
|
return [jsonResults copy];
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
static inline SBSDKBarcodeMSIPlesseyChecksumAlgorithm extractPlesseyChecksumAlgorithmFromConfiguration(NSDictionary* configuration) {
|
|
91
|
+
NSString* algorithm = [configuration objectForKey:@"msiPlesseyChecksumAlgorithm"];
|
|
92
|
+
|
|
93
|
+
if (algorithm != nil) {
|
|
94
|
+
if ([algorithm isEqualToString:@"None"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmNone;
|
|
95
|
+
if ([algorithm isEqualToString:@"Mod10"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod10;
|
|
96
|
+
if ([algorithm isEqualToString:@"Mod1010"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod1010;
|
|
97
|
+
if ([algorithm isEqualToString:@"Mod11IBM"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod11IBM;
|
|
98
|
+
if ([algorithm isEqualToString:@"Mod11NCR"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod11NCR;
|
|
99
|
+
if ([algorithm isEqualToString:@"Mod1110IBM"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod1110IBM;
|
|
100
|
+
if ([algorithm isEqualToString:@"Mod1110NCR"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod1110NCR;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod10;
|
|
104
|
+
}
|
|
105
|
+
|
|
90
106
|
static inline SBSDKUIBarcodeFilter* extractBarcodeFilter(NSDictionary* configuration) {
|
|
91
107
|
NSString* jsonFilterType = [configuration objectForKey:@"barcodeFilter"];
|
|
92
108
|
if (jsonFilterType == nil) {
|
|
@@ -104,6 +120,21 @@ static inline SBSDKUIBarcodeFilter* extractBarcodeFilter(NSDictionary* configura
|
|
|
104
120
|
return nil;
|
|
105
121
|
}
|
|
106
122
|
|
|
123
|
+
static inline NSArray* filterBarcodeResults(NSArray<SBSDKBarcodeScannerResult *>* barcodeResults, SBSDKUIBarcodeFilter* filter) {
|
|
124
|
+
NSMutableArray<SBSDKBarcodeScannerResult *>* outResults = [[NSMutableArray alloc] init];
|
|
125
|
+
|
|
126
|
+
if (barcodeResults == nil) {
|
|
127
|
+
return outResults;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
for (SBSDKBarcodeScannerResult* result in barcodeResults) {
|
|
131
|
+
if (![filter acceptsBarcode:result]) { continue; }
|
|
132
|
+
[outResults addObject:result];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return outResults;
|
|
136
|
+
}
|
|
137
|
+
|
|
107
138
|
static inline NSArray* extractBarcodeTypesFromConfiguration(NSDictionary* configuration) {
|
|
108
139
|
NSArray* barcodeFormats = [configuration objectForKey:@"barcodeFormats"];
|
|
109
140
|
if (barcodeFormats && [barcodeFormats indexOfObject:@"ALL_FORMATS"] == NSNotFound) {
|
|
@@ -144,20 +175,26 @@ static inline SBSDKBarcodeEngineMode extractEngineMode(NSDictionary* configurati
|
|
|
144
175
|
return SBSDKBarcodeEngineModeNextGen;
|
|
145
176
|
}
|
|
146
177
|
|
|
147
|
-
static inline
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if ([algorithm isEqualToString:@"None"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmNone;
|
|
152
|
-
if ([algorithm isEqualToString:@"Mod10"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod10;
|
|
153
|
-
if ([algorithm isEqualToString:@"Mod1010"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod1010;
|
|
154
|
-
if ([algorithm isEqualToString:@"Mod11IBM"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod11IBM;
|
|
155
|
-
if ([algorithm isEqualToString:@"Mod11NCR"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod11NCR;
|
|
156
|
-
if ([algorithm isEqualToString:@"Mod1110IBM"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod1110IBM;
|
|
157
|
-
if ([algorithm isEqualToString:@"Mod1110NCR"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod1110NCR;
|
|
178
|
+
static inline SBSDKBarcodeAdditionalParameters* extractAdditionalParameters(NSDictionary* configuration) {
|
|
179
|
+
SBSDKBarcodeAdditionalParameters* additionalParameters = [[SBSDKBarcodeAdditionalParameters alloc] init];
|
|
180
|
+
@try {
|
|
181
|
+
[ObjectMapper populateInstance:additionalParameters fromDictionary:configuration];
|
|
158
182
|
}
|
|
159
|
-
|
|
160
|
-
|
|
183
|
+
@catch (NSException* ex) {
|
|
184
|
+
return nil;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Need to manually extract because of naming disparity between iOS and Android
|
|
188
|
+
// Also, it is nullable, 'true' by default, so we wrap it in an NSNumber
|
|
189
|
+
NSNumber* gs1Decoding = [configuration objectForKey:@"gs1DecodingEnabled"];
|
|
190
|
+
if (gs1Decoding != nil) {
|
|
191
|
+
additionalParameters.enableGS1Decoding = [gs1Decoding boolValue];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// We also need to manually extract the MSI-Plessey Checksum Algorithm since it can't be mapped automatically
|
|
195
|
+
additionalParameters.msiPlesseyChecksumAlgorithm = extractPlesseyChecksumAlgorithmFromConfiguration(configuration);
|
|
196
|
+
|
|
197
|
+
return additionalParameters;
|
|
161
198
|
}
|
|
162
199
|
|
|
163
200
|
static inline SBSDKUICameraConfiguration* extractCameraConfiguration(NSDictionary* configuration) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-scanbot-barcode-scanner-sdk",
|
|
3
3
|
"title": "Scanbot Barcode Scanner SDK for React Native",
|
|
4
|
-
"version": "3.2.1-
|
|
4
|
+
"version": "3.2.1-beta4",
|
|
5
5
|
"description": "Scanbot Barcode Scanner SDK React Native Plugin for Android and iOS",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"files": [
|