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