From 1c6c2c5e68608e3cce0f839b02d33c6c9d5e4580 Mon Sep 17 00:00:00 2001 From: maning <154292322@qq.com> Date: Tue, 17 Sep 2019 16:50:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=9A1=E9=AB=98=E5=BA=A6=E5=81=8F=E7=A7=BB=E5=80=BC?= =?UTF-8?q?=EF=BC=8C2=E5=85=A8=E5=B1=8F=E6=89=AB=E6=8F=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 28 +++++---------- .../maning/zxingcodedemo/MainActivity.java | 7 ++++ .../zxing/client/android/CaptureActivity.java | 21 +++++++++-- .../client/android/camera/CameraManager.java | 15 ++++++-- .../client/android/model/MNScanConfig.java | 36 +++++++++++++++++++ 5 files changed, 82 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 6f234b0..09b79cd 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,10 @@ .setGridScanLineColumn(30) //网格高度 .setGridScanLineHeight(150) + //高度偏移值(单位px) + .setScanFrameHeightOffect(150) + //是否全屏扫描 + .setFullScreenScan(true) //自定义遮罩 .setCustomShadeViewLayoutID(R.layout.layout_custom_view, new MNCustomViewBindCallback() { @Override @@ -161,6 +165,10 @@ ``` ## 版本记录: + v2.1.2(未发布): + 1.支持设置扫描框高度偏移值 + 2.支持设置全屏扫描(默认只扫描扫描框内的二维码) + v2.1.1: 1.支持网格扫描线设置列数和高度 2.支持隐藏默认闪光灯开关 @@ -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.优化界面显示 - ## 感谢: diff --git a/app/src/main/java/com/maning/zxingcodedemo/MainActivity.java b/app/src/main/java/com/maning/zxingcodedemo/MainActivity.java index 5bba155..537f238 100644 --- a/app/src/main/java/com/maning/zxingcodedemo/MainActivity.java +++ b/app/src/main/java/com/maning/zxingcodedemo/MainActivity.java @@ -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); diff --git a/libraryzxing/src/main/java/com/google/zxing/client/android/CaptureActivity.java b/libraryzxing/src/main/java/com/google/zxing/client/android/CaptureActivity.java index 17f90ea..425624b 100755 --- a/libraryzxing/src/main/java/com/google/zxing/client/android/CaptureActivity.java +++ b/libraryzxing/src/main/java/com/google/zxing/client/android/CaptureActivity.java @@ -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; } @@ -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(); @@ -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; + } + //---------对外提供方法---------- diff --git a/libraryzxing/src/main/java/com/google/zxing/client/android/camera/CameraManager.java b/libraryzxing/src/main/java/com/google/zxing/client/android/camera/CameraManager.java index 487220b..bc31189 100755 --- a/libraryzxing/src/main/java/com/google/zxing/client/android/camera/CameraManager.java +++ b/libraryzxing/src/main/java/com/google/zxing/client/android/camera/CameraManager.java @@ -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; @@ -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; @@ -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); } @@ -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); + } } diff --git a/libraryzxing/src/main/java/com/google/zxing/client/android/model/MNScanConfig.java b/libraryzxing/src/main/java/com/google/zxing/client/android/model/MNScanConfig.java index e8f1daa..f2eff8b 100644 --- a/libraryzxing/src/main/java/com/google/zxing/client/android/model/MNScanConfig.java +++ b/libraryzxing/src/main/java/com/google/zxing/client/android/model/MNScanConfig.java @@ -64,6 +64,10 @@ public enum LaserStyle { private int gridScanLineHeight; //显示闪光灯 private boolean showLightController = true; + //扫描框高度偏移值:+向上偏移,-向下偏移 (单位px) + private int scanFrameHeightOffect; + //是否需要全屏扫描,默认值扫描扫描框中的二维码 + private boolean isFullScreenScan = false; private MNScanConfig() { @@ -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() { @@ -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; @@ -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); @@ -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; + } + } }