@carviz/capacitor-camera-preview 7.0.0

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.
Files changed (56) hide show
  1. package/CarvizCapacitorCameraPreview.podspec +17 -0
  2. package/LICENSE +22 -0
  3. package/README.md +229 -0
  4. package/android/.project +17 -0
  5. package/android/build.gradle +57 -0
  6. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  7. package/android/gradle/wrapper/gradle-wrapper.properties +8 -0
  8. package/android/gradle.properties +18 -0
  9. package/android/gradlew +248 -0
  10. package/android/gradlew.bat +92 -0
  11. package/android/proguard-rules.pro +21 -0
  12. package/android/settings.gradle +2 -0
  13. package/android/src/androidTest/java/com/getcapacitor/android/ExampleInstrumentedTest.java +26 -0
  14. package/android/src/main/AndroidManifest.xml +5 -0
  15. package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraActivity.java +831 -0
  16. package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +396 -0
  17. package/android/src/main/java/com/ahm/capacitor/camera/preview/CustomSurfaceView.java +23 -0
  18. package/android/src/main/java/com/ahm/capacitor/camera/preview/CustomTextureView.java +29 -0
  19. package/android/src/main/java/com/ahm/capacitor/camera/preview/Preview.java +384 -0
  20. package/android/src/main/java/com/ahm/capacitor/camera/preview/TapGestureDetector.java +24 -0
  21. package/android/src/main/res/layout/bridge_layout_main.xml +15 -0
  22. package/android/src/main/res/layout/camera_activity.xml +68 -0
  23. package/android/src/main/res/values/camera_ids.xml +4 -0
  24. package/android/src/main/res/values/camera_theme.xml +9 -0
  25. package/android/src/main/res/values/colors.xml +3 -0
  26. package/android/src/main/res/values/strings.xml +3 -0
  27. package/android/src/main/res/values/styles.xml +3 -0
  28. package/android/src/test/java/com/getcapacitor/ExampleUnitTest.java +18 -0
  29. package/dist/esm/definitions.d.ts +86 -0
  30. package/dist/esm/definitions.js +2 -0
  31. package/dist/esm/definitions.js.map +1 -0
  32. package/dist/esm/index.d.ts +4 -0
  33. package/dist/esm/index.js +7 -0
  34. package/dist/esm/index.js.map +1 -0
  35. package/dist/esm/web.d.ts +24 -0
  36. package/dist/esm/web.js +120 -0
  37. package/dist/esm/web.js.map +1 -0
  38. package/dist/plugin.cjs.js +134 -0
  39. package/dist/plugin.cjs.js.map +1 -0
  40. package/dist/plugin.js +137 -0
  41. package/dist/plugin.js.map +1 -0
  42. package/ios/Plugin/CameraController.swift +483 -0
  43. package/ios/Plugin/Info.plist +24 -0
  44. package/ios/Plugin/Plugin.h +10 -0
  45. package/ios/Plugin/Plugin.m +16 -0
  46. package/ios/Plugin/Plugin.swift +324 -0
  47. package/ios/Plugin/UIImage.swift +56 -0
  48. package/ios/Plugin.xcodeproj/project.pbxproj +599 -0
  49. package/ios/Plugin.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  50. package/ios/Plugin.xcworkspace/contents.xcworkspacedata +10 -0
  51. package/ios/Plugin.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  52. package/ios/PluginTests/Info.plist +22 -0
  53. package/ios/PluginTests/PluginTests.swift +16 -0
  54. package/ios/Podfile +16 -0
  55. package/ios/Podfile.lock +22 -0
  56. package/package.json +85 -0
@@ -0,0 +1,384 @@
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 extends RelativeLayout implements SurfaceHolder.Callback, TextureView.SurfaceTextureListener {
18
+
19
+ private final String TAG = "Preview";
20
+
21
+ CustomSurfaceView mSurfaceView;
22
+ CustomTextureView mTextureView;
23
+ SurfaceHolder mHolder;
24
+ SurfaceTexture mSurface;
25
+ Camera.Size mPreviewSize;
26
+ List<Camera.Size> mSupportedPreviewSizes;
27
+ Camera mCamera;
28
+ int cameraId;
29
+ int displayOrientation;
30
+ int facing = Camera.CameraInfo.CAMERA_FACING_BACK;
31
+ int viewWidth;
32
+ int viewHeight;
33
+ private boolean enableOpacity = false;
34
+ private float opacity = 1F;
35
+
36
+ Preview(Context context) {
37
+ this(context, false);
38
+ }
39
+
40
+ Preview(Context context, boolean enableOpacity) {
41
+ super(context);
42
+ this.enableOpacity = enableOpacity;
43
+ if (!enableOpacity) {
44
+ mSurfaceView = new CustomSurfaceView(context);
45
+ addView(mSurfaceView);
46
+ requestLayout();
47
+
48
+ // Install a SurfaceHolder.Callback so we get notified when the
49
+ // underlying surface is created and destroyed.
50
+ mHolder = mSurfaceView.getHolder();
51
+ mHolder.addCallback(this);
52
+ mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
53
+ } else {
54
+ // Use a TextureView so we can manage opacity
55
+ mTextureView = new CustomTextureView(context);
56
+ // Install a SurfaceTextureListener so we get notified
57
+ mTextureView.setSurfaceTextureListener(this);
58
+ mTextureView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
59
+ addView(mTextureView);
60
+ requestLayout();
61
+ }
62
+ }
63
+
64
+ public void setCamera(Camera camera, int cameraId) {
65
+ if (camera != null) {
66
+ mCamera = camera;
67
+ this.cameraId = cameraId;
68
+ mSupportedPreviewSizes = mCamera.getParameters().getSupportedPreviewSizes();
69
+ setCameraDisplayOrientation();
70
+
71
+ List<String> mFocusModes = mCamera.getParameters().getSupportedFocusModes();
72
+
73
+ Camera.Parameters params = mCamera.getParameters();
74
+ if (mFocusModes.contains("continuous-picture")) {
75
+ params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
76
+ } else if (mFocusModes.contains("auto")) {
77
+ params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
78
+ }
79
+ mCamera.setParameters(params);
80
+ }
81
+ }
82
+
83
+ public int getDisplayOrientation() {
84
+ return displayOrientation;
85
+ }
86
+
87
+ public int getCameraFacing() {
88
+ return facing;
89
+ }
90
+
91
+ public void printPreviewSize(String from) {
92
+ Log.d(TAG, "printPreviewSize from " + from + ": > width: " + mPreviewSize.width + " height: " + mPreviewSize.height);
93
+ }
94
+
95
+ public void setCameraPreviewSize() {
96
+ if (mCamera != null) {
97
+ Camera.Parameters parameters = mCamera.getParameters();
98
+ parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
99
+ mCamera.setParameters(parameters);
100
+ }
101
+ }
102
+
103
+ public void setCameraDisplayOrientation() {
104
+ Camera.CameraInfo info = new Camera.CameraInfo();
105
+ int rotation = ((Activity) getContext()).getWindowManager().getDefaultDisplay().getRotation();
106
+ int degrees = 0;
107
+ DisplayMetrics dm = new DisplayMetrics();
108
+
109
+ Camera.getCameraInfo(cameraId, info);
110
+ ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(dm);
111
+
112
+ switch (rotation) {
113
+ case Surface.ROTATION_0:
114
+ degrees = 0;
115
+ break;
116
+ case Surface.ROTATION_90:
117
+ degrees = 90;
118
+ break;
119
+ case Surface.ROTATION_180:
120
+ degrees = 180;
121
+ break;
122
+ case Surface.ROTATION_270:
123
+ degrees = 270;
124
+ break;
125
+ }
126
+ facing = info.facing;
127
+ if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
128
+ displayOrientation = (info.orientation + degrees) % 360;
129
+ displayOrientation = (360 - displayOrientation) % 360;
130
+ } else {
131
+ displayOrientation = (info.orientation - degrees + 360) % 360;
132
+ }
133
+
134
+ Log.d(TAG, "screen is rotated " + degrees + "deg from natural");
135
+ Log.d(
136
+ TAG,
137
+ (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT ? "front" : "back") +
138
+ " camera is oriented -" +
139
+ info.orientation +
140
+ "deg from natural"
141
+ );
142
+ Log.d(TAG, "need to rotate preview " + displayOrientation + "deg");
143
+ mCamera.setDisplayOrientation(displayOrientation);
144
+ }
145
+
146
+ public void switchCamera(Camera camera, int cameraId) {
147
+ try {
148
+ setCamera(camera, cameraId);
149
+
150
+ Log.d("CameraPreview", "before set camera");
151
+
152
+ View v;
153
+ if (enableOpacity) {
154
+ camera.setPreviewTexture(mSurface);
155
+ v = mTextureView;
156
+ } else {
157
+ camera.setPreviewDisplay(mHolder);
158
+ v = mSurfaceView;
159
+ }
160
+
161
+ Log.d("CameraPreview", "before getParameters");
162
+
163
+ Camera.Parameters parameters = camera.getParameters();
164
+
165
+ Log.d("CameraPreview", "before setPreviewSize");
166
+
167
+ mSupportedPreviewSizes = parameters.getSupportedPreviewSizes();
168
+ mPreviewSize = getOptimalPreviewSize(mSupportedPreviewSizes, v.getWidth(), v.getHeight());
169
+ parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
170
+ Log.d(TAG, mPreviewSize.width + " " + mPreviewSize.height);
171
+
172
+ camera.setParameters(parameters);
173
+ } catch (IOException exception) {
174
+ Log.e(TAG, exception.getMessage());
175
+ }
176
+ }
177
+
178
+ @Override
179
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
180
+ // We purposely disregard child measurements because act as a
181
+ // wrapper to a SurfaceView that centers the camera preview instead
182
+ // of stretching it.
183
+ final int width = resolveSize(getSuggestedMinimumWidth(), widthMeasureSpec);
184
+ final int height = resolveSize(getSuggestedMinimumHeight(), heightMeasureSpec);
185
+ setMeasuredDimension(width, height);
186
+
187
+ if (mSupportedPreviewSizes != null) {
188
+ mPreviewSize = getOptimalPreviewSize(mSupportedPreviewSizes, width, height);
189
+ }
190
+ }
191
+
192
+ @Override
193
+ protected void onLayout(boolean changed, int l, int t, int r, int b) {
194
+ if (changed && getChildCount() > 0) {
195
+ final View child = getChildAt(0);
196
+
197
+ int width = r - l;
198
+ int height = b - t;
199
+
200
+ int previewWidth = width;
201
+ int previewHeight = height;
202
+
203
+ if (mPreviewSize != null) {
204
+ previewWidth = mPreviewSize.width;
205
+ previewHeight = mPreviewSize.height;
206
+
207
+ if (displayOrientation == 90 || displayOrientation == 270) {
208
+ previewWidth = mPreviewSize.height;
209
+ previewHeight = mPreviewSize.width;
210
+ }
211
+ // LOG.d(TAG, "previewWidth:" + previewWidth + " previewHeight:" + previewHeight);
212
+ }
213
+
214
+ int nW;
215
+ int nH;
216
+ int top;
217
+ int left;
218
+
219
+ float scale = 1.0f;
220
+
221
+ // Center the child SurfaceView within the parent.
222
+ if (width * previewHeight < height * previewWidth) {
223
+ Log.d(TAG, "center horizontally");
224
+ int scaledChildWidth = (int) ((previewWidth * height / previewHeight) * scale);
225
+ nW = (width + scaledChildWidth) / 2;
226
+ nH = (int) (height * scale);
227
+ top = 0;
228
+ left = (width - scaledChildWidth) / 2;
229
+ } else {
230
+ Log.d(TAG, "center vertically");
231
+ int scaledChildHeight = (int) ((previewHeight * width / previewWidth) * scale);
232
+ nW = (int) (width * scale);
233
+ nH = (height + scaledChildHeight) / 2;
234
+ top = (height - scaledChildHeight) / 2;
235
+ left = 0;
236
+ }
237
+ child.layout(left, top, nW, nH);
238
+
239
+ Log.d("layout", "left:" + left);
240
+ Log.d("layout", "top:" + top);
241
+ Log.d("layout", "right:" + nW);
242
+ Log.d("layout", "bottom:" + nH);
243
+ }
244
+ }
245
+
246
+ public void surfaceCreated(SurfaceHolder holder) {
247
+ // The Surface has been created, acquire the camera and tell it where
248
+ // to draw.
249
+ try {
250
+ if (mCamera != null) {
251
+ mSurfaceView.setWillNotDraw(false);
252
+ mCamera.setPreviewDisplay(holder);
253
+ }
254
+ } catch (Exception exception) {
255
+ Log.e(TAG, "Exception caused by setPreviewDisplay()", exception);
256
+ }
257
+ }
258
+
259
+ public void surfaceDestroyed(SurfaceHolder holder) {
260
+ // Surface will be destroyed when we return, so stop the preview.
261
+ try {
262
+ if (mCamera != null) {
263
+ mCamera.stopPreview();
264
+ }
265
+ } catch (Exception exception) {
266
+ Log.e(TAG, "Exception caused by surfaceDestroyed()", exception);
267
+ }
268
+ }
269
+
270
+ private Camera.Size getOptimalPreviewSize(List<Camera.Size> sizes, int w, int h) {
271
+ final double ASPECT_TOLERANCE = 0.1;
272
+ double targetRatio = (double) w / h;
273
+ if (displayOrientation == 90 || displayOrientation == 270) {
274
+ targetRatio = (double) h / w;
275
+ }
276
+
277
+ if (sizes == null) {
278
+ return null;
279
+ }
280
+
281
+ Camera.Size optimalSize = null;
282
+ double minDiff = Double.MAX_VALUE;
283
+
284
+ int targetHeight = h;
285
+
286
+ // Try to find an size match aspect ratio and size
287
+ for (Camera.Size size : sizes) {
288
+ double ratio = (double) size.width / size.height;
289
+ if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
290
+ if (Math.abs(size.height - targetHeight) < minDiff) {
291
+ optimalSize = size;
292
+ minDiff = Math.abs(size.height - targetHeight);
293
+ }
294
+ }
295
+
296
+ // Cannot find the one match the aspect ratio, ignore the requirement
297
+ if (optimalSize == null) {
298
+ minDiff = Double.MAX_VALUE;
299
+ for (Camera.Size size : sizes) {
300
+ if (Math.abs(size.height - targetHeight) < minDiff) {
301
+ optimalSize = size;
302
+ minDiff = Math.abs(size.height - targetHeight);
303
+ }
304
+ }
305
+ }
306
+
307
+ Log.d(TAG, "optimal preview size: w: " + optimalSize.width + " h: " + optimalSize.height);
308
+ return optimalSize;
309
+ }
310
+
311
+ public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
312
+ if (mCamera != null) {
313
+ try {
314
+ // Now that the size is known, set up the camera parameters and begin
315
+ // the preview.
316
+ mSupportedPreviewSizes = mCamera.getParameters().getSupportedPreviewSizes();
317
+ if (mSupportedPreviewSizes != null) {
318
+ mPreviewSize = getOptimalPreviewSize(mSupportedPreviewSizes, w, h);
319
+ }
320
+ startCamera();
321
+ } catch (Exception exception) {
322
+ Log.e(TAG, "Exception caused by surfaceChanged()", exception);
323
+ }
324
+ }
325
+ }
326
+
327
+ private void startCamera() {
328
+ Camera.Parameters parameters = mCamera.getParameters();
329
+ parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
330
+ requestLayout();
331
+ //mCamera.setDisplayOrientation(90);
332
+ mCamera.setParameters(parameters);
333
+ mCamera.startPreview();
334
+ }
335
+
336
+ // Texture Callbacks
337
+
338
+ public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
339
+ // The Surface has been created, acquire the camera and tell it where
340
+ // to draw.
341
+ try {
342
+ mSurface = surface;
343
+ if (mSupportedPreviewSizes != null) {
344
+ mPreviewSize = getOptimalPreviewSize(mSupportedPreviewSizes, width, height);
345
+ }
346
+ if (mCamera != null) {
347
+ mTextureView.setAlpha(opacity);
348
+ mCamera.setPreviewTexture(surface);
349
+ startCamera();
350
+ }
351
+ } catch (Exception exception) {
352
+ Log.e(TAG, "Exception caused by onSurfaceTextureAvailable()", exception);
353
+ }
354
+ }
355
+
356
+ public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {}
357
+
358
+ public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
359
+ try {
360
+ if (mCamera != null) {
361
+ mCamera.stopPreview();
362
+ }
363
+ } catch (Exception exception) {
364
+ Log.e(TAG, "Exception caused by onSurfaceTextureDestroyed()", exception);
365
+ return false;
366
+ }
367
+ return true;
368
+ }
369
+
370
+ public void onSurfaceTextureUpdated(SurfaceTexture surface) {}
371
+
372
+ public void setOneShotPreviewCallback(Camera.PreviewCallback callback) {
373
+ if (mCamera != null) {
374
+ mCamera.setOneShotPreviewCallback(callback);
375
+ }
376
+ }
377
+
378
+ public void setOpacity(final float opacity) {
379
+ this.opacity = opacity;
380
+ if (mCamera != null && enableOpacity) {
381
+ mTextureView.setAlpha(opacity);
382
+ }
383
+ }
384
+ }
@@ -0,0 +1,24 @@
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
+ }
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+ xmlns:app="http://schemas.android.com/apk/res-auto"
4
+ xmlns:tools="http://schemas.android.com/tools"
5
+ android:layout_width="match_parent"
6
+ android:layout_height="match_parent"
7
+ tools:context="com.getcapacitor.BridgeActivity"
8
+ >
9
+
10
+ <WebView
11
+ android:id="@+id/webview"
12
+ android:layout_width="fill_parent"
13
+ android:layout_height="fill_parent" />
14
+
15
+ </androidx.coordinatorlayout.widget.CoordinatorLayout>
@@ -0,0 +1,68 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <FrameLayout
3
+ android:layout_width="match_parent"
4
+ android:layout_height="match_parent"
5
+ tools:context="com.ahm.capacitor.camera.preview.CameraActivity"
6
+ android:id="@+id/frame_container"
7
+ xmlns:android="http://schemas.android.com/apk/res/android"
8
+ xmlns:tools="http://schemas.android.com/tools"
9
+ android:layout_gravity="center_horizontal|top"
10
+ android:layout_weight=".7">
11
+
12
+ <RelativeLayout
13
+ android:layout_width="match_parent"
14
+ android:layout_height="match_parent"
15
+ android:gravity="center_horizontal|top"
16
+ android:id="@+id/frame_camera_cont"
17
+ android:layout_gravity="center_horizontal|top">
18
+
19
+ <FrameLayout
20
+ android:layout_width="match_parent"
21
+ android:layout_height="match_parent"
22
+ android:id="@+id/video_view"
23
+
24
+ android:scaleType="fitXY"
25
+ android:layout_gravity="top" />
26
+
27
+ <ImageView
28
+ android:layout_width="match_parent"
29
+ android:layout_height="match_parent"
30
+ android:id="@+id/picture_view"
31
+ android:layout_gravity="center|bottom"
32
+ android:adjustViewBounds="true"
33
+ android:scaleType="fitXY" />
34
+
35
+ <ImageView
36
+ android:layout_width="match_parent"
37
+ android:layout_height="match_parent"
38
+ android:id="@+id/frame_view"
39
+ android:layout_gravity="center_horizontal|bottom"
40
+ android:adjustViewBounds="true"
41
+ android:scaleType="centerInside" />
42
+
43
+ </RelativeLayout>
44
+
45
+ <FrameLayout
46
+ android:layout_width="match_parent"
47
+ android:layout_height="match_parent"
48
+ android:id="@+id/camera_loader"
49
+ android:scaleType="fitXY"
50
+ android:layout_gravity="top"
51
+ android:layout_alignWithParentIfMissing="false"
52
+ android:layout_alignParentTop="false"
53
+ android:layout_alignParentLeft="false"
54
+ android:layout_alignParentBottom="false"
55
+ android:layout_alignParentRight="false"
56
+ android:visibility="invisible"
57
+ android:background="#ff000000">
58
+
59
+ <ProgressBar
60
+ android:layout_width="wrap_content"
61
+ android:layout_height="wrap_content"
62
+ android:id="@+id/camera_loader_spinner"
63
+ android:layout_gravity="center"
64
+ android:indeterminate="false"
65
+ android:indeterminateBehavior="cycle"
66
+ android:indeterminateOnly="true"/>
67
+ </FrameLayout>
68
+ </FrameLayout>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <resources>
3
+ <item type="id" name="camera_container" />
4
+ </resources>
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <resources>
3
+ <style name="CameraPreviewTheme" parent="android:Theme.Light">
4
+ <item name="android:windowIsFloating">true</item>
5
+ <item name="android:windowCloseOnTouchOutside">false</item>
6
+ <item name="android:colorBackgroundCacheHint">@null</item>
7
+ <item name="android:backgroundDimEnabled">false</item>
8
+ </style>
9
+ </resources>
@@ -0,0 +1,3 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <resources>
3
+ </resources>
@@ -0,0 +1,3 @@
1
+ <resources>
2
+ <string name="my_string">Just a simple string</string>
3
+ </resources>
@@ -0,0 +1,3 @@
1
+ <resources>
2
+
3
+ </resources>
@@ -0,0 +1,18 @@
1
+ package com.getcapacitor;
2
+
3
+ import static org.junit.Assert.*;
4
+
5
+ import org.junit.Test;
6
+
7
+ /**
8
+ * Example local unit test, which will execute on the development machine (host).
9
+ *
10
+ * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
11
+ */
12
+ public class ExampleUnitTest {
13
+
14
+ @Test
15
+ public void addition_isCorrect() throws Exception {
16
+ assertEquals(4, 2 + 2);
17
+ }
18
+ }
@@ -0,0 +1,86 @@
1
+ import type { PermissionState } from '@capacitor/core';
2
+ export type CameraPosition = 'rear' | 'front';
3
+ export interface CameraPreviewOptions {
4
+ /** Parent element to attach the video preview element to (applicable to the web platform only) */
5
+ parent?: string;
6
+ /** Class name to add to the video preview element (applicable to the web platform only) */
7
+ className?: string;
8
+ /** The preview width in pixels, default window.screen.width */
9
+ width?: number;
10
+ /** The preview height in pixels, default window.screen.height */
11
+ height?: number;
12
+ /** The x origin, default 0 (applicable to the android and ios platforms only) */
13
+ x?: number;
14
+ /** The y origin, default 0 (applicable to the android and ios platforms only) */
15
+ y?: number;
16
+ /** Brings your html in front of your preview, default false (applicable to the android only) */
17
+ toBack?: boolean;
18
+ /** The preview bottom padding in pixes. Useful to keep the appropriate preview sizes when orientation changes (applicable to the android and ios platforms only) */
19
+ paddingBottom?: number;
20
+ /** Rotate preview when orientation changes (applicable to the ios platforms only; default value is true) */
21
+ rotateWhenOrientationChanged?: boolean;
22
+ /** Choose the camera to use 'front' or 'rear', default 'front' */
23
+ position?: CameraPosition | string;
24
+ /** Defaults to false - Capture images to a file and return the file path instead of returning base64 encoded data */
25
+ storeToFile?: boolean;
26
+ /** Defaults to false - Android Only - Disable automatic rotation of the image, and let the browser deal with it */
27
+ disableExifHeaderStripping?: boolean;
28
+ /** Defaults to false - iOS only - Activate high resolution image capture so that output images are from the highest resolution possible on the device **/
29
+ enableHighResolution?: boolean;
30
+ /** Android Only - Locks device orientation when camera is showing. */
31
+ lockAndroidOrientation?: boolean;
32
+ /** Defaults to false - Android and Web only. Set if camera preview can change opacity. */
33
+ enableOpacity?: boolean;
34
+ /** Defaults to false - Android and iOS only. Set if camera preview will support pinch to zoom. */
35
+ enableZoom?: boolean;
36
+ }
37
+ export interface CameraPreviewPictureOptions {
38
+ /** The picture height, respecting the default aspect ratio of the device - Android only */
39
+ height?: number;
40
+ /** The picture width, respecting the default aspect ratio of the device - Android only */
41
+ width?: number;
42
+ /**
43
+ * The picture quality, 0 - 100, default 85 on `iOS/Android`.
44
+ * If left undefined, the `web` implementation will export a PNG, otherwise a JPEG will be generated
45
+ */
46
+ quality?: number;
47
+ }
48
+ export interface CameraSampleOptions {
49
+ /** The picture quality, 0 - 100, default 85 */
50
+ quality?: number;
51
+ }
52
+ export type CameraPreviewFlashMode = 'off' | 'on' | 'auto' | 'red-eye' | 'torch';
53
+ export interface CameraOpacityOptions {
54
+ /** The percent opacity to set for camera view, default 1 */
55
+ opacity?: number;
56
+ }
57
+ export interface CameraPreviewPlugin {
58
+ /** Starts the camera preview instance */
59
+ start(options: CameraPreviewOptions): Promise<{}>;
60
+ /** Stops the camera preview instance */
61
+ stop(): Promise<{}>;
62
+ /** Captures a picture from the camera preview */
63
+ capture(options: CameraPreviewPictureOptions): Promise<{
64
+ value: string;
65
+ }>;
66
+ /** Captures a sample image from the video stream - Android / iOS only */
67
+ captureSample(options: CameraSampleOptions): Promise<{
68
+ value: string;
69
+ }>;
70
+ /** Get the flash modes supported by the camera device currently started */
71
+ getSupportedFlashModes(): Promise<{
72
+ result: CameraPreviewFlashMode[];
73
+ }>;
74
+ /** Set the flash mode */
75
+ setFlashMode(options: {
76
+ flashMode: CameraPreviewFlashMode | string;
77
+ }): Promise<void>;
78
+ /** Switch between rear and front camera - Android / iOS only */
79
+ flip(): Promise<void>;
80
+ /** Changes the opacity of the shown camera preview - Android / Web only */
81
+ setOpacity(options: CameraOpacityOptions): Promise<{}>;
82
+ /** Check camera permission */
83
+ checkPermissions(): Promise<PermissionState>;
84
+ /** Request camera permission */
85
+ requestPermissions(): Promise<PermissionState>;
86
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import type { CameraPreviewPlugin } from './definitions';
2
+ declare const CameraPreview: CameraPreviewPlugin;
3
+ export * from './definitions';
4
+ export { CameraPreview };
@@ -0,0 +1,7 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ const CameraPreview = registerPlugin('CameraPreview', {
3
+ web: () => import('./web').then((m) => new m.CameraPreviewWeb()),
4
+ });
5
+ export * from './definitions';
6
+ export { CameraPreview };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,aAAa,GAAG,cAAc,CAAsB,eAAe,EAAE;IACzE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;CACjE,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import type { CameraPreviewOptions, CameraPreviewPictureOptions, CameraPreviewPlugin, CameraPreviewFlashMode, CameraSampleOptions, CameraOpacityOptions } from './definitions';
3
+ export declare class CameraPreviewWeb extends WebPlugin implements CameraPreviewPlugin {
4
+ /**
5
+ * track which camera is used based on start options
6
+ * used in capture
7
+ */
8
+ private isBackCamera;
9
+ constructor();
10
+ start(options: CameraPreviewOptions): Promise<{}>;
11
+ stop(): Promise<any>;
12
+ capture(options: CameraPreviewPictureOptions): Promise<any>;
13
+ captureSample(_options: CameraSampleOptions): Promise<any>;
14
+ getSupportedFlashModes(): Promise<{
15
+ result: CameraPreviewFlashMode[];
16
+ }>;
17
+ setFlashMode(_options: {
18
+ flashMode: CameraPreviewFlashMode | string;
19
+ }): Promise<void>;
20
+ flip(): Promise<void>;
21
+ setOpacity(_options: CameraOpacityOptions): Promise<any>;
22
+ checkPermissions(): Promise<PermissionState>;
23
+ requestPermissions(): Promise<PermissionState>;
24
+ }