Skip to content

Commit

Permalink
添加新功能:1高度偏移值,2全屏扫描
Browse files Browse the repository at this point in the history
  • Loading branch information
maning0303 committed Sep 17, 2019
1 parent e52fae9 commit 1c6c2c5
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 25 deletions.
28 changes: 8 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
.setGridScanLineColumn(30)
//网格高度
.setGridScanLineHeight(150)
//高度偏移值(单位px)
.setScanFrameHeightOffect(150)
//是否全屏扫描
.setFullScreenScan(true)
//自定义遮罩
.setCustomShadeViewLayoutID(R.layout.layout_custom_view, new MNCustomViewBindCallback() {
@Override
Expand Down Expand Up @@ -161,6 +165,10 @@
```

## 版本记录:
v2.1.2(未发布):
1.支持设置扫描框高度偏移值
2.支持设置全屏扫描(默认只扫描扫描框内的二维码)

v2.1.1:
1.支持网格扫描线设置列数和高度
2.支持隐藏默认闪光灯开关
Expand All @@ -173,26 +181,6 @@
3.优化扫描图片相关
4.内部检查读写权限

v2.0.1:
1.再次修复8.0-Only fullscreen ...错误
2.优化权限,内部检查相机权限

v2.0.0:
1.添加缩放控制器,可以缩放相机焦距
2.缩放控制器方向:左,右,下
v1.1.9:
1.添加退出动画配置
2.修复activity动画黑色背景问题
v1.1.8:
1.扫描线动画处理
2.优化UI
v1.1.7:
1.图片识别二维码对图片进行压缩处理,防止OOM
2.优化界面显示


## 感谢:

Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/maning/zxingcodedemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,17 @@ public void scanCode(View view) {
.setGridScanLineColumn(30)
//网格高度
.setGridScanLineHeight(150)
//高度偏移值(单位px)
.setScanFrameHeightOffect(150)
//是否全屏扫描,默认只扫描扫描框内的二维码
.setFullScreenScan(true)
//自定义遮罩
.setCustomShadeViewLayoutID(R.layout.layout_custom_view, new MNCustomViewBindCallback() {
@Override
public void onBindView(View customView) {
if(customView == null){
return;
}
ImageView iv_back = customView.findViewById(R.id.iv_back);
ImageView iv_photo = customView.findViewById(R.id.iv_photo);
LinearLayout btn_scan_light = customView.findViewById(R.id.btn_scan_light);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
//自定义遮罩View
private static MNCustomViewBindCallback customViewBindCallback;

private MNScanConfig mnScanConfig;

public static void setMnCustomViewBindCallback(MNCustomViewBindCallback mnCustomViewBindCallback) {
customViewBindCallback = mnCustomViewBindCallback;
}
Expand Down Expand Up @@ -294,9 +296,10 @@ private void closeLight() {
}

private void initIntent() {
Intent intent = getIntent();

MNScanConfig mnScanConfig = (MNScanConfig) intent.getSerializableExtra(MNScanManager.INTENT_KEY_CONFIG_MODEL);
mnScanConfig = (MNScanConfig) getIntent().getSerializableExtra(MNScanManager.INTENT_KEY_CONFIG_MODEL);
if (mnScanConfig == null) {
mnScanConfig = new MNScanConfig.Builder().builder();
}

String scanColor = mnScanConfig.getScanColor();
String maskColor = mnScanConfig.getBgColor();
Expand Down Expand Up @@ -732,6 +735,18 @@ public boolean onTouchEvent(MotionEvent event) {
return super.onTouchEvent(event);
}

//----------------对内方法
/**
* 获取配置信息
* @return
*/
public static MNScanConfig getScanConfig() {
if (sActivityRef != null && sActivityRef.get() != null) {
return sActivityRef.get().mnScanConfig;
}
return null;
}


//---------对外提供方法----------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.view.SurfaceHolder;

import com.google.zxing.PlanarYUVLuminanceSource;
import com.google.zxing.client.android.CaptureActivity;
import com.google.zxing.client.android.camera.open.OpenCamera;
import com.google.zxing.client.android.camera.open.OpenCameraInterface;

Expand All @@ -45,7 +46,7 @@ public final class CameraManager {
private static final int MIN_FRAME_WIDTH = 240;
private static final int MIN_FRAME_HEIGHT = 240;
private static final int MAX_FRAME_WIDTH = 675;
private static final int MAX_FRAME_HEIGHT = 675;
private static final int MAX_FRAME_HEIGHT = 675; // = 5/8 * 1080

private final Context context;
private final CameraConfigurationManager configManager;
Expand Down Expand Up @@ -253,6 +254,10 @@ public synchronized Rect getFramingRect() {

int leftOffset = (screenResolution.x - width) / 2;
int topOffset = (screenResolution.y - height) / 2;
//高度偏移值
if (CaptureActivity.getScanConfig() != null) {
topOffset = topOffset - CaptureActivity.getScanConfig().getScanFrameHeightOffect();
}
framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height);
Log.d(TAG, "Calculated framing rect: " + framingRect);
}
Expand Down Expand Up @@ -360,9 +365,15 @@ public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int
if (rect == null) {
return null;
}
// Go ahead and assume it's YUV rather than die.
if (CaptureActivity.getScanConfig() != null && CaptureActivity.getScanConfig().isFullScreenScan()) {
//识别区域改为全屏
return new PlanarYUVLuminanceSource(data, width, height, 0, 0,
width, height, false);
}
//识别区域是中间区域
return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
rect.width(), rect.height(), false);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public enum LaserStyle {
private int gridScanLineHeight;
//显示闪光灯
private boolean showLightController = true;
//扫描框高度偏移值:+向上偏移,-向下偏移 (单位px)
private int scanFrameHeightOffect;
//是否需要全屏扫描,默认值扫描扫描框中的二维码
private boolean isFullScreenScan = false;

private MNScanConfig() {

Expand All @@ -88,6 +92,8 @@ private MNScanConfig(Builder builder) {
showLightController = builder.showLightController;
scanHintTextColor = builder.scanHintTextColor;
scanHintTextSize = builder.scanHintTextSize;
scanFrameHeightOffect = builder.scanFrameHeightOffect;
isFullScreenScan = builder.isFullScreenScan;
}

public LaserStyle getLaserStyle() {
Expand Down Expand Up @@ -226,6 +232,22 @@ public void setScanHintTextSize(int scanHintTextSize) {
this.scanHintTextSize = scanHintTextSize;
}

public int getScanFrameHeightOffect() {
return scanFrameHeightOffect;
}

public void setScanFrameHeightOffect(int scanFrameHeightOffect) {
this.scanFrameHeightOffect = scanFrameHeightOffect;
}

public boolean isFullScreenScan() {
return isFullScreenScan;
}

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

public static class Builder {
private boolean showPhotoAlbum = true;
private boolean showBeep = true;
Expand All @@ -248,6 +270,10 @@ public static class Builder {
private String scanHintTextColor;
//扫描提示文案字体大小
private int scanHintTextSize;
//扫描框高度偏移值:+向上偏移,-向下偏移
private int scanFrameHeightOffect = 0;
//是否需要全屏扫描,默认值扫描扫描框中的二维码
private boolean isFullScreenScan = false;

public MNScanConfig builder() {
return new MNScanConfig(this);
Expand Down Expand Up @@ -339,6 +365,16 @@ public Builder setScanHintTextSize(int scanHintTextSize) {
return this;
}

public Builder setScanFrameHeightOffect(int scanFrameHeightOffect) {
this.scanFrameHeightOffect = scanFrameHeightOffect;
return this;
}

public Builder setFullScreenScan(boolean fullScreenScan) {
isFullScreenScan = fullScreenScan;
return this;
}

}

}

0 comments on commit 1c6c2c5

Please sign in to comment.