Small refactoring

pull/806/head
alexander.melnikov 5 years ago
parent f70ee53a33
commit 17439581a9
  1. 5
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  2. 26
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java
  3. 16
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraBaseEngine.java

@ -870,6 +870,11 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
mExperimental = experimental; mExperimental = experimental;
} }
/**
* Sets the flag if you want disable restart camera on change mode (Photo/Video),
* but only for {@link Engine#CAMERA1}
* @param changeModeWithoutRestart - true if you want disable restart
*/
public void setChangeModeWithoutRestart(boolean changeModeWithoutRestart) { public void setChangeModeWithoutRestart(boolean changeModeWithoutRestart) {
mChangeModeWithoutRestart = changeModeWithoutRestart; mChangeModeWithoutRestart = changeModeWithoutRestart;
} }

@ -150,18 +150,7 @@ public class Camera1Engine extends CameraBaseEngine implements
protected void prepareNewMode() { protected void prepareNewMode() {
mCaptureSize = computeCaptureSize(); mCaptureSize = computeCaptureSize();
Camera.Parameters params = mCamera.getParameters(); Camera.Parameters params = mCamera.getParameters();
if (getMode() == Mode.PICTURE) { setPictureSize(params);
// setPictureSize is allowed during preview
params.setPictureSize(mCaptureSize.getWidth(), mCaptureSize.getHeight());
} else {
// mCaptureSize in this case is a video size. The available video sizes are not
// necessarily a subset of the picture sizes, so we can't use the mCaptureSize value:
// it might crash. However, the setPictureSize() passed here is useless : we don't allow
// HQ pictures in video mode.
// While this might be lifted in the future, for now, just use a picture capture size.
Size pictureSize = computeCaptureSize(Mode.PICTURE);
params.setPictureSize(pictureSize.getWidth(), pictureSize.getHeight());
}
applyDefaultFocus(params); applyDefaultFocus(params);
params.setRecordingHint(getMode() == Mode.VIDEO); params.setRecordingHint(getMode() == Mode.VIDEO);
mCamera.setParameters(params); mCamera.setParameters(params);
@ -238,18 +227,7 @@ public class Camera1Engine extends CameraBaseEngine implements
params.setPreviewFormat(ImageFormat.NV21); params.setPreviewFormat(ImageFormat.NV21);
// setPreviewSize is not allowed during preview // setPreviewSize is not allowed during preview
params.setPreviewSize(mPreviewStreamSize.getWidth(), mPreviewStreamSize.getHeight()); params.setPreviewSize(mPreviewStreamSize.getWidth(), mPreviewStreamSize.getHeight());
if (getMode() == Mode.PICTURE) { setPictureSize(params);
// setPictureSize is allowed during preview
params.setPictureSize(mCaptureSize.getWidth(), mCaptureSize.getHeight());
} else {
// mCaptureSize in this case is a video size. The available video sizes are not
// necessarily a subset of the picture sizes, so we can't use the mCaptureSize value:
// it might crash. However, the setPictureSize() passed here is useless : we don't allow
// HQ pictures in video mode.
// While this might be lifted in the future, for now, just use a picture capture size.
Size pictureSize = computeCaptureSize(Mode.PICTURE);
params.setPictureSize(pictureSize.getWidth(), pictureSize.getHeight());
}
mCamera.setParameters(params); mCamera.setParameters(params);
mCamera.setPreviewCallbackWithBuffer(null); // Release anything left mCamera.setPreviewCallbackWithBuffer(null); // Release anything left

@ -2,6 +2,7 @@ package com.otaliastudios.cameraview.engine;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.RectF; import android.graphics.RectF;
import android.hardware.Camera;
import android.location.Location; import android.location.Location;
import androidx.annotation.CallSuper; import androidx.annotation.CallSuper;
@ -756,6 +757,21 @@ public abstract class CameraBaseEngine extends CameraEngine {
: preview.getSurfaceSize(); : preview.getSurfaceSize();
} }
void setPictureSize(Camera.Parameters params) {
if (getMode() == Mode.PICTURE) {
// setPictureSize is allowed during preview
params.setPictureSize(mCaptureSize.getWidth(), mCaptureSize.getHeight());
} else {
// mCaptureSize in this case is a video size. The available video sizes are not
// necessarily a subset of the picture sizes, so we can't use the mCaptureSize value:
// it might crash. However, the setPictureSize() passed here is useless : we don't allow
// HQ pictures in video mode.
// While this might be lifted in the future, for now, just use a picture capture size.
Size pictureSize = computeCaptureSize(Mode.PICTURE);
params.setPictureSize(pictureSize.getWidth(), pictureSize.getHeight());
}
}
/** /**
* Returns the snapshot size, but not cropped with the view dimensions, which * Returns the snapshot size, but not cropped with the view dimensions, which
* is what we will do before creating the snapshot. However, cropping is done at various * is what we will do before creating the snapshot. However, cropping is done at various

Loading…
Cancel
Save