scandit-capacitor-datacapture-core 6.27.1 → 6.28.0-beta.1

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.
@@ -16,5 +16,5 @@ Pod::Spec.new do |s|
16
16
  s.swift_version = "5.7"
17
17
 
18
18
  s.dependency "Capacitor"
19
- s.dependency "scandit-datacapture-frameworks-core", '= 6.27.1'
19
+ s.dependency "scandit-datacapture-frameworks-core", '= 6.28.0-beta.1'
20
20
  end
@@ -56,7 +56,7 @@ repositories {
56
56
  }
57
57
 
58
58
  dependencies {
59
- def sdk_version = "6.27.1"
59
+ def sdk_version = "6.28.0-beta.1"
60
60
 
61
61
  implementation fileTree(dir: 'libs', include: ['*.jar'])
62
62
 
@@ -2,20 +2,22 @@ package com.scandit.capacitor.datacapture.core
2
2
 
3
3
  import android.Manifest
4
4
  import android.util.Log
5
- import com.getcapacitor.*
5
+ import com.getcapacitor.JSObject
6
+ import com.getcapacitor.PermissionState
7
+ import com.getcapacitor.Plugin
8
+ import com.getcapacitor.PluginCall
9
+ import com.getcapacitor.PluginMethod
6
10
  import com.getcapacitor.annotation.CapacitorPlugin
7
11
  import com.getcapacitor.annotation.Permission
8
12
  import com.getcapacitor.annotation.PermissionCallback
13
+ import com.scandit.capacitor.datacapture.core.communication.CameraPermissionGrantedListener
9
14
  import com.scandit.capacitor.datacapture.core.data.ResizeAndMoveInfo
10
- import com.scandit.capacitor.datacapture.core.errors.*
15
+ import com.scandit.capacitor.datacapture.core.errors.JsonParseError
16
+ import com.scandit.capacitor.datacapture.core.errors.NullFrameError
11
17
  import com.scandit.capacitor.datacapture.core.handlers.DataCaptureViewHandler
12
18
  import com.scandit.capacitor.datacapture.core.utils.CapacitorResult
13
19
  import com.scandit.datacapture.core.source.FrameSourceState
14
- import com.scandit.datacapture.core.source.FrameSourceStateDeserializer
15
- import com.scandit.datacapture.core.ui.DataCaptureView
16
20
  import com.scandit.datacapture.frameworks.core.CoreModule
17
- import com.scandit.datacapture.frameworks.core.deserialization.DefaultDeserializationLifecycleObserver
18
- import com.scandit.datacapture.frameworks.core.deserialization.DeserializationLifecycleObserver
19
21
  import com.scandit.datacapture.frameworks.core.events.Emitter
20
22
  import com.scandit.datacapture.frameworks.core.listeners.FrameworksDataCaptureContextListener
21
23
  import com.scandit.datacapture.frameworks.core.listeners.FrameworksDataCaptureViewListener
@@ -36,7 +38,6 @@ import org.json.JSONObject
36
38
  )
37
39
  class ScanditCaptureCoreNative :
38
40
  Plugin(),
39
- DeserializationLifecycleObserver.Observer,
40
41
  Emitter {
41
42
 
42
43
  companion object {
@@ -60,8 +61,6 @@ class ScanditCaptureCoreNative :
60
61
  )
61
62
  private val mainThread: MainThread = DefaultMainThread.getInstance()
62
63
  private val lastFrameData: LastFrameData = DefaultLastFrameData.getInstance()
63
- private val deserializationLifecycleObserver: DeserializationLifecycleObserver =
64
- DefaultDeserializationLifecycleObserver.getInstance()
65
64
 
66
65
  private var lastFrameSourceState: FrameSourceState = FrameSourceState.OFF
67
66
 
@@ -91,7 +90,6 @@ class ScanditCaptureCoreNative :
91
90
 
92
91
  captureViewHandler.attachWebView(bridge.webView, bridge.activity)
93
92
  coreModule.onCreate(this.context)
94
- deserializationLifecycleObserver.attach(this)
95
93
  }
96
94
 
97
95
  override fun handleOnStart() {
@@ -112,41 +110,51 @@ class ScanditCaptureCoreNative :
112
110
  }
113
111
 
114
112
  override fun handleOnDestroy() {
115
- deserializationLifecycleObserver.detach(this)
116
113
  coreModule.onDestroy()
117
114
  }
118
115
 
119
- override fun onDataCaptureViewDeserialized(dataCaptureView: DataCaptureView?) {
120
- if (dataCaptureView == null) {
121
- captureViewHandler.disposeCurrentDataCaptureView()
122
- return
123
- }
124
- captureViewHandler.attachDataCaptureView(dataCaptureView, this.activity)
125
- }
126
-
127
116
  private fun checkCameraPermission(): Boolean =
128
117
  getPermissionState("camera") == PermissionState.GRANTED
129
118
 
130
- private fun checkOrRequestCameraPermissions(call: PluginCall) {
131
- if (!checkCameraPermission()) {
132
- requestPermissionForAlias("camera", call, "onCameraPermissionResult")
119
+ private fun checkOrRequestInitialCameraPermission(call: PluginCall) {
120
+ if (getPermissionState("camera") != PermissionState.GRANTED) {
121
+ requestPermissionForAlias("camera", call, "initialCameraPermsCallback")
133
122
  } else {
134
- onCameraPermissionResult(call)
123
+ updateContext(call)
124
+ }
125
+ }
126
+
127
+ private fun checkOrRequestUpdateCameraPermission(call: PluginCall) {
128
+ if (getPermissionState("camera") != PermissionState.GRANTED) {
129
+ requestPermissionForAlias("camera", call, "updateCameraPermsCallback")
130
+ } else {
131
+ updateContext(call)
135
132
  }
136
133
  }
137
134
 
138
135
  @Suppress("unused")
139
136
  @PermissionCallback
140
- private fun onCameraPermissionResult(call: PluginCall) {
141
- if (checkCameraPermission()) {
142
- coreModule.switchToDesiredCameraState(lastFrameSourceState)
143
- call.resolve()
144
- return
137
+ private fun initialCameraPermsCallback(call: PluginCall) {
138
+ if (getPermissionState("camera") == PermissionState.GRANTED) {
139
+ notifyCameraPermissionGrantedToPlugins()
145
140
  }
141
+ updateContext(call)
142
+ }
146
143
 
147
- call.reject("Camera permissions not granted.")
144
+ @Suppress("unused")
145
+ @PermissionCallback
146
+ private fun updateCameraPermsCallback(call: PluginCall) {
147
+ if (getPermissionState("camera") == PermissionState.GRANTED) {
148
+ notifyCameraPermissionGrantedToPlugins()
149
+ }
150
+ updateContext(call)
148
151
  }
149
152
 
153
+ private fun notifyCameraPermissionGrantedToPlugins() =
154
+ plugins.filterIsInstance<CameraPermissionGrantedListener>().forEach {
155
+ it.onCameraPermissionGranted()
156
+ }
157
+
150
158
  //region CameraProxy
151
159
  @PluginMethod
152
160
  fun getCurrentCameraState(call: PluginCall) =
@@ -172,27 +180,19 @@ class ScanditCaptureCoreNative :
172
180
 
173
181
  @PluginMethod
174
182
  fun switchCameraToDesiredState(call: PluginCall) {
175
- val desiredStateJson = call.data.getString("desiredState") ?: run {
176
- call.reject(
177
- "Missing desiredState argument in switchCameraToDesiredState."
178
- )
179
- return
180
- }
181
-
182
- if (checkCameraPermission()) {
183
- coreModule.switchCameraToDesiredState(desiredStateJson, CapacitorResult(call))
184
- lastFrameSourceState = coreModule.getCurrentCameraDesiredState() ?: FrameSourceState.OFF
185
- return
186
- }
187
-
188
- lastFrameSourceState = FrameSourceStateDeserializer.fromJson(desiredStateJson)
189
- checkOrRequestCameraPermissions(call)
183
+ val desiredStateJson = call.data.getString("desiredState") ?: return
184
+ coreModule.switchCameraToDesiredState(desiredStateJson, CapacitorResult(call))
190
185
  }
191
186
  //endregion
192
187
 
193
188
  //region DataCaptureContextProxy
194
189
  @PluginMethod
195
190
  fun contextFromJSON(call: PluginCall) {
191
+ initializeContextFromJson(call)
192
+ checkOrRequestInitialCameraPermission(call)
193
+ }
194
+
195
+ private fun initializeContextFromJson(call: PluginCall) {
196
196
  val jsonString = call.data.getString("context")
197
197
  ?: return call.reject(EMPTY_STRING_ERROR)
198
198
  coreModule.createContextFromJson(jsonString, CapacitorResult(call))
@@ -208,7 +208,9 @@ class ScanditCaptureCoreNative :
208
208
  }
209
209
 
210
210
  @PluginMethod
211
- fun updateContextFromJSON(call: PluginCall) {
211
+ fun updateContextFromJSON(call: PluginCall) = checkOrRequestUpdateCameraPermission(call)
212
+
213
+ private fun updateContext(call: PluginCall) {
212
214
  val jsonString = call.data.getString("context")
213
215
  ?: return call.reject(EMPTY_STRING_ERROR)
214
216
 
@@ -350,33 +352,27 @@ class ScanditCaptureCoreNative :
350
352
  fun createDataCaptureView(call: PluginCall) {
351
353
  val viewJson = call.data.getString("viewJson")
352
354
  ?: return call.reject(EMPTY_STRING_ERROR)
353
- coreModule.createDataCaptureView(viewJson, CapacitorResult(call))
354
- }
355
-
356
- @PluginMethod
357
- fun updateDataCaptureView(call: PluginCall) {
358
- val viewJson = call.data.getString("viewJson")
359
- ?: return call.reject(EMPTY_STRING_ERROR)
360
- coreModule.updateDataCaptureView(viewJson, CapacitorResult(call))
355
+ val view = coreModule.createDataCaptureView(viewJson, CapacitorResult(call))
356
+ if (view != null) {
357
+ captureViewHandler.attachDataCaptureView(view, this.activity)
358
+ }
361
359
  }
362
360
 
363
361
  @PluginMethod
364
- fun addOverlay(call: PluginCall) {
365
- val overlayJson = call.data.getString("overlayJson")
366
- ?: return call.reject(EMPTY_STRING_ERROR)
367
- coreModule.addOverlayToView(overlayJson, CapacitorResult(call))
362
+ fun removeDataCaptureView(call: PluginCall) {
363
+ val dcViewToRemove = captureViewHandler.dataCaptureView
364
+ if (dcViewToRemove != null) {
365
+ coreModule.dataCaptureViewDisposed(dcViewToRemove)
366
+ }
367
+ captureViewHandler.disposeCurrentDataCaptureView()
368
+ call.resolve()
368
369
  }
369
370
 
370
371
  @PluginMethod
371
- fun removeOverlay(call: PluginCall) {
372
- val overlayJson = call.data.getString("overlayJson")
372
+ fun updateDataCaptureView(call: PluginCall) {
373
+ val viewJson = call.data.getString("viewJson")
373
374
  ?: return call.reject(EMPTY_STRING_ERROR)
374
- coreModule.removeOverlayFromView(overlayJson, CapacitorResult(call))
375
- }
376
-
377
- @PluginMethod
378
- fun removeAllOverlays(call: PluginCall) {
379
- coreModule.removeAllOverlays(CapacitorResult(call))
375
+ coreModule.updateDataCaptureView(viewJson, CapacitorResult(call))
380
376
  }
381
377
 
382
378
  override fun emit(eventName: String, payload: MutableMap<String, Any?>) {
@@ -0,0 +1,11 @@
1
+ /*
2
+ * This file is part of the Scandit Data Capture SDK
3
+ *
4
+ * Copyright (C) 2019- Scandit AG. All rights reserved.
5
+ */
6
+
7
+ package com.scandit.capacitor.datacapture.core.communication
8
+
9
+ interface CameraPermissionGrantedListener {
10
+ fun onCameraPermissionGranted()
11
+ }
@@ -30,6 +30,9 @@ class DataCaptureViewHandler(
30
30
  private val webView: View?
31
31
  get() = webViewReference.get()
32
32
 
33
+ val dataCaptureView: DataCaptureView?
34
+ get() = dataCaptureViewReference.get()
35
+
33
36
  fun attachDataCaptureView(dataCaptureView: DataCaptureView, activity: AppCompatActivity) {
34
37
  if (this.dataCaptureViewReference.get() != dataCaptureView) {
35
38
  disposeCurrentDataCaptureView()
package/dist/core.js CHANGED
@@ -1219,6 +1219,9 @@ DataCaptureContext.instance = null;
1219
1219
  __decorate([
1220
1220
  nameForSerialization('frameSource')
1221
1221
  ], DataCaptureContext.prototype, "_frameSource", void 0);
1222
+ __decorate([
1223
+ ignoreFromSerialization
1224
+ ], DataCaptureContext.prototype, "view", void 0);
1222
1225
  __decorate([
1223
1226
  ignoreFromSerialization
1224
1227
  ], DataCaptureContext.prototype, "modes", void 0);
@@ -1753,11 +1756,13 @@ var DataCaptureViewEvents;
1753
1756
  DataCaptureViewEvents["didChangeSize"] = "DataCaptureViewListener.onSizeChanged";
1754
1757
  })(DataCaptureViewEvents || (DataCaptureViewEvents = {}));
1755
1758
  class DataCaptureViewController extends BaseController {
1756
- static forDataCaptureView(view) {
1759
+ static forDataCaptureView(view, autoCreateNativeView) {
1757
1760
  const controller = new DataCaptureViewController();
1758
1761
  controller.view = view;
1759
- controller.createView();
1760
- controller.subscribeListener();
1762
+ if (autoCreateNativeView) {
1763
+ controller.createView();
1764
+ controller.subscribeListener();
1765
+ }
1761
1766
  return controller;
1762
1767
  }
1763
1768
  constructor() {
@@ -1784,6 +1789,15 @@ class DataCaptureViewController extends BaseController {
1784
1789
  hide() {
1785
1790
  return this._proxy.hide();
1786
1791
  }
1792
+ createNativeView() {
1793
+ return __awaiter(this, void 0, void 0, function* () {
1794
+ yield this.createView();
1795
+ this.subscribeListener();
1796
+ });
1797
+ }
1798
+ removeNativeView() {
1799
+ return this._proxy.removeView();
1800
+ }
1787
1801
  createView() {
1788
1802
  return this._proxy.createView(JSON.stringify(this.view.toJSON()));
1789
1803
  }
@@ -1793,12 +1807,6 @@ class DataCaptureViewController extends BaseController {
1793
1807
  dispose() {
1794
1808
  this.unsubscribeListener();
1795
1809
  }
1796
- addOverlay(overlay) {
1797
- return this._proxy.addOverlay(JSON.stringify(overlay.toJSON()));
1798
- }
1799
- removeOverlay(overlay) {
1800
- return this._proxy.removeOverlay(JSON.stringify(overlay.toJSON()));
1801
- }
1802
1810
  subscribeListener() {
1803
1811
  var _a, _b;
1804
1812
  this._proxy.registerListenerForViewEvents();
@@ -1889,18 +1897,20 @@ class BaseDataCaptureView extends DefaultSerializeable {
1889
1897
  get privateContext() {
1890
1898
  return this.context;
1891
1899
  }
1892
- static forContext(context) {
1893
- const view = new BaseDataCaptureView();
1900
+ static forContext(context, autoCreateNativeView = true) {
1901
+ const view = new BaseDataCaptureView(autoCreateNativeView);
1894
1902
  view.context = context;
1903
+ view.isViewCreated = autoCreateNativeView;
1895
1904
  return view;
1896
1905
  }
1897
- constructor() {
1906
+ constructor(autoCreateNativeView) {
1898
1907
  super();
1899
1908
  this._context = null;
1900
1909
  this.overlays = [];
1901
1910
  this.controls = [];
1902
1911
  this.listeners = [];
1903
- this.controller = DataCaptureViewController.forDataCaptureView(this);
1912
+ this.isViewCreated = false;
1913
+ this.controller = DataCaptureViewController.forDataCaptureView(this, autoCreateNativeView);
1904
1914
  this._scanAreaMargins = this.coreDefaults.DataCaptureView.scanAreaMargins;
1905
1915
  this._pointOfInterest = this.coreDefaults.DataCaptureView.pointOfInterest;
1906
1916
  this._logoAnchor = this.coreDefaults.DataCaptureView.logoAnchor;
@@ -1915,7 +1925,7 @@ class BaseDataCaptureView extends DefaultSerializeable {
1915
1925
  }
1916
1926
  overlay.view = this;
1917
1927
  this.overlays.push(overlay);
1918
- this.controller.addOverlay(overlay);
1928
+ this.controller.updateView();
1919
1929
  }
1920
1930
  removeOverlay(overlay) {
1921
1931
  if (!this.overlays.includes(overlay)) {
@@ -1923,7 +1933,7 @@ class BaseDataCaptureView extends DefaultSerializeable {
1923
1933
  }
1924
1934
  overlay.view = null;
1925
1935
  this.overlays.splice(this.overlays.indexOf(overlay), 1);
1926
- this.controller.removeOverlay(overlay);
1936
+ this.controller.updateView();
1927
1937
  }
1928
1938
  addListener(listener) {
1929
1939
  if (!this.listeners.includes(listener)) {
@@ -1967,11 +1977,29 @@ class BaseDataCaptureView extends DefaultSerializeable {
1967
1977
  controlUpdated() {
1968
1978
  this.controller.updateView();
1969
1979
  }
1980
+ createNativeView() {
1981
+ return __awaiter(this, void 0, void 0, function* () {
1982
+ if (this.isViewCreated) {
1983
+ return Promise.resolve();
1984
+ }
1985
+ yield this.controller.createNativeView();
1986
+ this.isViewCreated = true;
1987
+ });
1988
+ }
1989
+ removeNativeView() {
1990
+ return __awaiter(this, void 0, void 0, function* () {
1991
+ if (!this.isViewCreated) {
1992
+ return Promise.resolve();
1993
+ }
1994
+ this.controller.removeNativeView();
1995
+ this.isViewCreated = false;
1996
+ });
1997
+ }
1970
1998
  dispose() {
1971
- this.overlays.forEach(overlay => this.removeOverlay(overlay));
1972
1999
  this.overlays = [];
1973
2000
  this.listeners.forEach(listener => this.removeListener(listener));
1974
2001
  this.controller.dispose();
2002
+ this.isViewCreated = false;
1975
2003
  }
1976
2004
  // HTML Views only
1977
2005
  setFrame(frame, isUnderContent = false) {
@@ -2024,15 +2052,15 @@ __decorate([
2024
2052
  __decorate([
2025
2053
  nameForSerialization('logoStyle')
2026
2054
  ], BaseDataCaptureView.prototype, "_logoStyle", void 0);
2027
- __decorate([
2028
- ignoreFromSerialization
2029
- ], BaseDataCaptureView.prototype, "overlays", void 0);
2030
2055
  __decorate([
2031
2056
  ignoreFromSerialization
2032
2057
  ], BaseDataCaptureView.prototype, "controller", void 0);
2033
2058
  __decorate([
2034
2059
  ignoreFromSerialization
2035
2060
  ], BaseDataCaptureView.prototype, "listeners", void 0);
2061
+ __decorate([
2062
+ ignoreFromSerialization
2063
+ ], BaseDataCaptureView.prototype, "isViewCreated", void 0);
2036
2064
 
2037
2065
  class ZoomSwitchControl extends DefaultSerializeable {
2038
2066
  constructor() {