diff --git a/example/RNExampleApp/android/.project b/example/RNExampleApp/android/.project
index 11d1f9d6..33b4feb8 100644
--- a/example/RNExampleApp/android/.project
+++ b/example/RNExampleApp/android/.project
@@ -16,12 +16,12 @@
- 1644311700747
+ 1669021212230
30
org.eclipse.core.resources.regexFilterMatcher
- node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__
+ node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__
diff --git a/example/RNExampleApp/android/app/.project b/example/RNExampleApp/android/app/.project
index fcbad646..7a185896 100644
--- a/example/RNExampleApp/android/app/.project
+++ b/example/RNExampleApp/android/app/.project
@@ -22,12 +22,12 @@
- 1644311700752
+ 1669021212234
30
org.eclipse.core.resources.regexFilterMatcher
- node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__
+ node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__
diff --git a/example/RNExampleApp/android/app/build.gradle b/example/RNExampleApp/android/app/build.gradle
index eb8fea7c..eb661ba0 100644
--- a/example/RNExampleApp/android/app/build.gradle
+++ b/example/RNExampleApp/android/app/build.gradle
@@ -160,8 +160,6 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
-
-
}
@@ -177,13 +175,19 @@ dependencies {
else { implementation jscFlavor }
implementation project(':anyline-ocr-react-native-module')
implementation fileTree(dir: "libs", include: ["*.jar"])
- implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
+ implementation 'androidx.appcompat:appcompat:1.2.0'
implementation "com.facebook.react:react-native:+" // From node_modules
implementation 'androidx.multidex:multidex:2.0.1'
}
+configurations.all {
+ resolutionStrategy {
+ force 'androidx.core:core:1.5.0'
+ }
+}
+
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
diff --git a/example/RNExampleApp/android/build.gradle b/example/RNExampleApp/android/build.gradle
index d14daf00..410d91a9 100644
--- a/example/RNExampleApp/android/build.gradle
+++ b/example/RNExampleApp/android/build.gradle
@@ -2,11 +2,10 @@
buildscript {
ext {
- buildToolsVersion = "29.0.3"
+ buildToolsVersion = "33.0.0"
minSdkVersion = 21
- compileSdkVersion = 29
- targetSdkVersion = 29
- supportLibVersion = "28.0.0"
+ compileSdkVersion = 31
+ targetSdkVersion = 31
ndkVersion = "20.1.5948944"
}
repositories {
diff --git a/example/RNExampleApp/android/gradle/wrapper/gradle-wrapper.properties b/example/RNExampleApp/android/gradle/wrapper/gradle-wrapper.properties
index 3c9d0852..cb24abda 100644
--- a/example/RNExampleApp/android/gradle/wrapper/gradle-wrapper.properties
+++ b/example/RNExampleApp/android/gradle/wrapper/gradle-wrapper.properties
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
diff --git a/example/RNExampleApp/package.json b/example/RNExampleApp/package.json
index e42edc2f..42ad6a51 100644
--- a/example/RNExampleApp/package.json
+++ b/example/RNExampleApp/package.json
@@ -4,8 +4,8 @@
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
- "reinstall": "yarn remove anyline-ocr-react-native-module && yarn add ../../plugin && react-native link",
- "reinstall-pods": "cd ios/ && rm -rf Pods Podfile.lock && pod update --verbose && cd .. && react-native link",
+ "reinstall": "yarn remove anyline-ocr-react-native-module && yarn add ../../plugin && yarn react-native link",
+ "reinstall-pods": "cd ios/ && rm -rf Pods Podfile.lock && pod update --verbose && cd .. && yarn react-native link",
"test": "jest",
"bundleAndroid": "react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/",
"bundleiOS": "react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios"
@@ -16,7 +16,7 @@
"hermes-engine": "^0.7.2",
"jsc-android": "^241213.1.0",
"react": "17.0.2",
- "react-native": "0.67.2"
+ "react-native": "0.67.5"
},
"devDependencies": {
"@babel/core": "^7.12.9",
diff --git a/example/RNExampleApp/src/Result.js b/example/RNExampleApp/src/Result.js
index e1fedf8b..ece3c549 100755
--- a/example/RNExampleApp/src/Result.js
+++ b/example/RNExampleApp/src/Result.js
@@ -1,4 +1,7 @@
-import React from 'react';
+import React, {
+ Component,
+ useState
+} from 'react';
import {
Button,
Image,
@@ -7,9 +10,12 @@ import {
Text,
View,
Dimensions,
+ Platform,
TouchableWithoutFeedback,
+ TextInput,
} from 'react-native';
import {flattenObject} from './utils/utils';
+import AnylineOCR from 'anyline-ocr-react-native-module';
const withoutImagePaths = value =>
value !== 'imagePath' && value !== 'fullImagePath';
@@ -23,6 +29,66 @@ export default function Result({
hasBackButton,
title = false,
}) {
+
+ const [correctedResult, setCorrectedResult] = useState('');
+ const [responseText, setResponseText] = useState('');
+
+ let onReportCorrectedResultResponseHandler = function(response) {
+ /*
+ The response is a string with the following style if it's an error:
+ {
+ "code": ,
+ "message": {
+ "code": ,
+ "timestamp": ,
+ "path": ,
+ "method": ,
+ "message":
+ }
+ }
+
+ If the response is successful it looks like this:
+ {
+ "code" : 201,
+ "message" : {
+ "message": "ok"
+ }
+ }
+ */
+ var parsedResponse = JSON.parse(response);
+ if(parsedResponse["code"] === 201){
+ setResponseText("Sending corrected result was successful.");
+ } else {
+ setResponseText("Error while sending corrected result: " + parsedResponse["message"]);
+ }
+ }
+
+ let onReportCorrectedResultPressed = function() {
+ let blobKey = result["blobKey"];
+
+ if(typeof blobKey === 'undefined' || blobKey === '' || blobKey === null){
+ setResponseText("Only licenses with 'debugReporting' set to 'on' allow user corrected results.");
+ } else if(correctedResult !== "") {
+ setResponseText("Waiting for response...");
+ AnylineOCR.reportCorrectedResult(result["blobKey"], correctedResult, onReportCorrectedResultResponseHandler);
+ }
+ };
+
+ let reportCorrectedResultButton = (
+
+ setCorrectedResult(newCorrectedResult) }
+ />
+
+ {responseText}
+
+ );
+
let fullImage = ;
let fullImageText = ;
if (fullImagePath && fullImagePath !== '') {
@@ -90,6 +156,7 @@ export default function Result({
);
})}
+ { Platform.OS === 'android' && reportCorrectedResultButton }
{BackButton}
@@ -163,6 +230,14 @@ const styles = StyleSheet.create({
alignSelf: 'center',
},
+ reportCorrectedResultButtonStyle: {
+ marginTop: 25,
+ width: Dimensions.get('window').width,
+ alignSelf: 'center',
+ paddingLeft: 24,
+ paddingRight: 24
+ },
+
titleText: {
color: '#0099FF',
fontSize: 20
diff --git a/plugin/android/build.gradle b/plugin/android/build.gradle
index 07049689..4f7c88ec 100755
--- a/plugin/android/build.gradle
+++ b/plugin/android/build.gradle
@@ -19,11 +19,11 @@ allprojects {
android {
- compileSdkVersion 28
+ compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
- minSdkVersion 21
- targetSdkVersion 28
+ minSdkVersion rootProject.ext.minSdkVersion
+ targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
ndk {
diff --git a/plugin/android/src/main/java/com/anyline/reactnative/Anyline4Activity.java b/plugin/android/src/main/java/com/anyline/reactnative/Anyline4Activity.java
index 971dd05f..369ba348 100644
--- a/plugin/android/src/main/java/com/anyline/reactnative/Anyline4Activity.java
+++ b/plugin/android/src/main/java/com/anyline/reactnative/Anyline4Activity.java
@@ -51,7 +51,6 @@
import io.anyline.plugin.ocr.OcrScanResult;
import io.anyline.plugin.ocr.OcrScanViewPlugin;
import io.anyline.plugin.tire.TireScanResult;
-import io.anyline.plugin.tire.TireScanPlugin;
import io.anyline.plugin.tire.TireScanViewPlugin;
import io.anyline.view.AbstractBaseScanViewPlugin;
import io.anyline.view.CutoutRect;
@@ -62,7 +61,7 @@
public class Anyline4Activity extends AnylineBaseActivity {
private static final String TAG = Anyline4Activity.class.getSimpleName();
-
+ private static final String KEY_DEFAULT_ORIENTATION_APPLIED = "default_orientation_applied";
private ScanView anylineScanView;
private AbstractBaseScanViewPlugin scanViewPlugin;
private RadioGroup radioGroup;
@@ -71,7 +70,6 @@ public class Anyline4Activity extends AnylineBaseActivity {
private Boolean isFirstCameraOpen; // only if camera is opened the first time get coordinates of the cutout to avoid flickering when switching between analog and digital
private RelativeLayout parentLayout;
private boolean defaultOrientationApplied;
- private static final String KEY_DEFAULT_ORIENTATION_APPLIED = "default_orientation_applied";
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -241,8 +239,8 @@ public void onResult(ScanResult result) {
} else if (subResult instanceof BarcodeScanResult) {
try {
jsonResult.put(
- subResult.getPluginId(),
- extractBarcodeResult(jsonResult, subResult)
+ subResult.getPluginId(),
+ extractBarcodeResult(jsonResult, subResult)
);
} catch (Exception e) {
Log.e(TAG, "EXCEPTION", e);
@@ -264,23 +262,19 @@ public void onResult(ScanResult result) {
}
});
} else if (scanViewPlugin instanceof LicensePlateScanViewPlugin) {
- scanViewPlugin.addScanResultListener(new ScanResultListener() {
- @Override
- public void onResult(LicensePlateScanResult licensePlateResult) {
- JSONObject jsonResult = new JSONObject();
- try {
- jsonResult.put("country", licensePlateResult.getCountry());
- jsonResult.put("licensePlate", licensePlateResult.getResult());
-
- jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, licensePlateResult,
- jsonResult);
- } catch (JSONException e) {
- e.printStackTrace();
- }
-
- setResult(scanViewPlugin, jsonResult);
+ scanViewPlugin.addScanResultListener((ScanResultListener) licensePlateResult -> {
+ JSONObject jsonResult = new JSONObject();
+ try {
+ jsonResult.put("country", licensePlateResult.getCountry());
+ jsonResult.put("licensePlate", licensePlateResult.getResult());
+
+ jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, licensePlateResult,
+ jsonResult);
+ } catch (JSONException e) {
+ e.printStackTrace();
}
+ setResult(scanViewPlugin, jsonResult);
});
} else if (scanViewPlugin instanceof IdScanViewPlugin) {
if (((IdScanPlugin) ((IdScanViewPlugin) scanViewPlugin).getScanPlugin()).getIdConfig() instanceof MrzConfig) {
@@ -290,90 +284,75 @@ public void onResult(LicensePlateScanResult licensePlateResult) {
cropAndTransformError = json.getString("cropAndTransformErrorMessage");
}
- scanViewPlugin.addScanResultListener(new ScanResultListener>() {
- @Override
- public void onResult(ScanResult idScanResult) {
- JSONObject jsonResult = ((MrzIdentification) idScanResult.getResult()).toJSONObject();
- try {
- if (jsonResult.get("issuingCountryCode").equals("D")
- && jsonResult.get("documentType").equals("ID")) {
- if (jsonResult.get("issuingCountryCode").equals("D")) {
- jsonResult.put("address", jsonResult.get("address"));
- } else {
- jsonResult.remove("address");
- }
-
+ scanViewPlugin.addScanResultListener((ScanResultListener>) idScanResult -> {
+ JSONObject jsonResult = ((MrzIdentification) idScanResult.getResult()).toJSONObject();
+ try {
+ if (jsonResult.get("issuingCountryCode").equals("D")
+ && jsonResult.get("documentType").equals("ID")) {
+ if (jsonResult.get("issuingCountryCode").equals("D")) {
+ jsonResult.put("address", jsonResult.get("address"));
+ } else {
+ jsonResult.remove("address");
}
- } catch (JSONException e) {
- e.printStackTrace();
- }
-
- try {
- jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, idScanResult,
- jsonResult);
- } catch (Exception e) {
- Log.e(TAG, "Exception is: ", e);
}
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
- setResult(scanViewPlugin, jsonResult);
+ try {
+ jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, idScanResult,
+ jsonResult);
+ } catch (Exception e) {
+ Log.e(TAG, "Exception is: ", e);
}
+ setResult(scanViewPlugin, jsonResult);
+
});
} else if (((IdScanPlugin) ((IdScanViewPlugin) scanViewPlugin).getScanPlugin()).getIdConfig() instanceof UniversalIdConfig) {
- scanViewPlugin.addScanResultListener(new ScanResultListener>() {
- @Override
- public void onResult(ScanResult idScanResult) {
- Identification identification = (Identification) idScanResult.getResult();
- HashMap data = (HashMap) identification.getResultData();
+ scanViewPlugin.addScanResultListener((ScanResultListener>) idScanResult -> {
+ Identification identification = (Identification) idScanResult.getResult();
+ HashMap data = (HashMap) identification.getResultData();
- JSONObject jsonResult = new JSONObject(data);
+ JSONObject jsonResult = new JSONObject(data);
- try {
- jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, idScanResult,
- jsonResult);
- } catch (Exception e) {
- Log.e(TAG, "Exception is: ", e);
+ try {
+ jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, idScanResult,
+ jsonResult);
+ } catch (Exception e) {
+ Log.e(TAG, "Exception is: ", e);
- }
- setResult(scanViewPlugin, jsonResult);
}
+ setResult(scanViewPlugin, jsonResult);
});
}
} else if (scanViewPlugin instanceof OcrScanViewPlugin) {
- scanViewPlugin.addScanResultListener(new ScanResultListener() {
- @Override
- public void onResult(OcrScanResult ocrScanResult) {
- JSONObject jsonResult = new JSONObject();
- try {
- jsonResult.put("text", ocrScanResult.getResult().trim());
- jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, ocrScanResult,
- jsonResult);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- setResult(scanViewPlugin, jsonResult);
-
+ scanViewPlugin.addScanResultListener((ScanResultListener) ocrScanResult -> {
+ JSONObject jsonResult = new JSONObject();
+ try {
+ jsonResult.put("text", ocrScanResult.getResult().trim());
+ jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, ocrScanResult,
+ jsonResult);
+ } catch (JSONException e) {
+ e.printStackTrace();
}
+ setResult(scanViewPlugin, jsonResult);
});
} else if (scanViewPlugin instanceof TireScanViewPlugin) {
- scanViewPlugin.addScanResultListener(new ScanResultListener() {
- @Override
- public void onResult(TireScanResult tireScanResult) {
- JSONObject jsonResult = new JSONObject();
- try {
- jsonResult.put("text", tireScanResult.getResult().trim());
- jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, tireScanResult,
- jsonResult);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- setResult(scanViewPlugin, jsonResult);
-
+ scanViewPlugin.addScanResultListener((ScanResultListener) tireScanResult -> {
+ JSONObject jsonResult = new JSONObject();
+ try {
+ jsonResult.put("text", tireScanResult.getResult().trim());
+ jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, tireScanResult,
+ jsonResult);
+ } catch (JSONException e) {
+ e.printStackTrace();
}
+ setResult(scanViewPlugin, jsonResult);
});
@@ -423,24 +402,21 @@ public void onResult(BarcodeScanResult barcodeScanResult) {
addSegmentRadioButtonUI(json);
anylineScanView.setCameraOpenListener(this);
- scanViewPlugin.addScanResultListener(new ScanResultListener() {
- @Override
- public void onResult(MeterScanResult meterScanResult) {
- JSONObject jsonResult = new JSONObject();
- try {
- jsonResult = AnylinePluginHelper.setMeterScanMode(meterScanResult.getScanMode(),
- jsonResult);
- jsonResult.put("reading", meterScanResult.getResult());
-
- jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, meterScanResult,
- jsonResult);
-
- } catch (Exception e) {
- Log.e(TAG, "EXCEPTION", e);
- }
-
- setResult(scanViewPlugin, jsonResult);
+ scanViewPlugin.addScanResultListener((ScanResultListener) meterScanResult -> {
+ JSONObject jsonResult = new JSONObject();
+ try {
+ jsonResult = AnylinePluginHelper.setMeterScanMode(meterScanResult.getScanMode(),
+ jsonResult);
+ jsonResult.put("reading", meterScanResult.getResult());
+
+ jsonResult = AnylinePluginHelper.jsonHelper(Anyline4Activity.this, meterScanResult,
+ jsonResult);
+
+ } catch (Exception e) {
+ Log.e(TAG, "EXCEPTION", e);
}
+
+ setResult(scanViewPlugin, jsonResult);
});
}
diff --git a/plugin/android/src/main/java/com/anyline/reactnative/AnylinePluginHelper.java b/plugin/android/src/main/java/com/anyline/reactnative/AnylinePluginHelper.java
index 818bcdd8..11ffe535 100644
--- a/plugin/android/src/main/java/com/anyline/reactnative/AnylinePluginHelper.java
+++ b/plugin/android/src/main/java/com/anyline/reactnative/AnylinePluginHelper.java
@@ -144,6 +144,10 @@ public static JSONObject jsonHelper(Anyline4Activity activity, ScanResult> sca
scanResult.getCutoutImage().save(imageFile, 90);
jsonObject.put("imagePath", imageFile.getAbsolutePath());
+ if (scanResult.getBlobKey() != null) {
+ jsonObject.put("blobKey", scanResult.getBlobKey());
+ }
+
File imageFileFull = TempFileUtil.createTempFileCheckCache(activity, UUID.randomUUID().toString(), ".jpg");
scanResult.getFullImage().save(imageFileFull, 90);
jsonObject.put("fullImagePath", imageFileFull.getAbsolutePath());
@@ -185,6 +189,10 @@ public static JSONObject wrapBarcodeInJson(Barcode b) {
return json;
}
+ private static List getNativeBarcodeList() {
+ return finalBarcodeList;
+ }
+
private static void setNativeBarcodeList(List barcodes) {
final List barcodeList = new ArrayList<>();
final List barcodesDisplayedVal = new ArrayList<>();
@@ -208,10 +216,6 @@ private static void setNativeBarcodeList(List barcodes) {
}
- private static List getNativeBarcodeList() {
- return finalBarcodeList;
- }
-
private static String findValidFormatForReference(int format) {
if (format == Barcode.FORMAT_AZTEC) {
return BarcodeFormat.AZTEC.toString();
diff --git a/plugin/android/src/main/java/com/anyline/reactnative/AnylineSDKPlugin.java b/plugin/android/src/main/java/com/anyline/reactnative/AnylineSDKPlugin.java
index 6bafb574..67a8ae08 100755
--- a/plugin/android/src/main/java/com/anyline/reactnative/AnylineSDKPlugin.java
+++ b/plugin/android/src/main/java/com/anyline/reactnative/AnylineSDKPlugin.java
@@ -21,9 +21,11 @@
import at.nineyards.anyline.core.LicenseException;
import io.anyline.AnylineSDK;
+import io.anyline.plugin.ScanResult;
import io.anyline.products.AnylineUpdater;
import io.anyline.products.IAnylineUpdateDelegate;
import io.anyline.trainer.AssetContext;
+import io.anyline.trainer.TrainerUtils;
class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultReporter.OnResultListener {
@@ -38,9 +40,6 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
public static final int RESULT_CANCELED = 0;
public static final int RESULT_OK = 1;
public static final int RESULT_ERROR = 2;
-
- private static final String E_ERROR = "E_ERROR";
-
public static final int DIGITAL_METER = 3;
public static final int ANALOG_METER = 4;
public static final int AUTO_ANALOG_DIGITAL_METER = 5;
@@ -53,7 +52,7 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
public static final int SERIAL_NUMBER = 12;
public static final int DOT_MATRIX_METER = 13;
public static final int REQUEST_ANYLINE_4 = 14;
-
+ private static final String E_ERROR = "E_ERROR";
private JSONObject configObject;
private ReactApplicationContext reactContext;
private String license;
@@ -152,6 +151,23 @@ public void setup(String config, String scanMode, Callback onResultReact, Callba
routeScanMode(scanMode);
}
+ @ReactMethod
+ public void reportCorrectedResult(String blobKey, String correctedResult, Callback onResponseCallback) {
+ ScanResult.reportCorrectedResult(
+ this.reactContext,
+ blobKey,
+ correctedResult,
+ "",
+ new TrainerUtils.ReportCorrectedResultHandler() {
+
+ @Override
+ public void onReportCorrectedResult(String s) {
+ onResponseCallback.invoke(s);
+ }
+ }
+ );
+ }
+
@ReactMethod
public void setupPromise(String config, String scanMode, final Promise promise) {
this.promise = promise;