anyline-ocr-react-native-module 55.2.1 → 55.5.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/AnylineReact.podspec +1 -1
- package/android/build.gradle +1 -3
- package/android/src/main/AndroidManifest.xml +1 -3
- package/android/src/main/java/com/anyline/reactnative/AnylineSDKPlugin.java +241 -254
- package/index.js +1 -15
- package/ios/AnylineSDKPlugin.h +4 -4
- package/ios/AnylineSDKPlugin.m +275 -214
- package/package.json +1 -1
- package/android/.gradle/7.6/checksums/checksums.lock +0 -0
- package/android/.gradle/7.6/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.6/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.6/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.6/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.6/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/src/main/java/com/anyline/reactnative/FeedbackConfig.java +0 -59
- package/android/src/main/java/com/anyline/reactnative/ImageTextConfig.java +0 -49
- package/android/src/main/java/com/anyline/reactnative/InstructionConfig.java +0 -20
- package/android/src/main/java/com/anyline/reactnative/Offset.java +0 -21
- package/android/src/main/java/com/anyline/reactnative/RotateButtonConfig.java +0 -32
- package/android/src/main/java/com/anyline/reactnative/ScanActivity.java +0 -426
- package/android/src/main/java/com/anyline/reactnative/updateAsset/AnylineUpdateDelegateImpl.java +0 -50
- package/android/src/main/java/com/anyline/reactnative/updateAsset/AssetContextJsonParser.java +0 -28
- package/android/src/main/res/drawable/rotate_screen_background.xml +0 -18
- package/android/src/main/res/drawable/rotate_screen_white.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_flash_auto.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_flash_off.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_flash_on.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_flash_auto.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_flash_off.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_flash_on.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_flash_auto.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_flash_off.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_flash_on.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_flash_auto.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_flash_off.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_flash_on.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_flash_auto.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_flash_off.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_flash_on.png +0 -0
- package/android/src/main/res/layout/activity_scan.xml +0 -93
- package/ios/ALJsonUIConfiguration.h +0 -54
- package/ios/ALJsonUIConfiguration.m +0 -251
- package/ios/ALPluginHelper.h +0 -48
- package/ios/ALPluginHelper.m +0 -332
- package/ios/ALPluginScanViewController.h +0 -18
- package/ios/ALPluginScanViewController.m +0 -476
- package/ios/ALRoundedView.h +0 -25
- package/ios/ALRoundedView.m +0 -107
package/AnylineReact.podspec
CHANGED
|
@@ -18,7 +18,7 @@ Pod::Spec.new do |s|
|
|
|
18
18
|
s.source = { :git => "https://github.com/Anyline/anyline-ocr-react-native-module.git", :tag => "#{s.version}" }
|
|
19
19
|
|
|
20
20
|
s.source_files = 'ios/**/*.{h,m,swift}'
|
|
21
|
-
s.dependency "Anyline", "55.
|
|
21
|
+
s.dependency "Anyline", "55.5.0"
|
|
22
22
|
s.dependency "React"
|
|
23
23
|
|
|
24
24
|
end
|
package/android/build.gradle
CHANGED
|
@@ -61,8 +61,6 @@ repositories {
|
|
|
61
61
|
|
|
62
62
|
dependencies {
|
|
63
63
|
implementation fileTree(dir: "libs", include: ["*.jar"])
|
|
64
|
-
implementation 'io.anyline:anylinesdk:55.
|
|
64
|
+
implementation 'io.anyline:anylinesdk:55.5.0'
|
|
65
65
|
implementation "com.facebook.react:react-native:+"
|
|
66
|
-
implementation("com.google.android.material:material:1.9.0")
|
|
67
|
-
implementation 'androidx.multidex:multidex:2.0.1'
|
|
68
66
|
}
|
|
@@ -4,79 +4,82 @@ package com.anyline.reactnative;
|
|
|
4
4
|
* Created by jonesBoi on 02.12.16.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import android.content.
|
|
7
|
+
import android.content.Context;
|
|
8
|
+
|
|
9
|
+
import androidx.annotation.NonNull;
|
|
8
10
|
|
|
9
|
-
import com.anyline.reactnative.updateAsset.AnylineUpdateDelegateImpl;
|
|
10
|
-
import com.anyline.reactnative.updateAsset.AssetContextJsonParser;
|
|
11
11
|
import com.facebook.react.bridge.Callback;
|
|
12
12
|
import com.facebook.react.bridge.Promise;
|
|
13
13
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
14
14
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
15
15
|
import com.facebook.react.bridge.ReactMethod;
|
|
16
|
+
import com.facebook.react.bridge.Arguments;
|
|
17
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
16
18
|
|
|
17
|
-
import org.
|
|
19
|
+
import org.jetbrains.annotations.NotNull;
|
|
18
20
|
import org.json.JSONObject;
|
|
19
21
|
|
|
20
|
-
import java.
|
|
21
|
-
|
|
22
|
-
import
|
|
23
|
-
|
|
24
|
-
import io.
|
|
22
|
+
import java.util.List;
|
|
23
|
+
|
|
24
|
+
import io.anyline.plugin.config.UIFeedbackElementConfig;
|
|
25
|
+
import io.anyline.plugin.result.ExportedScanResult;
|
|
26
|
+
import io.anyline.wrapper.config.WrapperSessionExportCachedEventsResponse;
|
|
27
|
+
import io.anyline.wrapper.config.WrapperSessionExportCachedEventsResponseSucceed;
|
|
28
|
+
import io.anyline.wrapper.config.WrapperSessionExportCachedEventsResponseFail;
|
|
29
|
+
import io.anyline.wrapper.config.WrapperSessionScanResultExtraInfo;
|
|
30
|
+
import io.anyline.wrapper.config.WrapperSessionScanResultsResponse;
|
|
31
|
+
import io.anyline.wrapper.config.WrapperSessionScanStartRequest;
|
|
32
|
+
import io.anyline.wrapper.config.WrapperSessionScanResponse;
|
|
33
|
+
import io.anyline.wrapper.config.WrapperSessionScanResultConfig;
|
|
34
|
+
import io.anyline.wrapper.config.WrapperSessionSdkInitializationResponse;
|
|
35
|
+
import io.anyline.wrapper.config.WrapperSessionSdkInitializationResponseInitialized;
|
|
36
|
+
import io.anyline.wrapper.config.WrapperSessionUCRReportRequest;
|
|
37
|
+
import io.anyline.wrapper.config.WrapperSessionUCRReportResponse;
|
|
25
38
|
import io.anyline2.WrapperInfo;
|
|
26
|
-
import io.anyline2.core.PluginType;
|
|
27
39
|
import io.anyline2.di.context.ContextProvider;
|
|
28
|
-
import io.anyline2.
|
|
29
|
-
import io.anyline2.
|
|
30
|
-
import io.anyline2.
|
|
31
|
-
import io.anyline2.
|
|
32
|
-
import io.anyline2.
|
|
33
|
-
import io.anyline2.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// We're creating a static variable to retain the SDK instance in order to prevent crashes due to garbage collection cleaning up the SDK.
|
|
43
|
-
protected static final AnylineSdk anylineSdk = AnylineSdk.INSTANCE;
|
|
40
|
+
import io.anyline2.sdk.extension.UIFeedbackElementConfigExtensionKt;
|
|
41
|
+
import io.anyline2.wrapper.WrapperSessionClientInterface;
|
|
42
|
+
import io.anyline2.wrapper.WrapperSessionProvider;
|
|
43
|
+
import io.anyline2.wrapper.extensions.WrapperSessionScanStartRequestExtensionKt;
|
|
44
|
+
import io.anyline2.wrapper.extensions.WrapperSessionSdkInitializationResponseExtensionKt;
|
|
45
|
+
import io.anyline2.wrapper.extensions.WrapperSessionUCRReportRequestExtensionKt;
|
|
46
|
+
import io.anyline2.wrapper.legacy.LegacyPluginHelper;
|
|
47
|
+
|
|
48
|
+
class AnylineSDKPlugin extends ReactContextBaseJavaModule
|
|
49
|
+
implements WrapperSessionClientInterface, ResultReporter.OnResultListener {
|
|
50
|
+
|
|
51
|
+
// We're creating a static variable to retain the WrapperSessionProvider instance in order to prevent crashes due to garbage collection cleaning up the SDK.
|
|
52
|
+
protected static final WrapperSessionProvider wrapperSessionProvider = WrapperSessionProvider.INSTANCE;
|
|
44
53
|
// We're creating a static variable to store the last license used to initialize the SDK
|
|
45
54
|
private static String license;
|
|
46
55
|
|
|
47
56
|
private static boolean isInitializedWithLicenseKey(String requestedLicense) {
|
|
48
|
-
return (license != null
|
|
57
|
+
return (license != null
|
|
58
|
+
&& WrapperSessionProvider.getCurrentSdkInitializationResponse().getInitialized() == Boolean.TRUE
|
|
59
|
+
&& license.equals(requestedLicense));
|
|
49
60
|
}
|
|
50
61
|
|
|
51
62
|
public static final String REACT_CLASS = "AnylineSDKPlugin";
|
|
52
|
-
public static final String EXTRA_CONFIG_JSON = "EXTRA_CONFIG_JSON";
|
|
53
|
-
public static final String EXTRA_SCANVIEW_INITIALIZATION_PARAMETERS = "EXTRA_SCANVIEW_INITIALIZATION_PARAMETERS";
|
|
54
|
-
public static final String EXTRA_SCAN_MODE = "EXTRA_SCAN_MODE";
|
|
55
|
-
public static final String EXTRA_ERROR_MESSAGE = "EXTRA_ERROR_MESSAGE";
|
|
56
|
-
public static final String EXTRA_OCR_CONFIG_JSON = "EXTRA_OCR_CONFIG_JSON";
|
|
57
|
-
public static final String EXTRA_ENABLE_BARCODE_SCANNING = "EXTRA_ENABLE_BARCODE_SCANNING";
|
|
58
|
-
|
|
59
|
-
public static final int RESULT_CANCELED = 0;
|
|
60
|
-
public static final int RESULT_OK = 1;
|
|
61
|
-
public static final int RESULT_ERROR = 2;
|
|
62
63
|
private static final String E_ERROR = "E_ERROR";
|
|
63
|
-
|
|
64
|
-
private ReactApplicationContext reactContext;
|
|
65
|
-
|
|
66
|
-
private Callback onResultCallback;
|
|
67
|
-
private Callback onErrorCallback;
|
|
68
|
-
private Promise promise;
|
|
64
|
+
|
|
65
|
+
private final ReactApplicationContext reactContext;
|
|
66
|
+
|
|
69
67
|
private String returnMethod;
|
|
70
|
-
private String config;
|
|
71
|
-
private String scanViewInitializationParameters;
|
|
72
|
-
private AssetContextJsonParser assetContextJsonParser;
|
|
73
68
|
|
|
74
|
-
private
|
|
69
|
+
private Promise wrapperSessionSdkInitializationResponsePromise = null;
|
|
70
|
+
|
|
71
|
+
private Promise wrapperSessionScanResponsePromise = null;
|
|
72
|
+
private Callback scanResponseResultCallback = null;
|
|
73
|
+
private Callback scanResponseErrorCallback = null;
|
|
74
|
+
|
|
75
|
+
private Promise wrapperSessionExportCachedEventsPromise = null;
|
|
76
|
+
|
|
77
|
+
private Callback reportCorrectedResultResponseCallback = null;
|
|
78
|
+
private Callback reportCorrectedResultErrorCallback = null;
|
|
75
79
|
|
|
76
80
|
AnylineSDKPlugin(ReactApplicationContext context) {
|
|
77
81
|
super(context);
|
|
78
82
|
this.reactContext = context;
|
|
79
|
-
this.assetContextJsonParser = new AssetContextJsonParser();
|
|
80
83
|
ContextProvider.setInstance(context);
|
|
81
84
|
}
|
|
82
85
|
|
|
@@ -91,57 +94,37 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
|
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
@ReactMethod
|
|
94
|
-
protected void
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
);
|
|
97
|
+
protected void setupWrapperSession(final String pluginVersion) {
|
|
98
|
+
WrapperInfo wrapperInfo = new WrapperInfo(WrapperInfo.WrapperType.ReactNative, pluginVersion);
|
|
99
|
+
WrapperSessionProvider.setupWrapperSession(wrapperInfo,this);
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
@ReactMethod
|
|
101
103
|
public void licenseKeyExpiryDate(final Promise promise) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
if (WrapperSessionProvider.getCurrentSdkInitializationResponse().getInitialized() == Boolean.TRUE) {
|
|
105
|
+
WrapperSessionSdkInitializationResponseInitialized sdkInitializationResponseInitialized
|
|
106
|
+
= WrapperSessionProvider.getCurrentSdkInitializationResponse().getSucceedInfo();
|
|
107
|
+
if (sdkInitializationResponseInitialized != null) {
|
|
108
|
+
promise.resolve(sdkInitializationResponseInitialized.getExpiryDate());
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
106
111
|
}
|
|
112
|
+
promise.reject(E_ERROR, "Anyline SDK was not initialized");
|
|
107
113
|
}
|
|
108
114
|
|
|
109
115
|
@ReactMethod
|
|
110
116
|
public void isInitialized(final Promise promise) {
|
|
111
|
-
promise.resolve(
|
|
117
|
+
promise.resolve(WrapperSessionProvider.getCurrentSdkInitializationResponse().getInitialized());
|
|
112
118
|
}
|
|
113
119
|
|
|
114
120
|
@ReactMethod
|
|
115
121
|
@Deprecated
|
|
116
122
|
public void setupScanViewWithConfigJson(String config, String scanMode, Callback onResultReact, Callback onErrorReact) {
|
|
117
|
-
|
|
118
|
-
|
|
123
|
+
scanResponseResultCallback = onResultReact;
|
|
124
|
+
scanResponseErrorCallback = onErrorReact;
|
|
119
125
|
this.returnMethod = "callback";
|
|
120
|
-
this.config = config;
|
|
121
126
|
|
|
122
|
-
routeScanMode(
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
@ReactMethod
|
|
126
|
-
public void update(
|
|
127
|
-
String assetContextJson,
|
|
128
|
-
Callback onUpdateError,
|
|
129
|
-
Callback onUpdateFinished
|
|
130
|
-
) {
|
|
131
|
-
try {
|
|
132
|
-
AssetContext assetContext = assetContextJsonParser.parseJson(reactContext, assetContextJson);
|
|
133
|
-
|
|
134
|
-
if (assetContext != null) {
|
|
135
|
-
AnylineUpdater.update(
|
|
136
|
-
reactContext,
|
|
137
|
-
assetContext,
|
|
138
|
-
new AnylineUpdateDelegateImpl(reactContext, onUpdateError, onUpdateFinished),
|
|
139
|
-
PluginType.OCR
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
} catch (JSONException e) {
|
|
143
|
-
returnError(e.getMessage());
|
|
144
|
-
}
|
|
127
|
+
routeScanMode(config, null, null, null);
|
|
145
128
|
}
|
|
146
129
|
|
|
147
130
|
@ReactMethod
|
|
@@ -155,22 +138,8 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
|
|
|
155
138
|
promise.resolve(true);
|
|
156
139
|
return;
|
|
157
140
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (enableOfflineCache) {
|
|
161
|
-
cacheConfig = CacheConfig.Preset.OfflineLicenseEventCachingEnabled.INSTANCE;
|
|
162
|
-
}
|
|
163
|
-
try {
|
|
164
|
-
AnylineSdk.init(license, reactContext, "", cacheConfig, wrapperConfig);
|
|
165
|
-
this.license = license;
|
|
166
|
-
if (promise != null) {
|
|
167
|
-
promise.resolve(true);
|
|
168
|
-
}
|
|
169
|
-
} catch (LicenseException e) {
|
|
170
|
-
if (promise != null) {
|
|
171
|
-
promise.reject(E_ERROR, e.getMessage());
|
|
172
|
-
}
|
|
173
|
-
}
|
|
141
|
+
wrapperSessionSdkInitializationResponsePromise = promise;
|
|
142
|
+
initSdkWithCacheConfig(license, enableOfflineCache);
|
|
174
143
|
}
|
|
175
144
|
|
|
176
145
|
@ReactMethod
|
|
@@ -183,187 +152,98 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
|
|
|
183
152
|
if (isInitializedWithLicenseKey(license)) {
|
|
184
153
|
return;
|
|
185
154
|
}
|
|
155
|
+
AnylineSDKPlugin.license = license;
|
|
186
156
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
cacheConfig = CacheConfig.Preset.OfflineLicenseEventCachingEnabled.INSTANCE;
|
|
190
|
-
}
|
|
191
|
-
try {
|
|
192
|
-
AnylineSdk.init(license, reactContext, "", cacheConfig, wrapperConfig);
|
|
193
|
-
this.license = license;
|
|
194
|
-
} catch (LicenseException e) {
|
|
195
|
-
returnError(e.getMessage());
|
|
196
|
-
}
|
|
197
|
-
}
|
|
157
|
+
JSONObject wrapperSessionSdkInitializationRequestJson =
|
|
158
|
+
LegacyPluginHelper.getWrapperSessionSdkInitializationRequestJson(license, enableOfflineCache, null);
|
|
198
159
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
// TODO
|
|
160
|
+
WrapperSessionProvider.requestSdkInitialization(
|
|
161
|
+
wrapperSessionSdkInitializationRequestJson.toString());
|
|
202
162
|
}
|
|
203
163
|
|
|
204
164
|
@ReactMethod
|
|
205
165
|
public void setup(String config, String scanMode, Callback onResultReact, Callback onErrorReact) {
|
|
206
166
|
setupWithInitializationParameters(null, config, scanMode, onResultReact, onErrorReact);
|
|
207
167
|
}
|
|
208
|
-
|
|
209
168
|
@ReactMethod
|
|
210
|
-
public void setupWithInitializationParameters(String
|
|
211
|
-
|
|
212
|
-
|
|
169
|
+
public void setupWithInitializationParameters(String scanViewInitializationParametersString, String config, String scanMode, Callback onResultReact, Callback onErrorReact) {
|
|
170
|
+
scanResponseResultCallback = onResultReact;
|
|
171
|
+
scanResponseErrorCallback = onErrorReact;
|
|
213
172
|
this.returnMethod = "callback";
|
|
214
|
-
this.config = config;
|
|
215
|
-
this.scanViewInitializationParameters = initializationParameters;
|
|
216
173
|
|
|
217
|
-
routeScanMode(
|
|
174
|
+
routeScanMode(config, scanViewInitializationParametersString, null, null);
|
|
218
175
|
}
|
|
219
|
-
|
|
220
176
|
@ReactMethod
|
|
221
|
-
public void
|
|
222
|
-
|
|
223
|
-
String correctedResultReturn = ScanResult.reportCorrectedResultFromBlobKey(blobKey, correctedResult);
|
|
224
|
-
try {
|
|
225
|
-
JSONObject correctedResultJson = new JSONObject(correctedResultReturn);
|
|
226
|
-
int correctedResultCode = correctedResultJson.optInt("code", 0);
|
|
227
|
-
String correctedResultMessage = correctedResultJson.optString("message");
|
|
228
|
-
if (correctedResultCode == 200) {
|
|
229
|
-
String correctedResultInternalMessage = "";
|
|
230
|
-
if (correctedResultMessage != null) {
|
|
231
|
-
correctedResultInternalMessage = new JSONObject(correctedResultMessage).optString("message");
|
|
232
|
-
}
|
|
233
|
-
onResponseCallback.invoke(correctedResultInternalMessage);
|
|
234
|
-
} else {
|
|
235
|
-
onErrorCallback.invoke(correctedResultMessage);
|
|
236
|
-
}
|
|
237
|
-
} catch (JSONException e) {
|
|
238
|
-
onErrorCallback.invoke(e.getMessage());
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
catch (IllegalArgumentException e) {
|
|
242
|
-
onErrorCallback.invoke(e.getMessage());
|
|
243
|
-
}
|
|
177
|
+
public void setupPromise(String config, String scanMode, final Promise promise) {
|
|
178
|
+
setupPromiseWithInitializationParameters(null, config, scanMode, promise);
|
|
244
179
|
}
|
|
245
|
-
|
|
246
180
|
@ReactMethod
|
|
247
|
-
public void
|
|
248
|
-
|
|
249
|
-
String exportedFile = AnylineSdk.exportCachedEvents();
|
|
250
|
-
if (exportedFile != null) {
|
|
251
|
-
if (promise != null) {
|
|
252
|
-
promise.resolve(String.valueOf(exportedFile));
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
if (promise != null) {
|
|
257
|
-
promise.reject(E_ERROR, "Event cache is empty.");
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
} catch (IOException e) {
|
|
261
|
-
if (promise != null) {
|
|
262
|
-
promise.reject(E_ERROR, e.getMessage());
|
|
263
|
-
}
|
|
264
|
-
}
|
|
181
|
+
public void setupPromiseWithScanCallbackConfig(String config, String scanMode, String scanCallbackConfigString, final Promise promise) {
|
|
182
|
+
setupPromiseWithInitializationParametersAndScanCallbackConfig(null, config, scanMode, scanCallbackConfigString, promise);
|
|
265
183
|
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* This function removes all previous scan result images from disk, either from external
|
|
269
|
-
* or internal files dir, e.g.:
|
|
270
|
-
* /sdcard/Android/[applicationId]/files/results/image1729849635965
|
|
271
|
-
*/
|
|
272
|
-
private void deleteAllPreviousScanResultImages() {
|
|
273
|
-
String imagePath = "";
|
|
274
|
-
if (reactContext.getExternalFilesDir(null) != null) {
|
|
275
|
-
imagePath = reactContext
|
|
276
|
-
.getExternalFilesDir(null)
|
|
277
|
-
.toString() + "/results/";
|
|
278
|
-
|
|
279
|
-
} else if (reactContext.getFilesDir() != null) {
|
|
280
|
-
imagePath = reactContext
|
|
281
|
-
.getFilesDir()
|
|
282
|
-
.toString() + "/results/";
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
File resultFolder = new File(imagePath);
|
|
286
|
-
File[] files = resultFolder.listFiles();
|
|
287
|
-
if (files != null) {
|
|
288
|
-
for (int fileIndex = 0; fileIndex < files.length; fileIndex++) {
|
|
289
|
-
if (files[fileIndex].getName().startsWith("image")) {
|
|
290
|
-
files[fileIndex].delete();
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
184
|
@ReactMethod
|
|
297
|
-
public void
|
|
298
|
-
|
|
185
|
+
public void setupPromiseWithInitializationParameters(String initializationParametersString, String config, String scanMode, final Promise promise) {
|
|
186
|
+
setupPromiseWithInitializationParametersAndScanCallbackConfig(initializationParametersString, config, scanMode, null, promise);
|
|
299
187
|
}
|
|
300
188
|
@ReactMethod
|
|
301
|
-
public void
|
|
302
|
-
this.
|
|
189
|
+
public void setupPromiseWithInitializationParametersAndScanCallbackConfig(String initializationParametersString, String config, String scanMode, String scanCallbackConfigString, final Promise promise) {
|
|
190
|
+
this.wrapperSessionScanResponsePromise = promise;
|
|
303
191
|
this.returnMethod = "promise";
|
|
304
|
-
this.config = config;
|
|
305
|
-
this.scanViewInitializationParameters = initializationParameters;
|
|
306
192
|
|
|
307
|
-
|
|
308
|
-
routeScanMode(scanMode);
|
|
193
|
+
routeScanMode(config, initializationParametersString, null, scanCallbackConfigString);
|
|
309
194
|
}
|
|
310
195
|
|
|
311
|
-
private void routeScanMode(
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
returnError("Wrong ScanMode");
|
|
318
|
-
}
|
|
319
|
-
}
|
|
196
|
+
private void routeScanMode(
|
|
197
|
+
String scanViewConfigContent,
|
|
198
|
+
String scanViewInitializationParametersString,
|
|
199
|
+
String scanViewConfigPath,
|
|
200
|
+
String scanCallbackConfigString) {
|
|
201
|
+
boolean shouldReturnImages = true;
|
|
320
202
|
|
|
321
|
-
|
|
203
|
+
WrapperSessionScanStartRequest wrapperSessionScanRequest;
|
|
322
204
|
try {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
205
|
+
wrapperSessionScanRequest = LegacyPluginHelper.getWrapperSessionScanStartRequest(
|
|
206
|
+
this.reactContext,
|
|
207
|
+
scanViewConfigContent,
|
|
208
|
+
scanViewInitializationParametersString,
|
|
209
|
+
scanViewConfigPath,
|
|
210
|
+
scanCallbackConfigString,
|
|
211
|
+
shouldReturnImages);
|
|
212
|
+
} catch (Exception e) {
|
|
213
|
+
returnError("Could not parse parameters: " + e.getMessage());
|
|
214
|
+
return;
|
|
333
215
|
}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
private void scan() throws LicenseException, JSONException {
|
|
337
216
|
|
|
338
|
-
|
|
217
|
+
JSONObject wrapperSessionScanStartRequestJson
|
|
218
|
+
= WrapperSessionScanStartRequestExtensionKt.toJsonObject(wrapperSessionScanRequest);
|
|
339
219
|
|
|
340
|
-
|
|
341
|
-
if (this.license != null) {
|
|
342
|
-
AnylineSdk.init(this.license, reactContext, "", CacheConfig.Preset.Default.INSTANCE, wrapperConfig);
|
|
343
|
-
}
|
|
344
|
-
else {
|
|
345
|
-
throw new JSONException("SDK is not initialized. Please initialize SDK before scanning.");
|
|
346
|
-
}
|
|
347
|
-
}
|
|
220
|
+
WrapperSessionProvider.requestScanStart(wrapperSessionScanStartRequestJson.toString());
|
|
348
221
|
|
|
349
|
-
|
|
222
|
+
ResultReporter.setListener(this);
|
|
223
|
+
}
|
|
350
224
|
|
|
351
|
-
|
|
225
|
+
@ReactMethod
|
|
226
|
+
public void reportCorrectedResult(String blobKey, String correctedResult, Callback onResponseCallback, Callback onErrorCallback) {
|
|
227
|
+
reportCorrectedResultResponseCallback = onResponseCallback;
|
|
228
|
+
reportCorrectedResultErrorCallback = onErrorCallback;
|
|
229
|
+
WrapperSessionUCRReportRequest wrapperSessionUCRReportRequest = LegacyPluginHelper
|
|
230
|
+
.getWrapperSessionUCRReportRequest(blobKey, correctedResult);
|
|
352
231
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
EXTRA_ENABLE_BARCODE_SCANNING,
|
|
356
|
-
optionsJSONObject.optBoolean("nativeBarcodeEnabled", false)
|
|
357
|
-
);
|
|
358
|
-
}
|
|
232
|
+
JSONObject wrapperSessionUCRReportRequestJson = WrapperSessionUCRReportRequestExtensionKt
|
|
233
|
+
.toJsonObject(wrapperSessionUCRReportRequest);
|
|
359
234
|
|
|
360
|
-
|
|
361
|
-
|
|
235
|
+
WrapperSessionProvider.requestUCRReport(wrapperSessionUCRReportRequestJson.toString());
|
|
236
|
+
}
|
|
362
237
|
|
|
363
|
-
|
|
364
|
-
|
|
238
|
+
@ReactMethod
|
|
239
|
+
public void exportCachedEvents(final Promise promise) {
|
|
240
|
+
wrapperSessionExportCachedEventsPromise = promise;
|
|
241
|
+
WrapperSessionProvider.requestExportCachedEvents();
|
|
242
|
+
}
|
|
365
243
|
|
|
366
|
-
|
|
244
|
+
@ReactMethod
|
|
245
|
+
public void tryStopScan(String scanStopRequestParams) {
|
|
246
|
+
WrapperSessionProvider.requestScanStop(scanStopRequestParams);
|
|
367
247
|
}
|
|
368
248
|
|
|
369
249
|
@Override
|
|
@@ -384,13 +264,15 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
|
|
|
384
264
|
private void returnError(String error) {
|
|
385
265
|
switch (this.returnMethod) {
|
|
386
266
|
case "callback":
|
|
387
|
-
if (
|
|
388
|
-
|
|
389
|
-
|
|
267
|
+
if (scanResponseErrorCallback != null) {
|
|
268
|
+
scanResponseErrorCallback.invoke(error);
|
|
269
|
+
scanResponseErrorCallback = null;
|
|
390
270
|
}
|
|
391
271
|
break;
|
|
392
272
|
case "promise":
|
|
393
|
-
|
|
273
|
+
if (wrapperSessionScanResponsePromise != null) {
|
|
274
|
+
wrapperSessionScanResponsePromise.reject(E_ERROR, error);
|
|
275
|
+
}
|
|
394
276
|
break;
|
|
395
277
|
default:
|
|
396
278
|
break;
|
|
@@ -400,16 +282,121 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
|
|
|
400
282
|
private void returnSuccess(String result) {
|
|
401
283
|
switch (this.returnMethod) {
|
|
402
284
|
case "callback":
|
|
403
|
-
if (
|
|
404
|
-
|
|
405
|
-
|
|
285
|
+
if (scanResponseResultCallback != null) {
|
|
286
|
+
scanResponseResultCallback.invoke(result);
|
|
287
|
+
scanResponseResultCallback = null;
|
|
406
288
|
}
|
|
407
289
|
break;
|
|
408
290
|
case "promise":
|
|
409
|
-
|
|
291
|
+
if (wrapperSessionScanResponsePromise != null) {
|
|
292
|
+
wrapperSessionScanResponsePromise.resolve(result);
|
|
293
|
+
}
|
|
410
294
|
break;
|
|
411
295
|
default:
|
|
412
296
|
break;
|
|
413
297
|
}
|
|
414
298
|
}
|
|
299
|
+
|
|
300
|
+
private void sendEvent(String eventName, Object params) {
|
|
301
|
+
reactContext
|
|
302
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
303
|
+
.emit(eventName, params);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
@Override
|
|
307
|
+
public @NotNull Context getContext() {
|
|
308
|
+
return this.reactContext;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
@Override
|
|
312
|
+
public void onSdkInitializationResponse(@NotNull WrapperSessionSdkInitializationResponse initializationResponse) {
|
|
313
|
+
JSONObject json =
|
|
314
|
+
WrapperSessionSdkInitializationResponseExtensionKt.toJsonObject(initializationResponse);
|
|
315
|
+
|
|
316
|
+
if (wrapperSessionSdkInitializationResponsePromise != null) {
|
|
317
|
+
if (initializationResponse.getInitialized() == Boolean.TRUE) {
|
|
318
|
+
wrapperSessionSdkInitializationResponsePromise.resolve(true);
|
|
319
|
+
} else {
|
|
320
|
+
wrapperSessionSdkInitializationResponsePromise.reject(E_ERROR, json.toString());
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
@Override
|
|
326
|
+
public void onScanResults(@NotNull WrapperSessionScanResultsResponse scanResultsResponse) {
|
|
327
|
+
WrapperSessionScanResultConfig scanResultConfig = scanResultsResponse.getScanResultConfig();
|
|
328
|
+
List<ExportedScanResult> scanResultList = scanResultsResponse.getExportedScanResults();
|
|
329
|
+
WrapperSessionScanResultExtraInfo scanResultExtraInfo = scanResultsResponse.getScanResultExtraInfo();
|
|
330
|
+
try {
|
|
331
|
+
String resultsWithImagePathString = LegacyPluginHelper
|
|
332
|
+
.getScanResultsWithImagePath(scanResultList, scanResultExtraInfo.getViewPluginType());
|
|
333
|
+
|
|
334
|
+
if (scanResultConfig.getCallbackConfig() != null
|
|
335
|
+
&& scanResultConfig.getCallbackConfig().getOnResultEventName() != null) {
|
|
336
|
+
sendEvent(
|
|
337
|
+
scanResultConfig.getCallbackConfig().getOnResultEventName(),
|
|
338
|
+
resultsWithImagePathString);
|
|
339
|
+
} else {
|
|
340
|
+
ResultReporter.onResult(resultsWithImagePathString, true);
|
|
341
|
+
}
|
|
342
|
+
} catch (Exception e) {
|
|
343
|
+
//exception will not be handled here
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
@Override
|
|
348
|
+
public void onUIElementClicked(@NonNull WrapperSessionScanResultConfig scanResultConfig,
|
|
349
|
+
@NonNull UIFeedbackElementConfig uiFeedbackElementConfig) {
|
|
350
|
+
if (scanResultConfig.getCallbackConfig() != null
|
|
351
|
+
&& scanResultConfig.getCallbackConfig().getOnUIElementClickedEventName() != null) {
|
|
352
|
+
sendEvent(
|
|
353
|
+
scanResultConfig.getCallbackConfig().getOnUIElementClickedEventName(),
|
|
354
|
+
UIFeedbackElementConfigExtensionKt.toJsonObject(uiFeedbackElementConfig).toString());
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
@Override
|
|
359
|
+
public void onScanResponse(@NotNull WrapperSessionScanResponse scanResponse) {
|
|
360
|
+
if (scanResponse.getStatus() != null) {
|
|
361
|
+
switch (scanResponse.getStatus()) {
|
|
362
|
+
case SCAN_SUCCEEDED:
|
|
363
|
+
WrapperSessionScanResultConfig scanResultConfig = scanResponse.getScanResultConfig();
|
|
364
|
+
if (scanResultConfig.getCallbackConfig() != null
|
|
365
|
+
&& scanResultConfig.getCallbackConfig().getOnResultEventName() != null) {
|
|
366
|
+
ResultReporter.onResult("", true);
|
|
367
|
+
}
|
|
368
|
+
break;
|
|
369
|
+
case SCAN_FAILED:
|
|
370
|
+
ResultReporter.onError(scanResponse.getFailInfo().getLastError());
|
|
371
|
+
break;
|
|
372
|
+
case SCAN_ABORTED:
|
|
373
|
+
ResultReporter.onCancel();
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
@Override
|
|
380
|
+
public void onUCRReportResponse(@NotNull WrapperSessionUCRReportResponse ucrReportResponse) {
|
|
381
|
+
if (ucrReportResponse.getStatus() == WrapperSessionUCRReportResponse.WrapperSessionUCRReportResponseStatus.UCR_REPORT_SUCCEEDED) {
|
|
382
|
+
reportCorrectedResultResponseCallback.invoke(ucrReportResponse.getSucceedInfo().getMessage());
|
|
383
|
+
} else {
|
|
384
|
+
reportCorrectedResultErrorCallback.invoke(LegacyPluginHelper
|
|
385
|
+
.getWrapperSessionUCRReportResponseFailMessage(ucrReportResponse.getFailInfo()));
|
|
386
|
+
}
|
|
387
|
+
reportCorrectedResultResponseCallback = null;
|
|
388
|
+
reportCorrectedResultErrorCallback = null;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
@Override
|
|
392
|
+
public void onExportCachedEventsResponse(@NotNull WrapperSessionExportCachedEventsResponse exportCachedEventsResponse) {
|
|
393
|
+
if (exportCachedEventsResponse.getStatus() == WrapperSessionExportCachedEventsResponse.WrapperSessionExportCachedEventsResponseStatus.EXPORT_SUCCEEDED) {
|
|
394
|
+
WrapperSessionExportCachedEventsResponseSucceed exportCachedEventsSucceed = exportCachedEventsResponse.getSucceedInfo();
|
|
395
|
+
wrapperSessionExportCachedEventsPromise.resolve(exportCachedEventsSucceed.getExportedFile());
|
|
396
|
+
} else {
|
|
397
|
+
WrapperSessionExportCachedEventsResponseFail exportCachedEventsFail = exportCachedEventsResponse.getFailInfo();
|
|
398
|
+
wrapperSessionExportCachedEventsPromise.reject(E_ERROR, exportCachedEventsFail.getLastError());
|
|
399
|
+
}
|
|
400
|
+
wrapperSessionExportCachedEventsPromise = null;
|
|
401
|
+
}
|
|
415
402
|
}
|