Fix Mapper bug, new icon

pull/1/head
Mattia Iavarone 7 years ago
parent e140b9efaf
commit 2432b11fb8
  1. BIN
      art/icon.png
  2. BIN
      art/screen1.png
  3. BIN
      art/screen2.png
  4. 12
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraOptions.java
  5. 59
      cameraview/src/main/java/com/otaliastudios/cameraview/Mapper.java
  6. BIN
      demo/src/main/res/mipmap-hdpi/cameraview.png
  7. BIN
      demo/src/main/res/mipmap-mdpi/cameraview.png
  8. BIN
      demo/src/main/res/mipmap-xhdpi/cameraview.png
  9. BIN
      demo/src/main/res/mipmap-xxhdpi/cameraview.png
  10. BIN
      demo/src/main/res/mipmap-xxxhdpi/cameraview.png
  11. 6
      demo/src/main/res/values/colors.xml

Binary file not shown.

Before

Width:  |  Height:  |  Size: 164 KiB

After

Width:  |  Height:  |  Size: 144 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 MiB

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

After

Width:  |  Height:  |  Size: 106 KiB

@ -37,14 +37,16 @@ public class CameraOptions {
Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
for (int i = 0, count = Camera.getNumberOfCameras(); i < count; i++) { for (int i = 0, count = Camera.getNumberOfCameras(); i < count; i++) {
Camera.getCameraInfo(i, cameraInfo); Camera.getCameraInfo(i, cameraInfo);
supportedFacing.add(mapper.unmapFacing(cameraInfo.facing)); Integer value = mapper.unmapFacing(cameraInfo.facing);
if (value != null) supportedFacing.add(value);
} }
// WB // WB
strings = params.getSupportedWhiteBalance(); strings = params.getSupportedWhiteBalance();
if (strings != null) { if (strings != null) {
for (String string : strings) { 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(); strings = params.getSupportedFlashModes();
if (strings != null) { if (strings != null) {
for (String string : strings) { for (String string : strings) {
supportedFlash.add(mapper.unmapFlash(string)); Integer value = mapper.unmapFlash(string);
if (value != null) supportedFlash.add(value);
} }
} }
// Focus // Focus
strings = params.getSupportedFocusModes(); // Never null. strings = params.getSupportedFocusModes(); // Never null.
for (String string : strings) { for (String string : strings) {
supportedFocus.add(mapper.unmapFocus(string)); Integer value = mapper.unmapFocus(string);
if (value != null) supportedFocus.add(value);
} }
zoomSupported = params.isZoomSupported(); zoomSupported = params.isZoomSupported();

@ -3,22 +3,24 @@ package com.otaliastudios.cameraview;
import android.hardware.Camera; import android.hardware.Camera;
import android.util.SparseArray; import android.util.SparseArray;
import java.util.HashMap;
abstract class Mapper { abstract class Mapper {
abstract <T> T mapFlash(@Flash int internalConstant); abstract <T> T mapFlash(@Flash int internalConstant);
abstract <T> T mapFacing(@Facing int internalConstant); abstract <T> T mapFacing(@Facing int internalConstant);
abstract <T> T mapWhiteBalance(@WhiteBalance int internalConstant); abstract <T> T mapWhiteBalance(@WhiteBalance int internalConstant);
abstract <T> T mapFocus(@Focus int internalConstant); abstract <T> T mapFocus(@Focus int internalConstant);
@Flash abstract <T> int unmapFlash(T cameraConstant); @Flash abstract <T> Integer unmapFlash(T cameraConstant);
@Facing abstract <T> int unmapFacing(T cameraConstant); @Facing abstract <T> Integer unmapFacing(T cameraConstant);
@WhiteBalance abstract <T> int unmapWhiteBalance(T cameraConstant); @WhiteBalance abstract <T> Integer unmapWhiteBalance(T cameraConstant);
@Focus abstract <T> int unmapFocus(T cameraConstant); @Focus abstract <T> Integer unmapFocus(T cameraConstant);
static class Mapper1 extends Mapper { static class Mapper1 extends Mapper {
private static final SparseArray<String> FLASH = new SparseArray<>(); private static final HashMap<Integer, String> FLASH = new HashMap<>();
private static final SparseArray<String> WB = new SparseArray<>(); private static final HashMap<Integer, String> WB = new HashMap<>();
private static final SparseArray<Integer> FACING = new SparseArray<>(); private static final HashMap<Integer, Integer> FACING = new HashMap<>();
private static final SparseArray<String> FOCUS = new SparseArray<>(); private static final HashMap<Integer, String> FOCUS = new HashMap<>();
static { static {
FLASH.put(CameraConstants.FLASH_OFF, Camera.Parameters.FLASH_MODE_OFF); FLASH.put(CameraConstants.FLASH_OFF, Camera.Parameters.FLASH_MODE_OFF);
@ -40,43 +42,52 @@ abstract class Mapper {
@Override @Override
<T> T mapFlash(int internalConstant) { <T> T mapFlash(int internalConstant) {
return (T) FLASH.get(internalConstant, null); return (T) FLASH.get(internalConstant);
} }
@Override @Override
<T> T mapFacing(int internalConstant) { <T> T mapFacing(int internalConstant) {
return (T) FACING.get(internalConstant, null); return (T) FACING.get(internalConstant);
} }
@Override @Override
<T> T mapWhiteBalance(int internalConstant) { <T> T mapWhiteBalance(int internalConstant) {
return (T) WB.get(internalConstant, null); return (T) WB.get(internalConstant);
} }
@Override @Override
<T> T mapFocus(@Focus int internalConstant) { <T> T mapFocus(@Focus int internalConstant) {
return (T) FOCUS.get(internalConstant, null); return (T) FOCUS.get(internalConstant);
}
private Integer reverseLookup(HashMap<Integer, ?> map, Object object) {
for (int value : map.keySet()) {
if (map.get(value).equals(object)) {
return value;
}
}
return null;
} }
@Override @Override
<T> int unmapFlash(T cameraConstant) { <T> Integer unmapFlash(T cameraConstant) {
return FLASH.keyAt(FLASH.indexOfValue((String) cameraConstant)); return reverseLookup(FLASH, cameraConstant);
} }
@Override @Override
<T> int unmapFacing(T cameraConstant) { <T> Integer unmapFacing(T cameraConstant) {
return FACING.keyAt(FACING.indexOfValue((Integer) cameraConstant)); return reverseLookup(FACING, cameraConstant);
} }
@Override @Override
<T> int unmapWhiteBalance(T cameraConstant) { <T> Integer unmapWhiteBalance(T cameraConstant) {
return WB.keyAt(WB.indexOfValue((String) cameraConstant)); return reverseLookup(WB, cameraConstant);
} }
// This will ignore FOCUS_TAP_WITH_MARKER but it's fine // This will ignore FOCUS_TAP_WITH_MARKER but it's fine
@Override @Override
<T> int unmapFocus(T cameraConstant) { <T> Integer unmapFocus(T cameraConstant) {
return FOCUS.keyAt(FOCUS.indexOfValue((String) cameraConstant)); return reverseLookup(FOCUS, cameraConstant);
} }
} }
@ -98,17 +109,17 @@ abstract class Mapper {
} }
@Override @Override
<T> int unmapFlash(T cameraConstant) { <T> Integer unmapFlash(T cameraConstant) {
return 0; return 0;
} }
@Override @Override
<T> int unmapFacing(T cameraConstant) { <T> Integer unmapFacing(T cameraConstant) {
return 0; return 0;
} }
@Override @Override
<T> int unmapWhiteBalance(T cameraConstant) { <T> Integer unmapWhiteBalance(T cameraConstant) {
return 0; return 0;
} }
@ -118,7 +129,7 @@ abstract class Mapper {
} }
@Override @Override
<T> int unmapFocus(T cameraConstant) { <T> Integer unmapFocus(T cameraConstant) {
return 0; return 0;
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 20 KiB

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<color name="colorPrimary">#29aaca</color> <color name="colorPrimary">#009966</color>
<color name="colorPrimaryDark">#1f8199</color> <color name="colorPrimaryDark">#00734d</color>
<color name="colorAccent">#4ed728</color> <color name="colorAccent">#65FF2D</color>
</resources> </resources>

Loading…
Cancel
Save