take APIs refactoring, removing deprecated

v2
Mattia Iavarone 7 years ago
parent a3e8d9fef4
commit 337df9f540
  1. 7
      MIGRATION.md
  2. 2
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraViewCallbacksTest.java
  3. 1
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraViewTest.java
  4. 29
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/IntegrationTest.java
  5. 8
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/MockCameraController.java
  6. 42
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java
  7. 8
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera2.java
  8. 8
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java
  9. 6
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraListener.java
  10. 116
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  11. 4
      demo/src/main/java/com/otaliastudios/cameraview/demo/CameraActivity.java

@ -2,4 +2,9 @@
- JpegQuality: both cameraJpegQuality and setJpegQuality() have been removed, because - JpegQuality: both cameraJpegQuality and setJpegQuality() have been removed, because
they were working only with specific setups. We'll use the default quality provided they were working only with specific setups. We'll use the default quality provided
by the camera engine. by the camera engine.
- capturePicture: renamed to takePicture()
- captureSnapshot: renamed to takePictureSnapshot()
- startCapturingVideo: renamed to takeVideo(). Signature changed from long to int.
- getSnapshotSize(): removed. The size of snapshots (pictures and videos) is equal to
the preview size as returned by getPreviewSize().

@ -269,7 +269,7 @@ public class CameraViewCallbacksTest extends BaseTest {
// Create fake JPEG array and trigger the process. // Create fake JPEG array and trigger the process.
if (jpeg) { if (jpeg) {
camera.mCameraCallbacks.processImage(mockJpeg(imageDim[0], imageDim[1]), true, false); camera.mCameraCallbacks.processPicture(mockJpeg(imageDim[0], imageDim[1]), true, false);
} else { } else {
camera.mCameraCallbacks.processSnapshot(mockYuv(imageDim[0], imageDim[1]), true, false); camera.mCameraCallbacks.processSnapshot(mockYuv(imageDim[0], imageDim[1]), true, false);
} }

@ -79,7 +79,6 @@ public class CameraViewTest extends BaseTest {
assertNull(cameraView.getExtraProperties()); assertNull(cameraView.getExtraProperties());
assertNull(cameraView.getPreviewSize()); assertNull(cameraView.getPreviewSize());
assertNull(cameraView.getPictureSize()); assertNull(cameraView.getPictureSize());
assertNull(cameraView.getSnapshotSize());
} }
@Test @Test

@ -5,7 +5,6 @@ import android.graphics.Bitmap;
import android.graphics.PointF; import android.graphics.PointF;
import android.hardware.Camera; import android.hardware.Camera;
import android.os.Build; import android.os.Build;
import android.os.Handler;
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
import android.support.test.rule.ActivityTestRule; import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4; import android.support.test.runner.AndroidJUnit4;
@ -90,7 +89,7 @@ public class IntegrationTest extends BaseTest {
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
camera.stopCapturingVideo(); camera.stopVideo();
camera.destroy(); camera.destroy();
WorkerHandler.destroy(); WorkerHandler.destroy();
} }
@ -150,7 +149,7 @@ public class IntegrationTest extends BaseTest {
private void waitForVideoStart() { private void waitForVideoStart() {
controller.mStartVideoTask.listen(); controller.mStartVideoTask.listen();
camera.startCapturingVideo(null); camera.takeVideo(null);
controller.mStartVideoTask.await(400); controller.mStartVideoTask.await(400);
} }
@ -432,7 +431,7 @@ public class IntegrationTest extends BaseTest {
//endregion //endregion
//region test startVideo //region test takeVideo
@Test(expected = RuntimeException.class) @Test(expected = RuntimeException.class)
public void testStartVideo_whileInPictureMode() throws Throwable { public void testStartVideo_whileInPictureMode() throws Throwable {
@ -452,7 +451,7 @@ public class IntegrationTest extends BaseTest {
// as documented. This works locally though. // as documented. This works locally though.
camera.setSessionType(SessionType.VIDEO); camera.setSessionType(SessionType.VIDEO);
waitForOpen(true); waitForOpen(true);
camera.startCapturingVideo(null, 4000); camera.takeVideo(null, 4000);
waitForVideoEnd(true); waitForVideoEnd(true);
} }
@ -460,7 +459,7 @@ public class IntegrationTest extends BaseTest {
public void testEndVideo_withoutStarting() { public void testEndVideo_withoutStarting() {
camera.setSessionType(SessionType.VIDEO); camera.setSessionType(SessionType.VIDEO);
waitForOpen(true); waitForOpen(true);
camera.stopCapturingVideo(); camera.stopVideo();
waitForVideoEnd(false); waitForVideoEnd(false);
} }
@ -510,7 +509,7 @@ public class IntegrationTest extends BaseTest {
@Test @Test
public void testCapturePicture_beforeStarted() { public void testCapturePicture_beforeStarted() {
camera.capturePicture(); camera.takePicture();
waitForPicture(false); waitForPicture(false);
} }
@ -522,8 +521,8 @@ public class IntegrationTest extends BaseTest {
CountDownLatch latch = new CountDownLatch(2); CountDownLatch latch = new CountDownLatch(2);
doCountDown(latch).when(listener).onPictureTaken(any(byte[].class)); doCountDown(latch).when(listener).onPictureTaken(any(byte[].class));
camera.capturePicture(); camera.takePicture();
camera.capturePicture(); camera.takePicture();
boolean did = latch.await(4, TimeUnit.SECONDS); boolean did = latch.await(4, TimeUnit.SECONDS);
assertFalse(did); assertFalse(did);
assertEquals(latch.getCount(), 1); assertEquals(latch.getCount(), 1);
@ -535,7 +534,7 @@ public class IntegrationTest extends BaseTest {
waitForOpen(true); waitForOpen(true);
Size size = camera.getPictureSize(); Size size = camera.getPictureSize();
camera.capturePicture(); camera.takePicture();
byte[] jpeg = waitForPicture(true); byte[] jpeg = waitForPicture(true);
Bitmap b = CameraUtils.decodeBitmap(jpeg, Integer.MAX_VALUE, Integer.MAX_VALUE); Bitmap b = CameraUtils.decodeBitmap(jpeg, Integer.MAX_VALUE, Integer.MAX_VALUE);
// Result can actually have swapped dimensions // Result can actually have swapped dimensions
@ -546,7 +545,7 @@ public class IntegrationTest extends BaseTest {
@Test @Test
public void testCaptureSnapshot_beforeStarted() { public void testCaptureSnapshot_beforeStarted() {
camera.captureSnapshot(); camera.takePictureSnapshot();
waitForPicture(false); waitForPicture(false);
} }
@ -558,8 +557,8 @@ public class IntegrationTest extends BaseTest {
CountDownLatch latch = new CountDownLatch(2); CountDownLatch latch = new CountDownLatch(2);
doCountDown(latch).when(listener).onPictureTaken(any(byte[].class)); doCountDown(latch).when(listener).onPictureTaken(any(byte[].class));
camera.captureSnapshot(); camera.takePictureSnapshot();
camera.captureSnapshot(); camera.takePictureSnapshot();
boolean did = latch.await(6, TimeUnit.SECONDS); boolean did = latch.await(6, TimeUnit.SECONDS);
assertFalse(did); assertFalse(did);
assertEquals(1, latch.getCount()); assertEquals(1, latch.getCount());
@ -571,7 +570,7 @@ public class IntegrationTest extends BaseTest {
waitForOpen(true); waitForOpen(true);
Size size = camera.getPreviewSize(); Size size = camera.getPreviewSize();
camera.captureSnapshot(); camera.takePictureSnapshot();
byte[] jpeg = waitForPicture(true); byte[] jpeg = waitForPicture(true);
Bitmap b = CameraUtils.decodeBitmap(jpeg, Integer.MAX_VALUE, Integer.MAX_VALUE); Bitmap b = CameraUtils.decodeBitmap(jpeg, Integer.MAX_VALUE, Integer.MAX_VALUE);
// Result can actually have swapped dimensions // Result can actually have swapped dimensions
@ -609,7 +608,7 @@ public class IntegrationTest extends BaseTest {
// In Camera1, snapshots will clear the preview callback // In Camera1, snapshots will clear the preview callback
// Ensure we restore correctly // Ensure we restore correctly
camera.captureSnapshot(); camera.takePictureSnapshot();
waitForPicture(true); waitForPicture(true);
assert30Frames(processor); assert30Frames(processor);

@ -92,20 +92,20 @@ public class MockCameraController extends CameraController {
} }
@Override @Override
void capturePicture() { void takePicture() {
mPictureCaptured = true; mPictureCaptured = true;
} }
@Override @Override
void captureSnapshot() { void takePictureSnapshot() {
} }
@Override @Override
void startVideo(@NonNull File file) { void takeVideo(@NonNull File file) {
} }
@Override @Override
void endVideo() { void stopVideo() {
} }
@Override @Override

@ -207,7 +207,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
if (mCamera != null) { if (mCamera != null) {
LOG.i("onStop:", "Clean up.", "Ending video."); LOG.i("onStop:", "Clean up.", "Ending video.");
endVideoImmediately(); stopVideoImmediately();
try { try {
LOG.i("onStop:", "Clean up.", "Stopping preview."); LOG.i("onStop:", "Clean up.", "Stopping preview.");
@ -500,12 +500,12 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
} }
@Override @Override
void capturePicture() { void takePicture() {
LOG.v("capturePicture: scheduling"); LOG.v("takePicture: scheduling");
schedule(null, true, new Runnable() { schedule(null, true, new Runnable() {
@Override @Override
public void run() { public void run() {
LOG.v("capturePicture: performing.", mIsCapturingImage); LOG.v("takePicture: performing.", mIsCapturingImage);
if (mIsCapturingImage) return; if (mIsCapturingImage) return;
if (mIsCapturingVideo && !mCameraOptions.isVideoSnapshotSupported()) return; if (mIsCapturingVideo && !mCameraOptions.isVideoSnapshotSupported()) return;
@ -530,7 +530,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
@Override @Override
public void onPictureTaken(byte[] data, final Camera camera) { public void onPictureTaken(byte[] data, final Camera camera) {
mIsCapturingImage = false; mIsCapturingImage = false;
mCameraCallbacks.processImage(data, outputMatchesView, outputFlip); mCameraCallbacks.processPicture(data, outputMatchesView, outputFlip);
camera.startPreview(); // This is needed, read somewhere in the docs. camera.startPreview(); // This is needed, read somewhere in the docs.
} }
} }
@ -541,17 +541,17 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
@Override @Override
void captureSnapshot() { void takePictureSnapshot() {
LOG.v("captureSnapshot: scheduling"); LOG.v("takePictureSnapshot: scheduling");
schedule(null, true, new Runnable() { schedule(null, true, new Runnable() {
@Override @Override
public void run() { public void run() {
LOG.v("captureSnapshot: performing.", mIsCapturingImage); LOG.v("takePictureSnapshot: performing.", mIsCapturingImage);
if (mIsCapturingImage) return; if (mIsCapturingImage) return;
// This won't work while capturing a video. // This won't work while capturing a video.
// Switch to capturePicture. // Switch to takePicture.
if (mIsCapturingVideo) { if (mIsCapturingVideo) {
capturePicture(); takePicture();
return; return;
} }
mIsCapturingImage = true; mIsCapturingImage = true;
@ -577,9 +577,9 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
@Override @Override
public void run() { public void run() {
LOG.v("captureSnapshot: rotating."); LOG.v("takePictureSnapshot: rotating.");
byte[] rotatedData = RotationHelper.rotate(data, preWidth, preHeight, sensorToOutput); byte[] rotatedData = RotationHelper.rotate(data, preWidth, preHeight, sensorToOutput);
LOG.v("captureSnapshot: rotated."); LOG.v("takePictureSnapshot: rotated.");
YuvImage yuv = new YuvImage(rotatedData, format, postWidth, postHeight, null); YuvImage yuv = new YuvImage(rotatedData, format, postWidth, postHeight, null);
mCameraCallbacks.processSnapshot(yuv, outputMatchesView, outputFlip); mCameraCallbacks.processSnapshot(yuv, outputMatchesView, outputFlip);
mIsCapturingImage = false; mIsCapturingImage = false;
@ -631,7 +631,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
@Override @Override
void startVideo(@NonNull final File videoFile) { void takeVideo(@NonNull final File videoFile) {
schedule(mStartVideoTask, true, new Runnable() { schedule(mStartVideoTask, true, new Runnable() {
@Override @Override
public void run() { public void run() {
@ -647,7 +647,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
LOG.e("Error while starting MediaRecorder. Swallowing.", e); LOG.e("Error while starting MediaRecorder. Swallowing.", e);
mVideoFile = null; mVideoFile = null;
mCamera.lock(); mCamera.lock();
endVideoImmediately(); stopVideoImmediately();
} }
} else { } else {
throw new IllegalStateException("Can't record video while session type is picture"); throw new IllegalStateException("Can't record video while session type is picture");
@ -657,25 +657,25 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
} }
@Override @Override
void endVideo() { void stopVideo() {
schedule(null, false, new Runnable() { schedule(null, false, new Runnable() {
@Override @Override
public void run() { public void run() {
endVideoImmediately(); stopVideoImmediately();
} }
}); });
} }
@WorkerThread @WorkerThread
private void endVideoImmediately() { private void stopVideoImmediately() {
LOG.i("endVideoImmediately:", "is capturing:", mIsCapturingVideo); LOG.i("stopVideoImmediately:", "is capturing:", mIsCapturingVideo);
mIsCapturingVideo = false; mIsCapturingVideo = false;
if (mMediaRecorder != null) { if (mMediaRecorder != null) {
try { try {
mMediaRecorder.stop(); mMediaRecorder.stop();
} catch (Exception e) { } catch (Exception e) {
// This can happen if endVideo() is called right after startVideo(). We don't care. // This can happen if stopVideo() is called right after takeVideo(). We don't care.
LOG.w("endVideoImmediately:", "Error while closing media recorder. Swallowing", e); LOG.w("stopVideoImmediately:", "Error while closing media recorder. Swallowing", e);
} }
mMediaRecorder.release(); mMediaRecorder.release();
mMediaRecorder = null; mMediaRecorder = null;
@ -736,7 +736,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
switch (what) { switch (what) {
case MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED: case MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED:
case MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED: case MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED:
endVideoImmediately(); stopVideoImmediately();
break; break;
} }
} }

@ -86,22 +86,22 @@ class Camera2 extends CameraController {
} }
@Override @Override
void capturePicture() { void takePicture() {
} }
@Override @Override
void captureSnapshot() { void takePictureSnapshot() {
} }
@Override @Override
void startVideo(@NonNull File file) { void takeVideo(@NonNull File file) {
} }
@Override @Override
void endVideo() { void stopVideo() {
} }

@ -325,13 +325,13 @@ abstract class CameraController implements
// Throw if capturing. If in video session, recompute capture size, and, if needed, preview size. // Throw if capturing. If in video session, recompute capture size, and, if needed, preview size.
abstract void setVideoQuality(VideoQuality videoQuality); abstract void setVideoQuality(VideoQuality videoQuality);
abstract void capturePicture(); abstract void takePicture();
abstract void captureSnapshot(); abstract void takePictureSnapshot();
abstract void startVideo(@NonNull File file); abstract void takeVideo(@NonNull File file);
abstract void endVideo(); abstract void stopVideo();
abstract void startAutoFocus(@Nullable Gesture gesture, PointF point); abstract void startAutoFocus(@Nullable Gesture gesture, PointF point);

@ -50,8 +50,8 @@ public abstract class CameraListener {
/** /**
* Notifies that a picture previously captured with {@link CameraView#capturePicture()} * Notifies that a picture previously captured with {@link CameraView#takePicture()}
* or {@link CameraView#captureSnapshot()} is ready to be shown or saved. * or {@link CameraView#takePictureSnapshot()} is ready to be shown or saved.
* *
* If planning to get a bitmap, you can use {@link CameraUtils#decodeBitmap(byte[], CameraUtils.BitmapCallback)} * If planning to get a bitmap, you can use {@link CameraUtils#decodeBitmap(byte[], CameraUtils.BitmapCallback)}
* to decode the byte array taking care about orientation. * to decode the byte array taking care about orientation.
@ -66,7 +66,7 @@ public abstract class CameraListener {
/** /**
* Notifies that a video capture has just ended. The file parameter is the one that * Notifies that a video capture has just ended. The file parameter is the one that
* was passed to {@link CameraView#startCapturingVideo(File)}, if any. * was passed to {@link CameraView#takeVideo(File)}, if any.
* If not, the camera fallsback to: * If not, the camera fallsback to:
* <code> * <code>
* new File(getContext().getExternalFilesDir(null), "video.mp4"); * new File(getContext().getExternalFilesDir(null), "video.mp4");

@ -491,7 +491,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
switch (action) { switch (action) {
case CAPTURE: case CAPTURE:
mCameraController.capturePicture(); mCameraController.takePicture();
break; break;
case FOCUS: case FOCUS:
@ -989,8 +989,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
/** /**
* Set the current session type to either picture or video. * Set the current session type to either picture or video.
* When sessionType is video, * When sessionType is video,
* - {@link #startCapturingVideo(File)} will not throw any exception * - {@link #takeVideo(File)} will not throw any exception
* - {@link #capturePicture()} might fallback to {@link #captureSnapshot()} or might not work * - {@link #takePicture()} might fallback to {@link #takePictureSnapshot()} or might not work
* *
* @see SessionType#PICTURE * @see SessionType#PICTURE
* @see SessionType#VIDEO * @see SessionType#VIDEO
@ -1067,20 +1067,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
} }
/**
* Sets a {@link CameraListener} instance to be notified of all
* interesting events that will happen during the camera lifecycle.
*
* @param cameraListener a listener for events.
* @deprecated use {@link #addCameraListener(CameraListener)} instead.
*/
@Deprecated
public void setCameraListener(CameraListener cameraListener) {
mListeners.clear();
addCameraListener(cameraListener);
}
/** /**
* Adds a {@link CameraListener} instance to be notified of all * Adds a {@link CameraListener} instance to be notified of all
* interesting events that happen during the camera lifecycle. * interesting events that happen during the camera lifecycle.
@ -1155,12 +1141,12 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* was registered. * was registered.
* *
* Note that if sessionType is {@link SessionType#VIDEO}, this * Note that if sessionType is {@link SessionType#VIDEO}, this
* might fall back to {@link #captureSnapshot()} (that is, we might capture a preview frame). * might fall back to {@link #takePictureSnapshot()} (that is, we might capture a preview frame).
* *
* @see #captureSnapshot() * @see #takePictureSnapshot()
*/ */
public void capturePicture() { public void takePicture() {
mCameraController.capturePicture(); mCameraController.takePicture();
} }
@ -1169,25 +1155,13 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* This eventually triggers {@link CameraListener#onPictureTaken(byte[])} if a listener * This eventually triggers {@link CameraListener#onPictureTaken(byte[])} if a listener
* was registered. * was registered.
* *
* The difference with {@link #capturePicture()} is that this capture is faster, so it might be * The difference with {@link #takePicture()} is that this capture is faster, so it might be
* better on slower cameras, though the result can be generally blurry or low quality. * better on slower cameras, though the result can be generally blurry or low quality.
* *
* @see #capturePicture() * @see #takePicture()
*/ */
public void captureSnapshot() { public void takePictureSnapshot() {
mCameraController.captureSnapshot(); mCameraController.takePictureSnapshot();
}
/**
* Starts recording a video, in a file called "video.mp4" in the default folder.
* This is discouraged, please use {@link #startCapturingVideo(File)} instead.
*
* @deprecated see {@link #startCapturingVideo(File)}
*/
@Deprecated
public void startCapturingVideo() {
startCapturingVideo(null);
} }
@ -1197,11 +1171,11 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* *
* @param file a file where the video will be saved * @param file a file where the video will be saved
*/ */
public void startCapturingVideo(File file) { public void takeVideo(File file) {
if (file == null) { if (file == null) {
file = new File(getContext().getFilesDir(), "video.mp4"); file = new File(getContext().getFilesDir(), "video.mp4");
} }
mCameraController.startVideo(file); mCameraController.takeVideo(file);
mUiHandler.post(new Runnable() { mUiHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -1221,11 +1195,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @param file a file where the video will be saved * @param file a file where the video will be saved
* @param durationMillis recording max duration * @param durationMillis recording max duration
* *
* @deprecated use {@link #setVideoMaxDuration(int)} instead.
*/ */
@Deprecated public void takeVideo(File file, int durationMillis) {
public void startCapturingVideo(File file, long durationMillis) {
// TODO: v2: change signature to int, or remove (better).
final int old = getVideoMaxDuration(); final int old = getVideoMaxDuration();
addCameraListener(new CameraListener() { addCameraListener(new CameraListener() {
@Override @Override
@ -1234,8 +1205,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
removeCameraListener(this); removeCameraListener(this);
} }
}); });
setVideoMaxDuration((int) durationMillis); setVideoMaxDuration(durationMillis);
startCapturingVideo(file); takeVideo(file);
} }
@ -1246,8 +1217,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* Stops capturing video, if there was a video record going on. * Stops capturing video, if there was a video record going on.
* This will fire {@link CameraListener#onVideoTaken(File)}. * This will fire {@link CameraListener#onVideoTaken(File)}.
*/ */
public void stopCapturingVideo() { public void stopVideo() {
mCameraController.endVideo(); mCameraController.stopVideo();
mUiHandler.post(new Runnable() { mUiHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -1260,6 +1231,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
/** /**
* Returns the size used for the preview, * Returns the size used for the preview,
* or null if it hasn't been computed (for example if the surface is not ready). * or null if it hasn't been computed (for example if the surface is not ready).
* This is the size of snapshots.
*
* @return a Size * @return a Size
*/ */
@Nullable @Nullable
@ -1271,6 +1244,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
/** /**
* Returns the size used for the capture, * Returns the size used for the capture,
* or null if it hasn't been computed yet (for example if the surface is not ready). * or null if it hasn't been computed yet (for example if the surface is not ready).
*
* @return a Size * @return a Size
*/ */
@Nullable @Nullable
@ -1279,18 +1253,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
} }
/**
* Returns the size used for capturing snapshots.
* This is equal to {@link #getPreviewSize()}.
*
* @return a Size
*/
@Nullable
public Size getSnapshotSize() {
return getPreviewSize();
}
// If we end up here, we're in M. // If we end up here, we're in M.
@TargetApi(Build.VERSION_CODES.M) @TargetApi(Build.VERSION_CODES.M)
private void requestPermissions(boolean requestCamera, boolean requestAudio) { private void requestPermissions(boolean requestCamera, boolean requestAudio) {
@ -1436,7 +1398,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
void dispatchOnCameraClosed(); void dispatchOnCameraClosed();
void onCameraPreviewSizeChanged(); void onCameraPreviewSizeChanged();
void onShutter(boolean shouldPlaySound); void onShutter(boolean shouldPlaySound);
void processImage(byte[] jpeg, boolean consistentWithView, boolean flipHorizontally); void processPicture(byte[] jpeg, boolean consistentWithView, boolean flipHorizontally);
void processSnapshot(YuvImage image, boolean consistentWithView, boolean flipHorizontally); void processSnapshot(YuvImage image, boolean consistentWithView, boolean flipHorizontally);
void dispatchOnVideoTaken(File file); void dispatchOnVideoTaken(File file);
void dispatchOnFocusStart(@Nullable Gesture trigger, PointF where); void dispatchOnFocusStart(@Nullable Gesture trigger, PointF where);
@ -1520,8 +1482,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* because it was taken with the front camera. * because it was taken with the front camera.
*/ */
@Override @Override
public void processImage(final byte[] jpeg, final boolean consistentWithView, final boolean flipHorizontally) { public void processPicture(final byte[] jpeg, final boolean consistentWithView, final boolean flipHorizontally) {
mLogger.i("processImage"); mLogger.i("processPicture");
dispatchOnPictureTaken(jpeg); dispatchOnPictureTaken(jpeg);
// TODO: remove. // TODO: remove.
} }
@ -1697,36 +1659,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
//region deprecated APIs //region deprecated APIs
/**
* @deprecated use {@link #getPictureSize()} instead.
*/
@Deprecated
@Nullable
public Size getCaptureSize() {
return getPictureSize();
}
/**
* Toggles the flash mode between {@link Flash#OFF},
* {@link Flash#ON} and {@link Flash#AUTO}, in this order.
*
* @deprecated Don't use this. Flash values might not be supported,
* and the return value is unreliable.
*
* @return the new flash value
*/
@Deprecated
public Flash toggleFlash() {
Flash flash = mCameraController.getFlash();
switch (flash) {
case OFF: setFlash(Flash.ON); break;
case ON: setFlash(Flash.AUTO); break;
case AUTO: case TORCH: setFlash(Flash.OFF); break;
}
return mCameraController.getFlash();
}
/* for tests */int getCameraId(){ /* for tests */int getCameraId(){
return mCameraController.mCameraId; return mCameraController.mCameraId;
} }

@ -153,7 +153,7 @@ public class CameraActivity extends AppCompatActivity implements View.OnClickLis
mCaptureTime = System.currentTimeMillis(); mCaptureTime = System.currentTimeMillis();
mCaptureNativeSize = camera.getPictureSize(); mCaptureNativeSize = camera.getPictureSize();
message("Capturing picture...", false); message("Capturing picture...", false);
camera.capturePicture(); camera.takePicture();
} }
private void captureVideo() { private void captureVideo() {
@ -164,7 +164,7 @@ public class CameraActivity extends AppCompatActivity implements View.OnClickLis
if (mCapturingPicture || mCapturingVideo) return; if (mCapturingPicture || mCapturingVideo) return;
mCapturingVideo = true; mCapturingVideo = true;
message("Recording for 8 seconds...", true); message("Recording for 8 seconds...", true);
camera.startCapturingVideo(null, 8000); camera.takeVideo(null, 8000);
} }
private void toggleCamera() { private void toggleCamera() {

Loading…
Cancel
Save