Moved WhiteBalance to enums

pull/1/head
Mattia Iavarone 7 years ago
parent 776238a5df
commit 324f0c8a47
  1. 8
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java
  2. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera2.java
  3. 10
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraConstants.java
  4. 18
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java
  5. 16
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraOptions.java
  6. 17
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  7. 25
      cameraview/src/main/java/com/otaliastudios/cameraview/Mapper.java
  8. 79
      cameraview/src/main/options/com/otaliastudios/cameraview/WhiteBalance.java

@ -145,7 +145,7 @@ class Camera1 extends CameraController {
applyDefaultFocus(params);
mergeFlash(params, Flash.DEFAULT);
mergeLocation(params, 0d, 0d);
mergeWhiteBalance(params, CameraConstants.Defaults.DEFAULT_WHITE_BALANCE);
mergeWhiteBalance(params, WhiteBalance.DEFAULT);
params.setRecordingHint(mSessionType == SESSION_TYPE_VIDEO);
mCamera.setParameters(params);
}
@ -250,8 +250,8 @@ class Camera1 extends CameraController {
}
@Override
void setWhiteBalance(@WhiteBalance int whiteBalance) {
int old = mWhiteBalance;
void setWhiteBalance(WhiteBalance whiteBalance) {
WhiteBalance old = mWhiteBalance;
mWhiteBalance = whiteBalance;
if (isCameraOpened()) {
synchronized (mLock) {
@ -261,7 +261,7 @@ class Camera1 extends CameraController {
}
}
private boolean mergeWhiteBalance(Camera.Parameters params, @WhiteBalance int oldWhiteBalance) {
private boolean mergeWhiteBalance(Camera.Parameters params, WhiteBalance oldWhiteBalance) {
if (mOptions.getSupportedWhiteBalance().contains(mWhiteBalance)) {
params.setWhiteBalance((String) mMapper.mapWhiteBalance(mWhiteBalance));
return true;

@ -152,7 +152,7 @@ class Camera2 extends CameraController {
}
@Override
void setWhiteBalance(@WhiteBalance int whiteBalance) {
void setWhiteBalance(WhiteBalance whiteBalance) {
}

@ -1,6 +1,8 @@
package com.otaliastudios.cameraview;
import android.hardware.Camera;
public class CameraConstants {
public static final int PERMISSION_REQUEST_CODE = 16;
@ -16,17 +18,9 @@ public class CameraConstants {
public static final int VIDEO_QUALITY_LOWEST = 5;
public static final int VIDEO_QUALITY_QVGA = 6;
public static final int WHITE_BALANCE_AUTO = 0;
public static final int WHITE_BALANCE_INCANDESCENT = 1;
public static final int WHITE_BALANCE_FLUORESCENT = 2;
public static final int WHITE_BALANCE_DAYLIGHT = 3;
public static final int WHITE_BALANCE_CLOUDY = 4;
static class Defaults {
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 boolean DEFAULT_CROP_OUTPUT = false;

@ -13,8 +13,8 @@ abstract class CameraController implements Preview.SurfaceCallback {
protected Facing mFacing;
protected Flash mFlash;
protected WhiteBalance mWhiteBalance;
@VideoQuality protected int mVideoQuality;
@WhiteBalance protected int mWhiteBalance;
@SessionType protected int mSessionType;
CameraController(CameraView.CameraCallbacks callback, Preview preview) {
@ -33,8 +33,8 @@ abstract class CameraController implements Preview.SurfaceCallback {
abstract boolean setExposureCorrection(float EVvalue);
abstract void setFacing(Facing facing);
abstract void setFlash(Flash flash);
abstract void setWhiteBalance(WhiteBalance whiteBalance);
abstract void setVideoQuality(@VideoQuality int videoQuality);
abstract void setWhiteBalance(@WhiteBalance int whiteBalance);
abstract void setSessionType(@SessionType int sessionType);
abstract void setLocation(double latitude, double longitude);
@ -53,17 +53,9 @@ abstract class CameraController implements Preview.SurfaceCallback {
@Nullable abstract ExtraProperties getExtraProperties();
@Nullable abstract CameraOptions getCameraOptions();
final Facing getFacing() {
return mFacing;
}
final Flash getFlash() {
return mFlash;
}
@WhiteBalance
final int getWhiteBalance() {
return mWhiteBalance;
}
final Facing getFacing() { return mFacing; }
final Flash getFlash() { return mFlash; }
final WhiteBalance getWhiteBalance() { return mWhiteBalance; }
@VideoQuality
final int getVideoQuality() {

@ -15,7 +15,7 @@ import java.util.Set;
*/
public class CameraOptions {
private Set<Integer> supportedWhiteBalance = new HashSet<>(5);
private Set<WhiteBalance> supportedWhiteBalance = new HashSet<>(5);
private Set<Facing> supportedFacing = new HashSet<>(2);
private Set<Flash> supportedFlash = new HashSet<>(4);
@ -45,7 +45,7 @@ public class CameraOptions {
strings = params.getSupportedWhiteBalance();
if (strings != null) {
for (String string : strings) {
Integer value = mapper.unmapWhiteBalance(string);
WhiteBalance value = mapper.unmapWhiteBalance(string);
if (value != null) supportedWhiteBalance.add(value);
}
}
@ -108,15 +108,15 @@ public class CameraOptions {
/**
* Set of supported white balance values.
*
* @see CameraConstants#WHITE_BALANCE_AUTO
* @see CameraConstants#WHITE_BALANCE_CLOUDY
* @see CameraConstants#WHITE_BALANCE_DAYLIGHT
* @see CameraConstants#WHITE_BALANCE_FLUORESCENT
* @see CameraConstants#WHITE_BALANCE_INCANDESCENT
* @see WhiteBalance#AUTO
* @see WhiteBalance#INCANDESCENT
* @see WhiteBalance#FLUORESCENT
* @see WhiteBalance#DAYLIGHT
* @see WhiteBalance#CLOUDY
* @return a set of supported values.
*/
@NonNull
public Set<Integer> getSupportedWhiteBalance() {
public Set<WhiteBalance> getSupportedWhiteBalance() {
return supportedWhiteBalance;
}

@ -95,8 +95,8 @@ public class CameraView extends FrameLayout {
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()));
WhiteBalance whiteBalance = WhiteBalance.fromValue(a.getInteger(R.styleable.CameraView_cameraWhiteBalance, WhiteBalance.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);
mJpegQuality = a.getInteger(R.styleable.CameraView_cameraJpegQuality, Defaults.DEFAULT_JPEG_QUALITY);
mCropOutput = a.getBoolean(R.styleable.CameraView_cameraCropOutput, Defaults.DEFAULT_CROP_OUTPUT);
@ -656,15 +656,15 @@ public class CameraView extends FrameLayout {
/**
* Sets desired white balance to current camera session.
*
* @see CameraConstants#WHITE_BALANCE_AUTO
* @see CameraConstants#WHITE_BALANCE_CLOUDY
* @see CameraConstants#WHITE_BALANCE_DAYLIGHT
* @see CameraConstants#WHITE_BALANCE_FLUORESCENT
* @see CameraConstants#WHITE_BALANCE_INCANDESCENT
* @see WhiteBalance#AUTO
* @see WhiteBalance#INCANDESCENT
* @see WhiteBalance#FLUORESCENT
* @see WhiteBalance#DAYLIGHT
* @see WhiteBalance#CLOUDY
*
* @param whiteBalance desired white balance behavior.
*/
public void setWhiteBalance(@WhiteBalance int whiteBalance) {
public void setWhiteBalance(WhiteBalance whiteBalance) {
mCameraController.setWhiteBalance(whiteBalance);
}
@ -673,8 +673,7 @@ public class CameraView extends FrameLayout {
* Returns the current white balance behavior.
* @return white balance value.
*/
@WhiteBalance
public int getWhiteBalance() {
public WhiteBalance getWhiteBalance() {
return mCameraController.getWhiteBalance();
}

@ -8,14 +8,15 @@ abstract class Mapper {
abstract <T> T mapFlash(Flash internalConstant);
abstract <T> T mapFacing(Facing internalConstant);
abstract <T> T mapWhiteBalance(@WhiteBalance int internalConstant);
abstract <T> T mapWhiteBalance(WhiteBalance internalConstant);
abstract <T> Flash unmapFlash(T cameraConstant);
abstract <T> Facing unmapFacing(T cameraConstant);
@WhiteBalance abstract <T> Integer unmapWhiteBalance(T cameraConstant);
abstract <T> WhiteBalance unmapWhiteBalance(T cameraConstant);
static class Mapper1 extends Mapper {
private static final HashMap<Flash, String> FLASH = new HashMap<>();
private static final HashMap<Integer, String> WB = new HashMap<>();
private static final HashMap<WhiteBalance, String> WB = new HashMap<>();
private static final HashMap<Facing, Integer> FACING = new HashMap<>();
static {
@ -25,11 +26,11 @@ abstract class Mapper {
FLASH.put(Flash.TORCH, Camera.Parameters.FLASH_MODE_TORCH);
FACING.put(Facing.BACK, Camera.CameraInfo.CAMERA_FACING_BACK);
FACING.put(Facing.FRONT, Camera.CameraInfo.CAMERA_FACING_FRONT);
WB.put(CameraConstants.WHITE_BALANCE_AUTO, Camera.Parameters.WHITE_BALANCE_AUTO);
WB.put(CameraConstants.WHITE_BALANCE_INCANDESCENT, Camera.Parameters.WHITE_BALANCE_INCANDESCENT);
WB.put(CameraConstants.WHITE_BALANCE_FLUORESCENT, Camera.Parameters.WHITE_BALANCE_FLUORESCENT);
WB.put(CameraConstants.WHITE_BALANCE_DAYLIGHT, Camera.Parameters.WHITE_BALANCE_DAYLIGHT);
WB.put(CameraConstants.WHITE_BALANCE_CLOUDY, Camera.Parameters.WHITE_BALANCE_CLOUDY_DAYLIGHT);
WB.put(WhiteBalance.AUTO, Camera.Parameters.WHITE_BALANCE_AUTO);
WB.put(WhiteBalance.INCANDESCENT, Camera.Parameters.WHITE_BALANCE_INCANDESCENT);
WB.put(WhiteBalance.FLUORESCENT, Camera.Parameters.WHITE_BALANCE_FLUORESCENT);
WB.put(WhiteBalance.DAYLIGHT, Camera.Parameters.WHITE_BALANCE_DAYLIGHT);
WB.put(WhiteBalance.CLOUDY, Camera.Parameters.WHITE_BALANCE_CLOUDY_DAYLIGHT);
}
@Override
@ -43,7 +44,7 @@ abstract class Mapper {
}
@Override
<T> T mapWhiteBalance(int internalConstant) {
<T> T mapWhiteBalance(WhiteBalance internalConstant) {
return (T) WB.get(internalConstant);
}
@ -67,7 +68,7 @@ abstract class Mapper {
}
@Override
<T> Integer unmapWhiteBalance(T cameraConstant) {
<T> WhiteBalance unmapWhiteBalance(T cameraConstant) {
return reverseLookup(WB, cameraConstant);
}
}
@ -75,7 +76,7 @@ abstract class Mapper {
static class Mapper2 extends Mapper {
@Override
<T> T mapWhiteBalance(@WhiteBalance int internalConstant) {
<T> T mapWhiteBalance(WhiteBalance internalConstant) {
return null;
}
@ -90,7 +91,7 @@ abstract class Mapper {
}
@Override
<T> Integer unmapWhiteBalance(T cameraConstant) {
<T> WhiteBalance unmapWhiteBalance(T cameraConstant) {
return null;
}

@ -1,18 +1,73 @@
package com.otaliastudios.cameraview;
import android.support.annotation.IntDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import static com.otaliastudios.cameraview.CameraConstants.WHITE_BALANCE_AUTO;
import static com.otaliastudios.cameraview.CameraConstants.WHITE_BALANCE_INCANDESCENT;
import static com.otaliastudios.cameraview.CameraConstants.WHITE_BALANCE_FLUORESCENT;
import static com.otaliastudios.cameraview.CameraConstants.WHITE_BALANCE_DAYLIGHT;
import static com.otaliastudios.cameraview.CameraConstants.WHITE_BALANCE_CLOUDY;
/**
* White balance values control the white balance settings.
*
* @see CameraView#setWhiteBalance(WhiteBalance)
*/
public enum WhiteBalance {
@Retention(RetentionPolicy.SOURCE)
@IntDef({WHITE_BALANCE_AUTO, WHITE_BALANCE_INCANDESCENT, WHITE_BALANCE_FLUORESCENT,
WHITE_BALANCE_DAYLIGHT, WHITE_BALANCE_CLOUDY})
public @interface WhiteBalance {
/**
* Automatic white balance selection (AWB).
* This is not guaranteed to be supported.
*
* @see CameraOptions#getSupportedWhiteBalance()
*/
AUTO(0),
/**
* White balance appropriate for incandescent light.
* This is not guaranteed to be supported.
*
* @see CameraOptions#getSupportedWhiteBalance()
*/
INCANDESCENT(1),
/**
* White balance appropriate for fluorescent light.
* This is not guaranteed to be supported.
*
* @see CameraOptions#getSupportedWhiteBalance()
*/
FLUORESCENT(2),
/**
* White balance appropriate for daylight captures.
* This is not guaranteed to be supported.
*
* @see CameraOptions#getSupportedWhiteBalance()
*/
DAYLIGHT(3),
/**
* White balance appropriate for pictures in cloudy conditions.
* This is not guaranteed to be supported.
*
* @see CameraOptions#getSupportedWhiteBalance()
*/
CLOUDY(4);
static final WhiteBalance DEFAULT = AUTO;
private int value;
WhiteBalance(int value) {
this.value = value;
}
int value() {
return value;
}
static WhiteBalance fromValue(int value) {
WhiteBalance[] list = WhiteBalance.values();
for (WhiteBalance action : list) {
if (action.value() == value) {
return action;
}
}
return null;
}
}
Loading…
Cancel
Save