anyline-ocr-react-native-module 42.2.0 → 43.0.0
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/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 -71
- 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/6.7/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/6.7/fileChanges/last-build.bin +0 -0
- package/android/.gradle/6.7/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/6.7/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/6.7/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- 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/.gradle/configuration-cache/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.idea/compiler.xml +0 -6
- package/android/.idea/gradle.xml +0 -18
- package/android/.idea/jarRepositories.xml +0 -35
- package/android/.idea/misc.xml +0 -10
- package/android/.idea/vcs.xml +0 -6
- package/android/.settings/org.eclipse.buildship.core.prefs +0 -13
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/local.properties +0 -8
- 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,621 +0,0 @@
|
|
|
1
|
-
package com.anyline.reactnative;
|
|
2
|
-
|
|
3
|
-
import android.content.pm.ActivityInfo;
|
|
4
|
-
import android.content.res.ColorStateList;
|
|
5
|
-
import android.graphics.Rect;
|
|
6
|
-
import android.os.Build;
|
|
7
|
-
import android.os.Bundle;
|
|
8
|
-
import android.os.Handler;
|
|
9
|
-
import android.util.Log;
|
|
10
|
-
import android.view.View;
|
|
11
|
-
import android.widget.Button;
|
|
12
|
-
import android.widget.RadioButton;
|
|
13
|
-
import android.widget.RadioGroup;
|
|
14
|
-
import android.widget.RelativeLayout;
|
|
15
|
-
|
|
16
|
-
import org.json.JSONArray;
|
|
17
|
-
import org.json.JSONException;
|
|
18
|
-
import org.json.JSONObject;
|
|
19
|
-
|
|
20
|
-
import java.util.ArrayList;
|
|
21
|
-
import java.util.Collection;
|
|
22
|
-
import java.util.HashMap;
|
|
23
|
-
import java.util.List;
|
|
24
|
-
|
|
25
|
-
import at.nineyards.anyline.core.LicenseException;
|
|
26
|
-
import at.nineyards.anyline.core.RunFailure;
|
|
27
|
-
import at.nineyards.anyline.core.Vector_Contour;
|
|
28
|
-
import at.nineyards.anyline.core.exception_error_codes;
|
|
29
|
-
import io.anyline.AnylineDebugListener;
|
|
30
|
-
import io.anyline.AnylineSDK;
|
|
31
|
-
import io.anyline.camera.CameraController;
|
|
32
|
-
import io.anyline.plugin.ScanResult;
|
|
33
|
-
import io.anyline.plugin.ScanResultListener;
|
|
34
|
-
import io.anyline.plugin.barcode.Barcode;
|
|
35
|
-
import io.anyline.plugin.barcode.BarcodeScanPlugin;
|
|
36
|
-
import io.anyline.plugin.barcode.BarcodeScanResult;
|
|
37
|
-
import io.anyline.plugin.barcode.BarcodeScanViewPlugin;
|
|
38
|
-
import io.anyline.plugin.barcode.PDF417;
|
|
39
|
-
import io.anyline.plugin.id.ID;
|
|
40
|
-
import io.anyline.plugin.id.IdScanPlugin;
|
|
41
|
-
import io.anyline.plugin.id.IdScanViewPlugin;
|
|
42
|
-
import io.anyline.plugin.id.Identification;
|
|
43
|
-
import io.anyline.plugin.id.MrzConfig;
|
|
44
|
-
import io.anyline.plugin.id.MrzIdentification;
|
|
45
|
-
import io.anyline.plugin.id.UniversalIdConfig;
|
|
46
|
-
import io.anyline.plugin.licenseplate.LicensePlateScanResult;
|
|
47
|
-
import io.anyline.plugin.licenseplate.LicensePlateScanViewPlugin;
|
|
48
|
-
import io.anyline.plugin.meter.MeterScanMode;
|
|
49
|
-
import io.anyline.plugin.meter.MeterScanResult;
|
|
50
|
-
import io.anyline.plugin.meter.MeterScanViewPlugin;
|
|
51
|
-
import io.anyline.plugin.ocr.OcrScanResult;
|
|
52
|
-
import io.anyline.plugin.ocr.OcrScanViewPlugin;
|
|
53
|
-
import io.anyline.plugin.tire.TireScanResult;
|
|
54
|
-
import io.anyline.plugin.tire.TireScanViewPlugin;
|
|
55
|
-
import io.anyline.view.AbstractBaseScanViewPlugin;
|
|
56
|
-
import io.anyline.plugin.tire.TireSizeScanResult;
|
|
57
|
-
import io.anyline.view.CutoutRect;
|
|
58
|
-
import io.anyline.view.ParallelScanViewComposite;
|
|
59
|
-
import io.anyline.view.ScanView;
|
|
60
|
-
import io.anyline.view.SerialScanViewComposite;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
public class Anyline4Activity extends AnylineBaseActivity {
|
|
64
|
-
private static final String TAG = Anyline4Activity.class.getSimpleName();
|
|
65
|
-
private static final String KEY_DEFAULT_ORIENTATION_APPLIED = "default_orientation_applied";
|
|
66
|
-
private ScanView anylineScanView;
|
|
67
|
-
private AbstractBaseScanViewPlugin scanViewPlugin;
|
|
68
|
-
private RadioGroup radioGroup;
|
|
69
|
-
private AnylineUIConfig anylineUIConfig;
|
|
70
|
-
private String cropAndTransformError;
|
|
71
|
-
private Boolean isFirstCameraOpen; // only if camera is opened the first time get coordinates of the cutout to avoid flickering when switching between analog and digital
|
|
72
|
-
private RelativeLayout parentLayout;
|
|
73
|
-
private boolean defaultOrientationApplied;
|
|
74
|
-
|
|
75
|
-
@Override
|
|
76
|
-
protected void onCreate(Bundle savedInstanceState) {
|
|
77
|
-
super.onCreate(savedInstanceState);
|
|
78
|
-
isFirstCameraOpen = true;
|
|
79
|
-
|
|
80
|
-
// init the scan view
|
|
81
|
-
anylineScanView = new ScanView(this, null);
|
|
82
|
-
parentLayout = new RelativeLayout(this);
|
|
83
|
-
|
|
84
|
-
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
|
|
85
|
-
RelativeLayout.LayoutParams.MATCH_PARENT,
|
|
86
|
-
RelativeLayout.LayoutParams.MATCH_PARENT);
|
|
87
|
-
parentLayout.addView(anylineScanView, layoutParams);
|
|
88
|
-
setContentView(parentLayout, layoutParams);
|
|
89
|
-
|
|
90
|
-
if (savedInstanceState != null) {
|
|
91
|
-
defaultOrientationApplied = savedInstanceState.getBoolean(KEY_DEFAULT_ORIENTATION_APPLIED);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
// start initialize anyline
|
|
96
|
-
initAnyline();
|
|
97
|
-
} catch (Exception ex) {
|
|
98
|
-
ex.printStackTrace();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
setDebugListener();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
@Override
|
|
105
|
-
protected void onSaveInstanceState(Bundle outState) {
|
|
106
|
-
super.onSaveInstanceState(outState);
|
|
107
|
-
outState.putBoolean(KEY_DEFAULT_ORIENTATION_APPLIED, defaultOrientationApplied);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
@Override
|
|
111
|
-
protected void onResume() {
|
|
112
|
-
super.onResume();
|
|
113
|
-
// start scanning
|
|
114
|
-
anylineScanView.start();
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
@Override
|
|
118
|
-
protected void onPause() {
|
|
119
|
-
super.onPause();
|
|
120
|
-
|
|
121
|
-
// stop scanning
|
|
122
|
-
anylineScanView.stop();
|
|
123
|
-
anylineScanView.releaseCameraInBackground();
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
private void setDebugListener() {
|
|
127
|
-
if (scanViewPlugin != null) {
|
|
128
|
-
scanViewPlugin.setDebugListener(new AnylineDebugListener() {
|
|
129
|
-
@Override
|
|
130
|
-
public void onDebug(String name, Object value) {
|
|
131
|
-
|
|
132
|
-
if (name.equals(AnylineDebugListener.BRIGHTNESS_VARIABLE_NAME)
|
|
133
|
-
&& value.getClass().equals(AnylineDebugListener.BRIGHTNESS_VARIABLE_CLASS)) {
|
|
134
|
-
Double val = AnylineDebugListener.BRIGHTNESS_VARIABLE_CLASS.cast(value);
|
|
135
|
-
|
|
136
|
-
Log.d(TAG, name + ": " + val);
|
|
137
|
-
}
|
|
138
|
-
if (name.equals(CONTOURS_VARIABLE_NAME) && value.getClass().equals(CONTOURS_VARIABLE_CLASS)) {
|
|
139
|
-
Vector_Contour contour = CONTOURS_VARIABLE_CLASS.cast(value);
|
|
140
|
-
Log.d(TAG, name + ": " + contour.toString());
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
@Override
|
|
146
|
-
public void onRunSkipped(RunFailure runFailure) {
|
|
147
|
-
// Show Toast, if cropAndTransform is on true, but not all corners are detected
|
|
148
|
-
if (runFailure != null
|
|
149
|
-
&& runFailure.errorCode() == exception_error_codes.PointsOutOfCutout.swigValue()) {
|
|
150
|
-
AnylinePluginHelper.showToast(cropAndTransformError, getApplicationContext());
|
|
151
|
-
}
|
|
152
|
-
Log.w(TAG, "run skipped: " + runFailure);
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
private void initAnyline() {
|
|
159
|
-
try {
|
|
160
|
-
JSONObject json = new JSONObject(configJson);
|
|
161
|
-
// this is used for the OCR Plugin, when languages has to be added
|
|
162
|
-
json = AnylinePluginHelper.setLanguages(json, getApplicationContext());
|
|
163
|
-
|
|
164
|
-
try {
|
|
165
|
-
AnylineSDK.init(licenseKey, this);
|
|
166
|
-
} catch (LicenseException e) {
|
|
167
|
-
finishWithError(getString(getResources().getIdentifier("error_license_init", "string", getPackageName())));
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (json.has("serialViewPluginComposite") || json.has("parallelViewPluginComposite")) {
|
|
171
|
-
anylineScanView.initComposite(json); // for composite
|
|
172
|
-
scanViewPlugin = anylineScanView.getScanViewPlugin();
|
|
173
|
-
} else {
|
|
174
|
-
anylineScanView.setScanConfig(json); // for non-composite
|
|
175
|
-
}
|
|
176
|
-
if (anylineScanView != null) {
|
|
177
|
-
scanViewPlugin = anylineScanView.getScanViewPlugin();
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (shouldShowRotateButton(json)) {
|
|
181
|
-
RotateButtonConfig rotateButtonConfig = new RotateButtonConfig(json.getJSONObject("rotateButton"));
|
|
182
|
-
addRotateButtonToView(rotateButtonConfig);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
setDefaultOrientation(json);
|
|
186
|
-
|
|
187
|
-
if (scanViewPlugin != null) {
|
|
188
|
-
//set nativeBarcodeMode
|
|
189
|
-
AnylinePluginHelper.setNativeBarcodeMode(json, anylineScanView);
|
|
190
|
-
|
|
191
|
-
if (scanViewPlugin instanceof SerialScanViewComposite || scanViewPlugin instanceof ParallelScanViewComposite) {
|
|
192
|
-
scanViewPlugin.addScanResultListener(new ScanResultListener() {
|
|
193
|
-
@Override
|
|
194
|
-
public void onResult(ScanResult result) {
|
|
195
|
-
// only triggered if all plugins reached a result
|
|
196
|
-
JSONObject jsonResult = new JSONObject();
|
|
197
|
-
|
|
198
|
-
for (ScanResult subResult : (Collection<ScanResult>) result.getResult()) {
|
|
199
|
-
if (subResult instanceof LicensePlateScanResult) {
|
|
200
|
-
JSONObject jsonLPResult = new JSONObject();
|
|
201
|
-
try {
|
|
202
|
-
LicensePlateScanResult licensePlateResult = (LicensePlateScanResult) subResult;
|
|
203
|
-
jsonLPResult.put("country", licensePlateResult.getCountry());
|
|
204
|
-
jsonLPResult.put("licensePlate", licensePlateResult.getResult());
|
|
205
|
-
jsonLPResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, licensePlateResult,
|
|
206
|
-
jsonLPResult);
|
|
207
|
-
|
|
208
|
-
jsonResult.put(subResult.getPluginId(), jsonLPResult);
|
|
209
|
-
} catch (JSONException e) {
|
|
210
|
-
e.printStackTrace();
|
|
211
|
-
}
|
|
212
|
-
} else if (subResult.getResult() instanceof MrzIdentification) {
|
|
213
|
-
JSONObject jsonIdResult = ((MrzIdentification) subResult.getResult()).toJSONObject();
|
|
214
|
-
try {
|
|
215
|
-
if (jsonIdResult.get("issuingCountryCode").equals("D")
|
|
216
|
-
&& jsonIdResult.get("documentType").equals("ID")) {
|
|
217
|
-
if (jsonIdResult.get("issuingCountryCode").equals("D")) {
|
|
218
|
-
jsonIdResult.put("address", jsonResult.get("address"));
|
|
219
|
-
} else {
|
|
220
|
-
jsonIdResult.remove("address");
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
jsonIdResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, subResult,
|
|
224
|
-
jsonIdResult);
|
|
225
|
-
|
|
226
|
-
jsonResult.put(subResult.getPluginId(), jsonIdResult);
|
|
227
|
-
} catch (JSONException e) {
|
|
228
|
-
e.printStackTrace();
|
|
229
|
-
}
|
|
230
|
-
} else if (subResult instanceof OcrScanResult) {
|
|
231
|
-
JSONObject jsonOcrResult = new JSONObject();
|
|
232
|
-
try {
|
|
233
|
-
jsonOcrResult.put("text", (((OcrScanResult) subResult).getResult()).trim());
|
|
234
|
-
jsonOcrResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, subResult,
|
|
235
|
-
jsonOcrResult);
|
|
236
|
-
jsonResult.put(subResult.getPluginId(), jsonOcrResult);
|
|
237
|
-
} catch (JSONException e) {
|
|
238
|
-
e.printStackTrace();
|
|
239
|
-
}
|
|
240
|
-
} else if (subResult instanceof BarcodeScanResult) {
|
|
241
|
-
try {
|
|
242
|
-
jsonResult.put(
|
|
243
|
-
subResult.getPluginId(),
|
|
244
|
-
extractBarcodeResult(jsonResult, subResult)
|
|
245
|
-
);
|
|
246
|
-
} catch (Exception e) {
|
|
247
|
-
Log.e(TAG, "EXCEPTION", e);
|
|
248
|
-
}
|
|
249
|
-
} else if (subResult instanceof MeterScanResult) {
|
|
250
|
-
JSONObject jsonMeterResult = new JSONObject();
|
|
251
|
-
try {
|
|
252
|
-
jsonMeterResult = AnylinePluginHelper.setMeterScanMode(((MeterScanResult) subResult).getScanMode(), jsonMeterResult);
|
|
253
|
-
jsonMeterResult.put("reading", subResult.getResult());
|
|
254
|
-
jsonMeterResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, subResult, jsonMeterResult);
|
|
255
|
-
jsonResult.put(subResult.getPluginId(), jsonMeterResult);
|
|
256
|
-
} catch (Exception e) {
|
|
257
|
-
Log.e(TAG, "EXCEPTION", e);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
setResult(scanViewPlugin, jsonResult);
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
} else if (scanViewPlugin instanceof LicensePlateScanViewPlugin) {
|
|
266
|
-
scanViewPlugin.addScanResultListener((ScanResultListener<LicensePlateScanResult>) licensePlateResult -> {
|
|
267
|
-
JSONObject jsonResult = new JSONObject();
|
|
268
|
-
try {
|
|
269
|
-
jsonResult.put("country", licensePlateResult.getCountry());
|
|
270
|
-
jsonResult.put("licensePlate", licensePlateResult.getResult());
|
|
271
|
-
|
|
272
|
-
jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, licensePlateResult,
|
|
273
|
-
jsonResult);
|
|
274
|
-
} catch (JSONException e) {
|
|
275
|
-
e.printStackTrace();
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
setResult(scanViewPlugin, jsonResult);
|
|
279
|
-
});
|
|
280
|
-
} else if (scanViewPlugin instanceof IdScanViewPlugin) {
|
|
281
|
-
if (((IdScanPlugin) ((IdScanViewPlugin) scanViewPlugin).getScanPlugin()).getIdConfig() instanceof MrzConfig) {
|
|
282
|
-
|
|
283
|
-
if (json.has("cropAndTransformErrorMessage")) {
|
|
284
|
-
setDebugListener();
|
|
285
|
-
cropAndTransformError = json.getString("cropAndTransformErrorMessage");
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
scanViewPlugin.addScanResultListener((ScanResultListener<ScanResult<ID>>) idScanResult -> {
|
|
289
|
-
JSONObject jsonResult = ((MrzIdentification) idScanResult.getResult()).toJSONObject();
|
|
290
|
-
try {
|
|
291
|
-
if (jsonResult.get("issuingCountryCode").equals("D")
|
|
292
|
-
&& jsonResult.get("documentType").equals("ID")) {
|
|
293
|
-
if (jsonResult.get("issuingCountryCode").equals("D")) {
|
|
294
|
-
jsonResult.put("address", jsonResult.get("address"));
|
|
295
|
-
} else {
|
|
296
|
-
jsonResult.remove("address");
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
}
|
|
300
|
-
} catch (JSONException e) {
|
|
301
|
-
e.printStackTrace();
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
try {
|
|
305
|
-
jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, idScanResult,
|
|
306
|
-
jsonResult);
|
|
307
|
-
} catch (Exception e) {
|
|
308
|
-
Log.e(TAG, "Exception is: ", e);
|
|
309
|
-
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
setResult(scanViewPlugin, jsonResult);
|
|
313
|
-
|
|
314
|
-
});
|
|
315
|
-
} else if (((IdScanPlugin) ((IdScanViewPlugin) scanViewPlugin).getScanPlugin()).getIdConfig() instanceof UniversalIdConfig) {
|
|
316
|
-
scanViewPlugin.addScanResultListener((ScanResultListener<ScanResult<ID>>) idScanResult -> {
|
|
317
|
-
Identification identification = (Identification) idScanResult.getResult();
|
|
318
|
-
HashMap<String, String> data = (HashMap<String, String>) identification.getResultData();
|
|
319
|
-
|
|
320
|
-
JSONObject jsonResult = new JSONObject(data);
|
|
321
|
-
|
|
322
|
-
try {
|
|
323
|
-
jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, idScanResult,
|
|
324
|
-
jsonResult);
|
|
325
|
-
} catch (Exception e) {
|
|
326
|
-
Log.e(TAG, "Exception is: ", e);
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
setResult(scanViewPlugin, jsonResult);
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
} else if (scanViewPlugin instanceof OcrScanViewPlugin) {
|
|
333
|
-
scanViewPlugin.addScanResultListener((ScanResultListener<OcrScanResult>) ocrScanResult -> {
|
|
334
|
-
JSONObject jsonResult = new JSONObject();
|
|
335
|
-
try {
|
|
336
|
-
jsonResult.put("text", ocrScanResult.getResult().trim());
|
|
337
|
-
jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, ocrScanResult,
|
|
338
|
-
jsonResult);
|
|
339
|
-
} catch (JSONException e) {
|
|
340
|
-
e.printStackTrace();
|
|
341
|
-
}
|
|
342
|
-
setResult(scanViewPlugin, jsonResult);
|
|
343
|
-
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
} else if (scanViewPlugin instanceof TireScanViewPlugin) {
|
|
347
|
-
scanViewPlugin.addScanResultListener((ScanResultListener<TireScanResult>) tireScanResult -> {
|
|
348
|
-
JSONObject jsonResult = new JSONObject();
|
|
349
|
-
try {
|
|
350
|
-
jsonResult.put("text", tireScanResult.getResult().trim());
|
|
351
|
-
jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, tireScanResult,
|
|
352
|
-
jsonResult);
|
|
353
|
-
if (tireScanResult instanceof TireSizeScanResult) {
|
|
354
|
-
String tireScanDetailedResult = ((TireSizeScanResult) tireScanResult).getResult().toJson();
|
|
355
|
-
jsonResult.put("tireScanDetailedResult", tireScanDetailedResult);
|
|
356
|
-
}
|
|
357
|
-
} catch (JSONException e) {
|
|
358
|
-
e.printStackTrace();
|
|
359
|
-
}
|
|
360
|
-
setResult(scanViewPlugin, jsonResult);
|
|
361
|
-
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
} else if (scanViewPlugin instanceof BarcodeScanViewPlugin) {
|
|
365
|
-
|
|
366
|
-
if (shouldEnablePDF417(json)) {
|
|
367
|
-
((BarcodeScanPlugin) ((BarcodeScanViewPlugin) scanViewPlugin).getScanPlugin()).enablePDF417Parsing();
|
|
368
|
-
}
|
|
369
|
-
scanViewPlugin.addScanResultListener(new ScanResultListener<BarcodeScanResult>() {
|
|
370
|
-
@Override
|
|
371
|
-
public void onResult(BarcodeScanResult barcodeScanResult) {
|
|
372
|
-
JSONObject jsonResult = new JSONObject();
|
|
373
|
-
try {
|
|
374
|
-
List<Barcode> barcodeList = barcodeScanResult.getResult();
|
|
375
|
-
|
|
376
|
-
JSONArray barcodeArray = new JSONArray();
|
|
377
|
-
if (barcodeList != null && barcodeList.size() > 0) {
|
|
378
|
-
for (int i = 0; i < barcodeList.size(); i++) {
|
|
379
|
-
JSONObject barcode = new JSONObject();
|
|
380
|
-
barcode.put("value", barcodeList.get(i).getValue());
|
|
381
|
-
barcode.put("barcodeFormat", barcodeList.get(i).getBarcodeFormat());
|
|
382
|
-
|
|
383
|
-
PDF417 pdf417 = barcodeList.get(i).getParsedPDF417();
|
|
384
|
-
|
|
385
|
-
if (pdf417 != null) {
|
|
386
|
-
barcode.put("parsedPDF417", pdf417.toJSONObject());
|
|
387
|
-
}
|
|
388
|
-
barcodeArray.put(barcode);
|
|
389
|
-
}
|
|
390
|
-
JSONObject finalObject = new JSONObject();
|
|
391
|
-
finalObject.put("barcodes", barcodeArray);
|
|
392
|
-
jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, barcodeScanResult, finalObject);
|
|
393
|
-
}
|
|
394
|
-
} catch (JSONException e) {
|
|
395
|
-
e.printStackTrace();
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
setResult(scanViewPlugin, jsonResult);
|
|
399
|
-
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
} else if (scanViewPlugin instanceof MeterScanViewPlugin) {
|
|
406
|
-
// create the radio button for the UI
|
|
407
|
-
addSegmentRadioButtonUI(json);
|
|
408
|
-
|
|
409
|
-
anylineScanView.setCameraOpenListener(this);
|
|
410
|
-
scanViewPlugin.addScanResultListener((ScanResultListener<MeterScanResult>) meterScanResult -> {
|
|
411
|
-
JSONObject jsonResult = new JSONObject();
|
|
412
|
-
try {
|
|
413
|
-
jsonResult = AnylinePluginHelper.setMeterScanMode(meterScanResult.getScanMode(),
|
|
414
|
-
jsonResult);
|
|
415
|
-
jsonResult.put("reading", meterScanResult.getResult());
|
|
416
|
-
|
|
417
|
-
jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, meterScanResult,
|
|
418
|
-
jsonResult);
|
|
419
|
-
|
|
420
|
-
} catch (Exception e) {
|
|
421
|
-
Log.e(TAG, "EXCEPTION", e);
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
setResult(scanViewPlugin, jsonResult);
|
|
425
|
-
});
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
/* Clear NativeBarcodeResult after every scan, otherwise the result from previous
|
|
429
|
-
* scan would be shown if now barcode was found */
|
|
430
|
-
AnylinePluginHelper.clearFinalBarcodeList();
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
} catch (Exception e) {
|
|
434
|
-
// JSONException or IllegalArgumentException is possible for errors in json
|
|
435
|
-
// IOException is possible for errors during asset copying
|
|
436
|
-
finishWithError(
|
|
437
|
-
getString(getResources().getIdentifier("error_invalid_json_data", "string", getPackageName()))
|
|
438
|
-
+ "\n" + e.getLocalizedMessage());
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
private void setDefaultOrientation(JSONObject jsonObject) {
|
|
443
|
-
if (defaultOrientationApplied) return;
|
|
444
|
-
|
|
445
|
-
if (jsonObject.has("defaultOrientation")
|
|
446
|
-
&& jsonObject.optString("defaultOrientation").equals("landscape")
|
|
447
|
-
&& getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
|
|
448
|
-
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
|
449
|
-
}
|
|
450
|
-
defaultOrientationApplied = true;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
private boolean shouldEnablePDF417(JSONObject jsonObject) {
|
|
454
|
-
JSONObject viewPlugin = jsonObject.optJSONObject("viewPlugin");
|
|
455
|
-
|
|
456
|
-
if (viewPlugin != null) {
|
|
457
|
-
JSONObject plugin = viewPlugin.optJSONObject("plugin");
|
|
458
|
-
|
|
459
|
-
if (plugin != null) {
|
|
460
|
-
JSONObject barcodePlugin = plugin.optJSONObject("barcodePlugin");
|
|
461
|
-
return barcodePlugin != null && barcodePlugin.optBoolean("enablePDF417Parsing");
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
return false;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
private JSONObject extractBarcodeResult(JSONObject jsonResult, ScanResult subResult) {
|
|
468
|
-
try {
|
|
469
|
-
List<Barcode> barcodeList = (List<Barcode>) subResult.getResult();
|
|
470
|
-
|
|
471
|
-
JSONArray barcodeArray = new JSONArray();
|
|
472
|
-
if (barcodeList.size() > 1) {
|
|
473
|
-
for (int i = 0; i < barcodeList.size(); i++) {
|
|
474
|
-
barcodeArray.put(barcodeList.get(i).toJSONObject());
|
|
475
|
-
}
|
|
476
|
-
JSONObject finalObject = new JSONObject();
|
|
477
|
-
finalObject.put("multiBarcodes", barcodeArray);
|
|
478
|
-
jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, subResult, finalObject);
|
|
479
|
-
} else {
|
|
480
|
-
jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, subResult, barcodeList.get(0).toJSONObject());
|
|
481
|
-
|
|
482
|
-
}
|
|
483
|
-
} catch (JSONException e) {
|
|
484
|
-
e.printStackTrace();
|
|
485
|
-
}
|
|
486
|
-
return jsonResult;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
// this method is used only for the meter scanning which contains radio buttons
|
|
490
|
-
@Override
|
|
491
|
-
public void onCameraOpened(CameraController cameraController, int width, int height) {
|
|
492
|
-
super.onCameraOpened(cameraController, width, height);
|
|
493
|
-
anylineScanView.post(new Runnable() {
|
|
494
|
-
@Override
|
|
495
|
-
public void run() {
|
|
496
|
-
if (radioGroup != null) {
|
|
497
|
-
Handler handler = new Handler();
|
|
498
|
-
handler.postDelayed(new Runnable() {
|
|
499
|
-
public void run() {
|
|
500
|
-
CutoutRect cutoutRect = ((MeterScanViewPlugin) scanViewPlugin).getCutoutRect();
|
|
501
|
-
|
|
502
|
-
if (isFirstCameraOpen && cutoutRect != null) {
|
|
503
|
-
isFirstCameraOpen = false;
|
|
504
|
-
Rect rect = cutoutRect.rectOnVisibleView;
|
|
505
|
-
|
|
506
|
-
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) radioGroup.getLayoutParams();
|
|
507
|
-
lp.setMargins(rect.left + anylineUIConfig.getOffsetX(), rect.top + anylineUIConfig.getOffsetY(), 0, 0);
|
|
508
|
-
radioGroup.setLayoutParams(lp);
|
|
509
|
-
|
|
510
|
-
radioGroup.setVisibility(View.VISIBLE);
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
}, 600);
|
|
514
|
-
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
});
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
private void addSegmentRadioButtonUI(JSONObject json) {
|
|
521
|
-
final String scanModeString = ((MeterScanViewPlugin) scanViewPlugin).getScanMode().toString();
|
|
522
|
-
anylineUIConfig = new AnylineUIConfig(this, json);
|
|
523
|
-
|
|
524
|
-
RadioGroup radioGroup = createRadioGroup(anylineUIConfig, scanModeString);
|
|
525
|
-
|
|
526
|
-
if (radioGroup != null) {
|
|
527
|
-
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
|
|
528
|
-
RelativeLayout.LayoutParams.WRAP_CONTENT);
|
|
529
|
-
lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
|
|
530
|
-
parentLayout.addView(radioGroup, lp);
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
private RadioGroup createRadioGroup(AnylineUIConfig anylineUIConfig, String scanModeString) {
|
|
535
|
-
ArrayList<String> titles = anylineUIConfig.getTitles();
|
|
536
|
-
final ArrayList<String> modes = anylineUIConfig.getModes();
|
|
537
|
-
|
|
538
|
-
if (titles != null && titles.size() > 0) {
|
|
539
|
-
|
|
540
|
-
if (titles.size() != modes.size()) {
|
|
541
|
-
finishWithError(getString(getResources().getIdentifier("error_invalid_segment_config", "string",
|
|
542
|
-
getPackageName() + "Titles not mathcing with modes")));
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
RadioButton[] radioButtons = new RadioButton[titles.size()];
|
|
546
|
-
radioGroup = new RadioGroup(this);
|
|
547
|
-
radioGroup.setOrientation(RadioGroup.VERTICAL);
|
|
548
|
-
|
|
549
|
-
int currentApiVersion = android.os.Build.VERSION.SDK_INT;
|
|
550
|
-
for (int i = 0; i < titles.size(); i++) {
|
|
551
|
-
radioButtons[i] = new RadioButton(this);
|
|
552
|
-
radioButtons[i].setText(titles.get(i));
|
|
553
|
-
|
|
554
|
-
if (currentApiVersion >= Build.VERSION_CODES.LOLLIPOP) {
|
|
555
|
-
radioButtons[i].setButtonTintList(ColorStateList.valueOf(anylineUIConfig.getTintColor()));
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
radioGroup.addView(radioButtons[i]);
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
Integer modeIndex = modes.indexOf(scanModeString);
|
|
562
|
-
RadioButton button = radioButtons[modeIndex];
|
|
563
|
-
button.setChecked(true);
|
|
564
|
-
|
|
565
|
-
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
|
|
566
|
-
@Override
|
|
567
|
-
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
|
568
|
-
View button = group.findViewById(checkedId);
|
|
569
|
-
String mode = modes.get(group.indexOfChild(button));
|
|
570
|
-
((MeterScanViewPlugin) scanViewPlugin).setScanMode(MeterScanMode.valueOf(mode));
|
|
571
|
-
anylineScanView.stop();
|
|
572
|
-
try {
|
|
573
|
-
Thread.sleep(100);
|
|
574
|
-
} catch (InterruptedException e) {
|
|
575
|
-
e.printStackTrace();
|
|
576
|
-
}
|
|
577
|
-
anylineScanView.start();
|
|
578
|
-
}
|
|
579
|
-
});
|
|
580
|
-
|
|
581
|
-
radioGroup.setVisibility(View.INVISIBLE);
|
|
582
|
-
return radioGroup;
|
|
583
|
-
}
|
|
584
|
-
return null;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
private void addRotateButtonToView(RotateButtonConfig rotateButtonConfig) {
|
|
588
|
-
Button button = new Button(this);
|
|
589
|
-
button.setText("Rotate");
|
|
590
|
-
button.setOnClickListener(new View.OnClickListener() {
|
|
591
|
-
|
|
592
|
-
@Override
|
|
593
|
-
public void onClick(View v) {
|
|
594
|
-
if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
|
|
595
|
-
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
|
596
|
-
} else if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
|
|
597
|
-
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
});
|
|
601
|
-
|
|
602
|
-
RelativeLayout.LayoutParams buttonLayoutParams = new RelativeLayout.LayoutParams(
|
|
603
|
-
RelativeLayout.LayoutParams.WRAP_CONTENT,
|
|
604
|
-
RelativeLayout.LayoutParams.WRAP_CONTENT);
|
|
605
|
-
|
|
606
|
-
if (rotateButtonConfig.hasOffset()) {
|
|
607
|
-
Offset offset = rotateButtonConfig.getOffset();
|
|
608
|
-
buttonLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
|
|
609
|
-
buttonLayoutParams.setMargins(offset.getX(), offset.getY(), 0, 0);
|
|
610
|
-
} else {
|
|
611
|
-
buttonLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
|
|
612
|
-
buttonLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
parentLayout.addView(button, buttonLayoutParams);
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
private boolean shouldShowRotateButton(JSONObject jsonObject) {
|
|
619
|
-
return jsonObject.has("rotateButton");
|
|
620
|
-
}
|
|
621
|
-
}
|