Add gridColor option

pull/360/head
Mattia Iavarone 6 years ago
parent ddf7c960c3
commit 437838056c
  1. 15
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  2. 2
      cameraview/src/main/res/values/attrs.xml
  3. 14
      cameraview/src/main/views/com/otaliastudios/cameraview/GridLinesLayout.java

@ -20,6 +20,7 @@ import android.media.MediaActionSound;
import android.os.Build; import android.os.Build;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.AttributeSet; 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())); 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())); 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())); 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())); 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())); 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())); 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); setMode(mode);
setWhiteBalance(whiteBalance); setWhiteBalance(whiteBalance);
setGrid(grid); setGrid(grid);
setGridColor(gridColor);
setHdr(hdr); setHdr(hdr);
setAudio(audio); setAudio(audio);
setAudioBitRate(audioBitRate); 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. * Controls the grids to be drawn over the current layout.
* *
@ -825,6 +839,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
mCameraController.setHdr(hdr); mCameraController.setHdr(hdr);
} }
/** /**
* Controls the preview engine. Should only be called * Controls the preview engine. Should only be called
* if this CameraView was never added to any window * if this CameraView was never added to any window

@ -89,6 +89,8 @@
<enum name="drawPhi" value="3" /> <enum name="drawPhi" value="3" />
</attr> </attr>
<attr name="cameraGridColor" format="color|reference"/>
<attr name="cameraMode" format="enum"> <attr name="cameraMode" format="enum">
<enum name="picture" value="0" /> <enum name="picture" value="0" />
<enum name="video" value="1" /> <enum name="video" value="1" />

@ -5,13 +5,13 @@ import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.View; import android.view.View;
// TODO animate lines!
class GridLinesLayout extends View { class GridLinesLayout extends View {
private Grid gridMode; private Grid gridMode;
@ -24,14 +24,16 @@ class GridLinesLayout extends View {
private final static float GOLDEN_RATIO_INV = 0.61803398874989f; 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) { public GridLinesLayout(@NonNull Context context) {
this(context, null); this(context, null);
} }
public GridLinesLayout(@NonNull Context context, @Nullable AttributeSet attrs) { public GridLinesLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs); super(context, attrs);
horiz = new ColorDrawable(Color.WHITE); horiz.setAlpha(160); horiz = new ColorDrawable(DEFAULT_COLOR);
vert = new ColorDrawable(Color.WHITE); vert.setAlpha(160); vert = new ColorDrawable(DEFAULT_COLOR);
width = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0.9f, context.getResources().getDisplayMetrics()); width = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0.9f, context.getResources().getDisplayMetrics());
} }
@ -51,6 +53,12 @@ class GridLinesLayout extends View {
postInvalidate(); postInvalidate();
} }
public void setGridColor(@ColorInt int gridColor) {
horiz = new ColorDrawable(gridColor);
vert = new ColorDrawable(gridColor);
postInvalidate();
}
private int getLineCount() { private int getLineCount() {
switch (gridMode) { switch (gridMode) {
case OFF: return 0; case OFF: return 0;

Loading…
Cancel
Save