Add isTakingPicture(), use in demo app

v2
Mattia Iavarone 7 years ago
parent 78c5e4b19c
commit b2d70d57d4
  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.
- 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().

@ -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.|

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

@ -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

@ -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);

Loading…
Cancel
Save