@regulaforensics/cordova-plugin-document-reader-api 6.8.0 → 6.9.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.
@@ -1,7 +1,12 @@
1
1
  package cordova.plugin.documentreader;
2
2
 
3
+ import static com.regula.documentreader.api.DocumentReader.Instance;
4
+ import static cordova.plugin.documentreader.Helpers.*;
5
+ import static cordova.plugin.documentreader.JSONConstructor.*;
6
+
3
7
  import android.annotation.SuppressLint;
4
8
  import android.app.Activity;
9
+ import android.app.LocaleManager;
5
10
  import android.app.PendingIntent;
6
11
  import android.content.Context;
7
12
  import android.content.Intent;
@@ -12,51 +17,53 @@ import android.graphics.Bitmap;
12
17
  import android.nfc.NfcAdapter;
13
18
  import android.nfc.tech.IsoDep;
14
19
  import android.os.Build;
15
- import android.os.Bundle;
20
+ import android.os.LocaleList;
16
21
  import android.util.Base64;
17
22
 
18
23
  import androidx.annotation.NonNull;
24
+ import androidx.annotation.Nullable;
19
25
 
20
26
  import com.regula.documentreader.api.completions.ICheckDatabaseUpdate;
21
27
  import com.regula.documentreader.api.completions.IDocumentReaderCompletion;
22
28
  import com.regula.documentreader.api.completions.IDocumentReaderInitCompletion;
23
29
  import com.regula.documentreader.api.completions.IDocumentReaderPrepareCompletion;
24
- import com.regula.documentreader.api.completions.IRfidPKDCertificateCompletion;
25
- import com.regula.documentreader.api.completions.IRfidReaderRequest;
26
- import com.regula.documentreader.api.completions.IRfidTASignatureCompletion;
27
- import com.regula.documentreader.api.completions.ITccParamsCompletion;
30
+ import com.regula.documentreader.api.completions.rfid.IRfidPKDCertificateCompletion;
31
+ import com.regula.documentreader.api.completions.rfid.IRfidReaderCompletion;
32
+ import com.regula.documentreader.api.completions.rfid.IRfidReaderRequest;
33
+ import com.regula.documentreader.api.completions.rfid.IRfidTASignatureCompletion;
34
+ import com.regula.documentreader.api.completions.rfid.ITccParamsCompletion;
28
35
  import com.regula.documentreader.api.enums.DocReaderAction;
36
+ import com.regula.documentreader.api.errors.DocReaderRfidException;
29
37
  import com.regula.documentreader.api.errors.DocumentReaderException;
30
38
  import com.regula.documentreader.api.internal.core.CoreScenarioUtil;
39
+ import com.regula.documentreader.api.internal.params.ImageInputParam;
40
+ import com.regula.documentreader.api.internal.parser.DocReaderResultsJsonParser;
31
41
  import com.regula.documentreader.api.params.BleDeviceConfig;
32
42
  import com.regula.documentreader.api.params.DocReaderConfig;
33
43
  import com.regula.documentreader.api.params.ImageInputData;
34
- import com.regula.documentreader.api.internal.params.ImageInputParam;
35
44
  import com.regula.documentreader.api.params.rfid.PKDCertificate;
36
45
  import com.regula.documentreader.api.params.rfid.authorization.PAResourcesIssuer;
37
46
  import com.regula.documentreader.api.params.rfid.authorization.TAChallenge;
38
47
  import com.regula.documentreader.api.results.DocumentReaderGraphicField;
48
+ import com.regula.documentreader.api.results.DocumentReaderNotification;
39
49
  import com.regula.documentreader.api.results.DocumentReaderResults;
40
50
  import com.regula.documentreader.api.results.DocumentReaderTextField;
41
- import com.regula.documentreader.api.internal.parser.DocReaderResultsJsonParser;
42
51
 
43
52
  import org.apache.cordova.CallbackContext;
44
53
  import org.apache.cordova.CordovaPlugin;
45
54
  import org.apache.cordova.PluginResult;
46
55
  import org.json.JSONArray;
47
- import org.json.JSONObject;
48
56
  import org.json.JSONException;
57
+ import org.json.JSONObject;
49
58
 
50
- import java.io.File;
51
59
  import java.io.IOException;
52
60
  import java.io.InputStream;
53
61
  import java.util.ArrayList;
62
+ import java.util.Arrays;
54
63
  import java.util.List;
55
64
  import java.util.Locale;
56
65
 
57
- import static com.regula.documentreader.api.DocumentReader.Instance;
58
-
59
- @SuppressWarnings({"ConstantConditions", "RedundantSuppression"})
66
+ @SuppressWarnings({"ConstantConditions", "RedundantSuppression", "deprecation"})
60
67
  public class DocumentReader extends CordovaPlugin {
61
68
  private CallbackContext callbackContext;
62
69
  private boolean backgroundRFIDEnabled = false;
@@ -65,16 +72,30 @@ public class DocumentReader extends CordovaPlugin {
65
72
  private IRfidPKDCertificateCompletion paCertificateCompletion;
66
73
  private IRfidPKDCertificateCompletion taCertificateCompletion;
67
74
  private IRfidTASignatureCompletion taSignatureCompletion;
68
- private final static String rfidNotificationCompletionEvent = "rfidNotificationCompletionEvent";
69
75
 
70
- private final static String paCertificateCompletionEvent = "paCertificateCompletionEvent";
71
- private final static String taCertificateCompletionEvent = "taCertificateCompletionEvent";
72
- private final static String taSignatureCompletionEvent = "taSignatureCompletionEvent";
76
+ private final static String eventDatabaseProgress = "database_progress";
77
+ private final static String eventCompletion = "completion";
78
+ // These events have a method that is associated only with this event
79
+ private final static List<String> singleEvents = Arrays.asList(eventDatabaseProgress, eventCompletion);
80
+
81
+ private final static String rfidOnProgressEvent = "rfid_notification_completion";
82
+ private final static String rfidOnChipDetectedEvent = "rfidOnChipDetectedEvent";
83
+ private final static String rfidOnRetryReadChipEvent = "rfidOnRetryReadChipEvent";
84
+
85
+ private final static String eventPACertificateCompletion = "pa_certificate_completion";
86
+ private final static String eventTACertificateCompletion = "ta_certificate_completion";
87
+ private final static String eventTASignatureCompletion = "ta_signature_completion";
73
88
 
74
89
  private final static String bleOnServiceConnectedEvent = "bleOnServiceConnectedEvent";
75
90
  private final static String bleOnServiceDisconnectedEvent = "bleOnServiceDisconnectedEvent";
76
91
  private final static String bleOnDeviceReadyEvent = "bleOnDeviceReadyEvent";
77
92
 
93
+ private final static String eventVideoEncoderCompletion = "video_encoder_completion";
94
+ private final static String onCustomButtonTappedEvent = "onCustomButtonTappedEvent";
95
+ // These events are not working in cordova and ionic because they don't have a method
96
+ // associated with it. Callbacks are set automatically right after init.
97
+ private final static List<String> skippedEvents = Arrays.asList(eventVideoEncoderCompletion, onCustomButtonTappedEvent);
98
+
78
99
  private static int databaseDownloadProgress = 0;
79
100
 
80
101
  private Context getContext() {
@@ -89,7 +110,7 @@ public class DocumentReader extends CordovaPlugin {
89
110
  public void onNewIntent(Intent intent) {
90
111
  super.onNewIntent(intent);
91
112
  if (intent.getAction() != null && intent.getAction().equals(NfcAdapter.ACTION_TECH_DISCOVERED) && backgroundRFIDEnabled)
92
- Instance().readRFID(IsoDep.get(intent.getParcelableExtra(NfcAdapter.EXTRA_TAG)), getCompletion());
113
+ Instance().readRFID(IsoDep.get(intent.getParcelableExtra(NfcAdapter.EXTRA_TAG)), getRfidReaderCompletion());
93
114
  }
94
115
 
95
116
  @Override
@@ -114,75 +135,29 @@ public class DocumentReader extends CordovaPlugin {
114
135
  return (T) data.get(index);
115
136
  }
116
137
 
117
- private void sendProgress(int progress) {
118
- PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, progress);
119
- pluginResult.setKeepCallback(true);
120
- callbackContext.sendPluginResult(pluginResult);
121
- }
122
-
123
- private void sendCompletion(int action, DocumentReaderResults results, DocumentReaderException error) {
124
- PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, JSONConstructor.generateCompletion(action, results, error, getContext()).toString());
125
- pluginResult.setKeepCallback(true);
126
- callbackContext.sendPluginResult(pluginResult);
127
- }
128
-
129
- private void sendVideoEncoderCompletion(String sessionId, File file) {
130
- PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, JSONConstructor.generateVideoEncoderCompletion(sessionId, file).toString());
131
- pluginResult.setKeepCallback(true);
132
- callbackContext.sendPluginResult(pluginResult);
133
- }
134
-
135
- private void sendIRfidNotificationCompletion(int notification, Bundle value) {
136
- PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, rfidNotificationCompletionEvent + JSONConstructor.generateRfidNotificationCompletion(notification, value));
137
- pluginResult.setKeepCallback(true);
138
- callbackContext.sendPluginResult(pluginResult);
139
- }
140
-
141
- private void sendPACertificateCompletion(byte[] serialNumber, PAResourcesIssuer issuer) {
142
- PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, paCertificateCompletionEvent + JSONConstructor.generatePACertificateCompletion(serialNumber, issuer));
143
- pluginResult.setKeepCallback(true);
144
- callbackContext.sendPluginResult(pluginResult);
145
- }
146
-
147
- private void sendTACertificateCompletion(String keyCAR) {
148
- PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, taCertificateCompletionEvent + keyCAR);
149
- pluginResult.setKeepCallback(true);
150
- callbackContext.sendPluginResult(pluginResult);
151
- }
152
- private void sendTASignatureCompletion(TAChallenge challenge) {
153
- PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, taSignatureCompletionEvent + JSONConstructor.generateTAChallenge(challenge));
154
- pluginResult.setKeepCallback(true);
155
- callbackContext.sendPluginResult(pluginResult);
156
- }
157
- private void sendBleOnServiceConnectedEvent(boolean isBleManagerConnected) {
158
- PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, bleOnServiceConnectedEvent + isBleManagerConnected);
159
- pluginResult.setKeepCallback(true);
160
- callbackContext.sendPluginResult(pluginResult);
161
- }
162
-
163
- private void sendBleOnServiceDisconnectedEvent() {
164
- PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, bleOnServiceDisconnectedEvent);
165
- pluginResult.setKeepCallback(true);
166
- callbackContext.sendPluginResult(pluginResult);
167
- }
168
- private void sendBleOnDeviceReadyEvent() {
169
- PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, bleOnDeviceReadyEvent);
170
- pluginResult.setKeepCallback(true);
171
- callbackContext.sendPluginResult(pluginResult);
172
- }
173
-
174
- private void sendOnCustomButtonTappedEvent(int tag) {
175
- PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, tag);
138
+ private void sendEvent(String event, Object data) {
139
+ PluginResult pluginResult;
140
+ String result;
141
+ if (data instanceof JSONObject || data instanceof JSONArray)
142
+ result = data.toString();
143
+ else
144
+ result = (String) data;
145
+ if (skippedEvents.contains(event))
146
+ return;
147
+ // Allows user to determine which event fired when there are more
148
+ // than one event associated with the function
149
+ if (!singleEvents.contains(event))
150
+ result = event + result;
151
+ pluginResult = new PluginResult(PluginResult.Status.OK, result);
176
152
  pluginResult.setKeepCallback(true);
177
153
  callbackContext.sendPluginResult(pluginResult);
178
154
  }
179
155
 
180
-
181
156
  @Override
182
157
  public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
183
158
  this.callbackContext = callbackContext;
184
159
  activity = cordova.getActivity();
185
- action = (String)args.remove(0);
160
+ action = (String) args.remove(0);
186
161
  data = args;
187
162
  Callback callback = new Callback() {
188
163
  @Override
@@ -343,8 +318,11 @@ public class DocumentReader extends CordovaPlugin {
343
318
  case "checkDatabaseUpdate":
344
319
  checkDatabaseUpdate(callback, args(0));
345
320
  break;
346
- case "getScenario":
347
- getScenario(callback, args(0));
321
+ case "scan":
322
+ scan(callback, args(0));
323
+ break;
324
+ case "recognize":
325
+ recognize(callback, args(0));
348
326
  break;
349
327
  case "recognizeImages":
350
328
  recognizeImages(callback, args(0));
@@ -406,9 +384,6 @@ public class DocumentReader extends CordovaPlugin {
406
384
  case "recognizeImagesWithImageInputs":
407
385
  recognizeImagesWithImageInputs(callback, args(0));
408
386
  break;
409
- case "setOnCustomButtonTappedListener":
410
- setOnCustomButtonTappedListener(callback);
411
- break;
412
387
  case "setLanguage":
413
388
  setLanguage(callback, args(0));
414
389
  break;
@@ -516,15 +491,15 @@ public class DocumentReader extends CordovaPlugin {
516
491
  BluetoothUtil.Companion.startBluetoothService(
517
492
  getActivity(),
518
493
  isBleManagerConnected -> {
519
- sendBleOnServiceConnectedEvent(isBleManagerConnected);
494
+ sendEvent(bleOnServiceConnectedEvent, isBleManagerConnected);
520
495
  return null;
521
496
  },
522
497
  () -> {
523
- sendBleOnServiceDisconnectedEvent();
498
+ sendEvent(bleOnServiceDisconnectedEvent, "");
524
499
  return null;
525
500
  },
526
501
  () -> {
527
- sendBleOnDeviceReadyEvent();
502
+ sendEvent(bleOnDeviceReadyEvent, "");
528
503
  return null;
529
504
  }
530
505
  );
@@ -541,12 +516,12 @@ public class DocumentReader extends CordovaPlugin {
541
516
  }
542
517
 
543
518
  private void getAvailableScenarios(Callback callback) throws JSONException {
544
- callback.success(JSONConstructor.generateList(Instance().availableScenarios, JSONConstructor::generateDocumentReaderScenario).toString());
519
+ callback.success(generateList(Instance().availableScenarios, JSONConstructor::generateDocumentReaderScenario).toString());
545
520
  }
546
521
 
547
522
  private void parseCoreResults(Callback callback, String json) {
548
523
  DocumentReaderResults results = (DocumentReaderResults) DocReaderResultsJsonParser.parseCoreResults(json).get("docReaderResults");
549
- callback.success(JSONConstructor.generateDocumentReaderResults(results, getContext()).toString());
524
+ callback.success(generateDocumentReaderResults(results, getContext()).toString());
550
525
  }
551
526
 
552
527
  private void getAPIVersion(Callback callback) {
@@ -586,7 +561,7 @@ public class DocumentReader extends CordovaPlugin {
586
561
  }
587
562
 
588
563
  private void setTCCParams(Callback callback, final JSONObject params) {
589
- Instance().setTccParams(JSONConstructor.TCCParamsFromJSON(params), getTCCParamsCompletion(callback));
564
+ Instance().setTccParams(TCCParamsFromJSON(params), getTCCParamsCompletion(callback));
590
565
  }
591
566
 
592
567
  private void deinitializeReader(Callback callback) {
@@ -607,11 +582,7 @@ public class DocumentReader extends CordovaPlugin {
607
582
  }
608
583
 
609
584
  private void selectedScenario(Callback callback) {
610
- callback.success(JSONConstructor.generateCoreDetailedScenario(CoreScenarioUtil.getScenario(Instance().processParams().getScenario())).toString());
611
- }
612
-
613
- private void getScenario(Callback callback, String scenario) {
614
- callback.success(JSONConstructor.generateCoreDetailedScenario(CoreScenarioUtil.getScenario(scenario)).toString());
585
+ callback.success(generateDocumentReaderScenario(CoreScenarioUtil.getScenario(Instance().processParams().getScenario())).toString());
615
586
  }
616
587
 
617
588
  private void getLicenseExpiryDate(Callback callback) {
@@ -625,7 +596,7 @@ public class DocumentReader extends CordovaPlugin {
625
596
  if (Instance().license().getCountryFilter() == null)
626
597
  callback.error("null");
627
598
  else
628
- callback.success(JSONConstructor.generateList(Instance().license().getCountryFilter()).toString());
599
+ callback.success(generateList(Instance().license().getCountryFilter()).toString());
629
600
  }
630
601
 
631
602
  private void licenseIsRfidAvailable(Callback callback) {
@@ -646,7 +617,7 @@ public class DocumentReader extends CordovaPlugin {
646
617
 
647
618
  private void initializeReader(Callback callback, JSONObject config) {
648
619
  if (!Instance().isReady())
649
- Instance().initializeReader(getContext(), JSONConstructor.DocReaderConfigFromJSON(config), getInitCompletion(callback));
620
+ Instance().initializeReader(getContext(), DocReaderConfigFromJSON(config), getInitCompletion(callback));
650
621
  else
651
622
  callback.success("already initialized");
652
623
  }
@@ -675,6 +646,16 @@ public class DocumentReader extends CordovaPlugin {
675
646
  callback.success();
676
647
  }
677
648
 
649
+ private void scan(@SuppressWarnings("unused") Callback callback, JSONObject config) {
650
+ stopBackgroundRFID();
651
+ Instance().showScanner(getContext(), ScannerConfigFromJSON(config), getCompletion());
652
+ }
653
+
654
+ private void recognize(@SuppressWarnings("unused") Callback callback, JSONObject config) {
655
+ stopBackgroundRFID();
656
+ Instance().recognize(getContext(), RecognizeConfigFromJSON(config), getCompletion());
657
+ }
658
+
678
659
  private void recognizeImageWithOpts(Callback callback, String base64Image, final JSONObject opts) throws JSONException {
679
660
  RegulaConfig.setConfig(Instance(), opts, getContext());
680
661
  recognizeImage(callback, base64Image);
@@ -694,7 +675,7 @@ public class DocumentReader extends CordovaPlugin {
694
675
  stopBackgroundRFID();
695
676
  Bitmap[] images = new Bitmap[base64Images.length()];
696
677
  for (int i = 0; i < images.length; i++)
697
- images[i] = Helpers.bitmapFromBase64(base64Images.getString(i));
678
+ images[i] = bitmapFromBase64(base64Images.getString(i));
698
679
  Instance().recognizeImages(images, getCompletion());
699
680
  }
700
681
 
@@ -702,7 +683,7 @@ public class DocumentReader extends CordovaPlugin {
702
683
  stopBackgroundRFID();
703
684
  ImageInputData[] images = new ImageInputData[base64Images.length()];
704
685
  for (int i = 0; i < images.length; i++)
705
- images[i] = JSONConstructor.ImageInputDataFromJSON(base64Images.getJSONObject(i));
686
+ images[i] = ImageInputDataFromJSON(base64Images.getJSONObject(i));
706
687
  Instance().recognizeImages(images, getCompletion());
707
688
  }
708
689
 
@@ -766,12 +747,7 @@ public class DocumentReader extends CordovaPlugin {
766
747
 
767
748
  private void startRFIDReader(@SuppressWarnings("unused") Callback callback) {
768
749
  stopBackgroundRFID();
769
- IRfidReaderRequest delegate = null;
770
- if (rfidDelegate == RFIDDelegate.NO_PA)
771
- delegate = getIRfidReaderRequestNoPA();
772
- if (rfidDelegate == RFIDDelegate.FULL)
773
- delegate = getIRfidReaderRequest();
774
- Instance().startRFIDReader(getContext(), getCompletion(), delegate, this::sendIRfidNotificationCompletion);
750
+ Instance().startRFIDReader(getContext(), getRfidReaderCompletion(), getRfidReaderRequest());
775
751
  }
776
752
 
777
753
  private void stopRFIDReader(Callback callback) {
@@ -807,18 +783,18 @@ public class DocumentReader extends CordovaPlugin {
807
783
  startForegroundDispatch(getActivity());
808
784
  }
809
785
 
810
- private void setOnCustomButtonTappedListener(Callback callback) {
811
- Instance().setOnClickListener(view -> sendOnCustomButtonTappedEvent((int) view.getTag()));
812
- callback.success();
813
- }
814
-
815
786
  private void setLanguage(Callback callback, String language) {
816
- Locale locale = new Locale(language);
817
- Locale.setDefault(locale);
818
- Resources resources = getContext().getResources();
819
- Configuration config = resources.getConfiguration();
820
- config.setLocale(locale);
821
- resources.updateConfiguration(config, resources.getDisplayMetrics());
787
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
788
+ LocaleManager localeManager = (LocaleManager) getContext().getSystemService(Context.LOCALE_SERVICE);
789
+ localeManager.setApplicationLocales(new LocaleList(Locale.forLanguageTag(language)));
790
+ } else {
791
+ Locale locale = new Locale(language);
792
+ Locale.setDefault(locale);
793
+ Resources resources = getContext().getResources();
794
+ Configuration config = resources.getConfiguration();
795
+ config.setLocale(locale);
796
+ resources.updateConfiguration(config, resources.getDisplayMetrics());
797
+ }
822
798
  callback.success();
823
799
  }
824
800
 
@@ -900,7 +876,7 @@ public class DocumentReader extends CordovaPlugin {
900
876
  if (result == null)
901
877
  callback.success(null);
902
878
  else
903
- callback.success(JSONConstructor.generateDocumentReaderTextField(result, getContext()).toString());
879
+ callback.success(generateDocumentReaderTextField(result, getContext()).toString());
904
880
  }
905
881
 
906
882
  private void textFieldByTypeLcid(Callback callback, String raw, int fieldType, int lcid) {
@@ -909,7 +885,7 @@ public class DocumentReader extends CordovaPlugin {
909
885
  if (result == null)
910
886
  callback.success(null);
911
887
  else
912
- callback.success(JSONConstructor.generateDocumentReaderTextField(result, getContext()).toString());
888
+ callback.success(generateDocumentReaderTextField(result, getContext()).toString());
913
889
  }
914
890
 
915
891
  private void graphicFieldByTypeSource(Callback callback, String raw, int fieldType, int source) {
@@ -918,7 +894,7 @@ public class DocumentReader extends CordovaPlugin {
918
894
  if (result == null)
919
895
  callback.success(null);
920
896
  else
921
- callback.success(JSONConstructor.generateDocumentReaderGraphicField(result, getContext()).toString());
897
+ callback.success(generateDocumentReaderGraphicField(result, getContext()).toString());
922
898
  }
923
899
 
924
900
  private void graphicFieldByTypeSourcePageIndex(Callback callback, String raw, int fieldType, int source, int pageIndex) {
@@ -927,7 +903,7 @@ public class DocumentReader extends CordovaPlugin {
927
903
  if (result == null)
928
904
  callback.success(null);
929
905
  else
930
- callback.success(JSONConstructor.generateDocumentReaderGraphicField(result, getContext()).toString());
906
+ callback.success(generateDocumentReaderGraphicField(result, getContext()).toString());
931
907
  }
932
908
 
933
909
  private void graphicFieldByTypeSourcePageIndexLight(Callback callback, String raw, int fieldType, int source, int pageIndex, int light) {
@@ -936,34 +912,34 @@ public class DocumentReader extends CordovaPlugin {
936
912
  if (result == null)
937
913
  callback.success(null);
938
914
  else
939
- callback.success(JSONConstructor.generateDocumentReaderGraphicField(result, getContext()).toString());
915
+ callback.success(generateDocumentReaderGraphicField(result, getContext()).toString());
940
916
  }
941
917
 
942
918
  private void graphicFieldImageByType(Callback callback, String raw, int fieldType) {
943
919
  DocumentReaderResults results = DocumentReaderResults.fromRawResults(raw);
944
- callback.success(Helpers.bitmapToBase64String(results.getGraphicFieldImageByType(fieldType)));
920
+ callback.success(bitmapToBase64String(results.getGraphicFieldImageByType(fieldType)));
945
921
  }
946
922
 
947
923
  private void graphicFieldImageByTypeSource(Callback callback, String raw, int fieldType, int source) {
948
924
  DocumentReaderResults results = DocumentReaderResults.fromRawResults(raw);
949
- callback.success(Helpers.bitmapToBase64String(results.getGraphicFieldImageByType(fieldType, source)));
925
+ callback.success(bitmapToBase64String(results.getGraphicFieldImageByType(fieldType, source)));
950
926
  }
951
927
 
952
928
  private void graphicFieldImageByTypeSourcePageIndex(Callback callback, String raw, int fieldType, int source, int pageIndex) {
953
929
  DocumentReaderResults results = DocumentReaderResults.fromRawResults(raw);
954
- callback.success(Helpers.bitmapToBase64String(results.getGraphicFieldImageByType(fieldType, source, pageIndex)));
930
+ callback.success(bitmapToBase64String(results.getGraphicFieldImageByType(fieldType, source, pageIndex)));
955
931
  }
956
932
 
957
933
  private void graphicFieldImageByTypeSourcePageIndexLight(Callback callback, String raw, int fieldType, int source, int pageIndex, int light) {
958
934
  DocumentReaderResults results = DocumentReaderResults.fromRawResults(raw);
959
- callback.success(Helpers.bitmapToBase64String(results.getGraphicFieldImageByType(fieldType, source, pageIndex, light)));
935
+ callback.success(bitmapToBase64String(results.getGraphicFieldImageByType(fieldType, source, pageIndex, light)));
960
936
  }
961
937
 
962
938
  @SuppressLint("WrongConstant")
963
939
  private void containers(Callback callback, String raw, JSONArray resultType) {
964
940
  try {
965
941
  DocumentReaderResults results = DocumentReaderResults.fromRawResults(raw);
966
- callback.success(results.getContainers(JSONConstructor.intArrayFromJSON(resultType)));
942
+ callback.success(results.getContainers(intArrayFromJSON(resultType)));
967
943
  } catch (JSONException e) {
968
944
  e.printStackTrace();
969
945
  callback.error(e.toString());
@@ -1003,24 +979,50 @@ public class DocumentReader extends CordovaPlugin {
1003
979
 
1004
980
  private IDocumentReaderCompletion getCompletion() {
1005
981
  return (action, results, error) -> {
1006
- sendCompletion(action, results, error);
982
+ sendEvent(eventCompletion, generateCompletion(action, results, error, getContext()));
1007
983
  if (action == DocReaderAction.ERROR || action == DocReaderAction.CANCEL || (action == DocReaderAction.COMPLETE && results != null && results.rfidResult == 1))
1008
984
  stopBackgroundRFID();
1009
985
  };
1010
986
  }
1011
987
 
988
+ private IRfidReaderCompletion getRfidReaderCompletion() {
989
+ return new IRfidReaderCompletion() {
990
+ @Override
991
+ public void onCompleted(int action, @Nullable DocumentReaderResults results, @Nullable DocumentReaderException error) {
992
+ sendEvent(eventCompletion, generateCompletion(action, results, error, getContext()));
993
+ if (action == DocReaderAction.ERROR || action == DocReaderAction.CANCEL || (action == DocReaderAction.COMPLETE && results != null && results.rfidResult == 1))
994
+ stopBackgroundRFID();
995
+ }
996
+
997
+ @Override
998
+ public void onChipDetected() {
999
+ sendEvent(rfidOnChipDetectedEvent, "");
1000
+ }
1001
+
1002
+ @Override
1003
+ public void onRetryReadChip(@NonNull DocReaderRfidException error) {
1004
+ sendEvent(rfidOnRetryReadChipEvent, generateRegulaException(error));
1005
+ }
1006
+
1007
+ @Override
1008
+ public void onProgress(@Nullable DocumentReaderNotification notification) {
1009
+ sendEvent(rfidOnProgressEvent, generateDocumentReaderNotification(notification));
1010
+ }
1011
+ };
1012
+ }
1013
+
1012
1014
  private IDocumentReaderPrepareCompletion getPrepareCompletion(Callback callback) {
1013
1015
  return new IDocumentReaderPrepareCompletion() {
1014
1016
  @Override
1015
1017
  public void onPrepareProgressChanged(int progress) {
1016
1018
  if (progress != databaseDownloadProgress) {
1017
- sendProgress(progress);
1019
+ sendEvent(eventDatabaseProgress, progress + "");
1018
1020
  databaseDownloadProgress = progress;
1019
1021
  }
1020
1022
  }
1021
1023
 
1022
1024
  @Override
1023
- public void onPrepareCompleted(boolean status, DocumentReaderException error) {
1025
+ public void onPrepareCompleted(boolean status, @Nullable DocumentReaderException error) {
1024
1026
  if (status)
1025
1027
  callback.success("database prepared");
1026
1028
  else
@@ -1032,7 +1034,8 @@ public class DocumentReader extends CordovaPlugin {
1032
1034
  private IDocumentReaderInitCompletion getInitCompletion(Callback callback) {
1033
1035
  return (success, error) -> {
1034
1036
  if (success) {
1035
- Instance().setVideoEncoderCompletion(this::sendVideoEncoderCompletion);
1037
+ Instance().setVideoEncoderCompletion((sessionId, file) -> sendEvent(eventVideoEncoderCompletion, generateVideoEncoderCompletion(sessionId, file)));
1038
+ Instance().setOnClickListener(view -> sendEvent(onCustomButtonTappedEvent, view.getTag()));
1036
1039
  callback.success("init completed");
1037
1040
  } else
1038
1041
  callback.error("Init failed:" + error);
@@ -1040,7 +1043,7 @@ public class DocumentReader extends CordovaPlugin {
1040
1043
  }
1041
1044
 
1042
1045
  private ICheckDatabaseUpdate getCheckDatabaseUpdateCompletion(Callback callback) {
1043
- return (database) -> callback.success(JSONConstructor.generateDocReaderDocumentsDatabase(database));
1046
+ return (database) -> callback.success(generateDocReaderDocumentsDatabase(database));
1044
1047
  }
1045
1048
 
1046
1049
  private ITccParamsCompletion getTCCParamsCompletion(Callback callback) {
@@ -1057,20 +1060,19 @@ public class DocumentReader extends CordovaPlugin {
1057
1060
  @Override
1058
1061
  public void onRequestPACertificates(byte[] serialNumber, PAResourcesIssuer issuer, @NonNull IRfidPKDCertificateCompletion completion) {
1059
1062
  paCertificateCompletion = completion;
1060
- completion.onCertificatesReceived(new PKDCertificate[0]);
1061
- sendPACertificateCompletion(serialNumber, issuer);
1063
+ sendEvent(eventPACertificateCompletion, generatePACertificateCompletion(serialNumber, issuer));
1062
1064
  }
1063
1065
 
1064
1066
  @Override
1065
1067
  public void onRequestTACertificates(String keyCAR, @NonNull IRfidPKDCertificateCompletion completion) {
1066
1068
  taCertificateCompletion = completion;
1067
- sendTACertificateCompletion(keyCAR);
1069
+ sendEvent(eventTACertificateCompletion, keyCAR);
1068
1070
  }
1069
1071
 
1070
1072
  @Override
1071
1073
  public void onRequestTASignature(TAChallenge challenge, @NonNull IRfidTASignatureCompletion completion) {
1072
1074
  taSignatureCompletion = completion;
1073
- sendTASignatureCompletion(challenge);
1075
+ sendEvent(eventTASignatureCompletion, generateTAChallenge(challenge));
1074
1076
  }
1075
1077
  };
1076
1078
  }
@@ -1086,17 +1088,26 @@ public class DocumentReader extends CordovaPlugin {
1086
1088
  @Override
1087
1089
  public void onRequestTACertificates(String keyCAR, @NonNull IRfidPKDCertificateCompletion completion) {
1088
1090
  taCertificateCompletion = completion;
1089
- sendTACertificateCompletion(keyCAR);
1091
+ sendEvent(eventTACertificateCompletion, keyCAR);
1090
1092
  }
1091
1093
 
1092
1094
  @Override
1093
1095
  public void onRequestTASignature(TAChallenge challenge, @NonNull IRfidTASignatureCompletion completion) {
1094
1096
  taSignatureCompletion = completion;
1095
- sendTASignatureCompletion(challenge);
1097
+ sendEvent(eventTASignatureCompletion, generateTAChallenge(challenge));
1096
1098
  }
1097
1099
  };
1098
1100
  }
1099
1101
 
1102
+ private IRfidReaderRequest getRfidReaderRequest() {
1103
+ IRfidReaderRequest delegate = null;
1104
+ if (rfidDelegate == RFIDDelegate.NO_PA)
1105
+ delegate = getIRfidReaderRequestNoPA();
1106
+ if (rfidDelegate == RFIDDelegate.FULL)
1107
+ delegate = getIRfidReaderRequest();
1108
+ return delegate;
1109
+ }
1110
+
1100
1111
  private static int rfidDelegate = RFIDDelegate.NULL;
1101
1112
 
1102
1113
  private static class RFIDDelegate {