* 内置手电筒按钮,当光线太暗时,自动显示手电筒 fix(#58)

*  生成二维码时Logo支持自定义大小 fix(#62)
This commit is contained in:
jenly1314
2019-11-15 18:22:48 +08:00
parent 39f13c3c3f
commit c9b74fd707
32 changed files with 427 additions and 160 deletions

View File

@@ -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);
}
}

View File

@@ -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();
}
}