@regulaforensics/cordova-plugin-document-reader-api 6.5.0 → 6.6.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.
- package/example/config.xml +7 -0
- package/example/package.json +2 -2
- package/example/www/index.html +109 -111
- package/package.json +1 -1
- package/plugin.xml +5 -3
- package/src/android/BluetoothUtil.kt +108 -0
- package/src/android/DocumentReader.java +100 -7
- package/src/android/Helpers.java +4 -5
- package/src/android/JSONConstructor.java +150 -1345
- package/src/android/RegulaConfig.java +22 -1
- package/src/android/build.gradle +5 -11
- package/src/ios/RGLDocumentReader.m +70 -26
- package/src/ios/RGLWJSONConstructor.h +6 -0
- package/src/ios/RGLWJSONConstructor.m +102 -1
- package/src/ios/RegulaConfig.m +25 -1
- package/www/DocumentReader.js +113 -78
- package/tmp.64209.json +0 -30
package/example/config.xml
CHANGED
|
@@ -17,11 +17,18 @@
|
|
|
17
17
|
<allow-intent href="mailto:*" />
|
|
18
18
|
<allow-intent href="geo:*" />
|
|
19
19
|
<platform name="android">
|
|
20
|
+
<preference name="GradlePluginKotlinEnabled" value="true" />
|
|
21
|
+
<preference name="GradlePluginKotlinCodeStyle" value="official" />
|
|
22
|
+
<preference name="GradlePluginKotlinVersion" value="1.7.10" />
|
|
23
|
+
<preference name="android-minSdkVersion" value="21" />
|
|
24
|
+
<preference name="android-targetSdkVersion" value="33" />
|
|
20
25
|
<preference name="AndroidXEnabled" value="true" />
|
|
21
26
|
<allow-intent href="market:*" />
|
|
22
27
|
<config-file parent="/*" target="AndroidManifest.xml">
|
|
23
28
|
<uses-permission android:name="android.permission.NFC" />
|
|
24
29
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
|
30
|
+
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
|
31
|
+
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
|
|
25
32
|
</config-file>
|
|
26
33
|
</platform>
|
|
27
34
|
<platform name="ios">
|
package/example/package.json
CHANGED
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"cordova-android": "^10.1.1",
|
|
17
17
|
"cordova-ios": "^6.2.0",
|
|
18
18
|
"cordova-plugin-add-swift-support": "^2.0.2",
|
|
19
|
-
"@regulaforensics/cordova-plugin-document-reader-api": "6.
|
|
20
|
-
"@regulaforensics/cordova-plugin-document-reader-core-fullrfid": "6.
|
|
19
|
+
"@regulaforensics/cordova-plugin-document-reader-api": "6.6.0",
|
|
20
|
+
"@regulaforensics/cordova-plugin-document-reader-core-fullrfid": "6.6.0",
|
|
21
21
|
"cordova-plugin-file": "^6.0.2",
|
|
22
22
|
"cordova-plugin-image-picker": "^1.1.3",
|
|
23
23
|
"cordova-plugin-android-permissions": "1.1.0",
|
package/example/www/index.html
CHANGED
|
@@ -1,115 +1,113 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html>
|
|
3
|
-
|
|
4
|
-
<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
<
|
|
15
|
-
<div
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
</div>
|
|
23
|
-
</div>
|
|
24
|
-
<div id="mainUI" style="
|
|
25
|
-
text-align: center;
|
|
26
|
-
background-color: #F5FCFF;
|
|
27
|
-
height: 100%;">
|
|
28
|
-
<div id="deviceready" style="position: absolute; top: 10px; width: 100%; text-align: center;">
|
|
29
|
-
<p class="event listening">Connecting to Device</p>
|
|
30
|
-
<p id="status" class="event received">Ready</p>
|
|
31
|
-
</div>
|
|
32
|
-
<div style="padding: 5px">
|
|
33
|
-
<div style="align-items:center; text-align: center;display: inline-block;"><br><br>
|
|
34
|
-
<p style="margin-bottom: 5px">Portrait</p>
|
|
35
|
-
<img style="height: 133px; width: 100px" src="img/portrait.png" resizeMode="contain"
|
|
36
|
-
id="portraitImage"/>
|
|
3
|
+
<head>
|
|
4
|
+
<meta http-equiv="Content-Security-Policy"
|
|
5
|
+
content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
|
|
6
|
+
<meta name="format-detection" content="telephone=no">
|
|
7
|
+
<meta name="msapplication-tap-highlight" content="no">
|
|
8
|
+
<meta name="viewport" content="initial-scale=1, width=device-width, viewport-fit=cover">
|
|
9
|
+
<link rel="stylesheet" type="text/css" href="css/index.css">
|
|
10
|
+
<title>Document Reader</title>
|
|
11
|
+
</head>
|
|
12
|
+
|
|
13
|
+
<body>
|
|
14
|
+
<div id="rfidUI" style="text-align: center; background-color: #F5FCFF; height: 100%; width:100%; display: none;">
|
|
15
|
+
<div style="position: absolute; top: 50%; left: 50%; width:100%; -ms-transform: translate(-50%, -50%); transform: translate(-50%, -50%); ">
|
|
16
|
+
<p id="rfidUIHeader">Reading RFID</p>
|
|
17
|
+
<p id="rfidDescription">Place your phone on top of the NFC tag</p>
|
|
18
|
+
<progress id="rfidProgress" value="0" max="100"></progress>
|
|
19
|
+
<br><br><br>
|
|
20
|
+
<button id="cancelButton">X</button>
|
|
21
|
+
</div>
|
|
37
22
|
</div>
|
|
38
|
-
<div style="align
|
|
39
|
-
<
|
|
40
|
-
|
|
23
|
+
<div id="mainUI" style="text-align: center;background-color: #F5FCFF;height: 100%;">
|
|
24
|
+
<div style="padding: 5px">
|
|
25
|
+
<div id="deviceready" style="padding-top: 12px; width: 100%; text-align: center;">
|
|
26
|
+
<p class="event listening">Connecting to Device</p>
|
|
27
|
+
<p id="status" class="event received">Ready</p>
|
|
28
|
+
</div>
|
|
29
|
+
<div style="align-items:center; text-align: center;display: inline-block;"><br><br>
|
|
30
|
+
<p style="margin-bottom: 5px">Portrait</p>
|
|
31
|
+
<img style="height: 133px; width: 100px" src="img/portrait.png" resizeMode="contain"
|
|
32
|
+
id="portraitImage"/>
|
|
33
|
+
</div>
|
|
34
|
+
<div style="align-items: center; text-align: center; display: inline-block;"><br><br>
|
|
35
|
+
<p style="margin-bottom: 5px">Document</p>
|
|
36
|
+
<img style="height: 133px;" src="img/id.png" resizeMode="contain" id="documentImage"/>
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
|
|
40
|
+
<div>
|
|
41
|
+
<div id="scenariosRadioGroup"
|
|
42
|
+
style="position: absolute; bottom: 130px; top: 300px; left: 75px; width:225px; padding: 5px; text-align:left; overflow: auto"/>
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
<div style="position: absolute; bottom: 0px; width: 100%;">
|
|
46
|
+
<div id="rfidDiv" style="flex-direction: row; padding: 5px">
|
|
47
|
+
<input id="rfidCheckbox" type="checkbox" name="rfid" disabled><span
|
|
48
|
+
id="rfidCheckboxText"
|
|
49
|
+
style="color: lightgrey"> Process rfid reading(unavailable)</span><br>
|
|
50
|
+
</div>
|
|
51
|
+
<div id="encryptionDiv" style="flex-direction: row; padding: 5px">
|
|
52
|
+
<input id="encryptionCheckbox" type="checkbox" name="rfid" disabled><span
|
|
53
|
+
id="encryptionCheckboxText"
|
|
54
|
+
style="color: lightgrey"> Data encryption(unavailable)</span><br>
|
|
55
|
+
</div>
|
|
56
|
+
<div style="flex-direction: row; padding: 10px">
|
|
57
|
+
<button id="showScannerButton" style="margin-right: 20px">scan doc</button>
|
|
58
|
+
<button id="showImagePicker" style="margin-left: 20px">scan image</button>
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
41
61
|
</div>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
button:hover {
|
|
97
|
-
background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #0688fa), color-stop(1, #2dabf9));
|
|
98
|
-
background: -moz-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
|
|
99
|
-
background: -webkit-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
|
|
100
|
-
background: -o-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
|
|
101
|
-
background: -ms-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
|
|
102
|
-
background: linear-gradient(to bottom, #0688fa 5%, #2dabf9 100%);
|
|
103
|
-
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0688fa', endColorstr='#2dabf9', GradientType=0);
|
|
104
|
-
background-color: #0688fa;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
button:active {
|
|
108
|
-
position: relative;
|
|
109
|
-
top: 1px;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
</style>
|
|
113
|
-
</body>
|
|
114
|
-
|
|
115
|
-
</html>
|
|
62
|
+
|
|
63
|
+
<script type="text/javascript" src="cordova.js"></script>
|
|
64
|
+
<script type="text/javascript" src="js/index.js"></script>
|
|
65
|
+
|
|
66
|
+
<style type="text/css">
|
|
67
|
+
button {
|
|
68
|
+
width: 40%;
|
|
69
|
+
-moz-box-shadow: inset 0px -3px 7px 0px #29bbff;
|
|
70
|
+
-webkit-box-shadow: inset 0px -3px 7px 0px #29bbff;
|
|
71
|
+
box-shadow: inset 0px -3px 7px 0px #29bbff;
|
|
72
|
+
background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #2dabf9), color-stop(1, #0688fa));
|
|
73
|
+
background: -moz-linear-gradient(top, #2dabf9 5%, #0688fa 100%);
|
|
74
|
+
background: -webkit-linear-gradient(top, #2dabf9 5%, #0688fa 100%);
|
|
75
|
+
background: -o-linear-gradient(top, #2dabf9 5%, #0688fa 100%);
|
|
76
|
+
background: -ms-linear-gradient(top, #2dabf9 5%, #0688fa 100%);
|
|
77
|
+
background: linear-gradient(to bottom, #2dabf9 5%, #0688fa 100%);
|
|
78
|
+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#2dabf9', endColorstr='#0688fa', GradientType=0);
|
|
79
|
+
background-color: #2dabf9;
|
|
80
|
+
-moz-border-radius: 3px;
|
|
81
|
+
-webkit-border-radius: 3px;
|
|
82
|
+
border-radius: 3px;
|
|
83
|
+
border: 1px solid #0b0e07;
|
|
84
|
+
display: inline-block;
|
|
85
|
+
cursor: pointer;
|
|
86
|
+
color: #ffffff;
|
|
87
|
+
font-family: Arial;
|
|
88
|
+
font-size: 15px;
|
|
89
|
+
padding: 9px 23px;
|
|
90
|
+
text-decoration: none;
|
|
91
|
+
text-shadow: 0px 1px 0px #263666;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
button:hover {
|
|
95
|
+
background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #0688fa), color-stop(1, #2dabf9));
|
|
96
|
+
background: -moz-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
|
|
97
|
+
background: -webkit-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
|
|
98
|
+
background: -o-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
|
|
99
|
+
background: -ms-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
|
|
100
|
+
background: linear-gradient(to bottom, #0688fa 5%, #2dabf9 100%);
|
|
101
|
+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0688fa', endColorstr='#2dabf9', GradientType=0);
|
|
102
|
+
background-color: #0688fa;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
button:active {
|
|
106
|
+
position: relative;
|
|
107
|
+
top: 1px;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
</style>
|
|
111
|
+
</body>
|
|
112
|
+
|
|
113
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regulaforensics/cordova-plugin-document-reader-api",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.6.0",
|
|
4
4
|
"description": "Cordova plugin for reading and validation of identification documents (API framework)",
|
|
5
5
|
"cordova": {
|
|
6
6
|
"id": "@regulaforensics/cordova-plugin-document-reader-api",
|
package/plugin.xml
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<?xml version='1.0' encoding='utf-8'?>
|
|
2
|
-
<plugin id="cordova-plugin-document-reader-api" version="6.
|
|
2
|
+
<plugin id="cordova-plugin-document-reader-api" version="6.6.0"
|
|
3
3
|
xmlns="http://apache.org/cordova/ns/plugins/1.0">
|
|
4
4
|
<name>DocumentReaderApi</name>
|
|
5
5
|
<description>Cordova plugin Document reader api</description>
|
|
@@ -23,9 +23,10 @@
|
|
|
23
23
|
<header-file src="src/ios/RegulaConfig.h" />
|
|
24
24
|
<source-file src="src/ios/RegulaConfig.m" />
|
|
25
25
|
<podspec>
|
|
26
|
-
|
|
26
|
+
<config>
|
|
27
|
+
</config>
|
|
27
28
|
<pods>
|
|
28
|
-
<pod name="DocumentReader" spec="~> 6.
|
|
29
|
+
<pod name="DocumentReader" spec="~> 6.6.2753" />
|
|
29
30
|
</pods>
|
|
30
31
|
</podspec>
|
|
31
32
|
</platform>
|
|
@@ -41,5 +42,6 @@
|
|
|
41
42
|
<source-file src="src/android/JSONConstructor.java" target-dir="src/cordova.plugin.documentreader" />
|
|
42
43
|
<source-file src="src/android/RegulaConfig.java" target-dir="src/cordova.plugin.documentreader" />
|
|
43
44
|
<source-file src="src/android/Helpers.java" target-dir="src/cordova.plugin.documentreader" />
|
|
45
|
+
<source-file src="src/android/BluetoothUtil.kt" target-dir="java/cordova.plugin.documentreader" />
|
|
44
46
|
</platform>
|
|
45
47
|
</plugin>
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
package cordova.plugin.documentreader
|
|
2
|
+
|
|
3
|
+
import android.Manifest.permission.*
|
|
4
|
+
import android.annotation.SuppressLint
|
|
5
|
+
import android.app.Activity
|
|
6
|
+
import android.bluetooth.BluetoothAdapter
|
|
7
|
+
import android.content.ComponentName
|
|
8
|
+
import android.content.Intent
|
|
9
|
+
import android.content.ServiceConnection
|
|
10
|
+
import android.content.pm.PackageManager.PERMISSION_GRANTED
|
|
11
|
+
import android.os.Build
|
|
12
|
+
import android.os.IBinder
|
|
13
|
+
import android.provider.Settings
|
|
14
|
+
import androidx.annotation.RequiresPermission
|
|
15
|
+
import androidx.core.app.ActivityCompat.requestPermissions
|
|
16
|
+
import androidx.core.content.ContextCompat.checkSelfPermission
|
|
17
|
+
import com.regula.documentreader.api.ble.BLEWrapper
|
|
18
|
+
import com.regula.documentreader.api.ble.BleWrapperCallback
|
|
19
|
+
import com.regula.documentreader.api.ble.RegulaBleService
|
|
20
|
+
import com.regula.documentreader.api.internal.permission.BluetoothPermissionHelper.BLE_ACCESS_PERMISSION
|
|
21
|
+
import com.regula.documentreader.api.internal.permission.BluetoothSettingsHelper.isBluetoothEnabled
|
|
22
|
+
import com.regula.documentreader.api.internal.permission.BluetoothSettingsHelper.isLocationServiceEnabled
|
|
23
|
+
|
|
24
|
+
class BluetoothUtil {
|
|
25
|
+
companion object {
|
|
26
|
+
private const val REQUEST_ENABLE_LOCATION = 196
|
|
27
|
+
private const val REQUEST_ENABLE_BT = 197
|
|
28
|
+
|
|
29
|
+
@SuppressLint("StaticFieldLeak")
|
|
30
|
+
var bleManager: BLEWrapper? = null
|
|
31
|
+
|
|
32
|
+
@RequiresPermission("android.permission.BLUETOOTH_CONNECT")
|
|
33
|
+
private fun requestEnableBle(activity: Activity) {
|
|
34
|
+
val enableIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
|
|
35
|
+
activity.startActivityForResult(enableIntent, REQUEST_ENABLE_BT)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private fun requestEnableLocationService(activity: Activity) {
|
|
39
|
+
val myIntent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
|
|
40
|
+
activity.startActivityForResult(myIntent, REQUEST_ENABLE_LOCATION)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// requestEnableBle() is called after a check for permission
|
|
44
|
+
@SuppressLint("MissingPermission")
|
|
45
|
+
fun isBlePermissionsGranted(activity: Activity): Boolean {
|
|
46
|
+
if (!isLocationServiceEnabled(activity)) {
|
|
47
|
+
requestEnableLocationService(activity)
|
|
48
|
+
return false
|
|
49
|
+
}
|
|
50
|
+
deniedBluetoothPermissions(activity)?.let {
|
|
51
|
+
requestPermissions(activity, it, BLE_ACCESS_PERMISSION)
|
|
52
|
+
return false
|
|
53
|
+
}
|
|
54
|
+
if (!isBluetoothEnabled(activity)) {
|
|
55
|
+
requestEnableBle(activity)
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
58
|
+
return true
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private fun deniedBluetoothPermissions(activity: Activity): Array<String>? {
|
|
62
|
+
val result = mutableListOf<String>()
|
|
63
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
64
|
+
result.addAll(deniedBluetoothPermission(activity, BLUETOOTH_SCAN))
|
|
65
|
+
result.addAll(deniedBluetoothPermission(activity, BLUETOOTH_CONNECT))
|
|
66
|
+
} else
|
|
67
|
+
result.addAll(deniedBluetoothPermission(activity, ACCESS_FINE_LOCATION))
|
|
68
|
+
return result.let { if (it.size > 0) it.toTypedArray() else null }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private fun deniedBluetoothPermission(
|
|
72
|
+
activity: Activity,
|
|
73
|
+
permission: String
|
|
74
|
+
): Array<String> {
|
|
75
|
+
if (checkSelfPermission(activity, permission) != PERMISSION_GRANTED)
|
|
76
|
+
return arrayOf(permission)
|
|
77
|
+
return arrayOf()
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
fun startBluetoothService(
|
|
81
|
+
activity: Activity,
|
|
82
|
+
onConnected: (Boolean) -> Unit,
|
|
83
|
+
onDisconnected: () -> Unit,
|
|
84
|
+
onReady: () -> Unit,
|
|
85
|
+
) {
|
|
86
|
+
val bleIntent = Intent(activity, RegulaBleService::class.java)
|
|
87
|
+
activity.startService(bleIntent)
|
|
88
|
+
|
|
89
|
+
activity.bindService(bleIntent, object : ServiceConnection {
|
|
90
|
+
override fun onServiceConnected(name: ComponentName, service: IBinder) {
|
|
91
|
+
bleManager = (service as RegulaBleService.LocalBinder).service.bleManager
|
|
92
|
+
val isBleManagerConnected = bleManager?.isConnected == true
|
|
93
|
+
onConnected(isBleManagerConnected)
|
|
94
|
+
if (!isBleManagerConnected) {
|
|
95
|
+
bleManager?.addCallback(object : BleWrapperCallback() {
|
|
96
|
+
override fun onDeviceReady() {
|
|
97
|
+
bleManager!!.removeCallback(this)
|
|
98
|
+
onReady()
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
override fun onServiceDisconnected(name: ComponentName) = onDisconnected()
|
|
105
|
+
}, 0)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -9,10 +9,12 @@ import android.content.IntentFilter;
|
|
|
9
9
|
import android.graphics.Bitmap;
|
|
10
10
|
import android.nfc.NfcAdapter;
|
|
11
11
|
import android.nfc.tech.IsoDep;
|
|
12
|
-
import androidx.annotation.NonNull;
|
|
13
12
|
import android.os.Bundle;
|
|
14
13
|
import android.util.Base64;
|
|
15
14
|
|
|
15
|
+
import androidx.annotation.NonNull;
|
|
16
|
+
|
|
17
|
+
import com.regula.documentreader.api.completions.ICheckDatabaseUpdate;
|
|
16
18
|
import com.regula.documentreader.api.completions.IDocumentReaderCompletion;
|
|
17
19
|
import com.regula.documentreader.api.completions.IDocumentReaderInitCompletion;
|
|
18
20
|
import com.regula.documentreader.api.completions.IDocumentReaderPrepareCompletion;
|
|
@@ -23,6 +25,7 @@ import com.regula.documentreader.api.completions.ITccParamsCompletion;
|
|
|
23
25
|
import com.regula.documentreader.api.enums.DocReaderAction;
|
|
24
26
|
import com.regula.documentreader.api.errors.DocumentReaderException;
|
|
25
27
|
import com.regula.documentreader.api.internal.core.CoreScenarioUtil;
|
|
28
|
+
import com.regula.documentreader.api.params.BleDeviceConfig;
|
|
26
29
|
import com.regula.documentreader.api.params.DocReaderConfig;
|
|
27
30
|
import com.regula.documentreader.api.params.ImageInputData;
|
|
28
31
|
import com.regula.documentreader.api.internal.params.ImageInputParam;
|
|
@@ -57,9 +60,15 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
57
60
|
private IRfidPKDCertificateCompletion taCertificateCompletion;
|
|
58
61
|
private IRfidTASignatureCompletion taSignatureCompletion;
|
|
59
62
|
private final static String rfidNotificationCompletionEvent = "rfidNotificationCompletionEvent";
|
|
63
|
+
|
|
60
64
|
private final static String paCertificateCompletionEvent = "paCertificateCompletionEvent";
|
|
61
65
|
private final static String taCertificateCompletionEvent = "taCertificateCompletionEvent";
|
|
62
66
|
private final static String taSignatureCompletionEvent = "taSignatureCompletionEvent";
|
|
67
|
+
|
|
68
|
+
private final static String bleOnServiceConnectedEvent = "bleOnServiceConnectedEvent";
|
|
69
|
+
private final static String bleOnServiceDisconnectedEvent = "bleOnServiceDisconnectedEvent";
|
|
70
|
+
private final static String bleOnDeviceReadyEvent = "bleOnDeviceReadyEvent";
|
|
71
|
+
|
|
63
72
|
private static int databaseDownloadProgress = 0;
|
|
64
73
|
|
|
65
74
|
private Context getContext() {
|
|
@@ -118,13 +127,13 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
118
127
|
}
|
|
119
128
|
|
|
120
129
|
private void sendIRfidNotificationCompletion(int notification, Bundle value) {
|
|
121
|
-
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, rfidNotificationCompletionEvent + JSONConstructor.generateRfidNotificationCompletion(notification, value)
|
|
130
|
+
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, rfidNotificationCompletionEvent + JSONConstructor.generateRfidNotificationCompletion(notification, value));
|
|
122
131
|
pluginResult.setKeepCallback(true);
|
|
123
132
|
callbackContext.sendPluginResult(pluginResult);
|
|
124
133
|
}
|
|
125
134
|
|
|
126
135
|
private void sendPACertificateCompletion(byte[] serialNumber, PAResourcesIssuer issuer) {
|
|
127
|
-
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, paCertificateCompletionEvent + JSONConstructor.generatePACertificateCompletion(serialNumber, issuer)
|
|
136
|
+
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, paCertificateCompletionEvent + JSONConstructor.generatePACertificateCompletion(serialNumber, issuer));
|
|
128
137
|
pluginResult.setKeepCallback(true);
|
|
129
138
|
callbackContext.sendPluginResult(pluginResult);
|
|
130
139
|
}
|
|
@@ -135,7 +144,23 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
135
144
|
callbackContext.sendPluginResult(pluginResult);
|
|
136
145
|
}
|
|
137
146
|
private void sendTASignatureCompletion(TAChallenge challenge) {
|
|
138
|
-
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, taSignatureCompletionEvent + JSONConstructor.generateTAChallenge(challenge)
|
|
147
|
+
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, taSignatureCompletionEvent + JSONConstructor.generateTAChallenge(challenge));
|
|
148
|
+
pluginResult.setKeepCallback(true);
|
|
149
|
+
callbackContext.sendPluginResult(pluginResult);
|
|
150
|
+
}
|
|
151
|
+
private void sendBleOnServiceConnectedEvent(boolean isBleManagerConnected) {
|
|
152
|
+
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, bleOnServiceConnectedEvent + isBleManagerConnected);
|
|
153
|
+
pluginResult.setKeepCallback(true);
|
|
154
|
+
callbackContext.sendPluginResult(pluginResult);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private void sendBleOnServiceDisconnectedEvent() {
|
|
158
|
+
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, bleOnServiceDisconnectedEvent);
|
|
159
|
+
pluginResult.setKeepCallback(true);
|
|
160
|
+
callbackContext.sendPluginResult(pluginResult);
|
|
161
|
+
}
|
|
162
|
+
private void sendBleOnDeviceReadyEvent() {
|
|
163
|
+
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, bleOnDeviceReadyEvent);
|
|
139
164
|
pluginResult.setKeepCallback(true);
|
|
140
165
|
callbackContext.sendPluginResult(pluginResult);
|
|
141
166
|
}
|
|
@@ -168,6 +193,18 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
168
193
|
case "initializeReaderAutomatically":
|
|
169
194
|
initializeReaderAutomatically(callback);
|
|
170
195
|
break;
|
|
196
|
+
case "isBlePermissionsGranted":
|
|
197
|
+
isBlePermissionsGranted(callback);
|
|
198
|
+
break;
|
|
199
|
+
case "startBluetoothService":
|
|
200
|
+
startBluetoothService(callback);
|
|
201
|
+
break;
|
|
202
|
+
case "initializeReaderBleDeviceConfig":
|
|
203
|
+
initializeReaderBleDeviceConfig(callback);
|
|
204
|
+
break;
|
|
205
|
+
case "getTag":
|
|
206
|
+
getTag(callback);
|
|
207
|
+
break;
|
|
171
208
|
case "getAPIVersion":
|
|
172
209
|
getAPIVersion(callback);
|
|
173
210
|
break;
|
|
@@ -288,6 +325,12 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
288
325
|
case "setCameraSessionIsPaused":
|
|
289
326
|
setCameraSessionIsPaused(callback, args(0));
|
|
290
327
|
break;
|
|
328
|
+
case "setTag":
|
|
329
|
+
setTag(callback, args(0));
|
|
330
|
+
break;
|
|
331
|
+
case "checkDatabaseUpdate":
|
|
332
|
+
checkDatabaseUpdate(callback, args(0));
|
|
333
|
+
break;
|
|
291
334
|
case "getScenario":
|
|
292
335
|
getScenario(callback, args(0));
|
|
293
336
|
break;
|
|
@@ -352,7 +395,8 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
352
395
|
recognizeImagesWithImageInputs(callback, args(0));
|
|
353
396
|
break;
|
|
354
397
|
}
|
|
355
|
-
} catch (Exception
|
|
398
|
+
} catch (Exception e) {
|
|
399
|
+
e.printStackTrace();
|
|
356
400
|
}
|
|
357
401
|
return true;
|
|
358
402
|
}
|
|
@@ -396,6 +440,37 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
396
440
|
callback.success("already initialized");
|
|
397
441
|
}
|
|
398
442
|
|
|
443
|
+
private void isBlePermissionsGranted(Callback callback) {
|
|
444
|
+
callback.success(BluetoothUtil.Companion.isBlePermissionsGranted(getActivity()));
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
private void startBluetoothService(Callback callback) {
|
|
448
|
+
BluetoothUtil.Companion.startBluetoothService(
|
|
449
|
+
getActivity(),
|
|
450
|
+
isBleManagerConnected -> {
|
|
451
|
+
sendBleOnServiceConnectedEvent(isBleManagerConnected);
|
|
452
|
+
return null;
|
|
453
|
+
},
|
|
454
|
+
() -> {
|
|
455
|
+
sendBleOnServiceDisconnectedEvent();
|
|
456
|
+
return null;
|
|
457
|
+
},
|
|
458
|
+
() -> {
|
|
459
|
+
sendBleOnDeviceReadyEvent();
|
|
460
|
+
return null;
|
|
461
|
+
}
|
|
462
|
+
);
|
|
463
|
+
callback.success();
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
private void initializeReaderBleDeviceConfig(Callback callback) {
|
|
467
|
+
if (BluetoothUtil.Companion.getBleManager() == null) callback.error("bleManager is null");
|
|
468
|
+
if (!Instance().isReady())
|
|
469
|
+
Instance().initializeReader(getContext(), new BleDeviceConfig(BluetoothUtil.Companion.getBleManager()), getInitCompletion(callback));
|
|
470
|
+
else
|
|
471
|
+
callback.success("already initialized");
|
|
472
|
+
}
|
|
473
|
+
|
|
399
474
|
private void getAvailableScenarios(Callback callback) throws JSONException {
|
|
400
475
|
callback.success(JSONConstructor.generateList(Instance().availableScenarios, JSONConstructor::generateDocumentReaderScenario).toString());
|
|
401
476
|
}
|
|
@@ -512,6 +587,20 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
512
587
|
callback.success();
|
|
513
588
|
}
|
|
514
589
|
|
|
590
|
+
private void getTag(Callback callback) {
|
|
591
|
+
callback.success(Instance().tag);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
private void setTag(Callback callback, String tag) {
|
|
595
|
+
Instance().tag = tag;
|
|
596
|
+
callback.success();
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
private void checkDatabaseUpdate(Callback callback, String databaseId) {
|
|
600
|
+
Instance().checkDatabaseUpdate(getContext(), databaseId, getCheckDatabaseUpdateCompletion(callback));
|
|
601
|
+
callback.success();
|
|
602
|
+
}
|
|
603
|
+
|
|
515
604
|
private void startNewPage(Callback callback) {
|
|
516
605
|
Instance().startNewPage();
|
|
517
606
|
callback.success();
|
|
@@ -553,7 +642,7 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
553
642
|
}
|
|
554
643
|
|
|
555
644
|
private void cancelDBUpdate(Callback callback) {
|
|
556
|
-
callback.success(Instance().cancelDBUpdate());
|
|
645
|
+
callback.success(Instance().cancelDBUpdate(getContext()));
|
|
557
646
|
}
|
|
558
647
|
|
|
559
648
|
private void resetConfiguration(Callback callback) {
|
|
@@ -699,7 +788,7 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
699
788
|
callback.error("getCameraSessionIsPaused() is an ios-only method");
|
|
700
789
|
}
|
|
701
790
|
|
|
702
|
-
private void stopRFIDReaderWithErrorMessage(Callback callback, String message) {
|
|
791
|
+
private void stopRFIDReaderWithErrorMessage(Callback callback, @SuppressWarnings("unused") String message) {
|
|
703
792
|
callback.error("stopRFIDReaderWithErrorMessage() is an ios-only method");
|
|
704
793
|
}
|
|
705
794
|
|
|
@@ -755,6 +844,10 @@ public class DocumentReader extends CordovaPlugin {
|
|
|
755
844
|
};
|
|
756
845
|
}
|
|
757
846
|
|
|
847
|
+
private ICheckDatabaseUpdate getCheckDatabaseUpdateCompletion(Callback callback) {
|
|
848
|
+
return (database) -> callback.success(JSONConstructor.generateDocReaderDocumentsDatabase(database));
|
|
849
|
+
}
|
|
850
|
+
|
|
758
851
|
private ITccParamsCompletion getTCCParamsCompletion(Callback callback) {
|
|
759
852
|
return (success, error) -> {
|
|
760
853
|
if (success)
|
package/src/android/Helpers.java
CHANGED
|
@@ -31,13 +31,12 @@ class Helpers {
|
|
|
31
31
|
return result;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
static BitmapDrawable drawableFromBase64(String base64, Context context)
|
|
35
|
-
{
|
|
34
|
+
static BitmapDrawable drawableFromBase64(String base64, Context context) {
|
|
36
35
|
byte[] decodedByte = Base64.decode(base64, 0);
|
|
37
|
-
Bitmap bitmap =
|
|
36
|
+
Bitmap bitmap = BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
|
|
38
37
|
float density = context.getResources().getDisplayMetrics().density;
|
|
39
|
-
int width = (int)(bitmap.getWidth()*density);
|
|
40
|
-
int height = (int)(bitmap.getHeight()*density);
|
|
38
|
+
int width = (int) (bitmap.getWidth() * density);
|
|
39
|
+
int height = (int) (bitmap.getHeight() * density);
|
|
41
40
|
return new BitmapDrawable(context.getResources(), Bitmap.createScaledBitmap(bitmap, width, height, false));
|
|
42
41
|
}
|
|
43
42
|
|