From 437838056c51d698f57906add71dcd0b31ad9b2d Mon Sep 17 00:00:00 2001 From: Mattia Iavarone Date: Thu, 20 Sep 2018 15:54:48 -0300 Subject: [PATCH] Add gridColor option --- .../com/otaliastudios/cameraview/CameraView.java | 15 +++++++++++++++ cameraview/src/main/res/values/attrs.xml | 2 ++ .../otaliastudios/cameraview/GridLinesLayout.java | 14 +++++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java index f22ba58d..dfed2b37 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java @@ -20,6 +20,7 @@ import android.media.MediaActionSound; import android.os.Build; import android.os.Handler; import android.os.Looper; +import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.AttributeSet; @@ -102,6 +103,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver { Facing facing = Facing.fromValue(a.getInteger(R.styleable.CameraView_cameraFacing, Facing.DEFAULT(context).value())); Flash flash = Flash.fromValue(a.getInteger(R.styleable.CameraView_cameraFlash, Flash.DEFAULT.value())); Grid grid = Grid.fromValue(a.getInteger(R.styleable.CameraView_cameraGrid, Grid.DEFAULT.value())); + int gridColor = a.getColor(R.styleable.CameraView_cameraGrid, GridLinesLayout.DEFAULT_COLOR); WhiteBalance whiteBalance = WhiteBalance.fromValue(a.getInteger(R.styleable.CameraView_cameraWhiteBalance, WhiteBalance.DEFAULT.value())); Mode mode = Mode.fromValue(a.getInteger(R.styleable.CameraView_cameraMode, Mode.DEFAULT.value())); Hdr hdr = Hdr.fromValue(a.getInteger(R.styleable.CameraView_cameraHdr, Hdr.DEFAULT.value())); @@ -207,6 +209,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver { setMode(mode); setWhiteBalance(whiteBalance); setGrid(grid); + setGridColor(gridColor); setHdr(hdr); setAudio(audio); setAudioBitRate(audioBitRate); @@ -813,6 +816,17 @@ public class CameraView extends FrameLayout implements LifecycleObserver { } + /** + * Controls the color of the grid lines that will be drawn + * over the current layout. + * + * @param color a resolved color + */ + public void setGridColor(@ColorInt int color) { + mGridLinesLayout.setGridColor(color); + } + + /** * Controls the grids to be drawn over the current layout. * @@ -825,6 +839,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver { mCameraController.setHdr(hdr); } + /** * Controls the preview engine. Should only be called * if this CameraView was never added to any window diff --git a/cameraview/src/main/res/values/attrs.xml b/cameraview/src/main/res/values/attrs.xml index 9b7a4864..45a559ab 100644 --- a/cameraview/src/main/res/values/attrs.xml +++ b/cameraview/src/main/res/values/attrs.xml @@ -89,6 +89,8 @@ + + diff --git a/cameraview/src/main/views/com/otaliastudios/cameraview/GridLinesLayout.java b/cameraview/src/main/views/com/otaliastudios/cameraview/GridLinesLayout.java index c84cdcae..3ab0e9f9 100644 --- a/cameraview/src/main/views/com/otaliastudios/cameraview/GridLinesLayout.java +++ b/cameraview/src/main/views/com/otaliastudios/cameraview/GridLinesLayout.java @@ -5,13 +5,13 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; +import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.util.TypedValue; import android.view.View; -// TODO animate lines! class GridLinesLayout extends View { private Grid gridMode; @@ -24,14 +24,16 @@ class GridLinesLayout extends View { private final static float GOLDEN_RATIO_INV = 0.61803398874989f; + public final static int DEFAULT_COLOR = Color.argb(160, 255, 255, 255); + public GridLinesLayout(@NonNull Context context) { this(context, null); } public GridLinesLayout(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); - horiz = new ColorDrawable(Color.WHITE); horiz.setAlpha(160); - vert = new ColorDrawable(Color.WHITE); vert.setAlpha(160); + horiz = new ColorDrawable(DEFAULT_COLOR); + vert = new ColorDrawable(DEFAULT_COLOR); width = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0.9f, context.getResources().getDisplayMetrics()); } @@ -51,6 +53,12 @@ class GridLinesLayout extends View { postInvalidate(); } + public void setGridColor(@ColorInt int gridColor) { + horiz = new ColorDrawable(gridColor); + vert = new ColorDrawable(gridColor); + postInvalidate(); + } + private int getLineCount() { switch (gridMode) { case OFF: return 0;