anyline-ocr-react-native-module 42.2.0 → 43.0.1
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/.idea/modules.xml +8 -0
- package/.idea/plugin.iml +9 -0
- package/.idea/vcs.xml +6 -0
- package/android/.gradle/6.7/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.0/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.0/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.0/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/7.0/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.0/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/7.0/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.0/gc.properties +0 -0
- package/android/.gradle/7.3/checksums/checksums.lock +0 -0
- package/android/.gradle/7.3/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.3/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.3/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.3/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.3/gc.properties +0 -0
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/7.4/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/7.4/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.4/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.4/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.4/fileHashes/resourceHashesCache.bin +0 -0
- package/android/.gradle/7.4/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +1 -1
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/android/.idea/gradle.xml +1 -0
- package/android/.idea/jarRepositories.xml +5 -0
- package/android/.idea/misc.xml +1 -1
- package/android/.idea/vcs.xml +1 -0
- package/android/build.gradle +7 -3
- package/android/src/main/AndroidManifest.xml +9 -8
- package/android/src/main/assets/cow_tag_scanner.ale +46 -0
- package/android/src/main/java/com/anyline/reactnative/AnylinePackage.java +1 -2
- package/android/src/main/java/com/anyline/reactnative/AnylineSDKPlugin.java +25 -77
- package/android/src/main/java/com/anyline/reactnative/RotateButtonConfig.java +12 -2
- package/android/src/main/java/com/anyline/reactnative/ScanActivity.java +206 -0
- package/android/src/main/res/drawable/rotate_screen_background.xml +18 -0
- package/android/src/main/res/drawable/rotate_screen_white.png +0 -0
- package/android/src/main/res/layout/activity_scan.xml +27 -0
- package/android/src/main/res/values/anyline_sdk_plugin_strings.xml +2 -28
- package/ios/ALJsonUIConfiguration.h +29 -36
- package/ios/ALJsonUIConfiguration.m +136 -76
- package/ios/ALNFCScanViewController.h +3 -16
- package/ios/ALNFCScanViewController.m +361 -232
- package/ios/ALPluginHelper.h +19 -62
- package/ios/ALPluginHelper.m +208 -529
- package/ios/ALPluginScanViewController.h +5 -32
- package/ios/ALPluginScanViewController.m +339 -287
- package/ios/AnylineReact.podspec +4 -3
- package/ios/AnylineSDKPlugin.m +39 -82
- package/package.json +8 -8
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/src/main/java/com/anyline/reactnative/Anyline4Activity.java +0 -621
- package/android/src/main/java/com/anyline/reactnative/AnylineBaseActivity.java +0 -267
- package/android/src/main/java/com/anyline/reactnative/AnylinePluginHelper.java +0 -324
- package/android/src/main/java/com/anyline/reactnative/AnylineUIConfig.java +0 -88
- package/android/src/main/java/com/anyline/reactnative/Document4Activity.java +0 -595
- package/android/src/main/res/layout/activity_scan_document.xml +0 -63
- package/android/src/main/res/layout/activity_scan_scanview.xml +0 -52
- package/android/src/main/res/values/com_crashlytics_export_strings.xml +0 -10
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Anyline React-Native Plugin
|
|
3
|
-
* AnylineBaseActivity.java
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) 2017 Anyline GmbH
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
package com.anyline.reactnative;
|
|
9
|
-
|
|
10
|
-
import android.app.Activity;
|
|
11
|
-
import android.content.Context;
|
|
12
|
-
import android.content.Intent;
|
|
13
|
-
import android.graphics.Color;
|
|
14
|
-
import android.graphics.PointF;
|
|
15
|
-
import android.os.Bundle;
|
|
16
|
-
import android.util.Log;
|
|
17
|
-
import android.view.WindowManager;
|
|
18
|
-
import android.widget.RelativeLayout;
|
|
19
|
-
import android.widget.TextView;
|
|
20
|
-
|
|
21
|
-
import org.json.JSONArray;
|
|
22
|
-
import org.json.JSONException;
|
|
23
|
-
import org.json.JSONObject;
|
|
24
|
-
|
|
25
|
-
import java.util.ArrayList;
|
|
26
|
-
import java.util.List;
|
|
27
|
-
|
|
28
|
-
import io.anyline.camera.CameraConfig;
|
|
29
|
-
import io.anyline.camera.CameraController;
|
|
30
|
-
import io.anyline.camera.CameraFeatures;
|
|
31
|
-
import io.anyline.camera.CameraOpenListener;
|
|
32
|
-
import io.anyline.plugin.barcode.BarcodeScanViewPlugin;
|
|
33
|
-
import io.anyline.plugin.id.IdScanViewPlugin;
|
|
34
|
-
import io.anyline.plugin.licenseplate.LicensePlateScanViewPlugin;
|
|
35
|
-
import io.anyline.plugin.meter.MeterScanViewPlugin;
|
|
36
|
-
import io.anyline.plugin.ocr.OcrScanViewPlugin;
|
|
37
|
-
import io.anyline.view.AbstractBaseScanViewPlugin;
|
|
38
|
-
import io.anyline.view.ParallelScanViewComposite;
|
|
39
|
-
import io.anyline.view.SerialScanViewComposite;
|
|
40
|
-
|
|
41
|
-
public abstract class AnylineBaseActivity extends Activity implements CameraOpenListener, Thread.UncaughtExceptionHandler {
|
|
42
|
-
|
|
43
|
-
private static final String TAG = AnylineBaseActivity.class.getSimpleName();
|
|
44
|
-
|
|
45
|
-
protected String licenseKey;
|
|
46
|
-
protected String configJson;
|
|
47
|
-
|
|
48
|
-
@Override
|
|
49
|
-
protected void onCreate(Bundle savedInstanceState) {
|
|
50
|
-
super.onCreate(savedInstanceState);
|
|
51
|
-
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
52
|
-
|
|
53
|
-
licenseKey = getIntent().getStringExtra(AnylineSDKPlugin.EXTRA_LICENSE_KEY);
|
|
54
|
-
configJson = getIntent().getStringExtra(AnylineSDKPlugin.EXTRA_CONFIG_JSON);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Always set this like this after the initAnyline: <br/>
|
|
59
|
-
* scanView.getAnylineController().setWorkerThreadUncaughtExceptionHandler(this);<br/>
|
|
60
|
-
* <br/>
|
|
61
|
-
* This will forward background errors back to the plugin (and back to javascript from there)
|
|
62
|
-
*/
|
|
63
|
-
@Override
|
|
64
|
-
public void uncaughtException(Thread thread, Throwable e) {
|
|
65
|
-
String msg = e.getMessage();
|
|
66
|
-
Log.e(TAG, "Cached uncaught exception", e);
|
|
67
|
-
|
|
68
|
-
String errorMessage;
|
|
69
|
-
if (msg.contains("license") || msg.contains("License")) {
|
|
70
|
-
errorMessage = "error_licence_invalid";
|
|
71
|
-
} else {
|
|
72
|
-
errorMessage = "error_occured";
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
finishWithError(errorMessage);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
protected void finishWithError(String errorMessage) {
|
|
79
|
-
Intent data = new Intent();
|
|
80
|
-
data.putExtra(AnylineSDKPlugin.EXTRA_ERROR_MESSAGE, errorMessage);
|
|
81
|
-
setResult(AnylineSDKPlugin.RESULT_ERROR, data);
|
|
82
|
-
ResultReporter.onError(errorMessage);
|
|
83
|
-
finish();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
@Override
|
|
87
|
-
public void onCameraOpened(CameraController cameraController, int width, int height) {
|
|
88
|
-
Log.d(TAG, "Camera opened. Frame size " + width + " x " + height + ".");
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
@Override
|
|
92
|
-
public void onCameraError(Exception e) {
|
|
93
|
-
finishWithError("error_accessing_camera");
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
@Override
|
|
98
|
-
public void onBackPressed() {
|
|
99
|
-
ResultReporter.onCancel();
|
|
100
|
-
super.onBackPressed();
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
protected String jsonForOutline(List<PointF> pointList) {
|
|
104
|
-
|
|
105
|
-
JSONObject upLeft = new JSONObject();
|
|
106
|
-
JSONObject upRight = new JSONObject();
|
|
107
|
-
JSONObject downRight = new JSONObject();
|
|
108
|
-
JSONObject downLeft = new JSONObject();
|
|
109
|
-
JSONObject outline = new JSONObject();
|
|
110
|
-
|
|
111
|
-
try {
|
|
112
|
-
upLeft.put("x", pointList.get(0).x);
|
|
113
|
-
upLeft.put("y", pointList.get(0).y);
|
|
114
|
-
|
|
115
|
-
upRight.put("x", pointList.get(1).x);
|
|
116
|
-
upRight.put("y", pointList.get(1).y);
|
|
117
|
-
|
|
118
|
-
downRight.put("x", pointList.get(2).x);
|
|
119
|
-
downRight.put("y", pointList.get(2).y);
|
|
120
|
-
|
|
121
|
-
downLeft.put("x", pointList.get(3).x);
|
|
122
|
-
downLeft.put("y", pointList.get(3).y);
|
|
123
|
-
|
|
124
|
-
outline.put("upLeft", upLeft);
|
|
125
|
-
outline.put("upRight", upRight);
|
|
126
|
-
outline.put("downRight", downRight);
|
|
127
|
-
outline.put("downLeft", downLeft);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
} catch (JSONException e) {
|
|
131
|
-
Log.d(TAG, e.toString());
|
|
132
|
-
e.printStackTrace();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return outline.toString();
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
protected TextView getLabelView(Context context) {
|
|
140
|
-
|
|
141
|
-
TextView labelView = new TextView(context);
|
|
142
|
-
|
|
143
|
-
try {
|
|
144
|
-
JSONObject jsonObject = new JSONObject(configJson);
|
|
145
|
-
JSONObject labelObject = jsonObject.getJSONObject("label");
|
|
146
|
-
labelView.setText(labelObject.getString("text"));
|
|
147
|
-
labelView.setTextColor(Color.parseColor("#" + labelObject.getString("color")));
|
|
148
|
-
labelView.setTextSize(Float.parseFloat(labelObject.getString("size")));
|
|
149
|
-
} catch (Exception e) {
|
|
150
|
-
e.printStackTrace();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return labelView;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
protected ArrayList getArrayListFromJsonArray(JSONArray jsonObject) {
|
|
157
|
-
ArrayList<Double> listdata = new ArrayList<Double>();
|
|
158
|
-
JSONArray jArray = jsonObject;
|
|
159
|
-
try {
|
|
160
|
-
for (int i = 0; i < jArray.length(); i++) {
|
|
161
|
-
listdata.add(jArray.getDouble(i));
|
|
162
|
-
}
|
|
163
|
-
} catch (JSONException e) {
|
|
164
|
-
e.printStackTrace();
|
|
165
|
-
}
|
|
166
|
-
return listdata;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
protected RelativeLayout.LayoutParams getTextLayoutParams() {
|
|
171
|
-
// Defining the RelativeLayout layout parameters.
|
|
172
|
-
// In this case I want to fill its parent
|
|
173
|
-
return new RelativeLayout.LayoutParams(
|
|
174
|
-
RelativeLayout.LayoutParams.MATCH_PARENT,
|
|
175
|
-
RelativeLayout.LayoutParams.MATCH_PARENT);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
protected RelativeLayout.LayoutParams getWrapContentLayoutParams() {
|
|
179
|
-
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
|
|
180
|
-
RelativeLayout.LayoutParams.WRAP_CONTENT,
|
|
181
|
-
RelativeLayout.LayoutParams.WRAP_CONTENT);
|
|
182
|
-
lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
|
|
183
|
-
return lp;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
protected void setFocusConfig(JSONObject json, CameraConfig camConfig) throws JSONException {
|
|
188
|
-
|
|
189
|
-
if (json.has("focus")) {
|
|
190
|
-
JSONObject focusConfig = json.getJSONObject("focus");
|
|
191
|
-
|
|
192
|
-
// change default focus mode to auto (works better if cutout is not in the center)
|
|
193
|
-
switch (focusConfig.getString("mode")) {
|
|
194
|
-
case ("AUTO"):
|
|
195
|
-
default:
|
|
196
|
-
camConfig.setFocusMode(CameraFeatures.FocusMode.AUTO);
|
|
197
|
-
break;
|
|
198
|
-
case ("MACRO"):
|
|
199
|
-
camConfig.setFocusMode(CameraFeatures.FocusMode.MACRO);
|
|
200
|
-
break;
|
|
201
|
-
case ("CONTINUOUS_PICTURE"):
|
|
202
|
-
camConfig.setFocusMode(CameraFeatures.FocusMode.CONTINUOUS_PICTURE);
|
|
203
|
-
break;
|
|
204
|
-
case ("CONTINUOUS_VIDEO"):
|
|
205
|
-
camConfig.setFocusMode(CameraFeatures.FocusMode.CONTINUOUS_VIDEO);
|
|
206
|
-
break;
|
|
207
|
-
case ("EDOF"):
|
|
208
|
-
camConfig.setFocusMode(CameraFeatures.FocusMode.EDOF);
|
|
209
|
-
break;
|
|
210
|
-
case ("FIXED"):
|
|
211
|
-
camConfig.setFocusMode(CameraFeatures.FocusMode.FIXED);
|
|
212
|
-
break;
|
|
213
|
-
case ("INFINITY"):
|
|
214
|
-
camConfig.setFocusMode(CameraFeatures.FocusMode.INFINITY);
|
|
215
|
-
break;
|
|
216
|
-
case ("OFF"):
|
|
217
|
-
camConfig.setFocusMode(CameraFeatures.FocusMode.OFF);
|
|
218
|
-
break;
|
|
219
|
-
}
|
|
220
|
-
// autofocus is called in this interval (8000 is default)
|
|
221
|
-
if (focusConfig.has("interval")) {
|
|
222
|
-
camConfig.setAutoFocusInterval(focusConfig.getInt("interval"));
|
|
223
|
-
}
|
|
224
|
-
// call autofocus if view is touched (true is default)
|
|
225
|
-
if (focusConfig.has("touchEnabled")) {
|
|
226
|
-
camConfig.setFocusOnTouchEnabled(focusConfig.getBoolean("touchEnabled"));
|
|
227
|
-
}
|
|
228
|
-
// focus where the cutout is (true is default)
|
|
229
|
-
if (focusConfig.has("regionEnabled")) {
|
|
230
|
-
camConfig.setFocusRegionEnabled(focusConfig.getBoolean("regionEnabled"));
|
|
231
|
-
}
|
|
232
|
-
// automatic exposure calculation based on where the cutout is (true is default)
|
|
233
|
-
if (focusConfig.has("autoExposureRegionEnabled")) {
|
|
234
|
-
camConfig.setAutoExposureRegionEnabled(focusConfig.getBoolean("autoExposureRegionEnabled"));
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
protected void setResult(AbstractBaseScanViewPlugin scanViewPlugin, JSONObject jsonResult) {
|
|
240
|
-
Boolean isCancelOnResult = true;
|
|
241
|
-
if (scanViewPlugin instanceof MeterScanViewPlugin) {
|
|
242
|
-
isCancelOnResult = ((MeterScanViewPlugin) scanViewPlugin).getScanViewPluginConfig().isCancelOnResult();
|
|
243
|
-
} else if (scanViewPlugin instanceof BarcodeScanViewPlugin) {
|
|
244
|
-
isCancelOnResult = ((BarcodeScanViewPlugin) scanViewPlugin).getScanViewPluginConfig().isCancelOnResult();
|
|
245
|
-
} else if (scanViewPlugin instanceof IdScanViewPlugin) {
|
|
246
|
-
isCancelOnResult = ((IdScanViewPlugin) scanViewPlugin).getScanViewPluginConfig().isCancelOnResult();
|
|
247
|
-
} else if (scanViewPlugin instanceof LicensePlateScanViewPlugin) {
|
|
248
|
-
isCancelOnResult = ((LicensePlateScanViewPlugin) scanViewPlugin).getScanViewPluginConfig().isCancelOnResult();
|
|
249
|
-
} else if (scanViewPlugin instanceof OcrScanViewPlugin) {
|
|
250
|
-
isCancelOnResult = ((OcrScanViewPlugin) scanViewPlugin).getScanViewPluginConfig().isCancelOnResult();
|
|
251
|
-
} else if (scanViewPlugin instanceof SerialScanViewComposite) {
|
|
252
|
-
isCancelOnResult = ((SerialScanViewComposite) scanViewPlugin).getScanViewPluginConfig().isCancelOnResult();
|
|
253
|
-
} else if (scanViewPlugin instanceof ParallelScanViewComposite) {
|
|
254
|
-
isCancelOnResult = ((ParallelScanViewComposite) scanViewPlugin).getScanViewPluginConfig().isCancelOnResult();
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
if (scanViewPlugin != null && isCancelOnResult) {
|
|
258
|
-
ResultReporter.onResult(jsonResult, true);
|
|
259
|
-
setResult(AnylineSDKPlugin.RESULT_OK);
|
|
260
|
-
finish();
|
|
261
|
-
} else {
|
|
262
|
-
ResultReporter.onResult(jsonResult, false);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
}
|
|
@@ -1,324 +0,0 @@
|
|
|
1
|
-
package com.anyline.reactnative;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
import android.util.Log;
|
|
5
|
-
import android.widget.Toast;
|
|
6
|
-
|
|
7
|
-
import com.google.mlkit.vision.barcode.Barcode;
|
|
8
|
-
|
|
9
|
-
import org.json.JSONArray;
|
|
10
|
-
import org.json.JSONException;
|
|
11
|
-
import org.json.JSONObject;
|
|
12
|
-
|
|
13
|
-
import java.io.File;
|
|
14
|
-
import java.io.IOException;
|
|
15
|
-
import java.util.ArrayList;
|
|
16
|
-
import java.util.List;
|
|
17
|
-
import java.util.Objects;
|
|
18
|
-
import java.util.UUID;
|
|
19
|
-
|
|
20
|
-
import io.anyline.camera.NativeBarcodeResultListener;
|
|
21
|
-
import io.anyline.plugin.ScanResult;
|
|
22
|
-
import io.anyline.plugin.barcode.BarcodeFormat;
|
|
23
|
-
import io.anyline.plugin.meter.MeterScanMode;
|
|
24
|
-
import io.anyline.util.AssetUtil;
|
|
25
|
-
import io.anyline.util.TempFileUtil;
|
|
26
|
-
import io.anyline.view.ScanView;
|
|
27
|
-
|
|
28
|
-
public class AnylinePluginHelper {
|
|
29
|
-
|
|
30
|
-
private static final String TAG = AnylinePluginHelper.class.getSimpleName();
|
|
31
|
-
|
|
32
|
-
private static Toast notificationToast;
|
|
33
|
-
private static boolean nativeBarcodeEnabled = false;
|
|
34
|
-
private static List<Barcode> finalBarcodeList;
|
|
35
|
-
|
|
36
|
-
public static JSONObject setLanguages(JSONObject json, Context context) {
|
|
37
|
-
if (json.has("viewPlugin")) {
|
|
38
|
-
try {
|
|
39
|
-
JSONObject viewPlugin = json.getJSONObject("viewPlugin");
|
|
40
|
-
if (viewPlugin != null && viewPlugin.has("plugin")) {
|
|
41
|
-
|
|
42
|
-
JSONObject plugin = viewPlugin.getJSONObject("plugin");
|
|
43
|
-
if (plugin != null && plugin.has("ocrPlugin")) {
|
|
44
|
-
JSONObject ocrScanPlugin = plugin.getJSONObject("ocrPlugin");
|
|
45
|
-
{
|
|
46
|
-
JSONArray tesseractArray = ocrScanPlugin.optJSONArray("languages");
|
|
47
|
-
if (tesseractArray == null) {
|
|
48
|
-
if (ocrScanPlugin.has("ocrConfig")) {
|
|
49
|
-
JSONObject ocrConfig = ocrScanPlugin.getJSONObject("ocrConfig");
|
|
50
|
-
tesseractArray = ocrConfig.optJSONArray("languages");
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
JSONArray newLanguagesArray = new JSONArray();
|
|
54
|
-
if (tesseractArray != null) {
|
|
55
|
-
String[] languages = new String[tesseractArray.length()];
|
|
56
|
-
for (int i = 0; i < languages.length; i++) {
|
|
57
|
-
long start = System.currentTimeMillis();
|
|
58
|
-
|
|
59
|
-
String traineddataFilePath = tesseractArray.getString(i);
|
|
60
|
-
String fileExtension = traineddataFilePath
|
|
61
|
-
.substring(traineddataFilePath.lastIndexOf(".") + 1);
|
|
62
|
-
|
|
63
|
-
// Check where to copy the training files
|
|
64
|
-
File dirToCopy = new File(context.getFilesDir(),
|
|
65
|
-
"anyline/module_anyline_ocr/tessdata/");
|
|
66
|
-
if (Objects.equals(fileExtension, "any")) {
|
|
67
|
-
dirToCopy = new File(context.getFilesDir(),
|
|
68
|
-
"anyline/module_anyline_ocr/trained_models/");
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
int lastFileSeparatorIndex = traineddataFilePath.lastIndexOf(File.separator);
|
|
72
|
-
int lastDotIndex = traineddataFilePath.lastIndexOf(".");
|
|
73
|
-
if (lastDotIndex > lastFileSeparatorIndex) {
|
|
74
|
-
// start after the "/" or with 0 if no fileseperator was found
|
|
75
|
-
languages[i] = traineddataFilePath.substring(lastFileSeparatorIndex + 1);
|
|
76
|
-
} else {
|
|
77
|
-
// maybe it should just fail here, case propably not useful
|
|
78
|
-
languages[i] = traineddataFilePath.substring(lastFileSeparatorIndex + 1);
|
|
79
|
-
}
|
|
80
|
-
newLanguagesArray.put(languages[i]);
|
|
81
|
-
Log.d("languages", languages[i]);
|
|
82
|
-
AssetUtil.copyAssetFileWithoutPath(context, traineddataFilePath, dirToCopy, false);
|
|
83
|
-
Log.v(TAG, "Copy traineddata duration: " + (System.currentTimeMillis() - start));
|
|
84
|
-
}
|
|
85
|
-
ocrScanPlugin.put("languages", newLanguagesArray);
|
|
86
|
-
|
|
87
|
-
} else {
|
|
88
|
-
Log.d(TAG, "No Training Data");
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
} catch (JSONException e) {
|
|
94
|
-
e.printStackTrace();
|
|
95
|
-
} catch (IOException e) {
|
|
96
|
-
e.printStackTrace();
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return json;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
public static void setNativeBarcodeMode(JSONObject jsonObject, ScanView anylineScanView) {
|
|
103
|
-
boolean nativeBarcodeEnabledJson = false;
|
|
104
|
-
if (jsonObject.has("nativeBarcodeEnabled")) {
|
|
105
|
-
try {
|
|
106
|
-
nativeBarcodeEnabledJson = jsonObject.getBoolean("nativeBarcodeEnabled");
|
|
107
|
-
if (nativeBarcodeEnabledJson) {
|
|
108
|
-
enableNativeBarcode(anylineScanView, null);
|
|
109
|
-
}
|
|
110
|
-
} catch (JSONException e) {
|
|
111
|
-
e.printStackTrace();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
nativeBarcodeEnabled = nativeBarcodeEnabledJson;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
public static boolean getNativeBarcodeMode() {
|
|
118
|
-
return nativeBarcodeEnabled;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
public static void clearFinalBarcodeList() {
|
|
122
|
-
finalBarcodeList = null;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
public static JSONArray arrayOfDetectedBarcodes() {
|
|
126
|
-
|
|
127
|
-
if (nativeBarcodeEnabled) {
|
|
128
|
-
// List<Barcode> finalBarcodeList = new ArrayList<>();
|
|
129
|
-
//finalBarcodeList = AnylinePluginHelper.getNativeBarcodeList();
|
|
130
|
-
final JSONArray jsonArray = new JSONArray();
|
|
131
|
-
if (finalBarcodeList != null) {
|
|
132
|
-
for (int i = 0; i < finalBarcodeList.size(); i++) {
|
|
133
|
-
jsonArray.put(AnylinePluginHelper.wrapBarcodeInJson(finalBarcodeList.get(i)));
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return jsonArray;
|
|
137
|
-
}
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
public static JSONObject jsonHelper(Anyline4Activity activity, ScanResult<?> scanResult, JSONObject jsonObject) {
|
|
142
|
-
try {
|
|
143
|
-
File imageFile = TempFileUtil.createTempFileCheckCache(activity, UUID.randomUUID().toString(), ".jpg");
|
|
144
|
-
scanResult.getCutoutImage().save(imageFile, 90);
|
|
145
|
-
jsonObject.put("imagePath", imageFile.getAbsolutePath());
|
|
146
|
-
|
|
147
|
-
if (scanResult.getBlobKey() != null) {
|
|
148
|
-
jsonObject.put("blobKey", scanResult.getBlobKey());
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
File imageFileFull = TempFileUtil.createTempFileCheckCache(activity, UUID.randomUUID().toString(), ".jpg");
|
|
152
|
-
scanResult.getFullImage().save(imageFileFull, 90);
|
|
153
|
-
jsonObject.put("fullImagePath", imageFileFull.getAbsolutePath());
|
|
154
|
-
|
|
155
|
-
if (scanResult.getOutline() != null) {
|
|
156
|
-
jsonObject.put("outline", activity.jsonForOutline(scanResult.getOutline()));
|
|
157
|
-
}
|
|
158
|
-
if (scanResult.getConfidence() != null) {
|
|
159
|
-
jsonObject.put("confidence", scanResult.getConfidence());
|
|
160
|
-
|
|
161
|
-
if (nativeBarcodeEnabled) {
|
|
162
|
-
JSONArray barcodeArray = arrayOfDetectedBarcodes();
|
|
163
|
-
|
|
164
|
-
if (barcodeArray.length() > 0) {
|
|
165
|
-
jsonObject.put("detectedBarcodes", barcodeArray);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
} catch (IOException e) {
|
|
170
|
-
Log.e(TAG, "Image file could not be saved.", e);
|
|
171
|
-
|
|
172
|
-
} catch (JSONException jsonException) {
|
|
173
|
-
// should not be possible
|
|
174
|
-
Log.e(TAG, "Error while putting image path to json.", jsonException);
|
|
175
|
-
}
|
|
176
|
-
return jsonObject;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
public static JSONObject wrapBarcodeInJson(Barcode b) {
|
|
180
|
-
JSONObject json = new JSONObject();
|
|
181
|
-
|
|
182
|
-
try {
|
|
183
|
-
json.put("value", b.getDisplayValue());
|
|
184
|
-
json.put("format", findValidFormatForReference(b.getFormat()));
|
|
185
|
-
} catch (JSONException jsonException) {
|
|
186
|
-
// should not be possible
|
|
187
|
-
Log.e(TAG, "Error while putting image path to json.", jsonException);
|
|
188
|
-
}
|
|
189
|
-
return json;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
private static List<Barcode> getNativeBarcodeList() {
|
|
193
|
-
return finalBarcodeList;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
private static void setNativeBarcodeList(List<Barcode> barcodes) {
|
|
197
|
-
final List<Barcode> barcodeList = new ArrayList<>();
|
|
198
|
-
final List<String> barcodesDisplayedVal = new ArrayList<>();
|
|
199
|
-
|
|
200
|
-
if (barcodeList.size() == 0) {
|
|
201
|
-
barcodeList.add(barcodes.get(0));
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (barcodes != null && barcodes.size() > 0) {
|
|
205
|
-
barcodesDisplayedVal.add(barcodes.get(0).getDisplayValue());
|
|
206
|
-
|
|
207
|
-
for (int i = 0; i < barcodes.size(); i++) {
|
|
208
|
-
if (!barcodesDisplayedVal.contains(barcodes.get(i).getDisplayValue())) {
|
|
209
|
-
barcodeList.add(barcodes.get(i));
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
finalBarcodeList = barcodeList;
|
|
216
|
-
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
private static String findValidFormatForReference(int format) {
|
|
220
|
-
if (format == Barcode.FORMAT_AZTEC) {
|
|
221
|
-
return BarcodeFormat.AZTEC.toString();
|
|
222
|
-
}
|
|
223
|
-
if (format == Barcode.FORMAT_CODABAR) {
|
|
224
|
-
return BarcodeFormat.CODABAR.toString();
|
|
225
|
-
}
|
|
226
|
-
if (format == Barcode.FORMAT_CODE_39) {
|
|
227
|
-
return BarcodeFormat.CODE_39.toString();
|
|
228
|
-
}
|
|
229
|
-
if (format == Barcode.FORMAT_CODE_93) {
|
|
230
|
-
return BarcodeFormat.CODE_93.toString();
|
|
231
|
-
}
|
|
232
|
-
if (format == Barcode.FORMAT_CODE_128) {
|
|
233
|
-
return BarcodeFormat.CODE_128.toString();
|
|
234
|
-
}
|
|
235
|
-
if (format == Barcode.FORMAT_DATA_MATRIX) {
|
|
236
|
-
return BarcodeFormat.DATA_MATRIX.toString();
|
|
237
|
-
}
|
|
238
|
-
if (format == Barcode.FORMAT_EAN_8) {
|
|
239
|
-
return BarcodeFormat.EAN_8.toString();
|
|
240
|
-
}
|
|
241
|
-
if (format == Barcode.FORMAT_EAN_13) {
|
|
242
|
-
return BarcodeFormat.EAN_13.toString();
|
|
243
|
-
}
|
|
244
|
-
if (format == Barcode.FORMAT_ITF) {
|
|
245
|
-
return BarcodeFormat.ITF.toString();
|
|
246
|
-
}
|
|
247
|
-
if (format == Barcode.FORMAT_PDF417) {
|
|
248
|
-
return BarcodeFormat.PDF_417.toString();
|
|
249
|
-
}
|
|
250
|
-
if (format == Barcode.FORMAT_QR_CODE) {
|
|
251
|
-
return BarcodeFormat.QR_CODE.toString();
|
|
252
|
-
}
|
|
253
|
-
if (format == Barcode.FORMAT_UPC_A) {
|
|
254
|
-
return BarcodeFormat.UPC_A.toString();
|
|
255
|
-
}
|
|
256
|
-
if (format == Barcode.FORMAT_UPC_E) {
|
|
257
|
-
return BarcodeFormat.UPC_E.toString();
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
// others are currently not supported by the native scanner (RSS_14,
|
|
261
|
-
// RSS_EXPANDED, UPC_EAN_EXTENSION)
|
|
262
|
-
return BarcodeFormat.UNKNOWN.toString();
|
|
263
|
-
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
public static void enableNativeBarcode(ScanView anylineScanView, final List<BarcodeFormat> barcodeFormats) {
|
|
267
|
-
anylineScanView.getCameraView().enableBarcodeDetection(new NativeBarcodeResultListener() {
|
|
268
|
-
@Override
|
|
269
|
-
public void onFailure(String e) {
|
|
270
|
-
//finalBarcodeList=null; // otherwise result from previous scan would be shown
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
@Override
|
|
274
|
-
public void onSuccess(List<Barcode> barcodes) {
|
|
275
|
-
setNativeBarcodeList(barcodes);
|
|
276
|
-
}
|
|
277
|
-
}, barcodeFormats);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
protected static void showToast(String st, Context context) {
|
|
281
|
-
try {
|
|
282
|
-
notificationToast.getView().isShown();
|
|
283
|
-
notificationToast.setText(st);
|
|
284
|
-
} catch (Exception e) {
|
|
285
|
-
notificationToast = Toast.makeText(context, st, Toast.LENGTH_SHORT);
|
|
286
|
-
}
|
|
287
|
-
notificationToast.show();
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
// Meter helper
|
|
291
|
-
public static JSONObject setMeterScanMode(MeterScanMode scanMode, JSONObject jsonResult) {
|
|
292
|
-
try {
|
|
293
|
-
switch (scanMode) {
|
|
294
|
-
case DIGITAL_METER:
|
|
295
|
-
jsonResult.put("meterType", "Digital Meter");
|
|
296
|
-
break;
|
|
297
|
-
case DIAL_METER:
|
|
298
|
-
jsonResult.put("meterType", "Dial Meter");
|
|
299
|
-
break;
|
|
300
|
-
case ANALOG_METER:
|
|
301
|
-
jsonResult.put("meterType", "Analog Meter");
|
|
302
|
-
break;
|
|
303
|
-
case AUTO_ANALOG_DIGITAL_METER:
|
|
304
|
-
jsonResult.put("meterType", "Auto Analog Digital Meter");
|
|
305
|
-
break;
|
|
306
|
-
case SERIAL_NUMBER:
|
|
307
|
-
jsonResult.put("meterType", "Serial Number");
|
|
308
|
-
break;
|
|
309
|
-
case DOT_MATRIX_METER:
|
|
310
|
-
jsonResult.put("meterType", "Dot Matrix Meter");
|
|
311
|
-
break;
|
|
312
|
-
default:
|
|
313
|
-
jsonResult.put("meterType", "Electric Meter");
|
|
314
|
-
break;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
jsonResult.put("scanMode", scanMode.toString());
|
|
318
|
-
} catch (JSONException e) {
|
|
319
|
-
e.printStackTrace();
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
return jsonResult;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
package com.anyline.reactnative;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
import android.graphics.Color;
|
|
5
|
-
|
|
6
|
-
import org.json.JSONArray;
|
|
7
|
-
import org.json.JSONException;
|
|
8
|
-
import org.json.JSONObject;
|
|
9
|
-
|
|
10
|
-
import java.util.ArrayList;
|
|
11
|
-
|
|
12
|
-
public class AnylineUIConfig {
|
|
13
|
-
|
|
14
|
-
public static final String SEGMENT = "segment";
|
|
15
|
-
public static final String SEGMENT_TITLES = "titles";
|
|
16
|
-
public static final String SEGMENT_MODES = "modes";
|
|
17
|
-
public static final String SEGMENT_TINT_COLOR = "tintColor";
|
|
18
|
-
public static final String SEGMENT_OFFSET = "offset";
|
|
19
|
-
public static final String SEGMENT_X = "x";
|
|
20
|
-
public static final String SEGMENT_Y = "y";
|
|
21
|
-
|
|
22
|
-
private ArrayList<String> titles = null;
|
|
23
|
-
private ArrayList<String> modes = null;
|
|
24
|
-
|
|
25
|
-
private int tintColor = 0;
|
|
26
|
-
|
|
27
|
-
private int offsetX = 0;
|
|
28
|
-
private int offsetY = 0;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Create config from the given json object.
|
|
32
|
-
*
|
|
33
|
-
* @param context the context
|
|
34
|
-
* @param jsonObject the json object with the settings
|
|
35
|
-
*/
|
|
36
|
-
public AnylineUIConfig(Context context, JSONObject jsonObject) {
|
|
37
|
-
initFromJsonObject(context, jsonObject);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
private void initFromJsonObject(Context context, JSONObject json) {
|
|
41
|
-
JSONObject segment = json.optJSONObject(SEGMENT);
|
|
42
|
-
|
|
43
|
-
if (segment != null) {
|
|
44
|
-
try {
|
|
45
|
-
JSONArray titlesJson = segment.getJSONArray(SEGMENT_TITLES);
|
|
46
|
-
JSONArray modesJson = segment.getJSONArray(SEGMENT_MODES);
|
|
47
|
-
|
|
48
|
-
titles = new ArrayList<String>();
|
|
49
|
-
modes = new ArrayList<String>();
|
|
50
|
-
for (int i = 0; i < titlesJson.length(); i++) {
|
|
51
|
-
titles.add(titlesJson.get(i).toString());
|
|
52
|
-
modes.add(modesJson.get(i).toString());
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
tintColor = Color.parseColor("#" + segment.optString(SEGMENT_TINT_COLOR));
|
|
56
|
-
|
|
57
|
-
JSONObject offsetJson = segment.optJSONObject(SEGMENT_OFFSET);
|
|
58
|
-
if (offsetJson != null) {
|
|
59
|
-
offsetX = offsetJson.optInt(SEGMENT_X);
|
|
60
|
-
offsetY = offsetJson.optInt(SEGMENT_Y);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
} catch (JSONException e) {
|
|
64
|
-
e.printStackTrace();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public ArrayList<String> getTitles() {
|
|
70
|
-
return titles;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
public ArrayList<String> getModes() {
|
|
74
|
-
return modes;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
public int getTintColor() {
|
|
78
|
-
return tintColor;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
public int getOffsetX() {
|
|
82
|
-
return offsetX;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public int getOffsetY() {
|
|
86
|
-
return offsetY;
|
|
87
|
-
}
|
|
88
|
-
}
|