Skip to content

Commit ab2e663

Browse files
committed
修复内存泄漏的问题
1 parent d1d97d1 commit ab2e663

5 files changed

Lines changed: 25 additions & 19 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ C++ port of ZXing for Android
99
### 使用
1010
在gradle中:
1111
``` groovy
12-
implementation 'me.devilsen:CZXing:0.9'
12+
implementation 'me.devilsen:CZXing:0.9.1'
1313
```
1414
建议加入abiFilters
1515
```gradle

czxing/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ android {
77
minSdkVersion rootProject.ext.minSdkVersion
88
targetSdkVersion rootProject.ext.targetSdkVersion
99
versionCode 16
10-
versionName "0.9"
10+
versionName "0.9.1"
1111

1212
externalNativeBuild {
1313
cmake {

czxing/src/main/java/me/devilsen/czxing/camera/CameraSurface.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -234,23 +234,27 @@ void handleZoom(boolean isZoomIn) {
234234
* @param scale 放大缩小的数值
235235
*/
236236
void handleZoom(boolean isZoomIn, int scale) {
237-
Camera.Parameters params = mCamera.getParameters();
238-
if (params.isZoomSupported()) {
239-
int zoom = params.getZoom();
240-
if (isZoomIn && zoom < params.getMaxZoom()) {
241-
BarCodeUtil.d("放大");
242-
zoom += scale;
243-
} else if (!isZoomIn && zoom > 0) {
244-
BarCodeUtil.d("缩小");
245-
mZoomOutFlag = true;
246-
zoom -= scale;
237+
try {
238+
Camera.Parameters params = mCamera.getParameters();
239+
if (params.isZoomSupported()) {
240+
int zoom = params.getZoom();
241+
if (isZoomIn && zoom < params.getMaxZoom()) {
242+
BarCodeUtil.d("放大");
243+
zoom += scale;
244+
} else if (!isZoomIn && zoom > 0) {
245+
BarCodeUtil.d("缩小");
246+
mZoomOutFlag = true;
247+
zoom -= scale;
248+
} else {
249+
BarCodeUtil.d("既不放大也不缩小");
250+
}
251+
params.setZoom(zoom);
252+
mCamera.setParameters(params);
247253
} else {
248-
BarCodeUtil.d("既不放大也不缩小");
254+
BarCodeUtil.d("不支持缩放");
249255
}
250-
params.setZoom(zoom);
251-
mCamera.setParameters(params);
252-
} else {
253-
BarCodeUtil.d("不支持缩放");
256+
} catch (Exception e) {
257+
e.printStackTrace();
254258
}
255259
}
256260

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public ScanView(Context context, AttributeSet attrs, int defStyleAttr) {
5656
BarcodeFormat.EAN_13,
5757
BarcodeFormat.UPC_A
5858
);
59-
reader.setReadCodeListener(this);
6059
}
6160

6261
@Override
@@ -71,6 +70,7 @@ public void onPreviewFrame(byte[] data, int left, int top, int width, int height
7170

7271
@Override
7372
public void startScan() {
73+
reader.setReadCodeListener(this);
7474
super.startScan();
7575
reader.prepareRead();
7676
isStop = false;
@@ -81,6 +81,7 @@ public void stopScan() {
8181
super.stopScan();
8282
reader.stopRead();
8383
isStop = true;
84+
reader.setReadCodeListener(null);
8485
}
8586

8687
@Override

sample/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ android {
4747

4848
dependencies {
4949

50+
// debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.0-beta-3'
5051
// implementation project(':czxing')
51-
implementation 'me.devilsen:CZXing:0.9'
52+
implementation 'me.devilsen:CZXing:0.9.1'
5253

5354
implementation rootProject.ext.appcompat
5455
testImplementation rootProject.ext.junit

0 commit comments

Comments
 (0)