@capgo/camera-preview 7.4.0-beta.7 → 7.4.0-beta.8
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/README.md +62 -28
- 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/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/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +1 -1
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.gradle/file-system.probe +0 -0
- package/android/build.gradle +1 -0
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +127 -14
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraXView.java +479 -29
- package/android/src/main/java/com/ahm/capacitor/camera/preview/GridOverlayView.java +2 -0
- package/dist/docs.json +46 -7
- package/dist/esm/definitions.d.ts +42 -5
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +25 -1
- package/dist/esm/web.js +81 -9
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +81 -9
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +81 -9
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CapgoCameraPreview/CameraController.swift +95 -18
- package/ios/Sources/CapgoCameraPreview/Plugin.swift +271 -91
- package/package.json +1 -1
- package/android/.gradle/config.properties +0 -2
- package/android/.idea/AndroidProjectSystem.xml +0 -6
- package/android/.idea/caches/deviceStreaming.xml +0 -811
- package/android/.idea/compiler.xml +0 -6
- package/android/.idea/gradle.xml +0 -18
- package/android/.idea/migrations.xml +0 -10
- package/android/.idea/misc.xml +0 -10
- package/android/.idea/runConfigurations.xml +0 -17
- package/android/.idea/vcs.xml +0 -6
- package/android/.idea/workspace.xml +0 -55
- package/android/local.properties +0 -8
package/README.md
CHANGED
|
@@ -239,6 +239,8 @@ Documentation for the [uploader](https://github.com/Cap-go/capacitor-uploader)
|
|
|
239
239
|
* [`removeAllListeners()`](#removealllisteners)
|
|
240
240
|
* [`setDeviceId(...)`](#setdeviceid)
|
|
241
241
|
* [`getDeviceId()`](#getdeviceid)
|
|
242
|
+
* [`getPreviewSize()`](#getpreviewsize)
|
|
243
|
+
* [`setPreviewSize(...)`](#setpreviewsize)
|
|
242
244
|
* [Interfaces](#interfaces)
|
|
243
245
|
* [Type Aliases](#type-aliases)
|
|
244
246
|
* [Enums](#enums)
|
|
@@ -338,14 +340,16 @@ Gets the flash modes supported by the active camera.
|
|
|
338
340
|
### setAspectRatio(...)
|
|
339
341
|
|
|
340
342
|
```typescript
|
|
341
|
-
setAspectRatio(options: { aspectRatio: '4:3' | '16:9'; }) => Promise<
|
|
343
|
+
setAspectRatio(options: { aspectRatio: '4:3' | '16:9'; x?: number; y?: number; }) => Promise<{ width: number; height: number; x: number; y: number; }>
|
|
342
344
|
```
|
|
343
345
|
|
|
344
346
|
Set the aspect ratio of the camera preview.
|
|
345
347
|
|
|
346
|
-
| Param | Type
|
|
347
|
-
| ------------- |
|
|
348
|
-
| **`options`** | <code>{ aspectRatio: '4:3' \| '16:9'; }</code> | - The desired aspect ratio. |
|
|
348
|
+
| Param | Type | Description |
|
|
349
|
+
| ------------- | ---------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
350
|
+
| **`options`** | <code>{ aspectRatio: '4:3' \| '16:9'; x?: number; y?: number; }</code> | - The desired aspect ratio and optional position. - aspectRatio: The desired aspect ratio ('4:3' or '16:9') - x: Optional x coordinate for positioning. If not provided, view will be auto-centered horizontally. - y: Optional y coordinate for positioning. If not provided, view will be auto-centered vertically. |
|
|
351
|
+
|
|
352
|
+
**Returns:** <code>Promise<{ width: number; height: number; x: number; y: number; }></code>
|
|
349
353
|
|
|
350
354
|
**Since:** 7.4.0
|
|
351
355
|
|
|
@@ -631,6 +635,36 @@ Gets the ID of the currently active camera device.
|
|
|
631
635
|
--------------------
|
|
632
636
|
|
|
633
637
|
|
|
638
|
+
### getPreviewSize()
|
|
639
|
+
|
|
640
|
+
```typescript
|
|
641
|
+
getPreviewSize() => Promise<{ x: number; y: number; width: number; height: number; }>
|
|
642
|
+
```
|
|
643
|
+
|
|
644
|
+
Gets the current preview size and position.
|
|
645
|
+
|
|
646
|
+
**Returns:** <code>Promise<{ x: number; y: number; width: number; height: number; }></code>
|
|
647
|
+
|
|
648
|
+
--------------------
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
### setPreviewSize(...)
|
|
652
|
+
|
|
653
|
+
```typescript
|
|
654
|
+
setPreviewSize(options: { x: number; y: number; width: number; height: number; }) => Promise<{ width: number; height: number; x: number; y: number; }>
|
|
655
|
+
```
|
|
656
|
+
|
|
657
|
+
Sets the preview size and position.
|
|
658
|
+
|
|
659
|
+
| Param | Type | Description |
|
|
660
|
+
| ------------- | --------------------------------------------------------------------- | -------------------------------- |
|
|
661
|
+
| **`options`** | <code>{ x: number; y: number; width: number; height: number; }</code> | The new position and dimensions. |
|
|
662
|
+
|
|
663
|
+
**Returns:** <code>Promise<{ width: number; height: number; x: number; y: number; }></code>
|
|
664
|
+
|
|
665
|
+
--------------------
|
|
666
|
+
|
|
667
|
+
|
|
634
668
|
### Interfaces
|
|
635
669
|
|
|
636
670
|
|
|
@@ -638,30 +672,30 @@ Gets the ID of the currently active camera device.
|
|
|
638
672
|
|
|
639
673
|
Defines the configuration options for starting the camera preview.
|
|
640
674
|
|
|
641
|
-
| Prop | Type | Description
|
|
642
|
-
| ---------------------------------- | --------------------------------------------- |
|
|
643
|
-
| **`parent`** | <code>string</code> | The parent element to attach the video preview to.
|
|
644
|
-
| **`className`** | <code>string</code> | A CSS class name to add to the preview element.
|
|
645
|
-
| **`width`** | <code>number</code> | The width of the preview in pixels. Defaults to the screen width.
|
|
646
|
-
| **`height`** | <code>number</code> | The height of the preview in pixels. Defaults to the screen height.
|
|
647
|
-
| **`x`** | <code>number</code> | The horizontal origin of the preview, in pixels.
|
|
648
|
-
| **`y`** | <code>number</code> | The vertical origin of the preview, in pixels.
|
|
649
|
-
| **`aspectRatio`** | <code>'4:3' \| '16:9' \| 'fill'</code> | The aspect ratio of the camera preview, '4:3' or '16:9'.
|
|
650
|
-
| **`gridMode`** | <code><a href="#gridmode">GridMode</a></code> | The grid overlay to display on the camera preview.
|
|
651
|
-
| **`includeSafeAreaInsets`** | <code>boolean</code> | Adjusts the y-position to account for safe areas (e.g., notches).
|
|
652
|
-
| **`toBack`** | <code>boolean</code> | If true, places the preview behind the webview.
|
|
653
|
-
| **`paddingBottom`** | <code>number</code> | Bottom padding for the preview, in pixels.
|
|
654
|
-
| **`rotateWhenOrientationChanged`** | <code>boolean</code> | Whether to rotate the preview when the device orientation changes.
|
|
655
|
-
| **`position`** | <code>string</code> | The camera to use.
|
|
656
|
-
| **`storeToFile`** | <code>boolean</code> | If true, saves the captured image to a file and returns the file path. If false, returns a base64 encoded string.
|
|
657
|
-
| **`disableExifHeaderStripping`** | <code>boolean</code> | If true, prevents the plugin from rotating the image based on EXIF data.
|
|
658
|
-
| **`enableHighResolution`** | <code>boolean</code> | If true, enables high-resolution image capture.
|
|
659
|
-
| **`disableAudio`** | <code>boolean</code> | If true, disables the audio stream, preventing audio permission requests.
|
|
660
|
-
| **`lockAndroidOrientation`** | <code>boolean</code> | If true, locks the device orientation while the camera is active.
|
|
661
|
-
| **`enableOpacity`** | <code>boolean</code> | If true, allows the camera preview's opacity to be changed.
|
|
662
|
-
| **`enableZoom`** | <code>boolean</code> | If true, enables pinch-to-zoom functionality on the preview.
|
|
663
|
-
| **`enableVideoMode`** | <code>boolean</code> | If true, uses the video-optimized preset for the camera session.
|
|
664
|
-
| **`deviceId`** | <code>string</code> | The `deviceId` of the camera to use. If provided, `position` is ignored.
|
|
675
|
+
| Prop | Type | Description | Default | Since |
|
|
676
|
+
| ---------------------------------- | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- | ----- |
|
|
677
|
+
| **`parent`** | <code>string</code> | The parent element to attach the video preview to. | | |
|
|
678
|
+
| **`className`** | <code>string</code> | A CSS class name to add to the preview element. | | |
|
|
679
|
+
| **`width`** | <code>number</code> | The width of the preview in pixels. Defaults to the screen width. | | |
|
|
680
|
+
| **`height`** | <code>number</code> | The height of the preview in pixels. Defaults to the screen height. | | |
|
|
681
|
+
| **`x`** | <code>number</code> | The horizontal origin of the preview, in pixels. | | |
|
|
682
|
+
| **`y`** | <code>number</code> | The vertical origin of the preview, in pixels. | | |
|
|
683
|
+
| **`aspectRatio`** | <code>'4:3' \| '16:9' \| 'fill'</code> | The aspect ratio of the camera preview, '4:3' or '16:9' or 'fill'. Cannot be set if width or height is provided, otherwise the call will be rejected. Use setPreviewSize to adjust size after starting. | | 2.0.0 |
|
|
684
|
+
| **`gridMode`** | <code><a href="#gridmode">GridMode</a></code> | The grid overlay to display on the camera preview. | <code>"none"</code> | 2.1.0 |
|
|
685
|
+
| **`includeSafeAreaInsets`** | <code>boolean</code> | Adjusts the y-position to account for safe areas (e.g., notches). | <code>false</code> | |
|
|
686
|
+
| **`toBack`** | <code>boolean</code> | If true, places the preview behind the webview. | <code>true</code> | |
|
|
687
|
+
| **`paddingBottom`** | <code>number</code> | Bottom padding for the preview, in pixels. | | |
|
|
688
|
+
| **`rotateWhenOrientationChanged`** | <code>boolean</code> | Whether to rotate the preview when the device orientation changes. | <code>true</code> | |
|
|
689
|
+
| **`position`** | <code>string</code> | The camera to use. | <code>"rear"</code> | |
|
|
690
|
+
| **`storeToFile`** | <code>boolean</code> | If true, saves the captured image to a file and returns the file path. If false, returns a base64 encoded string. | <code>false</code> | |
|
|
691
|
+
| **`disableExifHeaderStripping`** | <code>boolean</code> | If true, prevents the plugin from rotating the image based on EXIF data. | <code>false</code> | |
|
|
692
|
+
| **`enableHighResolution`** | <code>boolean</code> | If true, enables high-resolution image capture. | <code>false</code> | |
|
|
693
|
+
| **`disableAudio`** | <code>boolean</code> | If true, disables the audio stream, preventing audio permission requests. | <code>true</code> | |
|
|
694
|
+
| **`lockAndroidOrientation`** | <code>boolean</code> | If true, locks the device orientation while the camera is active. | <code>false</code> | |
|
|
695
|
+
| **`enableOpacity`** | <code>boolean</code> | If true, allows the camera preview's opacity to be changed. | <code>false</code> | |
|
|
696
|
+
| **`enableZoom`** | <code>boolean</code> | If true, enables pinch-to-zoom functionality on the preview. | <code>false</code> | |
|
|
697
|
+
| **`enableVideoMode`** | <code>boolean</code> | If true, uses the video-optimized preset for the camera session. | <code>false</code> | |
|
|
698
|
+
| **`deviceId`** | <code>string</code> | The `deviceId` of the camera to use. If provided, `position` is ignored. | | |
|
|
665
699
|
|
|
666
700
|
|
|
667
701
|
#### ExifData
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#
|
|
1
|
+
#Mon Jun 30 22:10:14 EEST 2025
|
|
2
2
|
gradle.version=8.14.2
|
|
Binary file
|
|
Binary file
|
package/android/build.gradle
CHANGED
|
@@ -50,6 +50,7 @@ dependencies {
|
|
|
50
50
|
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
51
51
|
implementation 'androidx.exifinterface:exifinterface:1.4.1'
|
|
52
52
|
implementation 'com.google.android.gms:play-services-location:21.3.0'
|
|
53
|
+
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.3.0'
|
|
53
54
|
|
|
54
55
|
// CameraX dependencies
|
|
55
56
|
def camerax_version = "1.5.0-beta01"
|
|
@@ -6,7 +6,6 @@ import static android.Manifest.permission.RECORD_AUDIO;
|
|
|
6
6
|
import android.Manifest;
|
|
7
7
|
import android.content.pm.ActivityInfo;
|
|
8
8
|
import android.util.DisplayMetrics;
|
|
9
|
-
import android.util.TypedValue;
|
|
10
9
|
import com.getcapacitor.JSArray;
|
|
11
10
|
import com.getcapacitor.JSObject;
|
|
12
11
|
import com.getcapacitor.PermissionState;
|
|
@@ -28,6 +27,8 @@ import com.google.android.gms.location.FusedLocationProviderClient;
|
|
|
28
27
|
import com.google.android.gms.location.LocationServices;
|
|
29
28
|
import org.json.JSONObject;
|
|
30
29
|
import android.location.Location;
|
|
30
|
+
import android.view.ViewGroup;
|
|
31
|
+
|
|
31
32
|
import com.getcapacitor.Logger;
|
|
32
33
|
|
|
33
34
|
|
|
@@ -392,6 +393,12 @@ public class CameraPreview
|
|
|
392
393
|
final boolean disableAudio = Boolean.TRUE.equals(call.getBoolean("disableAudio", true));
|
|
393
394
|
final String aspectRatio = call.getString("aspectRatio", "4:3");
|
|
394
395
|
final String gridMode = call.getString("gridMode", "none");
|
|
396
|
+
|
|
397
|
+
// Check for conflict between aspectRatio and size
|
|
398
|
+
if (call.getData().has("aspectRatio") && (call.getData().has("width") || call.getData().has("height"))) {
|
|
399
|
+
call.reject("Cannot set both aspectRatio and size (width/height). Use setPreviewSize after start.");
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
395
402
|
|
|
396
403
|
float targetZoom = 1.0f;
|
|
397
404
|
// Check if the selected device is a physical ultra-wide
|
|
@@ -424,11 +431,46 @@ public class CameraPreview
|
|
|
424
431
|
if (lockOrientation) {
|
|
425
432
|
getBridge().getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
|
|
426
433
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
434
|
+
|
|
435
|
+
// Debug: Let's check all the positioning information
|
|
436
|
+
ViewGroup webViewParent = (ViewGroup) getBridge().getWebView().getParent();
|
|
437
|
+
|
|
438
|
+
// Get webview position in different coordinate systems
|
|
439
|
+
int[] webViewLocationInWindow = new int[2];
|
|
440
|
+
int[] webViewLocationOnScreen = new int[2];
|
|
441
|
+
getBridge().getWebView().getLocationInWindow(webViewLocationInWindow);
|
|
442
|
+
getBridge().getWebView().getLocationOnScreen(webViewLocationOnScreen);
|
|
443
|
+
|
|
444
|
+
int webViewLeft = getBridge().getWebView().getLeft();
|
|
445
|
+
int webViewTop = getBridge().getWebView().getTop();
|
|
446
|
+
|
|
447
|
+
// Check parent position too
|
|
448
|
+
int[] parentLocationInWindow = new int[2];
|
|
449
|
+
int[] parentLocationOnScreen = new int[2];
|
|
450
|
+
webViewParent.getLocationInWindow(parentLocationInWindow);
|
|
451
|
+
webViewParent.getLocationOnScreen(parentLocationOnScreen);
|
|
452
|
+
|
|
453
|
+
// Calculate pixel ratio
|
|
454
|
+
float pixelRatio = metrics.density;
|
|
455
|
+
|
|
456
|
+
// Try using just the pixel ratio without any webview offset for now
|
|
457
|
+
int computedX = (int) (x * pixelRatio);
|
|
458
|
+
int computedY = (int) (y * pixelRatio);
|
|
459
|
+
|
|
460
|
+
Log.d("CameraPreview", "=== COORDINATE DEBUG ===");
|
|
461
|
+
Log.d("CameraPreview", "WebView getLeft/getTop: (" + webViewLeft + ", " + webViewTop + ")");
|
|
462
|
+
Log.d("CameraPreview", "WebView locationInWindow: (" + webViewLocationInWindow[0] + ", " + webViewLocationInWindow[1] + ")");
|
|
463
|
+
Log.d("CameraPreview", "WebView locationOnScreen: (" + webViewLocationOnScreen[0] + ", " + webViewLocationOnScreen[1] + ")");
|
|
464
|
+
Log.d("CameraPreview", "Parent locationInWindow: (" + parentLocationInWindow[0] + ", " + parentLocationInWindow[1] + ")");
|
|
465
|
+
Log.d("CameraPreview", "Parent locationOnScreen: (" + parentLocationOnScreen[0] + ", " + parentLocationOnScreen[1] + ")");
|
|
466
|
+
Log.d("CameraPreview", "Parent class: " + webViewParent.getClass().getSimpleName());
|
|
467
|
+
Log.d("CameraPreview", "Requested position (logical): (" + x + ", " + y + ")");
|
|
468
|
+
Log.d("CameraPreview", "Pixel ratio: " + pixelRatio);
|
|
469
|
+
Log.d("CameraPreview", "Final computed position (no offset): (" + computedX + ", " + computedY + ")");
|
|
470
|
+
Log.d("CameraPreview", "========================");
|
|
471
|
+
int computedWidth = width != 0 ? (int) (width * pixelRatio) : getBridge().getWebView().getWidth();
|
|
472
|
+
int computedHeight = height != 0 ? (int) (height * pixelRatio) : getBridge().getWebView().getHeight();
|
|
473
|
+
computedHeight -= (int) (paddingBottom * pixelRatio);
|
|
432
474
|
|
|
433
475
|
CameraSessionConfiguration config = new CameraSessionConfiguration(finalDeviceId, position, computedX, computedY, computedWidth, computedHeight, paddingBottom, toBack, storeToFile, enableOpacity, enableZoom, disableExifHeaderStripping, disableAudio, 1.0f, aspectRatio, gridMode);
|
|
434
476
|
config.setTargetZoom(finalTargetZoom);
|
|
@@ -469,11 +511,15 @@ public class CameraPreview
|
|
|
469
511
|
public void onCameraStarted(int width, int height, int x, int y) {
|
|
470
512
|
PluginCall call = bridge.getSavedCall(cameraStartCallbackId);
|
|
471
513
|
if (call != null) {
|
|
514
|
+
// Convert pixel values back to logical units
|
|
515
|
+
DisplayMetrics metrics = getBridge().getActivity().getResources().getDisplayMetrics();
|
|
516
|
+
float pixelRatio = metrics.density;
|
|
517
|
+
|
|
472
518
|
JSObject result = new JSObject();
|
|
473
|
-
result.put("width", width);
|
|
474
|
-
result.put("height", height);
|
|
475
|
-
result.put("x", x);
|
|
476
|
-
result.put("y", y);
|
|
519
|
+
result.put("width", width / pixelRatio);
|
|
520
|
+
result.put("height", height / pixelRatio);
|
|
521
|
+
result.put("x", x / pixelRatio);
|
|
522
|
+
result.put("y", y / pixelRatio);
|
|
477
523
|
call.resolve(result);
|
|
478
524
|
bridge.releaseCall(call);
|
|
479
525
|
cameraStartCallbackId = null; // Prevent re-use
|
|
@@ -509,8 +555,21 @@ public class CameraPreview
|
|
|
509
555
|
return;
|
|
510
556
|
}
|
|
511
557
|
String aspectRatio = call.getString("aspectRatio", "4:3");
|
|
512
|
-
|
|
513
|
-
call.
|
|
558
|
+
Float x = call.getFloat("x");
|
|
559
|
+
Float y = call.getFloat("y");
|
|
560
|
+
|
|
561
|
+
getActivity().runOnUiThread(() -> {
|
|
562
|
+
cameraXView.setAspectRatio(aspectRatio, x, y, () -> {
|
|
563
|
+
// Return the actual preview bounds after layout and camera operations are complete
|
|
564
|
+
int[] bounds = cameraXView.getCurrentPreviewBounds();
|
|
565
|
+
JSObject ret = new JSObject();
|
|
566
|
+
ret.put("x", bounds[0]);
|
|
567
|
+
ret.put("y", bounds[1]);
|
|
568
|
+
ret.put("width", bounds[2]);
|
|
569
|
+
ret.put("height", bounds[3]);
|
|
570
|
+
call.resolve(ret);
|
|
571
|
+
});
|
|
572
|
+
});
|
|
514
573
|
}
|
|
515
574
|
|
|
516
575
|
@PluginMethod
|
|
@@ -532,8 +591,10 @@ public class CameraPreview
|
|
|
532
591
|
return;
|
|
533
592
|
}
|
|
534
593
|
String gridMode = call.getString("gridMode", "none");
|
|
535
|
-
|
|
536
|
-
|
|
594
|
+
getActivity().runOnUiThread(() -> {
|
|
595
|
+
cameraXView.setGridMode(gridMode);
|
|
596
|
+
call.resolve();
|
|
597
|
+
});
|
|
537
598
|
}
|
|
538
599
|
|
|
539
600
|
@PluginMethod
|
|
@@ -546,4 +607,56 @@ public class CameraPreview
|
|
|
546
607
|
ret.put("gridMode", cameraXView.getGridMode());
|
|
547
608
|
call.resolve(ret);
|
|
548
609
|
}
|
|
610
|
+
|
|
611
|
+
@PluginMethod
|
|
612
|
+
public void getPreviewSize(PluginCall call) {
|
|
613
|
+
if (cameraXView == null || !cameraXView.isRunning()) {
|
|
614
|
+
call.reject("Camera is not running");
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// Convert pixel values back to logical units
|
|
619
|
+
DisplayMetrics metrics = getBridge().getActivity().getResources().getDisplayMetrics();
|
|
620
|
+
float pixelRatio = metrics.density;
|
|
621
|
+
|
|
622
|
+
JSObject ret = new JSObject();
|
|
623
|
+
ret.put("x", cameraXView.getPreviewX() / pixelRatio);
|
|
624
|
+
ret.put("y", cameraXView.getPreviewY() / pixelRatio);
|
|
625
|
+
ret.put("width", cameraXView.getPreviewWidth() / pixelRatio);
|
|
626
|
+
ret.put("height", cameraXView.getPreviewHeight() / pixelRatio);
|
|
627
|
+
call.resolve(ret);
|
|
628
|
+
}
|
|
629
|
+
@PluginMethod
|
|
630
|
+
public void setPreviewSize(PluginCall call) {
|
|
631
|
+
if (cameraXView == null || !cameraXView.isRunning()) {
|
|
632
|
+
call.reject("Camera is not running");
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// Get values from call - null values will become 0
|
|
637
|
+
Integer xParam = call.getInt("x");
|
|
638
|
+
Integer yParam = call.getInt("y");
|
|
639
|
+
Integer widthParam = call.getInt("width");
|
|
640
|
+
Integer heightParam = call.getInt("height");
|
|
641
|
+
|
|
642
|
+
// Apply pixel ratio conversion to non-null values
|
|
643
|
+
DisplayMetrics metrics = getBridge().getActivity().getResources().getDisplayMetrics();
|
|
644
|
+
float pixelRatio = metrics.density;
|
|
645
|
+
|
|
646
|
+
int x = (xParam != null && xParam > 0) ? (int) (xParam * pixelRatio) : 0;
|
|
647
|
+
int y = (yParam != null && yParam > 0) ? (int) (yParam * pixelRatio) : 0;
|
|
648
|
+
int width = (widthParam != null && widthParam > 0) ? (int) (widthParam * pixelRatio) : 0;
|
|
649
|
+
int height = (heightParam != null && heightParam > 0) ? (int) (heightParam * pixelRatio) : 0;
|
|
650
|
+
|
|
651
|
+
cameraXView.setPreviewSize(x, y, width, height, () -> {
|
|
652
|
+
// Return the actual preview bounds after layout operations are complete
|
|
653
|
+
int[] bounds = cameraXView.getCurrentPreviewBounds();
|
|
654
|
+
JSObject ret = new JSObject();
|
|
655
|
+
ret.put("x", bounds[0]);
|
|
656
|
+
ret.put("y", bounds[1]);
|
|
657
|
+
ret.put("width", bounds[2]);
|
|
658
|
+
ret.put("height", bounds[3]);
|
|
659
|
+
call.resolve(ret);
|
|
660
|
+
});
|
|
661
|
+
}
|
|
549
662
|
}
|