Skip to content

Commit

Permalink
修改README
Browse files Browse the repository at this point in the history
  • Loading branch information
maning0303 committed Aug 29, 2019
1 parent 79cb747 commit 8769694
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 36 deletions.
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# ZXingCode 二维码扫描
# ZXingCode 快速集成二维码扫描

## 快速集成二维码扫描,生成二维码,可配置相册,闪光灯,相机可以调整焦距放大缩小,自定义扫描线颜色,自定义背景颜色,自定义遮罩层(ZXing 3.3.3
## 快速集成二维码扫描,生成二维码,可配置相册,闪光灯,相机可以调整焦距放大缩小,自定义扫描线颜色,自定义背景颜色,自定义遮罩层(ZXing 3.4.0
[![](https://jitpack.io/v/maning0303/MNZXingCode.svg)](https://jitpack.io/#maning0303/MNZXingCode)

## 功能:
1:生成二维码(带Logo)
2:二维码扫描
3:相册中选取图片识别
4:开启闪光灯
4:闪光灯开关
5: 相机可以调整焦距放大缩小
6: 完全自定义遮罩层
6: 完全自定义遮罩层,高度自定义

## 截图:
![image](https://github.com/maning0303/ZXingCodeDemo/blob/master/screenshots/mn_zxing_screenshot_001.png)
Expand Down Expand Up @@ -74,27 +74,39 @@
.isShowBeep(true)
//显示相册功能
.isShowPhotoAlbum(true)
//显示闪光灯
.isShowLightController(true)
//打开扫描页面的动画
.setActivityOpenAnime(R.anim.activity_anmie_in)
//退出扫描页面动画
.setActivityExitAnime(R.anim.activity_anmie_out)
//自定义文案
.setScanHintText("请将二维码放入框中...")
.setScanHintText("请将二维码放入框中")
//自定义文案颜色
.setScanHintTextColor("#FFFF00")
//自定义文案大小(单位sp)
.setScanHintTextSize(16)
//扫描线的颜色
.setScanColor("#FFFF00")
//是否显示缩放控制器
.isShowZoomController(true)
//显示缩放控制器位置
.setZoomControllerLocation(MNScanConfig.ZoomControllerLocation.Bottom)
//扫描线样式
.setLaserStyle(MNScanConfig.LaserStyle.Grid)
//背景颜色
.setBgColor("#33FF0000")
//网格扫描线的列数
.setGridScanLineColumn(30)
//网格高度
.setGridScanLineHeight(150)
//自定义遮罩
.setCustomShadeViewLayoutID(R.layout.layout_custom_view, new MNCustomViewBindCallback() {
@Override
public void onBindView(View customView) {
//TODO:通过findviewById 获取View
}
})
//背景颜色
.setBgColor("#33FF0000")
.builder();
MNScanManager.startScan(this, scanConfig, new MNScanCallback() {
@Override
Expand Down Expand Up @@ -149,8 +161,11 @@
```

## 版本记录:
v2.1.1:(未发布)
1.网格扫描线支持设置列数和高度
v2.1.1(未发布):
1.支持网格扫描线设置列数和高度
2.支持隐藏默认闪光灯开关
3.支持修改提示文案颜色和大小
4.UI优化显示

v2.1.0:
1.支持自定义遮罩层
Expand Down
20 changes: 12 additions & 8 deletions app/src/main/java/com/maning/zxingcodedemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,24 @@ public void onActivityResult(int resultCode, Intent data) {
}

public void scanCode(View view) {
requestCameraPerm();
//需要判断有没有权限
MNScanConfig scanConfig = new MNScanConfig.Builder()
//设置完成震动
.isShowVibrate(false)
//扫描完成声音
.isShowBeep(true)
//显示相册功能
.isShowPhotoAlbum(true)
//显示闪光灯
.isShowLightController(true)
//打开扫描页面的动画
.setActivityOpenAnime(R.anim.activity_anmie_in)
//退出扫描页面动画
.setActivityExitAnime(R.anim.activity_anmie_out)
//自定义文案
.setScanHintText("请将二维码放入框中...")
.setScanHintText("请将二维码放入框中")
.setScanHintTextColor("#FFFF00")
.setScanHintTextSize(16)
//扫描线的颜色
.setScanColor("#FFFF00")
//是否显示缩放控制器
Expand All @@ -88,6 +92,12 @@ public void scanCode(View view) {
.setZoomControllerLocation(MNScanConfig.ZoomControllerLocation.Bottom)
//扫描线样式
.setLaserStyle(MNScanConfig.LaserStyle.Grid)
//背景颜色
.setBgColor("#33FF0000")
//网格扫描线的列数
.setGridScanLineColumn(30)
//网格高度
.setGridScanLineHeight(150)
//自定义遮罩
.setCustomShadeViewLayoutID(R.layout.layout_custom_view, new MNCustomViewBindCallback() {
@Override
Expand Down Expand Up @@ -144,12 +154,6 @@ public void onClick(View v) {
});
}
})
//背景颜色
.setBgColor("#33FF0000")
//网格扫描线的列数
.setGridScanLineColumn(30)
//网格高度
.setGridScanLineHeight(150)
.builder();
MNScanManager.startScan(this, scanConfig, new MNScanCallback() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
Expand Down Expand Up @@ -307,22 +306,17 @@ private void initIntent() {
zoomControllerFlag = mnScanConfig.isShowZoomController();
zoomControllerLocation = mnScanConfig.getZoomControllerLocation();

viewfinderView.setHintText(mnScanConfig.getScanHintText());
//扫描文字配置
viewfinderView.setHintText(mnScanConfig.getScanHintText(), mnScanConfig.getScanHintTextColor(), mnScanConfig.getScanHintTextSize());

//扫描线相关配置
if (!TextUtils.isEmpty(scanColor)) {
viewfinderView.setLaserColor(Color.parseColor(scanColor));
}
viewfinderView.setLaserStyle(mnScanConfig.getLaserStyle());
if (!TextUtils.isEmpty(maskColor)) {
viewfinderView.setMaskColor(Color.parseColor(maskColor));
}
if (!mnScanConfig.isShowPhotoAlbum()) {
btn_photo.setVisibility(View.GONE);
}
if (exitAnime == 0) {
exitAnime = R.anim.mn_scan_activity_bottom_out;
}

//网格扫描线相关配置
viewfinderView.setGridScannerColumn(mnScanConfig.getGridScanLineColumn());
viewfinderView.setGridScannerHeight(mnScanConfig.getGridScanLineHeight());

Expand All @@ -338,6 +332,23 @@ private void initIntent() {
} else {
rl_default_menu.setVisibility(View.VISIBLE);
}

//闪光灯配置
boolean showLightController = mnScanConfig.isShowLightController();
if (showLightController) {
btn_scan_light.setVisibility(View.VISIBLE);
} else {
btn_scan_light.setVisibility(View.GONE);
}

//其他配置
if (!mnScanConfig.isShowPhotoAlbum()) {
btn_photo.setVisibility(View.GONE);
}
if (exitAnime == 0) {
exitAnime = R.anim.mn_scan_activity_bottom_out;
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import android.graphics.Shader;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

import com.google.zxing.client.android.camera.CameraManager;
Expand All @@ -54,7 +53,9 @@ public final class ViewfinderView extends View {
private int laserColor;

private Rect frame;
private static String hintMsg;
private String hintMsg;
private String hintTextColor = "#FFFFFF";
private int hintTextSize = 14;
private int linePosition = 0;
private int margin;
private int laserLineW;
Expand Down Expand Up @@ -82,7 +83,7 @@ public ViewfinderView(Context context, AttributeSet attrs) {
hintMsg = resources.getString(R.string.mn_scan_hint_text);
//文字
paintText.setColor(Color.WHITE);
paintText.setTextSize(CommonUtils.dip2px(context, 14));
paintText.setTextSize(CommonUtils.sp2px(context, hintTextSize));
paintText.setTextAlign(Paint.Align.CENTER);
//四角
paintLine.setColor(laserColor);
Expand Down Expand Up @@ -156,14 +157,22 @@ public void setGridScannerHeight(int gridHeight) {

/**
* 设置文案
*
* @param msg
*/
public void setHintText(String msg) {
hintMsg = msg;
if (TextUtils.isEmpty(hintMsg)) {
hintMsg = "";
public void setHintText(String hintMsg, String hintTextColor, int hintTextSize) {
//文字
if (!TextUtils.isEmpty(hintMsg)) {
this.hintMsg = hintMsg;
}
//文字颜色
if (!TextUtils.isEmpty(hintTextColor)) {
this.hintTextColor = hintTextColor;
}
//文字大小
if (hintTextSize > 0) {
this.hintTextSize = hintTextSize;
}
paintText.setColor(Color.parseColor(this.hintTextColor));
paintText.setTextSize(CommonUtils.sp2px(context, this.hintTextSize));
}

public void setCameraManager(CameraManager cameraManager) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public enum LaserStyle {
private LaserStyle laserStyle;
//扫描提示文案
private String scanHintText;
//扫描提示文案颜色
private String scanHintTextColor;
//扫描提示文案字体大小
private int scanHintTextSize;
//开启Activity动画
private int activityOpenAnime;
//关闭Activity动画
Expand All @@ -58,6 +62,8 @@ public enum LaserStyle {
private int gridScanLineColumn;
//网格扫描线的高度
private int gridScanLineHeight;
//显示闪光灯
private boolean showLightController = true;

private MNScanConfig() {

Expand All @@ -79,6 +85,9 @@ private MNScanConfig(Builder builder) {
bgColor = builder.bgColor;
gridScanLineColumn = builder.gridScanLineColumn;
gridScanLineHeight = builder.gridScanLineHeight;
showLightController = builder.showLightController;
scanHintTextColor = builder.scanHintTextColor;
scanHintTextSize = builder.scanHintTextSize;
}

public LaserStyle getLaserStyle() {
Expand Down Expand Up @@ -193,6 +202,30 @@ public void setGridScanLineHeight(int gridScanLineHeight) {
this.gridScanLineHeight = gridScanLineHeight;
}

public boolean isShowLightController() {
return showLightController;
}

public void setShowLightController(boolean showLightController) {
this.showLightController = showLightController;
}

public String getScanHintTextColor() {
return scanHintTextColor;
}

public void setScanHintTextColor(String scanHintTextColor) {
this.scanHintTextColor = scanHintTextColor;
}

public int getScanHintTextSize() {
return scanHintTextSize;
}

public void setScanHintTextSize(int scanHintTextSize) {
this.scanHintTextSize = scanHintTextSize;
}

public static class Builder {
private boolean showPhotoAlbum = true;
private boolean showBeep = true;
Expand All @@ -210,6 +243,11 @@ public static class Builder {
private int gridScanLineColumn;
//网格扫描线的高度
private int gridScanLineHeight;
private boolean showLightController = true;
//扫描提示文案颜色
private String scanHintTextColor;
//扫描提示文案字体大小
private int scanHintTextSize;

public MNScanConfig builder() {
return new MNScanConfig(this);
Expand Down Expand Up @@ -286,6 +324,21 @@ public Builder setGridScanLineHeight(int gridScanLineHeight) {
return this;
}

public Builder isShowLightController(boolean showLightController) {
this.showLightController = showLightController;
return this;
}

public Builder setScanHintTextColor(String scanHintTextColor) {
this.scanHintTextColor = scanHintTextColor;
return this;
}

public Builder setScanHintTextSize(int scanHintTextSize) {
this.scanHintTextSize = scanHintTextSize;
return this;
}

}

}
Binary file modified screenshots/mn_zxing_screenshot_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/mn_zxing_screenshot_003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8769694

Please sign in to comment.