diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser
index 71ac3c4..d7a1447 100644
Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index 2715a34..816e1f7 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -1,5 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -25,5 +49,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml
new file mode 100644
index 0000000..8095114
--- /dev/null
+++ b/.idea/dbnavigator.xml
@@ -0,0 +1,456 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index c0f68ed..99202cc 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -25,7 +25,7 @@
-
+
diff --git a/.travis.yml b/.travis.yml
index 5af2c1d..655f90c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,12 +1,12 @@
language: android
jdk: oraclejdk8
before_install:
-- yes | sdkmanager "platforms;android-27"
+- yes | sdkmanager "platforms;android-28"
env:
global:
- - ANDROID_API_LEVEL=27
- - ANDROID_BUILD_TOOLS_VERSION=27.0.3
+ - ANDROID_API_LEVEL=28
+ - ANDROID_BUILD_TOOLS_VERSION=28.0.3
- TRAVIS_SECURE_ENV_VARS=true
android:
diff --git a/README.md b/README.md
index 794df0a..65f38c1 100644
--- a/README.md
+++ b/README.md
@@ -29,9 +29,13 @@ ZXingLite for Android 是ZXing的精简版,基于ZXing库优化扫码和生成
| labelTextColor | color |#FFC0C0C0| 提示文本字体颜色 |
| labelTextSize | dimension |14sp| 提示文本字体大小 |
| labelTextPadding | dimension |24dp| 提示文本距离扫描区的间距 |
+| labelTextLocation | enum |bottom| 提示文本显示位置 |
| showResultPoint | boolean | false | 是否显示合适的扫码结果点 |
-| frameWidth | dimension | | 扫码框宽度,需与frameHeight同时使用才有效 |
-| frameHeight | dimension | | 扫码框高度,需与frameWidth同时使用才有效 |
+| frameWidth | dimension | | 扫码框宽度 |
+| frameHeight | dimension | | 扫码框高度 |
+| laserStyle | enum | line | 扫描激光的样式 |
+| gridColumn | integer | 20 | 网格扫描激光列数 |
+| gridHeight | integer | 40dp | 网格扫描激光高度,为0dp时,表示动态铺满 |
## 引入
@@ -41,17 +45,17 @@ ZXingLite for Android 是ZXing的精简版,基于ZXing库优化扫码和生成
com.king.zxing
zxing-lite
- 1.0.6
+ 1.0.7
pom
```
### Gradle:
```gradle
-implementation 'com.king.zxing:zxing-lite:1.0.6'
+implementation 'com.king.zxing:zxing-lite:1.0.7'
```
### Lvy:
```lvy
-
+
```
@@ -67,7 +71,7 @@ allprojects {
## 引入的库:
```gradle
-compileOnly 'com.android.support:appcompat-v7:27.1.1'
+compileOnly 'com.android.support:appcompat-v7:28.0.0'
api 'com.google.zxing:core:3.3.3'
```
@@ -101,6 +105,10 @@ api 'com.google.zxing:core:3.3.3'
更多使用详情,请查看[app](app)中的源码使用示例
## 版本记录
+#### v1.0.7:2019-4-9
+* 新增网格样式的扫描激光(类似支付宝扫码样式)
+* 升级Gradle至v4.6
+
#### v1.0.6:2019-1-16
* 支持连续扫码
* 支持横屏扫码(主要为了支持Pad)
diff --git a/app/release/app-release.apk b/app/release/app-release.apk
index fb2cdaf..ece8e6a 100644
Binary files a/app/release/app-release.apk and b/app/release/app-release.apk differ
diff --git a/app/release/output.json b/app/release/output.json
index 7d6c441..dced801 100644
--- a/app/release/output.json
+++ b/app/release/output.json
@@ -1 +1 @@
-[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":7,"versionName":"1.0.6","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
\ No newline at end of file
+[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":8,"versionName":"1.0.7","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
\ No newline at end of file
diff --git a/app/src/main/java/com/king/zxing/app/CodeActivity.java b/app/src/main/java/com/king/zxing/app/CodeActivity.java
index 8e3c01a..5ab430d 100644
--- a/app/src/main/java/com/king/zxing/app/CodeActivity.java
+++ b/app/src/main/java/com/king/zxing/app/CodeActivity.java
@@ -57,7 +57,7 @@ public class CodeActivity extends AppCompatActivity {
*/
private void createQRCode(String content){
//生成二维码最好放子线程生成防止阻塞UI,这里只是演示
- Bitmap logo = BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher);
+ Bitmap logo = BitmapFactory.decodeResource(getResources(),R.drawable.logo);
Bitmap bitmap = CodeUtils.createQRCode(content,600,logo);
//显示二维码
ivCode.setImageBitmap(bitmap);
diff --git a/app/src/main/res/drawable-xxhdpi/logo.png b/app/src/main/res/drawable-xxhdpi/logo.png
new file mode 100644
index 0000000..4dcd5c8
Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/logo.png differ
diff --git a/app/src/main/res/layout/custom_capture_activity.xml b/app/src/main/res/layout/custom_capture_activity.xml
index 16b8228..5737de1 100644
--- a/app/src/main/res/layout/custom_capture_activity.xml
+++ b/app/src/main/res/layout/custom_capture_activity.xml
@@ -19,7 +19,8 @@
app:frameColor="@color/colorPrimary"
app:cornerColor="@color/colorPrimary"
app:resultPointColor="@color/colorAccent"
- app:labelTextLocation="bottom"/>
+ app:labelTextLocation="bottom"
+ app:laserStyle="grid"/>
possibleResultPoints;
private List lastPossibleResultPoints;
+ public enum LaserStyle{
+ NONE(0),LINE(1),GRID(2);
+ private int mValue;
+ LaserStyle(int value){
+ mValue = value;
+ }
+
+ private static LaserStyle getFromInt(int value){
+
+ for(LaserStyle style : LaserStyle.values()){
+ if(style.mValue == value){
+ return style;
+ }
+ }
+
+ return LaserStyle.LINE;
+ }
+ }
+
public enum TextLocation {
TOP(0),BOTTOM(1);
@@ -122,10 +148,21 @@ public final class ViewfinderView extends View {
}
- // This constructor is used when the class is built from an XML resource.
- public ViewfinderView(Context context, AttributeSet attrs) {
- super(context, attrs);
+ public ViewfinderView(Context context) {
+ this(context,null);
+ }
+ public ViewfinderView(Context context, @Nullable AttributeSet attrs) {
+ this(context, attrs,0);
+ }
+
+ public ViewfinderView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ init(context,attrs);
+ }
+
+
+ private void init(Context context, AttributeSet attrs) {
//初始化自定义属性信息
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.ViewfinderView);
maskColor = array.getColor(R.styleable.ViewfinderView_maskColor, ContextCompat.getColor(context,R.color.viewfinder_mask));
@@ -145,26 +182,37 @@ public final class ViewfinderView extends View {
frameWidth = array.getDimensionPixelSize(R.styleable.ViewfinderView_frameWidth,0);
frameHeight = array.getDimensionPixelSize(R.styleable.ViewfinderView_frameHeight,0);
+ laserStyle = LaserStyle.getFromInt(array.getInt(R.styleable.ViewfinderView_laserStyle,LaserStyle.LINE.mValue));
+ 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()));
+
array.recycle();
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
-// scannerAlpha = 0;
+
possibleResultPoints = new ArrayList<>(5);
lastPossibleResultPoints = null;
screenWidth = getDisplayMetrics().widthPixels;
screenHeight = getDisplayMetrics().heightPixels;
+
+ int size = (int)(Math.min(screenWidth,screenHeight) * 0.625f);
+
+ if(frameWidth<=0 || frameWidth > screenWidth){
+ frameWidth = size;
+ }
+
+ if(frameHeight<=0 || frameHeight > screenHeight){
+ frameHeight = size;
+ }
+
}
private DisplayMetrics getDisplayMetrics(){
return getResources().getDisplayMetrics();
}
- public void setCameraManager(CameraManager cameraManager) {
- this.cameraManager = cameraManager;
- }
-
public void setLabelText(String labelText) {
this.labelText = labelText;
}
@@ -181,24 +229,19 @@ public final class ViewfinderView extends View {
this.labelTextSize = textSize;
}
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ //扫码框默认居中,支持利用内距偏移扫码框
+ int leftOffset = (screenWidth - frameWidth) / 2 + getPaddingLeft() - getPaddingRight();
+ int topOffset = (screenHeight - frameHeight) / 2 + getPaddingTop() - getPaddingBottom();
+ frame = new Rect(leftOffset, topOffset, leftOffset + frameWidth, topOffset + frameHeight);
+ }
+
@SuppressLint("DrawAllocation")
@Override
public void onDraw(Canvas canvas) {
- Rect frame;
- if(frameWidth > 0 && frameWidth < screenWidth && frameHeight > 0 && frameHeight < screenHeight){
- //扫码框默认居中,当自定义扫码框宽高时,支持利用内距偏移
- int leftOffset = (screenWidth - frameWidth) / 2 + getPaddingLeft() - getPaddingRight();
- int topOffset = (screenHeight - frameHeight) / 2 + getPaddingTop() - getPaddingBottom();
- frame = new Rect(leftOffset, topOffset, leftOffset + frameWidth, topOffset + frameHeight);
- }else{
- if (cameraManager == null) {
- return; // not ready yet, early draw before done configuring
- }
- frame = cameraManager.getFramingRect();
- }
-
-
if (frame == null) {
return;
}
@@ -221,15 +264,11 @@ public final class ViewfinderView extends View {
} else {
// Draw a red "laser scanner" line through the middle to show decoding is active
-// paint.setColor(laserColor);
-// paint.setAlpha(SCANNER_ALPHA[scannerAlpha]);
-// scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length;
+ drawLaserScanner(canvas,frame);
// Draw a two pixel solid black border inside the framing rect
drawFrame(canvas, frame);
// 绘制边角
drawCorner(canvas, frame);
- // Draw a red "laser scanner" line through the middle to show decoding is active
- drawLaserScanner(canvas,frame);
//绘制提示信息
drawTextInfo(canvas, frame);
//绘制扫码结果点
@@ -244,7 +283,11 @@ public final class ViewfinderView extends View {
}
}
- //绘制文本
+ /**
+ * 绘制文本
+ * @param canvas
+ * @param frame
+ */
private void drawTextInfo(Canvas canvas, Rect frame) {
if(!TextUtils.isEmpty(labelText)){
textPaint.setColor(labelTextColor);
@@ -262,7 +305,11 @@ public final class ViewfinderView extends View {
}
- //绘制边角
+ /**
+ * 绘制边角
+ * @param canvas
+ * @param frame
+ */
private void drawCorner(Canvas canvas, Rect frame) {
paint.setColor(cornerColor);
//左上
@@ -279,9 +326,32 @@ public final class ViewfinderView extends View {
canvas.drawRect(frame.right - CORNER_RECT_HEIGHT, frame.bottom - CORNER_RECT_WIDTH, frame.right, frame.bottom, paint);
}
- //绘制扫描线
+ /**
+ * 绘制激光扫描线
+ * @param canvas
+ * @param frame
+ */
private void drawLaserScanner(Canvas canvas, Rect frame) {
- paint.setColor(laserColor);
+ if(laserStyle!=null){
+ paint.setColor(laserColor);
+ switch (laserStyle){
+ case LINE://线
+ drawLineScanner(canvas,frame);
+ break;
+ case GRID://网格
+ drawGridScanner(canvas,frame);
+ break;
+ }
+ paint.setShader(null);
+ }
+ }
+
+ /**
+ * 绘制线性式扫描
+ * @param canvas
+ * @param frame
+ */
+ private void drawLineScanner(Canvas canvas,Rect frame){
//线性渐变
LinearGradient linearGradient = new LinearGradient(
frame.left, scannerStart,
@@ -299,17 +369,61 @@ public final class ViewfinderView extends View {
} else {
scannerStart = frame.top;
}
- paint.setShader(null);
}
- //处理颜色模糊
+ /**
+ * 绘制网格式扫描
+ * @param canvas
+ * @param frame
+ */
+ private void drawGridScanner(Canvas canvas,Rect frame){
+ int stroke = 2;
+ paint.setStrokeWidth(stroke);
+ //计算Y轴开始位置
+ int startY = gridHeight > 0 && scannerStart - frame.top > gridHeight ? scannerStart - gridHeight : frame.top;
+
+ LinearGradient linearGradient = new LinearGradient(frame.left + frame.width()/2, startY, frame.left + frame.width()/2, scannerStart, new int[]{shadeColor(laserColor), laserColor}, new float[]{0,1f}, LinearGradient.TileMode.CLAMP);
+ //给画笔设置着色器
+ paint.setShader(linearGradient);
+
+ float wUnit = frame.width() * 1.0f/ gridColumn;
+ float hUnit = wUnit;
+ //遍历绘制网格纵线
+ for (int i = 1; i < gridColumn; i++) {
+ canvas.drawLine(frame.left + i * wUnit, startY,frame.left + i * wUnit, scannerStart,paint);
+ }
+
+ int height = gridHeight > 0 && scannerStart - frame.top > gridHeight ? gridHeight : scannerStart - frame.top;
+
+ //遍历绘制网格横线
+ for (int i = 0; i <= height/hUnit; i++) {
+ canvas.drawLine(frame.left, scannerStart - i * hUnit,frame.right, scannerStart - i * hUnit,paint);
+ }
+
+ if(scannerStart
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/versions.gradle b/versions.gradle
index 9ae88d2..89f045e 100644
--- a/versions.gradle
+++ b/versions.gradle
@@ -1,15 +1,15 @@
//App
def app_version = [:]
-app_version.versionCode = 7
-app_version.versionName = "1.0.6"
+app_version.versionCode = 8
+app_version.versionName = "1.0.7"
ext.app_version = app_version
//build version
def build_versions = [:]
build_versions.minSdk = 16
-build_versions.targetSdk = 27
-build_versions.compileSdk = 27
-build_versions.buildTools = "27.0.3"
+build_versions.targetSdk = 28
+build_versions.compileSdk = 28
+build_versions.buildTools = "28.0.3"
ext.build_versions = build_versions
ext.deps = [:]
@@ -17,8 +17,8 @@ ext.deps = [:]
// App dependencies
def versions = [:]
//support
-versions.supportLibrary = "27.1.1"
-versions.constraintLayout = "1.1.2"
+versions.supportLibrary = "28.0.0"
+versions.constraintLayout = "1.1.3"
//test
versions.junit = "4.12"