anyline-ocr-react-native-module 42.0.0 → 43.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +10 -6
- package/android/src/main/AndroidManifest.xml +9 -8
- package/android/src/main/assets/cow_tag_scanner.ale +46 -0
- package/android/src/main/java/com/anyline/reactnative/AnylinePackage.java +1 -2
- package/android/src/main/java/com/anyline/reactnative/AnylineSDKPlugin.java +44 -74
- package/android/src/main/java/com/anyline/reactnative/RotateButtonConfig.java +12 -2
- package/android/src/main/java/com/anyline/reactnative/ScanActivity.java +206 -0
- package/android/src/main/res/drawable/rotate_screen_background.xml +18 -0
- package/android/src/main/res/drawable/rotate_screen_white.png +0 -0
- package/android/src/main/res/layout/activity_scan.xml +27 -0
- package/android/src/main/res/values/anyline_sdk_plugin_strings.xml +2 -28
- package/ios/ALJsonUIConfiguration.h +29 -36
- package/ios/ALJsonUIConfiguration.m +136 -76
- package/ios/ALNFCScanViewController.h +3 -16
- package/ios/ALNFCScanViewController.m +361 -232
- package/ios/ALPluginHelper.h +19 -62
- package/ios/ALPluginHelper.m +208 -529
- package/ios/ALPluginScanViewController.h +5 -32
- package/ios/ALPluginScanViewController.m +339 -287
- package/ios/AnylineReact.podspec +4 -3
- package/ios/AnylineSDKPlugin.m +39 -82
- package/package.json +8 -8
- package/android/.gradle/6.7/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/6.7/fileChanges/last-build.bin +0 -0
- package/android/.gradle/6.7/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/6.7/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/configuration-cache/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.settings/org.eclipse.buildship.core.prefs +0 -13
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/src/main/java/com/anyline/reactnative/Anyline4Activity.java +0 -640
- package/android/src/main/java/com/anyline/reactnative/AnylineBaseActivity.java +0 -267
- package/android/src/main/java/com/anyline/reactnative/AnylinePluginHelper.java +0 -320
- package/android/src/main/java/com/anyline/reactnative/AnylineUIConfig.java +0 -88
- package/android/src/main/java/com/anyline/reactnative/Document4Activity.java +0 -595
- package/android/src/main/res/layout/activity_scan_document.xml +0 -63
- package/android/src/main/res/layout/activity_scan_scanview.xml +0 -52
- package/android/src/main/res/values/com_crashlytics_export_strings.xml +0 -10
package/android/build.gradle
CHANGED
|
@@ -3,7 +3,7 @@ apply plugin: "com.android.library"
|
|
|
3
3
|
buildscript {
|
|
4
4
|
repositories {
|
|
5
5
|
google()
|
|
6
|
-
|
|
6
|
+
mavenCentral()
|
|
7
7
|
}
|
|
8
8
|
dependencies {
|
|
9
9
|
classpath 'com.android.tools.build:gradle:4.1.3'
|
|
@@ -13,17 +13,17 @@ buildscript {
|
|
|
13
13
|
allprojects {
|
|
14
14
|
repositories {
|
|
15
15
|
google()
|
|
16
|
-
|
|
16
|
+
mavenCentral()
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
android {
|
|
22
|
-
compileSdkVersion
|
|
22
|
+
compileSdkVersion rootProject.ext.compileSdkVersion
|
|
23
23
|
|
|
24
24
|
defaultConfig {
|
|
25
|
-
minSdkVersion
|
|
26
|
-
targetSdkVersion
|
|
25
|
+
minSdkVersion rootProject.ext.minSdkVersion
|
|
26
|
+
targetSdkVersion rootProject.ext.targetSdkVersion
|
|
27
27
|
versionCode 1
|
|
28
28
|
versionName "1.0"
|
|
29
29
|
ndk {
|
|
@@ -52,6 +52,10 @@ android {
|
|
|
52
52
|
targetCompatibility JavaVersion.VERSION_1_8
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
buildFeatures {
|
|
56
|
+
viewBinding true
|
|
57
|
+
dataBinding true
|
|
58
|
+
}
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
repositories {
|
|
@@ -65,7 +69,7 @@ repositories {
|
|
|
65
69
|
|
|
66
70
|
dependencies {
|
|
67
71
|
implementation fileTree(dir: "libs", include: ["*.jar"])
|
|
68
|
-
implementation 'io.anyline:anylinesdk:
|
|
72
|
+
implementation 'io.anyline:anylinesdk:43.1.0'
|
|
69
73
|
implementation "com.facebook.react:react-native:+" // from node_modules
|
|
70
74
|
implementation("com.google.android.material:material:1.4.0-rc01")
|
|
71
75
|
implementation 'androidx.multidex:multidex:2.0.1'
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="utf-8"?>
|
|
2
2
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
-
|
|
3
|
+
package="com.anyline.reactnative">
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
<uses-permission android:name="android.permission.INTERNET" />
|
|
6
|
+
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
|
7
|
+
<uses-permission android:name="android.permission.CAMERA" />
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
<application android:allowBackup="true">
|
|
10
|
+
<activity
|
|
11
|
+
android:name=".ScanActivity"
|
|
12
|
+
android:screenOrientation="portrait" />
|
|
13
|
+
</application>
|
|
13
14
|
</manifest>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cameraConfig": {
|
|
3
|
+
"captureResolution": "1080p"
|
|
4
|
+
},
|
|
5
|
+
"flashConfig": {
|
|
6
|
+
"mode": "auto",
|
|
7
|
+
"alignment": "bottom_right"
|
|
8
|
+
},
|
|
9
|
+
"viewPluginConfig": {
|
|
10
|
+
"pluginConfig": {
|
|
11
|
+
"id": "Barcode|Barcodes",
|
|
12
|
+
"barcodeConfig": {
|
|
13
|
+
"barcodeFormats": [
|
|
14
|
+
"ALL"
|
|
15
|
+
],
|
|
16
|
+
"parseAAMVA": true
|
|
17
|
+
},
|
|
18
|
+
"cancelOnResult": false
|
|
19
|
+
},
|
|
20
|
+
"cutoutConfig": {
|
|
21
|
+
"style": "rect",
|
|
22
|
+
"maxWidthPercent": "80%",
|
|
23
|
+
"maxHeightPercent": "80%",
|
|
24
|
+
"alignment": "center",
|
|
25
|
+
"ratioFromSize": {
|
|
26
|
+
"width": 100,
|
|
27
|
+
"height": 80
|
|
28
|
+
},
|
|
29
|
+
"strokeWidth": 1,
|
|
30
|
+
"cornerRadius": 3,
|
|
31
|
+
"strokeColor": "FFFFFF",
|
|
32
|
+
"outerColor": "000000",
|
|
33
|
+
"outerAlpha": 0.3,
|
|
34
|
+
"feedbackStrokeColor": "0099FF"
|
|
35
|
+
},
|
|
36
|
+
"scanFeedbackConfig": {
|
|
37
|
+
"style": "rect",
|
|
38
|
+
"strokeColor": "0099FF",
|
|
39
|
+
"fillColor": "220099FF",
|
|
40
|
+
"animationDuration": 150,
|
|
41
|
+
"blinkAnimationOnResult": true,
|
|
42
|
+
"beepOnResult": true,
|
|
43
|
+
"vibrateOnResult": true
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -22,8 +22,7 @@ public class AnylinePackage implements ReactPackage {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
@Override
|
|
25
|
-
public List<NativeModule> createNativeModules(
|
|
26
|
-
ReactApplicationContext reactContext) {
|
|
25
|
+
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
|
27
26
|
List<NativeModule> modules = new ArrayList<>();
|
|
28
27
|
modules.add(new AnylineSDKPlugin(reactContext));
|
|
29
28
|
return modules;
|
|
@@ -4,12 +4,10 @@ package com.anyline.reactnative;
|
|
|
4
4
|
* Created by jonesBoi on 02.12.16.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import android.app.Activity;
|
|
8
7
|
import android.content.Intent;
|
|
9
8
|
|
|
10
9
|
import com.anyline.reactnative.updateAsset.AnylineUpdateDelegateImpl;
|
|
11
10
|
import com.anyline.reactnative.updateAsset.AssetContextJsonParser;
|
|
12
|
-
import com.facebook.react.ReactInstanceManager;
|
|
13
11
|
import com.facebook.react.bridge.Callback;
|
|
14
12
|
import com.facebook.react.bridge.Promise;
|
|
15
13
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
@@ -19,11 +17,12 @@ import com.facebook.react.bridge.ReactMethod;
|
|
|
19
17
|
import org.json.JSONException;
|
|
20
18
|
import org.json.JSONObject;
|
|
21
19
|
|
|
22
|
-
import
|
|
23
|
-
import io.anyline.AnylineSDK;
|
|
20
|
+
import io.anyline.plugin.ScanResult;
|
|
24
21
|
import io.anyline.products.AnylineUpdater;
|
|
25
|
-
import io.anyline.products.IAnylineUpdateDelegate;
|
|
26
22
|
import io.anyline.trainer.AssetContext;
|
|
23
|
+
import io.anyline.trainer.TrainerUtils;
|
|
24
|
+
import io.anyline2.AnylineSdk;
|
|
25
|
+
import io.anyline2.core.LicenseException;
|
|
27
26
|
|
|
28
27
|
class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultReporter.OnResultListener {
|
|
29
28
|
|
|
@@ -38,22 +37,7 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
|
|
|
38
37
|
public static final int RESULT_CANCELED = 0;
|
|
39
38
|
public static final int RESULT_OK = 1;
|
|
40
39
|
public static final int RESULT_ERROR = 2;
|
|
41
|
-
|
|
42
40
|
private static final String E_ERROR = "E_ERROR";
|
|
43
|
-
|
|
44
|
-
public static final int DIGITAL_METER = 3;
|
|
45
|
-
public static final int ANALOG_METER = 4;
|
|
46
|
-
public static final int AUTO_ANALOG_DIGITAL_METER = 5;
|
|
47
|
-
public static final int ANYLINE_OCR = 6;
|
|
48
|
-
public static final int BARCODE = 7;
|
|
49
|
-
public static final int ANYLINE_MRZ = 8;
|
|
50
|
-
public static final int ANYLINE_DOCUMENT = 9;
|
|
51
|
-
public static final int DIAL_METER = 10;
|
|
52
|
-
public static final int LICENSE_PLATE = 11;
|
|
53
|
-
public static final int SERIAL_NUMBER = 12;
|
|
54
|
-
public static final int DOT_MATRIX_METER = 13;
|
|
55
|
-
public static final int REQUEST_ANYLINE_4 = 14;
|
|
56
|
-
|
|
57
41
|
private JSONObject configObject;
|
|
58
42
|
private ReactApplicationContext reactContext;
|
|
59
43
|
private String license;
|
|
@@ -61,10 +45,8 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
|
|
|
61
45
|
private Callback onResultCallback;
|
|
62
46
|
private Callback onErrorCallback;
|
|
63
47
|
private Promise promise;
|
|
64
|
-
private ReactInstanceManager mReactInstanceManager;
|
|
65
48
|
private String returnMethod;
|
|
66
49
|
private String config;
|
|
67
|
-
private IAnylineUpdateDelegate anylineUpdateDelegate;
|
|
68
50
|
private AssetContextJsonParser assetContextJsonParser;
|
|
69
51
|
|
|
70
52
|
AnylineSDKPlugin(ReactApplicationContext context) {
|
|
@@ -118,22 +100,9 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
|
|
|
118
100
|
@ReactMethod
|
|
119
101
|
public void initSdk(String license) {
|
|
120
102
|
try {
|
|
121
|
-
|
|
103
|
+
AnylineSdk.init(license, reactContext);
|
|
122
104
|
} catch (LicenseException e) {
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
protected void finishWithError(String identifier, String type) {
|
|
128
|
-
Activity activity = getCurrentActivity();
|
|
129
|
-
|
|
130
|
-
if (activity != null) {
|
|
131
|
-
String errorMessage = activity.getString(activity.getResources().getIdentifier(identifier, type, activity.getPackageName()));
|
|
132
|
-
Intent data = new Intent();
|
|
133
|
-
data.putExtra(AnylineSDKPlugin.EXTRA_ERROR_MESSAGE, errorMessage);
|
|
134
|
-
activity.setResult(AnylineSDKPlugin.RESULT_ERROR, data);
|
|
135
|
-
ResultReporter.onError(errorMessage);
|
|
136
|
-
activity.finish();
|
|
105
|
+
e.printStackTrace();
|
|
137
106
|
}
|
|
138
107
|
}
|
|
139
108
|
|
|
@@ -152,6 +121,23 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
|
|
|
152
121
|
routeScanMode(scanMode);
|
|
153
122
|
}
|
|
154
123
|
|
|
124
|
+
@ReactMethod
|
|
125
|
+
public void reportCorrectedResult(String blobKey, String correctedResult, Callback onResponseCallback) {
|
|
126
|
+
ScanResult.reportCorrectedResult(
|
|
127
|
+
this.reactContext,
|
|
128
|
+
blobKey,
|
|
129
|
+
correctedResult,
|
|
130
|
+
"",
|
|
131
|
+
new TrainerUtils.ReportCorrectedResultHandler() {
|
|
132
|
+
|
|
133
|
+
@Override
|
|
134
|
+
public void onReportCorrectedResult(String s) {
|
|
135
|
+
onResponseCallback.invoke(s);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
155
141
|
@ReactMethod
|
|
156
142
|
public void setupPromise(String config, String scanMode, final Promise promise) {
|
|
157
143
|
this.promise = promise;
|
|
@@ -174,21 +160,9 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
|
|
|
174
160
|
private void scanAnyline4() {
|
|
175
161
|
try {
|
|
176
162
|
configObject = new JSONObject(this.config);
|
|
177
|
-
JSONObject options = configObject
|
|
178
|
-
if (
|
|
179
|
-
|
|
180
|
-
if (viewPlugin != null && viewPlugin.has("plugin")) {
|
|
181
|
-
JSONObject plugin = viewPlugin.getJSONObject("plugin");
|
|
182
|
-
if (plugin != null && plugin.has("documentPlugin")) {
|
|
183
|
-
scan(Document4Activity.class, null, REQUEST_ANYLINE_4);
|
|
184
|
-
} else {
|
|
185
|
-
scan(Anyline4Activity.class, null, REQUEST_ANYLINE_4);
|
|
186
|
-
}
|
|
187
|
-
} else {
|
|
188
|
-
returnError("No Plugin in config. Please check your configuration.");
|
|
189
|
-
}
|
|
190
|
-
} else if (options.has("serialViewPluginComposite") || options.has("parallelViewPluginComposite")) {
|
|
191
|
-
scan(Anyline4Activity.class, null, REQUEST_ANYLINE_4);
|
|
163
|
+
// JSONObject options = configObject;
|
|
164
|
+
if (configObject != null) {
|
|
165
|
+
scan();
|
|
192
166
|
} else {
|
|
193
167
|
returnError("No ViewPlugin in config. Please check your configuration.");
|
|
194
168
|
}
|
|
@@ -197,20 +171,21 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
|
|
|
197
171
|
}
|
|
198
172
|
}
|
|
199
173
|
|
|
200
|
-
private void scan(
|
|
174
|
+
private void scan() {
|
|
201
175
|
|
|
202
|
-
Intent intent = new Intent(getCurrentActivity(),
|
|
176
|
+
Intent intent = new Intent(getCurrentActivity(), ScanActivity.class);
|
|
203
177
|
|
|
204
178
|
try {
|
|
205
179
|
configObject = new JSONObject(this.config);
|
|
206
180
|
|
|
207
|
-
// Hacky -> force cancelOnResult = true
|
|
208
|
-
options = configObject.getJSONObject("options");
|
|
209
|
-
options.put("cancelOnResult", true);
|
|
210
|
-
|
|
211
181
|
license = configObject.get("license").toString();
|
|
212
|
-
|
|
213
|
-
|
|
182
|
+
JSONObject optionsJSONObject = configObject.optJSONObject("options");
|
|
183
|
+
|
|
184
|
+
if (optionsJSONObject != null) {
|
|
185
|
+
intent.putExtra(
|
|
186
|
+
EXTRA_ENABLE_BARCODE_SCANNING,
|
|
187
|
+
optionsJSONObject.optBoolean("nativeBarcodeEnabled", false)
|
|
188
|
+
);
|
|
214
189
|
}
|
|
215
190
|
|
|
216
191
|
} catch (JSONException e) {
|
|
@@ -218,24 +193,19 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
|
|
|
218
193
|
}
|
|
219
194
|
|
|
220
195
|
intent.putExtra(EXTRA_LICENSE_KEY, license);
|
|
221
|
-
intent.putExtra(EXTRA_CONFIG_JSON,
|
|
222
|
-
|
|
223
|
-
// Check if OCR
|
|
224
|
-
if (configObject.has("ocr")) {
|
|
225
|
-
try {
|
|
226
|
-
intent.putExtra(EXTRA_OCR_CONFIG_JSON, configObject.get("ocr").toString());
|
|
227
|
-
} catch (JSONException e) {
|
|
228
|
-
returnError(e.getMessage());
|
|
229
|
-
}
|
|
230
|
-
}
|
|
196
|
+
intent.putExtra(EXTRA_CONFIG_JSON, configObject.toString());
|
|
231
197
|
|
|
232
|
-
if (scanMode != null) {
|
|
233
|
-
intent.putExtra(EXTRA_SCAN_MODE, scanMode);
|
|
234
|
-
}
|
|
235
198
|
ResultReporter.setListener(this);
|
|
236
199
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
237
200
|
|
|
238
|
-
|
|
201
|
+
try {
|
|
202
|
+
AnylineSdk.init(configObject.getString("license"), reactContext);
|
|
203
|
+
} catch (LicenseException e) {
|
|
204
|
+
e.printStackTrace();
|
|
205
|
+
} catch (JSONException e) {
|
|
206
|
+
e.printStackTrace();
|
|
207
|
+
}
|
|
208
|
+
reactContext.startActivityForResult(intent, 1111, intent.getExtras());
|
|
239
209
|
}
|
|
240
210
|
|
|
241
211
|
@Override
|
|
@@ -4,14 +4,24 @@ import org.json.JSONException;
|
|
|
4
4
|
import org.json.JSONObject;
|
|
5
5
|
|
|
6
6
|
public class RotateButtonConfig {
|
|
7
|
+
private String alignment = "";
|
|
7
8
|
private Offset offset = null;
|
|
8
9
|
|
|
9
|
-
public RotateButtonConfig(JSONObject jsonObject)
|
|
10
|
+
public RotateButtonConfig(JSONObject jsonObject) {
|
|
11
|
+
alignment = jsonObject.optString("alignment", "");
|
|
10
12
|
if (jsonObject.has("offset")) {
|
|
11
|
-
|
|
13
|
+
try {
|
|
14
|
+
offset = new Offset(jsonObject.getJSONObject("offset"));
|
|
15
|
+
}
|
|
16
|
+
catch (JSONException e) {
|
|
17
|
+
|
|
18
|
+
}
|
|
12
19
|
}
|
|
13
20
|
}
|
|
14
21
|
|
|
22
|
+
public String getAlignment() {
|
|
23
|
+
return alignment;
|
|
24
|
+
}
|
|
15
25
|
public Offset getOffset() {
|
|
16
26
|
return offset;
|
|
17
27
|
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
package com.anyline.reactnative;
|
|
2
|
+
|
|
3
|
+
import static com.anyline.reactnative.AnylineSDKPlugin.EXTRA_CONFIG_JSON;
|
|
4
|
+
import static com.anyline.reactnative.AnylineSDKPlugin.EXTRA_ERROR_MESSAGE;
|
|
5
|
+
import static com.anyline.reactnative.AnylineSDKPlugin.RESULT_ERROR;
|
|
6
|
+
|
|
7
|
+
import android.content.Intent;
|
|
8
|
+
import android.content.pm.ActivityInfo;
|
|
9
|
+
import android.os.Bundle;
|
|
10
|
+
import android.view.Gravity;
|
|
11
|
+
import android.view.View;
|
|
12
|
+
|
|
13
|
+
import androidx.annotation.NonNull;
|
|
14
|
+
import androidx.annotation.Nullable;
|
|
15
|
+
import androidx.appcompat.app.AppCompatActivity;
|
|
16
|
+
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
|
17
|
+
|
|
18
|
+
import com.anyline.reactnative.databinding.ActivityScanBinding;
|
|
19
|
+
|
|
20
|
+
import org.json.JSONArray;
|
|
21
|
+
import org.json.JSONException;
|
|
22
|
+
import org.json.JSONObject;
|
|
23
|
+
|
|
24
|
+
import io.anyline2.ScanResult;
|
|
25
|
+
import io.anyline2.view.ScanView;
|
|
26
|
+
import io.anyline2.viewplugin.ViewPluginBase;
|
|
27
|
+
|
|
28
|
+
public class ScanActivity extends AppCompatActivity {
|
|
29
|
+
|
|
30
|
+
private static final String KEY_DEFAULT_ORIENTATION_APPLIED = "default_orientation_applied";
|
|
31
|
+
|
|
32
|
+
private ActivityScanBinding binding;
|
|
33
|
+
private ScanView scanView;
|
|
34
|
+
|
|
35
|
+
private float dpFactor = 0;
|
|
36
|
+
private boolean defaultOrientationApplied;
|
|
37
|
+
private int orientation;
|
|
38
|
+
|
|
39
|
+
@Override
|
|
40
|
+
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
41
|
+
super.onCreate(savedInstanceState);
|
|
42
|
+
binding = ActivityScanBinding.inflate(getLayoutInflater());
|
|
43
|
+
setContentView(binding.getRoot());
|
|
44
|
+
|
|
45
|
+
dpFactor = getResources().getDisplayMetrics().density;
|
|
46
|
+
|
|
47
|
+
orientation = this.getResources().getConfiguration().orientation;
|
|
48
|
+
|
|
49
|
+
scanView = binding.scanView;
|
|
50
|
+
|
|
51
|
+
if (savedInstanceState != null) {
|
|
52
|
+
defaultOrientationApplied = savedInstanceState.getBoolean(KEY_DEFAULT_ORIENTATION_APPLIED);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (getIntent().hasExtra(EXTRA_CONFIG_JSON)) {
|
|
56
|
+
// TODO check for throws clauses
|
|
57
|
+
try {
|
|
58
|
+
JSONObject configJSON = new JSONObject(getIntent().getStringExtra(EXTRA_CONFIG_JSON));
|
|
59
|
+
|
|
60
|
+
applyDefaultOrientation(configJSON);
|
|
61
|
+
setupChangeOrientationButton(configJSON);
|
|
62
|
+
|
|
63
|
+
scanView.init(configJSON);
|
|
64
|
+
|
|
65
|
+
ViewPluginBase viewPluginBase = scanView.getScanViewPlugin();
|
|
66
|
+
|
|
67
|
+
viewPluginBase.resultReceived = scanResult -> {
|
|
68
|
+
setResult(AnylineSDKPlugin.RESULT_OK);
|
|
69
|
+
JSONObject resultObject = getResultWithImagePath(scanResult);
|
|
70
|
+
ResultReporter.onResult(resultObject.toString(), true);
|
|
71
|
+
finish();
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
viewPluginBase.resultsReceived = scanResults -> {
|
|
75
|
+
JSONArray resultJSONArray = new JSONArray();
|
|
76
|
+
|
|
77
|
+
for (ScanResult scanResult : scanResults) {
|
|
78
|
+
JSONObject resultObject = getResultWithImagePath(scanResult);
|
|
79
|
+
resultJSONArray.put(resultObject);
|
|
80
|
+
}
|
|
81
|
+
setResult(AnylineSDKPlugin.RESULT_OK);
|
|
82
|
+
ResultReporter.onResult(resultJSONArray.toString(), true);
|
|
83
|
+
finish();
|
|
84
|
+
};
|
|
85
|
+
} catch (JSONException e) {
|
|
86
|
+
finishWithError("Error parsing view config: " + e.getMessage());
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
finishWithError("View config not found");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private void applyDefaultOrientation(JSONObject configJSON) {
|
|
94
|
+
if (defaultOrientationApplied) return;
|
|
95
|
+
|
|
96
|
+
JSONObject optionsJsonObject = configJSON.optJSONObject("options");
|
|
97
|
+
|
|
98
|
+
if (optionsJsonObject != null) {
|
|
99
|
+
String defaultOrientationJsonString = optionsJsonObject.optString("defaultOrientation", "");
|
|
100
|
+
|
|
101
|
+
if ("portrait".equals(defaultOrientationJsonString)) {
|
|
102
|
+
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
|
103
|
+
} else if ("landscape".equals(defaultOrientationJsonString)) {
|
|
104
|
+
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
defaultOrientationApplied = true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private void setupChangeOrientationButton(JSONObject configJSON) {
|
|
111
|
+
binding.layoutChangeOrientation.setVisibility(View.GONE);
|
|
112
|
+
JSONObject optionsJsonObject = configJSON.optJSONObject("options");
|
|
113
|
+
|
|
114
|
+
if (optionsJsonObject != null) {
|
|
115
|
+
|
|
116
|
+
JSONObject rotateButtonJson = optionsJsonObject.optJSONObject("rotateButton");
|
|
117
|
+
if (rotateButtonJson != null) {
|
|
118
|
+
RotateButtonConfig rotateButtonConfig = new RotateButtonConfig(rotateButtonJson);
|
|
119
|
+
|
|
120
|
+
CoordinatorLayout.LayoutParams buttonLayoutParams = new CoordinatorLayout.LayoutParams(
|
|
121
|
+
CoordinatorLayout.LayoutParams.WRAP_CONTENT,
|
|
122
|
+
CoordinatorLayout.LayoutParams.WRAP_CONTENT);
|
|
123
|
+
|
|
124
|
+
buttonLayoutParams.gravity = Gravity.TOP | Gravity.RIGHT;
|
|
125
|
+
String alignment = rotateButtonConfig.getAlignment();
|
|
126
|
+
if (alignment.length() > 0) {
|
|
127
|
+
if (alignment.equals("top_left")) {
|
|
128
|
+
buttonLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
|
129
|
+
}
|
|
130
|
+
if (alignment.equals("top_right")) {
|
|
131
|
+
buttonLayoutParams.gravity = Gravity.TOP | Gravity.RIGHT;
|
|
132
|
+
}
|
|
133
|
+
if (alignment.equals("bottom_left")) {
|
|
134
|
+
buttonLayoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT;
|
|
135
|
+
}
|
|
136
|
+
if (alignment.equals("bottom_right")) {
|
|
137
|
+
buttonLayoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (rotateButtonConfig.hasOffset()) {
|
|
141
|
+
buttonLayoutParams.setMargins(rotateButtonConfig.getOffset().getX(), rotateButtonConfig.getOffset().getY(), 0, 0);
|
|
142
|
+
}
|
|
143
|
+
binding.layoutChangeOrientation.setLayoutParams(buttonLayoutParams);
|
|
144
|
+
binding.layoutChangeOrientation.requestLayout();
|
|
145
|
+
|
|
146
|
+
binding.layoutChangeOrientation.setVisibility(View.VISIBLE);
|
|
147
|
+
binding.imageviewChangeOrientation.setOnClickListener(v -> {
|
|
148
|
+
if (orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
|
|
149
|
+
orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
|
|
150
|
+
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
|
151
|
+
} else {
|
|
152
|
+
orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
|
153
|
+
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
@NonNull
|
|
161
|
+
private JSONObject getResultWithImagePath(ScanResult scanResult) {
|
|
162
|
+
JSONObject resultObject = scanResult.getResult();
|
|
163
|
+
|
|
164
|
+
try {
|
|
165
|
+
String fullImagePath = scanResult.getImage().save();
|
|
166
|
+
String cutoutImagePath = scanResult.getCutoutImage().save();
|
|
167
|
+
resultObject.put("fullImagePath", fullImagePath);
|
|
168
|
+
resultObject.put("imagePath", cutoutImagePath);
|
|
169
|
+
} catch (Exception e) {
|
|
170
|
+
e.printStackTrace();
|
|
171
|
+
}
|
|
172
|
+
return resultObject;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private void finishWithError(String errorMessage) {
|
|
176
|
+
Intent intent = new Intent();
|
|
177
|
+
intent.putExtra(EXTRA_ERROR_MESSAGE, errorMessage);
|
|
178
|
+
setResult(RESULT_ERROR, intent);
|
|
179
|
+
finish();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
@Override
|
|
183
|
+
protected void onSaveInstanceState(Bundle outState) {
|
|
184
|
+
super.onSaveInstanceState(outState);
|
|
185
|
+
outState.putBoolean(KEY_DEFAULT_ORIENTATION_APPLIED, defaultOrientationApplied);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
@Override
|
|
189
|
+
protected void onResume() {
|
|
190
|
+
super.onResume();
|
|
191
|
+
scanView.start();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
@Override
|
|
195
|
+
protected void onPause() {
|
|
196
|
+
scanView.stop();
|
|
197
|
+
scanView.getCameraView().releaseCameraInBackground();
|
|
198
|
+
super.onPause();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
@Override
|
|
202
|
+
public void onBackPressed() {
|
|
203
|
+
ResultReporter.onCancel();
|
|
204
|
+
super.onBackPressed();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
|
|
3
|
+
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
|
4
|
+
<solid
|
|
5
|
+
android:color="#A5000000"/>
|
|
6
|
+
<stroke
|
|
7
|
+
android:color="@android:color/white"
|
|
8
|
+
android:width="1dp"/>
|
|
9
|
+
<corners
|
|
10
|
+
android:radius="30dp" />
|
|
11
|
+
|
|
12
|
+
<padding
|
|
13
|
+
android:left="4dp"
|
|
14
|
+
android:top="4dp"
|
|
15
|
+
android:right="4dp"
|
|
16
|
+
android:bottom="4dp" />
|
|
17
|
+
|
|
18
|
+
</shape>
|
|
Binary file
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
2
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
3
|
+
android:layout_width="match_parent"
|
|
4
|
+
android:layout_height="match_parent">
|
|
5
|
+
|
|
6
|
+
<io.anyline2.view.ScanView
|
|
7
|
+
android:id="@+id/scan_view"
|
|
8
|
+
android:layout_width="match_parent"
|
|
9
|
+
android:layout_height="match_parent"
|
|
10
|
+
app:api_2_enabled="false" />
|
|
11
|
+
|
|
12
|
+
<LinearLayout
|
|
13
|
+
android:id="@+id/layout_change_orientation"
|
|
14
|
+
android:layout_width="wrap_content"
|
|
15
|
+
android:layout_height="wrap_content"
|
|
16
|
+
android:layout_gravity="right|top"
|
|
17
|
+
android:gravity="center"
|
|
18
|
+
android:padding="40px">
|
|
19
|
+
<ImageView
|
|
20
|
+
android:id="@+id/imageview_change_orientation"
|
|
21
|
+
android:layout_width="40dp"
|
|
22
|
+
android:layout_height="40dp"
|
|
23
|
+
android:scaleType="fitStart"
|
|
24
|
+
android:background="@drawable/rotate_screen_background"
|
|
25
|
+
android:src="@drawable/rotate_screen_white" />
|
|
26
|
+
</LinearLayout>
|
|
27
|
+
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
|
@@ -1,34 +1,8 @@
|
|
|
1
1
|
<resources>
|
|
2
|
-
<string name="
|
|
2
|
+
<string name="error_unknown_scan_mode">Unknown scan mode: </string>
|
|
3
3
|
<string name="error_invalid_json_data">Config json is invalid.</string>
|
|
4
4
|
<string name="error_invalid_segment_config">Semgent config not valid. Must have equal amount of titles and modes.</string>
|
|
5
5
|
<string name="error_accessing_camera">Error while accessing camera.</string>
|
|
6
6
|
<string name="error_licence_invalid">Error: Anyline license invalid.</string>
|
|
7
|
-
<string name="
|
|
8
|
-
|
|
9
|
-
<string name="document_advanced_outline_detection">Advanced Outline Detection</string>
|
|
10
|
-
<string name="document_fast_outline_detection">Fast Outline Detection</string>
|
|
11
|
-
<string name="document_error_not_sharp">Document is not sharp. Please hold the camera steadily and ensure the document is in focus</string>
|
|
12
|
-
<string name="document_error_skew_too_high">Document is skewed. Place the camera directly above the document</string>
|
|
13
|
-
<string name="document_error_outline_not_found">Could not detect document outline</string>
|
|
14
|
-
|
|
15
|
-
<string name="document_error_glare_detected">Please remove the glare</string>
|
|
16
|
-
<string name="document_error_too_dark">The image is too dark. Please ensure there is enough light</string>
|
|
17
|
-
<string name="document_error_unknown">Unknown Failure</string>
|
|
18
|
-
<string name="document_picture_error">Error scanning full document:\n</string>
|
|
19
|
-
<string name="document_preview_success">Scanning full document. Please hold still</string>
|
|
20
|
-
<string name="document_picture_success">Document scanned successfully</string>
|
|
21
|
-
<string name="document_using_fast_mode">Switched to fast detection mode</string>
|
|
22
|
-
<string name="document_using_advanced_mode">Switched to advanced detection mode</string>
|
|
23
|
-
<string name="document_processing_picture_header">Processing</string>
|
|
24
|
-
<string name="document_processing_picture">Processing the Picture. Please wait</string>
|
|
25
|
-
<string name="document_error_shake">Shake detected</string>
|
|
26
|
-
<string name="document_error_closer">Come closer</string>
|
|
27
|
-
<string name="document_error_format">Unrecognised format</string>
|
|
28
|
-
<string name="document_image_saved_to">Image saved to</string>
|
|
29
|
-
|
|
30
|
-
<string name="document_processing">Processing</string>
|
|
31
|
-
<string name="document_processing_picture_please_wait">Processing the picture. Please wait.</string>
|
|
32
|
-
|
|
33
|
-
|
|
7
|
+
<string name="error_occurred">An error occurred.</string>
|
|
34
8
|
</resources>
|