react-native-scanbot-barcode-scanner-sdk 3.2.1-beta2 → 3.2.1-beta5
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/JSONUtils.java +21 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ObjectMapper.java +22 -6
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ReactBarcodeExtensionsFilter.java +61 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ScanbotBarcodeSdkModule.java +52 -69
- 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 +41 -49
- package/ios/Utils/BarcodeMapping.h +68 -13
- package/ios/Utils/ReactBarcodeExtensionsFilter.h +22 -0
- package/ios/Utils/ReactBarcodeExtensionsFilter.m +55 -0
- package/package.json +1 -1
- package/src/configuration.ts +10 -5
- package/src/enum.ts +5 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/BarcodeExtensionsFilter.java +0 -24
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
package io.scanbot.barcodesdk.plugin.reactnative;
|
|
7
7
|
|
|
8
8
|
import android.graphics.PointF;
|
|
9
|
+
import android.util.Log;
|
|
9
10
|
|
|
10
11
|
import androidx.annotation.NonNull;
|
|
11
12
|
import androidx.annotation.Nullable;
|
|
@@ -30,6 +31,7 @@ import io.scanbot.sdk.barcode.entity.BarcodeFormat;
|
|
|
30
31
|
import io.scanbot.sdk.barcode.entity.BarcodeScannerAdditionalConfig;
|
|
31
32
|
import io.scanbot.sdk.barcode.entity.EngineMode;
|
|
32
33
|
import io.scanbot.sdk.barcode.entity.MSIPlesseyChecksumAlgorithm;
|
|
34
|
+
import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeFilter;
|
|
33
35
|
import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeScannerAdditionalConfiguration;
|
|
34
36
|
import io.scanbot.sdk.ui.view.base.configuration.CameraOrientationMode;
|
|
35
37
|
|
|
@@ -214,6 +216,25 @@ public final class JSONUtils {
|
|
|
214
216
|
) : null;
|
|
215
217
|
}
|
|
216
218
|
|
|
219
|
+
public static BarcodeFilter extractBarcodeFilter(final ReadableMap options) {
|
|
220
|
+
if (!options.hasKey("barcodeFilter")) {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
final String filterType = options.getString("barcodeFilter");
|
|
224
|
+
try {
|
|
225
|
+
final ReactBarcodeExtensionsFilter.Type type =
|
|
226
|
+
ReactBarcodeExtensionsFilter.Type.valueOf(filterType);
|
|
227
|
+
return new ReactBarcodeExtensionsFilter(type);
|
|
228
|
+
}
|
|
229
|
+
catch (IllegalArgumentException exception) {
|
|
230
|
+
exception.printStackTrace();
|
|
231
|
+
final String errMsg = String.format("The value passed in 'barcodeFilter' (%s) does not exist", filterType);
|
|
232
|
+
Log.e("SCANBOT_SDK", errMsg);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
|
|
217
238
|
public static ArrayList<String> getStringArrayListFromMap(final ReadableMap configuration, final String key) {
|
|
218
239
|
ArrayList<String> out = new ArrayList<>();
|
|
219
240
|
if(!configuration.hasKey(key)) {
|
|
@@ -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 ("onlyAcceptCodesWithExtensions".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
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
package io.scanbot.barcodesdk.plugin.reactnative;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import java.util.List;
|
|
6
|
+
import java.util.Map;
|
|
7
|
+
|
|
8
|
+
import io.scanbot.sdk.barcode.entity.BarcodeItem;
|
|
9
|
+
import io.scanbot.sdk.barcode.entity.BarcodeMetadataKey;
|
|
10
|
+
import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeFilter;
|
|
11
|
+
import io.scanbot.sdk.ui.view.barcode.configuration.IBarcodeFilter;
|
|
12
|
+
|
|
13
|
+
public class ReactBarcodeExtensionsFilter extends BarcodeFilter {
|
|
14
|
+
|
|
15
|
+
public enum Type {
|
|
16
|
+
WithExtension,
|
|
17
|
+
WithEAN2Extension,
|
|
18
|
+
WithEAN5Extension
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
private final Type filterType;
|
|
22
|
+
|
|
23
|
+
public ReactBarcodeExtensionsFilter(Type filterType) {
|
|
24
|
+
this.filterType = filterType;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Override
|
|
28
|
+
public boolean acceptsBarcode(@NonNull BarcodeItem barcodeItem) {
|
|
29
|
+
if (!super.acceptsBarcode(barcodeItem)) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
final String extension = getExtensionOrEmpty(barcodeItem);
|
|
34
|
+
if(extension.equals("")) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
switch(this.filterType) {
|
|
39
|
+
case WithExtension:
|
|
40
|
+
return true;
|
|
41
|
+
case WithEAN2Extension:
|
|
42
|
+
return extension.trim().length() == 2;
|
|
43
|
+
case WithEAN5Extension:
|
|
44
|
+
return extension.trim().length() == 5;
|
|
45
|
+
default:
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private static String getExtensionOrEmpty(final BarcodeItem barcodeItem)
|
|
51
|
+
{
|
|
52
|
+
final Map<BarcodeMetadataKey, String> metadata = barcodeItem.getMetadata();
|
|
53
|
+
|
|
54
|
+
if (!metadata.containsKey(BarcodeMetadataKey.UpcEanExtension)
|
|
55
|
+
) {
|
|
56
|
+
return "";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return metadata.get(BarcodeMetadataKey.UpcEanExtension);
|
|
60
|
+
}
|
|
61
|
+
}
|
package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ScanbotBarcodeSdkModule.java
CHANGED
|
@@ -29,29 +29,32 @@ 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.
|
|
53
|
+
import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeFilter;
|
|
50
54
|
import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeScannerAdditionalConfiguration;
|
|
51
55
|
import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeScannerConfiguration;
|
|
52
56
|
import io.scanbot.sdk.ui.view.base.configuration.CameraOrientationMode;
|
|
53
57
|
import kotlin.Unit;
|
|
54
|
-
import kotlin.jvm.functions.Function1;
|
|
55
58
|
|
|
56
59
|
import android.app.Activity;
|
|
57
60
|
|
|
@@ -168,62 +171,37 @@ public class ScanbotBarcodeSdkModule extends ReactContextBaseJavaModule implemen
|
|
|
168
171
|
if (rejectIfUninitialized(promise)) {
|
|
169
172
|
return;
|
|
170
173
|
}
|
|
171
|
-
this.threadPool.execute(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
String imageUri = options.getString("imageFileUri");
|
|
175
|
-
final ArrayList<BarcodeFormat> barcodeFormats = JSONUtils.extractBarcodeFormats(options);
|
|
176
|
-
final ArrayList<BarcodeDocumentFormat> barcodeDocumentFormats = JSONUtils.extractBarcodeDocumentFormats(options);
|
|
177
|
-
|
|
178
|
-
final Bitmap bitmap = MediaStore.Images.Media.getBitmap(getReactApplicationContext().getContentResolver(), Uri.parse(imageUri));
|
|
179
|
-
final ScanbotBarcodeScannerSDK sdk = new ScanbotBarcodeScannerSDK(getReactApplicationContext());
|
|
180
|
-
final ScanbotBarcodeDetector detector = sdk.createBarcodeDetector();
|
|
181
|
-
|
|
182
|
-
detector.modifyConfig(new Function1<BarcodeScannerConfigBuilder, Unit>() {
|
|
183
|
-
@Override
|
|
184
|
-
public Unit invoke(BarcodeScannerConfigBuilder barcodeScannerConfigBuilder) {
|
|
185
|
-
if (!barcodeFormats.isEmpty()) {
|
|
186
|
-
barcodeScannerConfigBuilder.setBarcodeFormats(barcodeFormats);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (!barcodeDocumentFormats.isEmpty()) {
|
|
190
|
-
barcodeScannerConfigBuilder.setAcceptedDocumentFormats(barcodeDocumentFormats);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// Additional Configuration
|
|
194
|
-
barcodeScannerConfigBuilder.modifyAdditionalConfig(new Function1<BarcodeScannerAdditionalConfigBuilder, Unit>() {
|
|
195
|
-
@Override
|
|
196
|
-
public Unit invoke(BarcodeScannerAdditionalConfigBuilder barcodeScannerAdditionalConfigBuilder) {
|
|
197
|
-
|
|
198
|
-
if (options.hasKey("minimumTextLength")) {
|
|
199
|
-
barcodeScannerAdditionalConfigBuilder.setMinimumTextLength(options.getInt("minimumTextLength"));
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (options.hasKey("maximumTextLength")) {
|
|
203
|
-
barcodeScannerAdditionalConfigBuilder.setMaximumTextLength(options.getInt("maximumTextLength"));
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (options.hasKey("minimum1DBarcodesQuietZone")) {
|
|
207
|
-
barcodeScannerAdditionalConfigBuilder.setMinimum1DQuietZoneSize(options.getInt("minimum1DBarcodesQuietZone"));
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return Unit.INSTANCE;
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
return Unit.INSTANCE;
|
|
215
|
-
}
|
|
216
|
-
});
|
|
174
|
+
this.threadPool.execute(() -> {
|
|
175
|
+
try {
|
|
176
|
+
final String imageUri = options.getString("imageFileUri");
|
|
217
177
|
|
|
218
|
-
|
|
178
|
+
final Bitmap bitmap = MediaStore.Images.Media.getBitmap(getReactApplicationContext().getContentResolver(), Uri.parse(imageUri));
|
|
179
|
+
final ScanbotBarcodeScannerSDK sdk = new ScanbotBarcodeScannerSDK(getReactApplicationContext());
|
|
219
180
|
|
|
220
|
-
|
|
221
|
-
jsonResult.putString("imageFileUri", imageUri);
|
|
222
|
-
promise.resolve(jsonResult);
|
|
181
|
+
final ScanbotBarcodeDetector detector = sdk.createBarcodeDetector();
|
|
223
182
|
|
|
224
|
-
|
|
225
|
-
|
|
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);
|
|
226
198
|
}
|
|
199
|
+
|
|
200
|
+
jsonResult.putString("imageFileUri", imageUri);
|
|
201
|
+
promise.resolve(jsonResult);
|
|
202
|
+
|
|
203
|
+
} catch (Exception ex) {
|
|
204
|
+
promise.reject(ex);
|
|
227
205
|
}
|
|
228
206
|
});
|
|
229
207
|
}
|
|
@@ -308,8 +286,11 @@ public class ScanbotBarcodeSdkModule extends ReactContextBaseJavaModule implemen
|
|
|
308
286
|
configuration.setCancelButtonIcon(R.drawable.ic_baseline_arrow_back_24);
|
|
309
287
|
}
|
|
310
288
|
|
|
311
|
-
if (options.hasKey("
|
|
312
|
-
|
|
289
|
+
if (options.hasKey("barcodeFilter")) {
|
|
290
|
+
final BarcodeFilter barcodeFilter = JSONUtils.extractBarcodeFilter(options);
|
|
291
|
+
if (barcodeFilter != null) {
|
|
292
|
+
configuration.setBarcodeFilter(barcodeFilter);
|
|
293
|
+
}
|
|
313
294
|
}
|
|
314
295
|
}
|
|
315
296
|
|
|
@@ -397,25 +378,27 @@ public class ScanbotBarcodeSdkModule extends ReactContextBaseJavaModule implemen
|
|
|
397
378
|
}
|
|
398
379
|
}
|
|
399
380
|
|
|
400
|
-
private static WritableMap jsonResultFromBarcodeScannerResult(
|
|
381
|
+
private static WritableMap jsonResultFromBarcodeScannerResult(List<BarcodeItem> barcodeItems) {
|
|
401
382
|
final WritableArray barcodes = Arguments.createArray();
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
barcode.putString("textWithExtension", barcodeItem.getTextWithExtension());
|
|
409
|
-
barcodes.pushMap(barcode);
|
|
410
|
-
}
|
|
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);
|
|
411
389
|
}
|
|
412
|
-
|
|
413
390
|
final WritableMap result = Arguments.createMap();
|
|
414
391
|
result.putString("status", "OK");
|
|
415
392
|
result.putArray("barcodes", barcodes);
|
|
416
393
|
return result;
|
|
417
394
|
}
|
|
418
395
|
|
|
396
|
+
private static WritableMap jsonResultFromBarcodeScannerResult(BarcodeScanningResult barcodeResult) {
|
|
397
|
+
return jsonResultFromBarcodeScannerResult(
|
|
398
|
+
barcodeResult != null ? barcodeResult.getBarcodeItems() : new ArrayList<>()
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
|
|
419
402
|
@NotNull
|
|
420
403
|
@Contract(pure = true)
|
|
421
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
|
+
}
|