From a37caf07604b9964c9edfd53d30b5115006cb661 Mon Sep 17 00:00:00 2001 From: Mattia Iavarone Date: Sat, 3 Mar 2018 15:28:12 +0100 Subject: [PATCH] Rename SessionType to Mode. takePicture fails when Mode == VIDEO --- MIGRATION.md | 5 + README.md | 14 +- .../cameraview/CameraOptions1Test.java | 6 +- .../cameraview/CameraViewCallbacksTest.java | 4 +- .../cameraview/CameraViewTest.java | 14 +- .../cameraview/IntegrationTest.java | 36 ++-- .../cameraview/MockCameraController.java | 4 +- .../com/otaliastudios/cameraview/Camera1.java | 161 +++++++++--------- .../com/otaliastudios/cameraview/Camera2.java | 2 +- .../cameraview/CameraController.java | 10 +- .../cameraview/CameraOptions.java | 15 +- .../otaliastudios/cameraview/CameraView.java | 55 +++--- .../com/otaliastudios/cameraview/Mode.java | 54 ++++++ .../otaliastudios/cameraview/SessionType.java | 56 ------ cameraview/src/main/res/values/attrs.xml | 2 +- .../cameraview/demo/CameraActivity.java | 4 +- .../cameraview/demo/Control.java | 11 +- demo/src/main/res/layout/activity_camera.xml | 2 +- 18 files changed, 225 insertions(+), 230 deletions(-) create mode 100644 cameraview/src/main/options/com/otaliastudios/cameraview/Mode.java delete mode 100644 cameraview/src/main/options/com/otaliastudios/cameraview/SessionType.java diff --git a/MIGRATION.md b/MIGRATION.md index fb301345..da0a4175 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -17,3 +17,8 @@ - onPictureTaken(): now passing a PictureResult. Use PictureResult.getJpeg() to access the jpeg stream. - CameraUtils.BitmapCallback: has been moved in a separate BitmapCallback class. - isCapturingVideo(): renamed to isTakingVideo(). +- SessionType: renamed to Mode. This means that setSessionType() and cameraSessionType are renamed to + setMode() and cameraMode. +- CameraOptions.isVideoSnapshotSupported(): removed, this would be ambiguous now. While in video + mode, you can only use takePictureSnapshot(), not takePicture(). +- takePicture(): will now throw an exception if called when Mode == Mode.VIDEO. You can only take snapshots. \ No newline at end of file diff --git a/README.md b/README.md index 049d6846..d6cb665c 100644 --- a/README.md +++ b/README.md @@ -410,8 +410,8 @@ Most camera parameters can be controlled through XML attributes or linked method app:cameraFacing="back" app:cameraFlash="off" app:cameraGrid="off" - app:cameraSessionType="picture" app:cameraVideoQuality="max480p" + app:cameraMode="picture" app:cameraVideoCodec="deviceDefault" app:cameraWhiteBalance="auto" app:cameraHdr="off" @@ -423,7 +423,7 @@ Most camera parameters can be controlled through XML attributes or linked method |XML Attribute|Method|Values|Default Value| |-------------|------|------|-------------| -|[`cameraSessionType`](#camerasessiontype)|`setSessionType()`|`picture` `video`|`picture`| +|[`cameraMode`](#cameramode)|`setMode()`|`picture` `video`|`picture`| |[`cameraFacing`](#camerafacing)|`setFacing()`|`back` `front`|`back`| |[`cameraFlash`](#cameraflash)|`setFlash()`|`off` `on` `auto` `torch`|`off`| |[`cameraGrid`](#cameragrid)|`setGrid()`|`off` `draw3x3` `draw4x4` `drawPhi`|`off`| @@ -436,21 +436,21 @@ Most camera parameters can be controlled through XML attributes or linked method |[`cameraVideoMaxSize`](#cameravideomaxsize)|`setVideoMaxSize()`|number|`0`| |[`cameraVideoMaxDuration`](#cameravideomaxduration)|`setVideoMaxDuration()`|number|`0`| -#### cameraSessionType +#### cameraMode What to capture - either picture or video. This has a couple of consequences: - Sizing: picture and preview size are chosen among the available picture or video sizes, depending on the flag. The picture size is chosen according to the given [size selector](#picture-size). When `video`, in addition, we try to match the `videoQuality` aspect ratio. -- Picture capturing: while recording a video, image capturing might work, but it is not guaranteed - (it's device dependent) +- Capturing: while in picture mode, `takeVideo` will throw an exception. +- Capturing: while in video mode, `takePicture` will throw an exception, but picture snapshots are supported. - Permission behavior: when requesting a `video` session, the record audio permission will be requested. If this is needed, the audio permission should be added to your manifest or the app will crash. ```java -cameraView.setSessionType(SessionType.PICTURE); -cameraView.setSessionType(SessionType.VIDEO); +cameraView.setMode(Mode.PICTURE); +cameraView.setMode(Mode.VIDEO); ``` #### cameraFacing diff --git a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraOptions1Test.java b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraOptions1Test.java index 54dad130..6c7dc073 100644 --- a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraOptions1Test.java +++ b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraOptions1Test.java @@ -35,7 +35,6 @@ public class CameraOptions1Test extends BaseTest { assertTrue(o.getSupportedHdr().isEmpty()); assertFalse(o.isAutoFocusSupported()); assertFalse(o.isExposureCorrectionSupported()); - assertFalse(o.isVideoSnapshotSupported()); assertFalse(o.isZoomSupported()); assertEquals(o.getExposureCorrectionMaxValue(), 0f, 0); assertEquals(o.getExposureCorrectionMinValue(), 0f, 0); @@ -135,11 +134,11 @@ public class CameraOptions1Test extends BaseTest { Collection grids = o.getSupportedControls(Grid.class); Collection video = o.getSupportedControls(VideoQuality.class); - Collection sessions = o.getSupportedControls(SessionType.class); + Collection sessions = o.getSupportedControls(Mode.class); Collection