Skip to content

Commit

Permalink
7.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins committed Apr 21, 2024
1 parent f0a1f9b commit 1a90d3b
Show file tree
Hide file tree
Showing 2,090 changed files with 124,502 additions and 121,903 deletions.
2 changes: 1 addition & 1 deletion .dart_tool/package_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
"languageVersion": "3.1"
}
],
"generated": "2024-02-22T07:41:56.445089Z",
"generated": "2024-04-21T09:24:38.425253Z",
"generator": "pub",
"generatorVersion": "3.2.0"
}
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
}

dependencies {
implementation('com.regula.documentreader:api:7.1.9667') {
implementation('com.regula.documentreader:api:7.2.9835') {
transitive = true
}

Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fun setFunctionality(functionality: Functionality, opts: JSONObject) = opts.forE
"showCaptureButtonDelayFromStart" -> editor.setShowCaptureButtonDelayFromStart(v.toLong())
"orientation" -> editor.setOrientation(v.toInt())
"captureMode" -> editor.setCaptureMode(v.toInt())
"cameraPosition" -> editor.setCameraMode(v.toInt())
"cameraMode" -> editor.setCameraMode(v.toInt())
"rfidTimeout" -> editor.setRfidTimeout(v.toInt())
"forcePagesCount" -> editor.setForcePagesCount(v.toInt())
"cameraFrame" -> editor.setCameraFrame(v as String)
Expand Down Expand Up @@ -88,7 +88,7 @@ fun getFunctionality(functionality: Functionality) = mapOf(
"showCaptureButtonDelayFromStart" to functionality.showCaptureButtonDelayFromStart,
"orientation" to functionality.orientation,
"captureMode" to functionality.captureMode,
"cameraPosition" to functionality.cameraMode,
"cameraMode" to functionality.cameraMode,
"rfidTimeout" to functionality.rfidTimeout,
"forcePagesCount" to functionality.forcePagesCount,
"cameraFrame" to functionality.cameraFrame,
Expand Down Expand Up @@ -150,10 +150,10 @@ fun setProcessParams(processParams: ProcessParam, opts: JSONObject) = opts.forEa
"scenario" -> processParams.scenario = v as String
"captureButtonScenario" -> processParams.captureButtonScenario = v as String
"sessionLogFolder" -> processParams.sessionLogFolder = v as String
"timeout" -> processParams.timeout = v as Double
"timeoutFromFirstDetect" -> processParams.timeoutFromFirstDetect = v as Double
"timeoutFromFirstDocType" -> processParams.timeoutFromFirstDocType = v as Double
"documentAreaMin" -> processParams.documentAreaMin = v as Double
"timeout" -> processParams.timeout = v.toDouble()
"timeoutFromFirstDetect" -> processParams.timeoutFromFirstDetect = v.toDouble()
"timeoutFromFirstDocType" -> processParams.timeoutFromFirstDocType = v.toDouble()
"documentAreaMin" -> processParams.documentAreaMin = v.toDouble()
"documentIDList" -> processParams.documentIDList = v.toIntArray()
"fieldTypesFilter" -> processParams.fieldTypesFilter = v.toIntArray()
"resultTypeOutput" -> processParams.resultTypeOutput = v.toIntArray()
Expand Down Expand Up @@ -412,6 +412,7 @@ fun setRfidScenario(rfidScenario: RfidScenario, opts: JSONObject) = opts.forEach
"authorizedInstallQCert" -> rfidScenario.isAuthorizedInstallQCert = v as Boolean
"applyAmendments" -> rfidScenario.isApplyAmendments = v as Boolean
"autoSettings" -> rfidScenario.isAutoSettings = v as Boolean
"proceedReadingAlways" -> rfidScenario.proceedReadingAlways = v as Boolean
"signManagementAction" -> rfidScenario.signManagementAction = v.toInt()
"readingBuffer" -> rfidScenario.readingBuffer = v.toInt()
"onlineTAToSignDataType" -> rfidScenario.onlineTAToSignDataType = v.toInt()
Expand Down Expand Up @@ -467,6 +468,7 @@ fun getRfidScenario(rfidScenario: RfidScenario) = mapOf(
"authorizedInstallQCert" to rfidScenario.isAuthorizedInstallQCert,
"applyAmendments" to rfidScenario.isApplyAmendments,
"autoSettings" to rfidScenario.isAutoSettings,
"proceedReadingAlways" to rfidScenario.proceedReadingAlways,
"signManagementAction" to rfidScenario.signManagementAction,
"readingBuffer" to rfidScenario.readingBuffer,
"onlineTAToSignDataType" to rfidScenario.onlineTAToSignDataType,
Expand Down Expand Up @@ -562,7 +564,7 @@ fun setImageQA(input: ImageQA, opts: JSONObject) = opts.forEach { k, v ->
"dpiThreshold" -> input.dpiThreshold = v.toInt()
"angleThreshold" -> input.angleThreshold = v.toInt()
"documentPositionIndent" -> input.documentPositionIndent = v.toInt()
"brightnessThreshold" -> input.brightnessThreshold = v as Double
"brightnessThreshold" -> input.brightnessThreshold = v.toDouble()
"expectedPass" -> input.expectedPass = v.toIntArray()
"glaresCheckParams" -> input.glaresCheckParams = glaresCheckParamsFromJSON(v as JSONObject)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by Pavel Masiuk on 21.09.2023.
// Copyright © 2023 Regula. All rights reserved.
//
@file:Suppress("UNCHECKED_CAST")

package io.flutter.plugins.regula.documentreader.flutter_document_reader_api

Expand All @@ -25,7 +24,8 @@ import com.regula.common.LocalizationCallbacks
import com.regula.documentreader.api.DocumentReader.Instance
import com.regula.documentreader.api.completions.IDocumentReaderCompletion
import com.regula.documentreader.api.completions.IDocumentReaderInitCompletion
import com.regula.documentreader.api.completions.IDocumentReaderPrepareCompletion
import com.regula.documentreader.api.completions.IDocumentReaderPrepareDbCompletion
import com.regula.documentreader.api.completions.model.PrepareProgress
import com.regula.documentreader.api.completions.rfid.IRfidPKDCertificateCompletion
import com.regula.documentreader.api.completions.rfid.IRfidReaderCompletion
import com.regula.documentreader.api.completions.rfid.IRfidReaderRequest
Expand Down Expand Up @@ -110,14 +110,14 @@ fun sendEvent(id: String, data: Any? = "") {
eventSinks[id]?.let { Handler(Looper.getMainLooper()).post { it.success(data.toSendable()) } }
}

fun <T> argsNullable(index: Int) = when {
args[index] == null -> null
args[index]!!.javaClass == HashMap::class.java -> hashMapToJSONObject(args[index] as HashMap<String, *>) as T
args[index]!!.javaClass == ArrayList::class.java -> arrayListToJSONArray(args[index] as ArrayList<*>) as T
else -> args[index] as T
inline fun <reified T> argsNullable(index: Int) = when (val v = args[index]) {
null -> null
is Map<*, *> -> v.toJson() as T
is List<*> -> v.toJson() as T
else -> v as T
}

lateinit var args: ArrayList<Any?>
lateinit var args: List<Any?>
val eventSinks = mutableMapOf<String, EventSink?>()
lateinit var binaryMessenger: BinaryMessenger
lateinit var activityBinding: ActivityPluginBinding
Expand All @@ -126,7 +126,7 @@ val lifecycle: Lifecycle

fun methodCall(call: MethodCall, result: MethodChannel.Result) {
val action = call.method
args = call.arguments as ArrayList<Any?>
args = call.arguments as List<*>
val callback = object : Callback {
override fun success(data: Any?) = result.success(data.toSendable())
override fun error(message: String) = result.error("", message, null)
Expand All @@ -148,6 +148,7 @@ fun methodCall(call: MethodCall, result: MethodChannel.Result) {
"setCustomization" -> setCustomization(args(0))
"getRfidScenario" -> getRfidScenario(callback)
"setRfidScenario" -> setRfidScenario(args(0))
"resetConfiguration" -> resetConfiguration()
"initializeReader" -> initializeReader(callback, args(0))
"initializeReaderWithBleDeviceConfig" -> initializeReaderWithBleDeviceConfig(callback, args(0))
"deinitializeReader" -> deinitializeReader(callback)
Expand All @@ -161,8 +162,8 @@ fun methodCall(call: MethodCall, result: MethodChannel.Result) {
"startNewPage" -> startNewPage(callback)
"stopScanner" -> stopScanner(callback)
"startRFIDReader" -> startRFIDReader(args(0), args(1), args(2))
"stopRFIDReader" -> stopRFIDReader(callback)
"readRFID" -> readRFID(args(0), args(1), args(2))
"stopRFIDReader" -> stopRFIDReader(callback)
"providePACertificates" -> providePACertificates(callback, argsNullable(0))
"provideTACertificates" -> provideTACertificates(callback, argsNullable(0))
"provideTASignature" -> provideTASignature(callback, args(0))
Expand Down Expand Up @@ -194,12 +195,12 @@ fun methodCall(call: MethodCall, result: MethodChannel.Result) {
"graphicFieldImageByTypeSourcePageIndexLight" -> graphicFieldImageByTypeSourcePageIndexLight(callback, args(0), args(1), args(2), args(3), args(4))
"containers" -> containers(callback, args(0), args(1))
"encryptedContainers" -> encryptedContainers(callback, args(0))
"getTranslation" -> getTranslation(callback, args(0), args(1))
"finalizePackage" -> finalizePackage(callback)
"getTranslation" -> getTranslation(callback, args(0), args(1))
}
}

fun <T> args(index: Int): T = argsNullable(index)!!
inline fun <reified T> args(index: Int) = argsNullable<T>(index)!!
interface Callback {
fun success(data: Any? = "")
fun error(message: String)
Expand All @@ -212,7 +213,6 @@ val context
get() = activity

var backgroundRFIDEnabled = false
var databaseDownloadProgress = 0

const val eventCompletion = "completion"
const val eventDatabaseProgress = "database_progress"
Expand Down Expand Up @@ -264,6 +264,8 @@ fun getRfidScenario(callback: Callback) = callback.success(getRfidScenario(Insta

fun setRfidScenario(rfidScenario: JSONObject) = setRfidScenario(Instance().rfidScenario(), rfidScenario)

fun resetConfiguration() = Instance().resetConfiguration()

fun initializeReader(callback: Callback, config: JSONObject) = Instance().initializeReader(context, docReaderConfigFromJSON(config), getInitCompletion(callback))

fun initializeReaderWithBleDeviceConfig(callback: Callback, config: JSONObject) = Instance().initializeReader(context, bleDeviceConfigFromJSON(config), getInitCompletion(callback))
Expand Down Expand Up @@ -371,9 +373,8 @@ fun startBluetoothService() = startBluetoothService(
{ sendEvent(bleOnDeviceReadyEvent) }
)

@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
fun setLocalizationDictionary(dictionary: JSONObject) {
localizationCallbacks = LocalizationCallbacks { dictionary.optString(it, null) }
localizationCallbacks = LocalizationCallbacks { if (dictionary.has(it)) dictionary.getString(it) else null }
Instance().setLocalizationCallback(localizationCallbacks!!)
}

Expand Down Expand Up @@ -454,15 +455,9 @@ val rfidReaderCompletion = object : IRfidReaderCompletion() {
override fun onProgress(notification: DocumentReaderNotification) = sendEvent(rfidOnProgressEvent, generateDocumentReaderNotification(notification))
}

fun getPrepareCompletion(callback: Callback) = object : IDocumentReaderPrepareCompletion {
override fun onPrepareProgressChanged(progress: Int) {
if (progress != databaseDownloadProgress) {
sendEvent(eventDatabaseProgress, progress)
databaseDownloadProgress = progress
}
}

override fun onPrepareCompleted(s: Boolean, e: DocumentReaderException?) = callback.success(generateSuccessCompletion(s, e))
fun getPrepareCompletion(callback: Callback) = object : IDocumentReaderPrepareDbCompletion() {
override fun onPrepareProgressChanged(progress: PrepareProgress) = sendEvent(eventDatabaseProgress, generatePrepareProgress(progress))
override fun onPrepareCompleted(success: Boolean, error: DocumentReaderException?) = callback.success(generateSuccessCompletion(success, error))
}

fun getInitCompletion(callback: Callback) = IDocumentReaderInitCompletion { success, error ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by Pavel Masiuk on 21.09.2023.
// Copyright © 2023 Regula. All rights reserved.
//
@file:Suppress("USELESS_CAST")

package io.flutter.plugins.regula.documentreader.flutter_document_reader_api

Expand All @@ -16,6 +15,7 @@ import android.graphics.Typeface
import android.util.Pair
import com.regula.common.exception.RegulaException
import com.regula.documentreader.api.License
import com.regula.documentreader.api.completions.model.PrepareProgress
import com.regula.documentreader.api.config.RecognizeConfig
import com.regula.documentreader.api.config.ScannerConfig
import com.regula.documentreader.api.enums.BarcodeType
Expand Down Expand Up @@ -123,6 +123,17 @@ fun generateSuccessCompletion(success: Boolean, error: RegulaException?) = objec
}
}

fun prepareProgressFromJSON(it: JSONObject) = PrepareProgress(
it.getInt("downloadedBytes"),
it.getInt("totalBytes")
)

fun generatePrepareProgress(it: PrepareProgress) = mapOf(
"downloadedBytes" to it.downloadedBytes,
"totalBytes" to it.totalBytes,
"progress" to it.progress
).toJson()

fun generatePACertificateCompletion(serialNumber: ByteArray?, issuer: PAResourcesIssuer?) = object : JSONObject() { init {
put("serialNumber", generateByteArray(serialNumber))
put("issuer", generatePAResourcesIssuer(issuer))
Expand Down Expand Up @@ -998,9 +1009,8 @@ fun generateImageQualityGroup(temp: ImageQualityGroup?): JSONObject? {
}

fun cameraSizeFromJSON(input: JSONObject): Pair<Int, Int> {
val cameraSize = input.getJSONObject("cameraSize")
val width = cameraSize.getInt("width")
val height = cameraSize.getInt("height")
val width = input.getInt("width")
val height = input.getInt("height")
return Pair(width, height)
}

Expand Down Expand Up @@ -1962,7 +1972,7 @@ fun generateDocReaderDocumentsDatabase(temp: DocReaderDocumentsDatabase?): JSONO
result.put("databaseDescription", input.databaseDescription)
result.put("countriesNumber", input.countriesNumber)
result.put("documentsNumber", input.documentsNumber)
result.put("size", input.size as Long?)
result.put("size", input.size)

return result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by Pavel Masiuk on 21.09.2023.
// Copyright © 2023 Regula. All rights reserved.
//
@file:Suppress("UNCHECKED_CAST")

package io.flutter.plugins.regula.documentreader.flutter_document_reader_api

Expand All @@ -31,27 +30,26 @@ fun Any?.toSendable(): Any? = this?.let {
else this
}

fun arrayListToJSONArray(list: ArrayList<*>): JSONArray {
fun List<*>.toJson(): JSONArray {
val result = JSONArray()
for (i in list.indices) {
when {
list[i] == null -> result.put(null)
list[i].javaClass == HashMap::class.java -> result.put(hashMapToJSONObject(list[i] as HashMap<String, *>))
list[i].javaClass == ArrayList::class.java -> result.put(arrayListToJSONArray(list[i] as ArrayList<*>))
else -> result.put(list[i])
for (i in indices)
when (val v = this[i]) {
null -> result.put(null)
is Map<*, *> -> result.put(v.toJson())
is List<*> -> result.put(v.toJson())
else -> result.put(v)
}
}
return result
}

fun hashMapToJSONObject(map: HashMap<String, *>): JSONObject {
fun Map<*, *>.toJson(): JSONObject {
val result = JSONObject()
for ((key, value) in map) {
when {
value == null -> result.put(key, null)
value.javaClass == HashMap::class.java -> result.put(key, hashMapToJSONObject(value as HashMap<String, *>))
value.javaClass == ArrayList::class.java -> result.put(key, arrayListToJSONArray(value as ArrayList<*>))
else -> result.put(key, value)
for ((k, v) in this) {
when (v) {
null -> result.put(k as String, null)
is Map<*, *> -> result.put(k as String, v.toJson())
is List<*> -> result.put(k as String, v.toJson())
else -> result.put(k as String, v)
}
}
return result
Expand All @@ -78,6 +76,7 @@ fun <T> listFromJSON(input: JSONArray?, fromJson: (JSONObject?) -> T) = input?.l
result
}

@Suppress("UNCHECKED_CAST")
fun <T> listFromJSON(input: JSONArray): List<T> {
val result: MutableList<T> = ArrayList()
for (i in 0 until input.length()) result.add(input.opt(i) as T)
Expand Down Expand Up @@ -170,6 +169,12 @@ fun Any?.toLong() = when (this) {
else -> this as Long
}

fun Any?.toDouble() = when (this) {
is Int -> toDouble()
is Long -> toDouble()
else -> this as Double
}

fun Any?.toColor() = "#" + toLong().toString(16)

fun Any?.toFloat() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ class FlutterDocumentReaderApiPluginTest {
@Test
fun scannerConfig() = compare("scannerConfig", ::scannerConfigFromJSON, ::generateScannerConfig)

@Test
fun scannerConfig2() = compare("scannerConfig2", ::scannerConfigFromJSON, ::generateScannerConfig)

// params.process_params

@Test
Expand Down Expand Up @@ -111,6 +108,9 @@ class FlutterDocumentReaderApiPluginTest {

// info

@Test
fun prepareProgress() = compare("prepareProgress", ::prepareProgressFromJSON, ::generatePrepareProgress)

@Test
fun documentsDatabase() = compare("documentsDatabase", ::docReaderDocumentsDatabaseFromJSON, ::generateDocReaderDocumentsDatabase)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ package io.flutter.plugins.regula.documentreader.flutter_document_reader_api

import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Canvas
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import androidx.test.core.app.ApplicationProvider
Expand Down Expand Up @@ -98,7 +96,7 @@ fun floatToDouble(input: JSONObject): JSONObject {
val value = input.get(key)
if (value is JSONObject) input.put(key, floatToDouble(value))
if (value is JSONArray) input.put(key, floatToDouble(value))
if (value is Float) input.put(key, value.toString().toDouble())
if (value is Float) input.put(key, java.lang.Double.parseDouble(value.toString()))
}
return input
}
Expand All @@ -108,7 +106,7 @@ fun floatToDouble(input: JSONArray): JSONArray {
val value = input.get(i)
if (value is JSONObject) input.put(i, floatToDouble(value))
if (value is JSONArray) input.put(i, floatToDouble(value))
if (value is Float) input.put(i, value.toString().toDouble())
if (value is Float) input.put(i, java.lang.Double.parseDouble(value.toString()))
}
return input
}
Expand Down
Loading

0 comments on commit 1a90d3b

Please sign in to comment.