From e5dd957c0560b31e729d13c756347d9bbc0cf478 Mon Sep 17 00:00:00 2001 From: hupei Date: Fri, 22 Jan 2021 16:22:51 +0800 Subject: [PATCH] release 2.2.0 --- README.md | 2 +- .../sample/OptionsScannerActivity.java | 7 +-- .../res/layout/activity_scanner_options.xml | 4 -- zxingscanner/build.gradle | 2 +- .../mylhyl/zxing/scanner/ViewfinderView.java | 49 +++++++++++-------- 5 files changed, 31 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index b8e5c21..060332d 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ - 依赖使用 Gradle 构建时添加一下即可 ```javascript -compile 'com.mylhyl:zxingscanner:2.1.9' +compile 'com.mylhyl:zxingscanner:2.2.0' ``` ## 2、离线jar,需要手动添加 Zxing 核心库 diff --git a/sample/src/main/java/com/mylhyl/zxing/scanner/sample/OptionsScannerActivity.java b/sample/src/main/java/com/mylhyl/zxing/scanner/sample/OptionsScannerActivity.java index 7e9987e..ec99e8a 100644 --- a/sample/src/main/java/com/mylhyl/zxing/scanner/sample/OptionsScannerActivity.java +++ b/sample/src/main/java/com/mylhyl/zxing/scanner/sample/OptionsScannerActivity.java @@ -48,11 +48,6 @@ protected void onCreate(Bundle savedInstanceState) { Drawable tintDrawable = DrawableCompat.wrap(originalDrawable).mutate(); DrawableCompat.setTint(tintDrawable, Color.RED); - Bitmap bitmap = Scanner.drawableToBitmap(tintDrawable); - - ImageView imageView = findViewById(R.id.imageView); - imageView.setImageBitmap(bitmap); - ScannerOptions.Builder builder = new ScannerOptions.Builder(); builder // .setFrameStrokeColor(Color.RED) @@ -74,7 +69,7 @@ protected void onCreate(Bundle savedInstanceState) { // .setLaserLine(ScannerOptions.LaserStyle.RES_GRID, R.mipmap.zfb_grid_scan_line)//网格图 // .setFrameCornerColor(0xFF26CEFF)//支付宝颜色 -// .setScanFullScreen(true) + .setScanFullScreen(true) // .setFrameHide(false) // .setFrameCornerHide(true) diff --git a/sample/src/main/res/layout/activity_scanner_options.xml b/sample/src/main/res/layout/activity_scanner_options.xml index b800da7..08a8f9d 100644 --- a/sample/src/main/res/layout/activity_scanner_options.xml +++ b/sample/src/main/res/layout/activity_scanner_options.xml @@ -10,8 +10,4 @@ android:layout_width="match_parent" android:layout_height="match_parent" /> - diff --git a/zxingscanner/build.gradle b/zxingscanner/build.gradle index 17741ff..ba08d7a 100644 --- a/zxingscanner/build.gradle +++ b/zxingscanner/build.gradle @@ -7,7 +7,7 @@ android { minSdkVersion 15 targetSdkVersion 28 versionCode 20210122 - versionName '2.1.9' + versionName '2.2.0' } buildTypes { release { diff --git a/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/ViewfinderView.java b/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/ViewfinderView.java index 41108b5..71e6b3b 100644 --- a/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/ViewfinderView.java +++ b/zxingscanner/src/main/java/com/mylhyl/zxing/scanner/ViewfinderView.java @@ -316,34 +316,41 @@ private void drawLaserLine(Canvas canvas, Rect frame) { * @param point */ private void drawLaserLineFullScreen(Canvas canvas, Point point) { - if (scannerOptions.getLaserStyle() == ScannerOptions.LaserStyle.COLOR_LINE) { + ScannerOptions.LaserStyle laserLineStyle = scannerOptions.getLaserStyle(); + if (laserLineStyle == ScannerOptions.LaserStyle.COLOR_LINE) { paint.setStyle(Paint.Style.FILL); paint.setColor(scannerOptions.getLaserLineColor());// 设置扫描线颜色 canvas.drawRect(0, laserLineTop, point.x, laserLineTop + laserLineHeight, paint); - } else { - if (laserLineBitmap == null)//图片资源文件转为 Bitmap + return; + } + // 图片资源文件转为 Bitmap + if (laserLineBitmap == null) { + if (laserLineStyle == ScannerOptions.LaserStyle.DRAWABLE_LINE || + laserLineStyle == ScannerOptions.LaserStyle.DRAWABLE_GRID) { + laserLineBitmap = Scanner.drawableToBitmap(scannerOptions.getLaserLineDrawable()); + } else { laserLineBitmap = BitmapFactory.decodeResource(getResources(), scannerOptions.getLaserLineResId()); - int height = laserLineBitmap.getHeight();//取原图高 - //网格图片 - if (scannerOptions.getLaserStyle() == ScannerOptions.LaserStyle.RES_GRID) { - int dstRectFTop = 0; - if (laserLineTop >= height) { - dstRectFTop = laserLineTop - height; - } - RectF dstRectF = new RectF(0, dstRectFTop, point.x, laserLineTop); - Rect srcRect = new Rect(0, (int) (height - dstRectF.height()), laserLineBitmap.getWidth(), height); - canvas.drawBitmap(laserLineBitmap, srcRect, dstRectF, paint); } - //线条图片 - else { - //如果没有设置线条高度,则用图片原始高度 - if (laserLineHeight == dp2px(ScannerOptions.DEFAULT_LASER_LINE_HEIGHT)) { - laserLineHeight = laserLineBitmap.getHeight() / 2; - } - Rect laserRect = new Rect(0, laserLineTop, point.x, laserLineTop + laserLineHeight); - canvas.drawBitmap(laserLineBitmap, null, laserRect, paint); + } + int height = laserLineBitmap.getHeight();//取原图高 + // 网格图片 + if (laserLineStyle == ScannerOptions.LaserStyle.RES_GRID || + laserLineStyle == ScannerOptions.LaserStyle.DRAWABLE_GRID) { + int dstRectFTop = 0; + if (laserLineTop >= height) { + dstRectFTop = laserLineTop - height; } + RectF dstRectF = new RectF(0, dstRectFTop, point.x, laserLineTop); + Rect srcRect = new Rect(0, (int) (height - dstRectF.height()), laserLineBitmap.getWidth(), height); + canvas.drawBitmap(laserLineBitmap, srcRect, dstRectF, paint); + return; } + // 线条图片, 如果没有设置线条高度,则用图片原始高度 + if (laserLineHeight == dp2px(ScannerOptions.DEFAULT_LASER_LINE_HEIGHT)) { + laserLineHeight = laserLineBitmap.getHeight() / 2; + } + Rect laserRect = new Rect(0, laserLineTop, point.x, laserLineTop + laserLineHeight); + canvas.drawBitmap(laserLineBitmap, null, laserRect, paint); } void drawViewfinder() {