@scr2em/capacitor-scanner 6.0.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/CapacitorScanner.podspec +17 -0
- package/Package.swift +24 -0
- package/README.md +161 -0
- package/android/build.gradle +74 -0
- package/android/src/main/AndroidManifest.xml +5 -0
- package/android/src/main/java/com/leadliaion/capacitorscanner/BarcodeFormatHelper.java +40 -0
- package/android/src/main/java/com/leadliaion/capacitorscanner/CapacitorScannerPlugin.java +489 -0
- package/android/src/main/java/com/leadliaion/capacitorscanner/Draft.java +575 -0
- package/android/src/main/java/com/leadliaion/capacitorscanner/VoteStatus.java +11 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +242 -0
- package/dist/esm/definitions.d.ts +42 -0
- package/dist/esm/definitions.js +15 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/plugin.cjs.js +23 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +26 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/CapacitorScannerPlugin/CapacitorScannerHelpers.swift +71 -0
- package/ios/Sources/CapacitorScannerPlugin/CapacitorScannerPlugin.swift +346 -0
- package/ios/Sources/CapacitorScannerPlugin/ScanSettings.swift +8 -0
- package/package.json +82 -0
|
@@ -0,0 +1,575 @@
|
|
|
1
|
+
// This is a draft file that was not used in the final implementation of the plugin. It is kept here for reference.
|
|
2
|
+
// This file contains the initial implementation of the plugin using CameraX and ZXing for barcode scanning
|
|
3
|
+
// instead of the ML Kit Barcode Scanning API.
|
|
4
|
+
|
|
5
|
+
//package com.leadliaion.capacitorscanner;
|
|
6
|
+
//
|
|
7
|
+
//
|
|
8
|
+
//import android.Manifest;
|
|
9
|
+
//import android.content.Intent;
|
|
10
|
+
//import android.graphics.Bitmap;
|
|
11
|
+
//import android.graphics.BitmapFactory;
|
|
12
|
+
//import android.graphics.ImageFormat;
|
|
13
|
+
//import android.graphics.Rect;
|
|
14
|
+
//import android.graphics.YuvImage;
|
|
15
|
+
//import android.net.Uri;
|
|
16
|
+
//import android.provider.Settings;
|
|
17
|
+
//import android.util.Base64;
|
|
18
|
+
//import android.util.Size;
|
|
19
|
+
//import android.view.ViewGroup;
|
|
20
|
+
//import android.webkit.WebView;
|
|
21
|
+
//import android.view.View;
|
|
22
|
+
//import androidx.annotation.NonNull;
|
|
23
|
+
//import androidx.camera.core.CameraSelector;
|
|
24
|
+
//import androidx.camera.core.Camera;
|
|
25
|
+
//import androidx.camera.core.ExperimentalGetImage;
|
|
26
|
+
//import androidx.camera.core.ImageAnalysis;
|
|
27
|
+
//import androidx.camera.core.ImageCapture;
|
|
28
|
+
//import androidx.camera.core.ImageProxy;
|
|
29
|
+
//import androidx.camera.core.Preview;
|
|
30
|
+
//import androidx.camera.lifecycle.ProcessCameraProvider;
|
|
31
|
+
//import androidx.camera.view.PreviewView;
|
|
32
|
+
//import androidx.core.content.ContextCompat;
|
|
33
|
+
//import androidx.lifecycle.LifecycleOwner;
|
|
34
|
+
//
|
|
35
|
+
//import com.getcapacitor.JSArray;
|
|
36
|
+
//import com.getcapacitor.JSObject;
|
|
37
|
+
//import com.getcapacitor.PermissionState;
|
|
38
|
+
//import com.getcapacitor.Plugin;
|
|
39
|
+
//import com.getcapacitor.PluginCall;
|
|
40
|
+
//import com.getcapacitor.PluginMethod;
|
|
41
|
+
//import com.getcapacitor.annotation.CapacitorPlugin;
|
|
42
|
+
//import com.getcapacitor.annotation.Permission;
|
|
43
|
+
//import com.getcapacitor.annotation.PermissionCallback;
|
|
44
|
+
//
|
|
45
|
+
//
|
|
46
|
+
//import com.google.common.util.concurrent.ListenableFuture;
|
|
47
|
+
//import com.google.zxing.BarcodeFormat;
|
|
48
|
+
//import com.google.zxing.DecodeHintType;
|
|
49
|
+
//import com.google.zxing.MultiFormatReader;
|
|
50
|
+
//import com.google.zxing.Result;
|
|
51
|
+
//import com.google.zxing.BinaryBitmap;
|
|
52
|
+
//import com.google.zxing.LuminanceSource;
|
|
53
|
+
//import com.google.zxing.common.HybridBinarizer;
|
|
54
|
+
//import com.google.zxing.NotFoundException;
|
|
55
|
+
//import com.google.zxing.RGBLuminanceSource;
|
|
56
|
+
//import com.google.zxing.multi.GenericMultipleBarcodeReader;
|
|
57
|
+
//
|
|
58
|
+
//import java.io.ByteArrayOutputStream;
|
|
59
|
+
//import java.io.File;
|
|
60
|
+
//import java.io.FileInputStream;
|
|
61
|
+
//import java.io.IOException;
|
|
62
|
+
//import java.nio.ByteBuffer;
|
|
63
|
+
//import java.util.concurrent.ExecutionException;
|
|
64
|
+
//import java.util.concurrent.Executor;
|
|
65
|
+
//import java.util.concurrent.Executors;
|
|
66
|
+
//import java.util.*;
|
|
67
|
+
// import java.util.concurrent.atomic.AtomicBoolean;
|
|
68
|
+
//
|
|
69
|
+
//import android.graphics.Bitmap;
|
|
70
|
+
//import android.graphics.BitmapFactory;
|
|
71
|
+
//import android.media.Image;
|
|
72
|
+
//
|
|
73
|
+
//import android.graphics.Color;
|
|
74
|
+
//import androidx.camera.core.ImageCaptureException;
|
|
75
|
+
//import android.widget.FrameLayout;
|
|
76
|
+
//import android.util.Log;
|
|
77
|
+
//
|
|
78
|
+
//
|
|
79
|
+
//
|
|
80
|
+
//@ExperimentalGetImage
|
|
81
|
+
//@CapacitorPlugin(
|
|
82
|
+
// name = "CapacitorScanner",
|
|
83
|
+
// permissions = {
|
|
84
|
+
// @Permission(strings = { Manifest.permission.CAMERA }, alias = "camera")
|
|
85
|
+
// }
|
|
86
|
+
//)
|
|
87
|
+
//public class CapacitorScannerPlugin extends Plugin {
|
|
88
|
+
//
|
|
89
|
+
// private PreviewView previewView;
|
|
90
|
+
// private ProcessCameraProvider cameraProvider;
|
|
91
|
+
// private ImageCapture imageCapture;
|
|
92
|
+
// private Map<String, VoteStatus> scannedCodesVotes = new HashMap<>();
|
|
93
|
+
// private final int voteThreshold = 5;
|
|
94
|
+
// private Executor executor = Executors.newSingleThreadExecutor();
|
|
95
|
+
// private AtomicBoolean isScanning = new AtomicBoolean(false);
|
|
96
|
+
//
|
|
97
|
+
// private class VoteStatus {
|
|
98
|
+
// public int votes;
|
|
99
|
+
// public boolean done;
|
|
100
|
+
//
|
|
101
|
+
// public VoteStatus(int votes, boolean done) {
|
|
102
|
+
// this.votes = votes;
|
|
103
|
+
// this.done = done;
|
|
104
|
+
// }
|
|
105
|
+
// }
|
|
106
|
+
//
|
|
107
|
+
// @Override
|
|
108
|
+
// public void load() {
|
|
109
|
+
// super.load();
|
|
110
|
+
// // ZXing's MultiFormatReader is initialized in BarcodeAnalyzer
|
|
111
|
+
// }
|
|
112
|
+
//
|
|
113
|
+
// @PluginMethod
|
|
114
|
+
// public void startScanning(PluginCall call) {
|
|
115
|
+
// echo("startScanning");
|
|
116
|
+
// if (isScanning.get()) {
|
|
117
|
+
// call.resolve();
|
|
118
|
+
// return;
|
|
119
|
+
// }
|
|
120
|
+
//
|
|
121
|
+
// if (getPermissionState("camera") != PermissionState.GRANTED) {
|
|
122
|
+
// echo("requestPermissionForAlias");
|
|
123
|
+
// requestPermissionForAlias("camera", call, "cameraPermsCallback");
|
|
124
|
+
// return;
|
|
125
|
+
// }
|
|
126
|
+
//
|
|
127
|
+
// getActivity().runOnUiThread(() -> {
|
|
128
|
+
// isScanning.set(true);
|
|
129
|
+
//
|
|
130
|
+
// try {
|
|
131
|
+
// // Get camera direction
|
|
132
|
+
// String cameraDirectionStr = call.getString("cameraDirection", "BACK");
|
|
133
|
+
// int lensFacing = cameraDirectionStr.equals("FRONT") ? CameraSelector.LENS_FACING_FRONT : CameraSelector.LENS_FACING_BACK;
|
|
134
|
+
//
|
|
135
|
+
// // Get formats
|
|
136
|
+
// JSArray formatsArray = call.getArray("formats");
|
|
137
|
+
// // Set up barcode formats for ZXing
|
|
138
|
+
// List<BarcodeFormat> barcodeFormats = new ArrayList<>();
|
|
139
|
+
// if (formatsArray != null && formatsArray.length() > 0) {
|
|
140
|
+
// for (int i = 0; i < formatsArray.length(); i++) {
|
|
141
|
+
// String formatStr = formatsArray.getString(i);
|
|
142
|
+
// BarcodeFormat format = stringToZXingBarcodeFormat(formatStr);
|
|
143
|
+
// if (format != null) {
|
|
144
|
+
// barcodeFormats.add(format);
|
|
145
|
+
// }
|
|
146
|
+
// }
|
|
147
|
+
// } else {
|
|
148
|
+
// // If no formats specified, default to common ones
|
|
149
|
+
// barcodeFormats.add(BarcodeFormat.AZTEC);
|
|
150
|
+
// barcodeFormats.add(BarcodeFormat.QR_CODE);
|
|
151
|
+
// barcodeFormats.add(BarcodeFormat.CODE_128);
|
|
152
|
+
// // Add other default formats as needed
|
|
153
|
+
// }
|
|
154
|
+
//
|
|
155
|
+
// // Set up the camera preview
|
|
156
|
+
// previewView = new PreviewView(getContext());
|
|
157
|
+
// previewView.setLayoutParams(new FrameLayout.LayoutParams(
|
|
158
|
+
// FrameLayout.LayoutParams.MATCH_PARENT,
|
|
159
|
+
// FrameLayout.LayoutParams.MATCH_PARENT));
|
|
160
|
+
// previewView.setScaleType(PreviewView.ScaleType.FILL_CENTER);
|
|
161
|
+
//
|
|
162
|
+
// // Insert the previewView into the view hierarchy
|
|
163
|
+
// FrameLayout containerView = new FrameLayout(getContext());
|
|
164
|
+
// containerView.setLayoutParams(new FrameLayout.LayoutParams(
|
|
165
|
+
// FrameLayout.LayoutParams.MATCH_PARENT,
|
|
166
|
+
// FrameLayout.LayoutParams.MATCH_PARENT));
|
|
167
|
+
//
|
|
168
|
+
// // Add the previewView to the container
|
|
169
|
+
// containerView.addView(previewView);
|
|
170
|
+
//
|
|
171
|
+
// // Get the root view and add the containerView
|
|
172
|
+
// ViewGroup rootView = (ViewGroup) getActivity().findViewById(android.R.id.content);
|
|
173
|
+
// rootView.addView(containerView);
|
|
174
|
+
//
|
|
175
|
+
// // Bring the WebView to front and make it transparent
|
|
176
|
+
// WebView webView = getBridge().getWebView();
|
|
177
|
+
// webView.setBackgroundColor(Color.TRANSPARENT);
|
|
178
|
+
// webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
|
179
|
+
// webView.bringToFront();
|
|
180
|
+
//
|
|
181
|
+
// // Initialize CameraX
|
|
182
|
+
// ListenableFuture<ProcessCameraProvider> cameraProviderFuture = ProcessCameraProvider.getInstance(getContext());
|
|
183
|
+
//
|
|
184
|
+
// cameraProviderFuture.addListener(() -> {
|
|
185
|
+
// try {
|
|
186
|
+
// cameraProvider = cameraProviderFuture.get();
|
|
187
|
+
// bindCamera(cameraProvider, previewView, lensFacing, barcodeFormats);
|
|
188
|
+
// call.resolve();
|
|
189
|
+
// } catch (ExecutionException | InterruptedException e) {
|
|
190
|
+
// e.printStackTrace();
|
|
191
|
+
// call.reject("Failed to initialize camera: " + e.getMessage());
|
|
192
|
+
// }
|
|
193
|
+
// }, ContextCompat.getMainExecutor(getContext()));
|
|
194
|
+
// } catch (Exception e) {
|
|
195
|
+
// e.printStackTrace();
|
|
196
|
+
// call.reject("Error setting up camera preview: " + e.getMessage());
|
|
197
|
+
// }
|
|
198
|
+
// });
|
|
199
|
+
// }
|
|
200
|
+
// @ExperimentalGetImage
|
|
201
|
+
// private void bindCamera(@NonNull ProcessCameraProvider cameraProvider, PreviewView previewView, int lensFacing, List<BarcodeFormat> barcodeFormats) {
|
|
202
|
+
// cameraProvider.unbindAll();
|
|
203
|
+
//
|
|
204
|
+
// // Preview Use Case
|
|
205
|
+
// Preview preview = new Preview.Builder().build();
|
|
206
|
+
//
|
|
207
|
+
// // Camera Selector
|
|
208
|
+
// CameraSelector cameraSelector = new CameraSelector.Builder()
|
|
209
|
+
// .requireLensFacing(lensFacing)
|
|
210
|
+
// .build();
|
|
211
|
+
//
|
|
212
|
+
// // Image Analysis Use Case
|
|
213
|
+
// ImageAnalysis imageAnalysis = new ImageAnalysis.Builder()
|
|
214
|
+
// .setTargetResolution(new Size(1920, 1080))
|
|
215
|
+
// .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
|
|
216
|
+
// .build();
|
|
217
|
+
//
|
|
218
|
+
// // Initialize BarcodeAnalyzer with desired formats
|
|
219
|
+
// imageAnalysis.setAnalyzer(executor, new BarcodeAnalyzer(barcodeFormats));
|
|
220
|
+
//
|
|
221
|
+
// // Image Capture Use Case
|
|
222
|
+
// imageCapture = new ImageCapture.Builder()
|
|
223
|
+
// .setTargetResolution(new Size(1280, 720))
|
|
224
|
+
// .build();
|
|
225
|
+
//
|
|
226
|
+
// // Bind to Lifecycle
|
|
227
|
+
// try {
|
|
228
|
+
// Camera camera = cameraProvider.bindToLifecycle((LifecycleOwner) getActivity(), cameraSelector, preview, imageAnalysis, imageCapture);
|
|
229
|
+
// // Set the surface provider AFTER binding to lifecycle
|
|
230
|
+
// preview.setSurfaceProvider(previewView.getSurfaceProvider());
|
|
231
|
+
// } catch (Exception e) {
|
|
232
|
+
// e.printStackTrace();
|
|
233
|
+
// }
|
|
234
|
+
// }
|
|
235
|
+
//
|
|
236
|
+
// @ExperimentalGetImage /**
|
|
237
|
+
// * ZXing-based BarcodeAnalyzer to process camera frames and detect barcodes.
|
|
238
|
+
// */
|
|
239
|
+
// private class BarcodeAnalyzer implements ImageAnalysis.Analyzer {
|
|
240
|
+
// private final MultiFormatReader reader;
|
|
241
|
+
//
|
|
242
|
+
// public BarcodeAnalyzer(List<BarcodeFormat> barcodeFormats) {
|
|
243
|
+
// reader = new MultiFormatReader();
|
|
244
|
+
// Map<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
|
|
245
|
+
// hints.put(DecodeHintType.POSSIBLE_FORMATS, barcodeFormats);
|
|
246
|
+
// hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
|
|
247
|
+
// hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE); // Add this line
|
|
248
|
+
// reader.setHints(hints);
|
|
249
|
+
// }
|
|
250
|
+
//
|
|
251
|
+
// @Override
|
|
252
|
+
// public void analyze(@NonNull ImageProxy imageProxy) {
|
|
253
|
+
// @androidx.camera.core.ExperimentalGetImage
|
|
254
|
+
// Image mediaImage = imageProxy.getImage();
|
|
255
|
+
// if (mediaImage != null) {
|
|
256
|
+
// try {
|
|
257
|
+
// // Convert Image to Bitmap
|
|
258
|
+
// Bitmap bitmap = toBitmap(mediaImage);
|
|
259
|
+
// if (bitmap == null) {
|
|
260
|
+
// echo("Failed to convert Image to Bitmap.");
|
|
261
|
+
// return;
|
|
262
|
+
// }
|
|
263
|
+
// int width = bitmap.getWidth();
|
|
264
|
+
// int height = bitmap.getHeight();
|
|
265
|
+
// int[] pixels = new int[width * height];
|
|
266
|
+
// bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
|
|
267
|
+
//
|
|
268
|
+
// // Convert Bitmap to LuminanceSource
|
|
269
|
+
// LuminanceSource source = new RGBLuminanceSource(width, height, pixels);
|
|
270
|
+
// BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
|
|
271
|
+
//
|
|
272
|
+
// // Decode the barcode
|
|
273
|
+
// Result result = reader.decodeWithState(binaryBitmap);
|
|
274
|
+
// if (result != null) {
|
|
275
|
+
// List<Result> results = new ArrayList<>();
|
|
276
|
+
// results.add(result);
|
|
277
|
+
// processBarcodes(results);
|
|
278
|
+
// }
|
|
279
|
+
// } catch (NotFoundException e) {
|
|
280
|
+
// // No barcode found in this frame
|
|
281
|
+
// } catch (Exception e) {
|
|
282
|
+
// e.printStackTrace();
|
|
283
|
+
// } finally {
|
|
284
|
+
// imageProxy.close();
|
|
285
|
+
// }
|
|
286
|
+
// } else {
|
|
287
|
+
// imageProxy.close();
|
|
288
|
+
// }
|
|
289
|
+
// }
|
|
290
|
+
//
|
|
291
|
+
// /**
|
|
292
|
+
// * Converts an Image object in YUV_420_888 format to a Bitmap using YuvImage.
|
|
293
|
+
// *
|
|
294
|
+
// * @param image The YUV_420_888 Image to convert.
|
|
295
|
+
// * @return The resulting Bitmap or null if conversion fails.
|
|
296
|
+
// */
|
|
297
|
+
// private Bitmap toBitmap(Image image) {
|
|
298
|
+
// try {
|
|
299
|
+
// ByteBuffer yBuffer = image.getPlanes()[0].getBuffer(); // Y
|
|
300
|
+
// ByteBuffer uBuffer = image.getPlanes()[1].getBuffer(); // U
|
|
301
|
+
// ByteBuffer vBuffer = image.getPlanes()[2].getBuffer(); // V
|
|
302
|
+
//
|
|
303
|
+
// int ySize = yBuffer.remaining();
|
|
304
|
+
// int uSize = uBuffer.remaining();
|
|
305
|
+
// int vSize = vBuffer.remaining();
|
|
306
|
+
//
|
|
307
|
+
// byte[] nv21 = new byte[ySize + uSize + vSize];
|
|
308
|
+
//
|
|
309
|
+
// // U and V are swapped
|
|
310
|
+
// yBuffer.get(nv21, 0, ySize);
|
|
311
|
+
// vBuffer.get(nv21, ySize, vSize);
|
|
312
|
+
// uBuffer.get(nv21, ySize + vSize, uSize);
|
|
313
|
+
//
|
|
314
|
+
// YuvImage yuvImage = new YuvImage(nv21, ImageFormat.NV21, image.getWidth(), image.getHeight(), null);
|
|
315
|
+
// ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
316
|
+
// yuvImage.compressToJpeg(new Rect(0, 0, image.getWidth(), image.getHeight()), 100, out);
|
|
317
|
+
// byte[] jpegBytes = out.toByteArray();
|
|
318
|
+
// return BitmapFactory.decodeByteArray(jpegBytes, 0, jpegBytes.length);
|
|
319
|
+
// } catch (Exception e) {
|
|
320
|
+
// e.printStackTrace();
|
|
321
|
+
// return null;
|
|
322
|
+
// }
|
|
323
|
+
// }
|
|
324
|
+
// }
|
|
325
|
+
//
|
|
326
|
+
// /**
|
|
327
|
+
// * Processes a list of ZXing Result objects to extract barcode information.
|
|
328
|
+
// *
|
|
329
|
+
// * @param barcodes A list of ZXing Result objects representing detected barcodes.
|
|
330
|
+
// */
|
|
331
|
+
// private void processBarcodes(List<Result> barcodes) {
|
|
332
|
+
//
|
|
333
|
+
// for (Result barcodeResult : barcodes) {
|
|
334
|
+
// String decodedText = barcodeResult.getText();
|
|
335
|
+
// BarcodeFormat format = barcodeResult.getBarcodeFormat();
|
|
336
|
+
//
|
|
337
|
+
// echo("Decoded Text: " + decodedText);
|
|
338
|
+
// echo("Barcode Format: " + barcodeFormatToString(format));
|
|
339
|
+
//
|
|
340
|
+
// echo("Decoded Text Length: " + decodedText.length());
|
|
341
|
+
//
|
|
342
|
+
//
|
|
343
|
+
// if (decodedText == null || decodedText.isEmpty()) {
|
|
344
|
+
// echo("Decoded text is null or empty. Skipping this barcode.");
|
|
345
|
+
// continue;
|
|
346
|
+
// }
|
|
347
|
+
//
|
|
348
|
+
// VoteStatus voteStatus = scannedCodesVotes.get(decodedText);
|
|
349
|
+
// if (voteStatus == null) {
|
|
350
|
+
// voteStatus = new VoteStatus(0, false);
|
|
351
|
+
// }
|
|
352
|
+
//
|
|
353
|
+
// if (!voteStatus.done) {
|
|
354
|
+
// voteStatus.votes += 1;
|
|
355
|
+
//
|
|
356
|
+
// if (voteStatus.votes >= voteThreshold) {
|
|
357
|
+
// voteStatus.done = true;
|
|
358
|
+
//
|
|
359
|
+
// JSObject data = new JSObject();
|
|
360
|
+
// data.put("scannedCode", decodedText);
|
|
361
|
+
// data.put("format", barcodeFormatToString(format));
|
|
362
|
+
// notifyListeners("barcodeScanned", data, true);
|
|
363
|
+
// }
|
|
364
|
+
//
|
|
365
|
+
// scannedCodesVotes.put(decodedText, voteStatus);
|
|
366
|
+
// }
|
|
367
|
+
// }
|
|
368
|
+
// }
|
|
369
|
+
//
|
|
370
|
+
// /**
|
|
371
|
+
// * Converts ZXing's BarcodeFormat to a readable string.
|
|
372
|
+
// *
|
|
373
|
+
// * @param format The BarcodeFormat enum from ZXing.
|
|
374
|
+
// * @return A string representation of the barcode format.
|
|
375
|
+
// */
|
|
376
|
+
// private String barcodeFormatToString(BarcodeFormat format) {
|
|
377
|
+
// switch (format) {
|
|
378
|
+
// case AZTEC:
|
|
379
|
+
// return "AZTEC";
|
|
380
|
+
// case CODE_39:
|
|
381
|
+
// return "CODE_39";
|
|
382
|
+
// case CODE_93:
|
|
383
|
+
// return "CODE_93";
|
|
384
|
+
// case CODE_128:
|
|
385
|
+
// return "CODE_128";
|
|
386
|
+
// case DATA_MATRIX:
|
|
387
|
+
// return "DATA_MATRIX";
|
|
388
|
+
// case EAN_8:
|
|
389
|
+
// return "EAN_8";
|
|
390
|
+
// case EAN_13:
|
|
391
|
+
// return "EAN_13";
|
|
392
|
+
// case ITF:
|
|
393
|
+
// return "ITF14";
|
|
394
|
+
// case PDF_417:
|
|
395
|
+
// return "PDF_417";
|
|
396
|
+
// case QR_CODE:
|
|
397
|
+
// return "QR_CODE";
|
|
398
|
+
// case UPC_E:
|
|
399
|
+
// return "UPC_E";
|
|
400
|
+
// default:
|
|
401
|
+
// return "UNKNOWN";
|
|
402
|
+
// }
|
|
403
|
+
// }
|
|
404
|
+
//
|
|
405
|
+
// /**
|
|
406
|
+
// * Converts a string representation of a barcode format to ZXing's BarcodeFormat enum.
|
|
407
|
+
// *
|
|
408
|
+
// * @param formatStr The string representation (e.g., "AZTEC").
|
|
409
|
+
// * @return The corresponding BarcodeFormat enum or null if not found.
|
|
410
|
+
// */
|
|
411
|
+
// private BarcodeFormat stringToZXingBarcodeFormat(String formatStr) {
|
|
412
|
+
// switch (formatStr) {
|
|
413
|
+
// case "AZTEC":
|
|
414
|
+
// return BarcodeFormat.AZTEC;
|
|
415
|
+
// case "CODE_39":
|
|
416
|
+
// return BarcodeFormat.CODE_39;
|
|
417
|
+
// case "CODE_93":
|
|
418
|
+
// return BarcodeFormat.CODE_93;
|
|
419
|
+
// case "CODE_128":
|
|
420
|
+
// return BarcodeFormat.CODE_128;
|
|
421
|
+
// case "DATA_MATRIX":
|
|
422
|
+
// return BarcodeFormat.DATA_MATRIX;
|
|
423
|
+
// case "EAN_8":
|
|
424
|
+
// return BarcodeFormat.EAN_8;
|
|
425
|
+
// case "EAN_13":
|
|
426
|
+
// return BarcodeFormat.EAN_13;
|
|
427
|
+
// case "ITF14":
|
|
428
|
+
// return BarcodeFormat.ITF;
|
|
429
|
+
// case "PDF_417":
|
|
430
|
+
// return BarcodeFormat.PDF_417;
|
|
431
|
+
// case "QR_CODE":
|
|
432
|
+
// return BarcodeFormat.QR_CODE;
|
|
433
|
+
// case "UPC_E":
|
|
434
|
+
// return BarcodeFormat.UPC_E;
|
|
435
|
+
// default:
|
|
436
|
+
// return null;
|
|
437
|
+
// }
|
|
438
|
+
// }
|
|
439
|
+
//
|
|
440
|
+
// @PluginMethod
|
|
441
|
+
// public void stopScanning(PluginCall call) {
|
|
442
|
+
// System.out.println("CUSTOM_LOG_IDENTIFIER stopScanning");
|
|
443
|
+
// getActivity().runOnUiThread(() -> {
|
|
444
|
+
// if (cameraProvider != null) {
|
|
445
|
+
// cameraProvider.unbindAll();
|
|
446
|
+
// }
|
|
447
|
+
// if (previewView != null) {
|
|
448
|
+
// ViewGroup parentView = (ViewGroup) previewView.getParent();
|
|
449
|
+
// if (parentView != null) {
|
|
450
|
+
// parentView.removeView(previewView);
|
|
451
|
+
// }
|
|
452
|
+
// previewView = null;
|
|
453
|
+
// }
|
|
454
|
+
// scannedCodesVotes.clear();
|
|
455
|
+
// isScanning.set(false);
|
|
456
|
+
//
|
|
457
|
+
// // Restore WebView background
|
|
458
|
+
// WebView webView = getBridge().getWebView();
|
|
459
|
+
// webView.setBackgroundColor(Color.WHITE);
|
|
460
|
+
// webView.getBackground().setAlpha(255);
|
|
461
|
+
//
|
|
462
|
+
// call.resolve();
|
|
463
|
+
// });
|
|
464
|
+
// }
|
|
465
|
+
//
|
|
466
|
+
// @PluginMethod
|
|
467
|
+
// public void capturePhoto(PluginCall call) {
|
|
468
|
+
// if (imageCapture == null) {
|
|
469
|
+
// call.reject("Camera is not set up or running");
|
|
470
|
+
// return;
|
|
471
|
+
// }
|
|
472
|
+
//
|
|
473
|
+
// // Create a file to save the image
|
|
474
|
+
// File photoFile = new File(getContext().getCacheDir(), System.currentTimeMillis() + ".jpg");
|
|
475
|
+
//
|
|
476
|
+
// ImageCapture.OutputFileOptions outputOptions =
|
|
477
|
+
// new ImageCapture.OutputFileOptions.Builder(photoFile).build();
|
|
478
|
+
//
|
|
479
|
+
// imageCapture.takePicture(outputOptions, ContextCompat.getMainExecutor(getContext()),
|
|
480
|
+
// new ImageCapture.OnImageSavedCallback() {
|
|
481
|
+
// @Override
|
|
482
|
+
// public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults) {
|
|
483
|
+
// // Read the image file and convert to base64
|
|
484
|
+
// try {
|
|
485
|
+
// FileInputStream fis = new FileInputStream(photoFile);
|
|
486
|
+
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
487
|
+
// byte[] buffer = new byte[1024];
|
|
488
|
+
// int len;
|
|
489
|
+
// while ((len = fis.read(buffer)) != -1) {
|
|
490
|
+
// baos.write(buffer, 0, len);
|
|
491
|
+
// }
|
|
492
|
+
// fis.close();
|
|
493
|
+
// byte[] bytes = baos.toByteArray();
|
|
494
|
+
// String base64 = Base64.encodeToString(bytes, Base64.NO_WRAP);
|
|
495
|
+
// JSObject ret = new JSObject();
|
|
496
|
+
// ret.put("imageBase64", "data:image/jpeg;base64," + base64);
|
|
497
|
+
// call.resolve(ret);
|
|
498
|
+
// // Delete the temporary file
|
|
499
|
+
// photoFile.delete();
|
|
500
|
+
// } catch (IOException e) {
|
|
501
|
+
// call.reject("Failed to read image file: " + e.getMessage());
|
|
502
|
+
// }
|
|
503
|
+
// }
|
|
504
|
+
//
|
|
505
|
+
// @Override
|
|
506
|
+
// public void onError(@NonNull ImageCaptureException exception) {
|
|
507
|
+
// call.reject("Photo capture failed: " + exception.getMessage());
|
|
508
|
+
// }
|
|
509
|
+
// });
|
|
510
|
+
// }
|
|
511
|
+
//
|
|
512
|
+
// @PluginMethod
|
|
513
|
+
// public void checkPermissions(PluginCall call) {
|
|
514
|
+
// PermissionState cameraPermState = getPermissionState("camera");
|
|
515
|
+
// String status = "prompt";
|
|
516
|
+
// if (cameraPermState == PermissionState.DENIED) {
|
|
517
|
+
// status = "denied";
|
|
518
|
+
// } else if (cameraPermState == PermissionState.GRANTED) {
|
|
519
|
+
// status = "granted";
|
|
520
|
+
// }
|
|
521
|
+
//
|
|
522
|
+
// JSObject ret = new JSObject();
|
|
523
|
+
// ret.put("camera", status);
|
|
524
|
+
// call.resolve(ret);
|
|
525
|
+
// }
|
|
526
|
+
//
|
|
527
|
+
// @PluginMethod
|
|
528
|
+
// public void requestPermissions(PluginCall call) {
|
|
529
|
+
// requestPermissionForAlias("camera", call, "cameraPermsCallback");
|
|
530
|
+
// }
|
|
531
|
+
//
|
|
532
|
+
// @PermissionCallback
|
|
533
|
+
// private void cameraPermsCallback(PluginCall call) {
|
|
534
|
+
// checkPermissions(call);
|
|
535
|
+
// }
|
|
536
|
+
//
|
|
537
|
+
// @PluginMethod
|
|
538
|
+
// public void openSettings(PluginCall call) {
|
|
539
|
+
// try {
|
|
540
|
+
// Intent intent = new Intent();
|
|
541
|
+
// intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
|
542
|
+
// Uri uri = Uri.fromParts("package", getContext().getPackageName(), null);
|
|
543
|
+
// intent.setData(uri);
|
|
544
|
+
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
545
|
+
// getContext().startActivity(intent);
|
|
546
|
+
// call.resolve();
|
|
547
|
+
// } catch (Exception ex) {
|
|
548
|
+
// call.reject("Failed to open settings: " + ex.getMessage());
|
|
549
|
+
// }
|
|
550
|
+
// }
|
|
551
|
+
//
|
|
552
|
+
//
|
|
553
|
+
// private void logLongMessage(String tag, String message) {
|
|
554
|
+
// if (message.length() > 4000) {
|
|
555
|
+
// // Split the message into chunks of 4000 characters
|
|
556
|
+
// int chunkCount = message.length() / 4000;
|
|
557
|
+
// for (int i = 0; i <= chunkCount; i++) {
|
|
558
|
+
// int max = 4000 * (i + 1);
|
|
559
|
+
// if (max >= message.length()) {
|
|
560
|
+
// Log.d(tag, message.substring(4000 * i));
|
|
561
|
+
// } else {
|
|
562
|
+
// Log.d(tag, message.substring(4000 * i, max));
|
|
563
|
+
// }
|
|
564
|
+
// }
|
|
565
|
+
// } else {
|
|
566
|
+
// Log.d(tag, message);
|
|
567
|
+
// }
|
|
568
|
+
// }
|
|
569
|
+
//
|
|
570
|
+
// private void echo(String value) {
|
|
571
|
+
// logLongMessage("CUSTOM_LOG_IDENTIFIER", value);
|
|
572
|
+
// }
|
|
573
|
+
//
|
|
574
|
+
//
|
|
575
|
+
//}
|
|
File without changes
|