@biso_gmbh/capacitor-plugin-ml-kit-barcode-scanner 1.0.8

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 (55) hide show
  1. package/CapacitorPluginMlKitBarcodeScanner.podspec +20 -0
  2. package/README.md +231 -0
  3. package/android/build.gradle +65 -0
  4. package/android/src/main/AndroidManifest.xml +8 -0
  5. package/android/src/main/assets/beep.mp3 +0 -0
  6. package/android/src/main/java/com/biso/capacitor/plugins/mlkit/barcode/scanner/BarcodeAnalyzer.java +119 -0
  7. package/android/src/main/java/com/biso/capacitor/plugins/mlkit/barcode/scanner/BarcodeFormat.java +40 -0
  8. package/android/src/main/java/com/biso/capacitor/plugins/mlkit/barcode/scanner/BarcodeFormats.java +38 -0
  9. package/android/src/main/java/com/biso/capacitor/plugins/mlkit/barcode/scanner/BarcodeType.java +37 -0
  10. package/android/src/main/java/com/biso/capacitor/plugins/mlkit/barcode/scanner/BarcodesListener.java +8 -0
  11. package/android/src/main/java/com/biso/capacitor/plugins/mlkit/barcode/scanner/CameraOverlay.java +161 -0
  12. package/android/src/main/java/com/biso/capacitor/plugins/mlkit/barcode/scanner/CaptureActivity.java +164 -0
  13. package/android/src/main/java/com/biso/capacitor/plugins/mlkit/barcode/scanner/DetectedBarcode.java +174 -0
  14. package/android/src/main/java/com/biso/capacitor/plugins/mlkit/barcode/scanner/MlKitBarcodeScannerPlugin.java +142 -0
  15. package/android/src/main/java/com/biso/capacitor/plugins/mlkit/barcode/scanner/ScannerSettings.java +348 -0
  16. package/android/src/main/java/com/biso/capacitor/plugins/mlkit/barcode/scanner/Utils.java +118 -0
  17. package/android/src/main/res/.gitkeep +0 -0
  18. package/android/src/main/res/drawable/torch_active.xml +12 -0
  19. package/android/src/main/res/drawable/torch_inactive.xml +12 -0
  20. package/android/src/main/res/drawable-mdpi/flashlight.png +0 -0
  21. package/android/src/main/res/layout/capture_activity.xml +28 -0
  22. package/dist/docs.json +279 -0
  23. package/dist/esm/definitions.d.ts +72 -0
  24. package/dist/esm/definitions.js +2 -0
  25. package/dist/esm/definitions.js.map +1 -0
  26. package/dist/esm/index.d.ts +4 -0
  27. package/dist/esm/index.js +7 -0
  28. package/dist/esm/index.js.map +1 -0
  29. package/dist/esm/web.d.ts +5 -0
  30. package/dist/esm/web.js +8 -0
  31. package/dist/esm/web.js.map +1 -0
  32. package/dist/plugin.cjs.js +22 -0
  33. package/dist/plugin.cjs.js.map +1 -0
  34. package/dist/plugin.js +25 -0
  35. package/dist/plugin.js.map +1 -0
  36. package/ios/Plugin/Assets.xcassets/Contents.json +6 -0
  37. package/ios/Plugin/Assets.xcassets/beep.dataset/Contents.json +12 -0
  38. package/ios/Plugin/Assets.xcassets/beep.dataset/beep.mp3 +0 -0
  39. package/ios/Plugin/Assets.xcassets/flashlight.imageset/Contents.json +12 -0
  40. package/ios/Plugin/Assets.xcassets/flashlight.imageset/flashlight.png +0 -0
  41. package/ios/Plugin/BarcodeFormat.swift +45 -0
  42. package/ios/Plugin/BarcodeFormats.swift +26 -0
  43. package/ios/Plugin/BarcodeType.swift +45 -0
  44. package/ios/Plugin/BarcodesAnalyzer.swift +79 -0
  45. package/ios/Plugin/CameraOverlay.swift +119 -0
  46. package/ios/Plugin/CameraViewController.swift +301 -0
  47. package/ios/Plugin/DetectedBarcode.swift +70 -0
  48. package/ios/Plugin/Info.plist +24 -0
  49. package/ios/Plugin/MlKitBarcodeScannerPlugin.h +10 -0
  50. package/ios/Plugin/MlKitBarcodeScannerPlugin.m +8 -0
  51. package/ios/Plugin/MlKitBarcodeScannerPlugin.swift +69 -0
  52. package/ios/Plugin/PrivacyInfo.xcprivacy +27 -0
  53. package/ios/Plugin/ScannerSettings.swift +171 -0
  54. package/ios/Plugin/Utils.swift +145 -0
  55. package/package.json +84 -0
@@ -0,0 +1,348 @@
1
+ package com.biso.capacitor.plugins.mlkit.barcode.scanner;
2
+
3
+ import static com.biso.capacitor.plugins.mlkit.barcode.scanner.ScannerSettings.Settings.*;
4
+ import static com.biso.capacitor.plugins.mlkit.barcode.scanner.Utils.getAspectRatioFromString;
5
+
6
+ import android.os.Parcel;
7
+ import android.os.Parcelable;
8
+ import android.util.Log;
9
+ import java.util.Arrays;
10
+ import java.util.Iterator;
11
+ import java.util.Objects;
12
+ import java.util.Optional;
13
+ import org.json.JSONObject;
14
+
15
+ public class ScannerSettings implements Parcelable {
16
+ private int barcodeFormats;
17
+ private String aspectRatio = "1:1";
18
+ private float aspectRatioF = 1;
19
+ private double detectorSize = 0.5;
20
+ private boolean drawFocusRect = true;
21
+ private String focusRectColor = "#FFFFFF";
22
+ private int focusRectBorderRadius = 100;
23
+ private int focusRectBorderThickness = 2;
24
+ private boolean drawFocusLine = true;
25
+ private String focusLineColor = "#FFFFFF";
26
+ private int focusLineThickness = 1;
27
+ private boolean drawFocusBackground = true;
28
+ private String focusBackgroundColor = "#CCFFFFFF";
29
+ private boolean beepOnSuccess = false;
30
+ private boolean vibrateOnSuccess = false;
31
+ private int stableThreshold = 5;
32
+ private boolean debugOverlay = false;
33
+ private boolean ignoreRotatedBarcodes = false;
34
+
35
+ public ScannerSettings(JSONObject settings) {
36
+ BarcodeFormats formats = new BarcodeFormats(settings.optJSONObject(BARCODE_FORMATS.value()));
37
+ barcodeFormats = formats.getFormatFlags();
38
+ Iterator<String> keys = settings.keys();
39
+
40
+ while(keys.hasNext()) {
41
+ String key = keys.next();
42
+
43
+ Optional<Settings> setting = Settings.get(key);
44
+ if(setting.isPresent()) {
45
+ switch (setting.get()) {
46
+ case BARCODE_FORMATS:
47
+ break;
48
+ case DETECTOR_ASPECT_RATIO:
49
+ aspectRatio = settings.optString(DETECTOR_ASPECT_RATIO.value(), getAspectRatio());
50
+ aspectRatioF = getAspectRatioFromString(aspectRatio);
51
+ break;
52
+ case DETECTOR_SIZE:
53
+ double temp = settings.optDouble(DETECTOR_SIZE.value(), getDetectorSize());
54
+ if (!(temp < 0 || temp > 1)) {
55
+ detectorSize = temp;
56
+ }
57
+ break;
58
+ case DRAW_FOCUS_RECT:
59
+ drawFocusRect = settings.optBoolean(DRAW_FOCUS_RECT.value(), isDrawFocusRect());
60
+ break;
61
+ case FOCUS_RECT_COLOR:
62
+ focusRectColor = settings.optString(FOCUS_RECT_COLOR.value(), getFocusRectColor());
63
+ break;
64
+ case FOCUS_RECT_BORDER_RADIUS:
65
+ focusRectBorderRadius = settings.optInt(FOCUS_RECT_BORDER_RADIUS.value(),
66
+ getFocusRectBorderRadius());
67
+ break;
68
+ case FOCUS_RECT_BORDER_THICKNESS:
69
+ focusRectBorderThickness = settings.optInt(FOCUS_RECT_BORDER_THICKNESS.value(),
70
+ getFocusRectBorderThickness());
71
+ break;
72
+ case DRAW_FOCUS_LINE:
73
+ drawFocusLine = settings.optBoolean(DRAW_FOCUS_LINE.value(), isDrawFocusLine());
74
+ break;
75
+ case FOCUS_LINE_COLOR:
76
+ focusLineColor = settings.optString(FOCUS_LINE_COLOR.value(), getFocusLineColor());
77
+ break;
78
+ case FOCUS_LINE_THICKNESS:
79
+ focusLineThickness = settings.optInt(FOCUS_LINE_THICKNESS.value(),
80
+ getFocusLineThickness());
81
+ break;
82
+ case DRAW_FOCUS_BACKGROUND:
83
+ drawFocusBackground = settings.optBoolean(DRAW_FOCUS_BACKGROUND.value(),
84
+ isDrawFocusBackground());
85
+ break;
86
+ case FOCUS_BACKGROUND_COLOR:
87
+ focusBackgroundColor = settings.optString(FOCUS_BACKGROUND_COLOR.value(),
88
+ getFocusBackgroundColor());
89
+ break;
90
+ case BEEP_ON_SUCCESS:
91
+ beepOnSuccess = settings.optBoolean(BEEP_ON_SUCCESS.value(), isBeepOnSuccess());
92
+ break;
93
+ case VIBRATE_ON_SUCCESS:
94
+ vibrateOnSuccess = settings.optBoolean(VIBRATE_ON_SUCCESS.value(),
95
+ isVibrateOnSuccess());
96
+ break;
97
+ case STABLE_THRESHOLD:
98
+ stableThreshold = settings.optInt(STABLE_THRESHOLD.value(), getStableThreshold());
99
+ break;
100
+ case DEBUG_OVERLAY:
101
+ debugOverlay = settings.optBoolean(DEBUG_OVERLAY.value(), isDebugOverlay());
102
+ break;
103
+ case IGNORE_ROTATED_BARCODES:
104
+ ignoreRotatedBarcodes = settings.optBoolean(IGNORE_ROTATED_BARCODES.value(),
105
+ isIgnoreRotatedBarcodes());
106
+ break;
107
+ default:
108
+ Log.e("SETTINGS", "No known setting for " + key);
109
+ break;
110
+ }
111
+ } else {
112
+ Log.e("SETTINGS", "No known setting for " + key);
113
+ }
114
+ }
115
+ }
116
+
117
+ public int getBarcodeFormats() {
118
+ return barcodeFormats;
119
+ }
120
+
121
+ public String getAspectRatio() {
122
+ return aspectRatio;
123
+ }
124
+
125
+ public float getAspectRatioF() {
126
+ return aspectRatioF;
127
+ }
128
+
129
+ public double getDetectorSize() {
130
+ return detectorSize;
131
+ }
132
+
133
+ public boolean isDrawFocusRect() {
134
+ return drawFocusRect;
135
+ }
136
+
137
+ public String getFocusRectColor() {
138
+ return focusRectColor;
139
+ }
140
+
141
+ public int getFocusRectBorderRadius() {
142
+ return focusRectBorderRadius;
143
+ }
144
+
145
+ public int getFocusRectBorderThickness() {
146
+ return focusRectBorderThickness;
147
+ }
148
+
149
+ public boolean isDrawFocusLine() {
150
+ return drawFocusLine;
151
+ }
152
+
153
+ public String getFocusLineColor() {
154
+ return focusLineColor;
155
+ }
156
+
157
+ public int getFocusLineThickness() {
158
+ return focusLineThickness;
159
+ }
160
+
161
+ public boolean isDrawFocusBackground() {
162
+ return drawFocusBackground;
163
+ }
164
+
165
+ public String getFocusBackgroundColor() {
166
+ return focusBackgroundColor;
167
+ }
168
+
169
+ public boolean isBeepOnSuccess() {
170
+ return beepOnSuccess;
171
+ }
172
+
173
+ public boolean isVibrateOnSuccess() {
174
+ return vibrateOnSuccess;
175
+ }
176
+
177
+ public int getStableThreshold() {
178
+ return stableThreshold;
179
+ }
180
+
181
+ public boolean isDebugOverlay() {
182
+ return debugOverlay;
183
+ }
184
+
185
+ public boolean isIgnoreRotatedBarcodes() {
186
+ return ignoreRotatedBarcodes;
187
+ }
188
+
189
+ @Override
190
+ public boolean equals(Object o) {
191
+ if (this == o) {
192
+ return true;
193
+ }
194
+ if (o == null || getClass() != o.getClass()) {
195
+ return false;
196
+ }
197
+ ScannerSettings that = (ScannerSettings) o;
198
+ return getBarcodeFormats() == that.getBarcodeFormats()
199
+ && Float.compare(that.getAspectRatioF(), getAspectRatioF()) == 0
200
+ && Double.compare(that.getDetectorSize(), getDetectorSize()) == 0
201
+ && isDrawFocusRect() == that.isDrawFocusRect()
202
+ && getFocusRectBorderRadius() == that.getFocusRectBorderRadius()
203
+ && getFocusRectBorderThickness() == that.getFocusRectBorderThickness()
204
+ && isDrawFocusLine() == that.isDrawFocusLine()
205
+ && getFocusLineThickness() == that.getFocusLineThickness()
206
+ && isDrawFocusBackground() == that.isDrawFocusBackground()
207
+ && isBeepOnSuccess() == that.isBeepOnSuccess()
208
+ && isVibrateOnSuccess() == that.isVibrateOnSuccess()
209
+ && getStableThreshold() == that.getStableThreshold()
210
+ && isDebugOverlay() == that.isDebugOverlay()
211
+ && isIgnoreRotatedBarcodes() == that.isIgnoreRotatedBarcodes()
212
+ && getAspectRatio().equals(that.getAspectRatio()) && getFocusRectColor().equals(
213
+ that.getFocusRectColor())
214
+ && getFocusLineColor().equals(that.getFocusLineColor()) && getFocusBackgroundColor().equals(
215
+ that.getFocusBackgroundColor());
216
+ }
217
+
218
+ @Override
219
+ public int hashCode() {
220
+ return Objects.hash(getBarcodeFormats(), getAspectRatio(), getAspectRatioF(), getDetectorSize(),
221
+ isDrawFocusRect(),
222
+ getFocusRectColor(), getFocusRectBorderRadius(), getFocusRectBorderThickness(),
223
+ isDrawFocusLine(),
224
+ getFocusLineColor(), getFocusLineThickness(), isDrawFocusBackground(),
225
+ getFocusBackgroundColor(),
226
+ isBeepOnSuccess(),
227
+ isVibrateOnSuccess(), getStableThreshold(), isDebugOverlay(), isIgnoreRotatedBarcodes());
228
+ }
229
+
230
+ @Override
231
+ public int describeContents() {
232
+ return hashCode();
233
+ }
234
+
235
+ @Override
236
+ public void writeToParcel(Parcel dest, int flags) {
237
+ dest.writeInt(this.getBarcodeFormats());
238
+ dest.writeString(this.getAspectRatio());
239
+ dest.writeFloat(this.getAspectRatioF());
240
+ dest.writeDouble(this.getDetectorSize());
241
+ dest.writeByte(this.isDrawFocusRect() ? (byte) 1 : (byte) 0);
242
+ dest.writeString(this.getFocusRectColor());
243
+ dest.writeInt(this.getFocusRectBorderRadius());
244
+ dest.writeInt(this.getFocusRectBorderThickness());
245
+ dest.writeByte(this.isDrawFocusLine() ? (byte) 1 : (byte) 0);
246
+ dest.writeString(this.getFocusLineColor());
247
+ dest.writeInt(this.getFocusLineThickness());
248
+ dest.writeByte(this.isDrawFocusBackground() ? (byte) 1 : (byte) 0);
249
+ dest.writeString(this.getFocusBackgroundColor());
250
+ dest.writeByte(this.isBeepOnSuccess() ? (byte) 1 : (byte) 0);
251
+ dest.writeByte(this.isVibrateOnSuccess() ? (byte) 1 : (byte) 0);
252
+ dest.writeInt(this.getStableThreshold());
253
+ dest.writeByte(this.isDebugOverlay() ? (byte) 1 : (byte) 0);
254
+ dest.writeByte(this.isIgnoreRotatedBarcodes() ? (byte) 1 : (byte) 0);
255
+ }
256
+
257
+ public void readFromParcel(Parcel source) {
258
+ this.barcodeFormats = source.readInt();
259
+ this.aspectRatio = source.readString();
260
+ this.aspectRatioF = source.readFloat();
261
+ this.detectorSize = source.readDouble();
262
+ this.drawFocusRect = source.readByte() != 0;
263
+ this.focusRectColor = source.readString();
264
+ this.focusRectBorderRadius = source.readInt();
265
+ this.focusRectBorderThickness = source.readInt();
266
+ this.drawFocusLine = source.readByte() != 0;
267
+ this.focusLineColor = source.readString();
268
+ this.focusLineThickness = source.readInt();
269
+ this.drawFocusBackground = source.readByte() != 0;
270
+ this.focusBackgroundColor = source.readString();
271
+ this.beepOnSuccess = source.readByte() != 0;
272
+ this.vibrateOnSuccess = source.readByte() != 0;
273
+ this.stableThreshold = source.readInt();
274
+ this.debugOverlay = source.readByte() != 0;
275
+ this.ignoreRotatedBarcodes = source.readByte() != 0;
276
+ }
277
+
278
+ protected ScannerSettings(Parcel in) {
279
+ this.barcodeFormats = in.readInt();
280
+ this.aspectRatio = in.readString();
281
+ this.aspectRatioF = in.readFloat();
282
+ this.detectorSize = in.readDouble();
283
+ this.drawFocusRect = in.readByte() != 0;
284
+ this.focusRectColor = in.readString();
285
+ this.focusRectBorderRadius = in.readInt();
286
+ this.focusRectBorderThickness = in.readInt();
287
+ this.drawFocusLine = in.readByte() != 0;
288
+ this.focusLineColor = in.readString();
289
+ this.focusLineThickness = in.readInt();
290
+ this.drawFocusBackground = in.readByte() != 0;
291
+ this.focusBackgroundColor = in.readString();
292
+ this.beepOnSuccess = in.readByte() != 0;
293
+ this.vibrateOnSuccess = in.readByte() != 0;
294
+ this.stableThreshold = in.readInt();
295
+ this.debugOverlay = in.readByte() != 0;
296
+ this.ignoreRotatedBarcodes = in.readByte() != 0;
297
+ }
298
+
299
+ public static final Creator<ScannerSettings> CREATOR = new Creator<ScannerSettings>() {
300
+ @Override
301
+ public ScannerSettings createFromParcel(Parcel source) {
302
+ return new ScannerSettings(source);
303
+ }
304
+
305
+ @Override
306
+ public ScannerSettings[] newArray(int size) {
307
+ return new ScannerSettings[size];
308
+ }
309
+ };
310
+
311
+ public enum Settings {
312
+
313
+ BARCODE_FORMATS("barcodeFormats"),
314
+ DETECTOR_ASPECT_RATIO("detectorAspectRatio"),
315
+ DETECTOR_SIZE("detectorSize"),
316
+ ROTATE_CAMERA("rotateCamera"),
317
+ DRAW_FOCUS_RECT("drawFocusRect"),
318
+ FOCUS_RECT_COLOR("focusRectColor"),
319
+ FOCUS_RECT_BORDER_RADIUS("focusRectBorderRadius"),
320
+ FOCUS_RECT_BORDER_THICKNESS("focusRectBorderThickness"),
321
+ DRAW_FOCUS_LINE("drawFocusLine"),
322
+ FOCUS_LINE_COLOR("focusLineColor"),
323
+ FOCUS_LINE_THICKNESS("focusLineThickness"),
324
+ DRAW_FOCUS_BACKGROUND("drawFocusBackground"),
325
+ FOCUS_BACKGROUND_COLOR("focusBackgroundColor"),
326
+ BEEP_ON_SUCCESS("beepOnSuccess"),
327
+ VIBRATE_ON_SUCCESS("vibrateOnSuccess"),
328
+ STABLE_THRESHOLD("stableThreshold"),
329
+ DEBUG_OVERLAY("debugOverlay"),
330
+ IGNORE_ROTATED_BARCODES("ignoreRotatedBarcodes");
331
+
332
+ private final String option;
333
+
334
+ Settings(String option) {
335
+ this.option = option;
336
+ }
337
+
338
+ public String value() {
339
+ return option;
340
+ }
341
+
342
+ public static Optional<Settings> get(String option) {
343
+ return Arrays.stream(Settings.values())
344
+ .filter(o -> o.option.equals(option))
345
+ .findFirst();
346
+ }
347
+ }
348
+ }
@@ -0,0 +1,118 @@
1
+ package com.biso.capacitor.plugins.mlkit.barcode.scanner;
2
+
3
+ import android.graphics.Matrix;
4
+ import android.graphics.Matrix.ScaleToFit;
5
+ import android.graphics.Rect;
6
+ import android.graphics.RectF;
7
+ import android.util.Pair;
8
+
9
+ public class Utils {
10
+
11
+ /**
12
+ * Calculates a centered rectangle. Rectangle will be centered in the area defined by width x
13
+ * height, have the aspect ratio and have a width of min(width, height) * scaleFactor
14
+ *
15
+ * @param height height of the area that the rectangle will be centered in
16
+ * @param width width of the area that the rectangle will be centered in
17
+ * @param scaleFactor factor to scale the rectangle with
18
+ * @param aspectRatio the intended aspect ratio of the rectangle
19
+ * @return rectangle based on float values, centered in the area
20
+ */
21
+ public static RectF calculateRectF(int height, int width, double scaleFactor, float aspectRatio) {
22
+ float rectWidth = (float) (Math.min(height, width) * scaleFactor);
23
+ float rectHeight = rectWidth / aspectRatio;
24
+
25
+ float offsetX = width - rectWidth;
26
+ float offsetY = height - rectHeight;
27
+
28
+ float left = offsetX / 2;
29
+ float top = offsetY / 2;
30
+ float right = left + rectWidth;
31
+ float bottom = top + rectHeight;
32
+
33
+ return new RectF(left, top, right, bottom);
34
+ }
35
+
36
+ /**
37
+ * Takes the aspect ratio string and returns it as a fraction.
38
+ *
39
+ * @param aspectRatioString the string containing an aspect ratio like 1:2
40
+ * @return The calculated aspect ratio, or 1 in case of error
41
+ */
42
+ public static float getAspectRatioFromString(String aspectRatioString) {
43
+ String separator = ":";
44
+ if (aspectRatioString.contains(separator)) {
45
+ String[] parts = aspectRatioString.split(separator);
46
+ if (parts.length == 2) {
47
+ try {
48
+ float left = Integer.parseInt(parts[0]);
49
+ float right = Integer.parseInt(parts[1]);
50
+ return (left / right);
51
+ } catch (NumberFormatException e) {
52
+ // do nothing
53
+ }
54
+ }
55
+ }
56
+ return 1;
57
+ }
58
+
59
+ /**
60
+ * Takes a rectangle and returns a copy rotated by rotationAngle
61
+ *
62
+ * @param rectF the rectangle to rotate
63
+ * @param rotationAngle the angle by which to rotate
64
+ * @return A RectF containing the rotated rectangle
65
+ */
66
+ public static RectF rotateRectF(RectF rectF, float rotationAngle) {
67
+ RectF rotated = new RectF(rectF);
68
+ Matrix matrix = new Matrix();
69
+ matrix.setRotate(rotationAngle, rectF.centerX(), rectF.centerY());
70
+ matrix.mapRect(rotated);
71
+
72
+ return rotated;
73
+ }
74
+
75
+ /**
76
+ * Generates a translation matrix that translates coordinates in the source rectangle to
77
+ * coordinates in the destination rectangle
78
+ *
79
+ * @param source A RectF to use as a source
80
+ * @param destination The target RectF
81
+ * @return a translation matrix
82
+ */
83
+ public static Matrix getTranslationMatrix(RectF source, RectF destination) {
84
+ Matrix matrix = new Matrix();
85
+ matrix.setRectToRect(source, destination, ScaleToFit.FILL);
86
+ return matrix;
87
+ }
88
+
89
+ /**
90
+ * Wrapper to map a Rect object inplace since Matrix only does RectF
91
+ *
92
+ * @param rect rect to map
93
+ * @param matrix matrix that does the mapping
94
+ */
95
+ public static void mapRectInplace(Rect rect, Matrix matrix) {
96
+ RectF rectF = new RectF(rect);
97
+ matrix.mapRect(rectF);
98
+ rect.set((int) rectF.left, (int) rectF.top, (int) rectF.right, (int) rectF.bottom);
99
+ }
100
+
101
+ /**
102
+ * Wrapper to map a Rect object and return a mapped RectF
103
+ *
104
+ * @param rect rect to map
105
+ * @param matrix matrix that does the mapping
106
+ * @return a Pair with the RectF as 1st parameter and a Boolean with orientation information as 2nd
107
+ */
108
+ public static Pair<RectF, Boolean> mapRect(Rect rect, Matrix matrix) {
109
+ RectF rectF = new RectF(rect);
110
+ matrix.mapRect(rectF);
111
+ return new Pair<>(rectF, rect.height() > rect.width());
112
+ }
113
+
114
+ private Utils() {
115
+ throw new IllegalStateException("Utility class");
116
+ }
117
+
118
+ }
File without changes
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+
3
+ <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
4
+ <item>
5
+ <shape android:shape="oval">
6
+ <solid android:color="#FFFFFF" />
7
+ </shape>
8
+ </item>
9
+ <item android:drawable="@drawable/flashlight" android:bottom="10dp" android:top="10dp" android:left="10dp" android:right="10dp" >
10
+
11
+ </item>
12
+ </layer-list>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+
3
+ <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
4
+ <item>
5
+ <shape android:shape="oval">
6
+ <solid android:color="#40FFFFFF" />
7
+ </shape>
8
+ </item>
9
+ <item android:drawable="@drawable/flashlight" android:bottom="10dp" android:top="10dp" android:left="10dp" android:right="10dp" >
10
+
11
+ </item>
12
+ </layer-list>
@@ -0,0 +1,28 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <androidx.constraintlayout.widget.ConstraintLayout
3
+ xmlns:android="http://schemas.android.com/apk/res/android"
4
+ xmlns:app="http://schemas.android.com/apk/res-auto"
5
+ android:id="@+id/topLayout"
6
+ android:layout_width="match_parent"
7
+ android:layout_height="match_parent">
8
+
9
+ <androidx.camera.view.PreviewView
10
+ android:id="@+id/previewView"
11
+ android:layout_width="0dp"
12
+ android:layout_height="0dp"
13
+ app:layout_constraintBottom_toBottomOf="parent"
14
+ app:layout_constraintEnd_toEndOf="parent"
15
+ app:layout_constraintHorizontal_bias="0.0"
16
+ app:layout_constraintStart_toStartOf="parent"
17
+ app:layout_constraintTop_toTopOf="parent"
18
+ app:layout_constraintVertical_bias="0.0" />
19
+
20
+ <ImageButton
21
+ android:id="@+id/torch_button"
22
+ android:layout_width="50dp"
23
+ android:layout_height="50dp"
24
+ app:layout_constraintBottom_toBottomOf="parent"
25
+ app:layout_constraintEnd_toEndOf="parent"
26
+ android:layout_margin="20dp"
27
+ android:background="@drawable/torch_inactive"/>
28
+ </androidx.constraintlayout.widget.ConstraintLayout>