@carviz/capacitor-camera-preview 8.0.1 → 8.0.2
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.
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraActivity.java +25 -15
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +14 -1
- package/android/src/main/java/com/ahm/capacitor/camera/preview/Preview.java +5 -2
- package/dist/esm/definitions.d.ts +6 -0
- package/package.json +1 -1
|
@@ -45,6 +45,7 @@ public class CameraActivity extends Fragment {
|
|
|
45
45
|
void onSnapshotTakenError(String message);
|
|
46
46
|
void onBackButton();
|
|
47
47
|
void onCameraStarted();
|
|
48
|
+
void onCameraStartError(String message);
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
public interface ZoomChangeListener {
|
|
@@ -324,7 +325,16 @@ public class CameraActivity extends Fragment {
|
|
|
324
325
|
public void onResume() {
|
|
325
326
|
super.onResume();
|
|
326
327
|
|
|
327
|
-
|
|
328
|
+
try {
|
|
329
|
+
mCamera = Camera.open(defaultCameraId);
|
|
330
|
+
} catch (RuntimeException e) {
|
|
331
|
+
Log.e(TAG, "Failed to open camera on resume", e);
|
|
332
|
+
mCamera = null;
|
|
333
|
+
if (eventListener != null) {
|
|
334
|
+
eventListener.onCameraStartError(e.getMessage() != null ? e.getMessage() : "Failed to open camera");
|
|
335
|
+
}
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
328
338
|
|
|
329
339
|
if (cameraParameters != null) {
|
|
330
340
|
mCamera.setParameters(cameraParameters);
|
|
@@ -789,25 +799,25 @@ public class CameraActivity extends Fragment {
|
|
|
789
799
|
|
|
790
800
|
public void setFocusArea(final int pointX, final int pointY, final Camera.AutoFocusCallback callback) {
|
|
791
801
|
if (mCamera != null) {
|
|
792
|
-
|
|
802
|
+
try {
|
|
803
|
+
mCamera.cancelAutoFocus();
|
|
793
804
|
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
// Store the original focus mode to restore it later
|
|
797
|
-
final String originalFocusMode = parameters.getFocusMode();
|
|
805
|
+
Camera.Parameters parameters = mCamera.getParameters();
|
|
798
806
|
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
parameters.setFocusAreas(Arrays.asList(new Camera.Area(focusRect, 1000)));
|
|
807
|
+
// Store the original focus mode to restore it later
|
|
808
|
+
final String originalFocusMode = parameters.getFocusMode();
|
|
802
809
|
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
parameters.
|
|
806
|
-
|
|
810
|
+
Rect focusRect = calculateTapArea(pointX, pointY, 1f);
|
|
811
|
+
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
|
|
812
|
+
parameters.setFocusAreas(Arrays.asList(new Camera.Area(focusRect, 1000)));
|
|
813
|
+
|
|
814
|
+
if (parameters.getMaxNumMeteringAreas() > 0) {
|
|
815
|
+
Rect meteringRect = calculateTapArea(pointX, pointY, 1.5f);
|
|
816
|
+
parameters.setMeteringAreas(Arrays.asList(new Camera.Area(meteringRect, 1000)));
|
|
817
|
+
}
|
|
807
818
|
|
|
808
|
-
try {
|
|
809
819
|
setCameraParameters(parameters);
|
|
810
|
-
|
|
820
|
+
|
|
811
821
|
// Wrap the callback to restore focus mode after autofocus completes
|
|
812
822
|
mCamera.autoFocus(new Camera.AutoFocusCallback() {
|
|
813
823
|
@Override
|
|
@@ -440,6 +440,19 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
440
440
|
bridge.releaseCall(pluginCall);
|
|
441
441
|
}
|
|
442
442
|
|
|
443
|
+
@Override
|
|
444
|
+
public void onCameraStartError(String message) {
|
|
445
|
+
PluginCall pluginCall = bridge.getSavedCall(cameraStartCallbackId);
|
|
446
|
+
if (pluginCall != null) {
|
|
447
|
+
pluginCall.reject(message);
|
|
448
|
+
bridge.releaseCall(pluginCall);
|
|
449
|
+
cameraStartCallbackId = "";
|
|
450
|
+
}
|
|
451
|
+
JSObject result = new JSObject();
|
|
452
|
+
result.put("message", message);
|
|
453
|
+
notifyListeners("cameraStartError", result);
|
|
454
|
+
}
|
|
455
|
+
|
|
443
456
|
@Override
|
|
444
457
|
public void onZoomChanged(float zoom) {
|
|
445
458
|
JSObject result = new JSObject();
|
|
@@ -477,7 +490,7 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
477
490
|
new View.OnTouchListener() {
|
|
478
491
|
@Override
|
|
479
492
|
public boolean onTouch(View v, MotionEvent event) {
|
|
480
|
-
if (
|
|
493
|
+
if (fragment != null && fragment.toBack && fragment.frameContainerLayout != null) {
|
|
481
494
|
fragment.frameContainerLayout.dispatchTouchEvent(event);
|
|
482
495
|
}
|
|
483
496
|
return false;
|
|
@@ -62,9 +62,9 @@ class Preview extends RelativeLayout implements SurfaceHolder.Callback, TextureV
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
public void setCamera(Camera camera, int cameraId) {
|
|
65
|
+
mCamera = camera;
|
|
66
|
+
this.cameraId = cameraId;
|
|
65
67
|
if (camera != null) {
|
|
66
|
-
mCamera = camera;
|
|
67
|
-
this.cameraId = cameraId;
|
|
68
68
|
mSupportedPreviewSizes = mCamera.getParameters().getSupportedPreviewSizes();
|
|
69
69
|
setCameraDisplayOrientation();
|
|
70
70
|
|
|
@@ -101,6 +101,9 @@ class Preview extends RelativeLayout implements SurfaceHolder.Callback, TextureV
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
public void setCameraDisplayOrientation() {
|
|
104
|
+
if (mCamera == null) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
104
107
|
Camera.CameraInfo info = new Camera.CameraInfo();
|
|
105
108
|
int rotation = ((Activity) getContext()).getWindowManager().getDefaultDisplay().getRotation();
|
|
106
109
|
int degrees = 0;
|
|
@@ -62,6 +62,10 @@ export interface CameraZoomChangeEvent {
|
|
|
62
62
|
/** The new zoom level */
|
|
63
63
|
zoom: number;
|
|
64
64
|
}
|
|
65
|
+
export interface CameraStartErrorEvent {
|
|
66
|
+
/** The error message from the native camera service */
|
|
67
|
+
message: string;
|
|
68
|
+
}
|
|
65
69
|
export interface CameraPreviewPosition {
|
|
66
70
|
/** The x position in points (iOS) or dp (Android) */
|
|
67
71
|
x: number;
|
|
@@ -125,6 +129,8 @@ export interface CameraPreviewPlugin {
|
|
|
125
129
|
requestPermissions(): Promise<PermissionState>;
|
|
126
130
|
/** Listen for zoom changes - Android / iOS only */
|
|
127
131
|
addListener(eventName: 'zoomChanged', listenerFunc: (event: CameraZoomChangeEvent) => void): Promise<PluginListenerHandle>;
|
|
132
|
+
/** Listen for camera start failures (e.g. the camera service rejecting an open on resume) - Android only */
|
|
133
|
+
addListener(eventName: 'cameraStartError', listenerFunc: (event: CameraStartErrorEvent) => void): Promise<PluginListenerHandle>;
|
|
128
134
|
/** Remove all listeners for this plugin */
|
|
129
135
|
removeAllListeners(): Promise<void>;
|
|
130
136
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carviz/capacitor-camera-preview",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.2",
|
|
4
4
|
"description": "Fork of the capacitor-community/camera-preview plugin focusing on high resolution photos without bloating up the code.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/plugin.cjs.js",
|