Skip to content

Commit 5f64967

Browse files
committed
优化一些细节
1 parent 3a8ee0f commit 5f64967

2 files changed

Lines changed: 10 additions & 19 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ private void startCameraById(int cameraId) {
219219
mCameraSurface.setCamera(mCamera);
220220
} catch (Exception e) {
221221
e.printStackTrace();
222+
mSpotAble = false;
222223
if (mScanListener != null) {
223224
mScanListener.onOpenCameraError();
224225
}

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

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import android.text.TextUtils;
55
import android.util.AttributeSet;
66

7-
import java.util.ArrayDeque;
8-
97
import me.devilsen.czxing.code.BarcodeFormat;
108
import me.devilsen.czxing.code.BarcodeReader;
119
import me.devilsen.czxing.code.CodeResult;
@@ -36,7 +34,7 @@ public class ScanView extends BarCoderView implements ScanBoxView.ScanBoxClickLi
3634

3735
private boolean isStop;
3836
private boolean isDark;
39-
private ArrayDeque<Boolean> darkList;
37+
private int showCounter;
4038
private BarcodeReader reader;
4139

4240
public ScanView(Context context) {
@@ -59,8 +57,6 @@ public ScanView(Context context, AttributeSet attrs, int defStyleAttr) {
5957
BarcodeFormat.UPC_A
6058
);
6159
reader.setReadCodeListener(this);
62-
63-
darkList = new ArrayDeque<>(DARK_LIST_SIZE);
6460
}
6561

6662
@Override
@@ -71,8 +67,6 @@ public void onPreviewFrame(byte[] data, int left, int top, int width, int height
7167

7268
reader.read(data, left, top, width, height, rowWidth, rowHeight);
7369
// SaveImageUtil.saveData(data, left, top, width, height, rowWidth);
74-
// int queueSize = mDispatcher.newRunnable(data, left, top, width, height, rowWidth, rowHeight, this).enqueue();
75-
// setQueueSize(queueSize);
7670
}
7771

7872
@Override
@@ -108,25 +102,21 @@ public void onReadCodeResult(CodeResult result) {
108102
public void onAnalysisBrightness(boolean isDark) {
109103
BarCodeUtil.d("isDark : " + isDark);
110104

111-
darkList.addFirst(isDark);
112-
if (darkList.size() > DARK_LIST_SIZE) {
113-
darkList.removeLast();
114-
}
115-
116-
int show = 0;
117-
for (Boolean dark : darkList) {
118-
if (dark) {
119-
show++;
120-
}
105+
if (isDark) {
106+
showCounter++;
107+
showCounter = showCounter > DARK_LIST_SIZE ? DARK_LIST_SIZE : showCounter;
108+
} else {
109+
showCounter--;
110+
showCounter = showCounter < 0 ? 0 : showCounter;
121111
}
122112

123113
if (this.isDark) {
124-
if (show <= 2) {
114+
if (showCounter <= 2) {
125115
this.isDark = false;
126116
mScanBoxView.setDark(false);
127117
}
128118
} else {
129-
if (show >= DARK_LIST_SIZE) {
119+
if (showCounter >= DARK_LIST_SIZE) {
130120
this.isDark = true;
131121
mScanBoxView.setDark(true);
132122
}

0 commit comments

Comments
 (0)