diff --git a/art/icon.png b/art/icon.png index 61313c7d..82611522 100644 Binary files a/art/icon.png and b/art/icon.png differ diff --git a/art/screen1.png b/art/screen1.png index cd066c70..72deb7c8 100644 Binary files a/art/screen1.png and b/art/screen1.png differ diff --git a/art/screen2.png b/art/screen2.png index 5502595e..c0ae2a54 100644 Binary files a/art/screen2.png and b/art/screen2.png differ diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraOptions.java b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraOptions.java index dc49771a..6a10a20a 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraOptions.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraOptions.java @@ -37,14 +37,16 @@ public class CameraOptions { Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); for (int i = 0, count = Camera.getNumberOfCameras(); i < count; i++) { Camera.getCameraInfo(i, cameraInfo); - supportedFacing.add(mapper.unmapFacing(cameraInfo.facing)); + Integer value = mapper.unmapFacing(cameraInfo.facing); + if (value != null) supportedFacing.add(value); } // WB strings = params.getSupportedWhiteBalance(); if (strings != null) { for (String string : strings) { - supportedWhiteBalance.add(mapper.unmapWhiteBalance(string)); + Integer value = mapper.unmapWhiteBalance(string); + if (value != null) supportedWhiteBalance.add(value); } } @@ -52,14 +54,16 @@ public class CameraOptions { strings = params.getSupportedFlashModes(); if (strings != null) { for (String string : strings) { - supportedFlash.add(mapper.unmapFlash(string)); + Integer value = mapper.unmapFlash(string); + if (value != null) supportedFlash.add(value); } } // Focus strings = params.getSupportedFocusModes(); // Never null. for (String string : strings) { - supportedFocus.add(mapper.unmapFocus(string)); + Integer value = mapper.unmapFocus(string); + if (value != null) supportedFocus.add(value); } zoomSupported = params.isZoomSupported(); diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/Mapper.java b/cameraview/src/main/java/com/otaliastudios/cameraview/Mapper.java index ab5f93a7..78447cd4 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/Mapper.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/Mapper.java @@ -3,22 +3,24 @@ package com.otaliastudios.cameraview; import android.hardware.Camera; import android.util.SparseArray; +import java.util.HashMap; + abstract class Mapper { abstract T mapFlash(@Flash int internalConstant); abstract T mapFacing(@Facing int internalConstant); abstract T mapWhiteBalance(@WhiteBalance int internalConstant); abstract T mapFocus(@Focus int internalConstant); - @Flash abstract int unmapFlash(T cameraConstant); - @Facing abstract int unmapFacing(T cameraConstant); - @WhiteBalance abstract int unmapWhiteBalance(T cameraConstant); - @Focus abstract int unmapFocus(T cameraConstant); + @Flash abstract Integer unmapFlash(T cameraConstant); + @Facing abstract Integer unmapFacing(T cameraConstant); + @WhiteBalance abstract Integer unmapWhiteBalance(T cameraConstant); + @Focus abstract Integer unmapFocus(T cameraConstant); static class Mapper1 extends Mapper { - private static final SparseArray FLASH = new SparseArray<>(); - private static final SparseArray WB = new SparseArray<>(); - private static final SparseArray FACING = new SparseArray<>(); - private static final SparseArray FOCUS = new SparseArray<>(); + private static final HashMap FLASH = new HashMap<>(); + private static final HashMap WB = new HashMap<>(); + private static final HashMap FACING = new HashMap<>(); + private static final HashMap FOCUS = new HashMap<>(); static { FLASH.put(CameraConstants.FLASH_OFF, Camera.Parameters.FLASH_MODE_OFF); @@ -40,43 +42,52 @@ abstract class Mapper { @Override T mapFlash(int internalConstant) { - return (T) FLASH.get(internalConstant, null); + return (T) FLASH.get(internalConstant); } @Override T mapFacing(int internalConstant) { - return (T) FACING.get(internalConstant, null); + return (T) FACING.get(internalConstant); } @Override T mapWhiteBalance(int internalConstant) { - return (T) WB.get(internalConstant, null); + return (T) WB.get(internalConstant); } @Override T mapFocus(@Focus int internalConstant) { - return (T) FOCUS.get(internalConstant, null); + return (T) FOCUS.get(internalConstant); + } + + private Integer reverseLookup(HashMap map, Object object) { + for (int value : map.keySet()) { + if (map.get(value).equals(object)) { + return value; + } + } + return null; } @Override - int unmapFlash(T cameraConstant) { - return FLASH.keyAt(FLASH.indexOfValue((String) cameraConstant)); + Integer unmapFlash(T cameraConstant) { + return reverseLookup(FLASH, cameraConstant); } @Override - int unmapFacing(T cameraConstant) { - return FACING.keyAt(FACING.indexOfValue((Integer) cameraConstant)); + Integer unmapFacing(T cameraConstant) { + return reverseLookup(FACING, cameraConstant); } @Override - int unmapWhiteBalance(T cameraConstant) { - return WB.keyAt(WB.indexOfValue((String) cameraConstant)); + Integer unmapWhiteBalance(T cameraConstant) { + return reverseLookup(WB, cameraConstant); } // This will ignore FOCUS_TAP_WITH_MARKER but it's fine @Override - int unmapFocus(T cameraConstant) { - return FOCUS.keyAt(FOCUS.indexOfValue((String) cameraConstant)); + Integer unmapFocus(T cameraConstant) { + return reverseLookup(FOCUS, cameraConstant); } } @@ -98,17 +109,17 @@ abstract class Mapper { } @Override - int unmapFlash(T cameraConstant) { + Integer unmapFlash(T cameraConstant) { return 0; } @Override - int unmapFacing(T cameraConstant) { + Integer unmapFacing(T cameraConstant) { return 0; } @Override - int unmapWhiteBalance(T cameraConstant) { + Integer unmapWhiteBalance(T cameraConstant) { return 0; } @@ -118,7 +129,7 @@ abstract class Mapper { } @Override - int unmapFocus(T cameraConstant) { + Integer unmapFocus(T cameraConstant) { return 0; } } diff --git a/demo/src/main/res/mipmap-hdpi/cameraview.png b/demo/src/main/res/mipmap-hdpi/cameraview.png index ac2ab7c7..fdeb9c33 100644 Binary files a/demo/src/main/res/mipmap-hdpi/cameraview.png and b/demo/src/main/res/mipmap-hdpi/cameraview.png differ diff --git a/demo/src/main/res/mipmap-mdpi/cameraview.png b/demo/src/main/res/mipmap-mdpi/cameraview.png index 0b1bb674..35cb3934 100644 Binary files a/demo/src/main/res/mipmap-mdpi/cameraview.png and b/demo/src/main/res/mipmap-mdpi/cameraview.png differ diff --git a/demo/src/main/res/mipmap-xhdpi/cameraview.png b/demo/src/main/res/mipmap-xhdpi/cameraview.png index 31cf7797..afd729b1 100644 Binary files a/demo/src/main/res/mipmap-xhdpi/cameraview.png and b/demo/src/main/res/mipmap-xhdpi/cameraview.png differ diff --git a/demo/src/main/res/mipmap-xxhdpi/cameraview.png b/demo/src/main/res/mipmap-xxhdpi/cameraview.png index d0db7f6e..f32577b6 100644 Binary files a/demo/src/main/res/mipmap-xxhdpi/cameraview.png and b/demo/src/main/res/mipmap-xxhdpi/cameraview.png differ diff --git a/demo/src/main/res/mipmap-xxxhdpi/cameraview.png b/demo/src/main/res/mipmap-xxxhdpi/cameraview.png index b0fad551..ab08529e 100644 Binary files a/demo/src/main/res/mipmap-xxxhdpi/cameraview.png and b/demo/src/main/res/mipmap-xxxhdpi/cameraview.png differ diff --git a/demo/src/main/res/values/colors.xml b/demo/src/main/res/values/colors.xml index 575c6206..755f50b0 100644 --- a/demo/src/main/res/values/colors.xml +++ b/demo/src/main/res/values/colors.xml @@ -1,6 +1,6 @@ - #29aaca - #1f8199 - #4ed728 + #009966 + #00734d + #65FF2D