|
|
|
@ -107,34 +107,65 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
|
long videoMaxSize = (long) a.getFloat(R.styleable.CameraView_cameraVideoMaxSize, 0); |
|
|
|
|
int videoMaxDuration = a.getInteger(R.styleable.CameraView_cameraVideoMaxDuration, 0); |
|
|
|
|
|
|
|
|
|
// Size selectors
|
|
|
|
|
List<SizeSelector> constraints = new ArrayList<>(3); |
|
|
|
|
// Picture size selector
|
|
|
|
|
List<SizeSelector> pictureConstraints = new ArrayList<>(3); |
|
|
|
|
if (a.hasValue(R.styleable.CameraView_cameraPictureSizeMinWidth)) { |
|
|
|
|
constraints.add(SizeSelectors.minWidth(a.getInteger(R.styleable.CameraView_cameraPictureSizeMinWidth, 0))); |
|
|
|
|
pictureConstraints.add(SizeSelectors.minWidth(a.getInteger(R.styleable.CameraView_cameraPictureSizeMinWidth, 0))); |
|
|
|
|
} |
|
|
|
|
if (a.hasValue(R.styleable.CameraView_cameraPictureSizeMaxWidth)) { |
|
|
|
|
constraints.add(SizeSelectors.maxWidth(a.getInteger(R.styleable.CameraView_cameraPictureSizeMaxWidth, 0))); |
|
|
|
|
pictureConstraints.add(SizeSelectors.maxWidth(a.getInteger(R.styleable.CameraView_cameraPictureSizeMaxWidth, 0))); |
|
|
|
|
} |
|
|
|
|
if (a.hasValue(R.styleable.CameraView_cameraPictureSizeMinHeight)) { |
|
|
|
|
constraints.add(SizeSelectors.minHeight(a.getInteger(R.styleable.CameraView_cameraPictureSizeMinHeight, 0))); |
|
|
|
|
pictureConstraints.add(SizeSelectors.minHeight(a.getInteger(R.styleable.CameraView_cameraPictureSizeMinHeight, 0))); |
|
|
|
|
} |
|
|
|
|
if (a.hasValue(R.styleable.CameraView_cameraPictureSizeMaxHeight)) { |
|
|
|
|
constraints.add(SizeSelectors.maxHeight(a.getInteger(R.styleable.CameraView_cameraPictureSizeMaxHeight, 0))); |
|
|
|
|
pictureConstraints.add(SizeSelectors.maxHeight(a.getInteger(R.styleable.CameraView_cameraPictureSizeMaxHeight, 0))); |
|
|
|
|
} |
|
|
|
|
if (a.hasValue(R.styleable.CameraView_cameraPictureSizeMinArea)) { |
|
|
|
|
constraints.add(SizeSelectors.minArea(a.getInteger(R.styleable.CameraView_cameraPictureSizeMinArea, 0))); |
|
|
|
|
pictureConstraints.add(SizeSelectors.minArea(a.getInteger(R.styleable.CameraView_cameraPictureSizeMinArea, 0))); |
|
|
|
|
} |
|
|
|
|
if (a.hasValue(R.styleable.CameraView_cameraPictureSizeMaxArea)) { |
|
|
|
|
constraints.add(SizeSelectors.maxArea(a.getInteger(R.styleable.CameraView_cameraPictureSizeMaxArea, 0))); |
|
|
|
|
pictureConstraints.add(SizeSelectors.maxArea(a.getInteger(R.styleable.CameraView_cameraPictureSizeMaxArea, 0))); |
|
|
|
|
} |
|
|
|
|
if (a.hasValue(R.styleable.CameraView_cameraPictureSizeAspectRatio)) { |
|
|
|
|
//noinspection ConstantConditions
|
|
|
|
|
constraints.add(SizeSelectors.aspectRatio(AspectRatio.parse(a.getString(R.styleable.CameraView_cameraPictureSizeAspectRatio)), 0)); |
|
|
|
|
pictureConstraints.add(SizeSelectors.aspectRatio(AspectRatio.parse(a.getString(R.styleable.CameraView_cameraPictureSizeAspectRatio)), 0)); |
|
|
|
|
} |
|
|
|
|
if (a.getBoolean(R.styleable.CameraView_cameraPictureSizeSmallest, false)) constraints.add(SizeSelectors.smallest()); |
|
|
|
|
if (a.getBoolean(R.styleable.CameraView_cameraPictureSizeBiggest, false)) constraints.add(SizeSelectors.biggest()); |
|
|
|
|
SizeSelector selector = !constraints.isEmpty() ? |
|
|
|
|
SizeSelectors.and(constraints.toArray(new SizeSelector[0])) : |
|
|
|
|
|
|
|
|
|
if (a.getBoolean(R.styleable.CameraView_cameraPictureSizeSmallest, false)) pictureConstraints.add(SizeSelectors.smallest()); |
|
|
|
|
if (a.getBoolean(R.styleable.CameraView_cameraPictureSizeBiggest, false)) pictureConstraints.add(SizeSelectors.biggest()); |
|
|
|
|
SizeSelector pictureSelector = !pictureConstraints.isEmpty() ? |
|
|
|
|
SizeSelectors.and(pictureConstraints.toArray(new SizeSelector[0])) : |
|
|
|
|
SizeSelectors.biggest(); |
|
|
|
|
|
|
|
|
|
// Video size selector
|
|
|
|
|
List<SizeSelector> videoConstraints = new ArrayList<>(3); |
|
|
|
|
if (a.hasValue(R.styleable.CameraView_cameraVideoSizeMinWidth)) { |
|
|
|
|
videoConstraints.add(SizeSelectors.minWidth(a.getInteger(R.styleable.CameraView_cameraVideoSizeMinWidth, 0))); |
|
|
|
|
} |
|
|
|
|
if (a.hasValue(R.styleable.CameraView_cameraVideoSizeMaxWidth)) { |
|
|
|
|
videoConstraints.add(SizeSelectors.maxWidth(a.getInteger(R.styleable.CameraView_cameraVideoSizeMaxWidth, 0))); |
|
|
|
|
} |
|
|
|
|
if (a.hasValue(R.styleable.CameraView_cameraVideoSizeMinHeight)) { |
|
|
|
|
videoConstraints.add(SizeSelectors.minHeight(a.getInteger(R.styleable.CameraView_cameraVideoSizeMinHeight, 0))); |
|
|
|
|
} |
|
|
|
|
if (a.hasValue(R.styleable.CameraView_cameraVideoSizeMaxHeight)) { |
|
|
|
|
videoConstraints.add(SizeSelectors.maxHeight(a.getInteger(R.styleable.CameraView_cameraVideoSizeMaxHeight, 0))); |
|
|
|
|
} |
|
|
|
|
if (a.hasValue(R.styleable.CameraView_cameraVideoSizeMinArea)) { |
|
|
|
|
videoConstraints.add(SizeSelectors.minArea(a.getInteger(R.styleable.CameraView_cameraVideoSizeMinArea, 0))); |
|
|
|
|
} |
|
|
|
|
if (a.hasValue(R.styleable.CameraView_cameraVideoSizeMaxArea)) { |
|
|
|
|
videoConstraints.add(SizeSelectors.maxArea(a.getInteger(R.styleable.CameraView_cameraVideoSizeMaxArea, 0))); |
|
|
|
|
} |
|
|
|
|
if (a.hasValue(R.styleable.CameraView_cameraVideoSizeAspectRatio)) { |
|
|
|
|
//noinspection ConstantConditions
|
|
|
|
|
videoConstraints.add(SizeSelectors.aspectRatio(AspectRatio.parse(a.getString(R.styleable.CameraView_cameraVideoSizeAspectRatio)), 0)); |
|
|
|
|
} |
|
|
|
|
if (a.getBoolean(R.styleable.CameraView_cameraVideoSizeSmallest, false)) videoConstraints.add(SizeSelectors.smallest()); |
|
|
|
|
if (a.getBoolean(R.styleable.CameraView_cameraVideoSizeBiggest, false)) videoConstraints.add(SizeSelectors.biggest()); |
|
|
|
|
SizeSelector videoSelector = !videoConstraints.isEmpty() ? |
|
|
|
|
SizeSelectors.and(videoConstraints.toArray(new SizeSelector[0])) : |
|
|
|
|
SizeSelectors.biggest(); |
|
|
|
|
|
|
|
|
|
// Gestures
|
|
|
|
@ -173,7 +204,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
|
setGrid(grid); |
|
|
|
|
setHdr(hdr); |
|
|
|
|
setAudio(audio); |
|
|
|
|
setPictureSize(selector); |
|
|
|
|
setPictureSize(pictureSelector); |
|
|
|
|
setVideoSize(videoSelector); |
|
|
|
|
setVideoCodec(codec); |
|
|
|
|
setVideoMaxSize(videoMaxSize); |
|
|
|
|
setVideoMaxDuration(videoMaxDuration); |
|
|
|
@ -1003,8 +1035,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Sets picture capture size for picture mode. |
|
|
|
|
* The {@link SizeSelector} will be invoked with the list of available size, and the first |
|
|
|
|
* Sets a capture size selector for picture mode. |
|
|
|
|
* The {@link SizeSelector} will be invoked with the list of available sizes, and the first |
|
|
|
|
* acceptable size will be accepted and passed to the internal engine. |
|
|
|
|
* See the {@link SizeSelectors} class for handy utilities for creating selectors. |
|
|
|
|
* |
|
|
|
@ -1015,6 +1047,19 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Sets a capture size selector for video mode. |
|
|
|
|
* The {@link SizeSelector} will be invoked with the list of available sizes, and the first |
|
|
|
|
* acceptable size will be accepted and passed to the internal engine. |
|
|
|
|
* See the {@link SizeSelectors} class for handy utilities for creating selectors. |
|
|
|
|
* |
|
|
|
|
* @param selector a size selector |
|
|
|
|
*/ |
|
|
|
|
public void setVideoSize(@NonNull SizeSelector selector) { |
|
|
|
|
mCameraController.setVideoSizeSelector(selector); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Adds a {@link CameraListener} instance to be notified of all |
|
|
|
|
* interesting events that happen during the camera lifecycle. |
|
|
|
@ -1204,7 +1249,9 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the size used for pictures taken with {@link #takePicture()}, |
|
|
|
|
* 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), |
|
|
|
|
* or null if we are in video mode. |
|
|
|
|
* |
|
|
|
|
* The size is rotated to match the output orientation. |
|
|
|
|
* |
|
|
|
|
* @return the size of pictures |
|
|
|
@ -1215,6 +1262,21 @@ public class CameraView extends FrameLayout implements LifecycleObserver { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the size used for videos taken with {@link #takeVideo(File)}, |
|
|
|
|
* or null if it hasn't been computed (for example if the surface is not ready), |
|
|
|
|
* or null if we are in picture mode. |
|
|
|
|
* |
|
|
|
|
* The size is rotated to match the output orientation. |
|
|
|
|
* |
|
|
|
|
* @return the size of videos |
|
|
|
|
*/ |
|
|
|
|
@Nullable |
|
|
|
|
public Size getVideoSize() { |
|
|
|
|
return mCameraController.getVideoSize(CameraController.REF_OUTPUT); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If we end up here, we're in M.
|
|
|
|
|
@TargetApi(Build.VERSION_CODES.M) |
|
|
|
|
private void requestPermissions(boolean requestCamera, boolean requestAudio) { |
|
|
|
|