Moved Grid to enums

pull/1/head
Mattia Iavarone 7 years ago
parent c122fbe80e
commit 776238a5df
  1. 20
      README.md
  2. 8
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraConstants.java
  3. 14
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  4. 2
      cameraview/src/main/options/com/otaliastudios/cameraview/Facing.java
  5. 2
      cameraview/src/main/options/com/otaliastudios/cameraview/Flash.java
  6. 58
      cameraview/src/main/options/com/otaliastudios/cameraview/Grid.java
  7. 6
      cameraview/src/main/res/values/attrs.xml
  8. 17
      cameraview/src/main/views/com/otaliastudios/cameraview/GridLinesLayout.java
  9. 11
      demo/src/main/java/com/otaliastudios/cameraview/demo/MainActivity.java

@ -294,7 +294,7 @@ Most camera parameters can be controlled through XML attributes or linked method
|[`cameraSessionType`](#camerasessiontype)|`setSessionType()`|`picture` `video`|`picture`|
|[`cameraFacing`](#camerafacing)|`setFacing()`|`back` `front`|`back`|
|[`cameraFlash`](#cameraflash)|`setFlash()`|`off` `on` `auto` `torch`|`off`|
|[`cameraGrid`](#cameragrid)|`setGrid()`|`off` `grid3x3` `grid4x4` `phi`|`off`|
|[`cameraGrid`](#cameragrid)|`setGrid()`|`off` `draw3x3` `draw4x4` `drawPhi`|`off`|
|[`cameraCropOutput`](#cameracropoutput)|`setCropOutput()`|`true` `false`|`false`|
|[`cameraJpegQuality`](#camerajpegquality)|`setJpegQuality()`|`0 <= n <= 100`|`100`|
|[`cameraVideoQuality`](#cameravideoquality)|`setVideoQuality()`|`max480p` `max720p` `max1080p` `max2160p` `highest` `lowest`|`max480p`|
@ -328,21 +328,21 @@ cameraView.setFacing(Facing.FRONT);
Flash mode, either off, on, auto or *torch*.
```java
cameraView.setFlash(CameraConstants.FLASH_OFF);
cameraView.setFlash(CameraConstants.FLASH_ON);
cameraView.setFlash(CameraConstants.FLASH_AUTO);
cameraView.setFlash(CameraConstants.FLASH_TORCH);
cameraView.setFlash(Flash.OFF);
cameraView.setFlash(Flash.ON);
cameraView.setFlash(Flash.AUTO);
cameraView.setFlash(Flash.TORCH);
```
#### cameraGrid
Lets you draw grids over the camera preview. Supported values are `off`, `grid3x3` and `grid4x4` for regular grids, and `phi` for a grid based on the golden ratio constant, often used in photography.
Lets you draw grids over the camera preview. Supported values are `off`, `draw3x3` and `draw4x4` for regular grids, and `drawPhi` for a grid based on the golden ratio constant, often used in photography.
```java
cameraView.setGrid(CameraConstants.GRID_OFF);
cameraView.setGrid(CameraConstants.GRID_3X3);
cameraView.setGrid(CameraConstants.GRID_4X4);
cameraView.setGrid(CameraConstants.GRID_PHI);
cameraView.setGrid(Grid.OFF);
cameraView.setGrid(Grid.DRAW_3X3);
cameraView.setGrid(Grid.DRAW_4X4);
cameraView.setGrid(Grid.DRAW_PHI);
```
#### cameraCropOutput

@ -5,11 +5,6 @@ public class CameraConstants {
public static final int PERMISSION_REQUEST_CODE = 16;
public static final int GRID_OFF = 0;
public static final int GRID_3X3 = 1;
public static final int GRID_4X4 = 2;
public static final int GRID_PHI = 3;
public static final int SESSION_TYPE_PICTURE = 0;
public static final int SESSION_TYPE_VIDEO = 1;
@ -30,13 +25,10 @@ public class CameraConstants {
static class Defaults {
// TODO: Move to enum classes
static final int DEFAULT_VIDEO_QUALITY = VIDEO_QUALITY_480P;
static final int DEFAULT_WHITE_BALANCE = WHITE_BALANCE_AUTO;
static final int DEFAULT_SESSION_TYPE = SESSION_TYPE_PICTURE;
static final int DEFAULT_JPEG_QUALITY = 100;
static final int DEFAULT_GRID = GRID_OFF;
static final boolean DEFAULT_CROP_OUTPUT = false;

@ -94,10 +94,10 @@ public class CameraView extends FrameLayout {
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CameraView, 0, 0);
Facing facing = Facing.fromValue(a.getInteger(R.styleable.CameraView_cameraFacing, Facing.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()));
int sessionType = a.getInteger(R.styleable.CameraView_cameraSessionType, Defaults.DEFAULT_SESSION_TYPE);
int whiteBalance = a.getInteger(R.styleable.CameraView_cameraWhiteBalance, Defaults.DEFAULT_WHITE_BALANCE);
int videoQuality = a.getInteger(R.styleable.CameraView_cameraVideoQuality, Defaults.DEFAULT_VIDEO_QUALITY);
int grid = a.getInteger(R.styleable.CameraView_cameraGrid, Defaults.DEFAULT_GRID);
mJpegQuality = a.getInteger(R.styleable.CameraView_cameraJpegQuality, Defaults.DEFAULT_JPEG_QUALITY);
mCropOutput = a.getBoolean(R.styleable.CameraView_cameraCropOutput, Defaults.DEFAULT_CROP_OUTPUT);
GestureAction tapGesture = GestureAction.fromValue(a.getInteger(R.styleable.CameraView_cameraGestureTap, GestureAction.DEFAULT_TAP.value()));
@ -621,13 +621,14 @@ public class CameraView extends FrameLayout {
/**
* Controls the grids to be drawn over the current layout.
*
* @see CameraConstants#GRID_OFF
* @see CameraConstants#GRID_3X3
* @see CameraConstants#GRID_4X4
* @see Grid#OFF
* @see Grid#DRAW_3X3
* @see Grid#DRAW_4X4
* @see Grid#DRAW_PHI
*
* @param gridMode desired grid mode
*/
public void setGrid(@Grid int gridMode) {
public void setGrid(Grid gridMode) {
mGridLinesLayout.setGridMode(gridMode);
}
@ -636,8 +637,7 @@ public class CameraView extends FrameLayout {
* Gets the current grid mode.
* @return the current grid mode
*/
@Grid
public int getGrid() {
public Grid getGrid() {
return mGridLinesLayout.getGridMode();
}

@ -4,7 +4,7 @@ package com.otaliastudios.cameraview;
/**
* Facing value indicates which camera sensor should be used for the current session.
*
* @see CameraView#setFacing(int)
* @see CameraView#setFacing(Facing)
*/
public enum Facing {

@ -4,7 +4,7 @@ package com.otaliastudios.cameraview;
/**
* Flash value indicates the flash mode to be used.
*
* @see CameraView#setFlash(int)
* @see CameraView#setFlash(Flash)
*/
public enum Flash {

@ -1,16 +1,54 @@
package com.otaliastudios.cameraview;
import android.support.annotation.IntDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Grid values can be used to draw grid lines over the camera preview.
*
* @see CameraView#setGrid(Grid)
*/
public enum Grid {
import static com.otaliastudios.cameraview.CameraConstants.GRID_OFF;
import static com.otaliastudios.cameraview.CameraConstants.GRID_3X3;
import static com.otaliastudios.cameraview.CameraConstants.GRID_4X4;
import static com.otaliastudios.cameraview.CameraConstants.GRID_PHI;
@IntDef({GRID_OFF, GRID_3X3, GRID_4X4, GRID_PHI})
@Retention(RetentionPolicy.SOURCE)
public @interface Grid {
/**
* No grid is drawn.
*/
OFF(0),
/**
* Draws a regular, 3x3 grid.
*/
DRAW_3X3(1),
/**
* Draws a regular, 4x4 grid.
*/
DRAW_4X4(2),
/**
* Draws a grid respecting the 'phi' constant proportions,
* often referred as to the golden ratio.
*/
DRAW_PHI(3);
static final Grid DEFAULT = OFF;
private int value;
Grid(int value) {
this.value = value;
}
int value() {
return value;
}
static Grid fromValue(int value) {
Grid[] list = Grid.values();
for (Grid action : list) {
if (action.value() == value) {
return action;
}
}
return null;
}
}

@ -49,9 +49,9 @@
<attr name="cameraGrid" format="enum">
<enum name="off" value="0" />
<enum name="grid3x3" value="1" />
<enum name="grid4x4" value="2" />
<enum name="phi" value="3" />
<enum name="draw3x3" value="1" />
<enum name="draw4x4" value="2" />
<enum name="drawPhi" value="3" />
</attr>
<attr name="cameraSessionType" format="enum">

@ -14,7 +14,7 @@ import android.view.View;
// TODO animate lines!
class GridLinesLayout extends View {
@Grid private int gridMode;
private Grid gridMode;
private final Drawable horiz;
private final Drawable vert;
@ -40,29 +40,28 @@ class GridLinesLayout extends View {
vert.setBounds(0, top, (int) width, bottom);
}
@Grid
public int getGridMode() {
public Grid getGridMode() {
return gridMode;
}
public void setGridMode(@Grid int gridMode) {
public void setGridMode(Grid gridMode) {
this.gridMode = gridMode;
invalidate();
}
private int getLineCount() {
switch (gridMode) {
case CameraConstants.GRID_OFF: return 0;
case CameraConstants.GRID_3X3: return 2;
case CameraConstants.GRID_PHI: return 2;
case CameraConstants.GRID_4X4: return 3;
case OFF: return 0;
case DRAW_3X3: return 2;
case DRAW_PHI: return 2;
case DRAW_4X4: return 3;
}
return 0;
}
private float getLinePosition(int lineNumber) {
int lineCount = getLineCount();
if (gridMode == CameraConstants.GRID_PHI) {
if (gridMode == Grid.DRAW_PHI) {
// 1 = 2x + GRIx
// 1 = x(2+GRI)
// x = 1/(2+GRI)

@ -17,6 +17,7 @@ import com.otaliastudios.cameraview.CameraConstants;
import com.otaliastudios.cameraview.CameraListener;
import com.otaliastudios.cameraview.CameraView;
import com.otaliastudios.cameraview.Facing;
import com.otaliastudios.cameraview.Grid;
import com.otaliastudios.cameraview.Size;
import java.io.File;
@ -256,12 +257,12 @@ public class MainActivity extends AppCompatActivity implements View.OnLayoutChan
RadioGroup.OnCheckedChangeListener gridModeChangedListener = new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
int grid = CameraConstants.GRID_OFF;
Grid grid = Grid.OFF;
switch (checkedId) {
case R.id.gridModeOff: grid = CameraConstants.GRID_OFF; break;
case R.id.gridMode3x3: grid = CameraConstants.GRID_3X3; break;
case R.id.gridMode4x4: grid = CameraConstants.GRID_4X4; break;
case R.id.gridModeGolden: grid = CameraConstants.GRID_PHI; break;
case R.id.gridModeOff: grid = Grid.OFF; break;
case R.id.gridMode3x3: grid = Grid.DRAW_3X3; break;
case R.id.gridMode4x4: grid = Grid.DRAW_4X4; break;
case R.id.gridModeGolden: grid = Grid.DRAW_PHI; break;
}
camera.setGrid(grid);
message("Grid mode changed!", false);

Loading…
Cancel
Save