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