44import android .text .TextUtils ;
55import android .util .AttributeSet ;
66
7- import java .util .ArrayDeque ;
8-
97import me .devilsen .czxing .code .BarcodeFormat ;
108import me .devilsen .czxing .code .BarcodeReader ;
119import 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