Skip to content

Commit

Permalink
自由设置解码类型
Browse files Browse the repository at this point in the history
  • Loading branch information
hupei committed Jul 7, 2017
1 parent aa9b5d3 commit 8092ffe
Show file tree
Hide file tree
Showing 253 changed files with 205 additions and 38,049 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
###一、概述
### 一、概述

相信Adnroid开发都知道,有四款扫描器,[Zxing](https://github.com/zxing/zxing)[Zbar](https://github.com/zbar/zbar)[Barcode4J](https://sourceforge.net/projects/barcode4j/files/)[OkapiBarcode](https://github.com/woo-j/OkapiBarcode) 前二者应用较广泛,至于介绍与区别就在此阐述,网上有很多。此文主要介绍在在使用过程中,官方客户端各种达不到需求。相信很多童鞋都有此体会,所以借此机会就在Zxing 官方客户端基础上修改,去除无用功能并二次封装达到可扩展。
- 官方客户端目前问题汇总
Expand All @@ -11,12 +11,12 @@
- 可定制扫描框与扫描线样式
- 加入创建二维码、识别图片中的二维码功能

###二、效果图
### 二、效果图
<img src="preview/gif.gif" width="240px"/>

###三、[下载APK体验](preview/sample-debug.apk)
### 三、[下载APK体验](preview/sample-debug.apk)

###四、引用
### 四、引用

## 1、在线
- 本库依赖使用Gradle构建时添加一下即可:
Expand Down Expand Up @@ -191,7 +191,14 @@ Bitmap bitmap = new QREncode.Builder(this)
</tr>
</table>

### 七、版本更新
### 七、注意事项
对于setLaserFrameTopMargin方法,扫描区域偏移的问题[issues-13](https://github.com/mylhyl/Android-Zxing/issues/13)

QQ交流群:630413339 [点击链接加入群Android-Zxing](https://jq.qq.com/?_wv=1027&k=4BR729O)

<img src="preview/qrcode.png"/>

### 八、版本更新

> 1.3.1 优化代码
Expand Down
Binary file added preview/qrcode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified preview/sample-debug.apk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.google.zxing.client.result.TextParsedResult;
import com.google.zxing.client.result.URIParsedResult;
import com.mylhyl.zxing.scanner.OnScannerCompletionListener;
import com.mylhyl.zxing.scanner.common.Intents;
import com.mylhyl.zxing.scanner.common.Scanner;
import com.mylhyl.zxing.scanner.result.AddressBookResult;
import com.mylhyl.zxing.scanner.result.ISBNResult;
import com.mylhyl.zxing.scanner.result.ProductResult;
Expand Down Expand Up @@ -69,26 +69,26 @@ public void OnScannerCompletion(Result rawResult, ParsedResult parsedResult, Bit
switch (type) {
case ADDRESSBOOK:
AddressBookParsedResult addressBook = (AddressBookParsedResult) parsedResult;
bundle.putSerializable(Intents.Scan.RESULT, new AddressBookResult(addressBook));
bundle.putSerializable(Scanner.Scan.RESULT, new AddressBookResult(addressBook));
break;
case PRODUCT:
ProductParsedResult product = (ProductParsedResult) parsedResult;
Log.i(TAG, "productID: " + product.getProductID());
bundle.putSerializable(Intents.Scan.RESULT, new ProductResult(product));
bundle.putSerializable(Scanner.Scan.RESULT, new ProductResult(product));
break;
case ISBN:
ISBNParsedResult isbn = (ISBNParsedResult) parsedResult;
Log.i(TAG, "isbn: " + isbn.getISBN());
bundle.putSerializable(Intents.Scan.RESULT, new ISBNResult(isbn));
bundle.putSerializable(Scanner.Scan.RESULT, new ISBNResult(isbn));
break;
case URI:
URIParsedResult uri = (URIParsedResult) parsedResult;
Log.i(TAG, "uri: " + uri.getURI());
bundle.putSerializable(Intents.Scan.RESULT, new URIResult(uri));
bundle.putSerializable(Scanner.Scan.RESULT, new URIResult(uri));
break;
case TEXT:
TextParsedResult textParsedResult = (TextParsedResult) parsedResult;
bundle.putString(Intents.Scan.RESULT, textParsedResult.getText());
bundle.putString(Scanner.Scan.RESULT, textParsedResult.getText());
break;
case GEO:
break;
Expand All @@ -102,7 +102,7 @@ public void OnScannerCompletion(Result rawResult, ParsedResult parsedResult, Bit

private void onReturnScanResult(Result rawResult) {
Intent intent = getIntent();
intent.putExtra(Intents.Scan.RESULT, rawResult.getText());
intent.putExtra(Scanner.Scan.RESULT, rawResult.getText());
setResult(Activity.RESULT_OK, intent);
finish();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import android.widget.TextView;

import com.google.zxing.client.result.ParsedResultType;
import com.mylhyl.zxing.scanner.common.Intents;
import com.mylhyl.zxing.scanner.common.Scanner;
import com.mylhyl.zxing.scanner.encode.QREncode;

import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -129,7 +129,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != Activity.RESULT_CANCELED && resultCode == Activity.RESULT_OK) {
if (requestCode == ScannerActivity.REQUEST_CODE_SCANNER) {
if (data != null) {
String stringExtra = data.getStringExtra(Intents.Scan.RESULT);
String stringExtra = data.getStringExtra(Scanner.Scan.RESULT);
tvResult.setText(stringExtra);
}
} else if (requestCode == PICK_CONTACT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.google.zxing.Result;
import com.mylhyl.zxing.scanner.ScannerView;
import com.mylhyl.zxing.scanner.common.Intents;
import com.mylhyl.zxing.scanner.common.Scanner;
import com.mylhyl.zxing.scanner.decode.QRDecode;
import com.mylhyl.zxing.scanner.sample.picture.PickPictureTotalActivity;

Expand Down Expand Up @@ -57,10 +57,12 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
findViewById(R.id.button4).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ContextCompat.checkSelfPermission(ScannerActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (ContextCompat.checkSelfPermission(ScannerActivity.this, Manifest.permission
.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
//权限还没有授予,需要在这里写申请权限的代码
ActivityCompat.requestPermissions(ScannerActivity.this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, APPLY_READ_EXTERNAL_STORAGE);
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
APPLY_READ_EXTERNAL_STORAGE);
} else {
PickPictureTotalActivity.gotoActivity(ScannerActivity.this);
}
Expand All @@ -72,8 +74,9 @@ public void onClick(View v) {
laserMode = extras.getInt(EXTRA_LASER_LINE_MODE);
}
mScannerView.setMediaResId(R.raw.beep);//设置扫描成功的声音
mScannerView.setDrawText("将二维码放入框内",true);
mScannerView.setDrawText("将二维码放入框内", true);
mScannerView.setDrawTextColor(Color.RED);
// mScannerView.setScanMode(Scanner.ScanMode.PRODUCT_MODE);

// mScannerView.setLaserFrameTopMargin(100);//扫描框与屏幕上方距离
// mScannerView.setLaserFrameSize(200, 200);//扫描框大小
Expand All @@ -95,7 +98,8 @@ public void onClick(View v) {
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == APPLY_READ_EXTERNAL_STORAGE) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Expand Down Expand Up @@ -146,14 +150,15 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != Activity.RESULT_CANCELED && resultCode == Activity.RESULT_OK) {
if (requestCode == PickPictureTotalActivity.REQUEST_CODE_SELECT_PICTURE) {
String picturePath = data.getStringExtra(PickPictureTotalActivity.EXTRA_PICTURE_PATH);
String picturePath = data.getStringExtra(PickPictureTotalActivity
.EXTRA_PICTURE_PATH);
QRDecode.decodeQR(picturePath, this);
}
}
}

public static void gotoActivity(Activity activity, boolean isBackResult, int laserMode) {
activity.startActivityForResult(new Intent(Intents.Scan.ACTION)
activity.startActivityForResult(new Intent(Scanner.Scan.ACTION)
.putExtra(ScannerActivity.EXTRA_RETURN_SCANNER_RESULT, isBackResult)
.putExtra(EXTRA_LASER_LINE_MODE, laserMode)
, ScannerActivity.REQUEST_CODE_SCANNER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import android.os.Bundle;
import android.widget.TextView;

import com.mylhyl.zxing.scanner.common.Intents;
import com.mylhyl.zxing.scanner.common.Scanner;
import com.mylhyl.zxing.scanner.result.AddressBookResult;
import com.mylhyl.zxing.scanner.sample.BasicActivity;
import com.mylhyl.zxing.scanner.sample.R;
Expand All @@ -25,7 +25,7 @@ protected void onCreate(Bundle savedInstanceState) {
Bundle extras = getIntent().getExtras();
if (extras == null) finish();

AddressBookResult addressBookResult = (AddressBookResult) extras.getSerializable(Intents.Scan.RESULT);
AddressBookResult addressBookResult = (AddressBookResult) extras.getSerializable(Scanner.Scan.RESULT);
if (addressBookResult == null) finish();

String[] names = addressBookResult.getNames();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.litesuits.http.request.StringRequest;
import com.litesuits.http.request.param.HttpMethods;
import com.litesuits.http.response.Response;
import com.mylhyl.zxing.scanner.common.Intents;
import com.mylhyl.zxing.scanner.common.Scanner;
import com.mylhyl.zxing.scanner.result.ISBNResult;
import com.mylhyl.zxing.scanner.result.ProductResult;
import com.mylhyl.zxing.scanner.sample.BasicActivity;
Expand Down Expand Up @@ -48,7 +48,7 @@ protected void onCreate(Bundle savedInstanceState) {
Bundle extras = getIntent().getExtras();
if (extras == null) finish();

Serializable serializable = extras.getSerializable(Intents.Scan.RESULT);
Serializable serializable = extras.getSerializable(Scanner.Scan.RESULT);
if (serializable == null) finish();

String productID = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import android.os.Bundle;
import android.widget.TextView;

import com.mylhyl.zxing.scanner.common.Intents;
import com.mylhyl.zxing.scanner.common.Scanner;
import com.mylhyl.zxing.scanner.sample.BasicActivity;
import com.mylhyl.zxing.scanner.sample.R;

Expand All @@ -20,7 +20,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_text);
Bundle extras = getIntent().getExtras();
if (extras != null)
((TextView) findViewById(R.id.textView3)).setText(extras.getString(Intents.Scan.RESULT));
((TextView) findViewById(R.id.textView3)).setText(extras.getString(Scanner.Scan.RESULT));
}

public static void gotoActivity(Activity activity, Bundle bundle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import android.webkit.WebViewClient;

import com.mylhyl.crlayout.SwipeRefreshWebView;
import com.mylhyl.zxing.scanner.common.Intents;
import com.mylhyl.zxing.scanner.common.Scanner;
import com.mylhyl.zxing.scanner.result.URIResult;
import com.mylhyl.zxing.scanner.sample.BasicActivity;
import com.mylhyl.zxing.scanner.sample.R;
Expand All @@ -22,7 +22,7 @@ public class UriActivity extends BasicActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_uri);
String uri = ((URIResult) getIntent().getSerializableExtra(Intents.Scan.RESULT)).getUri();
String uri = ((URIResult) getIntent().getSerializableExtra(Scanner.Scan.RESULT)).getUri();
swipeRefreshWebView = (SwipeRefreshWebView) findViewById(R.id.webView);
swipeRefreshWebView.getScrollView().loadUrl(uri);
swipeRefreshWebView.getScrollView().setWebViewClient(new SampleWebViewClient());
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include ':zxing', ':zxingscanner', ':sample'
include ':zxingscanner', ':sample'

1 change: 0 additions & 1 deletion zxing/.gitignore

This file was deleted.

39 changes: 0 additions & 39 deletions zxing/build.gradle

This file was deleted.

5 changes: 0 additions & 5 deletions zxing/src/main/AndroidManifest.xml

This file was deleted.

77 changes: 0 additions & 77 deletions zxing/src/main/java/com/google/zxing/BarcodeFormat.java

This file was deleted.

Loading

0 comments on commit 8092ffe

Please sign in to comment.