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