Suggesting keepScreenOn, support during videos

pull/1/head
Mattia Iavarone 7 years ago
parent 7f131c4cf9
commit 84c7f63443
  1. 11
      README.md
  2. 9
      camerakit/src/main/api16/com/flurgle/camerakit/Camera1.java
  3. 5
      camerakit/src/main/api21/com/flurgle/camerakit/Camera2.java
  4. 2
      camerakit/src/main/base/com/flurgle/camerakit/CameraImpl.java
  5. 7
      camerakit/src/main/java/com/flurgle/camerakit/CameraView.java

@ -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:* *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* - lots *of serious bugs fixed, I have lost the count*
- *decent orientation support* - *decent orientation support for both pictures and videos*
- *EXIF support* - *EXIF support*
- *simpler APIs* - *simpler APIs*
- *docs and comments in code* - *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 - Automatic output cropping to match your `CameraView` bounds
- Multiple capture methods - Multiple capture methods
- Take high-resolution pictures with `capturePicture` - 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 - Built-in tap to focus
- `CameraUtils` to help with Bitmaps and orientations - `CameraUtils` to help with Bitmaps and orientations
- EXIF support - EXIF support
@ -75,6 +75,7 @@ To use CameraKit, simply add a `CameraView` to your layout:
```xml ```xml
<com.flurgle.camerakit.CameraView <com.flurgle.camerakit.CameraView
android:id="@+id/camera" android:id="@+id/camera"
android:keepScreenOn="true"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
``` ```
@ -103,7 +104,7 @@ protected void onDestroy() {
### Capturing Images ### 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 ```java
camera.setCameraListener(new CameraListener() { 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 ### Capturing Video

@ -545,10 +545,10 @@ class Camera1 extends CameraImpl {
@Override @Override
void startVideo(@NonNull File videoFile) { boolean startVideo(@NonNull File videoFile) {
mVideoFile = videoFile; mVideoFile = videoFile;
if (mIsCapturingVideo) return; if (mIsCapturingVideo) return false;
if (!isCameraOpened()) return; if (!isCameraOpened()) return false;
Camera.Parameters params = mCamera.getParameters(); Camera.Parameters params = mCamera.getParameters();
params.setVideoStabilization(false); params.setVideoStabilization(false);
if (mSessionType == SESSION_TYPE_VIDEO) { if (mSessionType == SESSION_TYPE_VIDEO) {
@ -560,9 +560,10 @@ class Camera1 extends CameraImpl {
e.printStackTrace(); e.printStackTrace();
mVideoFile = null; mVideoFile = null;
endVideo(); endVideo();
return; return false;
} }
mMediaRecorder.start(); mMediaRecorder.start();
return true;
} 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");
} }

@ -17,7 +17,6 @@ import android.view.MotionEvent;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.TreeSet; import java.util.TreeSet;
@ -188,8 +187,8 @@ class Camera2 extends CameraImpl {
} }
@Override @Override
void startVideo(@NonNull File videoFile) { boolean startVideo(@NonNull File videoFile) {
return false;
} }
@Override @Override

@ -34,7 +34,7 @@ abstract class CameraImpl implements PreviewImpl.SurfaceCallback {
abstract void capturePicture(); abstract void capturePicture();
abstract void captureSnapshot(); abstract void captureSnapshot();
abstract void startVideo(@NonNull File file); abstract boolean startVideo(@NonNull File file);
abstract void endVideo(); abstract void endVideo();
abstract Size getCaptureSize(); abstract Size getCaptureSize();

@ -103,6 +103,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
private Lifecycle mLifecycle; private Lifecycle mLifecycle;
private FocusMarkerLayout mFocusMarkerLayout; private FocusMarkerLayout mFocusMarkerLayout;
private boolean mIsStarted; private boolean mIsStarted;
private boolean mKeepScreenOn;
public CameraView(@NonNull Context context) { public CameraView(@NonNull Context context) {
super(context, null); super(context, null);
@ -851,7 +852,10 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
if (file == null) { if (file == null) {
file = new File(getContext().getExternalFilesDir(null), "video.mp4"); 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() { public void stopCapturingVideo() {
mCameraImpl.endVideo(); mCameraImpl.endVideo();
if (getKeepScreenOn() != mKeepScreenOn) setKeepScreenOn(mKeepScreenOn);
} }

Loading…
Cancel
Save