capacitor-plugin-camera-forked 2.0.10 → 2.0.12
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
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
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
|
-
|
|
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
|
|
@@ -545,23 +545,28 @@ public class CameraPreviewPlugin: CAPPlugin, AVCaptureVideoDataOutputSampleBuffe
|
|
|
545
545
|
|
|
546
546
|
// 1. Check if focus point is supported
|
|
547
547
|
guard device.isFocusPointOfInterestSupported else {
|
|
548
|
+
device.unlockForConfiguration()
|
|
548
549
|
call.reject("Focus point of interest not supported on this device")
|
|
549
550
|
return
|
|
550
551
|
}
|
|
551
552
|
|
|
552
553
|
// 2. Set focus point
|
|
553
554
|
device.focusPointOfInterest = CGPoint(x: CGFloat(x), y: CGFloat(y))
|
|
554
|
-
|
|
555
555
|
// 3. Set focus mode (choose one supported by your use case)
|
|
556
|
-
if device.isFocusModeSupported(.
|
|
557
|
-
device.focusMode = .autoFocus
|
|
558
|
-
} else if device.isFocusModeSupported(.continuousAutoFocus) {
|
|
556
|
+
if device.isFocusModeSupported(.continuousAutoFocus) {
|
|
559
557
|
device.focusMode = .continuousAutoFocus
|
|
558
|
+
} else if device.isFocusModeSupported(.autoFocus) {
|
|
559
|
+
device.focusMode = .autoFocus
|
|
560
560
|
} else {
|
|
561
561
|
call.reject("No supported focus mode available")
|
|
562
562
|
return
|
|
563
563
|
}
|
|
564
|
-
|
|
564
|
+
|
|
565
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
|
|
566
|
+
device.unlockForConfiguration()
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
call.resolve()
|
|
565
570
|
} catch {
|
|
566
571
|
call.reject("Failed to lock device for configuration: \(error.localizedDescription)")
|
|
567
572
|
}
|
package/package.json
CHANGED