Skip to content

Commit 9b29b68

Browse files
v1.0.8 fix #13
1 parent b57ef49 commit 9b29b68

File tree

10 files changed

+109
-115
lines changed

10 files changed

+109
-115
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
2828
```groovy
2929
dependencies {
30-
compile 'com.google.zxing:core:3.1.0'
30+
compile 'com.google.zxing:core:3.2.1'
3131
compile 'cn.bingoogolapple:bga-qrcodecore:latestVersion@aar'
3232
compile 'cn.bingoogolapple:bga-zxing:latestVersion@aar'
3333
}
@@ -260,6 +260,6 @@ void onEncodeQRCodeFailure()
260260

261261
### 关于我
262262

263-
| 新浪微博 | 个人主页 | 邮箱 | BGA系列开源库QQ群 |
264-
| ------------ | ------------- | ------------ | ------------ |
265-
| <a href="http://weibo.com/bingoogol" target="_blank">bingoogolapple</a> | <a href="http://www.bingoogolapple.cn" target="_blank">bingoogolapple.cn</a> | <a href="mailto:bingoogolapple@gmail.com" target="_blank">bingoogolapple@gmail.com</a> | ![BGA_CODE_CLUB](http://7xk9dj.com1.z0.glb.clouddn.com/BGA_CODE_CLUB.png?imageView2/2/w/200) |
263+
| 新浪微博 | 个人主页 | 邮箱 | BGA系列开源库QQ群 | 如果你觉得这个库确实对你有帮助,可以考虑赞助我一块钱买机械键盘来撸代码 |
264+
| ------------ | ------------- | ------------ | ------------ | ------------ |
265+
| <a href="http://weibo.com/bingoogol" target="_blank">bingoogolapple</a> | <a href="http://www.bingoogolapple.cn" target="_blank">bingoogolapple.cn</a> | <a href="mailto:bingoogolapple@gmail.com" target="_blank">bingoogolapple@gmail.com</a> | ![BGA_CODE_CLUB](http://7xk9dj.com1.z0.glb.clouddn.com/BGA_CODE_CLUB.png?imageView2/2/w/200) | ![BGA_AliPay](http://7xk9dj.com1.z0.glb.clouddn.com/BGAAliPay.JPG?imageView2/2/w/300) |

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.1.0-beta1'
8+
classpath 'com.android.tools.build:gradle:2.1.0'
99

1010

1111
// NOTE: Do not place your application dependencies here; they belong

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ ANDROID_BUILD_TARGET_SDK_VERSION=23
33
ANDROID_BUILD_SDK_VERSION=23
44
ANDROID_BUILD_TOOLS_VERSION=23.0.3
55

6-
VERSION_NAME=1.0.7
7-
VERSION_CODE=107
6+
VERSION_NAME=1.0.8
7+
VERSION_CODE=108
88

99

1010

qrcodecore/src/main/java/cn/bingoogolapple/qrcode/core/CameraPreview.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import android.content.pm.PackageManager;
55
import android.hardware.Camera;
66
import android.os.Handler;
7-
import android.util.AttributeSet;
87
import android.util.Log;
98
import android.view.SurfaceHolder;
109
import android.view.SurfaceView;
@@ -22,10 +21,6 @@ public CameraPreview(Context context) {
2221
super(context);
2322
}
2423

25-
public CameraPreview(Context context, AttributeSet attrs) {
26-
super(context, attrs);
27-
}
28-
2924
public void setCamera(Camera camera) {
3025
mCamera = camera;
3126
if (mCamera != null) {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package cn.bingoogolapple.qrcode.core;
2+
3+
import android.hardware.Camera;
4+
import android.os.AsyncTask;
5+
6+
public class ProcessDataTask extends AsyncTask<Void,Void,String> {
7+
private Camera mCamera;
8+
private byte[] mData;
9+
private Delegate mDelegate;
10+
11+
public ProcessDataTask(Camera camera, byte[] data, Delegate delegate) {
12+
mCamera = camera;
13+
mData = data;
14+
mDelegate = delegate;
15+
}
16+
17+
@Override
18+
protected String doInBackground(Void... params) {
19+
Camera.Parameters parameters = mCamera.getParameters();
20+
Camera.Size size = parameters.getPreviewSize();
21+
int width = size.width;
22+
int height = size.height;
23+
24+
byte[] rotatedData = new byte[mData.length];
25+
for (int y = 0; y < height; y++) {
26+
for (int x = 0; x < width; x++) {
27+
rotatedData[x * height + height - y - 1] = mData[x + y * width];
28+
}
29+
}
30+
int tmp = width;
31+
width = height;
32+
height = tmp;
33+
34+
return mDelegate.processData(rotatedData, width, height);
35+
}
36+
37+
public interface Delegate {
38+
String processData(byte[] data, int width, int height);
39+
}
40+
}

qrcodecore/src/main/java/cn/bingoogolapple/qrcode/core/QRCodeView.java

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
import android.content.Context;
44
import android.hardware.Camera;
55
import android.os.Handler;
6+
import android.text.TextUtils;
67
import android.util.AttributeSet;
78
import android.view.View;
89
import android.widget.FrameLayout;
910

10-
public abstract class QRCodeView extends FrameLayout implements Camera.PreviewCallback {
11+
public abstract class QRCodeView extends FrameLayout implements Camera.PreviewCallback, ProcessDataTask.Delegate {
1112
protected Camera mCamera;
1213
protected CameraPreview mPreview;
1314
protected ScanBoxView mScanBoxView;
1415
protected Delegate mDelegate;
1516
protected Handler mHandler;
17+
protected boolean mSpotAble = false;
1618

1719
public QRCodeView(Context context, AttributeSet attributeSet) {
1820
this(context, attributeSet, 0);
@@ -103,6 +105,8 @@ public void startSpot() {
103105
* @param delay
104106
*/
105107
public void startSpotDelay(int delay) {
108+
mSpotAble = true;
109+
106110
startCamera();
107111
// 开始前先移除之前的任务
108112
mHandler.removeCallbacks(mOneShotPreviewCallbackTask);
@@ -113,6 +117,8 @@ public void startSpotDelay(int delay) {
113117
* 停止识别
114118
*/
115119
public void stopSpot() {
120+
mSpotAble = false;
121+
116122
if (mCamera != null) {
117123
mCamera.setOneShotPreviewCallback(null);
118124
}
@@ -152,32 +158,30 @@ public void closeFlashlight() {
152158
}
153159

154160
@Override
155-
public void onPreviewFrame(byte[] data, Camera camera) {
156-
Camera.Parameters parameters = camera.getParameters();
157-
Camera.Size size = parameters.getPreviewSize();
158-
int width = size.width;
159-
int height = size.height;
160-
161-
byte[] rotatedData = new byte[data.length];
162-
for (int y = 0; y < height; y++) {
163-
for (int x = 0; x < width; x++) {
164-
rotatedData[x * height + height - y - 1] = data[x + y * width];
165-
}
161+
public void onPreviewFrame(final byte[] data, final Camera camera) {
162+
if (mSpotAble) {
163+
new ProcessDataTask(camera, data, this) {
164+
@Override
165+
protected void onPostExecute(String result) {
166+
if (mSpotAble) {
167+
if (mDelegate != null && !TextUtils.isEmpty(result)) {
168+
mDelegate.onScanQRCodeSuccess(result);
169+
} else {
170+
try {
171+
camera.setOneShotPreviewCallback(QRCodeView.this);
172+
} catch (RuntimeException e) {
173+
}
174+
}
175+
}
176+
}
177+
}.execute();
166178
}
167-
int tmp = width;
168-
width = height;
169-
height = tmp;
170-
data = rotatedData;
171-
172-
handleData(data, width, height, camera);
173179
}
174180

175-
protected abstract void handleData(byte[] data, int width, int height, Camera camera);
176-
177181
private Runnable mOneShotPreviewCallbackTask = new Runnable() {
178182
@Override
179183
public void run() {
180-
if (mCamera != null) {
184+
if (mCamera != null && mSpotAble) {
181185
mCamera.setOneShotPreviewCallback(QRCodeView.this);
182186
}
183187
}
Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package cn.bingoogolapple.qrcode.zbar;
22

33
import android.content.Context;
4-
import android.hardware.Camera;
5-
import android.os.AsyncTask;
64
import android.text.TextUtils;
75
import android.util.AttributeSet;
86

@@ -43,40 +41,20 @@ public void setupScanner() {
4341
}
4442

4543
@Override
46-
protected void handleData(final byte[] data, final int width, final int height, final Camera camera) {
47-
new AsyncTask<Void,Void,String>() {
48-
49-
@Override
50-
protected String doInBackground(Void... params) {
51-
String result = null;
52-
Image barcode = new Image(width, height, "Y800");
53-
barcode.setData(data);
54-
if (mScanner.scanImage(barcode) != 0) {
55-
SymbolSet syms = mScanner.getResults();
56-
for (Symbol sym : syms) {
57-
String symData = sym.getData();
58-
if (!TextUtils.isEmpty(symData)) {
59-
result = symData;
60-
break;
61-
}
62-
}
63-
}
64-
return result;
65-
}
66-
67-
@Override
68-
protected void onPostExecute(String result) {
69-
if (mDelegate != null && !TextUtils.isEmpty(result)) {
70-
mDelegate.onScanQRCodeSuccess(result);
71-
} else {
72-
try {
73-
camera.setOneShotPreviewCallback(ZBarView.this);
74-
} catch (RuntimeException e) {
75-
}
44+
public String processData(byte[] data, int width, int height) {
45+
String result = null;
46+
Image barcode = new Image(width, height, "Y800");
47+
barcode.setData(data);
48+
if (mScanner.scanImage(barcode) != 0) {
49+
SymbolSet syms = mScanner.getResults();
50+
for (Symbol sym : syms) {
51+
String symData = sym.getData();
52+
if (!TextUtils.isEmpty(symData)) {
53+
result = symData;
54+
break;
7655
}
7756
}
78-
}.execute();
79-
57+
}
58+
return result;
8059
}
81-
8260
}

zbardemo/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ android {
1313
}
1414

1515
dependencies {
16-
compile 'com.android.support:appcompat-v7:23.3.0'
17-
compile 'pub.devrel:easypermissions:0.1.5'
16+
compile 'com.android.support:appcompat-v7:23.4.0'
17+
compile 'pub.devrel:easypermissions:0.1.6'
1818
// compile project(':zbar')
1919

2020
// -------------------- 以下两个库是必须依赖的 ----------------------------
21-
compile 'cn.bingoogolapple:bga-qrcodecore:1.0.7@aar'
22-
compile 'cn.bingoogolapple:bga-zbar:1.0.7@aar'
21+
compile 'cn.bingoogolapple:bga-qrcodecore:1.0.8@aar'
22+
compile 'cn.bingoogolapple:bga-zbar:1.0.8@aar'
2323
// -------------------- 以上两个库是必须依赖的 ----------------------------
2424
}
Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package cn.bingoogolapple.qrcode.zxing;
22

33
import android.content.Context;
4-
import android.hardware.Camera;
5-
import android.os.AsyncTask;
6-
import android.text.TextUtils;
74
import android.util.AttributeSet;
85

96
import com.google.zxing.BinaryBitmap;
@@ -17,7 +14,6 @@
1714
public class ZXingView extends QRCodeView {
1815
private MultiFormatReader mMultiFormatReader;
1916

20-
2117
public ZXingView(Context context, AttributeSet attributeSet) {
2218
this(context, attributeSet, 0);
2319
}
@@ -33,40 +29,21 @@ private void initMultiFormatReader() {
3329
}
3430

3531
@Override
36-
protected void handleData(final byte[] data, final int width, final int height, final Camera camera) {
37-
new AsyncTask<Void,Void,String>() {
38-
39-
@Override
40-
protected String doInBackground(Void... params) {
41-
String result = null;
42-
Result rawResult = null;
43-
44-
try {
45-
PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height, false);
46-
rawResult = mMultiFormatReader.decodeWithState(new BinaryBitmap(new HybridBinarizer(source)));
47-
} catch (Exception e) {
48-
} finally {
49-
mMultiFormatReader.reset();
50-
}
51-
52-
if (rawResult != null) {
53-
result = rawResult.getText();
54-
}
55-
return result;
56-
}
57-
58-
@Override
59-
protected void onPostExecute(String result) {
60-
if (mDelegate != null && !TextUtils.isEmpty(result)) {
61-
mDelegate.onScanQRCodeSuccess(result);
62-
} else {
63-
try {
64-
camera.setOneShotPreviewCallback(ZXingView.this);
65-
} catch (RuntimeException e) {
66-
}
67-
68-
}
69-
}
70-
}.execute();
32+
public String processData(byte[] data, int width, int height) {
33+
String result = null;
34+
Result rawResult = null;
35+
36+
try {
37+
PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height, false);
38+
rawResult = mMultiFormatReader.decodeWithState(new BinaryBitmap(new HybridBinarizer(source)));
39+
} catch (Exception e) {
40+
} finally {
41+
mMultiFormatReader.reset();
42+
}
43+
44+
if (rawResult != null) {
45+
result = rawResult.getText();
46+
}
47+
return result;
7148
}
7249
}

zxingdemo/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ android {
1313
}
1414

1515
dependencies {
16-
compile 'com.android.support:appcompat-v7:23.3.0'
17-
compile 'pub.devrel:easypermissions:0.1.5'
16+
compile 'com.android.support:appcompat-v7:23.4.0'
17+
compile 'pub.devrel:easypermissions:0.1.6'
1818
// compile project(':zxing')
1919

2020
// -------------------- 以下三个库是必须依赖的 ----------------------------
2121
compile 'com.google.zxing:core:3.2.1'
22-
compile 'cn.bingoogolapple:bga-qrcodecore:1.0.7@aar'
23-
compile 'cn.bingoogolapple:bga-zxing:1.0.7@aar'
22+
compile 'cn.bingoogolapple:bga-qrcodecore:1.0.8@aar'
23+
compile 'cn.bingoogolapple:bga-zxing:1.0.8@aar'
2424
// -------------------- 以上三个库是必须依赖的 ----------------------------
2525
}

0 commit comments

Comments
 (0)