-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from BlinkID/feature/v4.0.0
Feature/v4.0.0
- Loading branch information
Showing
249 changed files
with
22,807 additions
and
4,849 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ BlinkIdDemo | |
|
||
# res | ||
resources/signing | ||
|
||
BlinkIdDevDemo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,220 changes: 0 additions & 1,220 deletions
1,220
BlinkID/src/android/java/com/phonegap/plugins/blinkid/BlinkIdScanner.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...a/com/phonegap/plugins/blinkid/FakeR.java → ...om/phonegap/plugins/microblink/FakeR.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
BlinkID/src/android/java/com/phonegap/plugins/microblink/MicroblinkScanner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...negap/plugins/blinkid/RecognizerType.java → ...ap/plugins/microblink/RecognizerType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
|
13 changes: 13 additions & 0 deletions
13
...c/android/java/com/phonegap/plugins/microblink/overlays/OverlaySettingsSerialization.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
36 changes: 36 additions & 0 deletions
36
...src/android/java/com/phonegap/plugins/microblink/overlays/OverlaySettingsSerializers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...onegap/plugins/microblink/overlays/serialization/BarcodeOverlaySettingsSerialization.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...negap/plugins/microblink/overlays/serialization/DocumentOverlaySettingsSerialization.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...s/microblink/overlays/serialization/DocumentVerificationOverlaySettingsSerialization.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...src/android/java/com/phonegap/plugins/microblink/recognizers/RecognizerSerialization.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
Oops, something went wrong.