@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
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Utils.java
|
|
3
|
+
// DocumentReader
|
|
4
|
+
//
|
|
5
|
+
// Created by Pavel Masiuk on 21.09.2023.
|
|
6
|
+
// Copyright © 2023 Regula. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
@file:Suppress("UNCHECKED_CAST")
|
|
9
|
+
|
|
10
|
+
package cordova.plugin.documentreader
|
|
11
|
+
|
|
12
|
+
import android.content.Context
|
|
13
|
+
import android.graphics.Bitmap
|
|
14
|
+
import android.graphics.BitmapFactory
|
|
15
|
+
import android.graphics.Canvas
|
|
16
|
+
import android.graphics.Matrix
|
|
17
|
+
import android.graphics.Paint
|
|
18
|
+
import android.graphics.Typeface
|
|
19
|
+
import android.graphics.drawable.BitmapDrawable
|
|
20
|
+
import android.graphics.drawable.Drawable
|
|
21
|
+
import android.util.Base64
|
|
22
|
+
import com.regula.documentreader.api.enums.CustomizationFont
|
|
23
|
+
import com.regula.documentreader.api.params.ParamsCustomization
|
|
24
|
+
import org.json.JSONArray
|
|
25
|
+
import org.json.JSONObject
|
|
26
|
+
import java.io.ByteArrayOutputStream
|
|
27
|
+
import kotlin.math.sqrt
|
|
28
|
+
|
|
29
|
+
fun Any?.toSendable(): Any? = this?.let {
|
|
30
|
+
if (this is JSONObject || this is JSONArray) this.toString()
|
|
31
|
+
else this
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
fun arrayListToJSONArray(list: ArrayList<*>): JSONArray {
|
|
35
|
+
val result = JSONArray()
|
|
36
|
+
for (i in list.indices) {
|
|
37
|
+
when {
|
|
38
|
+
list[i] == null -> result.put(null)
|
|
39
|
+
list[i].javaClass == HashMap::class.java -> result.put(hashMapToJSONObject(list[i] as HashMap<String, *>))
|
|
40
|
+
list[i].javaClass == ArrayList::class.java -> result.put(arrayListToJSONArray(list[i] as ArrayList<*>))
|
|
41
|
+
else -> result.put(list[i])
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return result
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
fun hashMapToJSONObject(map: HashMap<String, *>): JSONObject {
|
|
48
|
+
val result = JSONObject()
|
|
49
|
+
for ((key, value) in map) {
|
|
50
|
+
when {
|
|
51
|
+
value == null -> result.put(key, null)
|
|
52
|
+
value.javaClass == HashMap::class.java -> result.put(key, hashMapToJSONObject(value as HashMap<String, *>))
|
|
53
|
+
value.javaClass == ArrayList::class.java -> result.put(key, arrayListToJSONArray(value as ArrayList<*>))
|
|
54
|
+
else -> result.put(key, value)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return result
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
fun <T> generateList(list: List<T>?) = list?.let {
|
|
61
|
+
val result = JSONArray()
|
|
62
|
+
for (t in list) if (t != null) result.put(t)
|
|
63
|
+
result
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
fun <T> generateList(list: List<T>, toJson: (T?) -> JSONObject?): JSONArray {
|
|
67
|
+
val result = JSONArray()
|
|
68
|
+
for (t in list) if (t != null) result.put(toJson(t))
|
|
69
|
+
return result
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
fun <T> listFromJSON(input: JSONArray?, fromJson: (JSONObject?) -> T) = input?.let {
|
|
73
|
+
val result: MutableList<T> = ArrayList()
|
|
74
|
+
for (i in 0 until input.length()) {
|
|
75
|
+
val item = input.getJSONObject(i)
|
|
76
|
+
result.add(fromJson(item))
|
|
77
|
+
}
|
|
78
|
+
result
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
fun <T> listFromJSON(input: JSONArray): List<T> {
|
|
82
|
+
val result: MutableList<T> = ArrayList()
|
|
83
|
+
for (i in 0 until input.length()) result.add(input.opt(i) as T)
|
|
84
|
+
return result
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
fun <T> arrayFromJSON(input: JSONArray?, fromJson: (JSONObject?) -> T, result: Array<T>) = input?.let {
|
|
88
|
+
for (i in 0 until input.length())
|
|
89
|
+
result[i] = fromJson(input.getJSONObject(i))
|
|
90
|
+
result
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
fun <T> generateList(list: List<T>, toJson: (T?, Context?) -> JSONObject?, context: Context?): JSONArray {
|
|
94
|
+
val result = JSONArray()
|
|
95
|
+
for (t in list) if (t != null) result.put(toJson(t, context))
|
|
96
|
+
return result
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
fun <T> generateArray(array: Array<T>?) = array?.let {
|
|
100
|
+
val result = JSONArray()
|
|
101
|
+
for (i in array.indices) result.put(i, array[i])
|
|
102
|
+
result
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
fun <T> generateArray(array: Array<T>?, toJson: (T?) -> JSONObject?) = array?.let {
|
|
106
|
+
val result = JSONArray()
|
|
107
|
+
for (i in array.indices) result.put(i, toJson(array[i]))
|
|
108
|
+
result
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
fun generateLongArray(array: LongArray?) = array?.let {
|
|
112
|
+
val result = JSONArray()
|
|
113
|
+
for (i in array.indices) result.put(i, array[i])
|
|
114
|
+
result
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
fun stringListFromJson(jsonArray: JSONArray): List<String> {
|
|
118
|
+
val result: MutableList<String> = ArrayList()
|
|
119
|
+
for (i in 0 until jsonArray.length()) result.add(jsonArray.optString(i))
|
|
120
|
+
return result
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
fun stringArrayFromJson(jsonArray: JSONArray): Array<String?> {
|
|
124
|
+
val result = arrayOfNulls<String>(jsonArray.length())
|
|
125
|
+
for (i in 0 until jsonArray.length()) result[i] = jsonArray.optString(i)
|
|
126
|
+
return result
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
fun paintCapToInt(cap: Paint.Cap) = when (cap) {
|
|
130
|
+
Paint.Cap.BUTT -> 0
|
|
131
|
+
Paint.Cap.ROUND -> 1
|
|
132
|
+
Paint.Cap.SQUARE -> 2
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
fun JSONObject.forEach(action: (String, Any?) -> Unit) {
|
|
136
|
+
val keys: Iterator<String> = keys()
|
|
137
|
+
while (keys.hasNext()) {
|
|
138
|
+
val key = keys.next()
|
|
139
|
+
action(key, get(key))
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
fun Map<String, Any?>.toJsonObject(): JSONObject {
|
|
144
|
+
val result = JSONObject()
|
|
145
|
+
forEach { (key, value) -> result.put(key, value) }
|
|
146
|
+
return result
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
fun stringMapFromJson(input: JSONObject): Map<String, String> {
|
|
150
|
+
val result: MutableMap<String, String> = HashMap()
|
|
151
|
+
input.forEach { key, value -> result[key] = value as String }
|
|
152
|
+
return result
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
fun generateStringMap(input: Map<String, String?>?) = input?.let {
|
|
156
|
+
val result = JSONObject()
|
|
157
|
+
for ((key, value) in input) result.put(key, value)
|
|
158
|
+
result
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
fun Any?.toInt() = when (this) {
|
|
162
|
+
is Double -> toInt()
|
|
163
|
+
is Long -> toInt()
|
|
164
|
+
else -> this as Int
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
fun Any?.toLong() = when (this) {
|
|
168
|
+
is Double -> toLong()
|
|
169
|
+
is Int -> toLong()
|
|
170
|
+
else -> this as Long
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
fun Any?.toColor() = "#" + toLong().toString(16)
|
|
174
|
+
|
|
175
|
+
fun Any?.toFloat() =
|
|
176
|
+
if (this is Double) toFloat()
|
|
177
|
+
else this as Float
|
|
178
|
+
|
|
179
|
+
fun Any?.toMatrix() = this?.let {
|
|
180
|
+
val matrix = Matrix()
|
|
181
|
+
val result = FloatArray((this as JSONArray).length())
|
|
182
|
+
for (i in 0 until length()) result[i] = getDouble(i).toFloat()
|
|
183
|
+
matrix.setValues(result)
|
|
184
|
+
matrix
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
fun Any?.toIntArray() = (this as JSONArray?)?.let {
|
|
188
|
+
val result = IntArray(it.length())
|
|
189
|
+
for (i in 0 until it.length()) result[i] = it.getInt(i)
|
|
190
|
+
result
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
fun IntArray?.generate() = this?.let {
|
|
194
|
+
val result = JSONArray()
|
|
195
|
+
for (i in indices) result.put(i, this[i])
|
|
196
|
+
result
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
fun String?.toLong() = this?.let {
|
|
200
|
+
if (this[0] == '#') this.substring(1).toLong(16)
|
|
201
|
+
else this.toLong(16)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
fun Matrix?.generate() = this?.let {
|
|
205
|
+
val floats = FloatArray(9)
|
|
206
|
+
getValues(floats)
|
|
207
|
+
val result = JSONArray()
|
|
208
|
+
for (f in floats) result.put(java.lang.Float.valueOf(f))
|
|
209
|
+
result
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
fun CustomizationFont.generate(fonts: Map<CustomizationFont, Typeface>, sizes: Map<CustomizationFont, Int>) = generateTypeface(fonts[this], sizes[this])
|
|
213
|
+
|
|
214
|
+
fun CustomizationFont.setFont(editor: ParamsCustomization.CustomizationEditor, value: Any?) {
|
|
215
|
+
val font = typefaceFromJSON(value as JSONObject)
|
|
216
|
+
editor.setFont(this, font.first)
|
|
217
|
+
font.second?.let { editor.setFontSize(this, it) }
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
internal object Convert {
|
|
221
|
+
fun byteArrayFromBase64(base64: String?) = base64?.let { Base64.decode(it, Base64.NO_WRAP) }
|
|
222
|
+
fun generateByteArray(array: ByteArray?) = array?.let { Base64.encodeToString(it, Base64.NO_WRAP) }
|
|
223
|
+
|
|
224
|
+
fun bitmapFromBase64(base64: String?) = base64?.let {
|
|
225
|
+
val decodedString = byteArrayFromBase64(base64)
|
|
226
|
+
var result = BitmapFactory.decodeByteArray(decodedString, 0, decodedString!!.size)
|
|
227
|
+
val sizeMultiplier = result.byteCount / 5000000
|
|
228
|
+
if (result.byteCount > 5000000) result = Bitmap.createScaledBitmap(result, result.width / sqrt(sizeMultiplier.toDouble()).toInt(), result.height / sqrt(sizeMultiplier.toDouble()).toInt(), false)
|
|
229
|
+
result
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
fun bitmapToBase64(bitmap: Bitmap?) = bitmap?.let {
|
|
233
|
+
val byteArrayOutputStream = ByteArrayOutputStream()
|
|
234
|
+
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream)
|
|
235
|
+
val byteArray = byteArrayOutputStream.toByteArray()
|
|
236
|
+
generateByteArray(byteArray)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
fun Any?.toDrawable(context: Context) = (this as String?)?.let {
|
|
240
|
+
val decodedByte = byteArrayFromBase64(it)
|
|
241
|
+
val bitmap = BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte!!.size)
|
|
242
|
+
val density = context.resources.displayMetrics.density
|
|
243
|
+
val width = (bitmap.width * density).toInt()
|
|
244
|
+
val height = (bitmap.height * density).toInt()
|
|
245
|
+
BitmapDrawable(context.resources, Bitmap.createScaledBitmap(bitmap, width, height, false))
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
fun Drawable?.toString() = this?.let {
|
|
249
|
+
if (this is BitmapDrawable) if (bitmap != null) return bitmapToBase64(bitmap)
|
|
250
|
+
val bitmap: Bitmap = if (intrinsicWidth <= 0 || intrinsicHeight <= 0) Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888) else Bitmap.createBitmap(intrinsicWidth, intrinsicHeight, Bitmap.Config.ARGB_8888)
|
|
251
|
+
val canvas = Canvas(bitmap)
|
|
252
|
+
setBounds(0, 0, canvas.width, canvas.height)
|
|
253
|
+
draw(canvas)
|
|
254
|
+
bitmapToBase64(bitmap)
|
|
255
|
+
}
|
|
256
|
+
}
|
package/src/android/build.gradle
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
apply plugin: 'kotlin-android'
|
|
2
2
|
|
|
3
3
|
android {
|
|
4
|
-
|
|
4
|
+
compileSdk 34
|
|
5
5
|
|
|
6
6
|
defaultConfig {
|
|
7
|
-
|
|
7
|
+
targetSdk 34
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -16,7 +16,7 @@ repositories {
|
|
|
16
16
|
|
|
17
17
|
dependencies {
|
|
18
18
|
//noinspection GradleDependency
|
|
19
|
-
implementation ('com.regula.documentreader:api:
|
|
19
|
+
implementation ('com.regula.documentreader:api:7.1.9667'){
|
|
20
20
|
transitive = true
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//
|
|
2
|
+
// RGLWConfig.h
|
|
3
|
+
// DocumentReader
|
|
4
|
+
//
|
|
5
|
+
// Created by Pavel Masiuk on 21.09.2023.
|
|
6
|
+
// Copyright © 2023 Regula. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#ifndef RGLWConfig_h
|
|
10
|
+
#define RGLWConfig_h
|
|
11
|
+
|
|
12
|
+
#import <DocumentReader/DocumentReader.h>
|
|
13
|
+
#import "RGLWJSONConstructor.h"
|
|
14
|
+
|
|
15
|
+
@import CoreGraphics;
|
|
16
|
+
@import UIKit;
|
|
17
|
+
@import AVFoundation;
|
|
18
|
+
|
|
19
|
+
@interface RGLWConfig : NSObject
|
|
20
|
+
|
|
21
|
+
+(void)setFunctionality:(NSDictionary*)options :(RGLFunctionality*)functionality;
|
|
22
|
+
+(void)setProcessParams:(NSDictionary*)options :(RGLProcessParams*)processParams;
|
|
23
|
+
+(void)setCustomization:(NSDictionary*)options :(RGLCustomization*)customization;
|
|
24
|
+
+(void)setRfidScenario:(NSDictionary*)options :(RGLRFIDScenario*)rfidScenario;
|
|
25
|
+
+(void)setDataGroups:(RGLDataGroup*)dataGroup dict:(NSDictionary*)dict;
|
|
26
|
+
+(void)setImageQA:(RGLImageQA*)result input:(NSDictionary*)input;
|
|
27
|
+
+(void)setAuthenticityParams:(RGLAuthenticityParams*)result input:(NSDictionary*)input;
|
|
28
|
+
+(void)setLivenessParams:(RGLLivenessParams*)result input:(NSDictionary*)input;
|
|
29
|
+
|
|
30
|
+
+(NSDictionary*)getFunctionality:(RGLFunctionality*)functionality;
|
|
31
|
+
+(NSDictionary*)getProcessParams:(RGLProcessParams*)processParams;
|
|
32
|
+
+(NSDictionary*)getCustomization:(RGLCustomization*)customization;
|
|
33
|
+
+(NSDictionary*)getRfidScenario:(RGLRFIDScenario*)rfidScenario;
|
|
34
|
+
+(NSDictionary*)getDataGroups:(RGLDataGroup*)dataGroup;
|
|
35
|
+
+(NSDictionary*)getImageQA:(RGLImageQA*)input;
|
|
36
|
+
+(NSDictionary*)getAuthenticityParams:(RGLAuthenticityParams*)input;
|
|
37
|
+
+(NSDictionary*)getLivenessParams:(RGLLivenessParams*)input;
|
|
38
|
+
|
|
39
|
+
+(RGLImageQualityCheckType)imageQualityCheckTypeWithNumber:(NSNumber*)value;
|
|
40
|
+
+(NSNumber*)generateDocReaderAction:(RGLDocReaderAction)action;
|
|
41
|
+
+(NSNumber*)generateRFIDCompleteAction:(RGLRFIDCompleteAction)action;
|
|
42
|
+
+(NSNumber*)generateImageQualityCheckType:(RGLImageQualityCheckType)value;
|
|
43
|
+
|
|
44
|
+
+(RGLDocReaderFrame)docReaderFrameWithString:(NSString*)value;
|
|
45
|
+
+(NSString*)generateDocReaderFrame:(RGLDocReaderFrame)value;
|
|
46
|
+
|
|
47
|
+
@end
|
|
48
|
+
#endif
|