Skip to content

Commit

Permalink
3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins committed Jul 29, 2021
1 parent 911fb49 commit 7217870
Show file tree
Hide file tree
Showing 85 changed files with 3,242 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
.dart_tool/

.packages
.pub/

build/
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 3.0.0
Flutter plugin that provides a solution for biometric verification by leveraging the power of Regula Face SDK Web Service. Biometric verification is the quickest and most reliable way to confirm any user’s identity and protect your business and your clients from fraud.

Features included:
* Face Matching: Check the likelihood that two faces belong to the same person.
* Face Recognition: Automatically capture a photo with a person's face on it.
* Liveness Detection: Find out if the person on camera is alive.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Regula Forensics

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
# flutter_face_api
# Regula Face API (Flutter version)
Face API is a framework that is used for face matching, recognition and liveness detection.

# Contents
* [How to build the demo application](#how-to-build-the-demo-application)
* [Documentation](#documentation)
* [Additional information](#additional-information)

## How to build the demo application
1. Download or the clone current repository using the command `git clone https://github.com/regulaforensics/flutter_face_api.git.git`.
2. Run the following commands within the root directory:
```bash
$ cd example
# Install packages
$ flutter pub get
# Check that supported devices are running
$ flutter devices
# Run the app
$ flutter run
```

## Documentation
You can find documentation on API [here](https://docs.regulaforensics.com/flutter-face).

## Additional information
If you have any technical questions, feel free to [contact](mailto:support@regulaforensics.com) us or create issues [here](https://github.com/regulaforensics/flutter_face_api/issues).
7 changes: 7 additions & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.iml
.gradle
/local.properties
.DS_Store
/build
/captures
/.idea
52 changes: 52 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
group 'io.flutter.plugins.regula.faceapi.flutter_face_api'
version '1.0'

buildscript {
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
}
}

rootProject.allprojects {
repositories {
google()
jcenter()
maven {
url "http://maven.regulaforensics.com/RegulaDocumentReader"
allowInsecureProtocol true
}
maven {
url "http://maven.regulaforensics.com/RegulaDocumentReader/Beta"
allowInsecureProtocol true
}
}
}

apply plugin: 'com.android.library'

android {
compileSdkVersion 28

defaultConfig {
minSdkVersion 18
}
lintOptions {
disable 'InvalidPackage'
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}

dependencies {
//noinspection GradleDependency
implementation('com.regula.face:api:3.0.1234'){
transitive = true
}
}
4 changes: 4 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
5 changes: 5 additions & 0 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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
1 change: 1 addition & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'flutter_face_api'
3 changes: 3 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.flutter.plugins.regula.faceapi.flutter_face_api">
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
package io.flutter.plugins.regula.faceapi.flutter_face_api;

import android.content.Context;

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

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import com.regula.facesdk.configuration.FaceCaptureConfiguration;
import com.regula.facesdk.configuration.LivenessConfiguration;

import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;

import static com.regula.facesdk.FaceSDK.Instance;

@SuppressWarnings({"unchecked", "NullableProblems", "ConstantConditions", "RedundantSuppression"})
public class FlutterFaceApiPlugin implements FlutterPlugin, MethodChannel.MethodCallHandler {
private ArrayList<Object> args;
private Context context;

public FlutterFaceApiPlugin() {
}

private Context getContext() {
return context;
}

@Override
public void onAttachedToEngine(FlutterPluginBinding flutterPluginBinding) {
context = flutterPluginBinding.getApplicationContext();
new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "flutter_face_api/method").setMethodCallHandler(this);
}

@Override
public void onDetachedFromEngine(FlutterPluginBinding binding) {
}

@SuppressWarnings("unused")
private interface Callback {
void success(Object o);

void error(String s);

default void success() {
success("");
}
}

private JSONArray arrayListToJSONArray(ArrayList<?> list) {
JSONArray result = new JSONArray();
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getClass().equals(java.util.HashMap.class))
result.put(hashMapToJSONObject((HashMap<String, ?>) list.get(i)));
else if (list.get(i).getClass().equals(java.util.ArrayList.class))
result.put(arrayListToJSONArray((ArrayList<?>) list.get(i)));
else
result.put(list.get(i));
}

return result;
}

private JSONObject hashMapToJSONObject(HashMap<String, ?> map) {
JSONObject result = new JSONObject();
try {
for (Map.Entry<String, ?> entry : map.entrySet()) {
if (entry.getValue().getClass().equals(java.util.HashMap.class))
result.put(entry.getKey(), hashMapToJSONObject((HashMap<String, ?>) entry.getValue()));
else if (entry.getValue().getClass().equals(java.util.ArrayList.class))
result.put(entry.getKey(), arrayListToJSONArray((ArrayList<?>) entry.getValue()));
else
result.put(entry.getKey(), entry.getValue());
}
} catch (JSONException e) {
e.printStackTrace();
}
return result;
}

private <T> T args(@SuppressWarnings("SameParameterValue") int index) {
if (args.get(index).getClass().equals(java.util.HashMap.class))
return (T) hashMapToJSONObject((HashMap<String, ?>) args.get(index));
if (args.get(index).getClass().equals(java.util.ArrayList.class))
return (T) arrayListToJSONArray((ArrayList<?>) args.get(index));
return (T) args.get(index);
}

@Override
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
String action = call.method;
args = (ArrayList<Object>) call.arguments;
Callback callback = new Callback() {
@Override
public void success(Object o) {
result.success(o);
}

@Override
public void error(String s) {
result.error("", s, null);
}
};

try {
switch (action) {
case "getServiceUrl":
getServiceUrl(callback);
break;
case "startLiveness":
startLiveness(callback);
break;
case "getFaceSdkVersion":
getFaceSdkVersion(callback);
break;
case "presentFaceCaptureActivity":
presentFaceCaptureActivity(callback);
break;
case "stopFaceCaptureActivity":
stopFaceCaptureActivity(callback);
break;
case "stopLivenessProcessing":
stopLivenessProcessing(callback);
break;
case "presentFaceCaptureActivityByCameraId":
presentFaceCaptureActivityByCameraId(callback, args(0));
break;
case "startLivenessByCameraId":
startLivenessByCameraId(callback, args(0));
break;
case "setServiceUrl":
setServiceUrl(callback, args(0));
break;
case "matchFaces":
matchFaces(callback, args(0));
break;
}
} catch (Exception ignored) {
}
}

private void getServiceUrl(Callback callback) {
callback.success(Instance().getServiceUrl());
}

private void startLiveness(Callback callback) {
Instance().startLiveness(getContext(), (response) -> callback.success(JSONConstructor.generateLivenessResponse(response).toString()));
}

private void getFaceSdkVersion(Callback callback) {
callback.success(Instance().getFaceSdkVersion());
}

private void presentFaceCaptureActivity(Callback callback) {
Instance().presentFaceCaptureActivity(getContext(), (response) -> callback.success(JSONConstructor.generateFaceCaptureResponse(response).toString()));
}

private void stopFaceCaptureActivity(Callback callback) {
Instance().stopFaceCaptureActivity(getContext());
callback.success();
}

private void stopLivenessProcessing(Callback callback) {
Instance().stopLivenessProcessing(getContext());
callback.success();
}

private void presentFaceCaptureActivityByCameraId(Callback callback, int cameraID) {
Instance().presentFaceCaptureActivity(getContext(), new FaceCaptureConfiguration.Builder().setCameraId(cameraID).build(), (response) -> callback.success(JSONConstructor.generateFaceCaptureResponse(response).toString()));
}

private void startLivenessByCameraId(Callback callback, int cameraID) {
Instance().startLiveness(getContext(), new LivenessConfiguration.Builder().setCameraId(cameraID).build(), (response) -> callback.success(JSONConstructor.generateLivenessResponse(response).toString()));
}

private void setServiceUrl(Callback callback, String url) {
Instance().setServiceUrl(url);
callback.success();
}

private void matchFaces(Callback callback, String request) throws JSONException {
Instance().matchFaces(JSONConstructor.MatchFacesRequestFromJSON(new JSONObject(request)), (response) -> callback.success(JSONConstructor.generateMatchFacesResponse(response).toString()));
}
}
Loading

0 comments on commit 7217870

Please sign in to comment.