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