Add to demo app

pull/661/head
Mattia Iavarone 6 years ago
parent f34e52b175
commit 0bd20d1a8b
  1. 1
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java
  2. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera2Engine.java
  3. 11
      demo/src/main/java/com/otaliastudios/cameraview/demo/CameraActivity.java
  4. 43
      demo/src/main/java/com/otaliastudios/cameraview/demo/Option.java

@ -392,6 +392,7 @@ public class Camera1Engine extends CameraEngine implements
// The correct formula seems to be deviceOrientation+displayOffset,
// which means offset(Reference.VIEW, Reference.OUTPUT, Axis.ABSOLUTE).
stub.rotation = getAngles().offset(Reference.VIEW, Reference.OUTPUT, Axis.ABSOLUTE);
stub.videoFrameRate = Math.round(mPreviewFrameRate);
LOG.i("onTakeVideoSnapshot", "rotation:", stub.rotation, "size:", stub.size);
// Start.

@ -814,7 +814,6 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv
if (!(mPreview instanceof GlCameraPreview)) {
throw new IllegalStateException("Video snapshots are only supported with GL_SURFACE.");
}
stub.videoFrameRate = (int) mPreviewFrameRate;
GlCameraPreview glPreview = (GlCameraPreview) mPreview;
Size outputSize = getUncroppedSnapshotSize(Reference.OUTPUT);
if (outputSize == null) {
@ -833,6 +832,7 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv
// Unlike Camera1, the correct formula seems to be deviceOrientation,
// which means offset(Reference.BASE, Reference.OUTPUT, Axis.ABSOLUTE).
stub.rotation = getAngles().offset(Reference.BASE, Reference.OUTPUT, Axis.ABSOLUTE);
stub.videoFrameRate = Math.round(mPreviewFrameRate);
LOG.i("onTakeVideoSnapshot", "rotation:", stub.rotation, "size:", stub.size);
// Start.

@ -116,7 +116,7 @@ public class CameraActivity extends AppCompatActivity implements View.OnClickLis
new Option.Flash(), new Option.WhiteBalance(), new Option.Hdr(),
new Option.PictureMetering(), new Option.PictureSnapshotMetering(),
// Video recording
new Option.VideoCodec(), new Option.Audio(),
new Option.PreviewFrameRate(), new Option.VideoCodec(), new Option.Audio(),
// Gestures
new Option.Pinch(), new Option.HorizontalScroll(), new Option.VerticalScroll(),
new Option.Tap(), new Option.LongTap(),
@ -128,12 +128,19 @@ public class CameraActivity extends AppCompatActivity implements View.OnClickLis
new Option.Grid(), new Option.GridColor(), new Option.UseDeviceOrientation()
);
List<Boolean> dividers = Arrays.asList(
// Layout
false, true,
// Engine and preview
false, false, true,
// Some controls
false, false, false, false, true,
false, true,
// Video recording
false, false, true,
// Gestures
false, false, false, false, true,
// Watermarks
false, false, true,
// Other
false, false, true
);
for (int i = 0; i < options.size(); i++) {

@ -60,7 +60,7 @@ public abstract class Option<T> {
@Override
public Collection<Integer> getAll(@NonNull CameraView view, @NonNull CameraOptions options) {
View root = (View) view.getParent();
ArrayList<Integer> list = new ArrayList<>();
List<Integer> list = new ArrayList<>();
int boundary = root.getWidth();
if (boundary == 0) boundary = 1000;
int step = boundary / 10;
@ -506,4 +506,45 @@ public abstract class Option<T> {
view.setUseDeviceOrientation(value);
}
}
public static class PreviewFrameRate extends Option<Integer> {
public PreviewFrameRate() {
super("Preview FPS");
}
@NonNull
@Override
public Collection<Integer> getAll(@NonNull CameraView view, @NonNull CameraOptions options) {
float min = options.getPreviewFrameRateMinValue();
float max = options.getPreviewFrameRateMaxValue();
float delta = max - min;
List<Integer> result = new ArrayList<>();
if (min == 0F && max == 0F) {
return result; // empty list
} else if (delta < 0.005F) {
result.add(Math.round(min));
return result; // single value
} else {
final int steps = 3;
final float step = delta / steps;
for (int i = 0; i <= steps; i++) {
result.add(Math.round(min));
min += step;
}
return result;
}
}
@NonNull
@Override
public Integer get(@NonNull CameraView view) {
return Math.round(view.getPreviewFrameRate());
}
@Override
public void set(@NonNull CameraView view, @NonNull Integer value) {
view.setPreviewFrameRate((float) value);
}
}
}

Loading…
Cancel
Save