@capgo/camera-preview 7.3.12 → 7.4.0-beta.10
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/CapgoCameraPreview.podspec +16 -13
- package/README.md +467 -73
- package/android/.gradle/8.14.2/checksums/checksums.lock +0 -0
- package/android/.gradle/8.14.2/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/8.14.2/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/8.14.2/executionHistory/executionHistory.bin +0 -0
- package/android/.gradle/8.14.2/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/8.14.2/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.14.2/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/8.14.2/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.14.2/fileHashes/resourceHashesCache.bin +0 -0
- package/android/.gradle/8.14.2/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.gradle/file-system.probe +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/build.gradle +11 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
- package/android/src/main/AndroidManifest.xml +5 -3
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +472 -541
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraXView.java +1648 -0
- package/android/src/main/java/com/ahm/capacitor/camera/preview/GridOverlayView.java +82 -0
- package/android/src/main/java/com/ahm/capacitor/camera/preview/model/CameraDevice.java +54 -0
- package/android/src/main/java/com/ahm/capacitor/camera/preview/model/CameraLens.java +70 -0
- package/android/src/main/java/com/ahm/capacitor/camera/preview/model/CameraSessionConfiguration.java +79 -0
- package/android/src/main/java/com/ahm/capacitor/camera/preview/model/LensInfo.java +34 -0
- package/android/src/main/java/com/ahm/capacitor/camera/preview/model/ZoomFactors.java +34 -0
- package/dist/docs.json +934 -154
- package/dist/esm/definitions.d.ts +445 -83
- package/dist/esm/definitions.js +10 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +73 -3
- package/dist/esm/web.js +492 -68
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +498 -68
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +498 -68
- package/dist/plugin.js.map +1 -1
- package/ios/{Plugin → Sources/CapgoCameraPreview}/CameraController.swift +601 -59
- package/ios/Sources/CapgoCameraPreview/GridOverlayView.swift +65 -0
- package/ios/Sources/CapgoCameraPreview/Plugin.swift +1369 -0
- package/ios/Tests/CameraPreviewPluginTests/CameraPreviewPluginTests.swift +15 -0
- package/package.json +1 -1
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraActivity.java +0 -1279
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CustomSurfaceView.java +0 -29
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CustomTextureView.java +0 -39
- package/android/src/main/java/com/ahm/capacitor/camera/preview/Preview.java +0 -461
- package/android/src/main/java/com/ahm/capacitor/camera/preview/TapGestureDetector.java +0 -24
- package/ios/Plugin/Info.plist +0 -24
- package/ios/Plugin/Plugin.h +0 -10
- package/ios/Plugin/Plugin.m +0 -18
- package/ios/Plugin/Plugin.swift +0 -511
- package/ios/Plugin.xcodeproj/project.pbxproj +0 -593
- package/ios/Plugin.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/ios/Plugin.xcworkspace/contents.xcworkspacedata +0 -10
- package/ios/Plugin.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/PluginTests/Info.plist +0 -22
- package/ios/PluginTests/PluginTests.swift +0 -83
- package/ios/Podfile +0 -13
- package/ios/Podfile.lock +0 -23
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
package com.ahm.capacitor.camera.preview;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
import android.view.SurfaceHolder;
|
|
5
|
-
import android.view.SurfaceView;
|
|
6
|
-
import androidx.annotation.NonNull;
|
|
7
|
-
|
|
8
|
-
class CustomSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
|
|
9
|
-
|
|
10
|
-
private final String TAG = "CustomSurfaceView";
|
|
11
|
-
|
|
12
|
-
CustomSurfaceView(Context context) {
|
|
13
|
-
super(context);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
@Override
|
|
17
|
-
public void surfaceCreated(@NonNull SurfaceHolder holder) {}
|
|
18
|
-
|
|
19
|
-
@Override
|
|
20
|
-
public void surfaceChanged(
|
|
21
|
-
@NonNull SurfaceHolder holder,
|
|
22
|
-
int format,
|
|
23
|
-
int width,
|
|
24
|
-
int height
|
|
25
|
-
) {}
|
|
26
|
-
|
|
27
|
-
@Override
|
|
28
|
-
public void surfaceDestroyed(@NonNull SurfaceHolder holder) {}
|
|
29
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
package com.ahm.capacitor.camera.preview;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
import android.graphics.SurfaceTexture;
|
|
5
|
-
import android.view.TextureView;
|
|
6
|
-
import androidx.annotation.NonNull;
|
|
7
|
-
|
|
8
|
-
class CustomTextureView
|
|
9
|
-
extends TextureView
|
|
10
|
-
implements TextureView.SurfaceTextureListener {
|
|
11
|
-
|
|
12
|
-
private final String TAG = "CustomTextureView";
|
|
13
|
-
|
|
14
|
-
CustomTextureView(Context context) {
|
|
15
|
-
super(context);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
@Override
|
|
19
|
-
public void onSurfaceTextureAvailable(
|
|
20
|
-
@NonNull SurfaceTexture surface,
|
|
21
|
-
int width,
|
|
22
|
-
int height
|
|
23
|
-
) {}
|
|
24
|
-
|
|
25
|
-
@Override
|
|
26
|
-
public void onSurfaceTextureSizeChanged(
|
|
27
|
-
@NonNull SurfaceTexture surface,
|
|
28
|
-
int width,
|
|
29
|
-
int height
|
|
30
|
-
) {}
|
|
31
|
-
|
|
32
|
-
@Override
|
|
33
|
-
public boolean onSurfaceTextureDestroyed(@NonNull SurfaceTexture surface) {
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
@Override
|
|
38
|
-
public void onSurfaceTextureUpdated(@NonNull SurfaceTexture surface) {}
|
|
39
|
-
}
|
|
@@ -1,461 +0,0 @@
|
|
|
1
|
-
package com.ahm.capacitor.camera.preview;
|
|
2
|
-
|
|
3
|
-
import android.app.Activity;
|
|
4
|
-
import android.content.Context;
|
|
5
|
-
import android.graphics.SurfaceTexture;
|
|
6
|
-
import android.hardware.Camera;
|
|
7
|
-
import android.util.DisplayMetrics;
|
|
8
|
-
import android.util.Log;
|
|
9
|
-
import android.view.Surface;
|
|
10
|
-
import android.view.SurfaceHolder;
|
|
11
|
-
import android.view.TextureView;
|
|
12
|
-
import android.view.View;
|
|
13
|
-
import android.widget.RelativeLayout;
|
|
14
|
-
import java.io.IOException;
|
|
15
|
-
import java.util.List;
|
|
16
|
-
|
|
17
|
-
class Preview
|
|
18
|
-
extends RelativeLayout
|
|
19
|
-
implements SurfaceHolder.Callback, TextureView.SurfaceTextureListener {
|
|
20
|
-
|
|
21
|
-
private final String TAG = "Preview";
|
|
22
|
-
|
|
23
|
-
CustomSurfaceView mSurfaceView;
|
|
24
|
-
CustomTextureView mTextureView;
|
|
25
|
-
SurfaceHolder mHolder;
|
|
26
|
-
SurfaceTexture mSurface;
|
|
27
|
-
Camera.Size mPreviewSize;
|
|
28
|
-
List<Camera.Size> mSupportedPreviewSizes;
|
|
29
|
-
Camera mCamera;
|
|
30
|
-
int cameraId;
|
|
31
|
-
int displayOrientation;
|
|
32
|
-
int facing = Camera.CameraInfo.CAMERA_FACING_BACK;
|
|
33
|
-
int viewWidth;
|
|
34
|
-
int viewHeight;
|
|
35
|
-
private boolean enableOpacity = false;
|
|
36
|
-
private float opacity = 1F;
|
|
37
|
-
|
|
38
|
-
Preview(Context context) {
|
|
39
|
-
this(context, false);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
Preview(Context context, boolean enableOpacity) {
|
|
43
|
-
super(context);
|
|
44
|
-
this.enableOpacity = enableOpacity;
|
|
45
|
-
if (!enableOpacity) {
|
|
46
|
-
mSurfaceView = new CustomSurfaceView(context);
|
|
47
|
-
addView(mSurfaceView);
|
|
48
|
-
requestLayout();
|
|
49
|
-
|
|
50
|
-
// Install a SurfaceHolder.Callback so we get notified when the
|
|
51
|
-
// underlying surface is created and destroyed.
|
|
52
|
-
mHolder = mSurfaceView.getHolder();
|
|
53
|
-
mHolder.addCallback(this);
|
|
54
|
-
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
|
55
|
-
} else {
|
|
56
|
-
// Use a TextureView so we can manage opacity
|
|
57
|
-
mTextureView = new CustomTextureView(context);
|
|
58
|
-
// Install a SurfaceTextureListener so we get notified
|
|
59
|
-
mTextureView.setSurfaceTextureListener(this);
|
|
60
|
-
mTextureView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
|
61
|
-
addView(mTextureView);
|
|
62
|
-
requestLayout();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
public void setCamera(Camera camera, int cameraId) {
|
|
67
|
-
if (camera != null) {
|
|
68
|
-
mCamera = camera;
|
|
69
|
-
this.cameraId = cameraId;
|
|
70
|
-
mSupportedPreviewSizes = mCamera
|
|
71
|
-
.getParameters()
|
|
72
|
-
.getSupportedPreviewSizes();
|
|
73
|
-
setCameraDisplayOrientation();
|
|
74
|
-
|
|
75
|
-
List<String> mFocusModes = mCamera
|
|
76
|
-
.getParameters()
|
|
77
|
-
.getSupportedFocusModes();
|
|
78
|
-
|
|
79
|
-
Camera.Parameters params = mCamera.getParameters();
|
|
80
|
-
if (mFocusModes.contains("continuous-picture")) {
|
|
81
|
-
params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
|
|
82
|
-
} else if (mFocusModes.contains("continuous-video")) {
|
|
83
|
-
params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
|
|
84
|
-
} else if (mFocusModes.contains("auto")) {
|
|
85
|
-
params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
|
|
86
|
-
}
|
|
87
|
-
mCamera.setParameters(params);
|
|
88
|
-
} else {
|
|
89
|
-
// Release the camera and set it to null when the camera parameter is null
|
|
90
|
-
if (mCamera != null) {
|
|
91
|
-
mCamera.release();
|
|
92
|
-
mCamera = null;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
public int getDisplayOrientation() {
|
|
98
|
-
return displayOrientation;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
public int getCameraFacing() {
|
|
102
|
-
return facing;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
public void printPreviewSize(String from) {
|
|
106
|
-
Log.d(
|
|
107
|
-
TAG,
|
|
108
|
-
"printPreviewSize from " +
|
|
109
|
-
from +
|
|
110
|
-
": > width: " +
|
|
111
|
-
mPreviewSize.width +
|
|
112
|
-
" height: " +
|
|
113
|
-
mPreviewSize.height
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
public void setCameraPreviewSize() {
|
|
118
|
-
if (mCamera != null) {
|
|
119
|
-
Camera.Parameters parameters = mCamera.getParameters();
|
|
120
|
-
parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
|
|
121
|
-
mCamera.setParameters(parameters);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
public void setCameraDisplayOrientation() {
|
|
126
|
-
Camera.CameraInfo info = new Camera.CameraInfo();
|
|
127
|
-
int rotation =
|
|
128
|
-
((Activity) getContext()).getWindowManager()
|
|
129
|
-
.getDefaultDisplay()
|
|
130
|
-
.getRotation();
|
|
131
|
-
int degrees = 0;
|
|
132
|
-
DisplayMetrics dm = new DisplayMetrics();
|
|
133
|
-
|
|
134
|
-
Camera.getCameraInfo(cameraId, info);
|
|
135
|
-
((Activity) getContext()).getWindowManager()
|
|
136
|
-
.getDefaultDisplay()
|
|
137
|
-
.getMetrics(dm);
|
|
138
|
-
|
|
139
|
-
switch (rotation) {
|
|
140
|
-
case Surface.ROTATION_0:
|
|
141
|
-
degrees = 0;
|
|
142
|
-
break;
|
|
143
|
-
case Surface.ROTATION_90:
|
|
144
|
-
degrees = 90;
|
|
145
|
-
break;
|
|
146
|
-
case Surface.ROTATION_180:
|
|
147
|
-
degrees = 180;
|
|
148
|
-
break;
|
|
149
|
-
case Surface.ROTATION_270:
|
|
150
|
-
degrees = 270;
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
facing = info.facing;
|
|
154
|
-
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
|
|
155
|
-
displayOrientation = (info.orientation + degrees) % 360;
|
|
156
|
-
displayOrientation = (360 - displayOrientation) % 360;
|
|
157
|
-
} else {
|
|
158
|
-
displayOrientation = (info.orientation - degrees + 360) % 360;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
Log.d(TAG, "screen is rotated " + degrees + "deg from natural");
|
|
162
|
-
Log.d(
|
|
163
|
-
TAG,
|
|
164
|
-
(info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT
|
|
165
|
-
? "front"
|
|
166
|
-
: "back") +
|
|
167
|
-
" camera is oriented -" +
|
|
168
|
-
info.orientation +
|
|
169
|
-
"deg from natural"
|
|
170
|
-
);
|
|
171
|
-
Log.d(TAG, "need to rotate preview " + displayOrientation + "deg");
|
|
172
|
-
mCamera.setDisplayOrientation(displayOrientation);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
public void switchCamera(Camera camera, int cameraId) {
|
|
176
|
-
try {
|
|
177
|
-
setCamera(camera, cameraId);
|
|
178
|
-
|
|
179
|
-
Log.d("CameraPreview", "before set camera");
|
|
180
|
-
|
|
181
|
-
View v;
|
|
182
|
-
if (enableOpacity) {
|
|
183
|
-
camera.setPreviewTexture(mSurface);
|
|
184
|
-
v = mTextureView;
|
|
185
|
-
} else {
|
|
186
|
-
camera.setPreviewDisplay(mHolder);
|
|
187
|
-
v = mSurfaceView;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
Log.d("CameraPreview", "before getParameters");
|
|
191
|
-
|
|
192
|
-
Camera.Parameters parameters = camera.getParameters();
|
|
193
|
-
|
|
194
|
-
Log.d("CameraPreview", "before setPreviewSize");
|
|
195
|
-
|
|
196
|
-
mSupportedPreviewSizes = parameters.getSupportedPreviewSizes();
|
|
197
|
-
mPreviewSize = getOptimalPreviewSize(
|
|
198
|
-
mSupportedPreviewSizes,
|
|
199
|
-
v.getWidth(),
|
|
200
|
-
v.getHeight()
|
|
201
|
-
);
|
|
202
|
-
parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
|
|
203
|
-
Log.d(TAG, mPreviewSize.width + " " + mPreviewSize.height);
|
|
204
|
-
|
|
205
|
-
camera.setParameters(parameters);
|
|
206
|
-
} catch (IOException exception) {
|
|
207
|
-
Log.e(TAG, exception.getMessage());
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
@Override
|
|
212
|
-
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
213
|
-
// We purposely disregard child measurements because act as a
|
|
214
|
-
// wrapper to a SurfaceView that centers the camera preview instead
|
|
215
|
-
// of stretching it.
|
|
216
|
-
final int width = resolveSize(getSuggestedMinimumWidth(), widthMeasureSpec);
|
|
217
|
-
final int height = resolveSize(
|
|
218
|
-
getSuggestedMinimumHeight(),
|
|
219
|
-
heightMeasureSpec
|
|
220
|
-
);
|
|
221
|
-
setMeasuredDimension(width, height);
|
|
222
|
-
|
|
223
|
-
if (mSupportedPreviewSizes != null) {
|
|
224
|
-
mPreviewSize = getOptimalPreviewSize(
|
|
225
|
-
mSupportedPreviewSizes,
|
|
226
|
-
width,
|
|
227
|
-
height
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
@Override
|
|
233
|
-
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
|
234
|
-
if (changed && getChildCount() > 0) {
|
|
235
|
-
final View child = getChildAt(0);
|
|
236
|
-
|
|
237
|
-
int width = r - l;
|
|
238
|
-
int height = b - t;
|
|
239
|
-
|
|
240
|
-
int previewWidth = width;
|
|
241
|
-
int previewHeight = height;
|
|
242
|
-
|
|
243
|
-
if (mPreviewSize != null) {
|
|
244
|
-
previewWidth = mPreviewSize.width;
|
|
245
|
-
previewHeight = mPreviewSize.height;
|
|
246
|
-
|
|
247
|
-
if (displayOrientation == 90 || displayOrientation == 270) {
|
|
248
|
-
previewWidth = mPreviewSize.height;
|
|
249
|
-
previewHeight = mPreviewSize.width;
|
|
250
|
-
}
|
|
251
|
-
// LOG.d(TAG, "previewWidth:" + previewWidth + " previewHeight:" + previewHeight);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
int nW;
|
|
255
|
-
int nH;
|
|
256
|
-
int top;
|
|
257
|
-
int left;
|
|
258
|
-
|
|
259
|
-
float scale = 1.0f;
|
|
260
|
-
|
|
261
|
-
// Center the child SurfaceView within the parent.
|
|
262
|
-
if (width * previewHeight < height * previewWidth) {
|
|
263
|
-
Log.d(TAG, "center horizontally");
|
|
264
|
-
int scaledChildWidth = (int) (((previewWidth * height) /
|
|
265
|
-
previewHeight) *
|
|
266
|
-
scale);
|
|
267
|
-
nW = (width + scaledChildWidth) / 2;
|
|
268
|
-
nH = (int) (height * scale);
|
|
269
|
-
top = 0;
|
|
270
|
-
left = (width - scaledChildWidth) / 2;
|
|
271
|
-
} else {
|
|
272
|
-
Log.d(TAG, "center vertically");
|
|
273
|
-
int scaledChildHeight = (int) (((previewHeight * width) /
|
|
274
|
-
previewWidth) *
|
|
275
|
-
scale);
|
|
276
|
-
nW = (int) (width * scale);
|
|
277
|
-
nH = (height + scaledChildHeight) / 2;
|
|
278
|
-
top = (height - scaledChildHeight) / 2;
|
|
279
|
-
left = 0;
|
|
280
|
-
}
|
|
281
|
-
child.layout(left, top, nW, nH);
|
|
282
|
-
|
|
283
|
-
Log.d("layout", "left:" + left);
|
|
284
|
-
Log.d("layout", "top:" + top);
|
|
285
|
-
Log.d("layout", "right:" + nW);
|
|
286
|
-
Log.d("layout", "bottom:" + nH);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
public void surfaceCreated(SurfaceHolder holder) {
|
|
291
|
-
// The Surface has been created, acquire the camera and tell it where
|
|
292
|
-
// to draw.
|
|
293
|
-
try {
|
|
294
|
-
if (mCamera != null) {
|
|
295
|
-
mSurfaceView.setWillNotDraw(false);
|
|
296
|
-
mCamera.setPreviewDisplay(holder);
|
|
297
|
-
}
|
|
298
|
-
} catch (Exception exception) {
|
|
299
|
-
Log.e(TAG, "Exception caused by setPreviewDisplay()", exception);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
public void surfaceDestroyed(SurfaceHolder holder) {
|
|
304
|
-
// Surface will be destroyed when we return, so stop the preview.
|
|
305
|
-
try {
|
|
306
|
-
if (mCamera != null) {
|
|
307
|
-
mCamera.stopPreview();
|
|
308
|
-
}
|
|
309
|
-
} catch (Exception exception) {
|
|
310
|
-
Log.e(TAG, "Exception caused by surfaceDestroyed()", exception);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
private Camera.Size getOptimalPreviewSize(
|
|
315
|
-
List<Camera.Size> sizes,
|
|
316
|
-
int w,
|
|
317
|
-
int h
|
|
318
|
-
) {
|
|
319
|
-
final double ASPECT_TOLERANCE = 0.1;
|
|
320
|
-
double targetRatio = (double) w / h;
|
|
321
|
-
|
|
322
|
-
int targetHeight = h;
|
|
323
|
-
if (displayOrientation == 90 || displayOrientation == 270) {
|
|
324
|
-
targetRatio = (double) h / w;
|
|
325
|
-
targetHeight = w;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
if (sizes == null) {
|
|
329
|
-
return null;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
Camera.Size optimalSize = null;
|
|
333
|
-
double minDiff = Double.MAX_VALUE;
|
|
334
|
-
|
|
335
|
-
// Try to find an size match aspect ratio and size
|
|
336
|
-
for (Camera.Size size : sizes) {
|
|
337
|
-
double ratio = (double) size.width / size.height;
|
|
338
|
-
if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
|
|
339
|
-
if (Math.abs(size.height - targetHeight) < minDiff) {
|
|
340
|
-
optimalSize = size;
|
|
341
|
-
minDiff = Math.abs(size.height - targetHeight);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
// Cannot find the one match the aspect ratio, ignore the requirement
|
|
346
|
-
if (optimalSize == null) {
|
|
347
|
-
minDiff = Double.MAX_VALUE;
|
|
348
|
-
for (Camera.Size size : sizes) {
|
|
349
|
-
if (Math.abs(size.height - targetHeight) < minDiff) {
|
|
350
|
-
optimalSize = size;
|
|
351
|
-
minDiff = Math.abs(size.height - targetHeight);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
Log.d(
|
|
357
|
-
TAG,
|
|
358
|
-
"optimal preview size: w: " +
|
|
359
|
-
optimalSize.width +
|
|
360
|
-
" h: " +
|
|
361
|
-
optimalSize.height
|
|
362
|
-
);
|
|
363
|
-
return optimalSize;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
|
|
367
|
-
Log.d(
|
|
368
|
-
TAG,
|
|
369
|
-
"Preview size in surfaceChanged: " +
|
|
370
|
-
mPreviewSize.width +
|
|
371
|
-
"x" +
|
|
372
|
-
mPreviewSize.height
|
|
373
|
-
);
|
|
374
|
-
|
|
375
|
-
if (mCamera != null) {
|
|
376
|
-
try {
|
|
377
|
-
// Now that the size is known, set up the camera parameters and begin
|
|
378
|
-
// the preview.
|
|
379
|
-
mSupportedPreviewSizes = mCamera
|
|
380
|
-
.getParameters()
|
|
381
|
-
.getSupportedPreviewSizes();
|
|
382
|
-
if (mSupportedPreviewSizes != null) {
|
|
383
|
-
mPreviewSize = getOptimalPreviewSize(mSupportedPreviewSizes, w, h);
|
|
384
|
-
}
|
|
385
|
-
startCamera();
|
|
386
|
-
} catch (Exception exception) {
|
|
387
|
-
Log.e(TAG, "Exception caused by surfaceChanged()", exception);
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
private void startCamera() {
|
|
393
|
-
Camera.Parameters parameters = mCamera.getParameters();
|
|
394
|
-
parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
|
|
395
|
-
requestLayout();
|
|
396
|
-
//mCamera.setDisplayOrientation(90);
|
|
397
|
-
mCamera.setParameters(parameters);
|
|
398
|
-
mCamera.startPreview();
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
// Texture Callbacks
|
|
402
|
-
|
|
403
|
-
public void onSurfaceTextureAvailable(
|
|
404
|
-
SurfaceTexture surface,
|
|
405
|
-
int width,
|
|
406
|
-
int height
|
|
407
|
-
) {
|
|
408
|
-
// The Surface has been created, acquire the camera and tell it where
|
|
409
|
-
// to draw.
|
|
410
|
-
try {
|
|
411
|
-
mSurface = surface;
|
|
412
|
-
if (mSupportedPreviewSizes != null) {
|
|
413
|
-
mPreviewSize = getOptimalPreviewSize(
|
|
414
|
-
mSupportedPreviewSizes,
|
|
415
|
-
width,
|
|
416
|
-
height
|
|
417
|
-
);
|
|
418
|
-
}
|
|
419
|
-
if (mCamera != null) {
|
|
420
|
-
mTextureView.setAlpha(opacity);
|
|
421
|
-
mCamera.setPreviewTexture(surface);
|
|
422
|
-
startCamera();
|
|
423
|
-
}
|
|
424
|
-
} catch (Exception exception) {
|
|
425
|
-
Log.e(TAG, "Exception caused by onSurfaceTextureAvailable()", exception);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
public void onSurfaceTextureSizeChanged(
|
|
430
|
-
SurfaceTexture surface,
|
|
431
|
-
int width,
|
|
432
|
-
int height
|
|
433
|
-
) {}
|
|
434
|
-
|
|
435
|
-
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
|
|
436
|
-
try {
|
|
437
|
-
if (mCamera != null) {
|
|
438
|
-
mCamera.stopPreview();
|
|
439
|
-
}
|
|
440
|
-
} catch (Exception exception) {
|
|
441
|
-
Log.e(TAG, "Exception caused by onSurfaceTextureDestroyed()", exception);
|
|
442
|
-
return false;
|
|
443
|
-
}
|
|
444
|
-
return true;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
public void onSurfaceTextureUpdated(SurfaceTexture surface) {}
|
|
448
|
-
|
|
449
|
-
public void setOneShotPreviewCallback(Camera.PreviewCallback callback) {
|
|
450
|
-
if (mCamera != null) {
|
|
451
|
-
mCamera.setOneShotPreviewCallback(callback);
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
public void setOpacity(final float opacity) {
|
|
456
|
-
this.opacity = opacity;
|
|
457
|
-
if (mCamera != null && enableOpacity) {
|
|
458
|
-
mTextureView.setAlpha(opacity);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
package com.ahm.capacitor.camera.preview;
|
|
2
|
-
|
|
3
|
-
import android.view.GestureDetector;
|
|
4
|
-
import android.view.MotionEvent;
|
|
5
|
-
|
|
6
|
-
class TapGestureDetector extends GestureDetector.SimpleOnGestureListener {
|
|
7
|
-
|
|
8
|
-
private final String TAG = "TapGestureDetector";
|
|
9
|
-
|
|
10
|
-
@Override
|
|
11
|
-
public boolean onDown(MotionEvent e) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
@Override
|
|
16
|
-
public boolean onSingleTapUp(MotionEvent e) {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
@Override
|
|
21
|
-
public boolean onSingleTapConfirmed(MotionEvent e) {
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
}
|
package/ios/Plugin/Info.plist
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
-
<plist version="1.0">
|
|
4
|
-
<dict>
|
|
5
|
-
<key>CFBundleDevelopmentRegion</key>
|
|
6
|
-
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
|
7
|
-
<key>CFBundleExecutable</key>
|
|
8
|
-
<string>$(EXECUTABLE_NAME)</string>
|
|
9
|
-
<key>CFBundleIdentifier</key>
|
|
10
|
-
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
|
11
|
-
<key>CFBundleInfoDictionaryVersion</key>
|
|
12
|
-
<string>6.0</string>
|
|
13
|
-
<key>CFBundleName</key>
|
|
14
|
-
<string>$(PRODUCT_NAME)</string>
|
|
15
|
-
<key>CFBundlePackageType</key>
|
|
16
|
-
<string>FMWK</string>
|
|
17
|
-
<key>CFBundleShortVersionString</key>
|
|
18
|
-
<string>1.0</string>
|
|
19
|
-
<key>CFBundleVersion</key>
|
|
20
|
-
<string>$(CURRENT_PROJECT_VERSION)</string>
|
|
21
|
-
<key>NSPrincipalClass</key>
|
|
22
|
-
<string></string>
|
|
23
|
-
</dict>
|
|
24
|
-
</plist>
|
package/ios/Plugin/Plugin.h
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#import <UIKit/UIKit.h>
|
|
2
|
-
|
|
3
|
-
//! Project version number for Plugin.
|
|
4
|
-
FOUNDATION_EXPORT double PluginVersionNumber;
|
|
5
|
-
|
|
6
|
-
//! Project version string for Plugin.
|
|
7
|
-
FOUNDATION_EXPORT const unsigned char PluginVersionString[];
|
|
8
|
-
|
|
9
|
-
// In this header, you should import all the public headers of your framework using statements like #import <Plugin/PublicHeader.h>
|
|
10
|
-
|
package/ios/Plugin/Plugin.m
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
#import <Foundation/Foundation.h>
|
|
2
|
-
#import <Capacitor/Capacitor.h>
|
|
3
|
-
|
|
4
|
-
// Define the plugin using the CAP_PLUGIN Macro, and
|
|
5
|
-
// each method the plugin supports using the CAP_PLUGIN_METHOD macro.
|
|
6
|
-
CAP_PLUGIN(CameraPreview, "CameraPreview",
|
|
7
|
-
CAP_PLUGIN_METHOD(start, CAPPluginReturnPromise);
|
|
8
|
-
CAP_PLUGIN_METHOD(stop, CAPPluginReturnPromise);
|
|
9
|
-
CAP_PLUGIN_METHOD(capture, CAPPluginReturnPromise);
|
|
10
|
-
CAP_PLUGIN_METHOD(captureSample, CAPPluginReturnPromise);
|
|
11
|
-
CAP_PLUGIN_METHOD(flip, CAPPluginReturnPromise);
|
|
12
|
-
CAP_PLUGIN_METHOD(getSupportedFlashModes, CAPPluginReturnPromise);
|
|
13
|
-
CAP_PLUGIN_METHOD(getHorizontalFov, CAPPluginReturnPromise);
|
|
14
|
-
CAP_PLUGIN_METHOD(setFlashMode, CAPPluginReturnPromise);
|
|
15
|
-
CAP_PLUGIN_METHOD(startRecordVideo, CAPPluginReturnPromise);
|
|
16
|
-
CAP_PLUGIN_METHOD(stopRecordVideo, CAPPluginReturnPromise);
|
|
17
|
-
CAP_PLUGIN_METHOD(getSupportedPictureSizes, CAPPluginReturnPromise);
|
|
18
|
-
)
|