@@ -72,6 +72,11 @@ public final class CameraManager {
|
||||
*/
|
||||
private final PreviewCallback previewCallback;
|
||||
|
||||
private OnTorchListener onTorchListener;
|
||||
private OnSensorListener onSensorListener;
|
||||
|
||||
private boolean isTorch;
|
||||
|
||||
public CameraManager(Context context) {
|
||||
this.context = context.getApplicationContext();
|
||||
this.configManager = new CameraConfigurationManager(context);
|
||||
@@ -192,14 +197,22 @@ public final class CameraManager {
|
||||
autoFocusManager.stop();
|
||||
autoFocusManager = null;
|
||||
}
|
||||
this.isTorch = newSetting;
|
||||
configManager.setTorch(theCamera.getCamera(), newSetting);
|
||||
if (wasAutoFocusManager) {
|
||||
autoFocusManager = new AutoFocusManager(context, theCamera.getCamera());
|
||||
autoFocusManager.start();
|
||||
}
|
||||
|
||||
if(onTorchListener!=null){
|
||||
onTorchListener.onTorchChanged(newSetting);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A single preview frame will be returned to the handler supplied. The data will arrive as byte[]
|
||||
* in the message.obj field, with width and height encoded as message.arg1 and message.arg2,
|
||||
@@ -376,4 +389,49 @@ public final class CameraManager {
|
||||
size, size, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提供闪光灯监听
|
||||
* @param listener
|
||||
*/
|
||||
public void setOnTorchListener(OnTorchListener listener){
|
||||
this.onTorchListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* 传感器光线照度监听
|
||||
* @param listener
|
||||
*/
|
||||
public void setOnSensorListener(OnSensorListener listener){
|
||||
this.onSensorListener = listener;
|
||||
}
|
||||
|
||||
public void sensorChanged(boolean tooDark,float ambientLightLux){
|
||||
if(onSensorListener!=null){
|
||||
onSensorListener.onSensorChanged(isTorch,tooDark,ambientLightLux);
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnTorchListener{
|
||||
/**
|
||||
* 当闪光灯状态改变时触发
|
||||
* @param torch true表示开启、false表示关闭
|
||||
*/
|
||||
void onTorchChanged(boolean torch);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 传感器灯光亮度监听
|
||||
*/
|
||||
public interface OnSensorListener{
|
||||
/**
|
||||
*
|
||||
* @param torch 闪光灯是否开启
|
||||
* @param tooDark 传感器检测到的光线亮度,是否太暗
|
||||
* @param ambientLightLux 光线照度
|
||||
*/
|
||||
void onSensorChanged(boolean torch,boolean tooDark,float ambientLightLux);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -16,7 +16,9 @@ package com.king.zxing.camera;
|
||||
*/
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.king.zxing.Preferences;
|
||||
|
||||
@@ -33,11 +35,16 @@ public enum FrontLightMode {
|
||||
OFF;
|
||||
|
||||
private static FrontLightMode parse(String modeString) {
|
||||
return modeString == null ? OFF : valueOf(modeString);
|
||||
return modeString == null ? AUTO : valueOf(modeString);
|
||||
}
|
||||
|
||||
public static FrontLightMode readPref(SharedPreferences sharedPrefs) {
|
||||
return parse(sharedPrefs.getString(Preferences.KEY_FRONT_LIGHT_MODE, OFF.toString()));
|
||||
return parse(sharedPrefs.getString(Preferences.KEY_FRONT_LIGHT_MODE, AUTO.toString()));
|
||||
}
|
||||
|
||||
public static void put(Context context, FrontLightMode mode) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
prefs.edit().putString(Preferences.KEY_FRONT_LIGHT_MODE, mode.toString()).commit();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user