Skip to content

Commit 35a03a9

Browse files
committed
添加扫码框的二维码,加入自定义演示界面
1 parent b2f3abc commit 35a03a9

22 files changed

Lines changed: 605 additions & 64 deletions

build.gradle

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,23 @@ project.ext {
2222

2323
buildscript {
2424
repositories {
25-
google()
2625
jcenter()
27-
26+
google()
2827
}
2928
dependencies {
3029
classpath 'com.android.tools.build:gradle:3.5.2'
3130
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
3231
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
33-
classpath 'com.tencent.bugly:symtabfileuploader:2.2.1'
32+
// classpath 'com.tencent.bugly:symtabfileuploader:2.2.1'
3433
// NOTE: Do not place your application dependencies here; they belong
3534
// in the individual module build.gradle files
3635
}
3736
}
3837

3938
allprojects {
4039
repositories {
41-
google()
4240
jcenter()
43-
41+
google()
4442
}
4543
}
4644

czxing/src/main/cpp/ImageScheduler.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ImageScheduler::ImageScheduler(JNIEnv *env, MultiFormatReader *_reader,
1818
zbarScanner = new ImageScanner();
1919
zbarScanner->set_config(ZBAR_QRCODE, ZBAR_CFG_ENABLE, 1);
2020
qrCodeRecognizer = new QRCodeRecognizer();
21+
decodeQr = true;
2122
stopProcessing.store(false);
2223
isProcessing.store(false);
2324
}
@@ -242,24 +243,26 @@ void ImageScheduler::decodeAdaptivePixels(const Mat &gray) {
242243
}
243244

244245
void ImageScheduler::recognizerQrCode(const Mat &mat) {
246+
LOGE("try to recognizerQrCode..., scanIndex = %d ", scanIndex);
247+
245248
// 不需要解析二维码
246249
if (!decodeQr) {
247250
return;
248251
}
249-
252+
// 7次没有解析出来,尝试聚焦
250253
if (scanIndex % 7 == 0) {
251254
javaCallHelper->onFocus();
252-
return;
253-
}
254-
255-
if (scanIndex % 3 != 0) {
256-
return;
257255
}
256+
// 只有3的倍数次才去使用OpenCV处理
257+
// if (scanIndex % 3 != 0) {
258+
// return;
259+
// }
258260
LOGE("start recognizerQrCode...");
259261

260262
cv::Rect rect;
261263
qrCodeRecognizer->processData(mat, &rect);
262-
if (rect.empty() || rect.height < 100) {
264+
// 一般认为,长度小于120的一般是误报
265+
if (rect.empty() || rect.height < 120) {
263266
return;
264267
}
265268

@@ -283,8 +286,6 @@ void ImageScheduler::recognizerQrCode(const Mat &mat) {
283286

284287
Result ImageScheduler::decodePixels(const Mat &mat) {
285288
try {
286-
// int width = mat.cols;
287-
// int height = mat.rows;
288289
// Mat resultMat(height, width, CV_8UC1, pixels);
289290
// imwrite("/storage/emulated/0/scan/result.jpg", resultMat);
290291

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,15 @@ private void initData() {
9090
ScanBoxView scanBox = mScanView.getScanBox();
9191
scanBox.setCornerColor(option.getCornerColor());
9292
scanBox.setBorderColor(option.getBorderColor());
93+
scanBox.setBorderSize(option.getBorderSize());
9394
scanBox.setScanLineColor(option.getScanLineColors());
95+
scanBox.setFlashLightOnDrawable(option.getFlashLightOnDrawable());
96+
scanBox.setFlashLightOffDrawable(option.getFlashLightOffDrawable());
9497
scanBox.setFlashLightOnText(option.getFlashLightOnText());
9598
scanBox.setFlashLightOffText(option.getFlashLightOffText());
99+
if (option.isDropFlashLight()){
100+
scanBox.dropFlashLightIcon();
101+
}
96102
scanBox.setScanNoticeText(option.getScanNoticeText());
97103

98104
// 标题栏

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

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public ScannerManager setBorderColor(int borderColor) {
3838
return this;
3939
}
4040

41+
public ScannerManager setBorderSize(int borderSize) {
42+
scanOption.borderSize = borderSize;
43+
return this;
44+
}
45+
4146
public ScannerManager setScanMode(int scanMode) {
4247
scanOption.scanMode = scanMode;
4348
return this;
@@ -58,6 +63,16 @@ public ScannerManager continuousScan() {
5863
return this;
5964
}
6065

66+
public ScannerManager setFlashLightOnDrawable(int flashLightOnDrawable) {
67+
scanOption.flashLightOnDrawable = flashLightOnDrawable;
68+
return this;
69+
}
70+
71+
public ScannerManager setFlashLightOffDrawable(int flashLightOffDrawable) {
72+
scanOption.flashLightOffDrawable = flashLightOffDrawable;
73+
return this;
74+
}
75+
6176
public ScannerManager setFlashLightOnText(String lightOnText) {
6277
scanOption.flashLightOnText = lightOnText;
6378
return this;
@@ -73,12 +88,17 @@ public ScannerManager setScanNoticeText(String scanNoticeText) {
7388
return this;
7489
}
7590

91+
public ScannerManager setFlashLightInvisible() {
92+
scanOption.dropFlashLight = true;
93+
return this;
94+
}
95+
7696
public ScannerManager setScanLineColors(List<Integer> scanLineColors) {
7797
scanOption.scanLineColors = scanLineColors;
7898
return this;
7999
}
80100

81-
public ScannerManager setBarcodeFormat(BarcodeFormat... barcodeFormats){
101+
public ScannerManager setBarcodeFormat(BarcodeFormat... barcodeFormats) {
82102
scanOption.barcodeFormats = Arrays.asList(barcodeFormats);
83103
return this;
84104
}
@@ -103,13 +123,17 @@ public static class ScanOption implements Parcelable {
103123

104124
private int cornerColor;
105125
private int borderColor;
126+
private int borderSize;
106127
private int scanMode;
107128
private String title;
108129
private boolean showAlbum = true;
109130
private boolean continuousScan;
110131

132+
private int flashLightOnDrawable;
133+
private int flashLightOffDrawable;
111134
private String flashLightOnText;
112135
private String flashLightOffText;
136+
private boolean dropFlashLight;
113137
private String scanNoticeText;
114138

115139
private List<BarcodeFormat> barcodeFormats;
@@ -123,6 +147,10 @@ public int getBorderColor() {
123147
return borderColor;
124148
}
125149

150+
public int getBorderSize() {
151+
return borderSize;
152+
}
153+
126154
public int getScanMode() {
127155
return scanMode;
128156
}
@@ -139,6 +167,14 @@ public boolean isContinuousScan() {
139167
return continuousScan;
140168
}
141169

170+
public int getFlashLightOnDrawable() {
171+
return flashLightOnDrawable;
172+
}
173+
174+
public int getFlashLightOffDrawable() {
175+
return flashLightOffDrawable;
176+
}
177+
142178
public String getFlashLightOnText() {
143179
return flashLightOnText;
144180
}
@@ -147,6 +183,10 @@ public String getFlashLightOffText() {
147183
return flashLightOffText;
148184
}
149185

186+
public boolean isDropFlashLight() {
187+
return dropFlashLight;
188+
}
189+
150190
public String getScanNoticeText() {
151191
return scanNoticeText;
152192
}
@@ -168,12 +208,16 @@ public int describeContents() {
168208
public void writeToParcel(Parcel dest, int flags) {
169209
dest.writeInt(this.cornerColor);
170210
dest.writeInt(this.borderColor);
211+
dest.writeInt(this.borderSize);
171212
dest.writeInt(this.scanMode);
172213
dest.writeString(this.title);
173214
dest.writeByte(this.showAlbum ? (byte) 1 : (byte) 0);
174215
dest.writeByte(this.continuousScan ? (byte) 1 : (byte) 0);
216+
dest.writeInt(this.flashLightOnDrawable);
217+
dest.writeInt(this.flashLightOffDrawable);
175218
dest.writeString(this.flashLightOnText);
176219
dest.writeString(this.flashLightOffText);
220+
dest.writeByte(this.dropFlashLight ? (byte) 1 : (byte) 0);
177221
dest.writeString(this.scanNoticeText);
178222
dest.writeList(this.barcodeFormats);
179223
dest.writeList(this.scanLineColors);
@@ -185,12 +229,16 @@ public ScanOption() {
185229
protected ScanOption(Parcel in) {
186230
this.cornerColor = in.readInt();
187231
this.borderColor = in.readInt();
232+
this.borderSize = in.readInt();
188233
this.scanMode = in.readInt();
189234
this.title = in.readString();
190235
this.showAlbum = in.readByte() != 0;
191236
this.continuousScan = in.readByte() != 0;
237+
this.flashLightOnDrawable = in.readInt();
238+
this.flashLightOffDrawable = in.readInt();
192239
this.flashLightOnText = in.readString();
193240
this.flashLightOffText = in.readString();
241+
this.dropFlashLight = in.readByte() != 0;
194242
this.scanNoticeText = in.readString();
195243
this.barcodeFormats = new ArrayList<>();
196244
in.readList(this.barcodeFormats, BarcodeFormat.class.getClassLoader());
@@ -209,5 +257,6 @@ public ScanOption[] newArray(int size) {
209257
return new ScanOption[size];
210258
}
211259
};
260+
212261
}
213262
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
abstract class BarCoderView extends FrameLayout implements Camera.PreviewCallback {
2828

2929
private static final int NO_CAMERA_ID = -1;
30-
private static final int DEFAULT_ZOOM_SCALE = 4;
30+
private static final int DEFAULT_ZOOM_SCALE = 3;
3131
private static final long ONE_HUNDRED_MILLISECONDS = 100_000_000;
3232
private final static long DELAY_STEP_TIME = 10_000_000;
3333

0 commit comments

Comments
 (0)