scandit-capacitor-datacapture-barcode 6.21.1 → 6.22.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.
Files changed (35) hide show
  1. package/ScanditCapacitorDatacaptureBarcode.podspec +10 -10
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/scandit/capacitor/datacapture/barcode/ScanditBarcodeNative.kt +346 -17
  4. package/android/src/main/java/com/scandit/capacitor/datacapture/barcode/pick/BarcodePickViewHandler.kt +139 -0
  5. package/dist/barcode.js +3165 -2438
  6. package/dist/barcode.js.map +1 -1
  7. package/dist/dts/definitions.d.ts +98 -0
  8. package/dist/dts/ts/BarcodeFindView.d.ts +59 -0
  9. package/dist/dts/ts/BarcodePickView.d.ts +32 -0
  10. package/dist/dts/ts/BarcodeTrackingAdvancedOverlay.d.ts +1 -1
  11. package/dist/dts/ts/Capacitor/BarcodeCaptureListenerProxy.d.ts +5 -2
  12. package/dist/dts/ts/Capacitor/BarcodeCountListenerProxy.d.ts +4 -2
  13. package/dist/dts/ts/Capacitor/BarcodeCountViewProxy.d.ts +11 -0
  14. package/dist/dts/ts/Capacitor/BarcodeFindListenerProxy.d.ts +15 -0
  15. package/dist/dts/ts/Capacitor/BarcodeFindViewProxy.d.ts +19 -0
  16. package/dist/dts/ts/Capacitor/BarcodePickProductProxy.d.ts +11 -0
  17. package/dist/dts/ts/Capacitor/BarcodePickViewProxy.d.ts +21 -0
  18. package/dist/dts/ts/Capacitor/BarcodeSelectionOverlayProxy.d.ts +1 -0
  19. package/dist/dts/ts/Capacitor/BarcodeSelectionProxy.d.ts +2 -0
  20. package/dist/dts/ts/Capacitor/BarcodeTrackingAdvancedOverlayProxy.d.ts +1 -0
  21. package/dist/dts/ts/Capacitor/BarcodeTrackingBasicOverlayProxy.d.ts +1 -0
  22. package/dist/dts/ts/Capacitor/BarcodeTrackingListenerProxy.d.ts +2 -0
  23. package/dist/dts/ts/Capacitor/Capacitor.d.ts +8 -1
  24. package/dist/dts/ts/Capacitor/SparkScanListenerProxy.d.ts +18 -0
  25. package/dist/dts/ts/Capacitor/SparkScanViewProxy.d.ts +23 -0
  26. package/dist/dts/ts/SparkScanView.d.ts +95 -0
  27. package/dist/dts/web.d.ts +4 -1
  28. package/dist/index.js +1066 -61
  29. package/dist/index.js.map +1 -1
  30. package/ios/Plugin/BarcodeCountViewHandler.swift +3 -3
  31. package/ios/Plugin/BarcodeFindViewHandler.swift +129 -0
  32. package/ios/Plugin/BarcodePickViewHandler.swift +128 -0
  33. package/ios/Plugin/Plugin.m +63 -1
  34. package/ios/Plugin/ScanditBarcodeCapture.swift +523 -55
  35. package/package.json +4 -4
@@ -4,18 +4,18 @@ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
4
  version = package["version"]
5
5
 
6
6
  Pod::Spec.new do |s|
7
- s.name = "ScanditCapacitorDatacaptureBarcode"
8
- s.version = version
9
- s.summary = package["description"]
10
- s.license = package["license"]
11
- s.homepage = package["homepage"]
12
- s.author = package["author"]
13
- s.source = { :git => package["homepage"], :tag => s.version.to_s }
14
- s.source_files = "ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}"
7
+ s.name = "ScanditCapacitorDatacaptureBarcode"
8
+ s.version = version
9
+ s.summary = package["description"]
10
+ s.license = package["license"]
11
+ s.homepage = package["homepage"]
12
+ s.author = package["author"]
13
+ s.source = { :git => package["homepage"], :tag => s.version.to_s }
14
+ s.source_files = "ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}"
15
15
  s.ios.deployment_target = "13.0"
16
- s.swift_version = "5.7"
16
+ s.swift_version = "5.7"
17
17
 
18
18
  s.dependency "Capacitor"
19
19
  s.dependency "ScanditCapacitorDatacaptureCore", "= #{version}"
20
- s.dependency "scandit-datacapture-frameworks-barcode", '= 6.21.1'
20
+ s.dependency "scandit-datacapture-frameworks-barcode", '= 6.22.0-beta.1'
21
21
  end
@@ -56,7 +56,7 @@ repositories {
56
56
  }
57
57
 
58
58
  dependencies {
59
- def sdk_version = "6.21.1"
59
+ def sdk_version = "6.22.0-beta.1"
60
60
 
61
61
  implementation fileTree(dir: 'libs', include: ['*.jar'])
62
62
  implementation fileTree(dir: 'library', include: ['*.aar'])
@@ -8,6 +8,7 @@ package com.scandit.capacitor.datacapture.barcode
8
8
  import android.graphics.Bitmap
9
9
  import android.graphics.BitmapFactory
10
10
  import android.util.Base64
11
+ import android.view.View
11
12
  import android.view.ViewGroup
12
13
  import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
13
14
  import com.getcapacitor.JSObject
@@ -18,12 +19,14 @@ import com.getcapacitor.annotation.CapacitorPlugin
18
19
  import com.scandit.capacitor.datacapture.barcode.count.BarcodeCountViewHandler
19
20
  import com.scandit.capacitor.datacapture.barcode.factories.BarcodeCaptureActionFactory
20
21
  import com.scandit.capacitor.datacapture.barcode.find.BarcodeFindViewHandler
22
+ import com.scandit.capacitor.datacapture.barcode.pick.BarcodePickViewHandler
21
23
  import com.scandit.capacitor.datacapture.barcode.utils.SerializableAdvancedOverlayViewData
22
24
  import com.scandit.capacitor.datacapture.core.ScanditCaptureCoreNative
23
25
  import com.scandit.capacitor.datacapture.core.data.ResizeAndMoveInfo
24
26
  import com.scandit.capacitor.datacapture.core.data.SerializableCallbackAction
25
27
  import com.scandit.capacitor.datacapture.core.data.SerializableFinishModeCallbackData
26
28
  import com.scandit.capacitor.datacapture.core.errors.JsonParseError
29
+ import com.scandit.capacitor.datacapture.core.utils.CapacitorNoopResult
27
30
  import com.scandit.capacitor.datacapture.core.utils.CapacitorResult
28
31
  import com.scandit.datacapture.core.ui.style.BrushDeserializer
29
32
  import com.scandit.datacapture.frameworks.barcode.BarcodeModule
@@ -37,10 +40,14 @@ import com.scandit.datacapture.frameworks.barcode.count.listeners.FrameworksBarc
37
40
  import com.scandit.datacapture.frameworks.barcode.find.BarcodeFindModule
38
41
  import com.scandit.datacapture.frameworks.barcode.find.listeners.FrameworksBarcodeFindListener
39
42
  import com.scandit.datacapture.frameworks.barcode.find.listeners.FrameworksBarcodeFindViewUiListener
43
+ import com.scandit.datacapture.frameworks.barcode.pick.BarcodePickModule
40
44
  import com.scandit.datacapture.frameworks.barcode.selection.BarcodeSelectionModule
41
45
  import com.scandit.datacapture.frameworks.barcode.selection.listeners.FrameworksBarcodeSelectionAimedBrushProvider
42
46
  import com.scandit.datacapture.frameworks.barcode.selection.listeners.FrameworksBarcodeSelectionListener
43
47
  import com.scandit.datacapture.frameworks.barcode.selection.listeners.FrameworksBarcodeSelectionTrackedBrushProvider
48
+ import com.scandit.datacapture.frameworks.barcode.spark.SparkScanModule
49
+ import com.scandit.datacapture.frameworks.barcode.spark.listeners.FrameworksSparkScanListener
50
+ import com.scandit.datacapture.frameworks.barcode.spark.listeners.FrameworksSparkScanViewUiListener
44
51
  import com.scandit.datacapture.frameworks.barcode.tracking.BarcodeTrackingModule
45
52
  import com.scandit.datacapture.frameworks.barcode.tracking.listeners.FrameworksBarcodeTrackingAdvancedOverlayListener
46
53
  import com.scandit.datacapture.frameworks.barcode.tracking.listeners.FrameworksBarcodeTrackingBasicOverlayListener
@@ -53,6 +60,7 @@ import com.scandit.datacapture.frameworks.core.utils.DefaultWorkerThread
53
60
  import com.scandit.datacapture.frameworks.core.utils.FrameworksLog
54
61
  import com.scandit.datacapture.frameworks.core.utils.MainThread
55
62
  import com.scandit.datacapture.frameworks.core.utils.WorkerThread
63
+ import org.json.JSONArray
56
64
  import org.json.JSONException
57
65
  import org.json.JSONObject
58
66
 
@@ -67,6 +75,9 @@ class ScanditBarcodeNative :
67
75
  companion object {
68
76
  private const val FIELD_RESULT = "result"
69
77
  private const val CORE_PLUGIN_NAME = "ScanditCaptureCoreNative"
78
+ private const val WRONG_INPUT = "Wrong input parameter"
79
+ private const val INVALID_JSON = "Failed to parse JSON argument"
80
+ private const val WEB_VIEW_NOT_ATTACHED = "WebView not attached yet"
70
81
  }
71
82
 
72
83
  private val barcodeModule = BarcodeModule()
@@ -87,14 +98,20 @@ class ScanditBarcodeNative :
87
98
  FrameworksBarcodeCountViewListener(this),
88
99
  FrameworksBarcodeCountViewUiListener(this)
89
100
  )
90
-
91
101
  private val barcodeFindModule = BarcodeFindModule(
92
102
  FrameworksBarcodeFindListener(this),
93
103
  FrameworksBarcodeFindViewUiListener(this)
94
104
  )
105
+ private val barcodePickModule = BarcodePickModule(
106
+ this
107
+ )
108
+ private val sparkScanModule = SparkScanModule(
109
+ FrameworksSparkScanListener(this), FrameworksSparkScanViewUiListener(this)
110
+ )
95
111
 
96
112
  private val barcodeCountViewHandler: BarcodeCountViewHandler = BarcodeCountViewHandler()
97
113
  private val barcodeFindViewHandler: BarcodeFindViewHandler = BarcodeFindViewHandler()
114
+ private val barcodePickViewHandler: BarcodePickViewHandler = BarcodePickViewHandler()
98
115
  private val logger: FrameworksLog = DefaultFrameworksLog.getInstance()
99
116
  private val workerThread: WorkerThread = DefaultWorkerThread.getInstance()
100
117
  private val mainThread: MainThread = DefaultMainThread.getInstance()
@@ -114,6 +131,7 @@ class ScanditBarcodeNative :
114
131
  mainThread.runOnMainThread {
115
132
  barcodeCountViewHandler.attachWebView(bridge.webView, bridge.activity)
116
133
  barcodeFindViewHandler.attachWebView(bridge.webView)
134
+ barcodePickViewHandler.attachWebView(bridge.webView, bridge.activity)
117
135
  }
118
136
  DeserializationLifecycleObserver.attach(this)
119
137
 
@@ -123,6 +141,8 @@ class ScanditBarcodeNative :
123
141
  barcodeSelectionModule.onCreate(context)
124
142
  barcodeCountModule.onCreate(context)
125
143
  barcodeFindModule.onCreate(context)
144
+ barcodePickModule.onCreate(context)
145
+ sparkScanModule.onCreate(context)
126
146
  }
127
147
 
128
148
  override fun handleOnDestroy() {
@@ -132,6 +152,18 @@ class ScanditBarcodeNative :
132
152
  barcodeSelectionModule.onDestroy()
133
153
  barcodeCountModule.onDestroy()
134
154
  barcodeFindModule.onDestroy()
155
+ barcodePickModule.onDestroy()
156
+ sparkScanModule.onDestroy()
157
+ }
158
+
159
+ override fun handleOnPause() {
160
+ super.handleOnPause()
161
+ barcodeFindModule.viewOnPause(CapacitorNoopResult())
162
+ }
163
+
164
+ override fun handleOnResume() {
165
+ super.handleOnResume()
166
+ barcodeFindModule.viewOnResume(CapacitorNoopResult())
135
167
  }
136
168
 
137
169
  @PluginMethod
@@ -177,7 +209,9 @@ class ScanditBarcodeNative :
177
209
  mapOf("BarcodeTracking" to barcodeTrackingModule.getDefaults()) +
178
210
  mapOf("BarcodeSelection" to barcodeSelectionModule.getDefaults()) +
179
211
  mapOf("BarcodeCount" to barcodeCountModule.getDefaults()) +
180
- mapOf("BarcodeFind" to barcodeFindModule.getDefaults())
212
+ mapOf("BarcodeFind" to barcodeFindModule.getDefaults()) +
213
+ mapOf("BarcodePick" to barcodePickModule.getDefaults()) +
214
+ mapOf("SparkScan" to sparkScanModule.getDefaults())
181
215
 
182
216
  )
183
217
  )
@@ -789,21 +823,26 @@ class ScanditBarcodeNative :
789
823
  fun createFindView(
790
824
  call: PluginCall
791
825
  ) {
792
- val viewJson = call.data.toString()
793
- val container = barcodeFindViewHandler.prepareContainer(this.context)
826
+ val viewJson = call.getString("view")
794
827
 
795
- val result = barcodeFindModule.getView(container, viewJson)
796
- if (result.isFailure) {
797
- call.reject(
798
- result.exceptionOrNull()?.message
799
- ?: "Unable to create the BarcodeFindView from the given json=$viewJson"
800
- )
801
- return
802
- }
828
+ viewJson?.let {
829
+ val container = barcodeFindViewHandler.prepareContainer(this.context)
803
830
 
804
- barcodeFindViewHandler.addBarcodeFindViewContainer(container, bridge.activity)
805
- barcodeCountViewHandler.render()
806
- call.resolve()
831
+ val result = barcodeFindModule.getView(container, viewJson)
832
+ if (result.isFailure) {
833
+ call.reject(
834
+ result.exceptionOrNull()?.message
835
+ ?: "Unable to create the BarcodeFindView from the given json=$viewJson"
836
+ )
837
+ return
838
+ }
839
+
840
+ barcodeFindViewHandler.addBarcodeFindViewContainer(container, bridge.activity)
841
+ barcodeCountViewHandler.render()
842
+ call.resolve()
843
+ } ?: run {
844
+ error("missing parameter for createFindView()")
845
+ }
807
846
  }
808
847
 
809
848
  @PluginMethod
@@ -853,8 +892,11 @@ class ScanditBarcodeNative :
853
892
  }
854
893
 
855
894
  @PluginMethod
856
- fun barcodeFindSetItemList(barcodeFindItemsJson: String, call: PluginCall) {
857
- barcodeFindModule.setItemList(barcodeFindItemsJson, CapacitorResult(call))
895
+ fun barcodeFindSetItemList(call: PluginCall) {
896
+ barcodeFindModule.setItemList(
897
+ call.data["BarcodeFindItemList"].toString(),
898
+ CapacitorResult(call)
899
+ )
858
900
  }
859
901
 
860
902
  @PluginMethod
@@ -906,4 +948,291 @@ class ScanditBarcodeNative :
906
948
  }
907
949
 
908
950
  //endregion
951
+
952
+ //region BarcodePick
953
+
954
+ @PluginMethod
955
+ fun createPickView(call: PluginCall) {
956
+ val viewJson = call.getString("json")
957
+
958
+ viewJson?.let {
959
+ val container = barcodePickViewHandler.prepareContainer(this.context)
960
+ barcodePickModule.addViewToContainer(container, viewJson, CapacitorResult(call))
961
+
962
+ barcodePickViewHandler.addBarcodePickViewContainer(container, bridge.activity)
963
+ barcodePickViewHandler.render()
964
+
965
+ call.resolve()
966
+ } ?: run {
967
+ error("missing parameter for createPickView()")
968
+ }
969
+ }
970
+
971
+ @PluginMethod
972
+ fun updatePickView(call: PluginCall) {
973
+ val viewJson = call.data.toString()
974
+ barcodePickModule.updateView(viewJson, CapacitorResult(call))
975
+ call.resolve()
976
+ }
977
+
978
+ @PluginMethod
979
+ fun setPickViewPositionAndSize(call: PluginCall) {
980
+ try {
981
+ val positionJson = call.data.getString("position")
982
+ ?: return call.reject("No position was given for setting the view.")
983
+ val info = JSONObject(positionJson)
984
+ barcodePickViewHandler.setResizeAndMoveInfo(ResizeAndMoveInfo(info))
985
+ call.resolve()
986
+ } catch (e: JSONException) {
987
+ call.reject(JsonParseError(e.message).toString())
988
+ }
989
+ }
990
+
991
+ @PluginMethod
992
+ fun addActionListener(call: PluginCall) {
993
+ barcodePickModule.addActionListener()
994
+ call.resolve()
995
+ }
996
+
997
+ @PluginMethod
998
+ fun removeActionListener(call: PluginCall) {
999
+ barcodePickModule.removeActionListener()
1000
+ call.resolve()
1001
+ }
1002
+
1003
+ @PluginMethod
1004
+ fun finishOnProductIdentifierForItems(call: PluginCall) {
1005
+ val barcodePickProductProviderCallbackItemsJson =
1006
+ JSONArray(call.getString("itemsJson")).toString()
1007
+ barcodePickModule.finishOnProductIdentifierForItems(
1008
+ barcodePickProductProviderCallbackItemsJson
1009
+ )
1010
+ call.resolve()
1011
+ }
1012
+
1013
+ @PluginMethod
1014
+ fun viewPause(call: PluginCall) {
1015
+ barcodePickModule.viewPause()
1016
+ call.resolve()
1017
+ }
1018
+
1019
+ @PluginMethod
1020
+ fun viewStart(call: PluginCall) {
1021
+ barcodePickModule.viewStart()
1022
+ call.resolve()
1023
+ }
1024
+
1025
+ @PluginMethod
1026
+ fun finishPickAction(call: PluginCall) {
1027
+ val itemDataJson = call.getString("code")
1028
+ val result = call.getBoolean("result")
1029
+
1030
+ if (itemDataJson == null || result == null) {
1031
+ call.reject("failed to parse finishPickAction JSON.")
1032
+ } else {
1033
+ barcodePickModule.finishPickAction(itemDataJson, result)
1034
+ call.resolve()
1035
+ }
1036
+ }
1037
+
1038
+ //endregion
1039
+
1040
+ @PluginMethod
1041
+ fun updateBarcodeCaptureOverlay(call: PluginCall) {
1042
+ val overlayJson = call.data.getString("overlayJson")
1043
+ ?: return call.reject(WRONG_INPUT)
1044
+ barcodeCaptureModule.updateOverlay(overlayJson, CapacitorResult(call))
1045
+ }
1046
+
1047
+ @PluginMethod
1048
+ fun updateBarcodeCaptureMode(call: PluginCall) {
1049
+ val modeJson = call.data.getString("modeJson")
1050
+ ?: return call.reject(WRONG_INPUT)
1051
+ barcodeCaptureModule.updateModeFromJson(modeJson, CapacitorResult(call))
1052
+ }
1053
+
1054
+ @PluginMethod
1055
+ fun applyBarcodeCaptureModeSettings(call: PluginCall) {
1056
+ val modeSettingsJson = call.data.getString("modeSettingsJson")
1057
+ ?: return call.reject(WRONG_INPUT)
1058
+ barcodeCaptureModule.applyModeSettings(modeSettingsJson, CapacitorResult(call))
1059
+ }
1060
+
1061
+ @PluginMethod
1062
+ fun updateBarcodeSelectionBasicOverlay(call: PluginCall) {
1063
+ val overlayJson = call.data.getString("overlayJson")
1064
+ ?: return call.reject(WRONG_INPUT)
1065
+ barcodeSelectionModule.updateBasicOverlay(overlayJson, CapacitorResult(call))
1066
+ }
1067
+
1068
+ @PluginMethod
1069
+ fun updateBarcodeSelectionMode(call: PluginCall) {
1070
+ val modeJson = call.data.getString("modeJson")
1071
+ ?: return call.reject(WRONG_INPUT)
1072
+ barcodeSelectionModule.updateModeFromJson(modeJson, CapacitorResult(call))
1073
+ }
1074
+
1075
+ @PluginMethod
1076
+ fun applyBarcodeSelectionModeSettings(call: PluginCall) {
1077
+ val modeSettingsJson = call.data.getString("modeSettingsJson")
1078
+ ?: return call.reject(WRONG_INPUT)
1079
+ barcodeSelectionModule.applyModeSettings(modeSettingsJson, CapacitorResult(call))
1080
+ }
1081
+
1082
+ @PluginMethod
1083
+ fun updateBarcodeTrackingBasicOverlay(call: PluginCall) {
1084
+ val overlayJson = call.data.getString("overlayJson")
1085
+ ?: return call.reject(WRONG_INPUT)
1086
+ barcodeTrackingModule.updateBasicOverlay(overlayJson, CapacitorResult(call))
1087
+ }
1088
+
1089
+ @PluginMethod
1090
+ fun updateBarcodeTrackingAdvancedOverlay(call: PluginCall) {
1091
+ val overlayJson = call.data.getString("overlayJson")
1092
+ ?: return call.reject(WRONG_INPUT)
1093
+ barcodeTrackingModule.updateAdvancedOverlay(overlayJson, CapacitorResult(call))
1094
+ }
1095
+
1096
+ @PluginMethod
1097
+ fun updateBarcodeTrackingMode(call: PluginCall) {
1098
+ val modeJson = call.data.getString("modeJson")
1099
+ ?: return call.reject(WRONG_INPUT)
1100
+ barcodeTrackingModule.updateModeFromJson(modeJson, CapacitorResult(call))
1101
+ }
1102
+
1103
+ @PluginMethod
1104
+ fun applyBarcodeTrackingModeSettings(call: PluginCall) {
1105
+ val modeSettingsJson = call.data.getString("modeSettingsJson")
1106
+ ?: return call.reject(WRONG_INPUT)
1107
+ barcodeTrackingModule.applyModeSettings(modeSettingsJson, CapacitorResult(call))
1108
+ }
1109
+
1110
+ @PluginMethod
1111
+ fun createSparkScanView(call: PluginCall) {
1112
+ val container = bridge.webView ?: run {
1113
+ call.reject(WEB_VIEW_NOT_ATTACHED)
1114
+ return
1115
+ }
1116
+
1117
+ val viewJson = call.data.getString("viewJson").orEmpty()
1118
+ container.post {
1119
+ sparkScanModule.addViewToContainer(
1120
+ container, viewJson, CapacitorResult(call)
1121
+ )
1122
+ }
1123
+
1124
+ sparkScanModule.sparkScanView?.bringToFront()
1125
+ }
1126
+
1127
+ @PluginMethod
1128
+ fun disposeSparkScanView(call: PluginCall) {
1129
+ mainThread.runOnMainThread {
1130
+ sparkScanModule.disposeView()
1131
+ }
1132
+ call.resolve()
1133
+ }
1134
+
1135
+ @PluginMethod
1136
+ fun updateSparkScanView(call: PluginCall) {
1137
+ val viewJson = call.data.toString()
1138
+ sparkScanModule.updateView(
1139
+ viewJson, CapacitorResult(call)
1140
+ )
1141
+ }
1142
+
1143
+ @PluginMethod
1144
+ fun updateSparkScanMode(call: PluginCall) {
1145
+ val modeJson = call.data.getString("sparkScanJson").orEmpty()
1146
+ sparkScanModule.updateMode(
1147
+ modeJson, CapacitorResult(call)
1148
+ )
1149
+ }
1150
+
1151
+ @PluginMethod
1152
+ fun showSparkScanView(call: PluginCall) {
1153
+ mainThread.runOnMainThread {
1154
+ sparkScanModule.sparkScanView?.visibility = View.VISIBLE
1155
+ }
1156
+ call.resolve()
1157
+ }
1158
+
1159
+ @PluginMethod
1160
+ fun hideSparkScanView(call: PluginCall) {
1161
+ mainThread.runOnMainThread {
1162
+ sparkScanModule.sparkScanView?.visibility = View.GONE
1163
+ }
1164
+ call.resolve()
1165
+ }
1166
+
1167
+ @PluginMethod
1168
+ fun registerSparkScanListenerForEvents(call: PluginCall) {
1169
+ sparkScanModule.addSparkScanListener()
1170
+ call.resolve()
1171
+ }
1172
+
1173
+ @PluginMethod
1174
+ fun unregisterSparkScanListenerForEvents(call: PluginCall) {
1175
+ sparkScanModule.removeSparkScanListener()
1176
+ call.resolve()
1177
+ }
1178
+
1179
+ @PluginMethod
1180
+ fun setSparkScanModeEnabledState(call: PluginCall) {
1181
+ sparkScanModule.setModeEnabled(call.data.getBoolean("enabled"))
1182
+ call.resolve()
1183
+ }
1184
+
1185
+ @PluginMethod
1186
+ fun emitSparkScanViewFeedback(call: PluginCall) {
1187
+ sparkScanModule.emitFeedback(
1188
+ call.data.getString("feedback").orEmpty(),
1189
+ CapacitorResult(call)
1190
+ )
1191
+ }
1192
+
1193
+ @PluginMethod
1194
+ fun finishSparkScanDidUpdateSessionCallback(call: PluginCall) {
1195
+ sparkScanModule.finishDidUpdateSessionCallback(call.data.getBoolean("enabled"))
1196
+ call.resolve()
1197
+ }
1198
+
1199
+ @PluginMethod
1200
+ fun finishSparkScanDidScanCallback(call: PluginCall) {
1201
+ sparkScanModule.finishDidScanCallback(call.data.getBoolean("enabled"))
1202
+ call.resolve()
1203
+ }
1204
+
1205
+ @PluginMethod
1206
+ fun registerSparkScanViewListenerEvents(call: PluginCall) {
1207
+ sparkScanModule.addSparkScanViewUiListener()
1208
+ call.resolve()
1209
+ }
1210
+
1211
+ @PluginMethod
1212
+ fun unregisterSparkScanViewListenerEvents(call: PluginCall) {
1213
+ sparkScanModule.removeSparkScanViewUiListener()
1214
+ call.resolve()
1215
+ }
1216
+
1217
+ @PluginMethod
1218
+ fun prepareSparkScanViewScanning(call: PluginCall) {
1219
+ sparkScanModule.onResume(CapacitorResult(call))
1220
+ }
1221
+
1222
+ @PluginMethod
1223
+ fun startSparkScanViewScanning(call: PluginCall) {
1224
+ sparkScanModule.startScanning(CapacitorResult(call))
1225
+ }
1226
+
1227
+ @PluginMethod
1228
+ fun pauseSparkScanViewScanning(call: PluginCall) {
1229
+ sparkScanModule.pauseScanning()
1230
+ call.resolve()
1231
+ }
1232
+
1233
+ @PluginMethod
1234
+ fun stopSparkScanViewScanning(call: PluginCall) {
1235
+ sparkScanModule.onPause()
1236
+ call.resolve()
1237
+ }
909
1238
  }
@@ -0,0 +1,139 @@
1
+ package com.scandit.capacitor.datacapture.barcode.pick
2
+
3
+ import android.content.Context
4
+ import android.graphics.Color
5
+ import android.view.View
6
+ import android.view.ViewGroup
7
+ import android.widget.FrameLayout
8
+ import androidx.appcompat.app.AppCompatActivity
9
+ import androidx.core.view.children
10
+ import com.scandit.capacitor.datacapture.core.data.ResizeAndMoveInfo
11
+ import com.scandit.capacitor.datacapture.core.utils.pxFromDp
12
+ import com.scandit.capacitor.datacapture.core.utils.removeFromParent
13
+ import com.scandit.datacapture.barcode.find.ui.BarcodeFindView
14
+ import com.scandit.datacapture.barcode.pick.ui.BarcodePickView
15
+ import com.scandit.datacapture.frameworks.core.utils.DefaultMainThread
16
+ import com.scandit.datacapture.frameworks.core.utils.MainThread
17
+ import java.lang.ref.WeakReference
18
+
19
+ class BarcodePickViewHandler (
20
+ private val mainThread: MainThread = DefaultMainThread.getInstance()
21
+ ) {
22
+ private var latestInfo: ResizeAndMoveInfo = ResizeAndMoveInfo(0, 0, 600, 600, false)
23
+ private var isVisible: Boolean = true
24
+ private var barcodePickViewContainerReference: WeakReference<FrameLayout>? = null
25
+ private var webViewReference: WeakReference<View>? = null
26
+
27
+ val barcodePickViewContainer: FrameLayout?
28
+ get() = barcodePickViewContainerReference?.get()
29
+
30
+ private val webView: View?
31
+ get() = webViewReference?.get()
32
+
33
+ fun prepareContainer(context: Context) : FrameLayout {
34
+ return FrameLayout(context)
35
+ }
36
+
37
+ fun addBarcodePickViewContainer(container: FrameLayout, activity: AppCompatActivity) {
38
+ if (this.barcodePickViewContainer != container) {
39
+ disposeCurrentView()
40
+ addContainer(container, activity)
41
+ }
42
+ }
43
+
44
+ fun attachWebView(webView: View, @Suppress("UNUSED_PARAMETER") activity: AppCompatActivity) {
45
+ if (this.webView != webView) {
46
+ webViewReference = WeakReference(webView)
47
+ webView.bringToFront()
48
+ webView.setBackgroundColor(Color.TRANSPARENT)
49
+ }
50
+ }
51
+
52
+ fun setVisible() {
53
+ isVisible = true
54
+ render()
55
+ }
56
+
57
+ fun setInvisible() {
58
+ isVisible = false
59
+ render()
60
+ }
61
+
62
+ fun setResizeAndMoveInfo(info: ResizeAndMoveInfo) {
63
+ latestInfo = info
64
+ render()
65
+ }
66
+
67
+ fun disposeCurrent() {
68
+ disposeCurrentView()
69
+ disposeCurrentWebView()
70
+ }
71
+
72
+ private fun disposeCurrentView() {
73
+ val view = barcodePickViewContainer ?: return
74
+ removeBarcodePickViewContainer(view)
75
+ }
76
+
77
+ private fun disposeCurrentWebView() {
78
+ webViewReference = null
79
+ }
80
+
81
+ private fun addContainer(
82
+ barcodeFindViewContainer: FrameLayout,
83
+ activity: AppCompatActivity
84
+ ) {
85
+ barcodePickViewContainerReference = WeakReference(barcodeFindViewContainer)
86
+
87
+ mainThread.runOnMainThread {
88
+ activity.addContentView(
89
+ barcodePickViewContainer,
90
+ ViewGroup.LayoutParams(
91
+ ViewGroup.LayoutParams.MATCH_PARENT,
92
+ ViewGroup.LayoutParams.MATCH_PARENT
93
+ )
94
+ )
95
+ render()
96
+ }
97
+ }
98
+
99
+ private fun removeBarcodePickViewContainer(barcodePickViewContainer: FrameLayout) {
100
+ barcodePickViewContainerReference = null
101
+ removeView(barcodePickViewContainer) {
102
+ (barcodePickViewContainer.children.firstOrNull() as? BarcodePickView)?.listener = null
103
+ (barcodePickViewContainer.children.firstOrNull() as? BarcodePickView)?.uiListener = null
104
+ }
105
+ }
106
+
107
+ private fun removeView(view: View, uiBlock: (() -> Unit)? = null) {
108
+ mainThread.runOnMainThread {
109
+ view.removeFromParent()
110
+ uiBlock?.invoke()
111
+ }
112
+ }
113
+
114
+ // Update the view visibility, position and size.
115
+ fun render() {
116
+ val view = barcodePickViewContainer ?: return
117
+ renderNoAnimate(view)
118
+ }
119
+
120
+ private fun renderNoAnimate(barcodePickViewContainer: FrameLayout) {
121
+ barcodePickViewContainer.post {
122
+ barcodePickViewContainer.visibility = if (isVisible) View.VISIBLE else View.GONE
123
+ barcodePickViewContainer.x = latestInfo.left.pxFromDp()
124
+ barcodePickViewContainer.y = latestInfo.top.pxFromDp()
125
+ barcodePickViewContainer.layoutParams.apply {
126
+ width = ViewGroup.LayoutParams.MATCH_PARENT
127
+ height = ViewGroup.LayoutParams.MATCH_PARENT
128
+ }
129
+ if (latestInfo.shouldBeUnderWebView) {
130
+ webView?.bringToFront()
131
+ (webView?.parent as View).translationZ = 1F
132
+ } else {
133
+ barcodePickViewContainer.bringToFront()
134
+ (webView?.parent as View).translationZ = -1F
135
+ }
136
+ barcodePickViewContainer.requestLayout()
137
+ }
138
+ }
139
+ }