@capgo/camera-preview 7.4.0-beta.16 → 7.4.0-beta.17
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.
|
@@ -360,6 +360,14 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
360
360
|
Log.d(TAG, "setupPreviewView: Setting grid mode to: " + currentGridMode);
|
|
361
361
|
gridOverlayView.setGridMode(currentGridMode);
|
|
362
362
|
});
|
|
363
|
+
|
|
364
|
+
// Add a layout listener to update grid bounds when preview view changes size
|
|
365
|
+
previewView.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
|
|
366
|
+
if (left != oldLeft || top != oldTop || right != oldRight || bottom != oldBottom) {
|
|
367
|
+
Log.d(TAG, "PreviewView layout changed, updating grid bounds");
|
|
368
|
+
updateGridOverlayBounds();
|
|
369
|
+
}
|
|
370
|
+
});
|
|
363
371
|
|
|
364
372
|
ViewGroup parent = (ViewGroup) webView.getParent();
|
|
365
373
|
if (parent != null) {
|
|
@@ -738,6 +746,9 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
738
746
|
actualHeight
|
|
739
747
|
);
|
|
740
748
|
|
|
749
|
+
// Update grid overlay bounds after camera is started
|
|
750
|
+
updateGridOverlayBounds();
|
|
751
|
+
|
|
741
752
|
listener.onCameraStarted(
|
|
742
753
|
actualWidth,
|
|
743
754
|
actualHeight,
|
|
@@ -2621,19 +2632,30 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
2621
2632
|
|
|
2622
2633
|
// Wait for camera rebinding to complete, then call callback
|
|
2623
2634
|
if (callback != null) {
|
|
2624
|
-
previewContainer.post(() ->
|
|
2635
|
+
previewContainer.post(() -> {
|
|
2636
|
+
updateGridOverlayBounds();
|
|
2637
|
+
previewContainer.post(callback);
|
|
2638
|
+
});
|
|
2639
|
+
} else {
|
|
2640
|
+
previewContainer.post(() -> updateGridOverlayBounds());
|
|
2625
2641
|
}
|
|
2626
2642
|
} else {
|
|
2627
2643
|
// No camera rebinding needed, wait for layout to complete then call callback
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2644
|
+
previewContainer.post(() -> {
|
|
2645
|
+
updateGridOverlayBounds();
|
|
2646
|
+
if (callback != null) {
|
|
2647
|
+
callback.run();
|
|
2648
|
+
}
|
|
2649
|
+
});
|
|
2631
2650
|
}
|
|
2632
2651
|
} else {
|
|
2633
2652
|
// No sessionConfig, just wait for layout then call callback
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2653
|
+
previewContainer.post(() -> {
|
|
2654
|
+
updateGridOverlayBounds();
|
|
2655
|
+
if (callback != null) {
|
|
2656
|
+
callback.run();
|
|
2657
|
+
}
|
|
2658
|
+
});
|
|
2637
2659
|
}
|
|
2638
2660
|
} else {
|
|
2639
2661
|
Log.w(
|
|
@@ -2772,6 +2794,9 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
2772
2794
|
finalY +
|
|
2773
2795
|
")"
|
|
2774
2796
|
);
|
|
2797
|
+
|
|
2798
|
+
// Update grid overlay bounds after aspect ratio change
|
|
2799
|
+
previewContainer.post(() -> updateGridOverlayBounds());
|
|
2775
2800
|
}
|
|
2776
2801
|
} catch (NumberFormatException e) {
|
|
2777
2802
|
Log.e(TAG, "Invalid aspect ratio format: " + aspectRatio, e);
|
|
@@ -2842,6 +2867,22 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
2842
2867
|
return new int[] { x, y, width, height };
|
|
2843
2868
|
}
|
|
2844
2869
|
|
|
2870
|
+
private void updateGridOverlayBounds() {
|
|
2871
|
+
if (gridOverlayView != null && previewView != null) {
|
|
2872
|
+
// Get the actual camera bounds
|
|
2873
|
+
Rect cameraBounds = getActualCameraBounds();
|
|
2874
|
+
|
|
2875
|
+
// Update the grid overlay with the camera bounds
|
|
2876
|
+
gridOverlayView.setCameraBounds(cameraBounds);
|
|
2877
|
+
|
|
2878
|
+
Log.d(
|
|
2879
|
+
TAG,
|
|
2880
|
+
"updateGridOverlayBounds: Updated grid bounds to " +
|
|
2881
|
+
cameraBounds.toString()
|
|
2882
|
+
);
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
|
|
2845
2886
|
private void triggerAutoFocus() {
|
|
2846
2887
|
if (camera == null) {
|
|
2847
2888
|
return;
|
|
@@ -3,6 +3,7 @@ package com.ahm.capacitor.camera.preview;
|
|
|
3
3
|
import android.content.Context;
|
|
4
4
|
import android.graphics.Canvas;
|
|
5
5
|
import android.graphics.Paint;
|
|
6
|
+
import android.graphics.Rect;
|
|
6
7
|
import android.util.AttributeSet;
|
|
7
8
|
import android.view.View;
|
|
8
9
|
|
|
@@ -10,6 +11,7 @@ public class GridOverlayView extends View {
|
|
|
10
11
|
|
|
11
12
|
private Paint gridPaint;
|
|
12
13
|
private String gridMode = "none";
|
|
14
|
+
private Rect cameraBounds = null;
|
|
13
15
|
|
|
14
16
|
public GridOverlayView(Context context) {
|
|
15
17
|
super(context);
|
|
@@ -38,6 +40,11 @@ public class GridOverlayView extends View {
|
|
|
38
40
|
gridPaint.setAntiAlias(true);
|
|
39
41
|
}
|
|
40
42
|
|
|
43
|
+
public void setCameraBounds(Rect bounds) {
|
|
44
|
+
this.cameraBounds = bounds;
|
|
45
|
+
invalidate();
|
|
46
|
+
}
|
|
47
|
+
|
|
41
48
|
public void setGridMode(String mode) {
|
|
42
49
|
String previousMode = this.gridMode;
|
|
43
50
|
this.gridMode = mode != null ? mode : "none";
|
|
@@ -62,34 +69,44 @@ public class GridOverlayView extends View {
|
|
|
62
69
|
return;
|
|
63
70
|
}
|
|
64
71
|
|
|
72
|
+
// Use camera bounds if available, otherwise use full view bounds
|
|
73
|
+
int left = 0;
|
|
74
|
+
int top = 0;
|
|
65
75
|
int width = getWidth();
|
|
66
76
|
int height = getHeight();
|
|
67
77
|
|
|
78
|
+
if (cameraBounds != null) {
|
|
79
|
+
left = cameraBounds.left;
|
|
80
|
+
top = cameraBounds.top;
|
|
81
|
+
width = cameraBounds.width();
|
|
82
|
+
height = cameraBounds.height();
|
|
83
|
+
}
|
|
84
|
+
|
|
68
85
|
if (width <= 0 || height <= 0) {
|
|
69
86
|
return;
|
|
70
87
|
}
|
|
71
88
|
|
|
72
89
|
if ("3x3".equals(gridMode)) {
|
|
73
|
-
drawGrid(canvas, width, height, 3);
|
|
90
|
+
drawGrid(canvas, left, top, width, height, 3);
|
|
74
91
|
} else if ("4x4".equals(gridMode)) {
|
|
75
|
-
drawGrid(canvas, width, height, 4);
|
|
92
|
+
drawGrid(canvas, left, top, width, height, 4);
|
|
76
93
|
}
|
|
77
94
|
}
|
|
78
95
|
|
|
79
|
-
private void drawGrid(Canvas canvas, int width, int height, int divisions) {
|
|
96
|
+
private void drawGrid(Canvas canvas, int left, int top, int width, int height, int divisions) {
|
|
80
97
|
float stepX = (float) width / divisions;
|
|
81
98
|
float stepY = (float) height / divisions;
|
|
82
99
|
|
|
83
100
|
// Draw vertical lines
|
|
84
101
|
for (int i = 1; i < divisions; i++) {
|
|
85
|
-
float x = i * stepX;
|
|
86
|
-
canvas.drawLine(x,
|
|
102
|
+
float x = left + (i * stepX);
|
|
103
|
+
canvas.drawLine(x, top, x, top + height, gridPaint);
|
|
87
104
|
}
|
|
88
105
|
|
|
89
106
|
// Draw horizontal lines
|
|
90
107
|
for (int i = 1; i < divisions; i++) {
|
|
91
|
-
float y = i * stepY;
|
|
92
|
-
canvas.drawLine(
|
|
108
|
+
float y = top + (i * stepY);
|
|
109
|
+
canvas.drawLine(left, y, left + width, y, gridPaint);
|
|
93
110
|
}
|
|
94
111
|
}
|
|
95
112
|
}
|