diff --git a/README.md b/README.md index 0566b555..1566195a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ *A fork of [Dylan McIntyre's CameraKit-Android library](https://github.com/gogopop/CameraKit-Android), originally a fork of [Google's CameraView library](https://github.com/google/cameraview). The CameraKit-Android at this point has been fairly rewritten and refactored:* - lots *of serious bugs fixed, I have lost the count* -- *decent orientation support* +- *decent orientation support for both pictures and videos* - *EXIF support* - *simpler APIs* - *docs and comments in code* @@ -56,7 +56,7 @@ CameraKit is an easy to use utility to work with the Android Camera APIs. Everyt - Automatic output cropping to match your `CameraView` bounds - Multiple capture methods - Take high-resolution pictures with `capturePicture` - - Take quick snapshots as a freeze frame of the preview with `captureSnapshot`, even while recording videos (similar to SnapChat and Instagram) + - Take quick snapshots as a freeze frame of the preview with `captureSnapshot` (similar to SnapChat and Instagram) - Built-in tap to focus - `CameraUtils` to help with Bitmaps and orientations - EXIF support @@ -75,6 +75,7 @@ To use CameraKit, simply add a `CameraView` to your layout: ```xml ``` @@ -103,7 +104,7 @@ protected void onDestroy() { ### Capturing Images -To capture an image just call `CameraView.captureImage()`. Make sure you setup a `CameraListener` to handle the image callback. +To capture an image just call `CameraView.capturePicture()`. Make sure you setup a `CameraListener` to handle the image callback. ```java camera.setCameraListener(new CameraListener() { @@ -115,10 +116,10 @@ camera.setCameraListener(new CameraListener() { } }); -camera.captureImage(); +camera.capturePicture(); ``` -You can also use `camera.captureSnapshot()` to capture a preview frame. This is faster, though has lower quality, and can be used while recording videos. +You can also use `camera.captureSnapshot()` to capture a preview frame. This is faster, though will ensure lower quality output. ### Capturing Video diff --git a/camerakit/src/main/api16/com/flurgle/camerakit/Camera1.java b/camerakit/src/main/api16/com/flurgle/camerakit/Camera1.java index 3e244189..bff379f7 100644 --- a/camerakit/src/main/api16/com/flurgle/camerakit/Camera1.java +++ b/camerakit/src/main/api16/com/flurgle/camerakit/Camera1.java @@ -545,10 +545,10 @@ class Camera1 extends CameraImpl { @Override - void startVideo(@NonNull File videoFile) { + boolean startVideo(@NonNull File videoFile) { mVideoFile = videoFile; - if (mIsCapturingVideo) return; - if (!isCameraOpened()) return; + if (mIsCapturingVideo) return false; + if (!isCameraOpened()) return false; Camera.Parameters params = mCamera.getParameters(); params.setVideoStabilization(false); if (mSessionType == SESSION_TYPE_VIDEO) { @@ -560,9 +560,10 @@ class Camera1 extends CameraImpl { e.printStackTrace(); mVideoFile = null; endVideo(); - return; + return false; } mMediaRecorder.start(); + return true; } else { throw new IllegalStateException("Can't record video while session type is picture"); } diff --git a/camerakit/src/main/api21/com/flurgle/camerakit/Camera2.java b/camerakit/src/main/api21/com/flurgle/camerakit/Camera2.java index 9326cf45..829c4eef 100644 --- a/camerakit/src/main/api21/com/flurgle/camerakit/Camera2.java +++ b/camerakit/src/main/api21/com/flurgle/camerakit/Camera2.java @@ -17,7 +17,6 @@ import android.view.MotionEvent; import java.io.File; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.TreeSet; @@ -188,8 +187,8 @@ class Camera2 extends CameraImpl { } @Override - void startVideo(@NonNull File videoFile) { - + boolean startVideo(@NonNull File videoFile) { + return false; } @Override diff --git a/camerakit/src/main/base/com/flurgle/camerakit/CameraImpl.java b/camerakit/src/main/base/com/flurgle/camerakit/CameraImpl.java index 8e458691..e3eb9611 100644 --- a/camerakit/src/main/base/com/flurgle/camerakit/CameraImpl.java +++ b/camerakit/src/main/base/com/flurgle/camerakit/CameraImpl.java @@ -34,7 +34,7 @@ abstract class CameraImpl implements PreviewImpl.SurfaceCallback { abstract void capturePicture(); abstract void captureSnapshot(); - abstract void startVideo(@NonNull File file); + abstract boolean startVideo(@NonNull File file); abstract void endVideo(); abstract Size getCaptureSize(); diff --git a/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java b/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java index 4efba926..368f3c7e 100644 --- a/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java +++ b/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java @@ -103,6 +103,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver { private Lifecycle mLifecycle; private FocusMarkerLayout mFocusMarkerLayout; private boolean mIsStarted; + private boolean mKeepScreenOn; public CameraView(@NonNull Context context) { super(context, null); @@ -851,7 +852,10 @@ public class CameraView extends FrameLayout implements LifecycleObserver { if (file == null) { file = new File(getContext().getExternalFilesDir(null), "video.mp4"); } - mCameraImpl.startVideo(file); + if (mCameraImpl.startVideo(file)) { + mKeepScreenOn = getKeepScreenOn(); + if (!mKeepScreenOn) setKeepScreenOn(true); + } } @@ -861,6 +865,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver { */ public void stopCapturingVideo() { mCameraImpl.endVideo(); + if (getKeepScreenOn() != mKeepScreenOn) setKeepScreenOn(mKeepScreenOn); }