Skip to content

Commit

Permalink
Merge pull request #70 from BlinkID/feature/v4.0.0
Browse files Browse the repository at this point in the history
Feature/v4.0.0
  • Loading branch information
DoDoENT authored Jun 20, 2018
2 parents a8afb23 + 909f29f commit 3e96941
Show file tree
Hide file tree
Showing 249 changed files with 22,807 additions and 4,849 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ BlinkIdDemo

# res
resources/signing

BlinkIdDevDemo
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": "1.5.6",
"version": "4.0.0",
"description": "A small and powerful ID card scanning library",
"cordova": {
"id": "com.microblink.blinkid",
Expand Down
250 changes: 237 additions & 13 deletions BlinkID/plugin.xml

Large diffs are not rendered by default.

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/v2.17.3/blinkid-ios_v2.17.3.zip'
LINK='https://github.com/BlinkID/blinkid-ios/releases/download/v4.0.0/blinkid-ios_v4.0.0.zip'
FILENAME='blinkid-ios.zip'

# check if Microblink framework and bundle already exist
Expand Down
1,220 changes: 0 additions & 1,220 deletions BlinkID/src/android/java/com/phonegap/plugins/blinkid/BlinkIdScanner.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.phonegap.plugins.blinkid;
package com.phonegap.plugins.microblink;

import android.app.Activity;
import android.content.Context;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/**
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
*
* Copyright (c) Matt Kane 2010
* Copyright (c) 2011, IBM Corporation
* Copyright (c) 2013, Maciej Nux Jaros
*/
package com.phonegap.plugins.microblink;

import android.app.Activity;
import android.content.Intent;

import com.microblink.MicroblinkSDK;
import com.microblink.intent.IntentDataTransferMode;
import com.microblink.entities.recognizers.RecognizerBundle;
import com.microblink.uisettings.UISettings;
import com.phonegap.plugins.microblink.overlays.OverlaySettingsSerializers;
import com.phonegap.plugins.microblink.recognizers.RecognizerSerializers;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class MicroblinkScanner extends CordovaPlugin {

private static final int REQUEST_CODE = 1337;

private static final String SCAN_WITH_CAMERA = "scanWithCamera";
private static final String CANCELLED = "cancelled";

private static final String RESULT_LIST = "resultList";

private CallbackContext mCallbackContext;
private RecognizerBundle mRecognizerBundle;

/**
* Constructor.
*/
public MicroblinkScanner() {
}

/**
* Executes the request.
*
* This method is called from the WebView thread. To do a non-trivial amount
* of work, use: cordova.getThreadPool().execute(runnable);
*
* To run on the UI thread, use:
* cordova.getActivity().runOnUiThread(runnable);
*
* @param action
* The action to execute.
* @param args
* The exec() arguments.
* @param callbackContext
* The callback context used when calling back into JavaScript.
* @return Whether the action was valid.
*
* @sa
* https://github.com/apache/cordova-android/blob/master/framework/src/org
* /apache/cordova/CordovaPlugin.java
*/
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
mCallbackContext = callbackContext;

try {
if (action.equals(SCAN_WITH_CAMERA)) {
JSONObject jsonOverlaySettings = args.getJSONObject(0);
JSONObject jsonRecognizerCollection = args.getJSONObject(1);
JSONObject jsonLicenses = args.getJSONObject(2);

setLicense(jsonLicenses);
mRecognizerBundle = RecognizerSerializers.INSTANCE.deserializeRecognizerCollection(jsonRecognizerCollection);
UISettings overlaySettings = OverlaySettingsSerializers.INSTANCE.getOverlaySettings(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);
} else {
return false;
}
return true;
} catch (JSONException e) {
mCallbackContext.error("JSON error: " + e.getMessage());
return false;
}
}

private void setLicense( JSONObject jsonLicense ) throws JSONException {
String androidLicense = jsonLicense.getString("android");
MicroblinkSDK.setLicenseKey(androidLicense, this.cordova.getContext());
MicroblinkSDK.setIntentDataTransferMode(IntentDataTransferMode.PERSISTED_OPTIMISED);
}

/**
* Called when the scanner intent completes.
*
* @param requestCode
* The request code originally supplied to
* startActivityForResult(), allowing you to identify who this
* result came from.
* @param resultCode
* The integer result code returned by the child activity through
* its setResult().
* @param data
* An Intent, which can return result data to the caller (various
* data can be attached to Intent "extras").
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

if (requestCode == REQUEST_CODE) {

if (resultCode == Activity.RESULT_OK) {
// load bundle
mRecognizerBundle.loadFromIntent(data);

JSONObject result = new JSONObject();
try {
result.put(CANCELLED, false);

JSONArray resultList = RecognizerSerializers.INSTANCE.serializeRecognizerResults(mRecognizerBundle.getRecognizers());
result.put(RESULT_LIST, resultList);
} catch(JSONException e) {
throw new RuntimeException(e);
}

mCallbackContext.success(result);

} else if (resultCode == Activity.RESULT_CANCELED) {
JSONObject obj = new JSONObject();
try {
obj.put(CANCELLED, true);
} catch (JSONException e) {
throw new RuntimeException(e);
}
mCallbackContext.success(obj);

} else {
mCallbackContext.error("Unexpected error");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.phonegap.plugins.blinkid;
package com.phonegap.plugins.microblink;

enum RecognizerType {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.phonegap.plugins.microblink.overlays;

import com.microblink.entities.recognizers.RecognizerBundle;
import com.microblink.uisettings.UISettings;

import org.json.JSONObject;

public interface OverlaySettingsSerialization {

UISettings createUISettings(JSONObject jsonUISettings, RecognizerBundle recognizerBundle);

String getJsonName();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.phonegap.plugins.microblink.overlays;


import com.microblink.entities.recognizers.RecognizerBundle;
import com.microblink.uisettings.UISettings;
import com.phonegap.plugins.microblink.overlays.serialization.*;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

public enum OverlaySettingsSerializers {
INSTANCE;

private HashMap<String, OverlaySettingsSerialization> mByJSONName = new HashMap<>();

private void registerMapping(OverlaySettingsSerialization overlaySettingsSerialization) {
mByJSONName.put(overlaySettingsSerialization.getJsonName(), overlaySettingsSerialization);
}

OverlaySettingsSerializers() {
registerMapping(new BarcodeOverlaySettingsSerialization());
registerMapping(new DocumentOverlaySettingsSerialization());
registerMapping(new DocumentVerificationOverlaySettingsSerialization());
}

public UISettings getOverlaySettings(JSONObject jsonOverlaySettings, RecognizerBundle recognizerBundle) {
try {
return mByJSONName.get(jsonOverlaySettings.getString("overlaySettingsType")).createUISettings(jsonOverlaySettings, recognizerBundle);
} catch (JSONException e) {
throw new RuntimeException(e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.phonegap.plugins.microblink.overlays.serialization;

import com.microblink.entities.recognizers.RecognizerBundle;
import com.microblink.uisettings.BarcodeUISettings;
import com.microblink.uisettings.UISettings;
import com.phonegap.plugins.microblink.overlays.OverlaySettingsSerialization;

import org.json.JSONObject;

public final class BarcodeOverlaySettingsSerialization implements OverlaySettingsSerialization {
@Override
public UISettings createUISettings(JSONObject jsonUISettings, RecognizerBundle recognizerBundle) {
// no settings deserialized at the moment
return new BarcodeUISettings(recognizerBundle);
}

@Override
public String getJsonName() {
return "BarcodeOverlaySettings";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.phonegap.plugins.microblink.overlays.serialization;

import com.microblink.entities.recognizers.RecognizerBundle;;
import com.microblink.uisettings.DocumentUISettings;
import com.microblink.uisettings.UISettings;
import com.phonegap.plugins.microblink.overlays.OverlaySettingsSerialization;

import org.json.JSONObject;

public final class DocumentOverlaySettingsSerialization implements OverlaySettingsSerialization {
@Override
public UISettings createUISettings(JSONObject jsonUISettings, RecognizerBundle recognizerBundle) {
// no settings deserialized at the moment
return new DocumentUISettings(recognizerBundle);
}

@Override
public String getJsonName() {
return "DocumentOverlaySettings";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.phonegap.plugins.microblink.overlays.serialization;

import com.microblink.entities.recognizers.RecognizerBundle;
import com.microblink.uisettings.DocumentVerificationUISettings;
import com.microblink.uisettings.UISettings;
import com.phonegap.plugins.microblink.overlays.OverlaySettingsSerialization;

import org.json.JSONObject;

public final class DocumentVerificationOverlaySettingsSerialization implements OverlaySettingsSerialization {
@Override
public UISettings createUISettings(JSONObject jsonUISettings, RecognizerBundle recognizerBundle) {
return new DocumentVerificationUISettings(recognizerBundle);
}

@Override
public String getJsonName() {
return "DocumentVerificationOverlaySettings";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.phonegap.plugins.microblink.recognizers;

import com.microblink.entities.recognizers.Recognizer;

import org.json.JSONObject;

public interface RecognizerSerialization {
Recognizer<?, ?> createRecognizer(JSONObject jsonRecognizer);
JSONObject serializeResult(Recognizer<?, ?> recognizer);

String getJsonName();
Class<?> getRecognizerClass();
}
Loading

0 comments on commit 3e96941

Please sign in to comment.