scandit-capacitor-datacapture-barcode 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/ScanditCapacitorDatacaptureBarcode.podspec +1 -1
- package/android/build.gradle +71 -23
- package/android/src/main/java/com/scandit/capacitor/datacapture/barcode/ScanditBarcodeNative.java +593 -0
- package/android/src/main/java/com/scandit/capacitor/datacapture/barcode/ar/BarcodeArViewHandler.java +146 -0
- package/android/src/main/java/com/scandit/capacitor/datacapture/barcode/count/BarcodeCountViewHandler.java +143 -0
- package/android/src/main/java/com/scandit/capacitor/datacapture/barcode/find/BarcodeFindViewHandler.java +181 -0
- package/android/src/main/java/com/scandit/capacitor/datacapture/barcode/pick/BarcodePickViewHandler.java +152 -0
- package/dist/barcode.js +5271 -1377
- package/dist/barcode.js.map +1 -1
- package/dist/dts/definitions.d.ts +35 -8
- package/dist/dts/ts/BarcodeArView.d.ts +57 -0
- package/dist/dts/ts/BarcodeBatchAdvancedOverlay.d.ts +1 -0
- package/dist/dts/ts/BarcodeFindView.d.ts +1 -0
- package/dist/dts/web.d.ts +1 -3
- package/dist/index.js +562 -316
- package/dist/index.js.map +1 -1
- package/ios/Sources/ScanditCapacitorBarcode/BarcodeArViewHandler.swift +146 -0
- package/ios/Sources/ScanditCapacitorBarcode/BarcodeCountViewHandler.swift +11 -0
- package/ios/Sources/ScanditCapacitorBarcode/BarcodeFindViewHandler.swift +43 -25
- package/ios/Sources/ScanditCapacitorBarcode/BarcodePickViewHandler.swift +11 -8
- package/ios/Sources/ScanditCapacitorBarcode/ScanditBarcodeCapture.swift +293 -1910
- package/package.json +7 -7
- package/android/src/main/java/com/scandit/capacitor/datacapture/barcode/ScanditBarcodeNative.kt +0 -1569
- package/android/src/main/java/com/scandit/capacitor/datacapture/barcode/count/BarcodeCountViewHandler.kt +0 -137
- package/android/src/main/java/com/scandit/capacitor/datacapture/barcode/factories/BarcodeCaptureActionFactory.kt +0 -13
- package/android/src/main/java/com/scandit/capacitor/datacapture/barcode/find/BarcodeFindViewHandler.kt +0 -166
- package/android/src/main/java/com/scandit/capacitor/datacapture/barcode/pick/BarcodePickViewHandler.kt +0 -136
- package/android/src/main/java/com/scandit/capacitor/datacapture/barcode/utils/AdvancedOverlayViewSerialization.kt +0 -89
- package/ios/Sources/ScanditCapacitorBarcode/BlockingCallbackResults.swift +0 -73
- package/ios/Sources/ScanditCapacitorBarcode/CommandJSONArgument+ScanditBarcodeCapture.swift +0 -70
- package/ios/Sources/ScanditCapacitorBarcode/TappableBase64ImageView.swift +0 -63
package/android/src/main/java/com/scandit/capacitor/datacapture/barcode/ar/BarcodeArViewHandler.java
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Scandit Data Capture SDK
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2023- Scandit AG. All rights reserved.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
package com.scandit.capacitor.datacapture.barcode.ar;
|
|
8
|
+
|
|
9
|
+
import static com.scandit.capacitor.datacapture.core.utils.CapacitorExtensions.*;
|
|
10
|
+
|
|
11
|
+
import android.view.View;
|
|
12
|
+
import android.view.ViewGroup;
|
|
13
|
+
import android.widget.FrameLayout;
|
|
14
|
+
import com.getcapacitor.Bridge;
|
|
15
|
+
import com.scandit.capacitor.datacapture.core.data.ResizeAndMoveInfo;
|
|
16
|
+
import com.scandit.datacapture.frameworks.core.utils.DefaultMainThread;
|
|
17
|
+
import com.scandit.datacapture.frameworks.core.utils.MainThread;
|
|
18
|
+
import java.lang.ref.WeakReference;
|
|
19
|
+
import java.util.Map;
|
|
20
|
+
import java.util.concurrent.ConcurrentHashMap;
|
|
21
|
+
|
|
22
|
+
public class BarcodeArViewHandler {
|
|
23
|
+
|
|
24
|
+
private final MainThread mainThread;
|
|
25
|
+
private final Map<Integer, WeakReference<FrameLayout>> containers;
|
|
26
|
+
private final Map<Integer, Boolean> containerVisibility;
|
|
27
|
+
private ResizeAndMoveInfo latestInfo;
|
|
28
|
+
private WeakReference<View> webViewReference;
|
|
29
|
+
|
|
30
|
+
public BarcodeArViewHandler() {
|
|
31
|
+
this(DefaultMainThread.getInstance());
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public BarcodeArViewHandler(MainThread mainThread) {
|
|
35
|
+
this.mainThread = mainThread;
|
|
36
|
+
this.containers = new ConcurrentHashMap<>();
|
|
37
|
+
this.containerVisibility = new ConcurrentHashMap<>();
|
|
38
|
+
this.latestInfo = new ResizeAndMoveInfo(0f, 0f, 0f, 0f, false);
|
|
39
|
+
this.webViewReference = new WeakReference<>(null);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public void addBarcodeArViewContainer(int viewId, FrameLayout container, Bridge bridge) {
|
|
43
|
+
if (containers.containsKey(viewId)) {
|
|
44
|
+
WeakReference<FrameLayout> existingRef = containers.remove(viewId);
|
|
45
|
+
if (existingRef != null) {
|
|
46
|
+
FrameLayout existingContainer = existingRef.get();
|
|
47
|
+
if (existingContainer != null) {
|
|
48
|
+
removeView(existingContainer);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
containers.put(viewId, new WeakReference<>(container));
|
|
54
|
+
containerVisibility.put(viewId, true);
|
|
55
|
+
|
|
56
|
+
bridge.executeOnMainThread(
|
|
57
|
+
() -> {
|
|
58
|
+
ViewGroup parent = (ViewGroup) bridge.getWebView().getParent();
|
|
59
|
+
ViewGroup.LayoutParams layoutParams =
|
|
60
|
+
new ViewGroup.LayoutParams(
|
|
61
|
+
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
62
|
+
// Add container to the same parent of the WebView
|
|
63
|
+
parent.addView(container, layoutParams);
|
|
64
|
+
|
|
65
|
+
webViewReference = new WeakReference<>(bridge.getWebView());
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public void setResizeAndMoveInfo(ResizeAndMoveInfo info) {
|
|
70
|
+
latestInfo = info;
|
|
71
|
+
mainThread.runOnMainThread(
|
|
72
|
+
() -> {
|
|
73
|
+
// Re-render all containers with the new info
|
|
74
|
+
for (Map.Entry<Integer, WeakReference<FrameLayout>> entry : containers.entrySet()) {
|
|
75
|
+
int viewId = entry.getKey();
|
|
76
|
+
WeakReference<FrameLayout> containerRef = entry.getValue();
|
|
77
|
+
FrameLayout container = containerRef.get();
|
|
78
|
+
if (container != null) {
|
|
79
|
+
Boolean visibility = containerVisibility.get(viewId);
|
|
80
|
+
renderNoAnimate(container, visibility != null && visibility);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public void disposeContainer(int viewId) {
|
|
87
|
+
mainThread.runOnMainThread(
|
|
88
|
+
() -> {
|
|
89
|
+
WeakReference<FrameLayout> containerRef = containers.remove(viewId);
|
|
90
|
+
if (containerRef != null) {
|
|
91
|
+
FrameLayout container = containerRef.get();
|
|
92
|
+
if (container != null) {
|
|
93
|
+
removeView(container);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
containerVisibility.remove(viewId);
|
|
99
|
+
|
|
100
|
+
if (containers.isEmpty()) {
|
|
101
|
+
mainThread.runOnMainThread(() -> bringWebViewToFront());
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private void removeView(View view) {
|
|
106
|
+
mainThread.runOnMainThread(() -> removeFromParent(view));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private void bringWebViewToFront() {
|
|
110
|
+
View webView = webViewReference.get();
|
|
111
|
+
if (webView != null) {
|
|
112
|
+
webView.bringToFront();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private void renderNoAnimate(FrameLayout container, boolean isVisible) {
|
|
117
|
+
container.post(
|
|
118
|
+
() -> {
|
|
119
|
+
if (latestInfo.getWidth() == 0f || latestInfo.getHeight() == 0f) {
|
|
120
|
+
container.setVisibility(View.GONE);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
container.setVisibility(isVisible ? View.VISIBLE : View.GONE);
|
|
125
|
+
container.setX(pxFromDp(latestInfo.getLeft()));
|
|
126
|
+
container.setY(pxFromDp(latestInfo.getTop()));
|
|
127
|
+
ViewGroup.LayoutParams params = container.getLayoutParams();
|
|
128
|
+
params.width = (int) pxFromDp(latestInfo.getWidth());
|
|
129
|
+
params.height = (int) pxFromDp(latestInfo.getHeight());
|
|
130
|
+
|
|
131
|
+
View webView = webViewReference.get();
|
|
132
|
+
if (latestInfo.getShouldBeUnderWebView()) {
|
|
133
|
+
if (webView != null) {
|
|
134
|
+
webView.bringToFront();
|
|
135
|
+
((View) webView.getParent()).setTranslationZ(1F);
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
container.bringToFront();
|
|
139
|
+
if (webView != null) {
|
|
140
|
+
((View) webView.getParent()).setTranslationZ(-1F);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
container.requestLayout();
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Scandit Data Capture SDK
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2023- Scandit AG. All rights reserved.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
package com.scandit.capacitor.datacapture.barcode.count;
|
|
8
|
+
|
|
9
|
+
import static com.scandit.capacitor.datacapture.core.utils.CapacitorExtensions.*;
|
|
10
|
+
|
|
11
|
+
import android.graphics.Color;
|
|
12
|
+
import android.view.View;
|
|
13
|
+
import android.view.ViewGroup;
|
|
14
|
+
import androidx.appcompat.app.AppCompatActivity;
|
|
15
|
+
import com.scandit.capacitor.datacapture.core.data.ResizeAndMoveInfo;
|
|
16
|
+
import com.scandit.datacapture.barcode.count.ui.view.BarcodeCountView;
|
|
17
|
+
import com.scandit.datacapture.frameworks.core.utils.DefaultMainThread;
|
|
18
|
+
import com.scandit.datacapture.frameworks.core.utils.MainThread;
|
|
19
|
+
import java.lang.ref.WeakReference;
|
|
20
|
+
|
|
21
|
+
public class BarcodeCountViewHandler {
|
|
22
|
+
|
|
23
|
+
private final MainThread mainThread;
|
|
24
|
+
private ResizeAndMoveInfo latestInfo;
|
|
25
|
+
private WeakReference<BarcodeCountView> barcodeCountViewReference;
|
|
26
|
+
private WeakReference<View> webViewReference;
|
|
27
|
+
|
|
28
|
+
public BarcodeCountViewHandler() {
|
|
29
|
+
this(DefaultMainThread.getInstance());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public BarcodeCountViewHandler(MainThread mainThread) {
|
|
33
|
+
this.mainThread = mainThread;
|
|
34
|
+
this.latestInfo = new ResizeAndMoveInfo(0f, 0f, 600f, 600f, false);
|
|
35
|
+
this.barcodeCountViewReference = null;
|
|
36
|
+
this.webViewReference = null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public BarcodeCountView getCurrentBarcodeCountView() {
|
|
40
|
+
return barcodeCountViewReference != null ? barcodeCountViewReference.get() : null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private View getWebView() {
|
|
44
|
+
return webViewReference != null ? webViewReference.get() : null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public void attachBarcodeCountView(Object barcodeCountView, AppCompatActivity activity) {
|
|
48
|
+
BarcodeCountView view = (BarcodeCountView) barcodeCountView;
|
|
49
|
+
if (getCurrentBarcodeCountView() != view) {
|
|
50
|
+
disposeCurrentView();
|
|
51
|
+
addBarcodeCountView(view, activity);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public void attachWebView(View webView) {
|
|
56
|
+
if (getWebView() != webView) {
|
|
57
|
+
webViewReference = new WeakReference<>(webView);
|
|
58
|
+
webView.bringToFront();
|
|
59
|
+
webView.setBackgroundColor(Color.TRANSPARENT);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public void setResizeAndMoveInfo(ResizeAndMoveInfo info) {
|
|
64
|
+
latestInfo = info;
|
|
65
|
+
render();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public void disposeCurrentView() {
|
|
69
|
+
BarcodeCountView view = getCurrentBarcodeCountView();
|
|
70
|
+
if (view == null) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
removeBarcodeCountView(view);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private void addBarcodeCountView(BarcodeCountView barcodeCountView, AppCompatActivity activity) {
|
|
77
|
+
barcodeCountViewReference = new WeakReference<>(barcodeCountView);
|
|
78
|
+
|
|
79
|
+
mainThread.runOnMainThread(
|
|
80
|
+
() -> {
|
|
81
|
+
activity.addContentView(
|
|
82
|
+
barcodeCountView,
|
|
83
|
+
new ViewGroup.LayoutParams(
|
|
84
|
+
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
|
85
|
+
render();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private void removeBarcodeCountView(BarcodeCountView barcodeCountView) {
|
|
90
|
+
barcodeCountViewReference = null;
|
|
91
|
+
removeView(
|
|
92
|
+
barcodeCountView,
|
|
93
|
+
() -> {
|
|
94
|
+
barcodeCountView.setListener(null);
|
|
95
|
+
barcodeCountView.setUiListener(null);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private void removeView(View view, Runnable uiBlock) {
|
|
100
|
+
mainThread.runOnMainThread(
|
|
101
|
+
() -> {
|
|
102
|
+
removeFromParent(view);
|
|
103
|
+
if (uiBlock != null) {
|
|
104
|
+
uiBlock.run();
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Update the view visibility, position and size.
|
|
110
|
+
public void render() {
|
|
111
|
+
BarcodeCountView view = getCurrentBarcodeCountView();
|
|
112
|
+
if (view == null) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
renderNoAnimate(view);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private void renderNoAnimate(BarcodeCountView barcodeCountView) {
|
|
119
|
+
barcodeCountView.post(
|
|
120
|
+
() -> {
|
|
121
|
+
barcodeCountView.setVisibility(View.VISIBLE);
|
|
122
|
+
barcodeCountView.setX(pxFromDp(latestInfo.getLeft()));
|
|
123
|
+
barcodeCountView.setY(pxFromDp(latestInfo.getTop()));
|
|
124
|
+
ViewGroup.LayoutParams params = barcodeCountView.getLayoutParams();
|
|
125
|
+
params.width = (int) pxFromDp(latestInfo.getWidth());
|
|
126
|
+
params.height = (int) pxFromDp(latestInfo.getHeight());
|
|
127
|
+
|
|
128
|
+
View webView = getWebView();
|
|
129
|
+
if (latestInfo.getShouldBeUnderWebView()) {
|
|
130
|
+
if (webView != null) {
|
|
131
|
+
webView.bringToFront();
|
|
132
|
+
((View) webView.getParent()).setTranslationZ(1F);
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
barcodeCountView.bringToFront();
|
|
136
|
+
if (webView != null) {
|
|
137
|
+
((View) webView.getParent()).setTranslationZ(-1F);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
barcodeCountView.requestLayout();
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Scandit Data Capture SDK
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2023- Scandit AG. All rights reserved.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
package com.scandit.capacitor.datacapture.barcode.find;
|
|
8
|
+
|
|
9
|
+
import static com.scandit.capacitor.datacapture.core.utils.CapacitorExtensions.*;
|
|
10
|
+
|
|
11
|
+
import android.content.Context;
|
|
12
|
+
import android.graphics.Color;
|
|
13
|
+
import android.view.View;
|
|
14
|
+
import android.view.ViewGroup;
|
|
15
|
+
import android.widget.FrameLayout;
|
|
16
|
+
import androidx.appcompat.app.AppCompatActivity;
|
|
17
|
+
import com.scandit.capacitor.datacapture.core.data.ResizeAndMoveInfo;
|
|
18
|
+
import com.scandit.datacapture.frameworks.core.utils.DefaultMainThread;
|
|
19
|
+
import com.scandit.datacapture.frameworks.core.utils.MainThread;
|
|
20
|
+
import java.lang.ref.WeakReference;
|
|
21
|
+
import java.util.Map;
|
|
22
|
+
import java.util.concurrent.ConcurrentHashMap;
|
|
23
|
+
|
|
24
|
+
public class BarcodeFindViewHandler {
|
|
25
|
+
|
|
26
|
+
private final MainThread mainThread;
|
|
27
|
+
private final Map<Integer, WeakReference<FrameLayout>> containers;
|
|
28
|
+
private final Map<Integer, Boolean> containerVisibility;
|
|
29
|
+
private WeakReference<View> webViewReference;
|
|
30
|
+
private ResizeAndMoveInfo latestInfo;
|
|
31
|
+
|
|
32
|
+
public BarcodeFindViewHandler() {
|
|
33
|
+
this(DefaultMainThread.getInstance());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public BarcodeFindViewHandler(MainThread mainThread) {
|
|
37
|
+
this.mainThread = mainThread;
|
|
38
|
+
this.containers = new ConcurrentHashMap<>();
|
|
39
|
+
this.containerVisibility = new ConcurrentHashMap<>();
|
|
40
|
+
this.webViewReference = null;
|
|
41
|
+
this.latestInfo = new ResizeAndMoveInfo(0f, 0f, 600f, 600f, false);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public void setResizeAndMoveInfo(ResizeAndMoveInfo info) {
|
|
45
|
+
latestInfo = info;
|
|
46
|
+
render();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private void render() {
|
|
50
|
+
for (WeakReference<FrameLayout> containerRef : containers.values()) {
|
|
51
|
+
FrameLayout container = containerRef.get();
|
|
52
|
+
if (container != null) {
|
|
53
|
+
Boolean visibility = true;
|
|
54
|
+
for (Map.Entry<Integer, WeakReference<FrameLayout>> entry : containers.entrySet()) {
|
|
55
|
+
if (entry.getValue().get() == container) {
|
|
56
|
+
visibility = containerVisibility.get(entry.getKey());
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
renderNoAnimate(container, visibility != null && visibility);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private View getWebView() {
|
|
66
|
+
return webViewReference != null ? webViewReference.get() : null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public FrameLayout prepareContainer(Context context) {
|
|
70
|
+
return new FrameLayout(context);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public void addBarcodeFindViewContainer(
|
|
74
|
+
int viewId, FrameLayout container, AppCompatActivity activity) {
|
|
75
|
+
if (containers.containsKey(viewId)) {
|
|
76
|
+
WeakReference<FrameLayout> existingRef = containers.remove(viewId);
|
|
77
|
+
if (existingRef != null) {
|
|
78
|
+
FrameLayout existingContainer = existingRef.get();
|
|
79
|
+
if (existingContainer != null) {
|
|
80
|
+
removeView(existingContainer);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
containers.put(viewId, new WeakReference<>(container));
|
|
86
|
+
containerVisibility.put(viewId, true);
|
|
87
|
+
|
|
88
|
+
addContainer(viewId, container, activity);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public void attachWebView(View webView) {
|
|
92
|
+
if (getWebView() != webView) {
|
|
93
|
+
webViewReference = new WeakReference<>(webView);
|
|
94
|
+
mainThread.runOnMainThread(
|
|
95
|
+
() -> {
|
|
96
|
+
webView.bringToFront();
|
|
97
|
+
webView.setBackgroundColor(Color.TRANSPARENT);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public void disposeContainer(int viewId) {
|
|
103
|
+
mainThread.runOnMainThread(
|
|
104
|
+
() -> {
|
|
105
|
+
WeakReference<FrameLayout> containerRef = containers.remove(viewId);
|
|
106
|
+
if (containerRef != null) {
|
|
107
|
+
FrameLayout container = containerRef.get();
|
|
108
|
+
if (container != null) {
|
|
109
|
+
removeView(container);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
containerVisibility.remove(viewId);
|
|
115
|
+
|
|
116
|
+
if (containers.isEmpty()) {
|
|
117
|
+
mainThread.runOnMainThread(() -> setWebViewVisible());
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private void addContainer(int viewId, FrameLayout container, AppCompatActivity activity) {
|
|
122
|
+
mainThread.runOnMainThread(
|
|
123
|
+
() -> {
|
|
124
|
+
activity.addContentView(
|
|
125
|
+
container,
|
|
126
|
+
new ViewGroup.LayoutParams(
|
|
127
|
+
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
|
128
|
+
Boolean visibility = containerVisibility.get(viewId);
|
|
129
|
+
renderNoAnimate(container, visibility != null && visibility);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private void removeView(View view) {
|
|
134
|
+
mainThread.runOnMainThread(() -> removeFromParent(view));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private void renderNoAnimate(FrameLayout container, boolean isVisible) {
|
|
138
|
+
container.post(
|
|
139
|
+
() -> {
|
|
140
|
+
container.setVisibility(isVisible ? View.VISIBLE : View.GONE);
|
|
141
|
+
container.setX(pxFromDp(latestInfo.getLeft()));
|
|
142
|
+
container.setY(pxFromDp(latestInfo.getTop()));
|
|
143
|
+
ViewGroup.LayoutParams params = container.getLayoutParams();
|
|
144
|
+
params.width = (int) pxFromDp(latestInfo.getWidth());
|
|
145
|
+
params.height = (int) pxFromDp(latestInfo.getHeight());
|
|
146
|
+
|
|
147
|
+
View webView = getWebView();
|
|
148
|
+
if (latestInfo.getShouldBeUnderWebView()) {
|
|
149
|
+
if (webView != null) {
|
|
150
|
+
webView.bringToFront();
|
|
151
|
+
((View) webView.getParent()).setTranslationZ(1F);
|
|
152
|
+
}
|
|
153
|
+
} else {
|
|
154
|
+
if (isVisible) {
|
|
155
|
+
container.bringToFront();
|
|
156
|
+
if (webView != null) {
|
|
157
|
+
((View) webView.getParent()).setTranslationZ(-1F);
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
setWebViewVisible();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
container.requestLayout();
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private void setWebViewVisible() {
|
|
168
|
+
View webView = getWebView();
|
|
169
|
+
if (webView != null) {
|
|
170
|
+
webView.bringToFront();
|
|
171
|
+
((View) webView.getParent()).setTranslationZ(1F);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private void setWebViewInvisible() {
|
|
176
|
+
View webView = getWebView();
|
|
177
|
+
if (webView != null) {
|
|
178
|
+
((View) webView.getParent()).setTranslationZ(-1F);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
package com.scandit.capacitor.datacapture.barcode.pick;
|
|
2
|
+
|
|
3
|
+
import static com.scandit.capacitor.datacapture.core.utils.CapacitorExtensions.*;
|
|
4
|
+
|
|
5
|
+
import android.content.Context;
|
|
6
|
+
import android.graphics.Color;
|
|
7
|
+
import android.view.View;
|
|
8
|
+
import android.view.ViewGroup;
|
|
9
|
+
import android.widget.FrameLayout;
|
|
10
|
+
import androidx.appcompat.app.AppCompatActivity;
|
|
11
|
+
import com.scandit.capacitor.datacapture.core.data.ResizeAndMoveInfo;
|
|
12
|
+
import com.scandit.datacapture.barcode.pick.ui.BarcodePickView;
|
|
13
|
+
import com.scandit.datacapture.frameworks.core.utils.DefaultMainThread;
|
|
14
|
+
import com.scandit.datacapture.frameworks.core.utils.MainThread;
|
|
15
|
+
import java.lang.ref.WeakReference;
|
|
16
|
+
|
|
17
|
+
public class BarcodePickViewHandler {
|
|
18
|
+
|
|
19
|
+
private final MainThread mainThread;
|
|
20
|
+
private ResizeAndMoveInfo latestInfo;
|
|
21
|
+
private WeakReference<FrameLayout> barcodePickViewContainerReference;
|
|
22
|
+
private WeakReference<View> webViewReference;
|
|
23
|
+
|
|
24
|
+
public BarcodePickViewHandler() {
|
|
25
|
+
this(DefaultMainThread.getInstance());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public BarcodePickViewHandler(MainThread mainThread) {
|
|
29
|
+
this.mainThread = mainThread;
|
|
30
|
+
this.latestInfo = new ResizeAndMoveInfo(0f, 0f, 600f, 600f, false);
|
|
31
|
+
this.barcodePickViewContainerReference = null;
|
|
32
|
+
this.webViewReference = null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public FrameLayout getBarcodePickViewContainer() {
|
|
36
|
+
return barcodePickViewContainerReference != null
|
|
37
|
+
? barcodePickViewContainerReference.get()
|
|
38
|
+
: null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private View getWebView() {
|
|
42
|
+
return webViewReference != null ? webViewReference.get() : null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public FrameLayout prepareContainer(Context context) {
|
|
46
|
+
return new FrameLayout(context);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public void addBarcodePickViewContainer(FrameLayout container, AppCompatActivity activity) {
|
|
50
|
+
if (getBarcodePickViewContainer() != container) {
|
|
51
|
+
disposeCurrentView();
|
|
52
|
+
addContainer(container, activity);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public void attachWebView(View webView, AppCompatActivity activity) {
|
|
57
|
+
if (getWebView() != webView) {
|
|
58
|
+
webViewReference = new WeakReference<>(webView);
|
|
59
|
+
webView.bringToFront();
|
|
60
|
+
webView.setBackgroundColor(Color.TRANSPARENT);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public void setResizeAndMoveInfo(ResizeAndMoveInfo info) {
|
|
65
|
+
latestInfo = info;
|
|
66
|
+
render();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public void disposeCurrentView() {
|
|
70
|
+
FrameLayout view = getBarcodePickViewContainer();
|
|
71
|
+
if (view == null) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
removeBarcodePickViewContainer(view);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private void addContainer(FrameLayout barcodePickViewContainer, AppCompatActivity activity) {
|
|
78
|
+
barcodePickViewContainerReference = new WeakReference<>(barcodePickViewContainer);
|
|
79
|
+
|
|
80
|
+
mainThread.runOnMainThread(
|
|
81
|
+
() -> {
|
|
82
|
+
activity.addContentView(
|
|
83
|
+
barcodePickViewContainer,
|
|
84
|
+
new ViewGroup.LayoutParams(
|
|
85
|
+
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
|
86
|
+
render();
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private void removeBarcodePickViewContainer(FrameLayout barcodePickViewContainer) {
|
|
91
|
+
barcodePickViewContainerReference = null;
|
|
92
|
+
removeView(
|
|
93
|
+
barcodePickViewContainer,
|
|
94
|
+
() -> {
|
|
95
|
+
// Find the first child that is a BarcodePickView and clear its listeners
|
|
96
|
+
for (int i = 0; i < barcodePickViewContainer.getChildCount(); i++) {
|
|
97
|
+
View child = barcodePickViewContainer.getChildAt(i);
|
|
98
|
+
if (child instanceof BarcodePickView) {
|
|
99
|
+
BarcodePickView pickView = (BarcodePickView) child;
|
|
100
|
+
pickView.setListener(null);
|
|
101
|
+
pickView.setUiListener(null);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private void removeView(View view, Runnable uiBlock) {
|
|
109
|
+
mainThread.runOnMainThread(
|
|
110
|
+
() -> {
|
|
111
|
+
removeFromParent(view);
|
|
112
|
+
if (uiBlock != null) {
|
|
113
|
+
uiBlock.run();
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Update the view visibility, position and size.
|
|
119
|
+
public void render() {
|
|
120
|
+
FrameLayout view = getBarcodePickViewContainer();
|
|
121
|
+
if (view == null) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
renderNoAnimate(view);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private void renderNoAnimate(FrameLayout barcodePickViewContainer) {
|
|
128
|
+
barcodePickViewContainer.post(
|
|
129
|
+
() -> {
|
|
130
|
+
barcodePickViewContainer.setVisibility(View.VISIBLE);
|
|
131
|
+
barcodePickViewContainer.setX(pxFromDp(latestInfo.getLeft()));
|
|
132
|
+
barcodePickViewContainer.setY(pxFromDp(latestInfo.getTop()));
|
|
133
|
+
ViewGroup.LayoutParams params = barcodePickViewContainer.getLayoutParams();
|
|
134
|
+
params.width = (int) pxFromDp(latestInfo.getWidth());
|
|
135
|
+
params.height = (int) pxFromDp(latestInfo.getHeight());
|
|
136
|
+
|
|
137
|
+
View webView = getWebView();
|
|
138
|
+
if (latestInfo.getShouldBeUnderWebView()) {
|
|
139
|
+
if (webView != null) {
|
|
140
|
+
webView.bringToFront();
|
|
141
|
+
((View) webView.getParent()).setTranslationZ(1F);
|
|
142
|
+
}
|
|
143
|
+
} else {
|
|
144
|
+
barcodePickViewContainer.bringToFront();
|
|
145
|
+
if (webView != null) {
|
|
146
|
+
((View) webView.getParent()).setTranslationZ(-1F);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
barcodePickViewContainer.requestLayout();
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|