Skip to content

Commit

Permalink
新增是否全屏扫描开关,默认值为true,若该选项设为false则仅仅在扫描框内扫描
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzhiqiang1993 committed May 29, 2018
1 parent ee993ee commit 4ee0b2d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 19 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/com/yzq/zxing/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public void onAction(List<String> permissions) {
config.setPlayBeep(true);
config.setShake(true);
config.setDecodeBarCode(false);
config.setFullScreenScan(true);
intent.putExtra(Constant.INTENT_ZXING_CONFIG, config);

startActivityForResult(intent, REQUEST_CODE_SCAN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ private void initView() {

viewfinderView = findViewById(R.id.viewfinder_view);
viewfinderView.setOnClickListener(this);
viewfinderView.setZxingConfig(config);

backIv = findViewById(R.id.backIv);
backIv.setOnClickListener(this);
Expand Down Expand Up @@ -220,7 +221,7 @@ private void switchVisibility(View view, boolean b) {
protected void onResume() {
super.onResume();

cameraManager = new CameraManager(getApplication());
cameraManager = new CameraManager(getApplication(),config);

viewfinderView.setCameraManager(cameraManager);
handler = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ZxingConfig implements Serializable {
/*是否播放声音*/
private boolean isPlayBeep = true;
/*是否震动*/
private boolean isShake = false;
private boolean isShake = true;
/*是否显示下方的其他功能布局*/
private boolean isShowbottomLayout = true;
/*是否显示闪光灯按钮*/
Expand All @@ -24,8 +24,18 @@ public class ZxingConfig implements Serializable {
private boolean isShowAlbum = true;
/*是否解析条形码*/
private boolean isDecodeBarCode=true;
/*是否全屏扫描*/
private boolean isFullScreenScan=true;


public boolean isFullScreenScan() {
return isFullScreenScan;
}

public void setFullScreenScan(boolean fullScreenScan) {
isFullScreenScan = fullScreenScan;
}

public boolean isDecodeBarCode() {
return isDecodeBarCode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import com.google.zxing.PlanarYUVLuminanceSource;
import com.yzq.zxinglibrary.android.CaptureActivityHandler;
import com.yzq.zxinglibrary.bean.ZxingConfig;
import com.yzq.zxinglibrary.common.Constant;

import java.io.IOException;
Expand All @@ -46,6 +47,7 @@ public final class CameraManager {

private final Context context;
private final CameraConfigurationManager configManager;
private ZxingConfig config;
private Camera camera;
private AutoFocusManager autoFocusManager;
private Rect framingRect;
Expand All @@ -62,17 +64,18 @@ public final class CameraManager {
*/
private final PreviewCallback previewCallback;

public CameraManager(Context context) {
public CameraManager(Context context, ZxingConfig config) {
this.context = context;
this.configManager = new CameraConfigurationManager(context);
previewCallback = new PreviewCallback(configManager);
this.config = config;
}

public static void init(Context context) {
if (cameraManager == null) {
cameraManager = new CameraManager(context);
}
}
// public static void init(Context context) {
// if (cameraManager == null) {
// cameraManager = new CameraManager(context, null);
// }
// }


/**
Expand Down Expand Up @@ -177,7 +180,6 @@ public void switchFlashLight(CaptureActivityHandler handler) {
msg.what = Constant.FLASH_CLOSE;



} else {
/*打开闪光灯*/
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
Expand Down Expand Up @@ -348,11 +350,25 @@ public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data,
return null;
}
// Go ahead and assume it's YUV rather than die.
// return new PlanarYUVLuminanceSource(data, width, height, rect.left,
// rect.top, rect.width(), rect.height(), false);
return new PlanarYUVLuminanceSource(data, width, height, 0,
0, width, height, false);


if (config == null) {
config = new ZxingConfig();
}

if (config.isFullScreenScan()) {
return new PlanarYUVLuminanceSource(data, width, height, 0,
0, width, height, false);
} else {
return new PlanarYUVLuminanceSource(data, width, height, rect.left,
rect.top, rect.width(), rect.height(), false);


}


}

public static CameraManager get() {
return cameraManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.google.zxing.ResultPoint;
import com.yzq.zxinglibrary.R;
import com.yzq.zxinglibrary.bean.ZxingConfig;
import com.yzq.zxinglibrary.camera.CameraManager;

import java.util.ArrayList;
Expand Down Expand Up @@ -61,6 +62,12 @@ public ViewfinderView(Context context, AttributeSet attrs) {

}



public void setZxingConfig(ZxingConfig config) {

}

public ViewfinderView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);

Expand Down Expand Up @@ -125,8 +132,9 @@ public void onDraw(Canvas canvas) {

/*绘制提示文字*/
// drawStatusText(canvas, frame, width);

/*绘制扫描线*/
drawScanLight(canvas, frame);
drawScanLight(canvas, frame);

float scaleX = frame.width() / (float) previewFrame.width();
float scaleY = frame.height() / (float) previewFrame.height();
Expand Down Expand Up @@ -186,11 +194,11 @@ private void drawFrameBounds(Canvas canvas, Rect frame) {


/*扫描框的边框线*/
// paint.setColor(Color.WHITE);
// paint.setStrokeWidth(2);
// paint.setStyle(Paint.Style.STROKE);
//
// canvas.drawRect(frame, paint);
paint.setColor(Color.WHITE);
paint.setStrokeWidth(2);
paint.setStyle(Paint.Style.STROKE);

canvas.drawRect(frame, paint);

/*扫描框的四个角*/
paint.setColor(Color.BLUE);
Expand Down Expand Up @@ -295,6 +303,8 @@ private void drawScanLight(Canvas canvas, Rect frame) {
Rect scanRect = new Rect(frame.left, scanLineTop, frame.right,
scanLineTop + scanLightHeight);
canvas.drawBitmap(scanLight, null, scanRect, paint);


}

public void drawViewfinder() {
Expand Down

0 comments on commit 4ee0b2d

Please sign in to comment.