Skip to content

Commit

Permalink
升级zxing3.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
maning committed Jun 4, 2018
1 parent 4a94a3e commit 2363b1b
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 68 deletions.
84 changes: 48 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ZXingCode

## 快速集成二维码扫描,使用最新版本的zxing代码提取(2017.11.10--ZXing 3.3.1
## 快速集成二维码扫描,生成二维码,可配置相册,闪光灯,自定义扫描线颜色(ZXing 3.3.3
[![](https://jitpack.io/v/maning0303/MNZXingCode.svg)](https://jitpack.io/#maning0303/MNZXingCode)

## 功能:
Expand All @@ -13,8 +13,6 @@
![image](https://github.com/maning0303/ZXingCodeDemo/blob/master/screenshots/mn_zxing_screenshot_001.png)
![image](https://github.com/maning0303/ZXingCodeDemo/blob/master/screenshots/mn_zxing_screenshot_002.jpg)
![image](https://github.com/maning0303/ZXingCodeDemo/blob/master/screenshots/mn_zxing_screenshot_003.jpg)
## 最新版本zxing(2017.11.10--ZXing 3.3.1):
![image](https://github.com/maning0303/ZXingCodeDemo/blob/master/screenshots/mn_zxing_screenshot_004.png)

## 如何添加
### Gradle添加:
Expand All @@ -32,57 +30,71 @@
#### 2.在Module目录下的build.gradle中添加依赖
``` gradle
dependencies {
compile 'com.github.maning0303:MNZXingCode:V1.1.3'
compile 'com.github.maning0303:MNZXingCode:V1.1.5'
}
```

### 源码添加:
#### 直接拷贝整个module:libraryzxing 和 libraryzxingcore,然后关联到你的项目就可以使用
#### 直接拷贝整个module:libraryzxing,然后关联到你的项目就可以使用

## 使用方法:
### 进入需要提前申请相机权限;进入需要提前申请相机权限;进入需要提前申请相机权限;


``` java

1.跳转:
Intent intent = new Intent(this, CaptureActivity.class);
//是否显示相册按钮
intent.putExtra(CaptureActivity.INTENT_KEY_PHOTO_FLAG, true);
//识别声音
intent.putExtra(CaptureActivity.INTENT_KEY_BEEP_FLAG, true);
//识别震动
intent.putExtra(CaptureActivity.INTENT_KEY_VIBRATE_FLAG, true);
//扫码框的颜色
intent.putExtra(CaptureActivity.INTENT_KEY_SCSNCOLOR, "#FFFF00");
//扫码框上面的提示文案
intent.putExtra(CaptureActivity.INTENT_KEY_HINTTEXT, "请将二维码放入框中....");
startActivityForResult(intent, 1000);

2.获取结果:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1000) {
if (data == null) {
return;
1:开始扫描:
//默认扫描
MNScanManager.startScan(this, new MNScanCallback() {
@Override
public void onActivityResult(int resultCode, Intent data) {
//TODO:
switch (resultCode) {
case MNScanManager.RESULT_SUCCESS:
String resultSuccess = data.getStringExtra(MNScanManager.INTENT_KEY_RESULT_SUCCESS);
break;
case MNScanManager.RESULT_FAIL:
String resultError = data.getStringExtra(MNScanManager.INTENT_KEY_RESULT_ERROR);
break;
case MNScanManager.RESULT_CANCLE:
showToast("取消扫码");
break;
}
}
});


//自定义扫描
MNScanConfig scanConfig = new MNScanConfig.Builder()
//设置完成震动
.isShowVibrate(false)
//扫描完成声音
.isShowBeep(true)
//显示相册功能
.isShowPhotoAlbum(true)
//打开扫描页面的动画
.setActivityOpenAnime(R.anim.activity_anmie_in)
//自定义文案
.setScanHintText("我是自定义文字")
//扫描线的颜色
.setScanColor("#FFFF00")
.builder();
MNScanManager.startScan(this, scanConfig, new MNScanCallback() {
@Override
public void onActivityResult(int resultCode, Intent data) {
//TODO:
switch (resultCode) {
case CaptureActivity.RESULT_SUCCESS:
String resultSuccess = data.getStringExtra(CaptureActivity.INTENT_KEY_RESULT_SUCCESS);
showToast(resultSuccess);
textView.setText(resultSuccess);
case MNScanManager.RESULT_SUCCESS:
String resultSuccess = data.getStringExtra(MNScanManager.INTENT_KEY_RESULT_SUCCESS);
break;
case CaptureActivity.RESULT_FAIL:
String resultError = data.getStringExtra(CaptureActivity.INTENT_KEY_RESULT_ERROR);
showToast(resultError);
case MNScanManager.RESULT_FAIL:
String resultError = data.getStringExtra(MNScanManager.INTENT_KEY_RESULT_ERROR);
break;
case CaptureActivity.RESULT_CANCLE:
case MNScanManager.RESULT_CANCLE:
showToast("取消扫码");
break;
}
}
}
});

3:生成二维码:
Bitmap qrImage = ZXingUtils.createQRImage("xxxxxx");
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/maning/zxingcodedemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ private void handlerResult(int resultCode, Intent data) {
return;
}
switch (resultCode) {
case CaptureActivity.RESULT_SUCCESS:
String resultSuccess = data.getStringExtra(CaptureActivity.INTENT_KEY_RESULT_SUCCESS);
case MNScanManager.RESULT_SUCCESS:
String resultSuccess = data.getStringExtra(MNScanManager.INTENT_KEY_RESULT_SUCCESS);
showToast(resultSuccess);
textView.setText(resultSuccess);
break;
case CaptureActivity.RESULT_FAIL:
String resultError = data.getStringExtra(CaptureActivity.INTENT_KEY_RESULT_ERROR);
case MNScanManager.RESULT_FAIL:
String resultError = data.getStringExtra(MNScanManager.INTENT_KEY_RESULT_ERROR);
showToast(resultError);
break;
case CaptureActivity.RESULT_CANCLE:
case MNScanManager.RESULT_CANCLE:
showToast("取消扫码");
break;
}
Expand Down
2 changes: 1 addition & 1 deletion libraryzxing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ android {

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.zxing:core:3.3.1'
compile 'com.google.zxing:core:3.3.3'
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,6 @@
public final class CaptureActivity extends Activity implements SurfaceHolder.Callback {

private static final String TAG = CaptureActivity.class.getSimpleName();
//常量
public static final int RESULT_SUCCESS = 0;
public static final int RESULT_FAIL = 1;
public static final int RESULT_CANCLE = 2;
public static final String INTENT_KEY_RESULT_SUCCESS = "intent_key_result_success";
public static final String INTENT_KEY_RESULT_ERROR = "intent_key_result_error";
public static final String INTENT_KEY_HINTTEXT = "intent_key_hinttext";
public static final String INTENT_KEY_SCSNCOLOR = "intent_key_scsncolor";
public static final String INTENT_KEY_PHOTO_FLAG = "intent_key_photo_flag";
public static final String INTENT_KEY_BEEP_FLAG = "intent_key_beep_flag";
public static final String INTENT_KEY_VIBRATE_FLAG = "intent_key_vibrate_flag";

private CameraManager cameraManager;
private CaptureActivityHandler handler;
Expand Down Expand Up @@ -181,11 +170,11 @@ public void onClick(View v) {

private void initIntent() {
Intent intent = getIntent();
String hintText = intent.getStringExtra(INTENT_KEY_HINTTEXT);
String scanColor = intent.getStringExtra(INTENT_KEY_SCSNCOLOR);
boolean photoFlag = intent.getBooleanExtra(INTENT_KEY_PHOTO_FLAG, true);
beepFlag = intent.getBooleanExtra(INTENT_KEY_BEEP_FLAG, true);
vibrateFlag = intent.getBooleanExtra(INTENT_KEY_VIBRATE_FLAG, true);
String hintText = intent.getStringExtra(MNScanManager.INTENT_KEY_HINTTEXT);
String scanColor = intent.getStringExtra(MNScanManager.INTENT_KEY_SCSNCOLOR);
boolean photoFlag = intent.getBooleanExtra(MNScanManager.INTENT_KEY_PHOTO_FLAG, true);
beepFlag = intent.getBooleanExtra(MNScanManager.INTENT_KEY_BEEP_FLAG, true);
vibrateFlag = intent.getBooleanExtra(MNScanManager.INTENT_KEY_VIBRATE_FLAG, true);
if (!TextUtils.isEmpty(hintText)) {
viewfinderView.setHintText(hintText);
}
Expand Down Expand Up @@ -336,24 +325,24 @@ public void handleDecode(Result rawResult, Bitmap barcode, float scaleFactor) {

private void finishFailed(String errorMsg) {
Intent intent = new Intent();
intent.putExtra(INTENT_KEY_RESULT_ERROR, errorMsg);
this.setResult(RESULT_FAIL, intent);
intent.putExtra(MNScanManager.INTENT_KEY_RESULT_ERROR, errorMsg);
this.setResult(MNScanManager.RESULT_FAIL, intent);
this.finish();
//关闭窗体动画显示
this.overridePendingTransition(R.anim.mn_scan_activity_bottom_out, 0);
}

private void finishCancle() {
this.setResult(RESULT_CANCLE, null);
this.setResult(MNScanManager.RESULT_CANCLE, null);
this.finish();
//关闭窗体动画显示
this.overridePendingTransition(R.anim.mn_scan_activity_bottom_out, 0);
}

private void finishSuccess(String result) {
Intent intent = new Intent();
intent.putExtra(INTENT_KEY_RESULT_SUCCESS, result);
this.setResult(RESULT_SUCCESS, intent);
intent.putExtra(MNScanManager.INTENT_KEY_RESULT_SUCCESS, result);
this.setResult(MNScanManager.RESULT_SUCCESS, intent);
this.finish();
//关闭窗体动画显示
this.overridePendingTransition(R.anim.mn_scan_activity_bottom_out, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@

public class MNScanManager {

//常量
public static final int RESULT_SUCCESS = 0;
public static final int RESULT_FAIL = 1;
public static final int RESULT_CANCLE = 2;
public static final String INTENT_KEY_RESULT_SUCCESS = "intent_key_result_success";
public static final String INTENT_KEY_RESULT_ERROR = "intent_key_result_error";


//跳转传入的数据
public static final String INTENT_KEY_HINTTEXT = "intent_key_hinttext";
public static final String INTENT_KEY_SCSNCOLOR = "intent_key_scsncolor";
public static final String INTENT_KEY_PHOTO_FLAG = "intent_key_photo_flag";
public static final String INTENT_KEY_BEEP_FLAG = "intent_key_beep_flag";
public static final String INTENT_KEY_VIBRATE_FLAG = "intent_key_vibrate_flag";


public static void startScan(Activity activity, MNScanCallback scanCallback) {
Intent intent = new Intent(activity.getApplicationContext(), CaptureActivity.class);
Expand All @@ -28,15 +43,15 @@ public static void startScan(Activity activity, MNScanConfig mnScanConfig, MNSca
}
Intent intent = new Intent(activity.getApplicationContext(), CaptureActivity.class);
//是否显示相册按钮
intent.putExtra(CaptureActivity.INTENT_KEY_PHOTO_FLAG, mnScanConfig.isShowPhotoAlbum());
intent.putExtra(MNScanManager.INTENT_KEY_PHOTO_FLAG, mnScanConfig.isShowPhotoAlbum());
//识别声音
intent.putExtra(CaptureActivity.INTENT_KEY_BEEP_FLAG, mnScanConfig.isShowBeep());
intent.putExtra(MNScanManager.INTENT_KEY_BEEP_FLAG, mnScanConfig.isShowBeep());
//识别震动
intent.putExtra(CaptureActivity.INTENT_KEY_VIBRATE_FLAG, mnScanConfig.isShowVibrate());
intent.putExtra(MNScanManager.INTENT_KEY_VIBRATE_FLAG, mnScanConfig.isShowVibrate());
//扫码框的颜色
intent.putExtra(CaptureActivity.INTENT_KEY_SCSNCOLOR, mnScanConfig.getScanColor());
intent.putExtra(MNScanManager.INTENT_KEY_SCSNCOLOR, mnScanConfig.getScanColor());
//扫码框上面的提示文案
intent.putExtra(CaptureActivity.INTENT_KEY_HINTTEXT, mnScanConfig.getScanHintText());
intent.putExtra(MNScanManager.INTENT_KEY_HINTTEXT, mnScanConfig.getScanHintText());

ActResultRequest actResultRequest = new ActResultRequest(activity);
actResultRequest.startForResult(intent, scanCallback);
Expand Down
Binary file removed screenshots/mn_zxing_screenshot_004.png
Binary file not shown.

0 comments on commit 2363b1b

Please sign in to comment.