Skip to content

Commit

Permalink
Merge pull request #82 from spoonconsulting/change-wide-angle-paramet…
Browse files Browse the repository at this point in the history
…ers-value

use wide instead ultra-wide-angle
  • Loading branch information
parveshneedhoo authored Jul 17, 2024
2 parents 95cc0dc + 503561c commit 7750113
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [2.0.23](https://github.com/spoonconsulting/cordova-plugin-simple-camera-preview/compare/v2.0.22...v2.0.23) (2024-07-17)
* **Android:** Use parameter lens with values wide or default
* **iOS:** Use parameter lens with values wide or default

## [2.0.22](https://github.com/spoonconsulting/cordova-plugin-simple-camera-preview/compare/v2.0.21...v2.0.22) (2024-07-12)
* **iOS:** Release memory when exiting capture preview

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,22 @@ SimpleCameraPreview.deviceHasUltraWideCamera(size, (value: boolean) => {

### switchCameraTo(option, successCallback, errorCallback)

Switch camera between ultra-wide or default
Switch camera between wide or auto

The variable captureDevice can take two values:
The variable lens can take two values:
```javascript
"ultra-wide-angle"
"wide"

or

"default"
"auto"
```
<br>

```javascript

const params = {
captureDevice: "ultra-wide-angle",
lens: "wide",
}

SimpleCameraPreview.switchCameraTo(
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@spoonconsulting/cordova-plugin-simple-camera-preview",
"version": "2.0.22",
"version": "2.0.23",
"description": "Cordova plugin that allows camera interaction from HTML code for showing camera preview below or on top of the HTML.",
"keywords": [
"cordova",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<plugin id="@spoonconsulting/cordova-plugin-simple-camera-preview" version="2.0.22" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<plugin id="@spoonconsulting/cordova-plugin-simple-camera-preview" version="2.0.23" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">

<name>cordova-plugin-simple-camera-preview</name>
<description>Cordova plugin that allows camera interaction from HTML code. Show camera preview popup on top of the HTML.</description>
Expand Down
10 changes: 5 additions & 5 deletions src/android/CameraPreviewFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class CameraPreviewFragment extends Fragment {

private static float ratio = (4 / (float) 3);
private static final String TAG = "SimpleCameraPreview";
private String captureDevice;
private String lens;

public CameraPreviewFragment() {

Expand All @@ -100,7 +100,7 @@ public CameraPreviewFragment(int cameraDirection, CameraStartedCallback cameraSt
e.printStackTrace();
}
try {
this.captureDevice = options.getString("captureDevice");
this.lens = options.getString("lens");
} catch (JSONException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -136,7 +136,7 @@ public void startCamera() {
startCameraCallback.onCameraStarted(new Exception("Unable to start camera"));
return;
}
setUpCamera(captureDevice,cameraProvider);
setUpCamera(lens,cameraProvider);

preview.setSurfaceProvider(viewFinder.getSurfaceProvider());

Expand Down Expand Up @@ -359,9 +359,9 @@ public void switchCameraTo(String device, CameraSwitchedCallback cameraSwitchedC
}

@SuppressLint("RestrictedApi")
public void setUpCamera(String captureDevice, ProcessCameraProvider cameraProvider) {
public void setUpCamera(String lens, ProcessCameraProvider cameraProvider) {
CameraSelector cameraSelector;
if (captureDevice != null && captureDevice.equals("ultra-wide-angle")) {
if (lens != null && lens.equals("wide")) {
cameraSelector = new CameraSelector.Builder()
.addCameraFilter(cameraInfos -> {
List<Camera2CameraInfoImpl> backCameras = new ArrayList<>();
Expand Down
8 changes: 4 additions & 4 deletions src/android/SimpleCameraPreview.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ private boolean enable(JSONObject options, CallbackContext callbackContext) {
e.printStackTrace();
}

String captureDevice = "default";
String lens = "default";
try {
if (options.getString("captureDevice") != null && !options.getString("captureDevice").equals("null")) {
captureDevice = options.getString("captureDevice");
if (options.getString("lens") != null && !options.getString("lens").equals("null")) {
lens = options.getString("lens");
}
} catch (JSONException | NumberFormatException e) {
e.printStackTrace();
Expand All @@ -169,7 +169,7 @@ private boolean enable(JSONObject options, CallbackContext callbackContext) {
}

try {
cameraPreviewOptions.put("captureDevice", captureDevice);
cameraPreviewOptions.put("lens", lens);
} catch (JSONException e) {
e.printStackTrace();
}
Expand Down
4 changes: 2 additions & 2 deletions src/ios/CameraSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ - (void) setupSession:(NSString *)defaultCamera completion:(void(^)(BOOL started

AVCaptureDevice *videoDevice;
videoDevice = [self cameraWithPosition:self.defaultCamera captureDeviceType:AVCaptureDeviceTypeBuiltInWideAngleCamera];
if ([options[@"captureDevice"] isEqual:@"ultra-wide-angle"] && [self deviceHasUltraWideCamera]) {
if ([options[@"lens"] isEqual:@"wide"] && [self deviceHasUltraWideCamera]) {
if (@available(iOS 13.0, *)) {
videoDevice = [self cameraWithPosition:self.defaultCamera captureDeviceType:AVCaptureDeviceTypeBuiltInUltraWideCamera];
}
Expand Down Expand Up @@ -185,7 +185,7 @@ - (void)switchCameraTo:(NSString*)cameraMode completion:(void (^)(BOOL success))
BOOL cameraSwitched = FALSE;
if (@available(iOS 13.0, *)) {
AVCaptureDevice *ultraWideCamera;
if([cameraMode isEqualToString:@"ultra-wide-angle"]) {
if([cameraMode isEqualToString:@"wide"]) {
ultraWideCamera = [self cameraWithPosition:self.defaultCamera captureDeviceType:AVCaptureDeviceTypeBuiltInUltraWideCamera];
} else {
ultraWideCamera = [self cameraWithPosition:self.defaultCamera captureDeviceType:AVCaptureDeviceTypeBuiltInWideAngleCamera];
Expand Down
4 changes: 2 additions & 2 deletions src/ios/SimpleCameraPreview.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ - (void) enable:(CDVInvokedUrlCommand*)command {
NSInteger targetSize = ((NSNumber*)config[@"targetSize"]).intValue;
[setupSessionOptions setValue:[NSNumber numberWithInteger:targetSize] forKey:@"targetSize"];
}
NSString *captureDevice = config[@"captureDevice"];
NSString *captureDevice = config[@"lens"];
if (captureDevice && [captureDevice length] > 0) {
[setupSessionOptions setValue:captureDevice forKey:@"captureDevice"];
[setupSessionOptions setValue:captureDevice forKey:@"lens"];
}
} @catch(NSException *exception) {
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"targetSize not well defined"] callbackId:command.callbackId];
Expand Down
4 changes: 2 additions & 2 deletions www/SimpleCameraPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ SimpleCameraPreview.torchSwitch = function (options, onSuccess, onError) {

SimpleCameraPreview.switchCameraTo = function (options, onSuccess, onError) {
options = options || {};
options.captureDevice = options.captureDevice || "default";
exec(onSuccess, onError, PLUGIN_NAME, "switchCameraTo", [options.captureDevice]);
options.lens = options.lens || "default";
exec(onSuccess, onError, PLUGIN_NAME, "switchCameraTo", [options.lens]);
};

SimpleCameraPreview.deviceHasFlash = function (onSuccess, onError) {
Expand Down

0 comments on commit 7750113

Please sign in to comment.