1、支持真实识别区域比例和识别区域偏移量可配置
2、对外暴露更多可配置参数
This commit is contained in:
21
README.md
21
README.md
@@ -39,6 +39,13 @@ ZXingLite for Android 是ZXing的精简版,基于ZXing库优化扫码和生成
|
|||||||
| laserStyle | enum | line | 扫描激光的样式 |
|
| laserStyle | enum | line | 扫描激光的样式 |
|
||||||
| gridColumn | integer | 20 | 网格扫描激光列数 |
|
| gridColumn | integer | 20 | 网格扫描激光列数 |
|
||||||
| gridHeight | integer | 40dp | 网格扫描激光高度,为0dp时,表示动态铺满 |
|
| gridHeight | integer | 40dp | 网格扫描激光高度,为0dp时,表示动态铺满 |
|
||||||
|
| cornerRectWidth | dimension | 4dp | 扫描区边角的宽 |
|
||||||
|
| cornerRectHeight | dimension | 16dp | 扫描区边角的高 |
|
||||||
|
| scannerLineMoveDistance | dimension | 2dp | 扫描线每次移动距离 |
|
||||||
|
| scannerLineHeight | dimension | 5dp | 扫描线高度 |
|
||||||
|
| frameLineWidth | dimension | 1dp | 边框线宽度 |
|
||||||
|
| scannerAnimationDelay | integer | 15 | 扫描动画延迟间隔时间,单位:毫秒 |
|
||||||
|
| frameRatio | float | 0.625f | 扫码框与屏幕占比 |
|
||||||
|
|
||||||
|
|
||||||
## 引入
|
## 引入
|
||||||
@@ -48,21 +55,21 @@ ZXingLite for Android 是ZXing的精简版,基于ZXing库优化扫码和生成
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.king.zxing</groupId>
|
<groupId>com.king.zxing</groupId>
|
||||||
<artifactId>zxing-lite</artifactId>
|
<artifactId>zxing-lite</artifactId>
|
||||||
<version>1.1.2</version>
|
<version>1.1.3</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
### Gradle:
|
### Gradle:
|
||||||
```gradle
|
```gradle
|
||||||
//AndroidX 版本
|
//AndroidX 版本
|
||||||
implementation 'com.king.zxing:zxing-lite:1.1.2-androidx'
|
implementation 'com.king.zxing:zxing-lite:1.1.3-androidx'
|
||||||
|
|
||||||
//Android 版本
|
//Android 版本
|
||||||
implementation 'com.king.zxing:zxing-lite:1.1.2'
|
implementation 'com.king.zxing:zxing-lite:1.1.3'
|
||||||
```
|
```
|
||||||
### Lvy:
|
### Lvy:
|
||||||
```lvy
|
```lvy
|
||||||
<dependency org='com.king.zxing' name='zxing-lite' rev='1.1.2'>
|
<dependency org='com.king.zxing' name='zxing-lite' rev='1.1.3'>
|
||||||
<artifact name='$AID' ext='pom'></artifact>
|
<artifact name='$AID' ext='pom'></artifact>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
@@ -140,6 +147,10 @@ api 'com.google.zxing:core:3.3.3'
|
|||||||
|
|
||||||
## 版本记录
|
## 版本记录
|
||||||
|
|
||||||
|
#### v1.1.3:2019-9-24
|
||||||
|
* 支持真实识别区域比例和识别区域偏移量可配置
|
||||||
|
* 对外暴露更多可配置参数
|
||||||
|
|
||||||
#### v1.1.2:2019-6-27
|
#### v1.1.2:2019-6-27
|
||||||
* 优化部分细节,为迁移至AndroidX做准备
|
* 优化部分细节,为迁移至AndroidX做准备
|
||||||
* 支持AndroidX对应版本
|
* 支持AndroidX对应版本
|
||||||
@@ -196,6 +207,8 @@ api 'com.google.zxing:core:3.3.3'
|
|||||||
|
|
||||||
CSDN: <a title="CSDN博客" href="http://blog.csdn.net/jenly121" target="_blank">jenly121</a>
|
CSDN: <a title="CSDN博客" href="http://blog.csdn.net/jenly121" target="_blank">jenly121</a>
|
||||||
|
|
||||||
|
博客园: <a title="博客园" href="https://www.cnblogs.com/jenly" target="_blank">jenly</a>
|
||||||
|
|
||||||
Github: <a title="Github开源项目" href="https://github.com/jenly1314" target="_blank">jenly1314</a>
|
Github: <a title="Github开源项目" href="https://github.com/jenly1314" target="_blank">jenly1314</a>
|
||||||
|
|
||||||
加入QQ群: <a title="点击加入QQ群" href="http://shang.qq.com/wpa/qunwpa?idkey=8fcc6a2f88552ea44b1411582c94fd124f7bb3ec227e2a400dbbfaad3dc2f5ad" target="_blank">20867961</a>
|
加入QQ群: <a title="点击加入QQ群" href="http://shang.qq.com/wpa/qunwpa?idkey=8fcc6a2f88552ea44b1411582c94fd124f7bb3ec227e2a400dbbfaad3dc2f5ad" target="_blank">20867961</a>
|
||||||
|
|||||||
Binary file not shown.
@@ -1 +1 @@
|
|||||||
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":11,"versionName":"1.1.2","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
|
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":13,"versionName":"1.1.3","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
|
||||||
@@ -61,8 +61,11 @@ public class CustomCaptureActivity extends CaptureActivity {
|
|||||||
//获取CaptureHelper,里面有扫码相关的配置设置
|
//获取CaptureHelper,里面有扫码相关的配置设置
|
||||||
getCaptureHelper().playBeep(false)//播放音效
|
getCaptureHelper().playBeep(false)//播放音效
|
||||||
.vibrate(true)//震动
|
.vibrate(true)//震动
|
||||||
// .decodeFormats(DecodeFormatManager.QR_CODE_FORMATS)//设置只识别二维码会提升速度
|
|
||||||
.supportVerticalCode(true)//支持扫垂直条码,建议有此需求时才使用。
|
.supportVerticalCode(true)//支持扫垂直条码,建议有此需求时才使用。
|
||||||
|
// .decodeFormats(DecodeFormatManager.QR_CODE_FORMATS)//设置只识别二维码会提升速度
|
||||||
|
// .framingRectRatio(0.9f)//设置识别区域比例,范围建议在0.625 ~ 1.0之间。非全屏识别时才有效
|
||||||
|
// .framingRectVerticalOffset(0)//设置识别区域垂直方向偏移量,非全屏识别时才有效
|
||||||
|
// .framingRectHorizontalOffset(0)//设置识别区域水平方向偏移量,非全屏识别时才有效
|
||||||
.continuousScan(isContinuousScan);//是否连扫
|
.continuousScan(isContinuousScan);//是否连扫
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,9 @@
|
|||||||
android:background="@color/colorPrimary"
|
android:background="@color/colorPrimary"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:contentInsetLeft="0dp"
|
app:contentInsetLeft="0dp"
|
||||||
app:contentInsetStart="0dp">
|
app:contentInsetStart="0dp"
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvTitle"
|
android:id="@+id/tvTitle"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -32,7 +34,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="20dp"
|
android:layout_marginLeft="20dp"
|
||||||
android:layout_marginRight="20dp"
|
android:layout_marginRight="20dp"
|
||||||
android:layout_marginTop="6dp"
|
android:layout_marginTop="16dp"
|
||||||
android:layout_marginBottom="6dp"
|
android:layout_marginBottom="6dp"
|
||||||
android:text="默认扫码"
|
android:text="默认扫码"
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ package com.king.zxing;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.RectF;
|
import android.graphics.RectF;
|
||||||
import android.hardware.Camera;
|
import android.hardware.Camera;
|
||||||
|
import android.support.annotation.FloatRange;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
@@ -114,6 +114,19 @@ public class CaptureHelper implements CaptureLifecycle,CaptureTouchEvent,Capture
|
|||||||
*/
|
*/
|
||||||
private boolean isFullScreenScan;
|
private boolean isFullScreenScan;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 识别区域比例,范围建议在0.625 ~ 1.0之间,默认0.9
|
||||||
|
*/
|
||||||
|
private float framingRectRatio = 0.9f;
|
||||||
|
/**
|
||||||
|
* 识别区域垂直方向偏移量
|
||||||
|
*/
|
||||||
|
private int framingRectVerticalOffset;
|
||||||
|
/**
|
||||||
|
* 识别区域水平方向偏移量
|
||||||
|
*/
|
||||||
|
private int framingRectHorizontalOffset;
|
||||||
|
|
||||||
private OnCaptureCallback onCaptureCallback;
|
private OnCaptureCallback onCaptureCallback;
|
||||||
|
|
||||||
|
|
||||||
@@ -139,6 +152,9 @@ public class CaptureHelper implements CaptureLifecycle,CaptureTouchEvent,Capture
|
|||||||
|
|
||||||
cameraManager = new CameraManager(activity);
|
cameraManager = new CameraManager(activity);
|
||||||
cameraManager.setFullScreenScan(isFullScreenScan);
|
cameraManager.setFullScreenScan(isFullScreenScan);
|
||||||
|
cameraManager.setFramingRectRatio(framingRectRatio);
|
||||||
|
cameraManager.setFramingRectVerticalOffset(framingRectVerticalOffset);
|
||||||
|
cameraManager.setFramingRectHorizontalOffset(framingRectHorizontalOffset);
|
||||||
callback = new SurfaceHolder.Callback() {
|
callback = new SurfaceHolder.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void surfaceCreated(SurfaceHolder holder) {
|
public void surfaceCreated(SurfaceHolder holder) {
|
||||||
@@ -162,15 +178,10 @@ public class CaptureHelper implements CaptureLifecycle,CaptureTouchEvent,Capture
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
onCaptureListener = new OnCaptureListener() {
|
onCaptureListener = (result, barcode, scaleFactor) -> {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onHandleDecode(Result result, Bitmap barcode, float scaleFactor) {
|
|
||||||
inactivityTimer.onActivity();
|
inactivityTimer.onActivity();
|
||||||
beepManager.playBeepSoundAndVibrate();
|
beepManager.playBeepSoundAndVibrate();
|
||||||
onResult(result);
|
onResult(result);
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
//设置是否播放音效和震动
|
//设置是否播放音效和震动
|
||||||
beepManager.setPlayBeep(isPlayBeep);
|
beepManager.setPlayBeep(isPlayBeep);
|
||||||
@@ -309,6 +320,7 @@ public class CaptureHelper implements CaptureLifecycle,CaptureTouchEvent,Capture
|
|||||||
* @param event
|
* @param event
|
||||||
* @param camera
|
* @param camera
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
private void focusOnTouch(MotionEvent event,Camera camera) {
|
private void focusOnTouch(MotionEvent event,Camera camera) {
|
||||||
|
|
||||||
Camera.Parameters params = camera.getParameters();
|
Camera.Parameters params = camera.getParameters();
|
||||||
@@ -332,13 +344,10 @@ public class CaptureHelper implements CaptureLifecycle,CaptureTouchEvent,Capture
|
|||||||
params.setFocusMode(Camera.Parameters.FOCUS_MODE_MACRO);
|
params.setFocusMode(Camera.Parameters.FOCUS_MODE_MACRO);
|
||||||
camera.setParameters(params);
|
camera.setParameters(params);
|
||||||
|
|
||||||
camera.autoFocus(new Camera.AutoFocusCallback() {
|
camera.autoFocus((success, camera1) -> {
|
||||||
@Override
|
Camera.Parameters params1 = camera1.getParameters();
|
||||||
public void onAutoFocus(boolean success, Camera camera) {
|
params1.setFocusMode(currentFocusMode);
|
||||||
Camera.Parameters params = camera.getParameters();
|
camera1.setParameters(params1);
|
||||||
params.setFocusMode(currentFocusMode);
|
|
||||||
camera.setParameters(params);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -421,9 +430,7 @@ public class CaptureHelper implements CaptureLifecycle,CaptureTouchEvent,Capture
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(isPlayBeep){//如果播放音效,则稍微延迟一点,给予播放音效时间
|
if(isPlayBeep){//如果播放音效,则稍微延迟一点,给予播放音效时间
|
||||||
captureHandler.postDelayed(new Runnable() {
|
captureHandler.postDelayed(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
//如果设置了回调,并且onCallback返回为true,则表示拦截
|
//如果设置了回调,并且onCallback返回为true,则表示拦截
|
||||||
if(onCaptureCallback!=null && onCaptureCallback.onResultCallback(text)){
|
if(onCaptureCallback!=null && onCaptureCallback.onResultCallback(text)){
|
||||||
return;
|
return;
|
||||||
@@ -432,7 +439,6 @@ public class CaptureHelper implements CaptureLifecycle,CaptureTouchEvent,Capture
|
|||||||
intent.putExtra(Intents.Scan.RESULT,text);
|
intent.putExtra(Intents.Scan.RESULT,text);
|
||||||
activity.setResult(Activity.RESULT_OK,intent);
|
activity.setResult(Activity.RESULT_OK,intent);
|
||||||
activity.finish();
|
activity.finish();
|
||||||
}
|
|
||||||
},100);
|
},100);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -599,6 +605,46 @@ public class CaptureHelper implements CaptureLifecycle,CaptureTouchEvent,Capture
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置识别区域比例,范围建议在0.625 ~ 1.0之间。非全屏识别时才有效
|
||||||
|
* 0.625 即与默认推荐显示区域一致,1.0表示与宽度一致
|
||||||
|
* @param framingRectRatio 默认0.9
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public CaptureHelper framingRectRatio(@FloatRange(from = 0.0f ,to = 1.0f) float framingRectRatio) {
|
||||||
|
this.framingRectRatio = framingRectRatio;
|
||||||
|
if(cameraManager!=null){
|
||||||
|
cameraManager.setFramingRectRatio(framingRectRatio);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置识别区域垂直方向偏移量,非全屏识别时才有效
|
||||||
|
* @param framingRectVerticalOffset 默认0,表示不偏移
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public CaptureHelper framingRectVerticalOffset(int framingRectVerticalOffset) {
|
||||||
|
this.framingRectVerticalOffset = framingRectVerticalOffset;
|
||||||
|
if(cameraManager!=null){
|
||||||
|
cameraManager.setFramingRectVerticalOffset(framingRectVerticalOffset);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置识别区域水平方向偏移量,非全屏识别时才有效
|
||||||
|
* @param framingRectHorizontalOffset 默认0,表示不偏移
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public CaptureHelper framingRectHorizontalOffset(int framingRectHorizontalOffset) {
|
||||||
|
this.framingRectHorizontalOffset = framingRectHorizontalOffset;
|
||||||
|
if(cameraManager!=null){
|
||||||
|
cameraManager.setFramingRectHorizontalOffset(framingRectHorizontalOffset);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置扫码回调
|
* 设置扫码回调
|
||||||
|
|||||||
@@ -17,17 +17,11 @@ package com.king.zxing;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.LinearGradient;
|
import android.graphics.LinearGradient;
|
||||||
import android.graphics.Matrix;
|
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Path;
|
|
||||||
import android.graphics.PointF;
|
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.RectF;
|
import android.graphics.RectF;
|
||||||
import android.graphics.Shader;
|
import android.graphics.Shader;
|
||||||
@@ -41,7 +35,6 @@ import android.text.TextPaint;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
@@ -58,52 +51,141 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public final class ViewfinderView extends View {
|
public final class ViewfinderView extends View {
|
||||||
|
|
||||||
private static final long ANIMATION_DELAY = 15L;
|
|
||||||
private static final int CURRENT_POINT_OPACITY = 0xA0;
|
private static final int CURRENT_POINT_OPACITY = 0xA0;
|
||||||
private static final int MAX_RESULT_POINTS = 20;
|
private static final int MAX_RESULT_POINTS = 20;
|
||||||
private static final int POINT_SIZE = 20;
|
private static final int POINT_SIZE = 20;
|
||||||
|
|
||||||
private static final int CORNER_RECT_WIDTH = 8; //扫描区边角的宽
|
/**
|
||||||
private static final int CORNER_RECT_HEIGHT = 40; //扫描区边角的高
|
* 画笔
|
||||||
private static final int SCANNER_LINE_MOVE_DISTANCE = 6; //扫描线移动距离
|
*/
|
||||||
private static final int SCANNER_LINE_HEIGHT = 10; //扫描线宽度
|
|
||||||
|
|
||||||
private Paint paint;
|
private Paint paint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文本画笔
|
||||||
|
*/
|
||||||
private TextPaint textPaint;
|
private TextPaint textPaint;
|
||||||
|
/**
|
||||||
|
* 扫码框外面遮罩颜色
|
||||||
|
*/
|
||||||
private int maskColor;
|
private int maskColor;
|
||||||
//扫描区域边框颜色
|
/**
|
||||||
|
* 扫描区域边框颜色
|
||||||
|
*/
|
||||||
private int frameColor;
|
private int frameColor;
|
||||||
//扫描线颜色
|
/**
|
||||||
|
* 扫描线颜色
|
||||||
|
*/
|
||||||
private int laserColor;
|
private int laserColor;
|
||||||
//四角颜色
|
/**
|
||||||
|
* 扫码框四角颜色
|
||||||
|
*/
|
||||||
private int cornerColor;
|
private int cornerColor;
|
||||||
|
/**
|
||||||
|
* 结果点颜色
|
||||||
|
*/
|
||||||
private int resultPointColor;
|
private int resultPointColor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提示文本与扫码框的边距
|
||||||
|
*/
|
||||||
private float labelTextPadding;
|
private float labelTextPadding;
|
||||||
|
/**
|
||||||
|
* 提示文本的位置
|
||||||
|
*/
|
||||||
private TextLocation labelTextLocation;
|
private TextLocation labelTextLocation;
|
||||||
//扫描区域提示文本
|
/**
|
||||||
|
* 扫描区域提示文本
|
||||||
|
*/
|
||||||
private String labelText;
|
private String labelText;
|
||||||
//扫描区域提示文本颜色
|
/**
|
||||||
|
* 扫描区域提示文本颜色
|
||||||
|
*/
|
||||||
private int labelTextColor;
|
private int labelTextColor;
|
||||||
|
/**
|
||||||
|
* 提示文本字体大小
|
||||||
|
*/
|
||||||
private float labelTextSize;
|
private float labelTextSize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扫描线开始位置
|
||||||
|
*/
|
||||||
public int scannerStart = 0;
|
public int scannerStart = 0;
|
||||||
|
/**
|
||||||
|
* 扫描线结束位置
|
||||||
|
*/
|
||||||
public int scannerEnd = 0;
|
public int scannerEnd = 0;
|
||||||
|
/**
|
||||||
|
* 是否显示结果点
|
||||||
|
*/
|
||||||
private boolean isShowResultPoint;
|
private boolean isShowResultPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 屏幕宽
|
||||||
|
*/
|
||||||
private int screenWidth;
|
private int screenWidth;
|
||||||
|
/**
|
||||||
|
* 屏幕高
|
||||||
|
*/
|
||||||
private int screenHeight;
|
private int screenHeight;
|
||||||
//扫码框宽
|
/**
|
||||||
|
* 扫码框宽
|
||||||
|
*/
|
||||||
private int frameWidth;
|
private int frameWidth;
|
||||||
//扫码框宽
|
/**
|
||||||
|
* 扫码框高
|
||||||
|
*/
|
||||||
private int frameHeight;
|
private int frameHeight;
|
||||||
//扫描激光线风格
|
/**
|
||||||
|
* 扫描激光线风格
|
||||||
|
*/
|
||||||
private LaserStyle laserStyle;
|
private LaserStyle laserStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 网格列数
|
||||||
|
*/
|
||||||
private int gridColumn;
|
private int gridColumn;
|
||||||
|
/**
|
||||||
|
* 网格高度
|
||||||
|
*/
|
||||||
private int gridHeight;
|
private int gridHeight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扫码框
|
||||||
|
*/
|
||||||
private Rect frame;
|
private Rect frame;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扫描区边角的宽
|
||||||
|
*/
|
||||||
|
private int cornerRectWidth;
|
||||||
|
/**
|
||||||
|
* 扫描区边角的高
|
||||||
|
*/
|
||||||
|
private int cornerRectHeight;
|
||||||
|
/**
|
||||||
|
* 扫描线每次移动距离
|
||||||
|
*/
|
||||||
|
private int scannerLineMoveDistance;
|
||||||
|
/**
|
||||||
|
* 扫描线高度
|
||||||
|
*/
|
||||||
|
private int scannerLineHeight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 边框线宽度
|
||||||
|
*/
|
||||||
|
private int frameLineWidth;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扫描动画延迟间隔时间 默认15毫秒
|
||||||
|
*/
|
||||||
|
private int scannerAnimationDelay;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扫码框占比
|
||||||
|
*/
|
||||||
|
private float frameRatio;
|
||||||
|
|
||||||
|
|
||||||
private List<ResultPoint> possibleResultPoints;
|
private List<ResultPoint> possibleResultPoints;
|
||||||
private List<ResultPoint> lastPossibleResultPoints;
|
private List<ResultPoint> lastPossibleResultPoints;
|
||||||
@@ -188,6 +270,13 @@ public final class ViewfinderView extends View {
|
|||||||
gridColumn = array.getInt(R.styleable.ViewfinderView_gridColumn,20);
|
gridColumn = array.getInt(R.styleable.ViewfinderView_gridColumn,20);
|
||||||
gridHeight = (int)array.getDimension(R.styleable.ViewfinderView_gridHeight,TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,40,getResources().getDisplayMetrics()));
|
gridHeight = (int)array.getDimension(R.styleable.ViewfinderView_gridHeight,TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,40,getResources().getDisplayMetrics()));
|
||||||
|
|
||||||
|
cornerRectWidth = (int)array.getDimension(R.styleable.ViewfinderView_cornerRectWidth,TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,4,getResources().getDisplayMetrics()));
|
||||||
|
cornerRectHeight = (int)array.getDimension(R.styleable.ViewfinderView_cornerRectHeight,TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,16,getResources().getDisplayMetrics()));
|
||||||
|
scannerLineMoveDistance = (int)array.getDimension(R.styleable.ViewfinderView_scannerLineMoveDistance,TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,2,getResources().getDisplayMetrics()));
|
||||||
|
scannerLineHeight = (int)array.getDimension(R.styleable.ViewfinderView_scannerLineHeight,TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,5,getResources().getDisplayMetrics()));
|
||||||
|
frameLineWidth = (int)array.getDimension(R.styleable.ViewfinderView_frameLineWidth,TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,1,getResources().getDisplayMetrics()));
|
||||||
|
scannerAnimationDelay = array.getInteger(R.styleable.ViewfinderView_scannerAnimationDelay,15);
|
||||||
|
frameRatio = array.getFloat(R.styleable.ViewfinderView_frameRatio,0.625f);
|
||||||
array.recycle();
|
array.recycle();
|
||||||
|
|
||||||
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
@@ -199,7 +288,7 @@ public final class ViewfinderView extends View {
|
|||||||
screenWidth = getDisplayMetrics().widthPixels;
|
screenWidth = getDisplayMetrics().widthPixels;
|
||||||
screenHeight = getDisplayMetrics().heightPixels;
|
screenHeight = getDisplayMetrics().heightPixels;
|
||||||
|
|
||||||
int size = (int)(Math.min(screenWidth,screenHeight) * 0.625f);
|
int size = (int)(Math.min(screenWidth,screenHeight) * frameRatio);
|
||||||
|
|
||||||
if(frameWidth<=0 || frameWidth > screenWidth){
|
if(frameWidth<=0 || frameWidth > screenWidth){
|
||||||
frameWidth = size;
|
frameWidth = size;
|
||||||
@@ -240,7 +329,6 @@ public final class ViewfinderView extends View {
|
|||||||
frame = new Rect(leftOffset, topOffset, leftOffset + frameWidth, topOffset + frameHeight);
|
frame = new Rect(leftOffset, topOffset, leftOffset + frameWidth, topOffset + frameHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("DrawAllocation")
|
|
||||||
@Override
|
@Override
|
||||||
public void onDraw(Canvas canvas) {
|
public void onDraw(Canvas canvas) {
|
||||||
|
|
||||||
@@ -250,7 +338,7 @@ public final class ViewfinderView extends View {
|
|||||||
|
|
||||||
if(scannerStart == 0 || scannerEnd == 0) {
|
if(scannerStart == 0 || scannerEnd == 0) {
|
||||||
scannerStart = frame.top;
|
scannerStart = frame.top;
|
||||||
scannerEnd = frame.bottom - SCANNER_LINE_HEIGHT;
|
scannerEnd = frame.bottom - scannerLineHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
int width = canvas.getWidth();
|
int width = canvas.getWidth();
|
||||||
@@ -270,7 +358,7 @@ public final class ViewfinderView extends View {
|
|||||||
drawResultPoint(canvas,frame);
|
drawResultPoint(canvas,frame);
|
||||||
// Request another update at the animation interval, but only repaint the laser line,
|
// Request another update at the animation interval, but only repaint the laser line,
|
||||||
// not the entire viewfinder mask.
|
// not the entire viewfinder mask.
|
||||||
postInvalidateDelayed(ANIMATION_DELAY,
|
postInvalidateDelayed(scannerAnimationDelay,
|
||||||
frame.left - POINT_SIZE,
|
frame.left - POINT_SIZE,
|
||||||
frame.top - POINT_SIZE,
|
frame.top - POINT_SIZE,
|
||||||
frame.right + POINT_SIZE,
|
frame.right + POINT_SIZE,
|
||||||
@@ -307,17 +395,17 @@ public final class ViewfinderView extends View {
|
|||||||
private void drawCorner(Canvas canvas, Rect frame) {
|
private void drawCorner(Canvas canvas, Rect frame) {
|
||||||
paint.setColor(cornerColor);
|
paint.setColor(cornerColor);
|
||||||
//左上
|
//左上
|
||||||
canvas.drawRect(frame.left, frame.top, frame.left + CORNER_RECT_WIDTH, frame.top + CORNER_RECT_HEIGHT, paint);
|
canvas.drawRect(frame.left, frame.top, frame.left + cornerRectWidth, frame.top + cornerRectHeight, paint);
|
||||||
canvas.drawRect(frame.left, frame.top, frame.left + CORNER_RECT_HEIGHT, frame.top + CORNER_RECT_WIDTH, paint);
|
canvas.drawRect(frame.left, frame.top, frame.left + cornerRectHeight, frame.top + cornerRectWidth, paint);
|
||||||
//右上
|
//右上
|
||||||
canvas.drawRect(frame.right - CORNER_RECT_WIDTH, frame.top, frame.right, frame.top + CORNER_RECT_HEIGHT, paint);
|
canvas.drawRect(frame.right - cornerRectWidth, frame.top, frame.right, frame.top + cornerRectHeight, paint);
|
||||||
canvas.drawRect(frame.right - CORNER_RECT_HEIGHT, frame.top, frame.right, frame.top + CORNER_RECT_WIDTH, paint);
|
canvas.drawRect(frame.right - cornerRectHeight, frame.top, frame.right, frame.top + cornerRectWidth, paint);
|
||||||
//左下
|
//左下
|
||||||
canvas.drawRect(frame.left, frame.bottom - CORNER_RECT_WIDTH, frame.left + CORNER_RECT_HEIGHT, frame.bottom, paint);
|
canvas.drawRect(frame.left, frame.bottom - cornerRectWidth, frame.left + cornerRectHeight, frame.bottom, paint);
|
||||||
canvas.drawRect(frame.left, frame.bottom - CORNER_RECT_HEIGHT, frame.left + CORNER_RECT_WIDTH, frame.bottom, paint);
|
canvas.drawRect(frame.left, frame.bottom - cornerRectHeight, frame.left + cornerRectWidth, frame.bottom, paint);
|
||||||
//右下
|
//右下
|
||||||
canvas.drawRect(frame.right - CORNER_RECT_WIDTH, frame.bottom - CORNER_RECT_HEIGHT, frame.right, frame.bottom, paint);
|
canvas.drawRect(frame.right - cornerRectWidth, frame.bottom - cornerRectHeight, frame.right, frame.bottom, paint);
|
||||||
canvas.drawRect(frame.right - CORNER_RECT_HEIGHT, frame.bottom - CORNER_RECT_WIDTH, frame.right, frame.bottom, paint);
|
canvas.drawRect(frame.right - cornerRectHeight, frame.bottom - cornerRectWidth, frame.right, frame.bottom, paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -349,7 +437,7 @@ public final class ViewfinderView extends View {
|
|||||||
//线性渐变
|
//线性渐变
|
||||||
LinearGradient linearGradient = new LinearGradient(
|
LinearGradient linearGradient = new LinearGradient(
|
||||||
frame.left, scannerStart,
|
frame.left, scannerStart,
|
||||||
frame.left, scannerStart + SCANNER_LINE_HEIGHT,
|
frame.left, scannerStart + scannerLineHeight,
|
||||||
shadeColor(laserColor),
|
shadeColor(laserColor),
|
||||||
laserColor,
|
laserColor,
|
||||||
Shader.TileMode.MIRROR);
|
Shader.TileMode.MIRROR);
|
||||||
@@ -357,9 +445,9 @@ public final class ViewfinderView extends View {
|
|||||||
paint.setShader(linearGradient);
|
paint.setShader(linearGradient);
|
||||||
if(scannerStart <= scannerEnd) {
|
if(scannerStart <= scannerEnd) {
|
||||||
//椭圆
|
//椭圆
|
||||||
RectF rectF = new RectF(frame.left + 2 * SCANNER_LINE_HEIGHT, scannerStart, frame.right - 2 * SCANNER_LINE_HEIGHT, scannerStart + SCANNER_LINE_HEIGHT);
|
RectF rectF = new RectF(frame.left + 2 * scannerLineHeight, scannerStart, frame.right - 2 * scannerLineHeight, scannerStart + scannerLineHeight);
|
||||||
canvas.drawOval(rectF, paint);
|
canvas.drawOval(rectF, paint);
|
||||||
scannerStart += SCANNER_LINE_MOVE_DISTANCE;
|
scannerStart += scannerLineMoveDistance;
|
||||||
} else {
|
} else {
|
||||||
scannerStart = frame.top;
|
scannerStart = frame.top;
|
||||||
}
|
}
|
||||||
@@ -395,7 +483,7 @@ public final class ViewfinderView extends View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(scannerStart<scannerEnd){
|
if(scannerStart<scannerEnd){
|
||||||
scannerStart += SCANNER_LINE_MOVE_DISTANCE;
|
scannerStart += scannerLineMoveDistance;
|
||||||
} else {
|
} else {
|
||||||
scannerStart = frame.top;
|
scannerStart = frame.top;
|
||||||
}
|
}
|
||||||
@@ -420,10 +508,10 @@ public final class ViewfinderView extends View {
|
|||||||
*/
|
*/
|
||||||
private void drawFrame(Canvas canvas, Rect frame) {
|
private void drawFrame(Canvas canvas, Rect frame) {
|
||||||
paint.setColor(frameColor);
|
paint.setColor(frameColor);
|
||||||
canvas.drawRect(frame.left, frame.top, frame.right + 1, frame.top + 2, paint);
|
canvas.drawRect(frame.left, frame.top, frame.right, frame.top + frameLineWidth, paint);
|
||||||
canvas.drawRect(frame.left, frame.top + 2, frame.left + 2, frame.bottom - 1, paint);
|
canvas.drawRect(frame.left, frame.top, frame.left + frameLineWidth, frame.bottom, paint);
|
||||||
canvas.drawRect(frame.right - 1, frame.top, frame.right + 1, frame.bottom - 1, paint);
|
canvas.drawRect(frame.right - frameLineWidth, frame.top, frame.right, frame.bottom, paint);
|
||||||
canvas.drawRect(frame.left, frame.bottom - 1, frame.right + 1, frame.bottom + 1, paint);
|
canvas.drawRect(frame.left, frame.bottom - frameLineWidth, frame.right, frame.bottom, paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -436,9 +524,9 @@ public final class ViewfinderView extends View {
|
|||||||
private void drawExterior(Canvas canvas, Rect frame, int width, int height) {
|
private void drawExterior(Canvas canvas, Rect frame, int width, int height) {
|
||||||
paint.setColor(maskColor);
|
paint.setColor(maskColor);
|
||||||
canvas.drawRect(0, 0, width, frame.top, paint);
|
canvas.drawRect(0, 0, width, frame.top, paint);
|
||||||
canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint);
|
canvas.drawRect(0, frame.top, frame.left, frame.bottom, paint);
|
||||||
canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint);
|
canvas.drawRect(frame.right, frame.top, width, frame.bottom, paint);
|
||||||
canvas.drawRect(0, frame.bottom + 1, width, height, paint);
|
canvas.drawRect(0, frame.bottom, width, height, paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -21,10 +21,11 @@ import android.content.Context;
|
|||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.hardware.Camera;
|
import android.hardware.Camera;
|
||||||
import android.media.FaceDetector;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.support.annotation.FloatRange;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
|
|
||||||
import com.google.zxing.PlanarYUVLuminanceSource;
|
import com.google.zxing.PlanarYUVLuminanceSource;
|
||||||
import com.king.zxing.camera.open.OpenCamera;
|
import com.king.zxing.camera.open.OpenCamera;
|
||||||
import com.king.zxing.camera.open.OpenCameraInterface;
|
import com.king.zxing.camera.open.OpenCameraInterface;
|
||||||
@@ -61,6 +62,10 @@ public final class CameraManager {
|
|||||||
private int requestedFramingRectHeight;
|
private int requestedFramingRectHeight;
|
||||||
private boolean isFullScreenScan;
|
private boolean isFullScreenScan;
|
||||||
|
|
||||||
|
private float framingRectRatio;
|
||||||
|
private int framingRectVerticalOffset;
|
||||||
|
private int framingRectHorizontalOffset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preview frames are delivered here, which we pass on to the registered handler. Make sure to
|
* Preview frames are delivered here, which we pass on to the registered handler. Make sure to
|
||||||
* clear the handler so it will only receive one message.
|
* clear the handler so it will only receive one message.
|
||||||
@@ -235,10 +240,10 @@ public final class CameraManager {
|
|||||||
if(isFullScreenScan){
|
if(isFullScreenScan){
|
||||||
framingRect = new Rect(0,0,width,height);
|
framingRect = new Rect(0,0,width,height);
|
||||||
}else{
|
}else{
|
||||||
int size = Math.min(width,height);
|
int size = (int)(Math.min(width,height) * framingRectRatio);
|
||||||
|
|
||||||
int leftOffset = (width - size) / 2;
|
int leftOffset = (width - size) / 2 + framingRectHorizontalOffset;
|
||||||
int topOffset = (height - size) / 2;
|
int topOffset = (height - size) / 2 + framingRectVerticalOffset;
|
||||||
framingRect = new Rect(leftOffset, topOffset, leftOffset + size, topOffset + size);
|
framingRect = new Rect(leftOffset, topOffset, leftOffset + size, topOffset + size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,14 +289,22 @@ public final class CameraManager {
|
|||||||
return framingRectInPreview;
|
return framingRectInPreview;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFullScreenScan() {
|
|
||||||
return isFullScreenScan;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFullScreenScan(boolean fullScreenScan) {
|
public void setFullScreenScan(boolean fullScreenScan) {
|
||||||
isFullScreenScan = fullScreenScan;
|
isFullScreenScan = fullScreenScan;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFramingRectRatio(@FloatRange(from = 0.0f ,to = 1.0f) float framingRectRatio) {
|
||||||
|
this.framingRectRatio = framingRectRatio;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFramingRectVerticalOffset(int framingRectVerticalOffset) {
|
||||||
|
this.framingRectVerticalOffset = framingRectVerticalOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFramingRectHorizontalOffset(int framingRectHorizontalOffset) {
|
||||||
|
this.framingRectHorizontalOffset = framingRectHorizontalOffset;
|
||||||
|
}
|
||||||
|
|
||||||
public Point getCameraResolution() {
|
public Point getCameraResolution() {
|
||||||
return configManager.getCameraResolution();
|
return configManager.getCameraResolution();
|
||||||
}
|
}
|
||||||
@@ -355,9 +368,9 @@ public final class CameraManager {
|
|||||||
if(isFullScreenScan){
|
if(isFullScreenScan){
|
||||||
return new PlanarYUVLuminanceSource(data,width,height,0,0,width,height,false);
|
return new PlanarYUVLuminanceSource(data,width,height,0,0,width,height,false);
|
||||||
}
|
}
|
||||||
int size = Math.min(width,height);
|
int size = (int)(Math.min(width,height) * framingRectRatio);
|
||||||
int left = (width-size)/2;
|
int left = (width-size)/2 + framingRectHorizontalOffset;
|
||||||
int top = (height-size)/2;
|
int top = (height-size)/2 + framingRectVerticalOffset;
|
||||||
// Go ahead and assume it's YUV rather than die.
|
// Go ahead and assume it's YUV rather than die.
|
||||||
return new PlanarYUVLuminanceSource(data, width, height, left, top,
|
return new PlanarYUVLuminanceSource(data, width, height, left, top,
|
||||||
size, size, false);
|
size, size, false);
|
||||||
|
|||||||
@@ -23,6 +23,14 @@
|
|||||||
<enum name="line" value="1"/>
|
<enum name="line" value="1"/>
|
||||||
<enum name="grid" value="2"/>
|
<enum name="grid" value="2"/>
|
||||||
</attr>
|
</attr>
|
||||||
|
<attr name="cornerRectWidth" format="dimension"/>
|
||||||
|
<attr name="cornerRectHeight" format="dimension"/>
|
||||||
|
<attr name="scannerLineMoveDistance" format="dimension"/>
|
||||||
|
<attr name="scannerLineHeight" format="dimension"/>
|
||||||
|
<attr name="frameLineWidth" format="dimension"/>
|
||||||
|
<attr name="scannerAnimationDelay" format="integer"/>
|
||||||
|
<attr name="frameRatio" format="float"/>
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//App
|
//App
|
||||||
def app_version = [:]
|
def app_version = [:]
|
||||||
app_version.versionCode = 11 //androidx 12
|
app_version.versionCode = 13 //androidx 14
|
||||||
app_version.versionName = "1.1.2"
|
app_version.versionName = "1.1.3"
|
||||||
ext.app_version = app_version
|
ext.app_version = app_version
|
||||||
|
|
||||||
//build version
|
//build version
|
||||||
|
|||||||
Reference in New Issue
Block a user