capacitor-plugin-camera-forked 2.0.9 → 2.0.11

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.
@@ -322,23 +322,36 @@ public class CameraPreviewPlugin extends Plugin {
322
322
 
323
323
  @PluginMethod
324
324
  public void setFocus(PluginCall call) {
325
- if (call.hasOption("x") && call.hasOption("y")) {
326
- Float x = call.getFloat("x");
327
- Float y = call.getFloat("y");
328
- try {
329
- MeteringPointFactory factory = new SurfaceOrientedMeteringPointFactory(previewView.getWidth(), previewView.getHeight());
330
- MeteringPoint point = factory.createPoint(x, y);
331
- FocusMeteringAction.Builder builder = new FocusMeteringAction.Builder(point, FocusMeteringAction.FLAG_AF);
332
- // auto calling cancelFocusAndMetering in 5 seconds
333
- builder.setAutoCancelDuration(5, TimeUnit.SECONDS);
334
- FocusMeteringAction action = builder.build();
335
- camera.getCameraControl().startFocusAndMetering(action);
336
- } catch (Exception e) {
337
- e.printStackTrace();
338
- call.reject(e.getMessage());
339
- }
325
+ if (call.hasOption("x") && call.hasOption("y")) {
326
+ Float x = call.getFloat("x");
327
+ Float y = call.getFloat("y");
328
+
329
+ if (previewView == null || camera == null) {
330
+ call.reject("Camera preview is not initialized");
331
+ return;
340
332
  }
341
- call.resolve();
333
+
334
+ try {
335
+ // Convert normalized coordinates to absolute pixel coordinates
336
+ float absoluteX = x * previewView.getWidth();
337
+ float absoluteY = y * previewView.getHeight();
338
+
339
+ MeteringPointFactory factory = new SurfaceOrientedMeteringPointFactory(previewView.getWidth(), previewView.getHeight());
340
+ MeteringPoint point = factory.createPoint(absoluteX, absoluteY);
341
+
342
+ FocusMeteringAction.Builder builder = new FocusMeteringAction.Builder(point, FocusMeteringAction.FLAG_AF);
343
+ builder.setAutoCancelDuration(5, TimeUnit.SECONDS);
344
+ FocusMeteringAction action = builder.build();
345
+ camera.getCameraControl().startFocusAndMetering(action);
346
+
347
+ call.resolve();
348
+ } catch (Exception e) {
349
+ call.reject("Error setting focus: " + e.getMessage());
350
+ }
351
+
352
+ } else {
353
+ call.reject("Invalid focus coordinates");
354
+ }
342
355
  }
343
356
 
344
357
  @PluginMethod
@@ -115,7 +115,7 @@ public class CameraPreviewPlugin: CAPPlugin, AVCaptureVideoDataOutputSampleBuffe
115
115
  let previewHeight = screenWidth * aspectRatio // Calculate height
116
116
 
117
117
  let screenHeight = previewView.bounds.height
118
- let previewY = (screenHeight - previewHeight) * 0.4 // Center vertically
118
+ let previewY = (screenHeight - previewHeight) * 0.5 // Center vertically
119
119
 
120
120
  self.previewView.frame = CGRect(x: 0, y: previewY, width: screenWidth, height: previewHeight)
121
121
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-plugin-camera-forked",
3
- "version": "2.0.9",
3
+ "version": "2.0.11",
4
4
  "description": "A capacitor camera plugin - A custom Capacitor camera plugin with additional features.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",