diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
index 018edf96..96905f8f 100644
--- a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
+++ b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
@@ -299,12 +299,10 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
@Override
public LayoutParams generateLayoutParams(AttributeSet attributeSet) {
- TypedArray a = getContext().obtainStyledAttributes(attributeSet, R.styleable.CameraView_Layout);
- if (a.getBoolean(R.styleable.CameraView_Layout_layout_isOverlay, false)) {
- a.recycle();
- return new OverlayLayoutParams(this.getContext(), attributeSet);
+ OverlayLayoutParams toBeChecked = new OverlayLayoutParams(this.getContext(), attributeSet);
+ if (toBeChecked.isOverlay()) {
+ return toBeChecked;
}
- a.recycle();
return super.generateLayoutParams(attributeSet);
}
@@ -1865,7 +1863,9 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
public static class OverlayLayoutParams extends FrameLayout.LayoutParams {
- private boolean isOverlay = false;
+ private boolean drawInPreview = false;
+ private boolean drawInPictureSnapshot = false;
+ private boolean drawInVideoSnapshot = false;
public OverlayLayoutParams(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
@@ -1883,18 +1883,40 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
private void readStyleParameters(Context context, AttributeSet attributeSet) {
TypedArray a = context.obtainStyledAttributes(attributeSet, R.styleable.CameraView_Layout);
try {
- this.isOverlay = a.getBoolean(R.styleable.CameraView_Layout_layout_isOverlay, false);
+ this.drawInPreview = a.getBoolean(R.styleable.CameraView_Layout_layout_drawInPreview, false);
+ this.drawInPictureSnapshot = a.getBoolean(R.styleable.CameraView_Layout_layout_drawInPictureSnapshot, false);
+ this.drawInVideoSnapshot = a.getBoolean(R.styleable.CameraView_Layout_layout_drawInVideoSnapshot, false);
} finally {
a.recycle();
}
}
- public boolean isOverlay() {
- return isOverlay;
+ public boolean isDrawInPreview() {
+ return drawInPreview;
+ }
+
+ public void setDrawInPreview(boolean drawInPreview) {
+ this.drawInPreview = drawInPreview;
}
- public void setOverlay(boolean overlay) {
- isOverlay = overlay;
+ public boolean isDrawInPictureSnapshot() {
+ return drawInPictureSnapshot;
+ }
+
+ public void setDrawInPictureSnapshot(boolean drawInPictureSnapshot) {
+ this.drawInPictureSnapshot = drawInPictureSnapshot;
+ }
+
+ public boolean isDrawInVideoSnapshot() {
+ return drawInVideoSnapshot;
+ }
+
+ public void setDrawInVideoSnapshot(boolean drawInVideoSnapshot) {
+ this.drawInVideoSnapshot = drawInVideoSnapshot;
+ }
+
+ public boolean isOverlay() {
+ return drawInPreview || drawInPictureSnapshot || drawInVideoSnapshot;
}
}
diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/OverlayLayout.java b/cameraview/src/main/java/com/otaliastudios/cameraview/OverlayLayout.java
index e2b553c9..b38d5f49 100644
--- a/cameraview/src/main/java/com/otaliastudios/cameraview/OverlayLayout.java
+++ b/cameraview/src/main/java/com/otaliastudios/cameraview/OverlayLayout.java
@@ -26,7 +26,7 @@ class OverlayLayout extends FrameLayout implements SurfaceDrawer {
}
@Override
- public void drawOnSurface(Surface outputSurface) {
+ public void drawOnSurfaceForPictureSnapshot(Surface outputSurface) {
try {
final Canvas surfaceCanvas = outputSurface.lockCanvas(null);
@@ -34,11 +34,49 @@ class OverlayLayout extends FrameLayout implements SurfaceDrawer {
float yScale = surfaceCanvas.getHeight() / (float) getHeight();
surfaceCanvas.scale(xScale, yScale);
surfaceCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
- super.draw(surfaceCanvas);
+
+ for (int i = 0; i < getChildCount(); i++) {
+ View child = getChildAt(i);
+ if (((CameraView.OverlayLayoutParams) child.getLayoutParams()).isDrawInPictureSnapshot()) {
+ drawChild(surfaceCanvas, child, getDrawingTime());
+ }
+ }
+
+ outputSurface.unlockCanvasAndPost(surfaceCanvas);
+ } catch (Surface.OutOfResourcesException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void drawOnSurfaceForVideoSnapshot(Surface outputSurface) {
+ try {
+ final Canvas surfaceCanvas = outputSurface.lockCanvas(null);
+
+ float xScale = surfaceCanvas.getWidth() / (float) getWidth();
+ float yScale = surfaceCanvas.getHeight() / (float) getHeight();
+ surfaceCanvas.scale(xScale, yScale);
+ surfaceCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
+
+ for (int i = 0; i < getChildCount(); i++) {
+ View child = getChildAt(i); if (((CameraView.OverlayLayoutParams) child.getLayoutParams()).isDrawInVideoSnapshot()) {
+ drawChild(surfaceCanvas, child, getDrawingTime());
+ }
+ }
outputSurface.unlockCanvasAndPost(surfaceCanvas);
} catch (Surface.OutOfResourcesException e) {
e.printStackTrace();
}
}
+
+ @Override
+ public void draw(Canvas canvas) {
+ for (int i = 0; i < getChildCount(); i++) {
+ View child = getChildAt(i); if (((CameraView.OverlayLayoutParams) child.getLayoutParams()).isDrawInPreview()) {
+ drawChild(canvas, child, getDrawingTime());
+ }
+ }
+ }
+
}
diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotPictureRecorder.java b/cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotPictureRecorder.java
index 05a6eaa4..f7a817c1 100644
--- a/cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotPictureRecorder.java
+++ b/cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotPictureRecorder.java
@@ -134,7 +134,7 @@ class SnapshotPictureRecorder extends PictureRecorder {
Surface drawOnto = new Surface(mOverlaySurfaceTexture);
if (mWithOverlay) {
for (SurfaceDrawer surfaceDrawer : mSurfaceDrawerList) {
- surfaceDrawer.drawOnSurface(drawOnto);
+ surfaceDrawer.drawOnSurfaceForPictureSnapshot(drawOnto);
}
mOverlaySurfaceTexture.updateTexImage();
mOverlaySurfaceTexture.getTransformMatrix(mOverlayTransform);
diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotVideoRecorder.java b/cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotVideoRecorder.java
index 8a839d8d..6e45703f 100644
--- a/cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotVideoRecorder.java
+++ b/cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotVideoRecorder.java
@@ -131,7 +131,7 @@ class SnapshotVideoRecorder extends VideoRecorder implements GlCameraPreview.Ren
// get overlay
if (mOverlaySurfaceTexture != null) {
for (SurfaceDrawer surfaceDrawer : mSurfaceDrawerList) {
- surfaceDrawer.drawOnSurface(mOverlaySurface);
+ surfaceDrawer.drawOnSurfaceForVideoSnapshot(mOverlaySurface);
}
mOverlaySurfaceTexture.updateTexImage();
mOverlaySurfaceTexture.getTransformMatrix(textureFrame.overlayTransform);
diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/SurfaceDrawer.java b/cameraview/src/main/java/com/otaliastudios/cameraview/SurfaceDrawer.java
index 8250405c..d1a0973a 100644
--- a/cameraview/src/main/java/com/otaliastudios/cameraview/SurfaceDrawer.java
+++ b/cameraview/src/main/java/com/otaliastudios/cameraview/SurfaceDrawer.java
@@ -3,5 +3,6 @@ package com.otaliastudios.cameraview;
import android.view.Surface;
interface SurfaceDrawer {
- void drawOnSurface(Surface surface);
+ void drawOnSurfaceForPictureSnapshot(Surface surface);
+ void drawOnSurfaceForVideoSnapshot(Surface surface);
}
diff --git a/cameraview/src/main/res/values/attrs.xml b/cameraview/src/main/res/values/attrs.xml
index 428e7c3e..6b1287e0 100644
--- a/cameraview/src/main/res/values/attrs.xml
+++ b/cameraview/src/main/res/values/attrs.xml
@@ -128,7 +128,9 @@
-
+
+
+
\ No newline at end of file
diff --git a/demo/src/main/res/layout/activity_camera.xml b/demo/src/main/res/layout/activity_camera.xml
index 0fc69548..e9397297 100644
--- a/demo/src/main/res/layout/activity_camera.xml
+++ b/demo/src/main/res/layout/activity_camera.xml
@@ -33,7 +33,9 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom|end"
- app:layout_isOverlay="true"
+ app:layout_drawInPreview="false"
+ app:layout_drawInVideoSnapshot="true"
+ app:layout_drawInPictureSnapshot="true"
android:gravity="center"
android:padding="8dp"
>
@@ -54,6 +56,16 @@
+
+