Add isTakingPicture(), use in demo app

pull/360/head
Mattia Iavarone 7 years ago
parent dbdade2525
commit bd7a4d3cc9
  1. 1
      MIGRATION.md
  2. 2
      README.md
  3. 4
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java
  4. 11
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  5. 25
      demo/src/main/java/com/otaliastudios/cameraview/demo/CameraActivity.java

@ -31,4 +31,5 @@
mode == Mode.PICTURE. mode == Mode.PICTURE.
- VideoSizeSelector: added. It is needed to choose the capture size in VIDEO mode. - 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. Defaults to SizeSelectors.biggest(), but you can choose by aspect ratio or whatever.
- isTakingPicture(): added on top of isTakingVideo().

@ -642,6 +642,8 @@ Other APIs not mentioned above are provided, and are well documented and comment
|Method|Description| |Method|Description|
|------|-----------| |------|-----------|
|`isStarted()`|Returns true if `start()` was called succesfully. This does not mean that camera is open or showing preview.| |`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.| |`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.| |`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.| |`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.|

@ -410,6 +410,10 @@ abstract class CameraController implements
return mIsTakingVideo; return mIsTakingVideo;
} }
final boolean isTakingPicture() {
return mIsTakingImage;
}
//endregion //endregion
//region Orientation utils //region Orientation utils

@ -1409,10 +1409,19 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* Returns true if the camera is currently recording a video * Returns true if the camera is currently recording a video
* @return boolean indicating if the camera is recording a video * @return boolean indicating if the camera is recording a video
*/ */
public boolean isTakingVideo(){ public boolean isTakingVideo() {
return mCameraController.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 //endregion
//region Callbacks and dispatching //region Callbacks and dispatching

@ -29,9 +29,6 @@ public class CameraActivity extends AppCompatActivity implements View.OnClickLis
private CameraView camera; private CameraView camera;
private ViewGroup controlPanel; private ViewGroup controlPanel;
private boolean mCapturingPicture;
private boolean mCapturingVideo;
// To show stuff in the callback // To show stuff in the callback
private long mCaptureTime; private long mCaptureTime;
@ -94,14 +91,13 @@ public class CameraActivity extends AppCompatActivity implements View.OnClickLis
} }
private void onPicture(PictureResult result) { private void onPicture(PictureResult result) {
mCapturingPicture = false; if (camera.isTakingVideo()) {
long callbackTime = System.currentTimeMillis();
if (mCapturingVideo) {
message("Captured while taking video. Size=" + result.getSize(), false); message("Captured while taking video. Size=" + result.getSize(), false);
return; return;
} }
// This can happen if picture was taken with a gesture. // This can happen if picture was taken with a gesture.
long callbackTime = System.currentTimeMillis();
if (mCaptureTime == 0) mCaptureTime = callbackTime - 300; if (mCaptureTime == 0) mCaptureTime = callbackTime - 300;
PicturePreviewActivity.setImage(result.getJpeg()); PicturePreviewActivity.setImage(result.getJpeg());
Intent intent = new Intent(CameraActivity.this, PicturePreviewActivity.class); 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("nativeWidth", result.getSize().getWidth());
intent.putExtra("nativeHeight", result.getSize().getHeight()); intent.putExtra("nativeHeight", result.getSize().getHeight());
startActivity(intent); startActivity(intent);
mCaptureTime = 0; mCaptureTime = 0;
} }
private void onVideo(File video) { private void onVideo(File video) {
mCapturingVideo = false;
Intent intent = new Intent(CameraActivity.this, VideoPreviewActivity.class); Intent intent = new Intent(CameraActivity.this, VideoPreviewActivity.class);
intent.putExtra("video", Uri.fromFile(video)); intent.putExtra("video", Uri.fromFile(video));
startActivity(intent); 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); message("Can't take HQ pictures while in VIDEO mode.", false);
return; return;
} }
if (mCapturingPicture) return; if (camera.isTakingPicture()) return;
mCapturingPicture = true;
mCaptureTime = System.currentTimeMillis(); mCaptureTime = System.currentTimeMillis();
message("Capturing picture...", false); message("Capturing picture...", false);
camera.takePicture(); camera.takePicture();
} }
private void capturePictureSnapshot() { private void capturePictureSnapshot() {
if (mCapturingPicture) return; if (camera.isTakingPicture()) return;
mCapturingPicture = true;
mCaptureTime = System.currentTimeMillis(); mCaptureTime = System.currentTimeMillis();
message("Capturing picture snapshot...", false); message("Capturing picture snapshot...", false);
camera.takePictureSnapshot(); 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); message("Can't record HQ videos while in PICTURE mode.", false);
return; return;
} }
if (mCapturingPicture || mCapturingVideo) return; if (camera.isTakingPicture() || camera.isTakingVideo()) return;
mCapturingVideo = true; message("Recording for 5 seconds...", true);
message("Recording for 8 seconds...", true); camera.takeVideo(null, 5000);
camera.takeVideo(null, 8000);
} }
private void toggleCamera() { private void toggleCamera() {
if (mCapturingPicture) return; if (camera.isTakingPicture() || camera.isTakingVideo()) return;
switch (camera.toggleFacing()) { switch (camera.toggleFacing()) {
case BACK: case BACK:
message("Switched to back camera!", false); message("Switched to back camera!", false);

Loading…
Cancel
Save