@regulaforensics/cordova-plugin-document-reader-api 8.1.122-nightly → 8.1.131-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.
- package/example/config.xml +1 -1
- package/example/package.json +2 -2
- package/package.json +1 -1
- package/plugin.xml +11 -8
- package/src/android/BluetoothUtil.kt +7 -16
- package/src/android/Config.kt +154 -120
- package/src/android/DocumentReader.kt +20 -487
- package/src/android/JSONConstructor.kt +1270 -1719
- package/src/android/Main.kt +553 -0
- package/src/android/Utils.kt +73 -160
- package/src/android/build.gradle +1 -1
- package/src/ios/RGLWConfig.h +0 -8
- package/src/ios/RGLWConfig.m +44 -52
- package/src/ios/RGLWDocumentReader.h +3 -27
- package/src/ios/RGLWDocumentReader.m +11 -716
- package/src/ios/RGLWJSONConstructor.h +1 -8
- package/src/ios/RGLWJSONConstructor.m +12 -10
- package/src/ios/RGLWMain.h +36 -0
- package/src/ios/RGLWMain.m +591 -0
package/src/android/Utils.kt
CHANGED
|
@@ -1,35 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
// Utils.kt
|
|
3
|
-
// DocumentReader
|
|
4
|
-
//
|
|
5
|
-
// Created by Pavel Masiuk on 21.09.2023.
|
|
6
|
-
// Copyright © 2023 Regula. All rights reserved.
|
|
7
|
-
//
|
|
1
|
+
@file:SuppressLint("UseKtx")
|
|
8
2
|
|
|
9
|
-
package
|
|
3
|
+
package com.regula.plugin.documentreader
|
|
10
4
|
|
|
11
|
-
import android.
|
|
5
|
+
import android.annotation.SuppressLint
|
|
12
6
|
import android.graphics.Bitmap
|
|
13
7
|
import android.graphics.BitmapFactory
|
|
14
8
|
import android.graphics.Canvas
|
|
15
|
-
import android.graphics.Matrix
|
|
16
|
-
import android.graphics.Paint
|
|
17
|
-
import android.graphics.Typeface
|
|
18
9
|
import android.graphics.drawable.BitmapDrawable
|
|
19
10
|
import android.graphics.drawable.Drawable
|
|
20
11
|
import android.util.Base64
|
|
21
|
-
import com.regula.documentreader.api.enums.CustomizationFont
|
|
22
|
-
import com.regula.documentreader.api.params.ParamsCustomization
|
|
23
12
|
import org.json.JSONArray
|
|
24
13
|
import org.json.JSONObject
|
|
25
14
|
import java.io.ByteArrayOutputStream
|
|
26
15
|
import kotlin.math.sqrt
|
|
27
16
|
|
|
28
|
-
fun Any?.toSendable(): Any? = this?.let {
|
|
29
|
-
if (this is JSONObject || this is JSONArray) this.toString()
|
|
30
|
-
else this
|
|
31
|
-
}
|
|
32
|
-
|
|
33
17
|
fun List<*>.toJson(): JSONArray {
|
|
34
18
|
val result = JSONArray()
|
|
35
19
|
for (i in indices)
|
|
@@ -55,83 +39,73 @@ fun Map<*, *>.toJson(): JSONObject {
|
|
|
55
39
|
return result
|
|
56
40
|
}
|
|
57
41
|
|
|
58
|
-
fun
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
result
|
|
42
|
+
fun Any?.toSendable(): Any? = this?.let {
|
|
43
|
+
if (it is JSONObject || it is JSONArray) it.toString()
|
|
44
|
+
else it
|
|
62
45
|
}
|
|
63
46
|
|
|
64
|
-
fun <T>
|
|
47
|
+
fun <T> List<T>?.toJson(toJson: (T?) -> Any?) = this?.let {
|
|
65
48
|
val result = JSONArray()
|
|
66
|
-
for (
|
|
67
|
-
|
|
49
|
+
for (item in it) result.put(toJson(item))
|
|
50
|
+
result
|
|
68
51
|
}
|
|
69
52
|
|
|
70
|
-
fun <T>
|
|
71
|
-
val result
|
|
72
|
-
for (
|
|
73
|
-
val item = input.getJSONObject(i)
|
|
74
|
-
result.add(fromJson(item))
|
|
75
|
-
}
|
|
53
|
+
fun <T> List<T>?.toJsonNullable(toJson: (T?) -> Any?) = this?.let {
|
|
54
|
+
val result = JSONArray()
|
|
55
|
+
for (item in it) result.put(toJson(item))
|
|
76
56
|
result
|
|
77
57
|
}
|
|
78
58
|
|
|
79
|
-
|
|
80
|
-
fun <T> listFromJSON(input: JSONArray): List<T> {
|
|
59
|
+
fun <T> JSONArray?.toList(fromJson: (JSONObject) -> T) = this?.let {
|
|
81
60
|
val result: MutableList<T> = ArrayList()
|
|
82
|
-
for (i in 0 until
|
|
83
|
-
|
|
61
|
+
for (i in 0 until it.length()) result.add(fromJson(it.getJSONObject(i)))
|
|
62
|
+
result
|
|
84
63
|
}
|
|
85
64
|
|
|
86
|
-
fun <T>
|
|
87
|
-
|
|
88
|
-
|
|
65
|
+
fun <T> JSONArray.toList() = this.let {
|
|
66
|
+
val result = mutableListOf<T>()
|
|
67
|
+
@Suppress("UNCHECKED_CAST")
|
|
68
|
+
for (i in 0 until length()) result.add(get(i) as T)
|
|
89
69
|
result
|
|
90
70
|
}
|
|
91
71
|
|
|
92
|
-
fun <T>
|
|
93
|
-
val result =
|
|
94
|
-
for (
|
|
95
|
-
|
|
72
|
+
inline fun <reified T> JSONArray?.toArray() = this?.let {
|
|
73
|
+
val result = arrayOfNulls<T>(length())
|
|
74
|
+
for (i in 0 until length()) result[i] = get(i) as T
|
|
75
|
+
result
|
|
96
76
|
}
|
|
97
77
|
|
|
98
|
-
fun <T>
|
|
99
|
-
val result =
|
|
100
|
-
for (i in
|
|
78
|
+
inline fun <reified T> JSONArray?.toArray(fromJson: (JSONObject?) -> T) = this?.let {
|
|
79
|
+
val result = arrayOfNulls<T>(length())
|
|
80
|
+
for (i in 0 until length()) result[i] = fromJson(getJSONObject(i))
|
|
101
81
|
result
|
|
102
82
|
}
|
|
103
83
|
|
|
104
|
-
fun <T>
|
|
84
|
+
fun <T> Array<T>?.toJson() = this?.let {
|
|
105
85
|
val result = JSONArray()
|
|
106
|
-
for (i in
|
|
86
|
+
for (i in it.indices) result.put(i, it[i])
|
|
107
87
|
result
|
|
108
88
|
}
|
|
109
89
|
|
|
110
|
-
fun
|
|
90
|
+
fun <T> Array<T>?.toJson(toJson: (T?) -> JSONObject?) = this?.let {
|
|
111
91
|
val result = JSONArray()
|
|
112
|
-
for (i in
|
|
92
|
+
for (i in indices) result.put(i, toJson(this[i]))
|
|
113
93
|
result
|
|
114
94
|
}
|
|
115
95
|
|
|
116
|
-
fun
|
|
117
|
-
val result
|
|
118
|
-
for (i in 0 until
|
|
119
|
-
|
|
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
|
|
96
|
+
fun Any?.toIntArray() = (this as JSONArray?)?.let {
|
|
97
|
+
val result = IntArray(it.length())
|
|
98
|
+
for (i in 0 until it.length()) result[i] = it.getInt(i)
|
|
99
|
+
result
|
|
126
100
|
}
|
|
127
101
|
|
|
128
|
-
fun
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
102
|
+
fun IntArray?.toJson() = this?.let {
|
|
103
|
+
val result = JSONArray()
|
|
104
|
+
for (i in it.indices) result.put(i, it[i])
|
|
105
|
+
result
|
|
132
106
|
}
|
|
133
107
|
|
|
134
|
-
fun JSONObject.forEach(action: (String, Any
|
|
108
|
+
fun JSONObject.forEach(action: (String, Any) -> Unit) {
|
|
135
109
|
val keys: Iterator<String> = keys()
|
|
136
110
|
while (keys.hasNext()) {
|
|
137
111
|
val key = keys.next()
|
|
@@ -139,130 +113,69 @@ fun JSONObject.forEach(action: (String, Any?) -> Unit) {
|
|
|
139
113
|
}
|
|
140
114
|
}
|
|
141
115
|
|
|
142
|
-
fun
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return result
|
|
116
|
+
fun JSONObject.getJSONObjectOrNull(name: String): JSONObject? {
|
|
117
|
+
if (has(name) && get(name).toString() != "null") return getJSONObject(name)
|
|
118
|
+
return null
|
|
146
119
|
}
|
|
147
120
|
|
|
148
|
-
fun
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return result
|
|
121
|
+
fun JSONObject.getIntOrNull(name: String): Int? {
|
|
122
|
+
if (has(name) && get(name).toString() != "null") return getInt(name)
|
|
123
|
+
return null
|
|
152
124
|
}
|
|
153
125
|
|
|
154
|
-
fun
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
result
|
|
126
|
+
fun JSONObject.getDoubleOrNull(name: String): Double? {
|
|
127
|
+
if (has(name) && get(name).toString() != "null") return getDouble(name)
|
|
128
|
+
return null
|
|
158
129
|
}
|
|
159
130
|
|
|
160
|
-
fun
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
else -> this as Int
|
|
131
|
+
fun JSONObject.getBooleanOrNull(name: String): Boolean? {
|
|
132
|
+
if (has(name) && get(name).toString() != "null") return getBoolean(name)
|
|
133
|
+
return null
|
|
164
134
|
}
|
|
165
135
|
|
|
166
|
-
fun
|
|
167
|
-
|
|
168
|
-
|
|
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) }
|
|
136
|
+
fun JSONObject.getStringOrNull(name: String): String? {
|
|
137
|
+
if (has(name) && get(name).toString() != "null") return getString(name)
|
|
138
|
+
return null
|
|
225
139
|
}
|
|
226
140
|
|
|
227
141
|
internal object Convert {
|
|
228
|
-
fun
|
|
229
|
-
var str =
|
|
142
|
+
fun String?.toByteArray(): ByteArray? {
|
|
143
|
+
var str = this ?: return null
|
|
230
144
|
if (str.startsWith("data")) str = str.substring(str.indexOf(",") + 1)
|
|
231
145
|
return Base64.decode(str, Base64.NO_WRAP)
|
|
232
146
|
}
|
|
233
147
|
|
|
234
|
-
fun
|
|
148
|
+
fun ByteArray?.toBase64() = this?.let { Base64.encodeToString(it, Base64.NO_WRAP) }
|
|
149
|
+
|
|
150
|
+
fun Bitmap?.toBase64() = this?.let {
|
|
151
|
+
val byteArrayOutputStream = ByteArrayOutputStream()
|
|
152
|
+
it.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream)
|
|
153
|
+
byteArrayOutputStream.toByteArray().toBase64()
|
|
154
|
+
}
|
|
235
155
|
|
|
236
|
-
fun
|
|
237
|
-
val decodedString =
|
|
238
|
-
var result = BitmapFactory.decodeByteArray(decodedString, 0, decodedString
|
|
156
|
+
fun String?.toBitmap() = this?.let {
|
|
157
|
+
val decodedString = toByteArray()!!
|
|
158
|
+
var result = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.size)
|
|
239
159
|
val sizeMultiplier = result.byteCount / 5000000
|
|
240
160
|
if (result.byteCount > 5000000) result = Bitmap.createScaledBitmap(result, result.width / sqrt(sizeMultiplier.toDouble()).toInt(), result.height / sqrt(sizeMultiplier.toDouble()).toInt(), false)
|
|
241
161
|
result
|
|
242
162
|
}
|
|
243
163
|
|
|
244
|
-
fun
|
|
245
|
-
val
|
|
246
|
-
bitmap.
|
|
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)
|
|
164
|
+
fun Any?.toDrawable() = (this as String?)?.let {
|
|
165
|
+
val decodedByte = it.toByteArray()!!
|
|
166
|
+
val bitmap = BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.size)
|
|
254
167
|
val density = context.resources.displayMetrics.density
|
|
255
168
|
val width = (bitmap.width * density).toInt()
|
|
256
169
|
val height = (bitmap.height * density).toInt()
|
|
257
170
|
BitmapDrawable(context.resources, Bitmap.createScaledBitmap(bitmap, width, height, false))
|
|
258
171
|
}
|
|
259
172
|
|
|
260
|
-
fun Drawable?.
|
|
261
|
-
if (this is BitmapDrawable) if (bitmap != null) return
|
|
173
|
+
fun Drawable?.toBase64() = this?.let {
|
|
174
|
+
if (this is BitmapDrawable) if (bitmap != null) return bitmap.toBase64()
|
|
262
175
|
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
176
|
val canvas = Canvas(bitmap)
|
|
264
177
|
setBounds(0, 0, canvas.width, canvas.height)
|
|
265
178
|
draw(canvas)
|
|
266
|
-
|
|
179
|
+
bitmap.toBase64()
|
|
267
180
|
}
|
|
268
|
-
}
|
|
181
|
+
}
|
package/src/android/build.gradle
CHANGED