mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Add support for controlling exposure for Froyo devices; fix typo
git-svn-id: https://zxing.googlecode.com/svn/trunk@2382 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
3e2b52fa38
commit
e7c2d667da
|
@ -28,8 +28,9 @@
|
||||||
-keep public class com.android.vending.licensing.ILicensingService
|
-keep public class com.android.vending.licensing.ILicensingService
|
||||||
|
|
||||||
# ADDED
|
# ADDED
|
||||||
-keep class com.srowen.bs.android.camera.open.**
|
-keep class com.google.zxing.client.android.camera.open.**
|
||||||
-keep class com.srowen.bs.android.common.executor.**
|
-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
|
# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
|
||||||
-keepclasseswithmembernames class * {
|
-keepclasseswithmembernames class * {
|
||||||
|
|
|
@ -26,6 +26,8 @@ import android.view.Display;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
import com.google.zxing.client.android.PreferencesActivity;
|
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.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -50,9 +52,11 @@ final class CameraConfigurationManager {
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private Point screenResolution;
|
private Point screenResolution;
|
||||||
private Point cameraResolution;
|
private Point cameraResolution;
|
||||||
|
private final ExposureInterface exposure;
|
||||||
|
|
||||||
CameraConfigurationManager(Context context) {
|
CameraConfigurationManager(Context context) {
|
||||||
this.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);
|
boolean currentSetting = prefs.getBoolean(PreferencesActivity.KEY_FRONT_LIGHT, false);
|
||||||
doSetTorch(parameters, currentSetting);
|
doSetTorch(parameters, currentSetting);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void doSetTorch(Camera.Parameters parameters, boolean newSetting) {
|
private void doSetTorch(Camera.Parameters parameters, boolean newSetting) {
|
||||||
String flashMode;
|
String flashMode;
|
||||||
if (newSetting) {
|
if (newSetting) {
|
||||||
flashMode = findSettableValue(parameters.getSupportedFlashModes(),
|
flashMode = findSettableValue(parameters.getSupportedFlashModes(),
|
||||||
|
@ -153,6 +157,8 @@ final class CameraConfigurationManager {
|
||||||
if (flashMode != null) {
|
if (flashMode != null) {
|
||||||
parameters.setFlashMode(flashMode);
|
parameters.setFlashMode(flashMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exposure.setExposure(parameters, newSetting);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Point findBestPreviewSizeValue(Camera.Parameters parameters, Point screenResolution) {
|
private Point findBestPreviewSizeValue(Camera.Parameters parameters, Point screenResolution) {
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
|
||||||
|
}
|
|
@ -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<ExposureInterface> {
|
||||||
|
|
||||||
|
public ExposureManager() {
|
||||||
|
super(ExposureInterface.class, new DefaultExposureInterface());
|
||||||
|
addImplementationClass(8, "com.google.zxing.client.android.camera.exposure.FroyoExposureInterface");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue