Skip to content

Commit

Permalink
Merge pull request #167 from BlinkID/release/v6.9.0
Browse files Browse the repository at this point in the history
Release/v6.9.0
  • Loading branch information
mparadina authored Jul 19, 2024
2 parents 8b47866 + d411132 commit 7e5cfb2
Show file tree
Hide file tree
Showing 19 changed files with 704 additions and 183 deletions.
2 changes: 1 addition & 1 deletion BlinkID/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blinkid-cordova",
"version": "6.7.0",
"version": "6.9.0",
"description": "A small and powerful ID card scanning library",
"cordova": {
"id": "blinkid-cordova",
Expand Down
4 changes: 2 additions & 2 deletions BlinkID/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="blinkid-cordova"
version="6.7.0">
version="6.9.0">

<name>BlinkIdScanner</name>
<description>A small and powerful ID card scanning library</description>
Expand Down Expand Up @@ -153,7 +153,7 @@
<framework src="AudioToolbox.framework" />
<framework src="OpenGLES.framework" />
<framework src="Accelerate.framework" />
<framework src="src/ios/BlinkID.xcframework" custom="true" embed="true"/>
<framework src="src/ios/blinkid-ios/BlinkID.xcframework" custom="true" embed="true"/>
<preference name="CAMERA_USAGE_DESCRIPTION" default=" " />
<config-file target="*-Info.plist" parent="NSCameraUsageDescription">
<string>$CAMERA_USAGE_DESCRIPTION</string>
Expand Down
2 changes: 1 addition & 1 deletion BlinkID/scripts/initIOSFramework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
HERE="$(dirname "$(test -L "$0" && readlink "$0" || echo "$0")")"
pushd "${HERE}/../src/ios/" > /dev/null

LINK='https://github.com/BlinkID/blinkid-ios/releases/download/v6.7.1/BlinkID.xcframework.zip'
LINK='https://github.com/BlinkID/blinkid-ios/releases/download/v6.9.0/BlinkID.xcframework.zip'
FILENAME='BlinkID.xcframework.zip'

# BlinkID framework will be obtained via wget or curl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.microblink.blinkid.recognition.RecognitionSuccessType;
import com.microblink.blinkid.metadata.MetadataCallbacks;
import com.microblink.blinkid.view.recognition.ScanResultListener;
import com.microblink.blinkid.licence.exception.LicenceKeyException;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
Expand Down Expand Up @@ -98,22 +99,22 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
}
}

private void scanWithCamera(JSONArray arguments) throws JSONException{
private void scanWithCamera(JSONArray arguments) throws JSONException {
try {
JSONObject jsonOverlaySettings = arguments.getJSONObject(0);
JSONObject jsonRecognizerCollection = arguments.getJSONObject(1);
JSONObject jsonLicenses = arguments.getJSONObject(2);

setLicense(jsonLicenses);
setLanguage(jsonOverlaySettings.getString("language"),
jsonOverlaySettings.getString("country"));
mRecognizerBundle = RecognizerSerializers.INSTANCE.deserializeRecognizerCollection(jsonRecognizerCollection);
UISettings overlaySettings = OverlaySettingsSerializers.INSTANCE.getOverlaySettings(this.cordova.getContext(), jsonOverlaySettings, mRecognizerBundle);

// unable to use ActivityRunner because we need to use cordova's activity launcher
Intent intent = new Intent(this.cordova.getContext(), overlaySettings.getTargetActivity());
overlaySettings.saveToIntent(intent);
this.cordova.startActivityForResult(this, intent, REQUEST_CODE);
if (setLicense(jsonLicenses)) {
setLanguage(jsonOverlaySettings.getString("language"),
jsonOverlaySettings.getString("country"));
mRecognizerBundle = RecognizerSerializers.INSTANCE.deserializeRecognizerCollection(jsonRecognizerCollection);
UISettings overlaySettings = OverlaySettingsSerializers.INSTANCE.getOverlaySettings(this.cordova.getContext(), jsonOverlaySettings, mRecognizerBundle);

// unable to use ActivityRunner because we need to use cordova's activity launcher
Intent intent = new Intent(this.cordova.getContext(), overlaySettings.getTargetActivity());
overlaySettings.saveToIntent(intent);
this.cordova.startActivityForResult(this, intent, REQUEST_CODE);
}
} catch (JSONException e) {
mCallbackContext.error("Could not start scanWithCamera.\nJSON error: " + e);
}
Expand All @@ -123,63 +124,64 @@ private void scanWithDirectApi(JSONArray arguments) throws JSONException {
//DirectAPI processing
JSONObject jsonRecognizerCollection = arguments.getJSONObject(0);
JSONObject jsonLicense = arguments.getJSONObject(3);
setLicense(jsonLicense);

ScanResultListener mScanResultListenerBackSide = new ScanResultListener() {
@Override
public void onScanningDone(@NonNull RecognitionSuccessType recognitionSuccessType) {
mFirstSideScanned = false;
handleDirectApiResult(recognitionSuccessType);
}
@Override
public void onUnrecoverableError(@NonNull Throwable throwable) {
handleDirectApiError(throwable.getMessage());
}
};
if (setLicense(jsonLicense)) {

FirstSideRecognitionCallback mFirstSideRecognitionCallback = new FirstSideRecognitionCallback() {
@Override
public void onFirstSideRecognitionFinished() {
mFirstSideScanned = true;
}
};
ScanResultListener mScanResultListenerBackSide = new ScanResultListener() {
@Override
public void onScanningDone(@NonNull RecognitionSuccessType recognitionSuccessType) {
mFirstSideScanned = false;
handleDirectApiResult(recognitionSuccessType);
}
@Override
public void onUnrecoverableError(@NonNull Throwable throwable) {
handleDirectApiError(throwable.getMessage());
}
};

ScanResultListener mScanResultListenerFrontSide = new ScanResultListener() {
@Override
public void onScanningDone(@NonNull RecognitionSuccessType recognitionSuccessType) {
if (mFirstSideScanned) {
//multiside recognizer used
try {
if (!arguments.getString(2).isEmpty() && !arguments.isNull(2)) {
processImage(arguments.getString(2), mScanResultListenerBackSide);
} else if (recognitionSuccessType != RecognitionSuccessType.UNSUCCESSFUL) {
handleDirectApiResult(recognitionSuccessType);
} else {
handleDirectApiError("Could not extract the information from the front side and the back side is empty!");
FirstSideRecognitionCallback mFirstSideRecognitionCallback = new FirstSideRecognitionCallback() {
@Override
public void onFirstSideRecognitionFinished() {
mFirstSideScanned = true;
}
};

ScanResultListener mScanResultListenerFrontSide = new ScanResultListener() {
@Override
public void onScanningDone(@NonNull RecognitionSuccessType recognitionSuccessType) {
if (mFirstSideScanned) {
//multiside recognizer used
try {
if (!arguments.getString(2).isEmpty() && !arguments.isNull(2)) {
processImage(arguments.getString(2), mScanResultListenerBackSide);
} else if (recognitionSuccessType != RecognitionSuccessType.UNSUCCESSFUL) {
handleDirectApiResult(recognitionSuccessType);
} else {
handleDirectApiError("Could not extract the information from the front side and the back side is empty!");
}
} catch (JSONException e) {
throw new RuntimeException(e);
}
} catch (JSONException e) {
throw new RuntimeException(e);
} else if (!mFirstSideScanned && recognitionSuccessType != RecognitionSuccessType.UNSUCCESSFUL){
//singleside recognizer used
handleDirectApiResult(recognitionSuccessType);
} else {
mFirstSideScanned = false;
handleDirectApiError("Could not extract the information with DirectAPI!");
}
} else if (!mFirstSideScanned && recognitionSuccessType != RecognitionSuccessType.UNSUCCESSFUL){
//singleside recognizer used
handleDirectApiResult(recognitionSuccessType);
} else {
mFirstSideScanned = false;
handleDirectApiError("Could not extract the information with DirectAPI!");
}
}
@Override
public void onUnrecoverableError(@NonNull Throwable throwable) {
handleDirectApiError(throwable.getMessage());
}
};
@Override
public void onUnrecoverableError(@NonNull Throwable throwable) {
handleDirectApiError(throwable.getMessage());
}
};

setupRecognizerRunner(jsonRecognizerCollection, mFirstSideRecognitionCallback);
setupRecognizerRunner(jsonRecognizerCollection, mFirstSideRecognitionCallback);

if (!arguments.getString(1).isEmpty() && !arguments.isNull(1)) {
processImage(arguments.getString(1), mScanResultListenerFrontSide);
} else {
handleDirectApiError("The provided image for the 'frontImage' parameter is empty!");
if (!arguments.getString(1).isEmpty() && !arguments.isNull(1)) {
processImage(arguments.getString(1), mScanResultListenerFrontSide);
} else {
handleDirectApiError("The provided image for the 'frontImage' parameter is empty!");
}
}
}

Expand Down Expand Up @@ -249,19 +251,30 @@ private void handleDirectApiError(String errorMessage) {
}
}

private void setLicense( JSONObject jsonLicense ) throws JSONException {
private boolean setLicense( JSONObject jsonLicense ) throws JSONException {
MicroblinkSDK.setShowTrialLicenseWarning(
jsonLicense.optBoolean("showTrialLicenseKeyWarning", true)
);
String androidLicense = jsonLicense.getString("android");
String licensee = jsonLicense.optString("licensee", null);
Context context = cordova.getContext();
if (licensee == null) {
MicroblinkSDK.setLicenseKey(androidLicense, context);
try {
MicroblinkSDK.setLicenseKey(androidLicense, context);
} catch (LicenceKeyException licenceKeyException) {
mCallbackContext.error("Android license key error: " + licenceKeyException.toString());
return false;
}
} else {
MicroblinkSDK.setLicenseKey(androidLicense, licensee, context);
try {
MicroblinkSDK.setLicenseKey(androidLicense, licensee, context);
} catch (LicenceKeyException licenceKeyException) {
mCallbackContext.error("Android license key error: " + licenceKeyException.toString());
return false;
}
}
MicroblinkSDK.setIntentDataTransferMode(IntentDataTransferMode.PERSISTED_OPTIMISED);
return true;
}

private Bitmap base64ToBitmap(String base64String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.microblink.blinkid.plugins.cordova.SerializationUtils;
import com.microblink.blinkid.plugins.cordova.overlays.OverlaySerializationUtils;
import com.microblink.blinkid.locale.LanguageUtils;
import com.microblink.blinkid.uisettings.CameraSettings;
import com.microblink.blinkid.hardware.camera.VideoResolutionPreset;

import org.json.JSONObject;

Expand Down Expand Up @@ -52,6 +54,15 @@ public UISettings createUISettings(Context context, JSONObject jsonUISettings, R
long backSideScanningTimeoutMilliseconds = jsonUISettings.optLong("backSideScanningTimeoutMilliseconds", 17000);
settings.setBackSideScanningTimeoutMs(backSideScanningTimeoutMilliseconds);

int videoResolutionPreset = jsonUISettings.optInt("androidCameraResolutionPreset", VideoResolutionPreset.VIDEO_RESOLUTION_DEFAULT.ordinal());

boolean androidLegacyCameraApi = jsonUISettings.optBoolean("enableAndroidLegacyCameraApi", false);

settings.setCameraSettings(new CameraSettings.Builder()
.setVideoResolutionPreset(VideoResolutionPreset.values()[videoResolutionPreset])
.setForceLegacyApi(androidLegacyCameraApi)
.build());

ReticleOverlayStrings.Builder overlasStringsBuilder = new ReticleOverlayStrings.Builder(context);

String firstSideInstructionsText = getStringFromJSONObject(jsonUISettings, "firstSideInstructionsText");
Expand Down Expand Up @@ -106,7 +117,14 @@ public UISettings createUISettings(Context context, JSONObject jsonUISettings, R
if (errorDocumentTooCloseToEdge != null) {
overlasStringsBuilder.setErrorDocumentTooCloseToEdge(errorDocumentTooCloseToEdge);
}

String errorBlurDetected = getStringFromJSONObject(jsonUISettings, "errorBlurDetected");
if (errorBlurDetected != null) {
overlasStringsBuilder.setErrorBlurDetected(errorBlurDetected);
}
String errorGlareDetected = getStringFromJSONObject(jsonUISettings, "errorGlareDetected");
if (errorGlareDetected != null) {
overlasStringsBuilder.setErrorGlareDetected(errorGlareDetected);
}
String language = getStringFromJSONObject(jsonUISettings, "language");
if (language != null) {
String country = getStringFromJSONObject(jsonUISettings, "country");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import com.microblink.blinkid.entities.recognizers.blinkid.generic.Side;
import com.microblink.blinkid.entities.recognizers.blinkid.generic.imageanalysis.CardRotation;
import com.microblink.blinkid.entities.recognizers.blinkid.generic.DocumentNumberAnonymizationSettings;
import com.microblink.blinkid.entities.recognizers.blinkid.generic.CustomClassRules;
import com.microblink.blinkid.entities.recognizers.blinkid.generic.DetailedFieldType;

import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -117,7 +119,6 @@ public static JSONObject serializeClassInfo(ClassInfo classInfo) throws JSONExce

public static JSONObject serializeImageAnalysisResult(ImageAnalysisResult imageAnalysisResult) throws JSONException {
JSONObject jsonImageAnalysis = new JSONObject();
jsonImageAnalysis.put("blurred", imageAnalysisResult.isBlurred());
jsonImageAnalysis.put("documentImageColorStatus", SerializationUtils.serializeEnum(imageAnalysisResult.getDocumentImageColorStatus()));
jsonImageAnalysis.put("documentImageMoireStatus", SerializationUtils.serializeEnum(imageAnalysisResult.getDocumentImageMoireStatus()));
jsonImageAnalysis.put("faceDetectionStatus", SerializationUtils.serializeEnum(imageAnalysisResult.getFaceDetectionStatus()));
Expand All @@ -126,6 +127,8 @@ public static JSONObject serializeImageAnalysisResult(ImageAnalysisResult imageA
jsonImageAnalysis.put("cardRotation", BlinkIDSerializationUtils.serializeCardRotation(imageAnalysisResult.getCardRotation()));
jsonImageAnalysis.put("cardOrientation", SerializationUtils.serializeEnum(imageAnalysisResult.getCardOrientation()));
jsonImageAnalysis.put("realIdDetectionStatus", SerializationUtils.serializeEnum(imageAnalysisResult.getRealIdDetectionStatus()));
jsonImageAnalysis.put("blurDetected", imageAnalysisResult.isBlurDetected());
jsonImageAnalysis.put("glareDetected", imageAnalysisResult.isGlareDetected());
return jsonImageAnalysis;
}

Expand Down Expand Up @@ -381,4 +384,53 @@ private static DocumentNumberAnonymizationSettings deserializeDocumentNumberAnon
return null;
}
}

public static CustomClassRules[] deserializeCustomClassRules(JSONArray jsonArray) {
if (jsonArray != null && jsonArray.length() > 0) {
CustomClassRules[] customClassRulesArray = new CustomClassRules[jsonArray.length()];

for (int i = 0; i < jsonArray.length(); i++) {

DetailedFieldType[] detailedFieldTypes = new DetailedFieldType[0];
Country country = Country.NONE;
Region region = Region.NONE;
Type type = Type.NONE;

try {
JSONObject jsonCustomClassRulesArray = jsonArray.getJSONObject(i);

JSONArray detailedFieldTypeJsonArray = jsonCustomClassRulesArray.optJSONArray("detailedFieldTypes");
detailedFieldTypes = new DetailedFieldType[detailedFieldTypeJsonArray.length()];
for (int x = 0; x < detailedFieldTypeJsonArray.length(); x++) {
FieldType fieldType = FieldType.values()[detailedFieldTypeJsonArray.getJSONObject(x).getInt("fieldType")];
AlphabetType alphabetType = AlphabetType.values()[detailedFieldTypeJsonArray.getJSONObject(x).getInt("alphabetType")];
detailedFieldTypes[x] = new DetailedFieldType(fieldType, alphabetType);
}
try {
country = Country.values()[jsonCustomClassRulesArray.getInt("country")];
} catch (JSONException e) {
country = null;
}
try {
region = Region.values()[jsonCustomClassRulesArray.getInt("region")];
} catch (JSONException e) {
region = null;
}
try {
type = Type.values()[jsonCustomClassRulesArray.getInt("type")];
} catch (JSONException e) {
type = null;
}

CustomClassRules customClassRules = new CustomClassRules(country, region, type, detailedFieldTypes);
customClassRulesArray[i] = customClassRules;
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
return customClassRulesArray;
} else {
return new CustomClassRules[]{};
}
}
}
Loading

0 comments on commit 7e5cfb2

Please sign in to comment.