Skip to content

Commit 6a74023

Browse files
author
Jenkins
committed
6.7.1
1 parent d628ea0 commit 6a74023

16 files changed

Lines changed: 844 additions & 40818 deletions

File tree

android/src/main/java/com/regula/documentreader/Helpers.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ static Bitmap bitmapFromDrawable(Drawable drawable) {
6363
}
6464

6565
static String bitmapToBase64String(Bitmap bitmap) {
66+
if(bitmap == null) return null;
67+
6668
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
6769
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
6870
byte[] byteArray = byteArrayOutputStream.toByteArray();

android/src/main/java/com/regula/documentreader/JSONConstructor.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@ static JSONArray generateIntArray(int[] array) throws JSONException {
149149
return result;
150150
}
151151

152+
static int[] intArrayFromJSON(JSONArray input) throws JSONException {
153+
int[] result = new int[input.length()];
154+
for (int i = 0; i < input.length(); i++)
155+
result[i] = input.getInt(i);
156+
157+
return result;
158+
}
159+
152160
static JSONArray generateByteArray(byte[] array) throws JSONException {
153161
JSONArray result = new JSONArray();
154162
if (array == null) return result;
@@ -186,18 +194,18 @@ static JSONObject generateCompletion(int action, DocumentReaderResults results,
186194
try {
187195
result.put("action", action);
188196
switch (action) {
189-
case DocReaderAction.PROCESS:
190-
case DocReaderAction.PROCESS_WHITE_UV_IMAGES:
191-
break;
192-
case DocReaderAction.NOTIFICATION:
193-
result.put("results", generateDocumentReaderResultsNotification(results));
194-
break;
195197
case DocReaderAction.COMPLETE:
196198
case DocReaderAction.MORE_PAGES_AVAILABLE:
197199
case DocReaderAction.CANCEL:
198200
case DocReaderAction.ERROR:
201+
case DocReaderAction.TIMEOUT:
199202
result.put("results", generateDocumentReaderResults(results, context));
200203
break;
204+
case DocReaderAction.NOTIFICATION:
205+
result.put("results", generateDocumentReaderResultsNotification(results));
206+
break;
207+
default:
208+
break;
201209
}
202210
if (error != null)
203211
result.put("error", generateDocumentReaderException(error));
@@ -470,6 +478,8 @@ static JSONObject generateDocumentReaderTextField(DocumentReaderTextField input,
470478
result.put("values", generateList(input.values, JSONConstructor::generateDocumentReaderValue, context));
471479
result.put("comparisonList", generateList(input.comparisonList, JSONConstructor::generateDocumentReaderComparison));
472480
result.put("validityList", generateList(input.validityList, JSONConstructor::generateDocumentReaderValidity));
481+
result.put("comparisonStatus", input.comparisonStatus);
482+
result.put("validityStatus", input.validityStatus);
473483
} catch (JSONException e) {
474484
e.printStackTrace();
475485
}
@@ -581,9 +591,11 @@ static JSONObject generateDocumentReaderNotification(DocumentReaderNotification
581591
JSONObject result = new JSONObject();
582592
if (input == null) return null;
583593
try {
584-
result.put("code", input.getNotificationCode());
585-
result.put("attachment", input.getDataFileType());
586-
result.put("value", input.getProgress());
594+
result.put("code", input.code);
595+
result.put("value", input.value);
596+
result.put("notificationCode", input.getNotificationCode());
597+
result.put("dataFileType", input.getDataFileType());
598+
result.put("progress", input.getProgress());
587599
} catch (JSONException e) {
588600
e.printStackTrace();
589601
}
@@ -1150,7 +1162,9 @@ static JSONObject generateDocumentReaderResults(DocumentReaderResults input, Con
11501162
JSONObject result = new JSONObject();
11511163
if (input == null) return null;
11521164
try {
1165+
result.put("videoCaptureSessionId", input.videoCaptureSessionId);
11531166
result.put("chipPage", input.chipPage);
1167+
result.put("irElapsedTime", input.irElapsedTime);
11541168
result.put("processingFinishedStatus", input.processingFinishedStatus);
11551169
result.put("elapsedTime", input.elapsedTime);
11561170
result.put("elapsedTimeRFID", input.elapsedTimeRFID);
@@ -1168,6 +1182,7 @@ static JSONObject generateDocumentReaderResults(DocumentReaderResults input, Con
11681182
result.put("rfidSessionData", generateRFIDSessionData(input.rfidSessionData));
11691183
result.put("authenticityResult", generateDocumentReaderAuthenticityResult(input.authenticityResult, context));
11701184
result.put("barcodeResult", generateDocumentReaderBarcodeResult(input.barcodeResult));
1185+
result.put("ppmIn", input.ppmIn);
11711186
result.put("documentType", generateList(input.documentType, JSONConstructor::generateDocumentReaderDocumentType));
11721187
result.put("status", generateDocumentReaderResultsStatus(input.status));
11731188
result.put("vdsncData", generateVDSNCData(input.vdsncData));

android/src/main/java/com/regula/documentreader/RNRegulaDocumentReaderModule.java

Lines changed: 184 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.graphics.Bitmap;
1010
import android.nfc.NfcAdapter;
1111
import android.nfc.tech.IsoDep;
12+
import android.os.Build;
1213
import android.os.Bundle;
1314
import android.util.Base64;
1415

@@ -40,7 +41,9 @@
4041
import com.regula.documentreader.api.params.rfid.PKDCertificate;
4142
import com.regula.documentreader.api.params.rfid.authorization.PAResourcesIssuer;
4243
import com.regula.documentreader.api.params.rfid.authorization.TAChallenge;
44+
import com.regula.documentreader.api.results.DocumentReaderGraphicField;
4345
import com.regula.documentreader.api.results.DocumentReaderResults;
46+
import com.regula.documentreader.api.results.DocumentReaderTextField;
4447
import com.regula.documentreader.api.internal.parser.DocReaderResultsJsonParser;
4548

4649
import org.json.JSONArray;
@@ -127,7 +130,17 @@ public void onHostPause() {
127130
public void onHostDestroy() {
128131
}
129132

133+
@SuppressWarnings({"WrapperTypeMayBePrimitive", "unchecked"})
130134
private <T> T args(int index) throws JSONException {
135+
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
136+
// Rewrite it according to react native documentation!!!
137+
// the is no int or double in js so all ints are sent as double by default
138+
Object value = data.get(index);
139+
if (value instanceof Double)
140+
if ((Double) value % 1 == 0) {
141+
Integer intValue = ((Double) value).intValue();
142+
return (T) intValue;
143+
}
131144
//noinspection unchecked
132145
return (T) data.get(index);
133146
}
@@ -414,6 +427,57 @@ public void error(String s) {
414427
case "recognizeImagesWithImageInputs":
415428
recognizeImagesWithImageInputs(callback, args(0));
416429
break;
430+
case "textFieldValueByType":
431+
textFieldValueByType(callback, args(0), args(1));
432+
break;
433+
case "textFieldValueByTypeLcid":
434+
textFieldValueByTypeLcid(callback, args(0), args(1), args(2));
435+
break;
436+
case "textFieldValueByTypeSource":
437+
textFieldValueByTypeSource(callback, args(0), args(1), args(2));
438+
break;
439+
case "textFieldValueByTypeLcidSource":
440+
textFieldValueByTypeLcidSource(callback, args(0), args(1), args(2), args(3));
441+
break;
442+
case "textFieldValueByTypeSourceOriginal":
443+
textFieldValueByTypeSourceOriginal(callback, args(0), args(1), args(2), args(3));
444+
break;
445+
case "textFieldValueByTypeLcidSourceOriginal":
446+
textFieldValueByTypeLcidSourceOriginal(callback, args(0), args(1), args(2), args(3), args(4));
447+
break;
448+
case "textFieldByType":
449+
textFieldByType(callback, args(0), args(1));
450+
break;
451+
case "textFieldByTypeLcid":
452+
textFieldByTypeLcid(callback, args(0), args(1), args(2));
453+
break;
454+
case "graphicFieldByTypeSource":
455+
graphicFieldByTypeSource(callback, args(0), args(1), args(2));
456+
break;
457+
case "graphicFieldByTypeSourcePageIndex":
458+
graphicFieldByTypeSourcePageIndex(callback, args(0), args(1), args(2), args(3));
459+
break;
460+
case "graphicFieldByTypeSourcePageIndexLight":
461+
graphicFieldByTypeSourcePageIndexLight(callback, args(0), args(1), args(2), args(3), args(4));
462+
break;
463+
case "graphicFieldImageByType":
464+
graphicFieldImageByType(callback, args(0), args(1));
465+
break;
466+
case "graphicFieldImageByTypeSource":
467+
graphicFieldImageByTypeSource(callback, args(0), args(1), args(2));
468+
break;
469+
case "graphicFieldImageByTypeSourcePageIndex":
470+
graphicFieldImageByTypeSourcePageIndex(callback, args(0), args(1), args(2), args(3));
471+
break;
472+
case "graphicFieldImageByTypeSourcePageIndexLight":
473+
graphicFieldImageByTypeSourcePageIndexLight(callback, args(0), args(1), args(2), args(3), args(4));
474+
break;
475+
case "containers":
476+
containers(callback, args(0), args(1));
477+
break;
478+
case "encryptedContainers":
479+
encryptedContainers(callback, args(0));
480+
break;
417481
}
418482
} catch (Exception e) {
419483
e.printStackTrace();
@@ -430,8 +494,10 @@ private void startForegroundDispatch(final Activity activity) {
430494
};
431495
Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
432496
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
433-
@SuppressLint("UnspecifiedImmutableFlag")
434-
PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);
497+
int flags = 0;
498+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
499+
flags = PendingIntent.FLAG_IMMUTABLE;
500+
PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, flags);
435501
NfcAdapter.getDefaultAdapter(getActivity()).enableForegroundDispatch(activity, pendingIntent, filters, techList);
436502
}
437503

@@ -482,6 +548,7 @@ private void startBluetoothService(Callback callback) {
482548
callback.success();
483549
}
484550

551+
@SuppressLint("MissingPermission")
485552
private void initializeReaderBleDeviceConfig(Callback callback) {
486553
if (BluetoothUtil.Companion.getBleManager() == null) callback.error("bleManager is null");
487554
if (!Instance().isReady())
@@ -794,15 +861,126 @@ private void provideTASignature(Callback callback, Object signature) {
794861
callback.success();
795862
}
796863

797-
private void setCameraSessionIsPaused(Callback callback, @SuppressWarnings("unused") boolean ignored) {
798-
callback.error("setCameraSessionIsPaused() is an ios-only method");
799-
}
800-
801864
private void setRfidDelegate(Callback callback, int delegate) {
802865
rfidDelegate = delegate;
803866
callback.success();
804867
}
805868

869+
private void textFieldValueByType(Callback callback, String raw, int fieldType) {
870+
DocumentReaderResults results = DocumentReaderResults.fromRawResults(raw);
871+
callback.success(results.getTextFieldValueByType(fieldType));
872+
}
873+
874+
private void textFieldValueByTypeLcid(Callback callback, String raw, int fieldType, int lcid) {
875+
DocumentReaderResults results = DocumentReaderResults.fromRawResults(raw);
876+
callback.success(results.getTextFieldValueByType(fieldType, lcid));
877+
}
878+
879+
private void textFieldValueByTypeSource(Callback callback, String raw, int fieldType, int source) {
880+
DocumentReaderResults results = DocumentReaderResults.fromRawResults(raw);
881+
callback.success(results.getTextFieldValueByTypeAndSource(fieldType, source));
882+
}
883+
884+
private void textFieldValueByTypeLcidSource(Callback callback, String raw, int fieldType, int lcid, int source) {
885+
DocumentReaderResults results = DocumentReaderResults.fromRawResults(raw);
886+
callback.success(results.getTextFieldValueByType(fieldType, lcid, source));
887+
}
888+
889+
private void textFieldValueByTypeSourceOriginal(Callback callback, String raw, int fieldType, int source, boolean original) {
890+
DocumentReaderResults results = DocumentReaderResults.fromRawResults(raw);
891+
callback.success(results.getTextFieldValueByTypeAndSource(fieldType, source, original));
892+
}
893+
894+
private void textFieldValueByTypeLcidSourceOriginal(Callback callback, String raw, int fieldType, int lcid, int source, boolean original) {
895+
DocumentReaderResults results = DocumentReaderResults.fromRawResults(raw);
896+
callback.success(results.getTextFieldValueByType(fieldType, lcid, source, original));
897+
}
898+
899+
private void textFieldByType(Callback callback, String raw, int fieldType) {
900+
DocumentReaderResults results = DocumentReaderResults.fromRawResults(raw);
901+
DocumentReaderTextField result = results.getTextFieldByType(fieldType);
902+
if (result == null)
903+
callback.success(null);
904+
else
905+
callback.success(JSONConstructor.generateDocumentReaderTextField(result, getContext()).toString());
906+
}
907+
908+
private void textFieldByTypeLcid(Callback callback, String raw, int fieldType, int lcid) {
909+
DocumentReaderResults results = DocumentReaderResults.fromRawResults(raw);
910+
DocumentReaderTextField result = results.getTextFieldByType(fieldType, lcid);
911+
if (result == null)
912+
callback.success(null);
913+
else
914+
callback.success(JSONConstructor.generateDocumentReaderTextField(result, getContext()).toString());
915+
}
916+
917+
private void graphicFieldByTypeSource(Callback callback, String raw, int fieldType, int source) {
918+
DocumentReaderResults results = DocumentReaderResults.fromRawResults(raw);
919+
DocumentReaderGraphicField result = results.getGraphicFieldByType(fieldType, source);
920+
if (result == null)
921+
callback.success(null);
922+
else
923+
callback.success(JSONConstructor.generateDocumentReaderGraphicField(result, getContext()).toString());
924+
}
925+
926+
private void graphicFieldByTypeSourcePageIndex(Callback callback, String raw, int fieldType, int source, int pageIndex) {
927+
DocumentReaderResults results = DocumentReaderResults.fromRawResults(raw);
928+
DocumentReaderGraphicField result = results.getGraphicFieldByType(fieldType, source, pageIndex);
929+
if (result == null)
930+
callback.success(null);
931+
else
932+
callback.success(JSONConstructor.generateDocumentReaderGraphicField(result, getContext()).toString());
933+
}
934+
935+
private void graphicFieldByTypeSourcePageIndexLight(Callback callback, String raw, int fieldType, int source, int pageIndex, int light) {
936+
DocumentReaderResults results = DocumentReaderResults.fromRawResults(raw);
937+
DocumentReaderGraphicField result = results.getGraphicFieldByType(fieldType, source, pageIndex, light);
938+
if (result == null)
939+
callback.success(null);
940+
else
941+
callback.success(JSONConstructor.generateDocumentReaderGraphicField(result, getContext()).toString());
942+
}
943+
944+
private void graphicFieldImageByType(Callback callback, String raw, int fieldType) {
945+
DocumentReaderResults results = DocumentReaderResults.fromRawResults(raw);
946+
callback.success(Helpers.bitmapToBase64String(results.getGraphicFieldImageByType(fieldType)));
947+
}
948+
949+
private void graphicFieldImageByTypeSource(Callback callback, String raw, int fieldType, int source) {
950+
DocumentReaderResults results = DocumentReaderResults.fromRawResults(raw);
951+
callback.success(Helpers.bitmapToBase64String(results.getGraphicFieldImageByType(fieldType, source)));
952+
}
953+
954+
private void graphicFieldImageByTypeSourcePageIndex(Callback callback, String raw, int fieldType, int source, int pageIndex) {
955+
DocumentReaderResults results = DocumentReaderResults.fromRawResults(raw);
956+
callback.success(Helpers.bitmapToBase64String(results.getGraphicFieldImageByType(fieldType, source, pageIndex)));
957+
}
958+
959+
private void graphicFieldImageByTypeSourcePageIndexLight(Callback callback, String raw, int fieldType, int source, int pageIndex, int light) {
960+
DocumentReaderResults results = DocumentReaderResults.fromRawResults(raw);
961+
callback.success(Helpers.bitmapToBase64String(results.getGraphicFieldImageByType(fieldType, source, pageIndex, light)));
962+
}
963+
964+
@SuppressLint("WrongConstant")
965+
private void containers(Callback callback, String raw, JSONArray resultType) {
966+
try {
967+
DocumentReaderResults results = DocumentReaderResults.fromRawResults(raw);
968+
callback.success(results.getContainers(JSONConstructor.intArrayFromJSON(resultType)));
969+
} catch (JSONException e) {
970+
e.printStackTrace();
971+
callback.error(e.toString());
972+
}
973+
}
974+
975+
private void encryptedContainers(Callback callback, String raw) {
976+
DocumentReaderResults results = DocumentReaderResults.fromRawResults(raw);
977+
callback.success(results.getEncryptedContainers());
978+
}
979+
980+
private void setCameraSessionIsPaused(Callback callback, @SuppressWarnings("unused") boolean ignored) {
981+
callback.error("setCameraSessionIsPaused() is an ios-only method");
982+
}
983+
806984
private void getCameraSessionIsPaused(Callback callback) {
807985
callback.error("getCameraSessionIsPaused() is an ios-only method");
808986
}

android/src/main/java/com/regula/documentreader/RegulaConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ private static void setProcessParams(ProcessParam processParams, JSONObject opts
227227
processParams.respectImageQuality = opts.getBoolean("respectImageQuality");
228228
if (opts.has("splitNames"))
229229
processParams.splitNames = opts.getBoolean("splitNames");
230+
if (opts.has("convertCase"))
231+
processParams.convertCase = opts.getInt("convertCase");
230232
}
231233

232234
private static void setCustomization(ParamsCustomization customization, JSONObject opts, Context context) throws JSONException {
@@ -516,6 +518,7 @@ private static JSONObject getProcessParams(ProcessParam processParams) throws JS
516518
object.put("documentGroupFilter", generateIntArray(processParams.documentGroupFilter));
517519
object.put("respectImageQuality", processParams.respectImageQuality);
518520
object.put("splitNames", processParams.splitNames);
521+
object.put("convertCase", processParams.convertCase);
519522

520523
return object;
521524
}

0 commit comments

Comments
 (0)