@regulaforensics/cordova-plugin-document-reader-api 6.9.0 → 7.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.
- package/README.md +10 -40
- package/example/README.md +32 -0
- package/example/config.xml +5 -1
- package/example/package.json +7 -10
- package/example/www/js/index.js +85 -160
- package/package.json +1 -1
- package/plugin.xml +8 -8
- package/src/android/BluetoothUtil.kt +78 -74
- package/src/android/Config.kt +690 -0
- package/src/android/DocumentReader.kt +525 -0
- package/src/android/JSONConstructor.kt +2187 -0
- package/src/android/Utils.kt +256 -0
- package/src/android/build.gradle +3 -3
- package/src/ios/RGLWConfig.h +48 -0
- package/src/ios/RGLWConfig.m +1325 -0
- package/src/ios/RGLWDocumentReader.h +11 -8
- package/src/ios/RGLWDocumentReader.m +388 -576
- package/src/ios/RGLWJSONConstructor.h +173 -69
- package/src/ios/RGLWJSONConstructor.m +1817 -762
- package/www/DocumentReader.js +241 -116
- package/src/android/DocumentReader.java +0 -1118
- package/src/android/Helpers.java +0 -259
- package/src/android/JSONConstructor.java +0 -1119
- package/src/android/RegulaConfig.java +0 -830
- package/src/ios/RGLWRegulaConfig.h +0 -26
- package/src/ios/RGLWRegulaConfig.m +0 -1152
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
//
|
|
2
|
+
// BluetoothUtil.kt
|
|
3
|
+
// DocumentReader
|
|
4
|
+
//
|
|
5
|
+
// Created by Pavel Masiuk on 21.09.2023.
|
|
6
|
+
// Copyright © 2023 Regula. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
1
9
|
package cordova.plugin.documentreader
|
|
2
10
|
|
|
3
11
|
import android.Manifest.permission.*
|
|
@@ -21,88 +29,84 @@ import com.regula.documentreader.api.internal.permission.BluetoothPermissionHelp
|
|
|
21
29
|
import com.regula.documentreader.api.internal.permission.BluetoothSettingsHelper.isBluetoothEnabled
|
|
22
30
|
import com.regula.documentreader.api.internal.permission.BluetoothSettingsHelper.isLocationServiceEnabled
|
|
23
31
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
private const val REQUEST_ENABLE_LOCATION = 196
|
|
27
|
-
private const val REQUEST_ENABLE_BT = 197
|
|
32
|
+
const val REQUEST_ENABLE_LOCATION = 196
|
|
33
|
+
const val REQUEST_ENABLE_BT = 197
|
|
28
34
|
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
@SuppressLint("StaticFieldLeak")
|
|
36
|
+
var bleManager: BLEWrapper? = null
|
|
31
37
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
@RequiresPermission("android.permission.BLUETOOTH_CONNECT")
|
|
39
|
+
fun requestEnableBle(activity: Activity) {
|
|
40
|
+
val enableIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
|
|
41
|
+
activity.startActivityForResult(enableIntent, REQUEST_ENABLE_BT)
|
|
42
|
+
}
|
|
37
43
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
fun requestEnableLocationService(activity: Activity) {
|
|
45
|
+
val myIntent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
|
|
46
|
+
activity.startActivityForResult(myIntent, REQUEST_ENABLE_LOCATION)
|
|
47
|
+
}
|
|
42
48
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
49
|
+
// requestEnableBle() is called after a check for permission
|
|
50
|
+
@SuppressLint("MissingPermission")
|
|
51
|
+
fun isBlePermissionsGranted(activity: Activity): Boolean {
|
|
52
|
+
if (!isLocationServiceEnabled(activity)) {
|
|
53
|
+
requestEnableLocationService(activity)
|
|
54
|
+
return false
|
|
55
|
+
}
|
|
56
|
+
deniedBluetoothPermissions(activity)?.let {
|
|
57
|
+
requestPermissions(activity, it, BLE_ACCESS_PERMISSION)
|
|
58
|
+
return false
|
|
59
|
+
}
|
|
60
|
+
if (!isBluetoothEnabled(activity)) {
|
|
61
|
+
requestEnableBle(activity)
|
|
62
|
+
return false
|
|
63
|
+
}
|
|
64
|
+
return true
|
|
65
|
+
}
|
|
60
66
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
fun deniedBluetoothPermissions(activity: Activity): Array<String>? {
|
|
68
|
+
val result = mutableListOf<String>()
|
|
69
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
70
|
+
result.addAll(deniedBluetoothPermission(activity, BLUETOOTH_SCAN))
|
|
71
|
+
result.addAll(deniedBluetoothPermission(activity, BLUETOOTH_CONNECT))
|
|
72
|
+
} else
|
|
73
|
+
result.addAll(deniedBluetoothPermission(activity, ACCESS_FINE_LOCATION))
|
|
74
|
+
return result.let { if (it.size > 0) it.toTypedArray() else null }
|
|
75
|
+
}
|
|
70
76
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
fun deniedBluetoothPermission(
|
|
78
|
+
activity: Activity,
|
|
79
|
+
permission: String
|
|
80
|
+
): Array<String> {
|
|
81
|
+
if (checkSelfPermission(activity, permission) != PERMISSION_GRANTED)
|
|
82
|
+
return arrayOf(permission)
|
|
83
|
+
return arrayOf()
|
|
84
|
+
}
|
|
79
85
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
fun startBluetoothService(
|
|
87
|
+
activity: Activity,
|
|
88
|
+
onConnected: (Boolean) -> Unit,
|
|
89
|
+
onDisconnected: () -> Unit,
|
|
90
|
+
onReady: () -> Unit
|
|
91
|
+
) {
|
|
92
|
+
val bleIntent = Intent(activity, RegulaBleService::class.java)
|
|
93
|
+
activity.startService(bleIntent)
|
|
88
94
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
})
|
|
95
|
+
activity.bindService(bleIntent, object : ServiceConnection {
|
|
96
|
+
override fun onServiceConnected(name: ComponentName, service: IBinder) {
|
|
97
|
+
bleManager = (service as RegulaBleService.LocalBinder).service.bleManager
|
|
98
|
+
val isBleManagerConnected = bleManager?.isConnected == true
|
|
99
|
+
onConnected(isBleManagerConnected)
|
|
100
|
+
if (!isBleManagerConnected) {
|
|
101
|
+
bleManager?.addCallback(object : BleWrapperCallback() {
|
|
102
|
+
override fun onDeviceReady() {
|
|
103
|
+
bleManager!!.removeCallback(this)
|
|
104
|
+
onReady()
|
|
101
105
|
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
override fun onServiceDisconnected(name: ComponentName) = onDisconnected()
|
|
105
|
-
}, 0)
|
|
106
|
+
})
|
|
107
|
+
}
|
|
106
108
|
}
|
|
107
|
-
|
|
109
|
+
|
|
110
|
+
override fun onServiceDisconnected(name: ComponentName) = onDisconnected()
|
|
111
|
+
}, 0)
|
|
108
112
|
}
|