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 07c6ac3 commit 9d18a99
Show file tree
Hide file tree
Showing 14 changed files with 829 additions and 374 deletions.
4 changes: 2 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"author": "Regula Forensics Inc.",
"license": "commercial",
"dependencies": {
"@regulaforensics/cordova-plugin-document-reader-api": "7.1.0",
"@regulaforensics/cordova-plugin-document-reader-core-fullrfid": "7.1.0",
"@regulaforensics/cordova-plugin-document-reader-api": "7.2.0",
"@regulaforensics/cordova-plugin-document-reader-core-fullrfid": "7.2.0",
"cordova-android": "12.0.1",
"cordova-ios": "7.0.1",
"cordova-plugin-add-swift-support": "2.0.2",
Expand Down
13 changes: 7 additions & 6 deletions example/www/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ var app = {
function onInitialized() {
document.getElementById("status").innerHTML = "Ready"
document.getElementById("status").style.backgroundColor = "green"

DocumentReader.setFunctionality({
showCaptureButton: true
}, function (s) { }, function (e) { })
var functionality = new Functionality()
functionality.showCaptureButton = true
DocumentReader.setFunctionality(functionality, function (s) { }, function (e) { })
}

this.receivedEvent('deviceready')
Expand All @@ -27,6 +27,7 @@ var app = {
var ScannerConfig = DocumentReaderPlugin.ScannerConfig
var RecognizeConfig = DocumentReaderPlugin.RecognizeConfig
var DocReaderConfig = DocumentReaderPlugin.DocReaderConfig
var Functionality = DocumentReaderPlugin.Functionality
var Enum = DocumentReaderPlugin.Enum

var selectedScenario = "Mrz"
Expand Down Expand Up @@ -113,7 +114,7 @@ var app = {
hideRfidUI()
displayResults(completion.results)
}
} else if (actionSuccess(completion.action))
} else if (actionSuccess(completion.action) || actionError(completion.action))
handleResults(completion.results)
}

Expand Down Expand Up @@ -184,7 +185,7 @@ var app = {

function handleResults(results) {
clearResults()
if (doRfid && !isReadingRfid && results != null) {
if (doRfid && !isReadingRfid && results != null && results.chipPage != 0) {
// customRFID()
usualRFID()
} else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@regulaforensics/cordova-plugin-document-reader-api",
"version": "7.1.0",
"version": "7.2.0",
"description": "Cordova plugin for reading and validation of identification documents (API framework)",
"cordova": {
"id": "@regulaforensics/cordova-plugin-document-reader-api",
Expand Down
4 changes: 2 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<plugin id="cordova-plugin-document-reader-api" version="7.1.0"
<plugin id="cordova-plugin-document-reader-api" version="7.2.0"
xmlns="http://apache.org/cordova/ns/plugins/1.0">
<name>DocumentReaderApi</name>
<description>Cordova plugin Document reader api</description>
Expand All @@ -26,7 +26,7 @@
<config>
</config>
<pods>
<pod name="DocumentReader" spec="7.1.3379" />
<pod name="DocumentReader" spec="7.2.3545" />
</pods>
</podspec>
</platform>
Expand Down
16 changes: 9 additions & 7 deletions src/android/Config.kt
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
31 changes: 15 additions & 16 deletions src/android/DocumentReader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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 @@ -77,7 +78,9 @@ fun sendEvent(event: String, data: Any? = "") {
}

@Suppress("UNCHECKED_CAST")
private fun <T> argsNullable(index: Int): T? = args.get(index) as T?
fun <T> argsNullable(index: Int): T? = if (args.get(index).toString() != "null") {
args.get(index) as T
} else null

lateinit var args: JSONArray
lateinit var callbackContext: CallbackContext
Expand Down Expand Up @@ -109,6 +112,7 @@ fun exec(arguments: JSONArray, tempContext: CallbackContext) {
"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 @@ -122,8 +126,8 @@ fun exec(arguments: JSONArray, tempContext: CallbackContext) {
"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 @@ -155,12 +159,12 @@ fun exec(arguments: JSONArray, tempContext: CallbackContext) {
"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 Down Expand Up @@ -225,6 +229,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 @@ -332,9 +338,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 @@ -415,15 +420,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
15 changes: 13 additions & 2 deletions src/android/JSONConstructor.kt
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 cordova.plugin.documentreader

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 @@ -1961,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
37 changes: 21 additions & 16 deletions src/android/Utils.kt
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 cordova.plugin.documentreader

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
2 changes: 1 addition & 1 deletion src/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repositories {

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

0 comments on commit 9d18a99

Please sign in to comment.