capacitor-plugin-camera-forked 3.0.94 → 3.0.96
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.
|
@@ -350,8 +350,12 @@ public class CameraPreviewPlugin extends Plugin {
|
|
|
350
350
|
return;
|
|
351
351
|
}
|
|
352
352
|
if (useCaseGroup == null) {
|
|
353
|
-
|
|
354
|
-
|
|
353
|
+
// Re-initialize use cases if they were cleared
|
|
354
|
+
setupUseCases(false);
|
|
355
|
+
if (useCaseGroup == null) {
|
|
356
|
+
call.reject("Camera use cases not initialized");
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
355
359
|
}
|
|
356
360
|
if (previewView == null) {
|
|
357
361
|
call.reject("Preview view not initialized");
|
|
@@ -412,9 +416,22 @@ public class CameraPreviewPlugin extends Plugin {
|
|
|
412
416
|
public void run() {
|
|
413
417
|
try {
|
|
414
418
|
restoreWebViewBackground();
|
|
415
|
-
previewView
|
|
416
|
-
|
|
417
|
-
|
|
419
|
+
if (previewView != null) {
|
|
420
|
+
previewView.setVisibility(View.INVISIBLE);
|
|
421
|
+
previewView.setBackgroundColor(Color.BLACK);
|
|
422
|
+
}
|
|
423
|
+
if (cameraProvider != null) {
|
|
424
|
+
cameraProvider.unbindAll();
|
|
425
|
+
}
|
|
426
|
+
// Null out references to help GC and ensure release
|
|
427
|
+
camera = null;
|
|
428
|
+
imageCapture = null;
|
|
429
|
+
preview = null;
|
|
430
|
+
imageAnalysis = null;
|
|
431
|
+
useCaseGroup = null;
|
|
432
|
+
recorder = null;
|
|
433
|
+
currentRecording = null;
|
|
434
|
+
Log.d("Camera", "Camera stopped and all references cleared.");
|
|
418
435
|
call.resolve();
|
|
419
436
|
} catch (Exception e) {
|
|
420
437
|
call.reject(e.getMessage());
|
|
@@ -525,7 +542,7 @@ public class CameraPreviewPlugin extends Plugin {
|
|
|
525
542
|
|
|
526
543
|
} catch (Exception e) {
|
|
527
544
|
e.printStackTrace();
|
|
528
|
-
call.
|
|
545
|
+
call.resolve();
|
|
529
546
|
}
|
|
530
547
|
}
|
|
531
548
|
call.resolve();
|
|
@@ -533,22 +550,34 @@ public class CameraPreviewPlugin extends Plugin {
|
|
|
533
550
|
|
|
534
551
|
@PluginMethod
|
|
535
552
|
public void setFocus(PluginCall call) {
|
|
553
|
+
|
|
554
|
+
JSObject response = new JSObject();
|
|
536
555
|
if (!call.hasOption("x") || !call.hasOption("y")) {
|
|
537
|
-
|
|
556
|
+
response.put("success", false);
|
|
557
|
+
call.resolve(response);
|
|
538
558
|
return;
|
|
539
559
|
}
|
|
540
560
|
|
|
541
561
|
Float x = call.getFloat("x");
|
|
542
562
|
Float y = call.getFloat("y");
|
|
543
563
|
|
|
564
|
+
// Check for null values
|
|
565
|
+
if (x == null || y == null) {
|
|
566
|
+
response.put("success", false);
|
|
567
|
+
call.resolve(response);
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
|
|
544
571
|
// Validate coordinate ranges (should be 0-1 for normalized coordinates)
|
|
545
572
|
if (x < 0.0f || x > 1.0f || y < 0.0f || y > 1.0f) {
|
|
546
|
-
|
|
573
|
+
response.put("success", false);
|
|
574
|
+
call.resolve(response);
|
|
547
575
|
return;
|
|
548
576
|
}
|
|
549
577
|
|
|
550
578
|
if (previewView == null || camera == null) {
|
|
551
|
-
|
|
579
|
+
response.put("success", false);
|
|
580
|
+
call.resolve(response);
|
|
552
581
|
return;
|
|
553
582
|
}
|
|
554
583
|
|
|
@@ -617,7 +646,9 @@ public class CameraPreviewPlugin extends Plugin {
|
|
|
617
646
|
|
|
618
647
|
} catch (Exception e) {
|
|
619
648
|
Log.e("Camera", "Error setting focus", e);
|
|
620
|
-
|
|
649
|
+
response.put("success", false);
|
|
650
|
+
response.put("error", e.getMessage());
|
|
651
|
+
call.resolve(response);
|
|
621
652
|
}
|
|
622
653
|
}
|
|
623
654
|
});
|
|
@@ -1222,12 +1253,21 @@ public class CameraPreviewPlugin extends Plugin {
|
|
|
1222
1253
|
|
|
1223
1254
|
@Override
|
|
1224
1255
|
protected void handleOnPause() {
|
|
1225
|
-
if (camera != null) {
|
|
1256
|
+
if (camera != null && cameraProvider != null) {
|
|
1226
1257
|
CameraState cameraStatus = camera.getCameraInfo().getCameraState().getValue();
|
|
1227
1258
|
previousCameraStatus = cameraStatus;
|
|
1228
1259
|
if (cameraStatus.getType() == CameraState.Type.OPEN) {
|
|
1229
1260
|
cameraProvider.unbindAll();
|
|
1230
1261
|
}
|
|
1262
|
+
// Null out references
|
|
1263
|
+
camera = null;
|
|
1264
|
+
imageCapture = null;
|
|
1265
|
+
preview = null;
|
|
1266
|
+
imageAnalysis = null;
|
|
1267
|
+
useCaseGroup = null;
|
|
1268
|
+
recorder = null;
|
|
1269
|
+
currentRecording = null;
|
|
1270
|
+
Log.d("Camera", "handleOnPause: Camera stopped and references cleared.");
|
|
1231
1271
|
}
|
|
1232
1272
|
super.handleOnPause();
|
|
1233
1273
|
}
|
|
@@ -1306,4 +1346,4 @@ public class CameraPreviewPlugin extends Plugin {
|
|
|
1306
1346
|
call.resolve(result);
|
|
1307
1347
|
}
|
|
1308
1348
|
|
|
1309
|
-
}
|
|
1349
|
+
}
|
package/package.json
CHANGED