diff --git a/android/proguard-android-optimize.txt b/android/proguard-android-optimize.txt index 1aa13c90b..086255ee2 100644 --- a/android/proguard-android-optimize.txt +++ b/android/proguard-android-optimize.txt @@ -28,8 +28,9 @@ -keep public class com.android.vending.licensing.ILicensingService # ADDED --keep class com.srowen.bs.android.camera.open.** --keep class com.srowen.bs.android.common.executor.** +-keep class com.google.zxing.client.android.camera.open.** +-keep class com.google.zxing.client.android.camera.exposure.** +-keep class com.google.zxing.client.android.common.executor.** # For native methods, see http://proguard.sourceforge.net/manual/examples.html#native -keepclasseswithmembernames class * { diff --git a/android/src/com/google/zxing/client/android/camera/CameraConfigurationManager.java b/android/src/com/google/zxing/client/android/camera/CameraConfigurationManager.java index a9be772a1..1ff16158e 100644 --- a/android/src/com/google/zxing/client/android/camera/CameraConfigurationManager.java +++ b/android/src/com/google/zxing/client/android/camera/CameraConfigurationManager.java @@ -26,6 +26,8 @@ import android.view.Display; import android.view.WindowManager; import com.google.zxing.client.android.PreferencesActivity; +import com.google.zxing.client.android.camera.exposure.ExposureInterface; +import com.google.zxing.client.android.camera.exposure.ExposureManager; import java.util.ArrayList; import java.util.Collection; @@ -50,9 +52,11 @@ final class CameraConfigurationManager { private final Context context; private Point screenResolution; private Point cameraResolution; + private final ExposureInterface exposure; CameraConfigurationManager(Context context) { this.context = context; + exposure = new ExposureManager().build(); } /** @@ -135,12 +139,12 @@ final class CameraConfigurationManager { } } - private static void initializeTorch(Camera.Parameters parameters, SharedPreferences prefs) { + private void initializeTorch(Camera.Parameters parameters, SharedPreferences prefs) { boolean currentSetting = prefs.getBoolean(PreferencesActivity.KEY_FRONT_LIGHT, false); doSetTorch(parameters, currentSetting); } - private static void doSetTorch(Camera.Parameters parameters, boolean newSetting) { + private void doSetTorch(Camera.Parameters parameters, boolean newSetting) { String flashMode; if (newSetting) { flashMode = findSettableValue(parameters.getSupportedFlashModes(), @@ -153,6 +157,8 @@ final class CameraConfigurationManager { if (flashMode != null) { parameters.setFlashMode(flashMode); } + + exposure.setExposure(parameters, newSetting); } private Point findBestPreviewSizeValue(Camera.Parameters parameters, Point screenResolution) { diff --git a/android/src/com/google/zxing/client/android/camera/exposure/DefaultExposureInterface.java b/android/src/com/google/zxing/client/android/camera/exposure/DefaultExposureInterface.java new file mode 100644 index 000000000..821f1b8f9 --- /dev/null +++ b/android/src/com/google/zxing/client/android/camera/exposure/DefaultExposureInterface.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2012 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing.client.android.camera.exposure; + +import android.hardware.Camera; + +public final class DefaultExposureInterface implements ExposureInterface { + + @Override + public void setExposure(Camera.Parameters parameters, boolean lightOn) { + // Do nothing + } + +} diff --git a/android/src/com/google/zxing/client/android/camera/exposure/ExposureInterface.java b/android/src/com/google/zxing/client/android/camera/exposure/ExposureInterface.java new file mode 100644 index 000000000..b04b5150c --- /dev/null +++ b/android/src/com/google/zxing/client/android/camera/exposure/ExposureInterface.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2012 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing.client.android.camera.exposure; + +import android.hardware.Camera; + +/** + * Implementations control auto-exposure settings of the camera, if available. + * + * @author Sean Owen + */ +public interface ExposureInterface { + + void setExposure(Camera.Parameters parameters, boolean lightOn); + +} diff --git a/android/src/com/google/zxing/client/android/camera/exposure/ExposureManager.java b/android/src/com/google/zxing/client/android/camera/exposure/ExposureManager.java new file mode 100644 index 000000000..defa025a4 --- /dev/null +++ b/android/src/com/google/zxing/client/android/camera/exposure/ExposureManager.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2012 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing.client.android.camera.exposure; + +import com.google.zxing.client.android.common.PlatformSupportManager; + +public final class ExposureManager extends PlatformSupportManager { + + public ExposureManager() { + super(ExposureInterface.class, new DefaultExposureInterface()); + addImplementationClass(8, "com.google.zxing.client.android.camera.exposure.FroyoExposureInterface"); + } + +} diff --git a/android/src/com/google/zxing/client/android/camera/exposure/FroyoExposureInterface.java b/android/src/com/google/zxing/client/android/camera/exposure/FroyoExposureInterface.java new file mode 100644 index 000000000..c85f2d8bf --- /dev/null +++ b/android/src/com/google/zxing/client/android/camera/exposure/FroyoExposureInterface.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2012 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing.client.android.camera.exposure; + +import android.annotation.TargetApi; +import android.hardware.Camera; +import android.util.Log; + +@TargetApi(8) +public final class FroyoExposureInterface implements ExposureInterface { + + private static final String TAG = FroyoExposureInterface.class.getSimpleName(); + + private static final float MAX_EXPOSURE_COMPENSATION = 1.5f; + private static final float MIN_EXPOSURE_COMPENSATION = 0.0f; + + @Override + public void setExposure(Camera.Parameters parameters, boolean lightOn) { + int minExposure = parameters.getMinExposureCompensation(); + int maxExposure = parameters.getMaxExposureCompensation(); + if (minExposure != 0 || maxExposure != 0) { + float step = parameters.getExposureCompensationStep(); + int desiredCompensation; + if (lightOn) { + // Light on; set low exposue compensation + desiredCompensation = Math.max((int) (MIN_EXPOSURE_COMPENSATION / step), minExposure); + } else { + // Light off; set high compensation + desiredCompensation = Math.min((int) (MAX_EXPOSURE_COMPENSATION / step), maxExposure); + } + Log.i(TAG, "Setting exposure compensation to " + desiredCompensation + " / " + (step * desiredCompensation)); + parameters.setExposureCompensation(desiredCompensation); + } else { + Log.i(TAG, "Camera does not support exposure compensation"); + } + } + +}