99import android .graphics .Bitmap ;
1010import android .nfc .NfcAdapter ;
1111import android .nfc .tech .IsoDep ;
12+ import android .os .Build ;
1213import android .os .Bundle ;
1314import android .util .Base64 ;
1415
4041import com .regula .documentreader .api .params .rfid .PKDCertificate ;
4142import com .regula .documentreader .api .params .rfid .authorization .PAResourcesIssuer ;
4243import com .regula .documentreader .api .params .rfid .authorization .TAChallenge ;
44+ import com .regula .documentreader .api .results .DocumentReaderGraphicField ;
4345import com .regula .documentreader .api .results .DocumentReaderResults ;
46+ import com .regula .documentreader .api .results .DocumentReaderTextField ;
4447import com .regula .documentreader .api .internal .parser .DocReaderResultsJsonParser ;
4548
4649import 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 }
0 commit comments