accurascan_kyc 0.1.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 (66) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +635 -0
  3. package/accurascan-kyc.podspec +38 -0
  4. package/android/build.gradle +118 -0
  5. package/android/gradle.properties +5 -0
  6. package/android/src/main/AndroidManifest.xml +18 -0
  7. package/android/src/main/java/com/accurascankyc/AccurascanKycModule.java +507 -0
  8. package/android/src/main/java/com/accurascankyc/AccurascanKycPackage.java +28 -0
  9. package/android/src/main/java/com/accurascankyc/ActivityFaceMatch.java +533 -0
  10. package/android/src/main/java/com/accurascankyc/BorderTextView.java +82 -0
  11. package/android/src/main/java/com/accurascankyc/OcrActivity.java +1263 -0
  12. package/android/src/main/java/com/accurascankyc/OcrResultActivity.java +736 -0
  13. package/android/src/main/java/com/accurascankyc/ReactNativeJson.java +123 -0
  14. package/android/src/main/java/com/accurascankyc/UnsafeOkHttpClient.java +57 -0
  15. package/android/src/main/res/drawable/btn_bg_gray.xml +6 -0
  16. package/android/src/main/res/drawable/btn_bg_red.xml +6 -0
  17. package/android/src/main/res/drawable/btn_bg_trasparent_bottom.xml +6 -0
  18. package/android/src/main/res/drawable/flip_camera_icon.png +0 -0
  19. package/android/src/main/res/drawable/ic_close.xml +5 -0
  20. package/android/src/main/res/drawable/round_border_rect.xml +12 -0
  21. package/android/src/main/res/drawable/splash.png +0 -0
  22. package/android/src/main/res/drawable-v24/ic_launcher_foreground.png +0 -0
  23. package/android/src/main/res/drawable-xhdpi/bg_home.png +0 -0
  24. package/android/src/main/res/drawable-xhdpi/ic_barcode.png +0 -0
  25. package/android/src/main/res/drawable-xhdpi/ic_biometric.png +0 -0
  26. package/android/src/main/res/drawable-xhdpi/ic_check.png +0 -0
  27. package/android/src/main/res/drawable-xhdpi/ic_liveness.png +0 -0
  28. package/android/src/main/res/drawable-xhdpi/ic_result.png +0 -0
  29. package/android/src/main/res/drawable-xhdpi/ic_scan.png +0 -0
  30. package/android/src/main/res/drawable-xhdpi/img_button_overlay.png +0 -0
  31. package/android/src/main/res/layout/activity_ocr_result.xml +18 -0
  32. package/android/src/main/res/layout/activity_splash.xml +26 -0
  33. package/android/src/main/res/layout/custom_frame_layout.xml +144 -0
  34. package/android/src/main/res/layout/ocr_activity.xml +28 -0
  35. package/android/src/main/res/layout-land/custom_frame_layout.xml +144 -0
  36. package/android/src/main/res/layout-land/ocr_activity.xml +41 -0
  37. package/android/src/main/res/menu/menu_land_port.xml +7 -0
  38. package/android/src/main/res/mipmap-hdpi/logo_loign.png +0 -0
  39. package/android/src/main/res/mipmap-mdpi/logo_loign.png +0 -0
  40. package/android/src/main/res/mipmap-xhdpi/ic_document_verified.png +0 -0
  41. package/android/src/main/res/mipmap-xhdpi/logo_loign.png +0 -0
  42. package/android/src/main/res/mipmap-xxhdpi/logo_loign.png +0 -0
  43. package/android/src/main/res/values/colors.xml +31 -0
  44. package/android/src/main/res/values/strings.xml +42 -0
  45. package/android/src/main/res/values/styles.xml +191 -0
  46. package/ios/AccurascanKyc-Bridging-Header.h +2 -0
  47. package/ios/AccurascanKyc.m +34 -0
  48. package/ios/AccurascanKyc.swift +649 -0
  49. package/ios/AccurascanKyc.xcodeproj/project.pbxproj +283 -0
  50. package/ios/AccurascanKyc.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
  51. package/ios/FMController.swift +587 -0
  52. package/ios/LVController.swift +346 -0
  53. package/ios/MainStoryboard_iPhone.storyboard +338 -0
  54. package/ios/ViewController.swift +2686 -0
  55. package/ios/resources/back_icon.png +0 -0
  56. package/ios/resources/flip_camera_icon.png +0 -0
  57. package/ios/resources/flip_document_icon.png +0 -0
  58. package/ios/resources/ic_logo.png +0 -0
  59. package/lib/commonjs/index.js +13 -0
  60. package/lib/commonjs/index.js.map +1 -0
  61. package/lib/module/index.js +6 -0
  62. package/lib/module/index.js.map +1 -0
  63. package/lib/typescript/index.d.ts +3 -0
  64. package/lib/typescript/index.d.ts.map +1 -0
  65. package/package.json +161 -0
  66. package/src/index.tsx +5 -0
@@ -0,0 +1,1263 @@
1
+ package com.accurascankyc;
2
+
3
+ import android.app.Dialog;
4
+ import android.content.Intent;
5
+ import android.content.pm.ActivityInfo;
6
+ import android.content.res.Resources;
7
+ import android.graphics.Bitmap;
8
+ import android.graphics.BitmapFactory;
9
+ import android.graphics.Rect;
10
+ import android.graphics.Color;
11
+ import android.graphics.Paint;
12
+ import android.graphics.drawable.GradientDrawable;
13
+ import android.os.Bundle;
14
+ import android.os.Handler;
15
+ import android.os.Message;
16
+ import android.text.TextUtils;
17
+ import android.util.Base64;
18
+ import android.util.Log;
19
+ import android.util.TypedValue;
20
+ import android.view.View;
21
+ import android.view.ViewGroup;
22
+ import android.view.Window;
23
+ import android.widget.ImageView;
24
+ import android.widget.RelativeLayout;
25
+ import android.widget.TextView;
26
+ import android.widget.Toast;
27
+
28
+ import androidx.annotation.Nullable;
29
+
30
+ import com.accurascan.facedetection.utils.AccuraLivenessLog;
31
+ import com.accurascan.ocr.mrz.CameraView;
32
+ import com.accurascan.ocr.mrz.customview.CustomTextView;
33
+ import com.accurascan.ocr.mrz.interfaces.OcrCallback;
34
+ import com.accurascan.ocr.mrz.model.BarcodeFormat;
35
+ import com.accurascan.ocr.mrz.model.CardDetails;
36
+ import com.accurascan.ocr.mrz.model.OcrData;
37
+ import com.accurascan.ocr.mrz.model.PDF417Data;
38
+ import com.accurascan.ocr.mrz.model.RecogResult;
39
+ import com.accurascan.ocr.mrz.motiondetection.SensorsActivity;
40
+ import com.accurascan.ocr.mrz.util.AccuraLog;
41
+ import com.docrecog.scan.MRZDocumentType;
42
+ import com.docrecog.scan.RecogEngine;
43
+ import com.docrecog.scan.RecogType;
44
+
45
+ import org.json.JSONException;
46
+ import org.json.JSONObject;
47
+
48
+ import java.io.File;
49
+ import java.io.FileNotFoundException;
50
+ import java.io.FileOutputStream;
51
+ import java.io.IOException;
52
+ import java.io.OutputStream;
53
+ import java.lang.ref.WeakReference;
54
+ import java.security.cert.CertificateException;
55
+ import java.util.Arrays;
56
+ import java.util.List;
57
+
58
+ import javax.net.ssl.HostnameVerifier;
59
+ import javax.net.ssl.SSLContext;
60
+ import javax.net.ssl.SSLSession;
61
+ import javax.net.ssl.SSLSocketFactory;
62
+ import javax.net.ssl.TrustManager;
63
+ import javax.net.ssl.X509TrustManager;
64
+
65
+ import okhttp3.OkHttpClient;
66
+
67
+
68
+ public class OcrActivity extends SensorsActivity implements OcrCallback {
69
+
70
+ private static final String TAG = OcrActivity.class.getSimpleName();
71
+ private CameraView cameraView;
72
+ private View viewLeft, viewRight, borderFrame,logoImg,viewTop,viewBottom;
73
+ private BorderTextView tvTitle, tvScanMessage;
74
+ private ImageView imageFlip;
75
+ private int cardId;
76
+ private int countryId;
77
+ public static RecogType recogType;
78
+ Dialog types_dialog;
79
+ private String cardName;
80
+ private boolean isBack = false;
81
+ private MRZDocumentType mrzType;
82
+ public static JSONObject accuraErrorConfg;
83
+ public static JSONObject accuraTitleMsg;
84
+ public static int barcodeFormat;
85
+ private Bitmap frame;
86
+
87
+ private static class MyHandler extends Handler {
88
+
89
+ private final WeakReference<OcrActivity> mActivity;
90
+
91
+ public MyHandler(OcrActivity activity) {
92
+ mActivity = new WeakReference<>(activity);
93
+ }
94
+
95
+ @Override
96
+ public void handleMessage(Message msg) {
97
+ OcrActivity activity = mActivity.get();
98
+ // try{
99
+ // if(accuraErrorConfg.getInt("enableLogs") == 1){
100
+ // AccuraLog.enableLogs(true); // make sure to disable logs in release mode
101
+ // AccuraLivenessLog.setDEBUG(true);
102
+ // AccuraLog.refreshLogfile(activity);
103
+ // }
104
+ // } catch (JSONException e) {
105
+ // e.printStackTrace();
106
+ // }
107
+
108
+
109
+ if (activity != null) {
110
+ String s = "";
111
+ if (msg.obj instanceof String) s = (String) msg.obj;
112
+ switch (msg.what) {
113
+ case 0: activity.tvTitle.setText(s);break;
114
+ case 1: activity.tvScanMessage.setText(s);break;
115
+ case 2:
116
+ try {
117
+ if(accuraErrorConfg.getInt("isFlipImg") == 1){
118
+ if (activity.cameraView != null) activity.cameraView.flipImage(activity.imageFlip);
119
+ }
120
+ } catch (JSONException e) {
121
+ e.printStackTrace();
122
+ }
123
+ break;
124
+ default: break;
125
+ }
126
+ }
127
+ super.handleMessage(msg);
128
+ }
129
+ }
130
+
131
+ private Handler handler = new MyHandler(this);
132
+ String type = "";
133
+ Boolean needCallback = true;
134
+ @Override
135
+ public void onCreate(Bundle savedInstanceState) {
136
+ if (cameraView != null) cameraView.startOcrScan(false);
137
+
138
+
139
+
140
+ int orientation = getResources().getConfiguration().orientation;
141
+ if (orientation == 1) {
142
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
143
+ } else {
144
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
145
+ }
146
+ super.onCreate(savedInstanceState);
147
+ requestWindowFeature(Window.FEATURE_NO_TITLE); // Hide the window title.
148
+ setContentView(R.layout.ocr_activity);
149
+ AccuraLog.loge(TAG, "Start Camera Activity");
150
+ init();
151
+
152
+ // recogType = RecogType.detachFrom(getIntent());
153
+ if (getIntent().hasExtra(MRZDocumentType.class.getName())) {
154
+ recogType = RecogType.MRZ;
155
+ mrzType = MRZDocumentType.detachFrom(getIntent());
156
+ } else {
157
+ mrzType = MRZDocumentType.NONE;
158
+ }
159
+ cardId = getIntent().getIntExtra("card_id", 0);
160
+ countryId = getIntent().getIntExtra("country_id", 0);
161
+ cardName = getIntent().getStringExtra("card_name");
162
+
163
+ AccuraLog.loge(TAG, "RecogType " + recogType);
164
+ AccuraLog.loge(TAG, "Card Id " + cardId);
165
+ AccuraLog.loge(TAG, "Country Id " + countryId);
166
+
167
+ initCamera();
168
+
169
+ // try {
170
+ // if(accuraErrorConfg.getInt("isShowLogo") == 0){
171
+ // logoImg.setVisibility(View.GONE);
172
+ // }else{
173
+ // logoImg.setVisibility(View.VISIBLE);
174
+ // }
175
+ // } catch (JSONException e) {
176
+ // e.printStackTrace();
177
+ // }
178
+ // if (bundle.containsKey("IS_SHOW_LOGO")) {
179
+ // Boolean isShow = bundle.getBoolean("IS_SHOW_LOGO");
180
+ // Log.i(TAG, "isSHow:- " + isShow);
181
+ // viewImageLayer.setVisibility( isShow ? View.VISIBLE : View.GONE);
182
+ // }
183
+
184
+ // if (recogType == RecogType.BARCODE) {
185
+ // barcodeFormatDialog();
186
+ // }
187
+ }
188
+
189
+ private void initCamera() {
190
+ AccuraLog.loge(TAG, "Initialized camera");
191
+ //<editor-fold desc="To get status bar height">
192
+ Rect rectangle = new Rect();
193
+ Window window = getWindow();
194
+ window.getDecorView().getWindowVisibleDisplayFrame(rectangle);
195
+ int statusBarTop = rectangle.top;
196
+ int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
197
+ int statusBarHeight = contentViewTop - statusBarTop;
198
+ //</editor-fold>
199
+
200
+ RelativeLayout linearLayout = findViewById(R.id.ocr_root); // layout width and height is match_parent
201
+
202
+ cameraView = new CameraView(this);
203
+ if (recogType == RecogType.OCR || recogType == RecogType.DL_PLATE) {
204
+ // must have to set data for RecogType.OCR and RecogType.DL_PLATE
205
+ cameraView.setCountryId(countryId).setCardId(cardId)
206
+ .setMinFrameForValidate(3); // to set min frame for qatar Id card
207
+ } else if (recogType == RecogType.PDF417) {
208
+ // must have to set data RecogType.PDF417
209
+ cameraView.setCountryId(countryId);
210
+ } else if (recogType == RecogType.MRZ) {
211
+ cameraView.setMRZDocumentType(mrzType);
212
+ // Pass 'all' for accepting MRZs of all countries
213
+ // or you can pass respective country codes of countries whose MRZ you want to accept. Eg:- IND, USA, TUN, etc.
214
+ cameraView.setMRZCountryCodeList("all");
215
+ }
216
+
217
+ cameraView.setRecogType(recogType)
218
+ .setView(linearLayout) // To add camera view
219
+ .setOcrCallback(this) // To get Update and Success Call back
220
+ .setStatusBarHeight(statusBarHeight) // To remove Height from Camera View if status bar visible
221
+ .setFrontSide();
222
+ cameraView.setCameraFacing(0);//(accuraErrorConfg.getInt("setCameraFacing")); // To set front or back camera.
223
+
224
+ if (recogType == RecogType.BARCODE) {
225
+ cameraView.setBarcodeFormat(barcodeFormat);
226
+ }
227
+ // optional field
228
+ // .setEnableMediaPlayer(false) // false to disable sound and true to enable sound and default it is true
229
+ // .setCustomMediaPlayer(MediaPlayer.create(this, com.accurascan.ocr.mrz.R.raw.beep)) // To add your custom sound and Must have to enable media player
230
+ cameraView.init(); // initialized camera
231
+ }
232
+
233
+ private void init() {
234
+ viewLeft = findViewById(R.id.view_left_frame);
235
+ viewRight = findViewById(R.id.view_right_frame);
236
+ viewTop = findViewById(R.id.view_top_frame);
237
+ viewBottom = findViewById(R.id.view_bottom_frame);
238
+
239
+ borderFrame = findViewById(R.id.border_frame);
240
+ tvTitle = findViewById(R.id.tv_title);
241
+ tvScanMessage = findViewById(R.id.tv_scan_msg);
242
+ imageFlip = findViewById(R.id.im_flip_image);
243
+ logoImg = findViewById(R.id.imageLOGO);
244
+ // btn_barcode_selection = findViewById(R.id.select_type);
245
+ View btn_flip = findViewById(R.id.btn_flip);
246
+ btn_flip.setOnClickListener(v -> {
247
+ if (cameraView!=null) {
248
+ cameraView.flipCamera();
249
+ }
250
+ });
251
+
252
+ // try {
253
+ // if (accuraErrorConfg.getInt("CameraScreen_Change_Button") == 0){
254
+ // btn_flip.setVisibility(View.GONE);
255
+ // }else{
256
+ // }
257
+ // } catch (JSONException e) {
258
+ // e.printStackTrace();
259
+ // }
260
+
261
+
262
+ String screenColor = "#00000000";
263
+ try {
264
+ if (accuraErrorConfg.getString("CameraScreen_Color").equals("") || !accuraErrorConfg.has("CameraScreen_Color")){
265
+ screenColor = "#00000000";
266
+ }else{
267
+ screenColor = accuraErrorConfg.getString("CameraScreen_Color");
268
+ }
269
+ } catch (JSONException e) {
270
+ e.printStackTrace();
271
+ }
272
+
273
+ viewLeft.setBackgroundColor(Color.parseColor(screenColor));
274
+ viewRight.setBackgroundColor(Color.parseColor(screenColor));
275
+ viewTop.setBackgroundColor(Color.parseColor(screenColor));
276
+ viewBottom.setBackgroundColor(Color.parseColor(screenColor));
277
+
278
+ int borderWidth = 2;
279
+ int borderCornerRadius = 10;
280
+
281
+ String borderColor = "#ffffff";
282
+ try {
283
+ if (accuraErrorConfg.getString("CameraScreen_Frame_Color").equals("") || !accuraErrorConfg.has("CameraScreen_Frame_Color")){
284
+ borderColor = "#ffffff";
285
+ }else{
286
+ borderColor = accuraErrorConfg.getString("CameraScreen_Frame_Color");
287
+ }
288
+ } catch (JSONException e) {
289
+ e.printStackTrace();
290
+ }
291
+ GradientDrawable drawable = (GradientDrawable)borderFrame.getBackground();
292
+ drawable.mutate(); // only change this instance of the xml, not all components using this xml
293
+ drawable.setStroke(dp2Px(borderWidth), Color.parseColor(borderColor));
294
+ // drawable.setCornerRadius(dp2Px(borderCornerRadius));
295
+
296
+ String titleTextColor = "#ffffff";
297
+ String messageTextColor = "#ff0000";
298
+
299
+ try {
300
+ if (accuraErrorConfg.getString("CameraScreen_Text_Color").equals("") || !accuraErrorConfg.has("CameraScreen_Text_Color")){
301
+ titleTextColor = "#ffffff";
302
+ }else{
303
+ titleTextColor = accuraErrorConfg.getString("CameraScreen_Text_Color");
304
+ }
305
+ } catch (JSONException e) {
306
+ e.printStackTrace();
307
+ }
308
+
309
+ try {
310
+ if (accuraErrorConfg.getString("CameraScreen_Text_Border_Color").equals("") || !accuraErrorConfg.has("CameraScreen_Text_Border_Color")){
311
+ messageTextColor = "#00000000";
312
+ }else{
313
+ messageTextColor = accuraErrorConfg.getString("CameraScreen_Text_Border_Color");
314
+ }
315
+ } catch (JSONException e) {
316
+ e.printStackTrace();
317
+ }
318
+
319
+ tvTitle.setTextColor(Color.parseColor(titleTextColor));
320
+ tvTitle.setStroke(2, Color.parseColor(messageTextColor), Paint.Join.BEVEL, 10);
321
+
322
+ tvScanMessage.setTextColor(Color.parseColor(titleTextColor));
323
+ tvScanMessage.setStroke(2, Color.parseColor(messageTextColor), Paint.Join.ROUND, 10);
324
+
325
+
326
+ }
327
+
328
+ int dp2Px(int dip){
329
+ Resources r = getResources();
330
+ int px = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, dip, r.getDisplayMetrics()
331
+ );
332
+ return px;
333
+ }
334
+
335
+ @Override
336
+ public void onWindowFocusChanged(boolean hasFocus) {
337
+ if (cameraView != null) cameraView.onWindowFocusUpdate(hasFocus);
338
+ }
339
+
340
+ @Override
341
+ protected void onResume() {
342
+ super.onResume();
343
+ if (cameraView != null) cameraView.onResume();
344
+ }
345
+
346
+ @Override
347
+ protected void onPause() {
348
+ if (cameraView != null) cameraView.onPause();
349
+ super.onPause();
350
+ }
351
+
352
+ @Override
353
+ public void onDestroy() {
354
+ AccuraLog.loge(TAG, "onDestroy");
355
+ if (cameraView != null) cameraView.onDestroy();
356
+ super.onDestroy();
357
+ Runtime.getRuntime().gc(); // to clear garbage
358
+ }
359
+
360
+ /**
361
+ * Override method call after camera initialized successfully
362
+ *
363
+ * And update your border frame according to width and height
364
+ * it's different for different card
365
+ *
366
+ * Call {@link CameraView#startOcrScan(boolean isReset)} To start Camera Preview
367
+ *
368
+ * @param width border layout width
369
+ * @param height border layout height
370
+ */
371
+ @Override
372
+ public void onUpdateLayout(int width, int height) {
373
+ AccuraLog.loge(TAG, "Frame Size (wxh) : " + width + "x" + height);
374
+ if (cameraView != null) cameraView.startOcrScan(false);
375
+
376
+ //<editor-fold desc="To set camera overlay Frame">
377
+ ViewGroup.LayoutParams layoutParams = borderFrame.getLayoutParams();
378
+ layoutParams.width = width;
379
+ layoutParams.height = height;
380
+ borderFrame.setLayoutParams(layoutParams);
381
+ ViewGroup.LayoutParams lpRight = viewRight.getLayoutParams();
382
+ lpRight.height = height;
383
+ viewRight.setLayoutParams(lpRight);
384
+ ViewGroup.LayoutParams lpLeft = viewLeft.getLayoutParams();
385
+ lpLeft.height = height;
386
+ viewLeft.setLayoutParams(lpLeft);
387
+
388
+ findViewById(R.id.ocr_frame).setVisibility(View.VISIBLE);
389
+ //</editor-fold>
390
+ //<editor-fold desc="Barcode Selection only add for RecogType.BARCODE">
391
+ // if (recogType == RecogType.BARCODE) cameraView.setBarcodeFormat(BarcodeFormat.BARCODE_AZTEC);
392
+ // else btn_barcode_selection.setVisibility(View.GONE);
393
+ //</editor-fold>
394
+ }
395
+
396
+ /**
397
+ * Override this method after scan complete to get data from document
398
+ *
399
+ * @param result is scanned card data
400
+ * result instance of {@link OcrData} if recog type is {@link com.docrecog.scan.RecogType#OCR}
401
+ * or {@link com.docrecog.scan.RecogType#DL_PLATE} or {@link com.docrecog.scan.RecogType#BARCODE}
402
+ * result instance of {@link RecogResult} if recog type is {@link com.docrecog.scan.RecogType#MRZ}
403
+ * result instance of {@link PDF417Data} if recog type is {@link com.docrecog.scan.RecogType#PDF417}
404
+ *
405
+ */
406
+ @Override
407
+ public void onScannedComplete(Object result) {
408
+ Runtime.getRuntime().gc(); // To clear garbage
409
+ AccuraLog.loge(TAG, "onScannedComplete: ");
410
+ if (result != null) {
411
+ if (result instanceof OcrData) {
412
+ if (recogType == RecogType.OCR) {
413
+ if (isBack || !cameraView.isBackSideAvailable()) {
414
+ OcrData.setOcrResult((OcrData) result);
415
+ /**@recogType is {@link RecogType#OCR}*/
416
+ sendDataToResultActivity(RecogType.OCR);
417
+ } else {
418
+ isBack = true;
419
+ cameraView.setBackSide();
420
+ try {
421
+ if(accuraErrorConfg.getInt("isFlipImg") == 1){
422
+ cameraView.flipImage(imageFlip);
423
+
424
+ }
425
+ } catch (JSONException e) {
426
+ e.printStackTrace();
427
+ }
428
+ }
429
+ } else if (recogType == RecogType.DL_PLATE || recogType == RecogType.BARCODE) {
430
+ /**
431
+ * @recogType is {@link RecogType#DL_PLATE} or recogType == {@link RecogType#BARCODE}*/
432
+ OcrData.setOcrResult((OcrData) result);
433
+ sendDataToResultActivity(recogType);
434
+ }
435
+ } else if (result instanceof RecogResult) {
436
+ /**
437
+ * @recogType is {@link RecogType#MRZ}*/
438
+ RecogResult.setRecogResult((RecogResult) result);
439
+ sendDataToResultActivity(RecogType.MRZ);
440
+ } else if (result instanceof CardDetails) {
441
+ /**
442
+ * @recogType is {@link RecogType#BANKCARD}*/
443
+ CardDetails.setCardDetails((CardDetails) result);
444
+ sendDataToResultActivity(RecogType.BANKCARD);
445
+ } else if (result instanceof PDF417Data) {
446
+ /**
447
+ * @recogType is {@link RecogType#PDF417}*/
448
+ if (isBack || !cameraView.isBackSideAvailable()) {
449
+ PDF417Data.setPDF417Result((PDF417Data) result);
450
+ sendDataToResultActivity(recogType);
451
+ } else {
452
+ isBack = true;
453
+ cameraView.setBackSide();
454
+ try {
455
+ if(accuraErrorConfg.has("isFlipImg")){
456
+ if(accuraErrorConfg.getInt("isFlipImg") == 1){
457
+ cameraView.flipImage(imageFlip);
458
+ }
459
+ }else{
460
+ cameraView.flipImage(imageFlip);
461
+ }
462
+ } catch (JSONException e) {
463
+ e.printStackTrace();
464
+ }
465
+ }
466
+ }
467
+ } else {
468
+ Toast.makeText(this, "Failed", Toast.LENGTH_SHORT).show();
469
+ this.finish();
470
+ }
471
+ }
472
+
473
+ private void sendDataToResultActivity(RecogType recogType) {
474
+ if (cameraView != null) cameraView.release(true);
475
+ // if (type.contains("ocr")) {
476
+ RecogResult recogResult = null;
477
+ CardDetails cardDetails = null;
478
+ PDF417Data barcodeData = PDF417Data.getPDF417Result();
479
+ Boolean isBarCodePdf417 = recogType == RecogType.BARCODE && barcodeData != null;
480
+ RecogType ocrTypes[] = {RecogType.BARCODE, RecogType.DL_PLATE, RecogType.OCR};
481
+ String frontUri = null, backUri = null, faceUri = null;
482
+ JSONObject results = new JSONObject();
483
+ JSONObject frontResult = new JSONObject();
484
+ JSONObject mrzResult = new JSONObject();
485
+ JSONObject backResult = new JSONObject();
486
+ OcrData data = null;
487
+ type = recogType.toString();
488
+ String fileDir = getFilesDir().getAbsolutePath();
489
+ if (Arrays.asList(ocrTypes).contains(recogType)) {
490
+ data = OcrData.getOcrResult();
491
+ if (data != null) {
492
+ faceUri = null;
493
+ frontUri = null;
494
+ backUri = null;
495
+ if (data.getFaceImage() != null) {
496
+ faceUri = AccurascanKycModule.getImageUri(data.getFaceImage(), "face", fileDir);
497
+ }
498
+ if (data.getFrontimage() != null) {
499
+ frontUri = AccurascanKycModule.getImageUri(data.getFrontimage(), "front", fileDir);
500
+ }
501
+ if (data.getBackimage() != null) {
502
+ backUri = AccurascanKycModule.getImageUri(data.getBackimage(), "back", fileDir);
503
+ }
504
+ }
505
+ }
506
+ if (recogType == RecogType.MRZ) {
507
+ faceUri = null;
508
+ frontUri = null;
509
+ backUri = null;
510
+ recogResult = RecogResult.getRecogResult();
511
+ if (recogResult != null) {
512
+ mrzResult = setMRZData(recogResult);
513
+ if (recogResult.faceBitmap != null) {
514
+ faceUri = AccurascanKycModule.getImageUri(recogResult.faceBitmap, "face", fileDir);
515
+ }
516
+ if (recogResult.docFrontBitmap != null) {
517
+ frontUri = AccurascanKycModule.getImageUri(recogResult.docFrontBitmap, "front", fileDir);
518
+ }
519
+ if (recogResult.docBackBitmap != null) {
520
+ backUri = AccurascanKycModule.getImageUri(recogResult.docBackBitmap, "back", fileDir);
521
+ }
522
+ }
523
+
524
+ } else if (recogType == RecogType.BANKCARD) {
525
+ faceUri = null;
526
+ frontUri = null;
527
+ backUri = null;
528
+ cardDetails = CardDetails.getCardDetails();
529
+ if (cardDetails.bitmap != null) {
530
+ frontUri = AccurascanKycModule.getImageUri(cardDetails.bitmap, "front", fileDir);
531
+ try {
532
+ frontResult.put("front_img", frontUri);
533
+ } catch (JSONException e) {
534
+ e.printStackTrace();
535
+ }
536
+ }
537
+ try {
538
+ frontResult.put("Expiry Date", cardDetails.expirationDate);
539
+ frontResult.put("Expiry Month", cardDetails.expirationMonth);
540
+ frontResult.put("Expiry Year", cardDetails.expirationYear);
541
+ frontResult.put("Card Type", cardDetails.cardType);
542
+ frontResult.put("Card Number", cardDetails.number);
543
+ } catch (JSONException e) {
544
+ e.printStackTrace();
545
+ }
546
+ } else if (recogType == RecogType.PDF417 || isBarCodePdf417) {
547
+ type += "PDF417";
548
+ faceUri = null;
549
+ frontUri = null;
550
+ backUri = null;
551
+ // results = null;
552
+ if (barcodeData.faceBitmap != null) {
553
+ faceUri = AccurascanKycModule.getImageUri(barcodeData.faceBitmap, "face", fileDir);
554
+ }
555
+ if (barcodeData.docFrontBitmap != null) {
556
+ frontUri = AccurascanKycModule.getImageUri(barcodeData.docFrontBitmap, "front", fileDir);
557
+ }
558
+ if (barcodeData.docBackBitmap != null) {
559
+ backUri = AccurascanKycModule.getImageUri(barcodeData.docBackBitmap, "back", fileDir);
560
+ }
561
+ try {
562
+ frontResult.put("firstName", barcodeData.fname);
563
+ frontResult.put("firstName", barcodeData.firstName);
564
+ frontResult.put("firstName", barcodeData.firstName1);
565
+ frontResult.put("lastName", barcodeData.lname);
566
+ frontResult.put("lastName", barcodeData.lastName);
567
+ frontResult.put("lastName", barcodeData.lastName1);
568
+ frontResult.put("middle_name", barcodeData.mname);
569
+ frontResult.put("middle_name", barcodeData.middleName);
570
+ frontResult.put("addressLine1", barcodeData.address1);
571
+ frontResult.put("addressLine2", barcodeData.address2);
572
+ frontResult.put("ResidenceStreetAddress1", barcodeData.ResidenceAddress1);
573
+ frontResult.put("ResidenceStreetAddress2", barcodeData.ResidenceAddress2);
574
+ frontResult.put("city", barcodeData.city);
575
+ frontResult.put("zipcode", barcodeData.zipcode);
576
+ frontResult.put("birth_date", barcodeData.birthday);
577
+ frontResult.put("birth_date", barcodeData.birthday1);
578
+ frontResult.put("license_number", barcodeData.licence_number);
579
+ frontResult.put("license_expiry_date", barcodeData.licence_expire_date);
580
+ frontResult.put("sex", barcodeData.sex);
581
+ frontResult.put("jurisdiction_code", barcodeData.jurisdiction);
582
+ frontResult.put("license_classification", barcodeData.licenseClassification);
583
+ frontResult.put("license_restriction", barcodeData.licenseRestriction);
584
+ frontResult.put("license_endorsement", barcodeData.licenseEndorsement);
585
+ frontResult.put("issue_date", barcodeData.issueDate);
586
+ frontResult.put("organ_donor", barcodeData.organDonor);
587
+ frontResult.put("height_in_ft", barcodeData.heightinFT);
588
+ frontResult.put("height_in_cm", barcodeData.heightCM);
589
+ frontResult.put("full_name", barcodeData.fullName);
590
+ frontResult.put("full_name", barcodeData.fullName1);
591
+ frontResult.put("weight_in_lbs", barcodeData.weightLBS);
592
+ frontResult.put("weight_in_kg", barcodeData.weightKG);
593
+ frontResult.put("name_prefix", barcodeData.namePrefix);
594
+ frontResult.put("name_suffix", barcodeData.nameSuffix);
595
+ frontResult.put("prefix", barcodeData.Prefix);
596
+ frontResult.put("suffix", barcodeData.Suffix);
597
+ frontResult.put("suffix", barcodeData.Suffix1);
598
+ frontResult.put("eye_color", barcodeData.eyeColor);
599
+ frontResult.put("hair_color", barcodeData.hairColor);
600
+ frontResult.put("issue_time", barcodeData.issueTime);
601
+ frontResult.put("number_of_duplicate", barcodeData.numberDuplicate);
602
+ frontResult.put("unique_customer_id", barcodeData.uniqueCustomerId);
603
+ frontResult.put("social_security_number", barcodeData.socialSecurityNo);
604
+ frontResult.put("social_security_number", barcodeData.socialSecurityNo1);
605
+ frontResult.put("under_18", barcodeData.under18);
606
+ frontResult.put("under_19", barcodeData.under19);
607
+ frontResult.put("under_21", barcodeData.under21);
608
+ frontResult.put("permit_classification_code", barcodeData.permitClassification);
609
+ frontResult.put("veteran_indicator", barcodeData.veteranIndicator);
610
+ frontResult.put("permit_issue", barcodeData.permitIssue);
611
+ frontResult.put("permit_expire", barcodeData.permitExpire);
612
+ frontResult.put("permit_restriction", barcodeData.permitRestriction);
613
+ frontResult.put("permit_endorsement", barcodeData.permitEndorsement);
614
+ frontResult.put("court_restriction", barcodeData.courtRestriction);
615
+ frontResult.put("inventory_control_no", barcodeData.inventoryNo);
616
+ frontResult.put("race_ethnicity", barcodeData.raceEthnicity);
617
+ frontResult.put("standard_vehicle_class", barcodeData.standardVehicleClass);
618
+ frontResult.put("document_discriminator", barcodeData.documentDiscriminator);
619
+ frontResult.put("ResidenceCity", barcodeData.ResidenceCity);
620
+ frontResult.put("ResidenceJurisdictionCode", barcodeData.ResidenceJurisdictionCode);
621
+ frontResult.put("ResidencePostalCode", barcodeData.ResidencePostalCode);
622
+ frontResult.put("MedicalIndicatorCodes", barcodeData.MedicalIndicatorCodes);
623
+ frontResult.put("NonResidentIndicator", barcodeData.NonResidentIndicator);
624
+ frontResult.put("VirginiaSpecificClass", barcodeData.VirginiaSpecificClass);
625
+ frontResult.put("VirginiaSpecificRestrictions", barcodeData.VirginiaSpecificRestrictions);
626
+ frontResult.put("VirginiaSpecificEndorsements", barcodeData.VirginiaSpecificEndorsements);
627
+ frontResult.put("PhysicalDescriptionWeight", barcodeData.PhysicalDescriptionWeight);
628
+ frontResult.put("CountryTerritoryOfIssuance", barcodeData.CountryTerritoryOfIssuance);
629
+ frontResult.put("FederalCommercialVehicleCodes", barcodeData.FederalCommercialVehicleCodes);
630
+ frontResult.put("PlaceOfBirth", barcodeData.PlaceOfBirth);
631
+ frontResult.put("StandardEndorsementCode", barcodeData.StandardEndorsementCode);
632
+ frontResult.put("StandardRestrictionCode", barcodeData.StandardRestrictionCode);
633
+ frontResult.put("JuriSpeciVehiClassiDescri", barcodeData.JuriSpeciVehiClassiDescri);
634
+ frontResult.put("JuriSpeciRestriCodeDescri", barcodeData.JuriSpeciRestriCodeDescri);
635
+ frontResult.put("ComplianceType", barcodeData.ComplianceType);
636
+ frontResult.put("CardRevisionDate", barcodeData.CardRevisionDate);
637
+ frontResult.put("HazMatEndorsementExpiryDate", barcodeData.HazMatEndorsementExpiryDate);
638
+ frontResult.put("LimitedDurationDocumentIndicator", barcodeData.LimitedDurationDocumentIndicator);
639
+ frontResult.put("FamilyNameTruncation", barcodeData.FamilyNameTruncation);
640
+ frontResult.put("FirstNamesTruncation", barcodeData.FirstNamesTruncation);
641
+ frontResult.put("MiddleNamesTruncation", barcodeData.MiddleNamesTruncation);
642
+ frontResult.put("organ_donor_indicator", barcodeData.OrganDonorIndicator);
643
+ frontResult.put("PermitIdentifier", barcodeData.PermitIdentifier);
644
+ frontResult.put("AuditInformation", barcodeData.AuditInformation);
645
+ frontResult.put("JurisdictionSpecific", barcodeData.JurisdictionSpecific);
646
+ if (!TextUtils.isEmpty(barcodeData.wholeDataString)) {
647
+ frontResult.put("PDF417", barcodeData.wholeDataString);
648
+ }
649
+ } catch (JSONException e) {
650
+ e.printStackTrace();
651
+ }
652
+ }
653
+
654
+ if (data != null) {
655
+ OcrData.MapData frontData = data.getFrontData();
656
+ OcrData.MapData backData = data.getBackData();
657
+ if (frontData != null) {
658
+ List<OcrData.MapData.ScannedData> frontScanData = frontData.getOcr_data();
659
+ for (int i = 0; i < frontScanData.size(); i++) {
660
+ if (frontScanData.get(i).getKey() != null) {
661
+ try {
662
+ if (frontScanData.get(i).getKey().equalsIgnoreCase("signature")) {
663
+ String base64Uri = getBase64Uri(frontScanData.get(i).getKey_data());
664
+ if (base64Uri != null) {
665
+ frontResult.put("signature", base64Uri);
666
+ }
667
+ } else if (frontScanData.get(i).getKey().equalsIgnoreCase("mrz")) {
668
+ RecogResult mrzData = data.getMrzData();
669
+ if (mrzData != null) {
670
+ mrzResult = setMRZData(mrzData);
671
+ }
672
+ } else {
673
+ frontResult.put(frontScanData.get(i).getKey(), frontScanData.get(i).getKey_data());
674
+ }
675
+ } catch (JSONException e) {
676
+ e.printStackTrace();
677
+ }
678
+ }
679
+ }
680
+ }
681
+ if (backData != null) {
682
+ List<OcrData.MapData.ScannedData> backScanData = backData.getOcr_data();
683
+ for (int i = 0; i < backScanData.size(); i++) {
684
+ if (backScanData.get(i).getKey() != null) {
685
+ try {
686
+ if (backScanData.get(i).getKey().equalsIgnoreCase("signature")) {
687
+ String base64Uri = getBase64Uri(backScanData.get(i).getKey_data());
688
+ if (base64Uri != null) {
689
+ backResult.put("signature", base64Uri);
690
+ }
691
+ } else if (backScanData.get(i).getKey().equalsIgnoreCase("mrz")) {
692
+ RecogResult mrzData = data.getMrzData();
693
+ if (mrzData != null) {
694
+ mrzResult = setMRZData(mrzData);
695
+ }
696
+ } else {
697
+ backResult.put(backScanData.get(i).getKey(), backScanData.get(i).getKey_data());
698
+ }
699
+
700
+ } catch (JSONException e) {
701
+ e.printStackTrace();
702
+ }
703
+ }
704
+
705
+ }
706
+ }
707
+ }
708
+ try {
709
+ if (faceUri != null) {
710
+ results.put("face", faceUri);
711
+ }
712
+ if (frontUri != null) {
713
+ results.put("front_img", frontUri);
714
+ }
715
+ if (backUri != null) {
716
+ results.put("back_img", backUri);
717
+ }
718
+ results.put("type", type);
719
+ if (recogType != RecogType.BARCODE){
720
+ results.put("back_data", backResult);
721
+ }
722
+ results.put("front_data", frontResult);
723
+ results.put("mrz_data", mrzResult);
724
+
725
+
726
+ } catch (JSONException e) {
727
+ e.printStackTrace();
728
+ }
729
+ runOnUiThread(new Runnable() {
730
+ public void run() {
731
+ //Do something on UiThread
732
+ Log.i(TAG, "runOnUiThread CALLED");
733
+ AccurascanKycModule.onResult.invoke(null, results.toString());
734
+
735
+ }
736
+ });
737
+
738
+ finish();
739
+ cameraView.onDestroy();
740
+
741
+ return;
742
+
743
+ }
744
+
745
+ //Extra Code
746
+ public String getBase64Uri(String base64Str) {
747
+ byte[] decodedString = Base64.decode(base64Str, Base64.DEFAULT);
748
+ String path = getFilesDir().getAbsolutePath();
749
+ OutputStream fOut = null;
750
+ File file = new File(path, AccurascanKycModule.getSaltString() + "_signature.jpg");
751
+ Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
752
+
753
+ try {
754
+ fOut = new FileOutputStream(file);
755
+ } catch (FileNotFoundException e) {
756
+ e.printStackTrace();
757
+ }
758
+ decodedByte.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
759
+ try {
760
+ fOut.close();
761
+ return "file://" + file.getAbsolutePath();
762
+ } catch (IOException e) {
763
+ e.printStackTrace();
764
+ }
765
+ return null;
766
+ }
767
+
768
+ /**
769
+ * @param titleCode to display scan card message on top of border Frame
770
+ *
771
+ * @param errorMessage To display process message.
772
+ * null if message is not available
773
+ * @param isFlip To set your customize animation after complete front scan
774
+ */
775
+ @Override
776
+ public void onProcessUpdate(int titleCode, String errorMessage, boolean isFlip) {
777
+ AccuraLog.loge(TAG, "onProcessUpdate :-> " + titleCode + "," + errorMessage + "," + isFlip);
778
+ Message message;
779
+ if (getTitleMessage(titleCode) != null) {
780
+ /**
781
+ *
782
+ * 1. Scan Frontside of Card Name // for front side ocr
783
+ * 2. Scan Backside of Card Name // for back side ocr
784
+ * 3. Scan Card Name // only for single side ocr
785
+ * 4. Scan Front Side of Document // for MRZ and PDF417
786
+ * 5. Now Scan Back Side of Document // for MRZ and PDF417
787
+ * 6. Scan Number Plate // for DL plate
788
+ */
789
+
790
+ message = new Message();
791
+ message.what = 0;
792
+ message.obj = getTitleMessage(titleCode);
793
+ handler.sendMessage(message);
794
+ // tvTitle.setText(title);
795
+ }
796
+ if (errorMessage != null) {
797
+ message = new Message();
798
+ message.what = 1;
799
+ message.obj = getErrorMessage(errorMessage);
800
+ handler.sendMessage(message);
801
+ // tvScanMessage.setText(message);
802
+ }
803
+ if (isFlip) {
804
+ message = new Message();
805
+ message.what = 2;
806
+ handler.sendMessage(message);// to set default animation or remove this line to set your customize animation
807
+ }
808
+
809
+ }
810
+
811
+ private String getTitleMessage(int titleCode) {
812
+ if (titleCode < 0) return null;
813
+ switch (titleCode){
814
+ case RecogEngine.SCAN_TITLE_OCR_FRONT:// for front side ocr;
815
+ if (accuraTitleMsg.has("SCAN_TITLE_OCR_FRONT")){
816
+ try {
817
+ if(accuraTitleMsg.getString("SCAN_TITLE_OCR_FRONT").equals("")){
818
+ return "";
819
+ }else{
820
+ return String.format(accuraTitleMsg.getString("SCAN_TITLE_OCR_FRONT") + " %s",cardName);
821
+ }
822
+ } catch (JSONException e) {
823
+ e.printStackTrace();
824
+ }
825
+ }else{
826
+ return String.format("Scan Front Side of %s", cardName);
827
+ }
828
+ case RecogEngine.SCAN_TITLE_OCR_BACK: // for back side ocr
829
+ if (accuraTitleMsg.has("SCAN_TITLE_OCR_BACK")){
830
+ try {
831
+ if(accuraTitleMsg.getString("SCAN_TITLE_OCR_BACK").equals("")){
832
+ return "";
833
+ }else {
834
+ return String.format(accuraTitleMsg.getString("SCAN_TITLE_OCR_BACK") + "%s", cardName);
835
+ }
836
+ } catch (JSONException e) {
837
+ e.printStackTrace();
838
+ }
839
+ }else{
840
+ return String.format("Scan Back Side of %s", cardName);
841
+ }
842
+ case RecogEngine.SCAN_TITLE_OCR: // only for single side ocr
843
+ if (accuraTitleMsg.has("SCAN_TITLE_OCR")){
844
+ try {
845
+ if(accuraTitleMsg.getString("SCAN_TITLE_OCR").equals("")){
846
+ return "";
847
+ }else {
848
+ return String.format(accuraTitleMsg.getString("SCAN_TITLE_OCR") + " %s", cardName);
849
+ }
850
+ } catch (JSONException e) {
851
+ e.printStackTrace();
852
+ }
853
+ }else {
854
+ return String.format("Scan %s", cardName);
855
+ }
856
+ case RecogEngine.SCAN_TITLE_MRZ_PDF417_FRONT:// for front side MRZ and PDF417
857
+ if (recogType == RecogType.BANKCARD) {
858
+ if (accuraTitleMsg.has("SCAN_TITLE_BANKCARD")){
859
+ try {
860
+ if(accuraTitleMsg.getString("SCAN_TITLE_BANKCARD").equals("")){
861
+ return "";
862
+ }else {
863
+ return accuraTitleMsg.getString("SCAN_TITLE_BANKCARD");
864
+ }
865
+ } catch (JSONException e) {
866
+ e.printStackTrace();
867
+ }
868
+ }else{
869
+ return "Scan Bank Card";
870
+ }
871
+ } else if (recogType == RecogType.BARCODE) {
872
+ if (accuraTitleMsg.has("SCAN_TITLE_BARCODE")){
873
+ try {
874
+ if(accuraTitleMsg.getString("SCAN_TITLE_BARCODE").equals("")){
875
+ return "";
876
+ }else {
877
+ return accuraTitleMsg.getString("SCAN_TITLE_BARCODE");
878
+ }
879
+ } catch (JSONException e) {
880
+ e.printStackTrace();
881
+ }
882
+ }else{
883
+ return "Scan Barcode";
884
+ }
885
+ } else
886
+ if (accuraTitleMsg.has("SCAN_TITLE_MRZ_PDF417_FRONT")){
887
+ try {
888
+ if(accuraTitleMsg.getString("SCAN_TITLE_MRZ_PDF417_FRONT").equals("")){
889
+ return "";
890
+ }else {
891
+ return accuraTitleMsg.getString("SCAN_TITLE_MRZ_PDF417_FRONT");
892
+ }
893
+ } catch (JSONException e) {
894
+ e.printStackTrace();
895
+ }
896
+ }else{
897
+ return "Scan Front Side of Document";
898
+ }
899
+ case RecogEngine.SCAN_TITLE_MRZ_PDF417_BACK: // for back side MRZ and PDF417
900
+ if (accuraTitleMsg.has("SCAN_TITLE_MRZ_PDF417_BACK")){
901
+ try {
902
+ if(accuraTitleMsg.getString("SCAN_TITLE_MRZ_PDF417_FRONT").equals("")){
903
+ return "";
904
+ }else {
905
+ return accuraTitleMsg.getString("SCAN_TITLE_MRZ_PDF417_BACK");
906
+ }
907
+ } catch (JSONException e) {
908
+ e.printStackTrace();
909
+ }
910
+ }else {
911
+ return "Now Scan Back Side of Document";
912
+ }
913
+ case RecogEngine.SCAN_TITLE_DLPLATE: // for DL plate
914
+ if (accuraTitleMsg.has("SCAN_TITLE_DLPLATE")){
915
+ try {
916
+ if(accuraTitleMsg.getString("SCAN_TITLE_DLPLATE").equals("")){
917
+ return "";
918
+ }else {
919
+ return accuraTitleMsg.getString("SCAN_TITLE_DLPLATE");
920
+ }
921
+ } catch (JSONException e) {
922
+ e.printStackTrace();
923
+ }
924
+ }else{
925
+ return "Scan Number Plate";
926
+ }
927
+ default:return "";
928
+ }
929
+ }
930
+
931
+ private String getErrorMessage(String s) {
932
+ switch (s) {
933
+ case RecogEngine.ACCURA_ERROR_CODE_MOTION:
934
+ if (accuraErrorConfg.has("ACCURA_ERROR_CODE_MOTION")){
935
+ try {
936
+ return accuraErrorConfg.getString("ACCURA_ERROR_CODE_MOTION");
937
+ } catch (JSONException e) {
938
+ e.printStackTrace();
939
+ }
940
+ }else {
941
+ return "Keep Document Steady";
942
+ }
943
+ case RecogEngine.ACCURA_ERROR_CODE_DOCUMENT_IN_FRAME:
944
+ if (accuraErrorConfg.has("ACCURA_ERROR_CODE_DOCUMENT_IN_FRAME")){
945
+ try {
946
+ return accuraErrorConfg.getString("ACCURA_ERROR_CODE_DOCUMENT_IN_FRAME");
947
+ } catch (JSONException e) {
948
+ e.printStackTrace();
949
+ }
950
+ }else {
951
+ return "Keep document in frame";
952
+ }
953
+ case RecogEngine.ACCURA_ERROR_CODE_BRING_DOCUMENT_IN_FRAME:
954
+ if (accuraErrorConfg.has("ACCURA_ERROR_CODE_BRING_DOCUMENT_IN_FRAME")){
955
+ try {
956
+ return accuraErrorConfg.getString("ACCURA_ERROR_CODE_BRING_DOCUMENT_IN_FRAME");
957
+ } catch (JSONException e) {
958
+ e.printStackTrace();
959
+ }
960
+ }else {
961
+ return "Bring card near to frame.";
962
+ }
963
+ case RecogEngine.ACCURA_ERROR_CODE_PROCESSING:
964
+ if (accuraErrorConfg.has("ACCURA_ERROR_CODE_PROCESSING")){
965
+ try {
966
+ return accuraErrorConfg.getString("ACCURA_ERROR_CODE_PROCESSING");
967
+ } catch (JSONException e) {
968
+ e.printStackTrace();
969
+ }
970
+ }else{
971
+ return "Processing...";
972
+ }
973
+ case RecogEngine.ACCURA_ERROR_CODE_BLUR_DOCUMENT:
974
+ if(accuraErrorConfg.has("ACCURA_ERROR_CODE_BLUR_DOCUMENT")){
975
+ try {
976
+ return accuraErrorConfg.getString("ACCURA_ERROR_CODE_BLUR_DOCUMENT");
977
+ } catch (JSONException e) {
978
+ e.printStackTrace();
979
+ }
980
+ }else {
981
+ return "Blur detect in document";
982
+ }
983
+ case RecogEngine.ACCURA_ERROR_CODE_FACE_BLUR:
984
+ if (accuraErrorConfg.has("ACCURA_ERROR_CODE_FACE_BLUR")){
985
+ try {
986
+ return accuraErrorConfg.getString("ACCURA_ERROR_CODE_FACE_BLUR");
987
+ } catch (JSONException e) {
988
+ e.printStackTrace();
989
+ }
990
+ }else {
991
+ return "Blur detected over face";
992
+ }
993
+ case RecogEngine.ACCURA_ERROR_CODE_GLARE_DOCUMENT:
994
+ if (accuraErrorConfg.has("ACCURA_ERROR_CODE_GLARE_DOCUMENT")){
995
+ try {
996
+ return accuraErrorConfg.getString("ACCURA_ERROR_CODE_GLARE_DOCUMENT");
997
+ } catch (JSONException e) {
998
+ e.printStackTrace();
999
+ }
1000
+ }else{
1001
+ return "Glare detect in document";
1002
+ }
1003
+ case RecogEngine.ACCURA_ERROR_CODE_HOLOGRAM:
1004
+ if (accuraErrorConfg.has("ACCURA_ERROR_CODE_HOLOGRAM")){
1005
+ try {
1006
+ return accuraErrorConfg.getString("ACCURA_ERROR_CODE_HOLOGRAM");
1007
+ } catch (JSONException e) {
1008
+ e.printStackTrace();
1009
+ }
1010
+ }else{
1011
+ return "Hologram Detected";
1012
+ }
1013
+ case RecogEngine.ACCURA_ERROR_CODE_DARK_DOCUMENT:
1014
+ if (accuraErrorConfg.has("ACCURA_ERROR_CODE_DARK_DOCUMENT")){
1015
+ try {
1016
+ return accuraErrorConfg.getString("ACCURA_ERROR_CODE_DARK_DOCUMENT");
1017
+ } catch (JSONException e) {
1018
+ e.printStackTrace();
1019
+ }
1020
+ }else{
1021
+ return "Low lighting detected";
1022
+ }
1023
+ case RecogEngine.ACCURA_ERROR_CODE_PHOTO_COPY_DOCUMENT:
1024
+ if (accuraErrorConfg.has("ACCURA_ERROR_CODE_PHOTO_COPY_DOCUMENT")){
1025
+ try {
1026
+ return accuraErrorConfg.getString("ACCURA_ERROR_CODE_PHOTO_COPY_DOCUMENT");
1027
+ } catch (JSONException e) {
1028
+ e.printStackTrace();
1029
+ }
1030
+ }else{
1031
+ return "Can not accept Photo Copy Document";
1032
+ }
1033
+ case RecogEngine.ACCURA_ERROR_CODE_FACE:
1034
+ if (accuraErrorConfg.has("ACCURA_ERROR_CODE_FACE")){
1035
+ try {
1036
+ return accuraErrorConfg.getString("ACCURA_ERROR_CODE_FACE");
1037
+ } catch (JSONException e) {
1038
+ e.printStackTrace();
1039
+ }
1040
+ }else{
1041
+ return "Face not detected";
1042
+ }
1043
+ case RecogEngine.ACCURA_ERROR_CODE_MRZ:
1044
+ if (accuraErrorConfg.has("ACCURA_ERROR_CODE_MRZ")){
1045
+ try {
1046
+ return accuraErrorConfg.getString("ACCURA_ERROR_CODE_MRZ");
1047
+ } catch (JSONException e) {
1048
+ e.printStackTrace();
1049
+ }
1050
+ }else{
1051
+ return "MRZ not detected";
1052
+ }
1053
+ case RecogEngine.ACCURA_ERROR_CODE_PASSPORT_MRZ:
1054
+ if (accuraErrorConfg.has("ACCURA_ERROR_CODE_PASSPORT_MRZ")){
1055
+ try {
1056
+ return accuraErrorConfg.getString("ACCURA_ERROR_CODE_PASSPORT_MRZ");
1057
+ } catch (JSONException e) {
1058
+ e.printStackTrace();
1059
+ }
1060
+ }else{
1061
+ return "Passport MRZ not detected";
1062
+ }
1063
+ case RecogEngine.ACCURA_ERROR_CODE_ID_MRZ:
1064
+ if(accuraErrorConfg.has("ACCURA_ERROR_CODE_ID_MRZ")){
1065
+ try {
1066
+ return accuraErrorConfg.getString("ACCURA_ERROR_CODE_ID_MRZ");
1067
+ } catch (JSONException e) {
1068
+ e.printStackTrace();
1069
+ }
1070
+ }else{
1071
+ return "ID card MRZ not detected";
1072
+ }
1073
+ case RecogEngine.ACCURA_ERROR_CODE_VISA_MRZ:
1074
+ if (accuraErrorConfg.has("ACCURA_ERROR_CODE_VISA_MRZ")){
1075
+ try {
1076
+ return accuraErrorConfg.getString("ACCURA_ERROR_CODE_VISA_MRZ");
1077
+ } catch (JSONException e) {
1078
+ e.printStackTrace();
1079
+ }
1080
+ }else{
1081
+ return "Visa MRZ not detected";
1082
+ }
1083
+ case RecogEngine.ACCURA_ERROR_CODE_WRONG_SIDE:
1084
+ if (accuraErrorConfg.has("ACCURA_ERROR_CODE_WRONG_SIDE")){
1085
+ try {
1086
+ return accuraErrorConfg.getString("ACCURA_ERROR_CODE_WRONG_SIDE");
1087
+ } catch (JSONException e) {
1088
+ e.printStackTrace();
1089
+ }
1090
+ }else {
1091
+ return "Scanning wrong side of document";
1092
+ }
1093
+ case RecogEngine.ACCURA_ERROR_CODE_UPSIDE_DOWN_SIDE:
1094
+ if (accuraErrorConfg.has("ACCURA_ERROR_CODE_UPSIDE_DOWN_SIDE")){
1095
+ try {
1096
+ return accuraErrorConfg.getString("ACCURA_ERROR_CODE_UPSIDE_DOWN_SIDE");
1097
+ } catch (JSONException e) {
1098
+ e.printStackTrace();
1099
+ }
1100
+ }else{
1101
+ return "Document is upside down. Place it properly";
1102
+ }
1103
+ default:
1104
+ return s;
1105
+ }
1106
+ }
1107
+
1108
+ @Override
1109
+ public void onError(final String errorMessage) {
1110
+ // stop ocr if failed
1111
+ tvScanMessage.setText(errorMessage);
1112
+ Runnable runnable = () -> Toast.makeText(OcrActivity.this, errorMessage, Toast.LENGTH_LONG).show();
1113
+ runOnUiThread(runnable);
1114
+ }
1115
+
1116
+ @Override
1117
+ protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
1118
+ super.onActivityResult(requestCode, resultCode, data);
1119
+ if (resultCode == RESULT_OK) {
1120
+ if (requestCode == 101) {
1121
+ Runtime.getRuntime().gc(); // To clear garbage
1122
+ //<editor-fold desc="Call CameraView#startOcrScan(true) To start again Camera Preview
1123
+ //And CameraView#startOcrScan(false) To start first time">
1124
+ if (cameraView != null) {
1125
+ isBack = false;
1126
+ cameraView.setFrontSide();
1127
+ AccuraLog.loge(TAG, "Rescan Document");
1128
+ cameraView.startOcrScan(true);
1129
+ if (types_dialog != null && types_dialog.isShowing()) types_dialog.dismiss();
1130
+ }
1131
+ //</editor-fold>
1132
+ }
1133
+ }
1134
+ }
1135
+
1136
+ /**
1137
+ * Set Barcode selection Dialog to Scan only selected barcode format
1138
+ * See {@link BarcodeFormat} to get All Barcode format
1139
+ * And use Array List {@link BarcodeFormat#getList()}
1140
+ */
1141
+ int mposition = 0;
1142
+ private void barcodeFormatDialog() {
1143
+ // btn_barcode_selection.setOnClickListener(v -> {
1144
+ // if (cameraView != null) cameraView.stopCamera();
1145
+ // types_dialog.show();
1146
+ // });
1147
+ // List<BarcodeFormat> CODE_NAMES = BarcodeFormat.getList();
1148
+ // types_dialog = new Dialog(this);
1149
+ //// types_dialog.setContentView(R.layout.dialog_barcode_type);
1150
+ // types_dialog.setCanceledOnTouchOutside(false);
1151
+ // types_dialog.setOnKeyListener((dialog, keyCode, event) -> {
1152
+ // if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
1153
+ // types_dialog.cancel();
1154
+ // }
1155
+ // return true;
1156
+ // });
1157
+ // types_dialog.setOnCancelListener(dialog -> {
1158
+ // if (cameraView != null) cameraView.startCamera();
1159
+ // });
1160
+ // cameraView.setBarcodeFormat(BarcodeFormat.BARCODE_AZTEC);
1161
+
1162
+ // cameraView.setBarcodeFormat(CODE_NAMES.get(mposition).formatsType);
1163
+
1164
+
1165
+ // View im_close = types_dialog.findViewById(R.id.btn_close);
1166
+ // im_close.setOnClickListener(v -> {
1167
+ // types_dialog.cancel();
1168
+ // });
1169
+ // ListView listView = types_dialog.findViewById(R.id.typelv);
1170
+
1171
+ // BarCodeFormatListAdapter adapter = new BarCodeFormatListAdapter(this, CODE_NAMES);
1172
+ // listView.setAdapter(adapter);
1173
+
1174
+ // listView.setOnItemClickListener((parent, view, position, id) -> {
1175
+ // for (int i = 0; i < CODE_NAMES.size(); i++) {
1176
+ // CODE_NAMES.get(i).isSelected = i == position;
1177
+ // }
1178
+ // adapter.notifyDataSetChanged();
1179
+ // mposition = position;
1180
+ // set barcode format to scan only selected barcode and by default scan all barcode
1181
+ //cameraView.setBarcodeFormat(CODE_NAMES.get(mposition).formatsType);
1182
+ // types_dialog.cancel();
1183
+ // });
1184
+
1185
+ }
1186
+
1187
+ private JSONObject setMRZData(RecogResult recogResult) {
1188
+ JSONObject frontResult = new JSONObject();
1189
+ try {
1190
+ frontResult.put("MRZ", recogResult.lines);
1191
+ frontResult.put("Document Type", recogResult.docType);
1192
+ frontResult.put("First Name", recogResult.givenname);
1193
+ frontResult.put("First Name", recogResult.givenname);
1194
+ frontResult.put("Last Name", recogResult.surname);
1195
+ frontResult.put("Document No.", recogResult.docnumber);
1196
+ frontResult.put("Document check No.", recogResult.docchecksum);
1197
+ frontResult.put("Correct Document check No.", recogResult.correctdocchecksum);
1198
+ frontResult.put("Country", recogResult.country);
1199
+ frontResult.put("Nationality", recogResult.nationality);
1200
+ String s = (recogResult.sex.equals("M")) ? "MALE" : ((recogResult.sex.equals("F")) ? "FEMALE" : ((recogResult.sex.equals("X")) ? "OTHER" : recogResult.sex));
1201
+ frontResult.put("Sex", s);
1202
+ frontResult.put("Date of Birth", recogResult.birth);
1203
+ frontResult.put("Birth Check No.", recogResult.birthchecksum);
1204
+ frontResult.put("Correct Birth Check No.", recogResult.correctbirthchecksum);
1205
+ frontResult.put("Date of Expiry", recogResult.expirationdate);
1206
+ frontResult.put("Expiration Check No.", recogResult.expirationchecksum);
1207
+ frontResult.put("Correct Expiration Check No.", recogResult.correctexpirationchecksum);
1208
+ frontResult.put("Date Of Issue", recogResult.issuedate);
1209
+ frontResult.put("Department No.", recogResult.departmentnumber);
1210
+ frontResult.put("Other ID", recogResult.otherid);
1211
+ frontResult.put("Other ID Check", recogResult.otheridchecksum);
1212
+ frontResult.put("Other ID2", recogResult.otherid2);
1213
+ frontResult.put("Second Row Check No.", recogResult.secondrowchecksum);
1214
+ frontResult.put("Correct Second Row Check No.", recogResult.correctsecondrowchecksum);
1215
+ } catch (Exception e) {
1216
+ e.printStackTrace();
1217
+ }
1218
+ return frontResult;
1219
+ }
1220
+
1221
+ public static OkHttpClient getUnsafeOkHttpClient() {
1222
+ try {
1223
+ // Create a trust manager that does not validate certificate chains
1224
+ final TrustManager[] trustAllCerts = new TrustManager[] {
1225
+ new X509TrustManager() {
1226
+ @Override
1227
+ public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
1228
+ }
1229
+
1230
+ @Override
1231
+ public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
1232
+ }
1233
+
1234
+ @Override
1235
+ public java.security.cert.X509Certificate[] getAcceptedIssuers() {
1236
+ return new java.security.cert.X509Certificate[]{};
1237
+ }
1238
+ }
1239
+ };
1240
+
1241
+ // Install the all-trusting trust manager
1242
+ final SSLContext sslContext = SSLContext.getInstance("SSL");
1243
+ sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
1244
+
1245
+ // Create an ssl socket factory with our all-trusting manager
1246
+ final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
1247
+
1248
+ OkHttpClient.Builder builder = new OkHttpClient.Builder();
1249
+ builder.sslSocketFactory(sslSocketFactory, (X509TrustManager)trustAllCerts[0]);
1250
+ builder.hostnameVerifier(new HostnameVerifier() {
1251
+ @Override
1252
+ public boolean verify(String hostname, SSLSession session) {
1253
+ return true;
1254
+ }
1255
+ });
1256
+
1257
+ OkHttpClient okHttpClient = builder.build();
1258
+ return okHttpClient;
1259
+ } catch (Exception e) {
1260
+ throw new RuntimeException(e);
1261
+ }
1262
+ }
1263
+ }