Skip to content

Commit

Permalink
chore: Run fmt command (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Jun 8, 2023
1 parent 1c18015 commit 2003f75
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import static org.junit.Assert.*;

import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import org.junit.Test;
import org.junit.runner.RunWith;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,16 @@ public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

final FrameLayout frameContainerLayout = (FrameLayout) view.findViewById(
getResources().getIdentifier("frame_container", "id", appResourcesPackage)
getResources().getIdentifier("frame_container", "id", appResourcesPackage)
);

final int previousOrientation = frameContainerLayout.getHeight() > frameContainerLayout.getWidth() ? Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
final int previousOrientation = frameContainerLayout.getHeight() > frameContainerLayout.getWidth()
? Configuration.ORIENTATION_PORTRAIT
: Configuration.ORIENTATION_LANDSCAPE;
// Checks if the orientation of the screen has changed
if (newConfig.orientation != previousOrientation) {

final RelativeLayout frameCamContainerLayout = (RelativeLayout) view.findViewById(
getResources().getIdentifier("frame_camera_cont", "id", appResourcesPackage)
getResources().getIdentifier("frame_camera_cont", "id", appResourcesPackage)
);

frameContainerLayout.getLayoutParams().width = frameCamContainerLayout.getHeight();
Expand All @@ -419,12 +420,9 @@ public void onConfigurationChanged(Configuration newConfig) {
frameCamContainerLayout.forceLayout();

mPreview.setCameraDisplayOrientation();

}

}


public Camera getCamera() {
return mCamera;
}
Expand Down
2 changes: 1 addition & 1 deletion ios/Plugin/CameraController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ extension CameraController: AVCapturePhotoCaptureDelegate {
public func photoOutput(_ captureOutput: AVCapturePhotoOutput, didFinishProcessingPhoto photoSampleBuffer: CMSampleBuffer?, previewPhoto previewPhotoSampleBuffer: CMSampleBuffer?,
resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Swift.Error?) {
if let error = error { self.photoCaptureCompletionBlock?(nil, error) } else if let buffer = photoSampleBuffer, let data = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: buffer, previewPhotoSampleBuffer: nil),
let image = UIImage(data: data) {
let image = UIImage(data: data) {
self.photoCaptureCompletionBlock?(image.fixedOrientation(), nil)
} else {
self.photoCaptureCompletionBlock?(nil, CameraControllerError.unknown)
Expand Down
10 changes: 5 additions & 5 deletions ios/Plugin/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public class CameraPreview: CAPPlugin {
var disableAudio: Bool = false

@objc func rotated() {
let height = self.paddingBottom != nil ? self.height! - self.paddingBottom!: self.height!;
let height = self.paddingBottom != nil ? self.height! - self.paddingBottom!: self.height!

if UIApplication.shared.statusBarOrientation.isLandscape {
self.previewView.frame = CGRect(x: self.y!, y: self.x!, width: max(height, self.width!), height: min(height, self.width!))
self.cameraController.previewLayer?.frame = self.previewView.frame
}

if UIApplication.shared.statusBarOrientation.isPortrait {
if (self.previewView != nil && self.x != nil && self.y != nil && self.width != nil && self.height != nil) {
if self.previewView != nil && self.x != nil && self.y != nil && self.width != nil && self.height != nil {
self.previewView.frame = CGRect(x: self.x!, y: self.y!, width: min(height, self.width!), height: max(height, self.width!))
}
self.cameraController.previewLayer?.frame = self.previewView.frame
Expand Down Expand Up @@ -67,7 +67,7 @@ public class CameraPreview: CAPPlugin {
self.storeToFile = call.getBool("storeToFile") ?? false
self.enableZoom = call.getBool("enableZoom") ?? false
self.disableAudio = call.getBool("disableAudio") ?? false

AVCaptureDevice.requestAccess(for: .video, completionHandler: { (granted: Bool) in
guard granted else {
call.reject("permission failed")
Expand All @@ -78,7 +78,7 @@ public class CameraPreview: CAPPlugin {
if self.cameraController.captureSession?.isRunning ?? false {
call.reject("camera already started")
} else {
self.cameraController.prepare(cameraPosition: self.cameraPosition, disableAudio: self.disableAudio){error in
self.cameraController.prepare(cameraPosition: self.cameraPosition, disableAudio: self.disableAudio) {error in
if let error = error {
print(error)
call.reject(error.localizedDescription)
Expand Down Expand Up @@ -235,7 +235,7 @@ public class CameraPreview: CAPPlugin {
do {
var flashModeAsEnum: AVCaptureDevice.FlashMode?
switch flashMode {
case "off" :
case "off":
flashModeAsEnum = AVCaptureDevice.FlashMode.off
case "on":
flashModeAsEnum = AVCaptureDevice.FlashMode.on
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ export default {
},
],
external: ['@capacitor/core'],
};
};
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { registerPlugin } from '@capacitor/core';
import { CameraPreviewPlugin } from './definitions';

import type { CameraPreviewPlugin } from './definitions';

const CameraPreview = registerPlugin<CameraPreviewPlugin>('CameraPreview', {
web: () => import('./web').then((m) => new m.CameraPreviewWeb()),
Expand Down
19 changes: 11 additions & 8 deletions src/web.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { WebPlugin } from '@capacitor/core';
import {

import type {
CameraPreviewOptions,
CameraPreviewPictureOptions,
CameraPreviewPlugin,
Expand Down Expand Up @@ -27,7 +28,7 @@ export class CameraPreviewWeb extends WebPlugin implements CameraPreviewPlugin {
await navigator.mediaDevices
.getUserMedia({
audio: !options.disableAudio,
video: true
video: true,
})
.then((stream: MediaStream) => {
// Stop any existing stream so we can request media with different constraints based on user input
Expand Down Expand Up @@ -68,8 +69,8 @@ export class CameraPreviewWeb extends WebPlugin implements CameraPreviewPlugin {
const constraints: MediaStreamConstraints = {
video: {
width: { ideal: options.width },
height: { ideal: options.height }
}
height: { ideal: options.height },
},
};

if (options.position === 'rear') {
Expand Down Expand Up @@ -105,8 +106,8 @@ export class CameraPreviewWeb extends WebPlugin implements CameraPreviewPlugin {
const st: any = video.srcObject;
const tracks = st.getTracks();

for (var i = 0; i < tracks.length; i++) {
var track = tracks[i];
for (let i = 0; i < tracks.length; i++) {
const track = tracks[i];
track.stop();
}
video.remove();
Expand Down Expand Up @@ -134,7 +135,9 @@ export class CameraPreviewWeb extends WebPlugin implements CameraPreviewPlugin {
let base64EncodedImage;

if (options.quality != undefined) {
base64EncodedImage = canvas.toDataURL('image/jpeg', options.quality / 100.0).replace('data:image/jpeg;base64,', '');
base64EncodedImage = canvas
.toDataURL('image/jpeg', options.quality / 100.0)
.replace('data:image/jpeg;base64,', '');
} else {
base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');
}
Expand Down Expand Up @@ -169,4 +172,4 @@ export class CameraPreviewWeb extends WebPlugin implements CameraPreviewPlugin {
video.style.setProperty('opacity', _options['opacity'].toString());
}
}
}
}

0 comments on commit 2003f75

Please sign in to comment.