Skip to content

Commit

Permalink
1.扫面页面关闭时停止动画并手动置空
Browse files Browse the repository at this point in the history
2.更新gradle版本
yuzhiqiang1993 committed Mar 13, 2019
1 parent f6c4340 commit eb7bc2a
Showing 11 changed files with 52 additions and 42 deletions.
5 changes: 5 additions & 0 deletions app/src/main/java/com/yzq/zxing/MainActivity.java
Original file line number Diff line number Diff line change
@@ -16,12 +16,15 @@
import android.widget.TextView;
import android.widget.Toast;

import com.google.zxing.Result;
import com.yanzhenjie.permission.Action;
import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.Permission;
import com.yzq.zxinglibrary.android.CaptureActivity;
import com.yzq.zxinglibrary.bean.ZxingConfig;
import com.yzq.zxinglibrary.common.Constant;
import com.yzq.zxinglibrary.decode.DecodeImgCallback;
import com.yzq.zxinglibrary.decode.DecodeImgThread;
import com.yzq.zxinglibrary.encode.CodeCreator;

import java.util.List;
@@ -93,6 +96,7 @@ private void initView() {
@Override
public void onClick(View v) {


Bitmap bitmap = null;
switch (v.getId()) {
case R.id.scanBtn:
@@ -166,6 +170,7 @@ public void onAction(List<String> permissions) {

break;


default:
}
}
Binary file added app/src/main/res/drawable/code.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 11 additions & 9 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -26,8 +26,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="8dp"
/>
android:padding="8dp" />

<Button
android:id="@+id/scanBtn"
@@ -40,6 +39,13 @@
android:layout_width="match_parent"
android:layout_height="56dp" />

<Button
android:id="@+id/decodeImgBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="长按图片识别二维码" />


<Button
android:id="@+id/encodeBtnWithLogo"
android:layout_width="match_parent"
@@ -64,13 +70,9 @@

<ImageView
android:id="@+id/contentIv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"

/>


android:layout_width="96dp"
android:layout_height="96dp"
android:layout_gravity="center" />


</LinearLayout>
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -9,8 +9,8 @@ buildscript {
min_sdk_version = 16
target_sdk_version = 27
constraint_version = '1.1.0'
version_code = 225
version_name = '2.2.5'
version_code = 226
version_name = '2.2.6'

/*support*/
android_support = '28.0.0'
@@ -30,9 +30,9 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.android.tools.build:gradle:3.3.2'

classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
3 changes: 1 addition & 2 deletions zxinglibrary/build.gradle
Original file line number Diff line number Diff line change
@@ -19,11 +19,10 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation files('libs/core-3.3.3.jar')
api files('libs/core-3.3.3.jar')
compileOnly "com.android.support:appcompat-v7:$android_support"
compileOnly "com.android.support:design:$android_support"
compileOnly "com.android.support:support-v4:$android_support"
compileOnly "com.android.support:support-vector-drawable:$android_support"
// implementation 'com.google.zxing:core:3.3.2'

}
Original file line number Diff line number Diff line change
@@ -294,6 +294,7 @@ protected void onPause() {
@Override
protected void onDestroy() {
inactivityTimer.shutdown();
viewfinderView.stopAnimator();
super.onDestroy();
}

@@ -345,6 +346,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == Constant.REQUEST_IMAGE && resultCode == RESULT_OK) {
String path = ImageUtil.getImageAbsolutePath(this, data.getData());


new DecodeImgThread(path, new DecodeImgCallback() {
@Override
public void onImageDecodeSuccess(Result result) {
Original file line number Diff line number Diff line change
@@ -27,8 +27,8 @@


/*
* 聚焦管理
* */
* 聚焦管理
* */
final class AutoFocusManager implements Camera.AutoFocusCallback {

private static final String TAG = AutoFocusManager.class.getSimpleName();
@@ -66,7 +66,7 @@ private synchronized void autoFocusAgainLater() {
if (!stopped && outstandingTask == null) {
AutoFocusTask newTask = new AutoFocusTask();
try {
// newTask.execute();
// newTask.execute();
newTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
outstandingTask = newTask;
} catch (RejectedExecutionException ree) {
Original file line number Diff line number Diff line change
@@ -4,12 +4,12 @@

/**
* Created by yzq on 2017/10/18.
*
* <p>
* 解析图片的回调
*/

public interface DecodeImgCallback {
public void onImageDecodeSuccess(Result result);
void onImageDecodeSuccess(Result result);

public void onImageDecodeFailed();
void onImageDecodeFailed();
}
Original file line number Diff line number Diff line change
@@ -39,24 +39,23 @@ public void run() {
return;
}


Bitmap scanBitmap = getBitmap(imgPath,400,400);
Bitmap scanBitmap = getBitmap(imgPath, 400, 400);

MultiFormatReader multiFormatReader = new MultiFormatReader();
// 解码的参数
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>(2);
// 可以解析的编码类型
Vector<BarcodeFormat> decodeFormats = new Vector<BarcodeFormat>();
if (decodeFormats == null || decodeFormats.isEmpty()) {
decodeFormats = new Vector<BarcodeFormat>();
// 扫描的类型 一维码和二维码
decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);
}


// 扫描的类型 一维码和二维码
decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);

hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
// 设置解析的字符编码格式为UTF8
// hints.put(DecodeHintType.CHARACTER_SET, "UTF8");
// hints.put(DecodeHintType.CHARACTER_SET, "UTF8");
// 设置解析配置参数
multiFormatReader.setHints(hints);
// 开始对图像资源解码
@@ -81,7 +80,6 @@ public void run() {
}



/**
* 根据路径获取图片
*
@@ -90,7 +88,7 @@ public void run() {
* @param maxHeight 图片最大高度
* @return bitmap
*/
public static Bitmap getBitmap(final String filePath, final int maxWidth, final int maxHeight) {
private static Bitmap getBitmap(final String filePath, final int maxWidth, final int maxHeight) {

BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
Original file line number Diff line number Diff line change
@@ -28,8 +28,6 @@
import java.util.Vector;
import java.util.concurrent.CountDownLatch;

import javax.crypto.spec.DESedeKeySpec;

/**
* This thread does all the heavy lifting of decoding the images.
*
@@ -39,7 +37,6 @@ public final class DecodeThread extends Thread {

private final CaptureActivity activity;
private final Hashtable<DecodeHintType, Object> hints;
private final Vector<BarcodeFormat> decodeFormats;
private Handler handler;
private final CountDownLatch handlerInitLatch;

@@ -50,19 +47,17 @@ public DecodeThread(CaptureActivity activity, ResultPointCallback resultPointCal

hints = new Hashtable<>();


decodeFormats = new Vector<BarcodeFormat>();

Vector<BarcodeFormat> decodeFormats = new Vector<BarcodeFormat>();

/*是否解析有条形码(一维码)*/
if (activity.config.isDecodeBarCode()) {
decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);

}

decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);
decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);

hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);

hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback);

Original file line number Diff line number Diff line change
@@ -151,6 +151,15 @@ public void setCameraManager(CameraManager cameraManager) {

}

public void stopAnimator() {
if (valueAnimator != null) {
valueAnimator.end();
valueAnimator.cancel();
valueAnimator = null;
}

}

@SuppressLint("DrawAllocation")
@Override
public void onDraw(Canvas canvas) {

0 comments on commit eb7bc2a

Please sign in to comment.