anyline-ocr-react-native-module 55.2.0 → 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/{ios/AnylineReact.podspec → AnylineReact.podspec} +3 -3
- package/android/build.gradle +1 -3
- package/android/src/main/AndroidManifest.xml +1 -3
- package/android/src/main/java/com/anyline/reactnative/AnylineSDKPlugin.java +251 -252
- package/index.js +3 -16
- package/ios/AnylineSDKPlugin.h +4 -4
- package/ios/AnylineSDKPlugin.m +285 -207
- package/package.json +12 -2
- package/android/.gradle/7.6/checksums/checksums.lock +0 -0
- package/android/.gradle/7.6/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/7.6/checksums/sha1-checksums.bin +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/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/7.6/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.6/fileHashes/fileHashes.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/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.gradle/config.properties +0 -2
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.idea/PipelineViewerConfig.xml +0 -6
- package/android/.idea/appInsightsSettings.xml +0 -28
- package/android/.idea/caches/deviceStreaming.xml +0 -486
- package/android/.idea/compiler.xml +0 -6
- package/android/.idea/gradle.xml +0 -19
- package/android/.idea/jarRepositories.xml +0 -30
- package/android/.idea/material_theme_project_new.xml +0 -13
- package/android/.idea/migrations.xml +0 -10
- package/android/.idea/misc.xml +0 -9
- package/android/.idea/runConfigurations.xml +0 -17
- package/android/.idea/vcs.xml +0 -6
- package/android/local.properties +0 -8
- 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require "json"
|
|
2
2
|
|
|
3
|
-
package = JSON.parse(File.read(File.join(__dir__, "
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
4
|
|
|
5
5
|
Pod::Spec.new do |s|
|
|
6
6
|
s.name = "AnylineReact"
|
|
@@ -17,8 +17,8 @@ Pod::Spec.new do |s|
|
|
|
17
17
|
|
|
18
18
|
s.source = { :git => "https://github.com/Anyline/anyline-ocr-react-native-module.git", :tag => "#{s.version}" }
|
|
19
19
|
|
|
20
|
-
s.source_files
|
|
21
|
-
s.dependency "Anyline", "55.
|
|
20
|
+
s.source_files = 'ios/**/*.{h,m,swift}'
|
|
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,71 +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
|
+
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;
|
|
53
|
+
// We're creating a static variable to store the last license used to initialize the SDK
|
|
54
|
+
private static String license;
|
|
55
|
+
|
|
56
|
+
private static boolean isInitializedWithLicenseKey(String requestedLicense) {
|
|
57
|
+
return (license != null
|
|
58
|
+
&& WrapperSessionProvider.getCurrentSdkInitializationResponse().getInitialized() == Boolean.TRUE
|
|
59
|
+
&& license.equals(requestedLicense));
|
|
40
60
|
}
|
|
41
61
|
|
|
42
62
|
public static final String REACT_CLASS = "AnylineSDKPlugin";
|
|
43
|
-
public static final String EXTRA_CONFIG_JSON = "EXTRA_CONFIG_JSON";
|
|
44
|
-
public static final String EXTRA_SCANVIEW_INITIALIZATION_PARAMETERS = "EXTRA_SCANVIEW_INITIALIZATION_PARAMETERS";
|
|
45
|
-
public static final String EXTRA_SCAN_MODE = "EXTRA_SCAN_MODE";
|
|
46
|
-
public static final String EXTRA_ERROR_MESSAGE = "EXTRA_ERROR_MESSAGE";
|
|
47
|
-
public static final String EXTRA_OCR_CONFIG_JSON = "EXTRA_OCR_CONFIG_JSON";
|
|
48
|
-
public static final String EXTRA_ENABLE_BARCODE_SCANNING = "EXTRA_ENABLE_BARCODE_SCANNING";
|
|
49
|
-
|
|
50
|
-
public static final int RESULT_CANCELED = 0;
|
|
51
|
-
public static final int RESULT_OK = 1;
|
|
52
|
-
public static final int RESULT_ERROR = 2;
|
|
53
63
|
private static final String E_ERROR = "E_ERROR";
|
|
54
|
-
|
|
55
|
-
private ReactApplicationContext reactContext;
|
|
56
|
-
|
|
57
|
-
private JSONObject options;
|
|
58
|
-
private Callback onResultCallback;
|
|
59
|
-
private Callback onErrorCallback;
|
|
60
|
-
private Promise promise;
|
|
64
|
+
|
|
65
|
+
private final ReactApplicationContext reactContext;
|
|
66
|
+
|
|
61
67
|
private String returnMethod;
|
|
62
|
-
private String config;
|
|
63
|
-
private String scanViewInitializationParameters;
|
|
64
|
-
private AssetContextJsonParser assetContextJsonParser;
|
|
65
68
|
|
|
66
|
-
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;
|
|
67
79
|
|
|
68
80
|
AnylineSDKPlugin(ReactApplicationContext context) {
|
|
69
81
|
super(context);
|
|
70
82
|
this.reactContext = context;
|
|
71
|
-
this.assetContextJsonParser = new AssetContextJsonParser();
|
|
72
83
|
ContextProvider.setInstance(context);
|
|
73
84
|
}
|
|
74
85
|
|
|
@@ -83,59 +94,37 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
|
|
|
83
94
|
}
|
|
84
95
|
|
|
85
96
|
@ReactMethod
|
|
86
|
-
protected void
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
);
|
|
97
|
+
protected void setupWrapperSession(final String pluginVersion) {
|
|
98
|
+
WrapperInfo wrapperInfo = new WrapperInfo(WrapperInfo.WrapperType.ReactNative, pluginVersion);
|
|
99
|
+
WrapperSessionProvider.setupWrapperSession(wrapperInfo,this);
|
|
90
100
|
}
|
|
91
101
|
|
|
92
102
|
@ReactMethod
|
|
93
103
|
public void licenseKeyExpiryDate(final Promise promise) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
+
}
|
|
99
111
|
}
|
|
112
|
+
promise.reject(E_ERROR, "Anyline SDK was not initialized");
|
|
100
113
|
}
|
|
101
114
|
|
|
102
115
|
@ReactMethod
|
|
103
116
|
public void isInitialized(final Promise promise) {
|
|
104
|
-
promise.resolve(
|
|
117
|
+
promise.resolve(WrapperSessionProvider.getCurrentSdkInitializationResponse().getInitialized());
|
|
105
118
|
}
|
|
106
119
|
|
|
107
120
|
@ReactMethod
|
|
108
121
|
@Deprecated
|
|
109
122
|
public void setupScanViewWithConfigJson(String config, String scanMode, Callback onResultReact, Callback onErrorReact) {
|
|
110
|
-
|
|
111
|
-
|
|
123
|
+
scanResponseResultCallback = onResultReact;
|
|
124
|
+
scanResponseErrorCallback = onErrorReact;
|
|
112
125
|
this.returnMethod = "callback";
|
|
113
|
-
this.config = config;
|
|
114
126
|
|
|
115
|
-
routeScanMode(
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
@ReactMethod
|
|
119
|
-
public void update(
|
|
120
|
-
String assetContextJson,
|
|
121
|
-
Callback onUpdateError,
|
|
122
|
-
Callback onUpdateFinished
|
|
123
|
-
) {
|
|
124
|
-
try {
|
|
125
|
-
AssetContext assetContext = assetContextJsonParser.parseJson(reactContext, assetContextJson);
|
|
126
|
-
|
|
127
|
-
if (assetContext != null) {
|
|
128
|
-
AnylineUpdater.update(
|
|
129
|
-
reactContext,
|
|
130
|
-
assetContext,
|
|
131
|
-
new AnylineUpdateDelegateImpl(reactContext, onUpdateError, onUpdateFinished),
|
|
132
|
-
PluginType.OCR
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
} catch (JSONException e) {
|
|
136
|
-
e.printStackTrace();
|
|
137
|
-
returnError(e.getMessage());
|
|
138
|
-
}
|
|
127
|
+
routeScanMode(config, null, null, null);
|
|
139
128
|
}
|
|
140
129
|
|
|
141
130
|
@ReactMethod
|
|
@@ -145,22 +134,12 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
|
|
|
145
134
|
|
|
146
135
|
@ReactMethod
|
|
147
136
|
public void setupAnylineSDKWithCacheConfig(String license, boolean enableOfflineCache, final Promise promise) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
try {
|
|
153
|
-
AnylineSdk.init(license, reactContext, "", cacheConfig, wrapperConfig);
|
|
154
|
-
this.license = license;
|
|
155
|
-
if (promise != null) {
|
|
156
|
-
promise.resolve(true);
|
|
157
|
-
}
|
|
158
|
-
} catch (LicenseException e) {
|
|
159
|
-
e.printStackTrace();
|
|
160
|
-
if (promise != null) {
|
|
161
|
-
promise.reject(E_ERROR, e.getMessage());
|
|
162
|
-
}
|
|
137
|
+
if (isInitializedWithLicenseKey(license)) {
|
|
138
|
+
promise.resolve(true);
|
|
139
|
+
return;
|
|
163
140
|
}
|
|
141
|
+
wrapperSessionSdkInitializationResponsePromise = promise;
|
|
142
|
+
initSdkWithCacheConfig(license, enableOfflineCache);
|
|
164
143
|
}
|
|
165
144
|
|
|
166
145
|
@ReactMethod
|
|
@@ -170,188 +149,101 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
|
|
|
170
149
|
|
|
171
150
|
@ReactMethod
|
|
172
151
|
public void initSdkWithCacheConfig(String license, boolean enableOfflineCache) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
cacheConfig = CacheConfig.Preset.OfflineLicenseEventCachingEnabled.INSTANCE;
|
|
176
|
-
}
|
|
177
|
-
try {
|
|
178
|
-
AnylineSdk.init(license, reactContext, "", cacheConfig, wrapperConfig);
|
|
179
|
-
} catch (LicenseException e) {
|
|
180
|
-
e.printStackTrace();
|
|
181
|
-
returnError(e.getMessage());
|
|
152
|
+
if (isInitializedWithLicenseKey(license)) {
|
|
153
|
+
return;
|
|
182
154
|
}
|
|
183
|
-
|
|
155
|
+
AnylineSDKPlugin.license = license;
|
|
184
156
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
157
|
+
JSONObject wrapperSessionSdkInitializationRequestJson =
|
|
158
|
+
LegacyPluginHelper.getWrapperSessionSdkInitializationRequestJson(license, enableOfflineCache, null);
|
|
159
|
+
|
|
160
|
+
WrapperSessionProvider.requestSdkInitialization(
|
|
161
|
+
wrapperSessionSdkInitializationRequestJson.toString());
|
|
188
162
|
}
|
|
189
163
|
|
|
190
164
|
@ReactMethod
|
|
191
165
|
public void setup(String config, String scanMode, Callback onResultReact, Callback onErrorReact) {
|
|
192
166
|
setupWithInitializationParameters(null, config, scanMode, onResultReact, onErrorReact);
|
|
193
167
|
}
|
|
194
|
-
|
|
195
168
|
@ReactMethod
|
|
196
|
-
public void setupWithInitializationParameters(String
|
|
197
|
-
|
|
198
|
-
|
|
169
|
+
public void setupWithInitializationParameters(String scanViewInitializationParametersString, String config, String scanMode, Callback onResultReact, Callback onErrorReact) {
|
|
170
|
+
scanResponseResultCallback = onResultReact;
|
|
171
|
+
scanResponseErrorCallback = onErrorReact;
|
|
199
172
|
this.returnMethod = "callback";
|
|
200
|
-
this.config = config;
|
|
201
|
-
this.scanViewInitializationParameters = initializationParameters;
|
|
202
173
|
|
|
203
|
-
routeScanMode(
|
|
174
|
+
routeScanMode(config, scanViewInitializationParametersString, null, null);
|
|
204
175
|
}
|
|
205
|
-
|
|
206
176
|
@ReactMethod
|
|
207
|
-
public void
|
|
208
|
-
|
|
209
|
-
String correctedResultReturn = ScanResult.reportCorrectedResultFromBlobKey(blobKey, correctedResult);
|
|
210
|
-
try {
|
|
211
|
-
JSONObject correctedResultJson = new JSONObject(correctedResultReturn);
|
|
212
|
-
int correctedResultCode = correctedResultJson.optInt("code", 0);
|
|
213
|
-
String correctedResultMessage = correctedResultJson.optString("message");
|
|
214
|
-
if (correctedResultCode == 200) {
|
|
215
|
-
String correctedResultInternalMessage = "";
|
|
216
|
-
if (correctedResultMessage != null) {
|
|
217
|
-
correctedResultInternalMessage = new JSONObject(correctedResultMessage).optString("message");
|
|
218
|
-
}
|
|
219
|
-
onResponseCallback.invoke(correctedResultInternalMessage);
|
|
220
|
-
} else {
|
|
221
|
-
onErrorCallback.invoke(correctedResultMessage);
|
|
222
|
-
}
|
|
223
|
-
} catch (JSONException e) {
|
|
224
|
-
onErrorCallback.invoke(e.getMessage());
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
catch (IllegalArgumentException e) {
|
|
228
|
-
onErrorCallback.invoke(e.getMessage());
|
|
229
|
-
}
|
|
177
|
+
public void setupPromise(String config, String scanMode, final Promise promise) {
|
|
178
|
+
setupPromiseWithInitializationParameters(null, config, scanMode, promise);
|
|
230
179
|
}
|
|
231
|
-
|
|
232
180
|
@ReactMethod
|
|
233
|
-
public void
|
|
234
|
-
|
|
235
|
-
String exportedFile = AnylineSdk.exportCachedEvents();
|
|
236
|
-
if (exportedFile != null) {
|
|
237
|
-
if (promise != null) {
|
|
238
|
-
promise.resolve(String.valueOf(exportedFile));
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
if (promise != null) {
|
|
243
|
-
promise.reject(E_ERROR, "Event cache is empty.");
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
} catch (IOException e) {
|
|
247
|
-
if (promise != null) {
|
|
248
|
-
promise.reject(E_ERROR, e.getMessage());
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* This function removes all previous scan result images from disk, either from external
|
|
255
|
-
* or internal files dir, e.g.:
|
|
256
|
-
* /sdcard/Android/[applicationId]/files/results/image1729849635965
|
|
257
|
-
*/
|
|
258
|
-
private void deleteAllPreviousScanResultImages() {
|
|
259
|
-
String imagePath = "";
|
|
260
|
-
if (reactContext.getExternalFilesDir(null) != null) {
|
|
261
|
-
imagePath = reactContext
|
|
262
|
-
.getExternalFilesDir(null)
|
|
263
|
-
.toString() + "/results/";
|
|
264
|
-
|
|
265
|
-
} else if (reactContext.getFilesDir() != null) {
|
|
266
|
-
imagePath = reactContext
|
|
267
|
-
.getFilesDir()
|
|
268
|
-
.toString() + "/results/";
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
File resultFolder = new File(imagePath);
|
|
272
|
-
File[] files = resultFolder.listFiles();
|
|
273
|
-
if (files != null) {
|
|
274
|
-
for (int fileIndex = 0; fileIndex < files.length; fileIndex++) {
|
|
275
|
-
if (files[fileIndex].getName().startsWith("image")) {
|
|
276
|
-
files[fileIndex].delete();
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
181
|
+
public void setupPromiseWithScanCallbackConfig(String config, String scanMode, String scanCallbackConfigString, final Promise promise) {
|
|
182
|
+
setupPromiseWithInitializationParametersAndScanCallbackConfig(null, config, scanMode, scanCallbackConfigString, promise);
|
|
280
183
|
}
|
|
281
|
-
|
|
282
184
|
@ReactMethod
|
|
283
|
-
public void
|
|
284
|
-
|
|
185
|
+
public void setupPromiseWithInitializationParameters(String initializationParametersString, String config, String scanMode, final Promise promise) {
|
|
186
|
+
setupPromiseWithInitializationParametersAndScanCallbackConfig(initializationParametersString, config, scanMode, null, promise);
|
|
285
187
|
}
|
|
286
188
|
@ReactMethod
|
|
287
|
-
public void
|
|
288
|
-
this.
|
|
189
|
+
public void setupPromiseWithInitializationParametersAndScanCallbackConfig(String initializationParametersString, String config, String scanMode, String scanCallbackConfigString, final Promise promise) {
|
|
190
|
+
this.wrapperSessionScanResponsePromise = promise;
|
|
289
191
|
this.returnMethod = "promise";
|
|
290
|
-
this.config = config;
|
|
291
|
-
this.scanViewInitializationParameters = initializationParameters;
|
|
292
192
|
|
|
293
|
-
|
|
294
|
-
routeScanMode(scanMode);
|
|
193
|
+
routeScanMode(config, initializationParametersString, null, scanCallbackConfigString);
|
|
295
194
|
}
|
|
296
195
|
|
|
297
|
-
private void routeScanMode(
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
returnError("Wrong ScanMode");
|
|
304
|
-
}
|
|
305
|
-
}
|
|
196
|
+
private void routeScanMode(
|
|
197
|
+
String scanViewConfigContent,
|
|
198
|
+
String scanViewInitializationParametersString,
|
|
199
|
+
String scanViewConfigPath,
|
|
200
|
+
String scanCallbackConfigString) {
|
|
201
|
+
boolean shouldReturnImages = true;
|
|
306
202
|
|
|
307
|
-
|
|
203
|
+
WrapperSessionScanStartRequest wrapperSessionScanRequest;
|
|
308
204
|
try {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
returnError("
|
|
318
|
-
|
|
319
|
-
e.printStackTrace();
|
|
320
|
-
returnError("JSON ERROR: " + e.getMessage());
|
|
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;
|
|
321
215
|
}
|
|
322
|
-
}
|
|
323
216
|
|
|
324
|
-
|
|
217
|
+
JSONObject wrapperSessionScanStartRequestJson
|
|
218
|
+
= WrapperSessionScanStartRequestExtensionKt.toJsonObject(wrapperSessionScanRequest);
|
|
325
219
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
if (!AnylineSdk.isInitialized()) {
|
|
329
|
-
if (this.license != null) {
|
|
330
|
-
AnylineSdk.init(this.license, reactContext, "", CacheConfig.Preset.Default.INSTANCE, wrapperConfig);
|
|
331
|
-
}
|
|
332
|
-
else {
|
|
333
|
-
throw new JSONException("SDK is not initialized. Please initialize SDK before scanning.");
|
|
334
|
-
}
|
|
335
|
-
}
|
|
220
|
+
WrapperSessionProvider.requestScanStart(wrapperSessionScanStartRequestJson.toString());
|
|
336
221
|
|
|
337
|
-
|
|
222
|
+
ResultReporter.setListener(this);
|
|
223
|
+
}
|
|
338
224
|
|
|
339
|
-
|
|
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);
|
|
340
231
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
EXTRA_ENABLE_BARCODE_SCANNING,
|
|
344
|
-
optionsJSONObject.optBoolean("nativeBarcodeEnabled", false)
|
|
345
|
-
);
|
|
346
|
-
}
|
|
232
|
+
JSONObject wrapperSessionUCRReportRequestJson = WrapperSessionUCRReportRequestExtensionKt
|
|
233
|
+
.toJsonObject(wrapperSessionUCRReportRequest);
|
|
347
234
|
|
|
348
|
-
|
|
349
|
-
|
|
235
|
+
WrapperSessionProvider.requestUCRReport(wrapperSessionUCRReportRequestJson.toString());
|
|
236
|
+
}
|
|
350
237
|
|
|
351
|
-
|
|
352
|
-
|
|
238
|
+
@ReactMethod
|
|
239
|
+
public void exportCachedEvents(final Promise promise) {
|
|
240
|
+
wrapperSessionExportCachedEventsPromise = promise;
|
|
241
|
+
WrapperSessionProvider.requestExportCachedEvents();
|
|
242
|
+
}
|
|
353
243
|
|
|
354
|
-
|
|
244
|
+
@ReactMethod
|
|
245
|
+
public void tryStopScan(String scanStopRequestParams) {
|
|
246
|
+
WrapperSessionProvider.requestScanStop(scanStopRequestParams);
|
|
355
247
|
}
|
|
356
248
|
|
|
357
249
|
@Override
|
|
@@ -372,13 +264,15 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
|
|
|
372
264
|
private void returnError(String error) {
|
|
373
265
|
switch (this.returnMethod) {
|
|
374
266
|
case "callback":
|
|
375
|
-
if (
|
|
376
|
-
|
|
377
|
-
|
|
267
|
+
if (scanResponseErrorCallback != null) {
|
|
268
|
+
scanResponseErrorCallback.invoke(error);
|
|
269
|
+
scanResponseErrorCallback = null;
|
|
378
270
|
}
|
|
379
271
|
break;
|
|
380
272
|
case "promise":
|
|
381
|
-
|
|
273
|
+
if (wrapperSessionScanResponsePromise != null) {
|
|
274
|
+
wrapperSessionScanResponsePromise.reject(E_ERROR, error);
|
|
275
|
+
}
|
|
382
276
|
break;
|
|
383
277
|
default:
|
|
384
278
|
break;
|
|
@@ -388,16 +282,121 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
|
|
|
388
282
|
private void returnSuccess(String result) {
|
|
389
283
|
switch (this.returnMethod) {
|
|
390
284
|
case "callback":
|
|
391
|
-
if (
|
|
392
|
-
|
|
393
|
-
|
|
285
|
+
if (scanResponseResultCallback != null) {
|
|
286
|
+
scanResponseResultCallback.invoke(result);
|
|
287
|
+
scanResponseResultCallback = null;
|
|
394
288
|
}
|
|
395
289
|
break;
|
|
396
290
|
case "promise":
|
|
397
|
-
|
|
291
|
+
if (wrapperSessionScanResponsePromise != null) {
|
|
292
|
+
wrapperSessionScanResponsePromise.resolve(result);
|
|
293
|
+
}
|
|
398
294
|
break;
|
|
399
295
|
default:
|
|
400
296
|
break;
|
|
401
297
|
}
|
|
402
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
|
+
}
|
|
403
402
|
}
|