From bd7a4d3cc94a87a41790398bba8fe9d4f6ddd8b2 Mon Sep 17 00:00:00 2001 From: Mattia Iavarone Date: Mon, 5 Mar 2018 22:34:40 +0100 Subject: [PATCH] Add isTakingPicture(), use in demo app --- MIGRATION.md | 1 + README.md | 2 ++ .../cameraview/CameraController.java | 4 +++ .../otaliastudios/cameraview/CameraView.java | 11 +++++++- .../cameraview/demo/CameraActivity.java | 25 ++++++------------- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index 9332220c..14fce068 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -31,4 +31,5 @@ mode == Mode.PICTURE. - VideoSizeSelector: added. It is needed to choose the capture size in VIDEO mode. Defaults to SizeSelectors.biggest(), but you can choose by aspect ratio or whatever. +- isTakingPicture(): added on top of isTakingVideo(). \ No newline at end of file diff --git a/README.md b/README.md index 4e127b39..b5756ceb 100644 --- a/README.md +++ b/README.md @@ -642,6 +642,8 @@ Other APIs not mentioned above are provided, and are well documented and comment |Method|Description| |------|-----------| |`isStarted()`|Returns true if `start()` was called succesfully. This does not mean that camera is open or showing preview.| +|`isTakingVideo()`|Returns true if the camera is currently recording a video.| +|`isTakingPicture()`|Returns true if the camera is currently capturing a picture.| |`getCameraOptions()`|If camera was started, returns non-null object with information about what is supported.| |`setZoom(float)`, `getZoom()`|Sets a zoom value, where 0 means camera zoomed out and 1 means zoomed in. No-op if zoom is not supported, or camera not started.| |`setExposureCorrection(float)`, `getExposureCorrection()`|Sets exposure compensation EV value, in camera stops. No-op if this is not supported. Should be between the bounds returned by CameraOptions.| diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java index d0e327f1..6149bda7 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java @@ -410,6 +410,10 @@ abstract class CameraController implements return mIsTakingVideo; } + final boolean isTakingPicture() { + return mIsTakingImage; + } + //endregion //region Orientation utils diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java index 7d6899c7..656ae697 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java @@ -1409,10 +1409,19 @@ public class CameraView extends FrameLayout implements LifecycleObserver { * Returns true if the camera is currently recording a video * @return boolean indicating if the camera is recording a video */ - public boolean isTakingVideo(){ + public boolean isTakingVideo() { return mCameraController.isTakingVideo(); } + + /** + * Returns true if the camera is currently capturing a picture + * @return boolean indicating if the camera is capturing a picture + */ + public boolean isTakingPicture() { + return mCameraController.isTakingPicture(); + } + //endregion //region Callbacks and dispatching diff --git a/demo/src/main/java/com/otaliastudios/cameraview/demo/CameraActivity.java b/demo/src/main/java/com/otaliastudios/cameraview/demo/CameraActivity.java index b0d50074..15e9b614 100644 --- a/demo/src/main/java/com/otaliastudios/cameraview/demo/CameraActivity.java +++ b/demo/src/main/java/com/otaliastudios/cameraview/demo/CameraActivity.java @@ -29,9 +29,6 @@ public class CameraActivity extends AppCompatActivity implements View.OnClickLis private CameraView camera; private ViewGroup controlPanel; - private boolean mCapturingPicture; - private boolean mCapturingVideo; - // To show stuff in the callback private long mCaptureTime; @@ -94,14 +91,13 @@ public class CameraActivity extends AppCompatActivity implements View.OnClickLis } private void onPicture(PictureResult result) { - mCapturingPicture = false; - long callbackTime = System.currentTimeMillis(); - if (mCapturingVideo) { + if (camera.isTakingVideo()) { message("Captured while taking video. Size=" + result.getSize(), false); return; } // This can happen if picture was taken with a gesture. + long callbackTime = System.currentTimeMillis(); if (mCaptureTime == 0) mCaptureTime = callbackTime - 300; PicturePreviewActivity.setImage(result.getJpeg()); Intent intent = new Intent(CameraActivity.this, PicturePreviewActivity.class); @@ -109,12 +105,10 @@ public class CameraActivity extends AppCompatActivity implements View.OnClickLis intent.putExtra("nativeWidth", result.getSize().getWidth()); intent.putExtra("nativeHeight", result.getSize().getHeight()); startActivity(intent); - mCaptureTime = 0; } private void onVideo(File video) { - mCapturingVideo = false; Intent intent = new Intent(CameraActivity.this, VideoPreviewActivity.class); intent.putExtra("video", Uri.fromFile(video)); startActivity(intent); @@ -151,16 +145,14 @@ public class CameraActivity extends AppCompatActivity implements View.OnClickLis message("Can't take HQ pictures while in VIDEO mode.", false); return; } - if (mCapturingPicture) return; - mCapturingPicture = true; + if (camera.isTakingPicture()) return; mCaptureTime = System.currentTimeMillis(); message("Capturing picture...", false); camera.takePicture(); } private void capturePictureSnapshot() { - if (mCapturingPicture) return; - mCapturingPicture = true; + if (camera.isTakingPicture()) return; mCaptureTime = System.currentTimeMillis(); message("Capturing picture snapshot...", false); camera.takePictureSnapshot(); @@ -171,14 +163,13 @@ public class CameraActivity extends AppCompatActivity implements View.OnClickLis message("Can't record HQ videos while in PICTURE mode.", false); return; } - if (mCapturingPicture || mCapturingVideo) return; - mCapturingVideo = true; - message("Recording for 8 seconds...", true); - camera.takeVideo(null, 8000); + if (camera.isTakingPicture() || camera.isTakingVideo()) return; + message("Recording for 5 seconds...", true); + camera.takeVideo(null, 5000); } private void toggleCamera() { - if (mCapturingPicture) return; + if (camera.isTakingPicture() || camera.isTakingVideo()) return; switch (camera.toggleFacing()) { case BACK: message("Switched to back camera!", false);