Skip to content

Commit 9676620

Browse files
committed
加入修改mask的api,加入亮度分析回调
1 parent 2276d12 commit 9676620

11 files changed

Lines changed: 189 additions & 12 deletions

File tree

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ project.ext {
2222

2323
buildscript {
2424
repositories {
25+
maven { url 'https://maven.aliyun.com/repository/jcenter' }
2526
jcenter()
2627
google()
2728
}
@@ -37,6 +38,7 @@ buildscript {
3738

3839
allprojects {
3940
repositories {
41+
maven { url 'https://maven.aliyun.com/repository/jcenter' }
4042
jcenter()
4143
google()
4244
}

czxing/src/main/java/me/devilsen/czxing/ScanActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ private void initData() {
8686
}
8787
mScanView.setScanMode(option.getScanMode());
8888
mScanView.setBarcodeFormat(option.getBarcodeFormat());
89+
mScanView.onFlashLightClick();
8990

9091
ScanBoxView scanBox = mScanView.getScanBox();
92+
scanBox.setMaskColor(option.getMaskColor());
9193
scanBox.setCornerColor(option.getCornerColor());
9294
scanBox.setBorderColor(option.getBorderColor());
9395
scanBox.setBorderSize(option.getBorderSize());
@@ -96,8 +98,8 @@ private void initData() {
9698
scanBox.setFlashLightOffDrawable(option.getFlashLightOffDrawable());
9799
scanBox.setFlashLightOnText(option.getFlashLightOnText());
98100
scanBox.setFlashLightOffText(option.getFlashLightOffText());
99-
if (option.isDropFlashLight()){
100-
scanBox.dropFlashLightIcon();
101+
if (option.isDropFlashLight()) {
102+
scanBox.invisibleFlashLightIcon();
101103
}
102104
scanBox.setScanNoticeText(option.getScanNoticeText());
103105

czxing/src/main/java/me/devilsen/czxing/ScannerManager.java

Lines changed: 125 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import me.devilsen.czxing.view.ScanActivityDelegate;
1414

1515
/**
16-
* desc :
16+
* desc : 扫码API管理
1717
* date : 2019/07/31
1818
*
1919
* @author : dongsen
@@ -28,101 +28,214 @@ public class ScannerManager {
2828
scanOption = new ScanOption();
2929
}
3030

31+
/**
32+
* 扫码框角颜色
33+
*
34+
* @param cornerColor 色值
35+
*/
3136
public ScannerManager setCornerColor(int cornerColor) {
3237
scanOption.cornerColor = cornerColor;
3338
return this;
3439
}
3540

41+
/**
42+
* 设置扫码框颜色
43+
*
44+
* @param borderColor 色值
45+
*/
3646
public ScannerManager setBorderColor(int borderColor) {
3747
scanOption.borderColor = borderColor;
3848
return this;
3949
}
4050

51+
/**
52+
* 设置扫码框四周颜色
53+
*
54+
* @param maskColor 色值
55+
*/
56+
public ScannerManager setMaskColor(int maskColor) {
57+
scanOption.maskColor = maskColor;
58+
return this;
59+
}
60+
61+
/**
62+
* 设置边框长度(扫码框大小)
63+
*
64+
* @param borderSize px
65+
*/
4166
public ScannerManager setBorderSize(int borderSize) {
4267
scanOption.borderSize = borderSize;
4368
return this;
4469
}
4570

71+
/**
72+
* 扫描模式,提供了三种扫码模式
73+
* ┏--------------┓
74+
* ┃ ┃
75+
* ┃ 2 ┃
76+
* ┃ ┏----┓ ┃
77+
* ┃ ┃ 1 ┃ ┃
78+
* ┃ ┗----┛ ┃
79+
* ┃ ┃
80+
* ┃ ┃
81+
* ┃ ┃
82+
* ┃ ┃
83+
* ┗--------------┛
84+
* <p>
85+
* 0:混合扫描模式(默认),扫描4次扫码框里的内容,扫描1次以屏幕宽为边长的内容
86+
* 1:只扫描扫码框里的内容
87+
* 2:扫描以屏幕宽为边长的内容
88+
*
89+
* @param scanMode 0 / 1 / 2
90+
*/
4691
public ScannerManager setScanMode(int scanMode) {
4792
scanOption.scanMode = scanMode;
4893
return this;
4994
}
5095

96+
/**
97+
* 设置扫码界面标题
98+
*
99+
* @param title 标题内容
100+
*/
51101
public ScannerManager setTitle(String title) {
52102
scanOption.title = title;
53103
return this;
54104
}
55105

106+
/**
107+
* 显示从图库选取图片按钮
108+
*
109+
* @param showAlbum true:显示 false:隐藏
110+
*/
56111
public ScannerManager showAlbum(boolean showAlbum) {
57112
scanOption.showAlbum = showAlbum;
58113
return this;
59114
}
60115

116+
/**
117+
* 连续扫码,当扫描出结果后不关闭扫码界面
118+
*/
61119
public ScannerManager continuousScan() {
62120
scanOption.continuousScan = true;
63121
return this;
64122
}
65123

124+
/**
125+
* 设置闪光灯打开时的样式
126+
*
127+
* @param flashLightOnDrawable drawable
128+
*/
66129
public ScannerManager setFlashLightOnDrawable(int flashLightOnDrawable) {
67130
scanOption.flashLightOnDrawable = flashLightOnDrawable;
68131
return this;
69132
}
70133

134+
/**
135+
* 设置闪光灯关闭时的样式
136+
*
137+
* @param flashLightOffDrawable drawable
138+
*/
71139
public ScannerManager setFlashLightOffDrawable(int flashLightOffDrawable) {
72140
scanOption.flashLightOffDrawable = flashLightOffDrawable;
73141
return this;
74142
}
75143

144+
/**
145+
* 设置闪光灯打开时的提示文字
146+
*
147+
* @param lightOnText 提示文字
148+
*/
76149
public ScannerManager setFlashLightOnText(String lightOnText) {
77150
scanOption.flashLightOnText = lightOnText;
78151
return this;
79152
}
80153

154+
/**
155+
* 设置闪光灯关闭时的提示文字
156+
*
157+
* @param lightOffText 提示文字
158+
*/
81159
public ScannerManager setFlashLightOffText(String lightOffText) {
82160
scanOption.flashLightOffText = lightOffText;
83161
return this;
84162
}
85163

164+
/**
165+
* 设置扫码框下方的提示文字
166+
*
167+
* @param scanNoticeText 提示文字
168+
*/
86169
public ScannerManager setScanNoticeText(String scanNoticeText) {
87170
scanOption.scanNoticeText = scanNoticeText;
88171
return this;
89172
}
90173

174+
/**
175+
* 隐藏闪光灯图标及文字
176+
*/
91177
public ScannerManager setFlashLightInvisible() {
92178
scanOption.dropFlashLight = true;
93179
return this;
94180
}
95181

182+
/**
183+
* 设置扫码线颜色,扫描线最好使用一个渐变颜色
184+
* 如:
185+
* --- === #### === ---
186+
* 我们需要一条线,将它分成5份,拿到1/5、2/5、3/5处的3个颜色就可以画出一条两边细中间粗的扫描线
187+
*
188+
* @param scanLineColors 颜色合集
189+
*/
96190
public ScannerManager setScanLineColors(List<Integer> scanLineColors) {
97191
scanOption.scanLineColors = scanLineColors;
98192
return this;
99193
}
100194

195+
/**
196+
* 设置扫码格式{@link BarcodeFormat}
197+
*
198+
* @param barcodeFormats 扫码格式
199+
*/
101200
public ScannerManager setBarcodeFormat(BarcodeFormat... barcodeFormats) {
102201
scanOption.barcodeFormats = Arrays.asList(barcodeFormats);
103202
return this;
104203
}
105204

205+
/**
206+
* 设置扫码代理,获取扫码结果
207+
*
208+
* @param delegate 扫码代理
209+
*/
106210
public ScannerManager setOnScanResultDelegate(ScanActivityDelegate.OnScanDelegate delegate) {
107211
ScanActivityDelegate.getInstance().setScanResultDelegate(delegate);
108212
return this;
109213
}
110214

215+
/**
216+
* 设置点击图库代理,可以通过自定义的图片选择框架,打开图库
217+
*
218+
* @param onClickAlbumDelegate 点击图库代理
219+
*/
220+
public ScannerManager setOnClickAlbumDelegate(ScanActivityDelegate.OnClickAlbumDelegate onClickAlbumDelegate) {
221+
ScanActivityDelegate.getInstance().setOnClickAlbumDelegate(onClickAlbumDelegate);
222+
return this;
223+
}
224+
225+
/**
226+
* 开启界面
227+
*/
111228
public void start() {
112229
Intent intent = new Intent(context, ScanActivity.class);
113230
intent.putExtra("option", scanOption);
114231
context.startActivity(intent);
115232
}
116233

117-
public ScannerManager setOnClickAlbumDelegate(ScanActivityDelegate.OnClickAlbumDelegate onClickAlbumDelegate) {
118-
ScanActivityDelegate.getInstance().setOnClickAlbumDelegate(onClickAlbumDelegate);
119-
return this;
120-
}
121-
122234
public static class ScanOption implements Parcelable {
123235

124236
private int cornerColor;
125237
private int borderColor;
238+
private int maskColor;
126239
private int borderSize;
127240
private int scanMode;
128241
private String title;
@@ -147,6 +260,10 @@ public int getBorderColor() {
147260
return borderColor;
148261
}
149262

263+
public int getMaskColor() {
264+
return maskColor;
265+
}
266+
150267
public int getBorderSize() {
151268
return borderSize;
152269
}
@@ -208,6 +325,7 @@ public int describeContents() {
208325
public void writeToParcel(Parcel dest, int flags) {
209326
dest.writeInt(this.cornerColor);
210327
dest.writeInt(this.borderColor);
328+
dest.writeInt(this.maskColor);
211329
dest.writeInt(this.borderSize);
212330
dest.writeInt(this.scanMode);
213331
dest.writeString(this.title);
@@ -229,6 +347,7 @@ public ScanOption() {
229347
protected ScanOption(Parcel in) {
230348
this.cornerColor = in.readInt();
231349
this.borderColor = in.readInt();
350+
this.maskColor = in.readInt();
232351
this.borderSize = in.readInt();
233352
this.scanMode = in.readInt();
234353
this.title = in.readString();

czxing/src/main/java/me/devilsen/czxing/view/ScanBoxView.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,15 @@ public void setBoxTopOffset(int offset) {
473473
mTopOffset = offset;
474474
}
475475

476+
/**
477+
* 设置扫码框四周的颜色
478+
*
479+
* @param color 透明颜色
480+
*/
481+
public void setMaskColor(int color) {
482+
mMaskColor = color;
483+
}
484+
476485
/**
477486
* 设定扫描线的颜色
478487
*
@@ -507,7 +516,7 @@ public void setFlashLightOffDrawable(int lightOffDrawable) {
507516
/**
508517
* 不使用手电筒图标
509518
*/
510-
public void dropFlashLightIcon() {
519+
public void invisibleFlashLightIcon() {
511520
mDropFlashLight = true;
512521
}
513522

czxing/src/main/java/me/devilsen/czxing/view/ScanListener.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,13 @@ public interface ScanListener {
2020
* 处理打开相机出错
2121
*/
2222
void onOpenCameraError();
23+
24+
/**
25+
* 亮度分析回调
26+
*/
27+
interface AnalysisBrightnessListener {
28+
29+
void onAnalysisBrightness(boolean isDark);
30+
31+
}
2332
}

czxing/src/main/java/me/devilsen/czxing/view/ScanView.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class ScanView extends BarCoderView implements ScanBoxView.ScanBoxClickLi
3636
private boolean isDark;
3737
private int showCounter;
3838
private BarcodeReader reader;
39+
private ScanListener.AnalysisBrightnessListener brightnessListener;
3940

4041
public ScanView(Context context) {
4142
this(context, null);
@@ -61,6 +62,13 @@ public void onPreviewFrame(byte[] data, int left, int top, int width, int height
6162
// SaveImageUtil.saveData(data, left, top, width, height, rowWidth);
6263
}
6364

65+
/**
66+
* 设置亮度分析会调
67+
*/
68+
public void setAnalysisBrightnessListener(ScanListener.AnalysisBrightnessListener brightnessListener) {
69+
this.brightnessListener = brightnessListener;
70+
}
71+
6472
/**
6573
* 设置扫描格式
6674
*/
@@ -134,6 +142,10 @@ public void onAnalysisBrightness(boolean isDark) {
134142
mScanBoxView.setDark(true);
135143
}
136144
}
145+
146+
if (brightnessListener != null) {
147+
brightnessListener.onAnalysisBrightness(this.isDark);
148+
}
137149
}
138150

139151
public void resetZoom() {

sample/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ dependencies {
5858

5959
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.0-beta-3'
6060
implementation project(':czxing')
61-
// implementation 'me.devilsen:CZXing:0.9.8'
61+
// implementation 'me.devilsen:CZXing:0.9.6'
6262

6363
implementation rootProject.ext.appcompat
6464
testImplementation rootProject.ext.junit

0 commit comments

Comments
 (0)