@regulaforensics/react-native-document-reader-api 8.1.136-nightly → 8.1.138-nightly

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 (36) hide show
  1. package/RNDocumentReaderApi.podspec +1 -1
  2. package/android/build.gradle +2 -2
  3. package/android/src/main/AndroidManifest.xml +1 -1
  4. package/android/src/main/java/com/regula/{documentreader → plugin/documentreader}/BluetoothUtil.kt +7 -16
  5. package/android/src/main/java/com/regula/{documentreader → plugin/documentreader}/Config.kt +154 -120
  6. package/android/src/main/java/com/regula/plugin/documentreader/JSONConstructor.kt +1778 -0
  7. package/android/src/main/java/com/regula/plugin/documentreader/Main.kt +553 -0
  8. package/android/src/main/java/com/regula/plugin/documentreader/RNRegulaDocumentReaderModule.kt +103 -0
  9. package/android/src/main/java/com/regula/plugin/documentreader/Utils.kt +181 -0
  10. package/example/android/app/build.gradle +7 -4
  11. package/example/android/app/src/debug/java/com/regula/dr/fullrfid/ReactNativeFlipper.java +1 -1
  12. package/example/android/app/src/main/java/com/regula/dr/{fullrfid → fullauthrfid}/MainActivity.java +1 -1
  13. package/example/android/app/src/main/java/com/regula/dr/{fullrfid → fullauthrfid}/MainApplication.java +10 -3
  14. package/example/android/app/src/release/java/com/regula/dr/fullrfid/ReactNativeFlipper.java +1 -1
  15. package/example/android/build.gradle +5 -5
  16. package/example/android/gradle/wrapper/gradle-wrapper.properties +1 -1
  17. package/example/android/settings.gradle +4 -2
  18. package/example/ios/DocumentReader/AppDelegate.mm +5 -0
  19. package/example/ios/DocumentReader/Info.plist +22 -0
  20. package/example/ios/DocumentReader.xcodeproj/project.pbxproj +4 -14
  21. package/example/ios/Podfile +1 -6
  22. package/example/package-lock.json +2665 -1874
  23. package/example/package.json +25 -22
  24. package/ios/RGLWConfig.h +0 -8
  25. package/ios/RGLWConfig.m +44 -52
  26. package/ios/RGLWJSONConstructor.h +1 -8
  27. package/ios/RGLWJSONConstructor.m +12 -10
  28. package/ios/RGLWMain.h +36 -0
  29. package/ios/RGLWMain.m +591 -0
  30. package/ios/RNRegulaDocumentReader.h +4 -20
  31. package/ios/RNRegulaDocumentReader.m +18 -726
  32. package/package.json +1 -1
  33. package/android/src/main/java/com/regula/documentreader/JSONConstructor.kt +0 -2227
  34. package/android/src/main/java/com/regula/documentreader/RNRegulaDocumentReaderModule.kt +0 -560
  35. package/android/src/main/java/com/regula/documentreader/RNRegulaDocumentReaderPackage.kt +0 -11
  36. package/android/src/main/java/com/regula/documentreader/Utils.kt +0 -268
@@ -1,268 +0,0 @@
1
- //
2
- // Utils.kt
3
- // DocumentReader
4
- //
5
- // Created by Pavel Masiuk on 21.09.2023.
6
- // Copyright © 2023 Regula. All rights reserved.
7
- //
8
-
9
- package com.regula.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() = when (this) {
181
- is Int -> toFloat()
182
- is Double -> toFloat()
183
- else -> this as Float
184
- }
185
-
186
- fun Any?.toMatrix() = this?.let {
187
- val matrix = Matrix()
188
- val result = FloatArray((this as JSONArray).length())
189
- for (i in 0 until length()) result[i] = getDouble(i).toFloat()
190
- matrix.setValues(result)
191
- matrix
192
- }
193
-
194
- fun Any?.toIntArray() = (this as JSONArray?)?.let {
195
- val result = IntArray(it.length())
196
- for (i in 0 until it.length()) result[i] = it.getInt(i)
197
- result
198
- }
199
-
200
- fun IntArray?.generate() = this?.let {
201
- val result = JSONArray()
202
- for (i in indices) result.put(i, this[i])
203
- result
204
- }
205
-
206
- fun String?.toLong() = this?.let {
207
- if (this[0] == '#') this.substring(1).toLong(16)
208
- else this.toLong(16)
209
- }
210
-
211
- fun Matrix?.generate() = this?.let {
212
- val floats = FloatArray(9)
213
- getValues(floats)
214
- val result = JSONArray()
215
- for (f in floats) result.put(java.lang.Float.valueOf(f))
216
- result
217
- }
218
-
219
- fun CustomizationFont.generate(fonts: Map<CustomizationFont, Typeface>, sizes: Map<CustomizationFont, Int>) = generateTypeface(fonts[this], sizes[this])
220
-
221
- fun CustomizationFont.setFont(editor: ParamsCustomization.CustomizationEditor, value: Any?) {
222
- val font = typefaceFromJSON(value as JSONObject)
223
- editor.setFont(this, font.first)
224
- font.second?.let { editor.setFontSize(this, it) }
225
- }
226
-
227
- internal object Convert {
228
- fun byteArrayFromBase64(base64: String?): ByteArray? {
229
- var str = base64 ?: return null
230
- if (str.startsWith("data")) str = str.substring(str.indexOf(",") + 1)
231
- return Base64.decode(str, Base64.NO_WRAP)
232
- }
233
-
234
- fun generateByteArray(array: ByteArray?) = array?.let { Base64.encodeToString(it, Base64.NO_WRAP) }
235
-
236
- fun bitmapFromBase64(base64: String?) = base64?.let {
237
- val decodedString = byteArrayFromBase64(base64)
238
- var result = BitmapFactory.decodeByteArray(decodedString, 0, decodedString!!.size)
239
- val sizeMultiplier = result.byteCount / 5000000
240
- if (result.byteCount > 5000000) result = Bitmap.createScaledBitmap(result, result.width / sqrt(sizeMultiplier.toDouble()).toInt(), result.height / sqrt(sizeMultiplier.toDouble()).toInt(), false)
241
- result
242
- }
243
-
244
- fun bitmapToBase64(bitmap: Bitmap?) = bitmap?.let {
245
- val byteArrayOutputStream = ByteArrayOutputStream()
246
- bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream)
247
- val byteArray = byteArrayOutputStream.toByteArray()
248
- generateByteArray(byteArray)
249
- }
250
-
251
- fun Any?.toDrawable(context: Context) = (this as String?)?.let {
252
- val decodedByte = byteArrayFromBase64(it)
253
- val bitmap = BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte!!.size)
254
- val density = context.resources.displayMetrics.density
255
- val width = (bitmap.width * density).toInt()
256
- val height = (bitmap.height * density).toInt()
257
- BitmapDrawable(context.resources, Bitmap.createScaledBitmap(bitmap, width, height, false))
258
- }
259
-
260
- fun Drawable?.toString() = this?.let {
261
- if (this is BitmapDrawable) if (bitmap != null) return bitmapToBase64(bitmap)
262
- 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)
263
- val canvas = Canvas(bitmap)
264
- setBounds(0, 0, canvas.width, canvas.height)
265
- draw(canvas)
266
- bitmapToBase64(bitmap)
267
- }
268
- }