scandit-capacitor-datacapture-core 8.1.1 → 8.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ScanditCapacitorDatacaptureCore.podspec +1 -1
- package/android/build.gradle +76 -24
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/ScanditCaptureCoreNative.java +311 -0
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/data/ResizeAndMoveInfo.java +44 -0
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/errors/ActionError.java +33 -0
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/errors/JsonParseError.java +18 -0
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/handlers/DataCaptureViewHandler.java +422 -0
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/utils/{Callback.kt → Callback.java} +7 -8
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/utils/CapacitorExtensions.java +31 -0
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/utils/CapacitorMethodCall.java +57 -0
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/utils/CapacitorResult.java +129 -0
- package/dist/core.js +473 -102
- package/dist/core.js.map +1 -1
- package/dist/dts/definitions.d.ts +6 -0
- package/dist/index.js +16 -4
- package/dist/index.js.map +1 -1
- package/ios/Sources/ScanditCapacitorCore/CapacitorMethodCall.swift +24 -1
- package/ios/Sources/ScanditCapacitorCore/CapacitorResult.swift +4 -0
- package/ios/Sources/ScanditCapacitorCore/ScanditCaptureCore.swift +21 -229
- package/package.json +7 -7
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/ScanditCaptureCoreNative.kt +0 -402
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/data/ResizeAndMoveInfo.kt +0 -15
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/data/SerializableCallbackAction.kt +0 -34
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/data/SerializableData.kt +0 -13
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/data/SerializableFinishModeCallbackData.kt +0 -20
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/data/defaults/SerializableBrushDefaults.kt +0 -49
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/data/defaults/SerializableCameraSettingsDefault.kt +0 -51
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/errors/ActionError.kt +0 -27
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/errors/JsonParseError.kt +0 -18
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/handlers/DataCaptureViewHandler.kt +0 -363
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/utils/CapacitorMethodCall.kt +0 -22
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/utils/CapacitorResult.kt +0 -40
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/utils/Extensions.kt +0 -28
|
@@ -0,0 +1,422 @@
|
|
|
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.handlers;
|
|
8
|
+
|
|
9
|
+
import static com.scandit.capacitor.datacapture.core.utils.CapacitorExtensions.*;
|
|
10
|
+
|
|
11
|
+
import android.annotation.SuppressLint;
|
|
12
|
+
import android.graphics.Color;
|
|
13
|
+
import android.os.Handler;
|
|
14
|
+
import android.os.Looper;
|
|
15
|
+
import android.os.SystemClock;
|
|
16
|
+
import android.view.MotionEvent;
|
|
17
|
+
import android.view.View;
|
|
18
|
+
import android.view.ViewGroup;
|
|
19
|
+
import android.widget.FrameLayout;
|
|
20
|
+
import com.getcapacitor.Bridge;
|
|
21
|
+
import com.scandit.capacitor.datacapture.core.data.ResizeAndMoveInfo;
|
|
22
|
+
import com.scandit.datacapture.core.ui.DataCaptureView;
|
|
23
|
+
import com.scandit.datacapture.frameworks.core.utils.DefaultFrameworksLog;
|
|
24
|
+
import com.scandit.datacapture.frameworks.core.utils.FrameworksLog;
|
|
25
|
+
import java.lang.ref.WeakReference;
|
|
26
|
+
import java.util.ArrayList;
|
|
27
|
+
import java.util.List;
|
|
28
|
+
import java.util.Locale;
|
|
29
|
+
|
|
30
|
+
public class DataCaptureViewHandler {
|
|
31
|
+
|
|
32
|
+
private static final long TOUCH_EVALUATION_TIMEOUT_MS = 20L;
|
|
33
|
+
private static final int MAX_PENDING_TOUCH_EVENTS = 40;
|
|
34
|
+
|
|
35
|
+
private final FrameworksLog logger;
|
|
36
|
+
private ResizeAndMoveInfo latestInfo;
|
|
37
|
+
private boolean isVisible;
|
|
38
|
+
private WeakReference<DataCaptureView> dataCaptureViewReference;
|
|
39
|
+
private WeakReference<View> webViewReference;
|
|
40
|
+
private View.OnTouchListener webViewTouchForwarder;
|
|
41
|
+
private final List<MotionEvent> pendingTouchEvents;
|
|
42
|
+
private boolean shouldForwardTouchEvents;
|
|
43
|
+
private boolean isEvaluatingTouchTarget;
|
|
44
|
+
private int currentTouchEvaluationToken;
|
|
45
|
+
private final Handler evaluationTimeoutHandler;
|
|
46
|
+
private Runnable evaluationTimeoutRunnable;
|
|
47
|
+
private long evaluationStartElapsedMs;
|
|
48
|
+
|
|
49
|
+
public DataCaptureViewHandler() {
|
|
50
|
+
this(DefaultFrameworksLog.getInstance());
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public DataCaptureViewHandler(FrameworksLog logger) {
|
|
54
|
+
this.logger = logger;
|
|
55
|
+
this.latestInfo = new ResizeAndMoveInfo(0f, 0f, 0f, 0f, false);
|
|
56
|
+
this.isVisible = false;
|
|
57
|
+
this.dataCaptureViewReference = new WeakReference<>(null);
|
|
58
|
+
this.webViewReference = new WeakReference<>(null);
|
|
59
|
+
this.webViewTouchForwarder = null;
|
|
60
|
+
this.pendingTouchEvents = new ArrayList<>();
|
|
61
|
+
this.shouldForwardTouchEvents = false;
|
|
62
|
+
this.isEvaluatingTouchTarget = false;
|
|
63
|
+
this.currentTouchEvaluationToken = 0;
|
|
64
|
+
this.evaluationTimeoutHandler = new Handler(Looper.getMainLooper());
|
|
65
|
+
this.evaluationTimeoutRunnable = null;
|
|
66
|
+
this.evaluationStartElapsedMs = 0L;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private View getWebView() {
|
|
70
|
+
return webViewReference.get();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public DataCaptureView getDataCaptureView() {
|
|
74
|
+
return dataCaptureViewReference.get();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public void setVisible() {
|
|
78
|
+
isVisible = true;
|
|
79
|
+
render();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public void setInvisible() {
|
|
83
|
+
isVisible = false;
|
|
84
|
+
render();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public void setResizeAndMoveInfo(ResizeAndMoveInfo info) {
|
|
88
|
+
latestInfo = info;
|
|
89
|
+
render();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public void disposeCurrentWebView() {
|
|
93
|
+
clearWebViewTouchForwarder();
|
|
94
|
+
webViewReference = new WeakReference<>(null);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@SuppressLint("ClickableViewAccessibility")
|
|
98
|
+
public void addDataCaptureView(DataCaptureView dataCaptureView, Bridge bridge) {
|
|
99
|
+
dataCaptureViewReference = new WeakReference<>(dataCaptureView);
|
|
100
|
+
|
|
101
|
+
bridge.executeOnMainThread(
|
|
102
|
+
new Runnable() {
|
|
103
|
+
@Override
|
|
104
|
+
public void run() {
|
|
105
|
+
FrameLayout dcContainer = new FrameLayout(bridge.getContext());
|
|
106
|
+
dcContainer.setMinimumHeight(bridge.getWebView().getHeight());
|
|
107
|
+
dcContainer.setMinimumWidth(bridge.getWebView().getWidth());
|
|
108
|
+
dcContainer.setBackgroundColor(Color.TRANSPARENT);
|
|
109
|
+
|
|
110
|
+
// Add DataCaptureView to the container
|
|
111
|
+
dcContainer.addView(dataCaptureView);
|
|
112
|
+
|
|
113
|
+
ViewGroup parent = (ViewGroup) bridge.getWebView().getParent();
|
|
114
|
+
ViewGroup.LayoutParams layoutParams =
|
|
115
|
+
new ViewGroup.LayoutParams(
|
|
116
|
+
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
117
|
+
// Add container to the same parent of the WebView
|
|
118
|
+
parent.addView(dcContainer, layoutParams);
|
|
119
|
+
|
|
120
|
+
// create touch listener
|
|
121
|
+
View.OnTouchListener touchForwarder =
|
|
122
|
+
new View.OnTouchListener() {
|
|
123
|
+
@Override
|
|
124
|
+
public boolean onTouch(View v, MotionEvent event) {
|
|
125
|
+
switch (event.getActionMasked()) {
|
|
126
|
+
case MotionEvent.ACTION_DOWN:
|
|
127
|
+
handleActionDown(event, bridge, dcContainer);
|
|
128
|
+
break;
|
|
129
|
+
case MotionEvent.ACTION_UP:
|
|
130
|
+
case MotionEvent.ACTION_CANCEL:
|
|
131
|
+
handleActionUp(event, dcContainer);
|
|
132
|
+
break;
|
|
133
|
+
default:
|
|
134
|
+
handleOtherActions(event, dcContainer);
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
bridge.getWebView().setOnTouchListener(touchForwarder);
|
|
142
|
+
webViewTouchForwarder = touchForwarder;
|
|
143
|
+
|
|
144
|
+
bridge.getWebView().bringToFront();
|
|
145
|
+
bridge.getWebView().setBackgroundColor(Color.TRANSPARENT);
|
|
146
|
+
|
|
147
|
+
webViewReference = new WeakReference<>(bridge.getWebView());
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
private void handleActionUp(MotionEvent event, FrameLayout dcViewParent) {
|
|
153
|
+
handleOtherActions(event, dcViewParent);
|
|
154
|
+
|
|
155
|
+
if (!isEvaluatingTouchTarget) {
|
|
156
|
+
resetTouchForwardingState();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private void handleOtherActions(MotionEvent event, FrameLayout dcViewParent) {
|
|
161
|
+
if (isEvaluatingTouchTarget) {
|
|
162
|
+
addPendingTouchEvent(event);
|
|
163
|
+
} else if (shouldForwardTouchEvents) {
|
|
164
|
+
forwardEventToDataCaptureView(dcViewParent, event);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private void handleActionDown(MotionEvent event, Bridge bridge, FrameLayout dcViewParent) {
|
|
169
|
+
currentTouchEvaluationToken += 1;
|
|
170
|
+
int evaluationToken = currentTouchEvaluationToken;
|
|
171
|
+
shouldForwardTouchEvents = false;
|
|
172
|
+
isEvaluatingTouchTarget = true;
|
|
173
|
+
evaluationStartElapsedMs = SystemClock.elapsedRealtime();
|
|
174
|
+
clearPendingTouchEvents();
|
|
175
|
+
addPendingTouchEvent(event);
|
|
176
|
+
evaluateTouchTarget(event, bridge, evaluationToken, dcViewParent);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
public void removeDataCaptureView(DataCaptureView dataCaptureView) {
|
|
180
|
+
if (getDataCaptureView() == dataCaptureView) {
|
|
181
|
+
dataCaptureViewReference = new WeakReference<>(null);
|
|
182
|
+
}
|
|
183
|
+
clearWebViewTouchForwarder();
|
|
184
|
+
removeView(dataCaptureView);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private void removeView(View view) {
|
|
188
|
+
view.post(
|
|
189
|
+
new Runnable() {
|
|
190
|
+
@Override
|
|
191
|
+
public void run() {
|
|
192
|
+
removeFromParent(view);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Update the view visibility, position and size.
|
|
198
|
+
private void render() {
|
|
199
|
+
DataCaptureView view = getDataCaptureView();
|
|
200
|
+
if (view == null) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
FrameLayout dcViewParent = (FrameLayout) view.getParent();
|
|
204
|
+
|
|
205
|
+
view.post(
|
|
206
|
+
new Runnable() {
|
|
207
|
+
@Override
|
|
208
|
+
public void run() {
|
|
209
|
+
view.setVisibility(isVisible ? View.VISIBLE : View.GONE);
|
|
210
|
+
view.setX(pxFromDp(latestInfo.getLeft()));
|
|
211
|
+
view.setY(pxFromDp(latestInfo.getTop()));
|
|
212
|
+
ViewGroup.LayoutParams params = view.getLayoutParams();
|
|
213
|
+
params.width = (int) pxFromDp(latestInfo.getWidth());
|
|
214
|
+
params.height = (int) pxFromDp(latestInfo.getHeight());
|
|
215
|
+
|
|
216
|
+
View webView = getWebView();
|
|
217
|
+
if (latestInfo.getShouldBeUnderWebView()) {
|
|
218
|
+
if (webView != null) {
|
|
219
|
+
webView.bringToFront();
|
|
220
|
+
webView.setTranslationZ(2F);
|
|
221
|
+
}
|
|
222
|
+
if (dcViewParent != null) {
|
|
223
|
+
dcViewParent.setTranslationZ(1F);
|
|
224
|
+
}
|
|
225
|
+
} else {
|
|
226
|
+
if (dcViewParent != null) {
|
|
227
|
+
dcViewParent.bringToFront();
|
|
228
|
+
dcViewParent.setTranslationZ(2F);
|
|
229
|
+
}
|
|
230
|
+
if (webView != null) {
|
|
231
|
+
webView.setTranslationZ(1F);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
view.requestLayout();
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
private void evaluateTouchTarget(
|
|
241
|
+
MotionEvent event, Bridge bridge, int evaluationToken, FrameLayout dcViewParent) {
|
|
242
|
+
String rawX = formatCoordinate(event.getX());
|
|
243
|
+
String rawY = formatCoordinate(event.getY());
|
|
244
|
+
String webViewScale = formatCoordinate(1f);
|
|
245
|
+
|
|
246
|
+
String js =
|
|
247
|
+
"(function() {\n"
|
|
248
|
+
+ " var rawX = "
|
|
249
|
+
+ rawX
|
|
250
|
+
+ ";\n"
|
|
251
|
+
+ " var rawY = "
|
|
252
|
+
+ rawY
|
|
253
|
+
+ ";\n"
|
|
254
|
+
+ " var webViewScale = "
|
|
255
|
+
+ webViewScale
|
|
256
|
+
+ ";\n"
|
|
257
|
+
+ " var dpr = window.devicePixelRatio || 1;\n"
|
|
258
|
+
+ " var viewportScale = (window.visualViewport && window.visualViewport.scale) ? window.visualViewport.scale : 1;\n"
|
|
259
|
+
+ "\n"
|
|
260
|
+
+ " var cssX = rawX / (dpr * viewportScale / webViewScale);\n"
|
|
261
|
+
+ " var cssY = rawY / (dpr * viewportScale / webViewScale);\n"
|
|
262
|
+
+ "\n"
|
|
263
|
+
+ " var container = document.querySelector('.data-capture-view');\n"
|
|
264
|
+
+ " if (!container) { return true; }\n"
|
|
265
|
+
+ "\n"
|
|
266
|
+
+ " var rect = container.getBoundingClientRect();\n"
|
|
267
|
+
+ " var x = cssX;\n"
|
|
268
|
+
+ " var y = cssY;\n"
|
|
269
|
+
+ "\n"
|
|
270
|
+
+ " if (x < rect.left || x > rect.right || y < rect.top || y > rect.bottom) {\n"
|
|
271
|
+
+ " return true;\n"
|
|
272
|
+
+ " }\n"
|
|
273
|
+
+ "\n"
|
|
274
|
+
+ " var el = document.elementFromPoint(x, y);\n"
|
|
275
|
+
+ " if (!el) { return true; }\n"
|
|
276
|
+
+ " \n"
|
|
277
|
+
+ " if (el.classList.contains('data-capture-view') || el.closest('.data-capture-view') === container) {\n"
|
|
278
|
+
+ " return false;\n"
|
|
279
|
+
+ " }\n"
|
|
280
|
+
+ "\n"
|
|
281
|
+
+ " return true;\n"
|
|
282
|
+
+ "})();";
|
|
283
|
+
|
|
284
|
+
scheduleEvaluationTimeout(evaluationToken, dcViewParent);
|
|
285
|
+
|
|
286
|
+
try {
|
|
287
|
+
bridge
|
|
288
|
+
.getWebView()
|
|
289
|
+
.evaluateJavascript(
|
|
290
|
+
js,
|
|
291
|
+
new android.webkit.ValueCallback<String>() {
|
|
292
|
+
@Override
|
|
293
|
+
public void onReceiveValue(String value) {
|
|
294
|
+
if (evaluationToken != currentTouchEvaluationToken) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
long durationMs = SystemClock.elapsedRealtime() - evaluationStartElapsedMs;
|
|
299
|
+
if (durationMs > TOUCH_EVALUATION_TIMEOUT_MS) {
|
|
300
|
+
logger.info("Touch evaluation resolved in " + durationMs + "ms");
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
boolean shouldForward = parseShouldForwardValue(value);
|
|
304
|
+
handleTouchEvaluationResult(shouldForward, dcViewParent);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
} catch (Exception e) {
|
|
308
|
+
if (evaluationToken == currentTouchEvaluationToken) {
|
|
309
|
+
logger.error("Touch evaluation failed", e);
|
|
310
|
+
handleTouchEvaluationResult(false, dcViewParent);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
private void handleTouchEvaluationResult(boolean shouldForward, FrameLayout dcViewParent) {
|
|
316
|
+
isEvaluatingTouchTarget = false;
|
|
317
|
+
shouldForwardTouchEvents = shouldForward;
|
|
318
|
+
cancelEvaluationTimeout();
|
|
319
|
+
|
|
320
|
+
if (shouldForward) {
|
|
321
|
+
for (MotionEvent event : pendingTouchEvents) {
|
|
322
|
+
dcViewParent.dispatchTouchEvent(event);
|
|
323
|
+
event.recycle();
|
|
324
|
+
}
|
|
325
|
+
} else {
|
|
326
|
+
for (MotionEvent event : pendingTouchEvents) {
|
|
327
|
+
event.recycle();
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
pendingTouchEvents.clear();
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
private void forwardEventToDataCaptureView(FrameLayout dcViewParent, MotionEvent event) {
|
|
335
|
+
MotionEvent eventCopy = MotionEvent.obtain(event);
|
|
336
|
+
dcViewParent.dispatchTouchEvent(eventCopy);
|
|
337
|
+
eventCopy.recycle();
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
private void clearPendingTouchEvents() {
|
|
341
|
+
for (MotionEvent event : pendingTouchEvents) {
|
|
342
|
+
event.recycle();
|
|
343
|
+
}
|
|
344
|
+
pendingTouchEvents.clear();
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
private void addPendingTouchEvent(MotionEvent event) {
|
|
348
|
+
if (pendingTouchEvents.size() >= MAX_PENDING_TOUCH_EVENTS) {
|
|
349
|
+
MotionEvent oldest = pendingTouchEvents.remove(0);
|
|
350
|
+
oldest.recycle();
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
pendingTouchEvents.add(MotionEvent.obtain(event));
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
private void resetTouchForwardingState() {
|
|
357
|
+
shouldForwardTouchEvents = false;
|
|
358
|
+
isEvaluatingTouchTarget = false;
|
|
359
|
+
clearPendingTouchEvents();
|
|
360
|
+
currentTouchEvaluationToken += 1;
|
|
361
|
+
cancelEvaluationTimeout();
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
private void clearWebViewTouchForwarder() {
|
|
365
|
+
View webView = webViewReference.get();
|
|
366
|
+
if (webView != null) {
|
|
367
|
+
webView.setOnTouchListener(null);
|
|
368
|
+
}
|
|
369
|
+
webViewTouchForwarder = null;
|
|
370
|
+
resetTouchForwardingState();
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
private void scheduleEvaluationTimeout(int evaluationToken, FrameLayout dcViewParent) {
|
|
374
|
+
cancelEvaluationTimeout();
|
|
375
|
+
|
|
376
|
+
Runnable runnable =
|
|
377
|
+
new Runnable() {
|
|
378
|
+
@Override
|
|
379
|
+
public void run() {
|
|
380
|
+
if (evaluationToken != currentTouchEvaluationToken || !isEvaluatingTouchTarget) {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
logger.info("Touch evaluation timed out after " + TOUCH_EVALUATION_TIMEOUT_MS + "ms");
|
|
385
|
+
handleTouchEvaluationResult(false, dcViewParent);
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
evaluationTimeoutRunnable = runnable;
|
|
390
|
+
evaluationTimeoutHandler.postDelayed(runnable, TOUCH_EVALUATION_TIMEOUT_MS);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
private void cancelEvaluationTimeout() {
|
|
394
|
+
if (evaluationTimeoutRunnable != null) {
|
|
395
|
+
evaluationTimeoutHandler.removeCallbacks(evaluationTimeoutRunnable);
|
|
396
|
+
}
|
|
397
|
+
evaluationTimeoutRunnable = null;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
private boolean parseShouldForwardValue(String value) {
|
|
401
|
+
String normalized =
|
|
402
|
+
value != null ? value.trim().replace("\"", "").toLowerCase(Locale.US) : null;
|
|
403
|
+
if (normalized == null) {
|
|
404
|
+
logger.error("Touch evaluation returned null result");
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
switch (normalized) {
|
|
409
|
+
case "true":
|
|
410
|
+
return false;
|
|
411
|
+
case "false":
|
|
412
|
+
return true;
|
|
413
|
+
default:
|
|
414
|
+
logger.error("Touch evaluation returned unexpected value: " + normalized);
|
|
415
|
+
return false;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
private String formatCoordinate(float value) {
|
|
420
|
+
return String.format(Locale.US, "%.4f", value);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
@@ -4,19 +4,18 @@
|
|
|
4
4
|
* Copyright (C) 2019- Scandit AG. All rights reserved.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
package com.scandit.capacitor.datacapture.core.utils
|
|
7
|
+
package com.scandit.capacitor.datacapture.core.utils;
|
|
8
8
|
|
|
9
|
-
import java.util.concurrent.atomic.AtomicBoolean
|
|
9
|
+
import java.util.concurrent.atomic.AtomicBoolean;
|
|
10
10
|
|
|
11
11
|
// Used as a base class for all the callback. Suppressed the warning because import
|
|
12
12
|
// doesn't contain any abstract members but we keep it abstract to avoid someone
|
|
13
13
|
// creating an instance of the class.
|
|
14
|
-
|
|
15
|
-
abstract class Callback {
|
|
14
|
+
public abstract class Callback {
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
protected final AtomicBoolean disposed = new AtomicBoolean(false);
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
public void dispose() {
|
|
19
|
+
disposed.set(true);
|
|
20
|
+
}
|
|
22
21
|
}
|
package/android/src/main/java/com/scandit/capacitor/datacapture/core/utils/CapacitorExtensions.java
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
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.utils;
|
|
8
|
+
|
|
9
|
+
import android.view.View;
|
|
10
|
+
import android.view.ViewGroup;
|
|
11
|
+
import com.scandit.datacapture.core.internal.sdk.AppAndroidEnvironment;
|
|
12
|
+
|
|
13
|
+
public final class CapacitorExtensions {
|
|
14
|
+
|
|
15
|
+
private CapacitorExtensions() {
|
|
16
|
+
// Private constructor to prevent instantiation
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public static float pxFromDp(float dp) {
|
|
20
|
+
android.content.Context context = AppAndroidEnvironment.INSTANCE.getApplicationContext();
|
|
21
|
+
float displayDensity = context.getResources().getDisplayMetrics().density;
|
|
22
|
+
return (dp * displayDensity + 0.5f);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public static void removeFromParent(View view) {
|
|
26
|
+
if (view.getParent() instanceof ViewGroup) {
|
|
27
|
+
ViewGroup parent = (ViewGroup) view.getParent();
|
|
28
|
+
parent.removeView(view);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
package/android/src/main/java/com/scandit/capacitor/datacapture/core/utils/CapacitorMethodCall.java
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
package com.scandit.capacitor.datacapture.core.utils;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.getcapacitor.PluginCall;
|
|
5
|
+
import com.scandit.datacapture.frameworks.core.method.FrameworksMethodCall;
|
|
6
|
+
import java.util.HashMap;
|
|
7
|
+
import java.util.Iterator;
|
|
8
|
+
import java.util.Map;
|
|
9
|
+
import org.json.JSONObject;
|
|
10
|
+
|
|
11
|
+
public class CapacitorMethodCall implements FrameworksMethodCall {
|
|
12
|
+
|
|
13
|
+
private final PluginCall call;
|
|
14
|
+
|
|
15
|
+
public CapacitorMethodCall(PluginCall call) {
|
|
16
|
+
this.call = call;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@NonNull
|
|
20
|
+
@Override
|
|
21
|
+
public String getMethod() {
|
|
22
|
+
String methodName = call.getData().getString("methodName");
|
|
23
|
+
return methodName != null ? methodName : "unknown";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@Override
|
|
27
|
+
@SuppressWarnings("unchecked")
|
|
28
|
+
public <T> T argument(@NonNull String key) {
|
|
29
|
+
// Check if key exists and is explicitly null
|
|
30
|
+
if (!call.getData().has(key) || call.getData().isNull(key)) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return (T) call.getData().opt(key);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Override
|
|
38
|
+
public boolean hasArgument(@NonNull String key) {
|
|
39
|
+
return call.getData().has(key);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@NonNull
|
|
43
|
+
@Override
|
|
44
|
+
public Map<String, Object> arguments() {
|
|
45
|
+
return jsonObjectToMap(call.getData());
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private Map<String, Object> jsonObjectToMap(JSONObject json) {
|
|
49
|
+
Map<String, Object> map = new HashMap<>();
|
|
50
|
+
Iterator<String> keys = json.keys();
|
|
51
|
+
while (keys.hasNext()) {
|
|
52
|
+
String key = keys.next();
|
|
53
|
+
map.put(key, json.opt(key));
|
|
54
|
+
}
|
|
55
|
+
return map;
|
|
56
|
+
}
|
|
57
|
+
}
|
package/android/src/main/java/com/scandit/capacitor/datacapture/core/utils/CapacitorResult.java
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
package com.scandit.capacitor.datacapture.core.utils;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.getcapacitor.JSObject;
|
|
5
|
+
import com.getcapacitor.PluginCall;
|
|
6
|
+
import com.scandit.datacapture.frameworks.core.result.FrameworksResult;
|
|
7
|
+
import java.util.Map;
|
|
8
|
+
import org.json.JSONObject;
|
|
9
|
+
|
|
10
|
+
public class CapacitorResult implements FrameworksResult {
|
|
11
|
+
|
|
12
|
+
private final PluginCall call;
|
|
13
|
+
|
|
14
|
+
public CapacitorResult(PluginCall call) {
|
|
15
|
+
this.call = call;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Override
|
|
19
|
+
public void success(Object result) {
|
|
20
|
+
if (result == null) {
|
|
21
|
+
call.resolve();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
String resultData;
|
|
26
|
+
if (result instanceof Map) {
|
|
27
|
+
resultData = new JSONObject((Map<?, ?>) result).toString();
|
|
28
|
+
} else {
|
|
29
|
+
resultData = result.toString();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
JSObject capacitorPayload = new JSObject();
|
|
33
|
+
capacitorPayload.put("data", resultData);
|
|
34
|
+
|
|
35
|
+
call.resolve(capacitorPayload);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Override
|
|
39
|
+
public void error(@NonNull String errorCode, String errorMessage, Object errorDetails) {
|
|
40
|
+
call.reject(errorMessage, errorMessage);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@Override
|
|
44
|
+
public void unregisterViewSpecificCallback(
|
|
45
|
+
int viewId, @NonNull java.util.List<String> eventNames) {
|
|
46
|
+
// noop for Capacitor
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@Override
|
|
50
|
+
public void registerViewSpecificCallback(int viewId, @NonNull java.util.List<String> eventNames) {
|
|
51
|
+
// noop for Capacitor
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@Override
|
|
55
|
+
public void registerModeSpecificCallback(int modeId, @NonNull java.util.List<String> eventNames) {
|
|
56
|
+
// noop for Capacitor
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@Override
|
|
60
|
+
public void unregisterModeSpecificCallback(
|
|
61
|
+
int modeId, @NonNull java.util.List<String> eventNames) {
|
|
62
|
+
// noop for Capacitor
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@Override
|
|
66
|
+
public void registerCallbackForEvents(@NonNull java.util.List<String> eventNames) {
|
|
67
|
+
// noop for Capacitor
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@Override
|
|
71
|
+
public void unregisterCallbackForEvents(@NonNull java.util.List<String> eventNames) {
|
|
72
|
+
// noop for Capacitor
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@Override
|
|
76
|
+
public void successAndKeepCallback(Object result) {
|
|
77
|
+
success(result);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
class CapacitorNoopResult implements FrameworksResult {
|
|
82
|
+
|
|
83
|
+
@Override
|
|
84
|
+
public void success(Object result) {
|
|
85
|
+
// noop
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@Override
|
|
89
|
+
public void error(@NonNull String errorCode, String errorMessage, Object errorDetails) {
|
|
90
|
+
// noop
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@Override
|
|
94
|
+
public void unregisterViewSpecificCallback(
|
|
95
|
+
int viewId, @NonNull java.util.List<String> eventNames) {
|
|
96
|
+
// noop
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@Override
|
|
100
|
+
public void registerViewSpecificCallback(int viewId, @NonNull java.util.List<String> eventNames) {
|
|
101
|
+
// noop
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@Override
|
|
105
|
+
public void registerModeSpecificCallback(int modeId, @NonNull java.util.List<String> eventNames) {
|
|
106
|
+
// noop
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@Override
|
|
110
|
+
public void unregisterModeSpecificCallback(
|
|
111
|
+
int modeId, @NonNull java.util.List<String> eventNames) {
|
|
112
|
+
// noop
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@Override
|
|
116
|
+
public void registerCallbackForEvents(@NonNull java.util.List<String> eventNames) {
|
|
117
|
+
// noop
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@Override
|
|
121
|
+
public void unregisterCallbackForEvents(@NonNull java.util.List<String> eventNames) {
|
|
122
|
+
// noop
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@Override
|
|
126
|
+
public void successAndKeepCallback(Object result) {
|
|
127
|
+
// noop
|
|
128
|
+
}
|
|
129
|
+
}
|