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.
Files changed (69) hide show
  1. package/{ios/AnylineReact.podspec → AnylineReact.podspec} +3 -3
  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 +251 -252
  5. package/index.js +3 -16
  6. package/ios/AnylineSDKPlugin.h +4 -4
  7. package/ios/AnylineSDKPlugin.m +285 -207
  8. package/package.json +12 -2
  9. package/android/.gradle/7.6/checksums/checksums.lock +0 -0
  10. package/android/.gradle/7.6/checksums/md5-checksums.bin +0 -0
  11. package/android/.gradle/7.6/checksums/sha1-checksums.bin +0 -0
  12. package/android/.gradle/7.6/dependencies-accessors/dependencies-accessors.lock +0 -0
  13. package/android/.gradle/7.6/dependencies-accessors/gc.properties +0 -0
  14. package/android/.gradle/7.6/executionHistory/executionHistory.lock +0 -0
  15. package/android/.gradle/7.6/fileChanges/last-build.bin +0 -0
  16. package/android/.gradle/7.6/fileHashes/fileHashes.bin +0 -0
  17. package/android/.gradle/7.6/fileHashes/fileHashes.lock +0 -0
  18. package/android/.gradle/7.6/gc.properties +0 -0
  19. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  20. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  21. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  22. package/android/.gradle/config.properties +0 -2
  23. package/android/.gradle/vcs-1/gc.properties +0 -0
  24. package/android/.idea/PipelineViewerConfig.xml +0 -6
  25. package/android/.idea/appInsightsSettings.xml +0 -28
  26. package/android/.idea/caches/deviceStreaming.xml +0 -486
  27. package/android/.idea/compiler.xml +0 -6
  28. package/android/.idea/gradle.xml +0 -19
  29. package/android/.idea/jarRepositories.xml +0 -30
  30. package/android/.idea/material_theme_project_new.xml +0 -13
  31. package/android/.idea/migrations.xml +0 -10
  32. package/android/.idea/misc.xml +0 -9
  33. package/android/.idea/runConfigurations.xml +0 -17
  34. package/android/.idea/vcs.xml +0 -6
  35. package/android/local.properties +0 -8
  36. package/android/src/main/java/com/anyline/reactnative/FeedbackConfig.java +0 -59
  37. package/android/src/main/java/com/anyline/reactnative/ImageTextConfig.java +0 -49
  38. package/android/src/main/java/com/anyline/reactnative/InstructionConfig.java +0 -20
  39. package/android/src/main/java/com/anyline/reactnative/Offset.java +0 -21
  40. package/android/src/main/java/com/anyline/reactnative/RotateButtonConfig.java +0 -32
  41. package/android/src/main/java/com/anyline/reactnative/ScanActivity.java +0 -426
  42. package/android/src/main/java/com/anyline/reactnative/updateAsset/AnylineUpdateDelegateImpl.java +0 -50
  43. package/android/src/main/java/com/anyline/reactnative/updateAsset/AssetContextJsonParser.java +0 -28
  44. package/android/src/main/res/drawable/rotate_screen_background.xml +0 -18
  45. package/android/src/main/res/drawable/rotate_screen_white.png +0 -0
  46. package/android/src/main/res/drawable-hdpi/ic_flash_auto.png +0 -0
  47. package/android/src/main/res/drawable-hdpi/ic_flash_off.png +0 -0
  48. package/android/src/main/res/drawable-hdpi/ic_flash_on.png +0 -0
  49. package/android/src/main/res/drawable-mdpi/ic_flash_auto.png +0 -0
  50. package/android/src/main/res/drawable-mdpi/ic_flash_off.png +0 -0
  51. package/android/src/main/res/drawable-mdpi/ic_flash_on.png +0 -0
  52. package/android/src/main/res/drawable-xhdpi/ic_flash_auto.png +0 -0
  53. package/android/src/main/res/drawable-xhdpi/ic_flash_off.png +0 -0
  54. package/android/src/main/res/drawable-xhdpi/ic_flash_on.png +0 -0
  55. package/android/src/main/res/drawable-xxhdpi/ic_flash_auto.png +0 -0
  56. package/android/src/main/res/drawable-xxhdpi/ic_flash_off.png +0 -0
  57. package/android/src/main/res/drawable-xxhdpi/ic_flash_on.png +0 -0
  58. package/android/src/main/res/drawable-xxxhdpi/ic_flash_auto.png +0 -0
  59. package/android/src/main/res/drawable-xxxhdpi/ic_flash_off.png +0 -0
  60. package/android/src/main/res/drawable-xxxhdpi/ic_flash_on.png +0 -0
  61. package/android/src/main/res/layout/activity_scan.xml +0 -93
  62. package/ios/ALJsonUIConfiguration.h +0 -54
  63. package/ios/ALJsonUIConfiguration.m +0 -251
  64. package/ios/ALPluginHelper.h +0 -48
  65. package/ios/ALPluginHelper.m +0 -332
  66. package/ios/ALPluginScanViewController.h +0 -18
  67. package/ios/ALPluginScanViewController.m +0 -476
  68. package/ios/ALRoundedView.h +0 -25
  69. 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__, "../", "package.json")))
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 = "*.{h,m}"
21
- s.dependency "Anyline", "55.2.0"
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
@@ -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.0'
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
  }
@@ -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,71 +4,82 @@ 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
+ 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
- private JSONObject configObject;
55
- private ReactApplicationContext reactContext;
56
- private String license;
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 static WrapperConfig wrapperConfig;
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 setPluginVersion(final String pluginVersion) {
87
- wrapperConfig = new WrapperConfig.Wrapper(
88
- new WrapperInfo(WrapperInfo.WrapperType.ReactNative, pluginVersion)
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
- try {
95
- promise.resolve(String.valueOf(AnylineSdk.getExpiryDate()));
96
- } catch (LicenseException e) {
97
- e.printStackTrace();
98
- promise.reject(E_ERROR, e.getMessage());
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(AnylineSdk.isInitialized());
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
- onResultCallback = onResultReact;
111
- onErrorCallback = onErrorReact;
123
+ scanResponseResultCallback = onResultReact;
124
+ scanResponseErrorCallback = onErrorReact;
112
125
  this.returnMethod = "callback";
113
- this.config = config;
114
126
 
115
- routeScanMode(scanMode);
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
- CacheConfig.Preset cacheConfig = CacheConfig.Preset.Default.INSTANCE;
149
- if (enableOfflineCache) {
150
- cacheConfig = CacheConfig.Preset.OfflineLicenseEventCachingEnabled.INSTANCE;
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
- CacheConfig.Preset cacheConfig = CacheConfig.Preset.Default.INSTANCE;
174
- if (enableOfflineCache) {
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
- @ReactMethod
186
- public void resetUpdate() {
187
- // TODO
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 initializationParameters, String config, String scanMode, Callback onResultReact, Callback onErrorReact) {
197
- onResultCallback = onResultReact;
198
- onErrorCallback = onErrorReact;
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(scanMode);
174
+ routeScanMode(config, scanViewInitializationParametersString, null, null);
204
175
  }
205
-
206
176
  @ReactMethod
207
- public void reportCorrectedResult(String blobKey, String correctedResult, Callback onResponseCallback, Callback onErrorCallback) {
208
- try {
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 exportCachedEvents(final Promise promise) {
234
- try {
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 setupPromise(String config, String scanMode, final Promise promise) {
284
- setupPromiseWithInitializationParameters(null, config, scanMode, promise);
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 setupPromiseWithInitializationParameters(String initializationParameters, String config, String scanMode, final Promise promise) {
288
- this.promise = promise;
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
- deleteAllPreviousScanResultImages();
294
- routeScanMode(scanMode);
193
+ routeScanMode(config, initializationParametersString, null, scanCallbackConfigString);
295
194
  }
296
195
 
297
- private void routeScanMode(String scanMode) {
298
- switch (scanMode) {
299
- case "scan": // > Anyline 4
300
- scanAnyline4();
301
- break;
302
- default:
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
- private void scanAnyline4() {
203
+ WrapperSessionScanStartRequest wrapperSessionScanRequest;
308
204
  try {
309
- configObject = new JSONObject(this.config);
310
- if (configObject != null) {
311
- scan();
312
- } else {
313
- returnError("No ViewPlugin in config. Please check your configuration.");
314
- }
315
- } catch (LicenseException e) {
316
- e.printStackTrace();
317
- returnError("LICENSE ERROR: " + e.getMessage());
318
- } catch (JSONException e) {
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
- private void scan() throws LicenseException, JSONException {
217
+ JSONObject wrapperSessionScanStartRequestJson
218
+ = WrapperSessionScanStartRequestExtensionKt.toJsonObject(wrapperSessionScanRequest);
325
219
 
326
- Intent intent = new Intent(getCurrentActivity(), ScanActivity.class);
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
- configObject = new JSONObject(this.config);
222
+ ResultReporter.setListener(this);
223
+ }
338
224
 
339
- JSONObject optionsJSONObject = configObject.optJSONObject("options");
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
- if (optionsJSONObject != null) {
342
- intent.putExtra(
343
- EXTRA_ENABLE_BARCODE_SCANNING,
344
- optionsJSONObject.optBoolean("nativeBarcodeEnabled", false)
345
- );
346
- }
232
+ JSONObject wrapperSessionUCRReportRequestJson = WrapperSessionUCRReportRequestExtensionKt
233
+ .toJsonObject(wrapperSessionUCRReportRequest);
347
234
 
348
- intent.putExtra(EXTRA_CONFIG_JSON, configObject.toString());
349
- intent.putExtra(EXTRA_SCANVIEW_INITIALIZATION_PARAMETERS, scanViewInitializationParameters);
235
+ WrapperSessionProvider.requestUCRReport(wrapperSessionUCRReportRequestJson.toString());
236
+ }
350
237
 
351
- ResultReporter.setListener(this);
352
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
238
+ @ReactMethod
239
+ public void exportCachedEvents(final Promise promise) {
240
+ wrapperSessionExportCachedEventsPromise = promise;
241
+ WrapperSessionProvider.requestExportCachedEvents();
242
+ }
353
243
 
354
- reactContext.startActivityForResult(intent, 1111, intent.getExtras());
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 (onErrorCallback != null) {
376
- onErrorCallback.invoke(error);
377
- onErrorCallback = null;
267
+ if (scanResponseErrorCallback != null) {
268
+ scanResponseErrorCallback.invoke(error);
269
+ scanResponseErrorCallback = null;
378
270
  }
379
271
  break;
380
272
  case "promise":
381
- promise.reject(E_ERROR, error);
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 (onResultCallback != null) {
392
- onResultCallback.invoke(result);
393
- onResultCallback = null;
285
+ if (scanResponseResultCallback != null) {
286
+ scanResponseResultCallback.invoke(result);
287
+ scanResponseResultCallback = null;
394
288
  }
395
289
  break;
396
290
  case "promise":
397
- promise.resolve(result);
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
  }