优化细节
This commit is contained in:
@@ -52,7 +52,10 @@ public class CaptureActivity extends AppCompatActivity implements OnCaptureCallb
|
|||||||
*/
|
*/
|
||||||
public void initUI(){
|
public void initUI(){
|
||||||
surfaceView = findViewById(getSurfaceViewId());
|
surfaceView = findViewById(getSurfaceViewId());
|
||||||
viewfinderView = findViewById(getViewfinderViewId());
|
int viewfinderViewId = getViewfinderViewId();
|
||||||
|
if(viewfinderViewId != 0){
|
||||||
|
viewfinderView = findViewById(viewfinderViewId);
|
||||||
|
}
|
||||||
int ivTorchId = getIvTorchId();
|
int ivTorchId = getIvTorchId();
|
||||||
if(ivTorchId != 0){
|
if(ivTorchId != 0){
|
||||||
ivTorch = findViewById(ivTorchId);
|
ivTorch = findViewById(ivTorchId);
|
||||||
@@ -85,7 +88,7 @@ public class CaptureActivity extends AppCompatActivity implements OnCaptureCallb
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link #viewfinderView} 的 ID
|
* {@link #viewfinderView} 的 ID
|
||||||
* @return
|
* @return 默认返回{@code R.id.viewfinderView}, 如果不需要扫码框可以返回0
|
||||||
*/
|
*/
|
||||||
public int getViewfinderViewId(){
|
public int getViewfinderViewId(){
|
||||||
return R.id.viewfinderView;
|
return R.id.viewfinderView;
|
||||||
|
|||||||
@@ -66,7 +66,10 @@ public class CaptureFragment extends Fragment implements OnCaptureCallback {
|
|||||||
*/
|
*/
|
||||||
public void initUI(){
|
public void initUI(){
|
||||||
surfaceView = mRootView.findViewById(getSurfaceViewId());
|
surfaceView = mRootView.findViewById(getSurfaceViewId());
|
||||||
viewfinderView = mRootView.findViewById(getViewfinderViewId());
|
int viewfinderViewId = getViewfinderViewId();
|
||||||
|
if(viewfinderViewId != 0){
|
||||||
|
viewfinderView = mRootView.findViewById(viewfinderViewId);
|
||||||
|
}
|
||||||
int ivTorchId = getIvTorchId();
|
int ivTorchId = getIvTorchId();
|
||||||
if(ivTorchId != 0){
|
if(ivTorchId != 0){
|
||||||
ivTorch = mRootView.findViewById(ivTorchId);
|
ivTorch = mRootView.findViewById(ivTorchId);
|
||||||
@@ -99,7 +102,7 @@ public class CaptureFragment extends Fragment implements OnCaptureCallback {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link ViewfinderView} 的 id
|
* {@link ViewfinderView} 的 id
|
||||||
* @return
|
* @return 默认返回{@code R.id.viewfinderView}, 如果不需要扫码框可以返回0
|
||||||
*/
|
*/
|
||||||
public int getViewfinderViewId(){
|
public int getViewfinderViewId(){
|
||||||
return R.id.viewfinderView;
|
return R.id.viewfinderView;
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ public class CaptureHandler extends Handler implements ResultPointCallback {
|
|||||||
private final DecodeThread decodeThread;
|
private final DecodeThread decodeThread;
|
||||||
private State state;
|
private State state;
|
||||||
private final CameraManager cameraManager;
|
private final CameraManager cameraManager;
|
||||||
private final Activity activity;
|
|
||||||
private final ViewfinderView viewfinderView;
|
private final ViewfinderView viewfinderView;
|
||||||
/**
|
/**
|
||||||
* 是否支持垂直的条形码
|
* 是否支持垂直的条形码
|
||||||
@@ -66,7 +65,6 @@ public class CaptureHandler extends Handler implements ResultPointCallback {
|
|||||||
Map<DecodeHintType,Object> baseHints,
|
Map<DecodeHintType,Object> baseHints,
|
||||||
String characterSet,
|
String characterSet,
|
||||||
CameraManager cameraManager) {
|
CameraManager cameraManager) {
|
||||||
this.activity = activity;
|
|
||||||
this.viewfinderView = viewfinderView;
|
this.viewfinderView = viewfinderView;
|
||||||
this.onCaptureListener = onCaptureListener;
|
this.onCaptureListener = onCaptureListener;
|
||||||
decodeThread = new DecodeThread(activity,cameraManager,this, decodeFormats, baseHints, characterSet, this);
|
decodeThread = new DecodeThread(activity,cameraManager,this, decodeFormats, baseHints, characterSet, this);
|
||||||
@@ -129,7 +127,9 @@ public class CaptureHandler extends Handler implements ResultPointCallback {
|
|||||||
if (state == State.SUCCESS) {
|
if (state == State.SUCCESS) {
|
||||||
state = State.PREVIEW;
|
state = State.PREVIEW;
|
||||||
cameraManager.requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
|
cameraManager.requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
|
||||||
viewfinderView.drawViewfinder();
|
if(viewfinderView!= null){
|
||||||
|
viewfinderView.drawViewfinder();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ final class InactivityTimer {
|
|||||||
protected Object doInBackground(Object... objects) {
|
protected Object doInBackground(Object... objects) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(INACTIVITY_DELAY_MS);
|
Thread.sleep(INACTIVITY_DELAY_MS);
|
||||||
LogUtils.i( "Finishing activity due to inactivity");
|
LogUtils.i( "Finishing activity due to inactivity");
|
||||||
Activity activity = weakReference.get();
|
Activity activity = weakReference.get();
|
||||||
if(activity!=null){
|
if(activity!=null){
|
||||||
activity.finish();
|
activity.finish();
|
||||||
|
|||||||
Reference in New Issue
Block a user