anyline-ocr-react-native-module 55.2.1 → 55.6.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.
Files changed (51) hide show
  1. package/AnylineReact.podspec +1 -1
  2. package/android/build.gradle +1 -3
  3. package/android/src/main/AndroidManifest.xml +1 -3
  4. package/android/src/main/java/com/anyline/reactnative/AnylineSDKPlugin.java +248 -254
  5. package/index.js +1 -15
  6. package/ios/AnylineSDKPlugin.h +4 -4
  7. package/ios/AnylineSDKPlugin.m +278 -211
  8. package/package.json +1 -1
  9. package/android/.gradle/7.6/checksums/checksums.lock +0 -0
  10. package/android/.gradle/7.6/dependencies-accessors/dependencies-accessors.lock +0 -0
  11. package/android/.gradle/7.6/dependencies-accessors/gc.properties +0 -0
  12. package/android/.gradle/7.6/fileChanges/last-build.bin +0 -0
  13. package/android/.gradle/7.6/fileHashes/fileHashes.lock +0 -0
  14. package/android/.gradle/7.6/gc.properties +0 -0
  15. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  16. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  17. package/android/.gradle/vcs-1/gc.properties +0 -0
  18. package/android/src/main/java/com/anyline/reactnative/FeedbackConfig.java +0 -59
  19. package/android/src/main/java/com/anyline/reactnative/ImageTextConfig.java +0 -49
  20. package/android/src/main/java/com/anyline/reactnative/InstructionConfig.java +0 -20
  21. package/android/src/main/java/com/anyline/reactnative/Offset.java +0 -21
  22. package/android/src/main/java/com/anyline/reactnative/RotateButtonConfig.java +0 -32
  23. package/android/src/main/java/com/anyline/reactnative/ScanActivity.java +0 -426
  24. package/android/src/main/java/com/anyline/reactnative/updateAsset/AnylineUpdateDelegateImpl.java +0 -50
  25. package/android/src/main/java/com/anyline/reactnative/updateAsset/AssetContextJsonParser.java +0 -28
  26. package/android/src/main/res/drawable/rotate_screen_background.xml +0 -18
  27. package/android/src/main/res/drawable/rotate_screen_white.png +0 -0
  28. package/android/src/main/res/drawable-hdpi/ic_flash_auto.png +0 -0
  29. package/android/src/main/res/drawable-hdpi/ic_flash_off.png +0 -0
  30. package/android/src/main/res/drawable-hdpi/ic_flash_on.png +0 -0
  31. package/android/src/main/res/drawable-mdpi/ic_flash_auto.png +0 -0
  32. package/android/src/main/res/drawable-mdpi/ic_flash_off.png +0 -0
  33. package/android/src/main/res/drawable-mdpi/ic_flash_on.png +0 -0
  34. package/android/src/main/res/drawable-xhdpi/ic_flash_auto.png +0 -0
  35. package/android/src/main/res/drawable-xhdpi/ic_flash_off.png +0 -0
  36. package/android/src/main/res/drawable-xhdpi/ic_flash_on.png +0 -0
  37. package/android/src/main/res/drawable-xxhdpi/ic_flash_auto.png +0 -0
  38. package/android/src/main/res/drawable-xxhdpi/ic_flash_off.png +0 -0
  39. package/android/src/main/res/drawable-xxhdpi/ic_flash_on.png +0 -0
  40. package/android/src/main/res/drawable-xxxhdpi/ic_flash_auto.png +0 -0
  41. package/android/src/main/res/drawable-xxxhdpi/ic_flash_off.png +0 -0
  42. package/android/src/main/res/drawable-xxxhdpi/ic_flash_on.png +0 -0
  43. package/android/src/main/res/layout/activity_scan.xml +0 -93
  44. package/ios/ALJsonUIConfiguration.h +0 -54
  45. package/ios/ALJsonUIConfiguration.m +0 -251
  46. package/ios/ALPluginHelper.h +0 -48
  47. package/ios/ALPluginHelper.m +0 -332
  48. package/ios/ALPluginScanViewController.h +0 -18
  49. package/ios/ALPluginScanViewController.m +0 -476
  50. package/ios/ALRoundedView.h +0 -25
  51. package/ios/ALRoundedView.m +0 -107
@@ -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.2.1"
21
+ s.dependency "Anyline", "55.6.0"
22
22
  s.dependency "React"
23
23
 
24
24
  end
@@ -61,8 +61,6 @@ repositories {
61
61
 
62
62
  dependencies {
63
63
  implementation fileTree(dir: "libs", include: ["*.jar"])
64
- implementation 'io.anyline:anylinesdk:55.2.1'
64
+ implementation 'io.anyline:anylinesdk:55.6.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
  }
@@ -6,8 +6,6 @@
6
6
  <uses-permission android:name="android.permission.CAMERA" />
7
7
 
8
8
  <application>
9
- <activity
10
- android:name=".ScanActivity"
11
- android:screenOrientation="portrait" />
9
+
12
10
  </application>
13
11
  </manifest>
@@ -4,79 +4,84 @@ package com.anyline.reactnative;
4
4
  * Created by jonesBoi on 02.12.16.
5
5
  */
6
6
 
7
- import android.content.Intent;
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.json.JSONException;
19
+ import org.jetbrains.annotations.NotNull;
18
20
  import org.json.JSONObject;
19
21
 
20
- import java.io.File;
21
- import java.io.IOException;
22
- import java.util.HashMap;
23
-
24
- import io.anyline2.WrapperConfig;
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.legacy.products.AnylineUpdater;
29
- import io.anyline2.legacy.trainer.AssetContext;
30
- import io.anyline2.AnylineSdk;
31
- import io.anyline2.CacheConfig;
32
- import io.anyline2.ScanResult;
33
- import io.anyline2.core.LicenseException;
34
-
35
- class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultReporter.OnResultListener {
36
-
37
- static {
38
- System.loadLibrary("opencv_java3_al");
39
- System.loadLibrary("anylineCore");
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 && AnylineSdk.isInitialized() && license.equals(requestedLicense));
57
+ return (license != null
58
+ && WrapperSessionProvider.getCurrentSdkInitializationResponse().getInitialized() == Boolean.TRUE
59
+ && license.equals(requestedLicense));
49
60
  }
50
61
 
62
+ private static String scanViewConfigPathString = null;
63
+
51
64
  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
65
  private static final String E_ERROR = "E_ERROR";
63
- private JSONObject configObject;
64
- private ReactApplicationContext reactContext;
65
- private JSONObject options;
66
- private Callback onResultCallback;
67
- private Callback onErrorCallback;
68
- private Promise promise;
66
+
67
+ private final ReactApplicationContext reactContext;
68
+
69
69
  private String returnMethod;
70
- private String config;
71
- private String scanViewInitializationParameters;
72
- private AssetContextJsonParser assetContextJsonParser;
73
70
 
74
- private static WrapperConfig wrapperConfig;
71
+ private Promise wrapperSessionSdkInitializationResponsePromise = null;
72
+
73
+ private Promise wrapperSessionScanResponsePromise = null;
74
+ private Callback scanResponseResultCallback = null;
75
+ private Callback scanResponseErrorCallback = null;
76
+
77
+ private Promise wrapperSessionExportCachedEventsPromise = null;
78
+
79
+ private Callback reportCorrectedResultResponseCallback = null;
80
+ private Callback reportCorrectedResultErrorCallback = null;
75
81
 
76
82
  AnylineSDKPlugin(ReactApplicationContext context) {
77
83
  super(context);
78
84
  this.reactContext = context;
79
- this.assetContextJsonParser = new AssetContextJsonParser();
80
85
  ContextProvider.setInstance(context);
81
86
  }
82
87
 
@@ -91,57 +96,42 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
91
96
  }
92
97
 
93
98
  @ReactMethod
94
- protected void setPluginVersion(final String pluginVersion) {
95
- wrapperConfig = new WrapperConfig.Wrapper(
96
- new WrapperInfo(WrapperInfo.WrapperType.ReactNative, pluginVersion)
97
- );
99
+ protected void setupWrapperSession(final String pluginVersion) {
100
+ WrapperInfo wrapperInfo = new WrapperInfo(WrapperInfo.WrapperType.ReactNative, pluginVersion);
101
+ WrapperSessionProvider.setupWrapperSession(wrapperInfo,this);
102
+ }
103
+
104
+ @ReactMethod
105
+ public void setViewConfigsPath(final String path) {
106
+ scanViewConfigPathString = path;
98
107
  }
99
108
 
100
109
  @ReactMethod
101
110
  public void licenseKeyExpiryDate(final Promise promise) {
102
- try {
103
- promise.resolve(String.valueOf(AnylineSdk.getExpiryDate()));
104
- } catch (LicenseException e) {
105
- promise.reject(E_ERROR, e.getMessage());
111
+ if (WrapperSessionProvider.getCurrentSdkInitializationResponse().getInitialized() == Boolean.TRUE) {
112
+ WrapperSessionSdkInitializationResponseInitialized sdkInitializationResponseInitialized
113
+ = WrapperSessionProvider.getCurrentSdkInitializationResponse().getSucceedInfo();
114
+ if (sdkInitializationResponseInitialized != null) {
115
+ promise.resolve(sdkInitializationResponseInitialized.getExpiryDate());
116
+ return;
117
+ }
106
118
  }
119
+ promise.reject(E_ERROR, "Anyline SDK was not initialized");
107
120
  }
108
121
 
109
122
  @ReactMethod
110
123
  public void isInitialized(final Promise promise) {
111
- promise.resolve(AnylineSdk.isInitialized());
124
+ promise.resolve(WrapperSessionProvider.getCurrentSdkInitializationResponse().getInitialized());
112
125
  }
113
126
 
114
127
  @ReactMethod
115
128
  @Deprecated
116
129
  public void setupScanViewWithConfigJson(String config, String scanMode, Callback onResultReact, Callback onErrorReact) {
117
- onResultCallback = onResultReact;
118
- onErrorCallback = onErrorReact;
130
+ scanResponseResultCallback = onResultReact;
131
+ scanResponseErrorCallback = onErrorReact;
119
132
  this.returnMethod = "callback";
120
- this.config = config;
121
-
122
- routeScanMode(scanMode);
123
- }
124
133
 
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
- }
134
+ routeScanMode(config, null, scanViewConfigPathString, null);
145
135
  }
146
136
 
147
137
  @ReactMethod
@@ -155,22 +145,8 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
155
145
  promise.resolve(true);
156
146
  return;
157
147
  }
158
-
159
- CacheConfig.Preset cacheConfig = CacheConfig.Preset.Default.INSTANCE;
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
- }
148
+ wrapperSessionSdkInitializationResponsePromise = promise;
149
+ initSdkWithCacheConfig(license, enableOfflineCache);
174
150
  }
175
151
 
176
152
  @ReactMethod
@@ -183,187 +159,98 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
183
159
  if (isInitializedWithLicenseKey(license)) {
184
160
  return;
185
161
  }
162
+ AnylineSDKPlugin.license = license;
186
163
 
187
- CacheConfig.Preset cacheConfig = CacheConfig.Preset.Default.INSTANCE;
188
- if (enableOfflineCache) {
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
- }
164
+ JSONObject wrapperSessionSdkInitializationRequestJson =
165
+ LegacyPluginHelper.getWrapperSessionSdkInitializationRequestJson(license, enableOfflineCache, null);
198
166
 
199
- @ReactMethod
200
- public void resetUpdate() {
201
- // TODO
167
+ WrapperSessionProvider.requestSdkInitialization(
168
+ wrapperSessionSdkInitializationRequestJson.toString());
202
169
  }
203
170
 
204
171
  @ReactMethod
205
172
  public void setup(String config, String scanMode, Callback onResultReact, Callback onErrorReact) {
206
173
  setupWithInitializationParameters(null, config, scanMode, onResultReact, onErrorReact);
207
174
  }
208
-
209
175
  @ReactMethod
210
- public void setupWithInitializationParameters(String initializationParameters, String config, String scanMode, Callback onResultReact, Callback onErrorReact) {
211
- onResultCallback = onResultReact;
212
- onErrorCallback = onErrorReact;
176
+ public void setupWithInitializationParameters(String scanViewInitializationParametersString, String config, String scanMode, Callback onResultReact, Callback onErrorReact) {
177
+ scanResponseResultCallback = onResultReact;
178
+ scanResponseErrorCallback = onErrorReact;
213
179
  this.returnMethod = "callback";
214
- this.config = config;
215
- this.scanViewInitializationParameters = initializationParameters;
216
180
 
217
- routeScanMode(scanMode);
181
+ routeScanMode(config, scanViewInitializationParametersString, scanViewConfigPathString, null);
218
182
  }
219
-
220
183
  @ReactMethod
221
- public void reportCorrectedResult(String blobKey, String correctedResult, Callback onResponseCallback, Callback onErrorCallback) {
222
- try {
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
- }
184
+ public void setupPromise(String config, String scanMode, final Promise promise) {
185
+ setupPromiseWithInitializationParameters(null, config, scanMode, promise);
244
186
  }
245
-
246
187
  @ReactMethod
247
- public void exportCachedEvents(final Promise promise) {
248
- try {
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
- }
188
+ public void setupPromiseWithScanCallbackConfig(String config, String scanMode, String scanCallbackConfigString, final Promise promise) {
189
+ setupPromiseWithInitializationParametersAndScanCallbackConfig(null, config, scanMode, scanCallbackConfigString, promise);
265
190
  }
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
191
  @ReactMethod
297
- public void setupPromise(String config, String scanMode, final Promise promise) {
298
- setupPromiseWithInitializationParameters(null, config, scanMode, promise);
192
+ public void setupPromiseWithInitializationParameters(String initializationParametersString, String config, String scanMode, final Promise promise) {
193
+ setupPromiseWithInitializationParametersAndScanCallbackConfig(initializationParametersString, config, scanMode, null, promise);
299
194
  }
300
195
  @ReactMethod
301
- public void setupPromiseWithInitializationParameters(String initializationParameters, String config, String scanMode, final Promise promise) {
302
- this.promise = promise;
196
+ public void setupPromiseWithInitializationParametersAndScanCallbackConfig(String initializationParametersString, String config, String scanMode, String scanCallbackConfigString, final Promise promise) {
197
+ this.wrapperSessionScanResponsePromise = promise;
303
198
  this.returnMethod = "promise";
304
- this.config = config;
305
- this.scanViewInitializationParameters = initializationParameters;
306
199
 
307
- deleteAllPreviousScanResultImages();
308
- routeScanMode(scanMode);
200
+ routeScanMode(config, initializationParametersString, scanViewConfigPathString, scanCallbackConfigString);
309
201
  }
310
202
 
311
- private void routeScanMode(String scanMode) {
312
- switch (scanMode) {
313
- case "scan": // > Anyline 4
314
- scanAnyline4();
315
- break;
316
- default:
317
- returnError("Wrong ScanMode");
318
- }
319
- }
203
+ private void routeScanMode(
204
+ String scanViewConfigContent,
205
+ String scanViewInitializationParametersString,
206
+ String scanViewConfigPath,
207
+ String scanCallbackConfigString) {
208
+ boolean shouldReturnImages = true;
320
209
 
321
- private void scanAnyline4() {
210
+ WrapperSessionScanStartRequest wrapperSessionScanRequest;
322
211
  try {
323
- configObject = new JSONObject(this.config);
324
- if (configObject != null) {
325
- scan();
326
- } else {
327
- returnError("No ViewPlugin in config. Please check your configuration.");
328
- }
329
- } catch (LicenseException e) {
330
- returnError("LICENSE ERROR: " + e.getMessage());
331
- } catch (JSONException e) {
332
- returnError("JSON ERROR: " + e.getMessage());
212
+ wrapperSessionScanRequest = LegacyPluginHelper.getWrapperSessionScanStartRequest(
213
+ this.reactContext,
214
+ scanViewConfigContent,
215
+ scanViewInitializationParametersString,
216
+ scanViewConfigPath,
217
+ scanCallbackConfigString,
218
+ shouldReturnImages);
219
+ } catch (Exception e) {
220
+ returnError("Could not parse parameters: " + e.getMessage());
221
+ return;
333
222
  }
334
- }
335
-
336
- private void scan() throws LicenseException, JSONException {
337
223
 
338
- Intent intent = new Intent(getCurrentActivity(), ScanActivity.class);
224
+ JSONObject wrapperSessionScanStartRequestJson
225
+ = WrapperSessionScanStartRequestExtensionKt.toJsonObject(wrapperSessionScanRequest);
339
226
 
340
- if (!AnylineSdk.isInitialized()) {
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
- }
227
+ WrapperSessionProvider.requestScanStart(wrapperSessionScanStartRequestJson.toString());
348
228
 
349
- configObject = new JSONObject(this.config);
229
+ ResultReporter.setListener(this);
230
+ }
350
231
 
351
- JSONObject optionsJSONObject = configObject.optJSONObject("options");
232
+ @ReactMethod
233
+ public void reportCorrectedResult(String blobKey, String correctedResult, Callback onResponseCallback, Callback onErrorCallback) {
234
+ reportCorrectedResultResponseCallback = onResponseCallback;
235
+ reportCorrectedResultErrorCallback = onErrorCallback;
236
+ WrapperSessionUCRReportRequest wrapperSessionUCRReportRequest = LegacyPluginHelper
237
+ .getWrapperSessionUCRReportRequest(blobKey, correctedResult);
352
238
 
353
- if (optionsJSONObject != null) {
354
- intent.putExtra(
355
- EXTRA_ENABLE_BARCODE_SCANNING,
356
- optionsJSONObject.optBoolean("nativeBarcodeEnabled", false)
357
- );
358
- }
239
+ JSONObject wrapperSessionUCRReportRequestJson = WrapperSessionUCRReportRequestExtensionKt
240
+ .toJsonObject(wrapperSessionUCRReportRequest);
359
241
 
360
- intent.putExtra(EXTRA_CONFIG_JSON, configObject.toString());
361
- intent.putExtra(EXTRA_SCANVIEW_INITIALIZATION_PARAMETERS, scanViewInitializationParameters);
242
+ WrapperSessionProvider.requestUCRReport(wrapperSessionUCRReportRequestJson.toString());
243
+ }
362
244
 
363
- ResultReporter.setListener(this);
364
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
245
+ @ReactMethod
246
+ public void exportCachedEvents(final Promise promise) {
247
+ wrapperSessionExportCachedEventsPromise = promise;
248
+ WrapperSessionProvider.requestExportCachedEvents();
249
+ }
365
250
 
366
- reactContext.startActivityForResult(intent, 1111, intent.getExtras());
251
+ @ReactMethod
252
+ public void tryStopScan(String scanStopRequestParams) {
253
+ WrapperSessionProvider.requestScanStop(scanStopRequestParams);
367
254
  }
368
255
 
369
256
  @Override
@@ -384,13 +271,15 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
384
271
  private void returnError(String error) {
385
272
  switch (this.returnMethod) {
386
273
  case "callback":
387
- if (onErrorCallback != null) {
388
- onErrorCallback.invoke(error);
389
- onErrorCallback = null;
274
+ if (scanResponseErrorCallback != null) {
275
+ scanResponseErrorCallback.invoke(error);
276
+ scanResponseErrorCallback = null;
390
277
  }
391
278
  break;
392
279
  case "promise":
393
- promise.reject(E_ERROR, error);
280
+ if (wrapperSessionScanResponsePromise != null) {
281
+ wrapperSessionScanResponsePromise.reject(E_ERROR, error);
282
+ }
394
283
  break;
395
284
  default:
396
285
  break;
@@ -400,16 +289,121 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
400
289
  private void returnSuccess(String result) {
401
290
  switch (this.returnMethod) {
402
291
  case "callback":
403
- if (onResultCallback != null) {
404
- onResultCallback.invoke(result);
405
- onResultCallback = null;
292
+ if (scanResponseResultCallback != null) {
293
+ scanResponseResultCallback.invoke(result);
294
+ scanResponseResultCallback = null;
406
295
  }
407
296
  break;
408
297
  case "promise":
409
- promise.resolve(result);
298
+ if (wrapperSessionScanResponsePromise != null) {
299
+ wrapperSessionScanResponsePromise.resolve(result);
300
+ }
410
301
  break;
411
302
  default:
412
303
  break;
413
304
  }
414
305
  }
306
+
307
+ private void sendEvent(String eventName, Object params) {
308
+ reactContext
309
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
310
+ .emit(eventName, params);
311
+ }
312
+
313
+ @Override
314
+ public @NotNull Context getContext() {
315
+ return this.reactContext;
316
+ }
317
+
318
+ @Override
319
+ public void onSdkInitializationResponse(@NotNull WrapperSessionSdkInitializationResponse initializationResponse) {
320
+ JSONObject json =
321
+ WrapperSessionSdkInitializationResponseExtensionKt.toJsonObject(initializationResponse);
322
+
323
+ if (wrapperSessionSdkInitializationResponsePromise != null) {
324
+ if (initializationResponse.getInitialized() == Boolean.TRUE) {
325
+ wrapperSessionSdkInitializationResponsePromise.resolve(true);
326
+ } else {
327
+ wrapperSessionSdkInitializationResponsePromise.reject(E_ERROR, json.toString());
328
+ }
329
+ }
330
+ }
331
+
332
+ @Override
333
+ public void onScanResults(@NotNull WrapperSessionScanResultsResponse scanResultsResponse) {
334
+ WrapperSessionScanResultConfig scanResultConfig = scanResultsResponse.getScanResultConfig();
335
+ List<ExportedScanResult> scanResultList = scanResultsResponse.getExportedScanResults();
336
+ WrapperSessionScanResultExtraInfo scanResultExtraInfo = scanResultsResponse.getScanResultExtraInfo();
337
+ try {
338
+ String resultsWithImagePathString = LegacyPluginHelper
339
+ .getScanResultsWithImagePath(scanResultList, scanResultExtraInfo.getViewPluginType());
340
+
341
+ if (scanResultConfig.getCallbackConfig() != null
342
+ && scanResultConfig.getCallbackConfig().getOnResultEventName() != null) {
343
+ sendEvent(
344
+ scanResultConfig.getCallbackConfig().getOnResultEventName(),
345
+ resultsWithImagePathString);
346
+ } else {
347
+ ResultReporter.onResult(resultsWithImagePathString, true);
348
+ }
349
+ } catch (Exception e) {
350
+ //exception will not be handled here
351
+ }
352
+ }
353
+
354
+ @Override
355
+ public void onUIElementClicked(@NonNull WrapperSessionScanResultConfig scanResultConfig,
356
+ @NonNull UIFeedbackElementConfig uiFeedbackElementConfig) {
357
+ if (scanResultConfig.getCallbackConfig() != null
358
+ && scanResultConfig.getCallbackConfig().getOnUIElementClickedEventName() != null) {
359
+ sendEvent(
360
+ scanResultConfig.getCallbackConfig().getOnUIElementClickedEventName(),
361
+ UIFeedbackElementConfigExtensionKt.toJsonObject(uiFeedbackElementConfig).toString());
362
+ }
363
+ }
364
+
365
+ @Override
366
+ public void onScanResponse(@NotNull WrapperSessionScanResponse scanResponse) {
367
+ if (scanResponse.getStatus() != null) {
368
+ switch (scanResponse.getStatus()) {
369
+ case SCAN_SUCCEEDED:
370
+ WrapperSessionScanResultConfig scanResultConfig = scanResponse.getScanResultConfig();
371
+ if (scanResultConfig.getCallbackConfig() != null
372
+ && scanResultConfig.getCallbackConfig().getOnResultEventName() != null) {
373
+ ResultReporter.onResult("", true);
374
+ }
375
+ break;
376
+ case SCAN_FAILED:
377
+ ResultReporter.onError(scanResponse.getFailInfo().getLastError());
378
+ break;
379
+ case SCAN_ABORTED:
380
+ ResultReporter.onCancel();
381
+ break;
382
+ }
383
+ }
384
+ }
385
+
386
+ @Override
387
+ public void onUCRReportResponse(@NotNull WrapperSessionUCRReportResponse ucrReportResponse) {
388
+ if (ucrReportResponse.getStatus() == WrapperSessionUCRReportResponse.WrapperSessionUCRReportResponseStatus.UCR_REPORT_SUCCEEDED) {
389
+ reportCorrectedResultResponseCallback.invoke(ucrReportResponse.getSucceedInfo().getMessage());
390
+ } else {
391
+ reportCorrectedResultErrorCallback.invoke(LegacyPluginHelper
392
+ .getWrapperSessionUCRReportResponseFailMessage(ucrReportResponse.getFailInfo()));
393
+ }
394
+ reportCorrectedResultResponseCallback = null;
395
+ reportCorrectedResultErrorCallback = null;
396
+ }
397
+
398
+ @Override
399
+ public void onExportCachedEventsResponse(@NotNull WrapperSessionExportCachedEventsResponse exportCachedEventsResponse) {
400
+ if (exportCachedEventsResponse.getStatus() == WrapperSessionExportCachedEventsResponse.WrapperSessionExportCachedEventsResponseStatus.EXPORT_SUCCEEDED) {
401
+ WrapperSessionExportCachedEventsResponseSucceed exportCachedEventsSucceed = exportCachedEventsResponse.getSucceedInfo();
402
+ wrapperSessionExportCachedEventsPromise.resolve(exportCachedEventsSucceed.getExportedFile());
403
+ } else {
404
+ WrapperSessionExportCachedEventsResponseFail exportCachedEventsFail = exportCachedEventsResponse.getFailInfo();
405
+ wrapperSessionExportCachedEventsPromise.reject(E_ERROR, exportCachedEventsFail.getLastError());
406
+ }
407
+ wrapperSessionExportCachedEventsPromise = null;
408
+ }
415
409
  }