1919import com .regula .documentreader .api .results .DocumentReaderDocumentType ;
2020import com .regula .documentreader .api .results .DocumentReaderGraphicField ;
2121import com .regula .documentreader .api .results .DocumentReaderGraphicResult ;
22- import com .regula .documentreader .api .results .DocumentReaderJsonResult ;
23- import com .regula .documentreader .api .results .DocumentReaderJsonResultGroup ;
2422import com .regula .documentreader .api .results .DocumentReaderNotification ;
2523import com .regula .documentreader .api .results .DocumentReaderResults ;
2624import com .regula .documentreader .api .results .DocumentReaderScenarioFull ;
6361
6462import java .io .ByteArrayInputStream ;
6563import java .io .ByteArrayOutputStream ;
64+ import java .util .ArrayList ;
6665import java .util .List ;
6766import java .util .Map ;
6867import java .util .Objects ;
@@ -133,8 +132,8 @@ static JSONObject resultsToJsonObject(DocumentReaderResults results, Context con
133132 jsonObject .put ("graphicResult" , generateDocumentReaderGraphicResult (results .graphicResult , context ));
134133 if (results .imageQuality != null )
135134 jsonObject .put ("imageQuality" , generateImageQualityGroup (results .imageQuality , context ));
136- if (results .jsonResult != null )
137- jsonObject .put ("jsonResult " , generateDocumentReaderJsonResult ( results .jsonResult , context ) );
135+ if (results .rawResult != null )
136+ jsonObject .put ("rawResult " , results .rawResult );
138137 if (results .mrzPosition != null )
139138 jsonObject .put ("mrzPosition" , generateElementPosition (results .mrzPosition ));
140139 if (results .rfidSessionData != null )
@@ -257,8 +256,8 @@ static private JSONObject generateDocumentReaderGraphicField(DocumentReaderGraph
257256 result .put ("lightName" , eRPRM_Lights .getTranslation (context , documentReaderGraphicField .light ));
258257 result .put ("pageIndex" , documentReaderGraphicField .pageIndex );
259258 result .put ("value" , documentReaderGraphicField .imageBase64 ());
260- if (documentReaderGraphicField .getRect () != null )
261- result .put ("fieldRect" , generateDocReaderFieldRect (documentReaderGraphicField .getRect () ));
259+ if (documentReaderGraphicField .boundRect != null )
260+ result .put ("fieldRect" , generateDocReaderFieldRect (documentReaderGraphicField .boundRect ));
262261
263262 return result ;
264263 }
@@ -299,20 +298,6 @@ static private JSONObject generateImageQuality(ImageQuality imageQuality, Contex
299298 return result ;
300299 }
301300
302- static private JSONObject generateDocumentReaderJsonResult (DocumentReaderJsonResult documentReaderJsonResult , Context context ) throws JSONException {
303- return new JSONObject ().put ("results" , generateList (documentReaderJsonResult .results , JSONConstructor ::generateDocumentReaderJsonResultGroup , context ));
304- }
305-
306- static private JSONObject generateDocumentReaderJsonResultGroup (DocumentReaderJsonResultGroup documentReaderJsonResultGroup , Context context ) throws JSONException {
307- JSONObject result = new JSONObject ();
308- result .put ("lightType" , documentReaderJsonResultGroup .lightType );
309- result .put ("pageIdx" , documentReaderJsonResultGroup .pageIdx );
310- result .put ("resultType" , documentReaderJsonResultGroup .resultType );
311- result .put ("jsonResult" , documentReaderJsonResultGroup .jsonResult );
312-
313- return result ;
314- }
315-
316301 static private JSONObject generateRfidSessionData (RFIDSessionData rfidSessionData , Context context ) throws JSONException {
317302 JSONObject result = new JSONObject ();
318303 result .put ("totalBytesSent" , rfidSessionData .totalBytesSent );
@@ -681,25 +666,28 @@ static JSONArray generateByteArray(byte[] array) throws JSONException {
681666 return result ;
682667 }
683668
684- static JSONObject generateCompletion (int action , DocumentReaderResults results , Throwable error , Context context ) throws JSONException {
669+ static JSONObject generateCompletion (int action , DocumentReaderResults results , Throwable error , Context context ) {
685670 JSONObject result = new JSONObject ();
686- result .put ("action" , action );
687- switch (action ) {
688- case DocReaderAction .PROCESS :
689- case DocReaderAction .PROCESS_WHITE_UV_IMAGES :
690- result .put ("results" , "" );
691- break ;
692- case DocReaderAction .NOTIFICATION :
693- result .put ("results" , resultsToJsonObjectNotification (results ));
694- break ;
695- case DocReaderAction .COMPLETE :
696- case DocReaderAction .MORE_PAGES_AVAILABLE :
697- case DocReaderAction .CANCEL :
698- case DocReaderAction .ERROR :
699- result .put ("results" , resultsToJsonObject (results , context ));
700- break ;
671+ try {
672+ result .put ("action" , action );
673+ switch (action ) {
674+ case DocReaderAction .PROCESS :
675+ case DocReaderAction .PROCESS_WHITE_UV_IMAGES :
676+ result .put ("results" , "" );
677+ break ;
678+ case DocReaderAction .NOTIFICATION :
679+ result .put ("results" , resultsToJsonObjectNotification (results ));
680+ break ;
681+ case DocReaderAction .COMPLETE :
682+ case DocReaderAction .MORE_PAGES_AVAILABLE :
683+ case DocReaderAction .CANCEL :
684+ case DocReaderAction .ERROR :
685+ result .put ("results" , resultsToJsonObject (results , context ));
686+ break ;
687+ }
688+ result .put ("error" , generateThrowable (error , context ));
689+ } catch (JSONException ignored ) {
701690 }
702- result .put ("error" , generateThrowable (error , context ));
703691
704692 return result ;
705693 }
@@ -710,7 +698,7 @@ static JSONObject generateThrowable(Throwable throwable, Context context) throws
710698 return result ;
711699 result .put ("localizedMessage" , throwable .getLocalizedMessage ());
712700 result .put ("message" , throwable .getMessage ());
713- result .put ("toString " , throwable .toString ());
701+ result .put ("string " , throwable .toString ());
714702 result .put ("stackTrace" , generateArray (throwable .getStackTrace (), JSONConstructor ::generateStackTraceElement , context ));
715703
716704 return result ;
@@ -725,7 +713,7 @@ static JSONObject generateStackTraceElement(StackTraceElement e, Context context
725713 result .put ("lineNumber" , e .getLineNumber ());
726714 result .put ("methodName" , e .getMethodName ());
727715 result .put ("isNativeMethod" , e .isNativeMethod ());
728- result .put ("toString " , e .toString ());
716+ result .put ("string " , e .toString ());
729717
730718 return result ;
731719 }
@@ -734,14 +722,13 @@ static JSONObject generateStackTraceElement(StackTraceElement e, Context context
734722
735723 static Bitmap bitmapFromBase64 (String base64 ) {
736724 byte [] decodedString = Base64 .decode (base64 , Base64 .DEFAULT );
737- return BitmapFactory .decodeByteArray (decodedString , 0 , decodedString .length );
738- }
739-
740- static byte [] byteArrayFromJson (JSONArray array ) throws JSONException {
741- byte [] bytes = new byte [array .length ()];
742- for (int i = 0 ; i < array .length (); i ++)
743- bytes [i ] = (byte ) array .getInt (i );
744- return bytes ;
725+ BitmapFactory .Options options = new BitmapFactory .Options ();
726+ options .inPreferredConfig = Bitmap .Config .RGB_565 ;
727+ Bitmap result = BitmapFactory .decodeByteArray (decodedString , 0 , decodedString .length , options );
728+ int sizeMultiplier = result .getByteCount () / 5000000 ;
729+ if (result .getByteCount () > 5000000 )
730+ result = Bitmap .createScaledBitmap (result , result .getWidth () / (int ) Math .sqrt (sizeMultiplier ), result .getHeight () / (int ) Math .sqrt (sizeMultiplier ), false );
731+ return result ;
745732 }
746733
747734 static Drawable drawableFromBase64 (String base64 , Context context ) {
@@ -827,4 +814,11 @@ static Bounds boundsFromJson(JSONObject object) throws JSONException {
827814
828815 return result ;
829816 }
817+
818+ static List <String > stringListFromJson (JSONArray jsonArray ) {
819+ List <String > result = new ArrayList <>();
820+ for (int i = 0 ; i < jsonArray .length (); i ++)
821+ result .add (jsonArray .optString (i ));
822+ return result ;
823+ }
830824}
0 commit comments