Skip to content

Commit

Permalink
新增是否解析条形码配置项,可设为false只解析二维码
Browse files Browse the repository at this point in the history
更新gradle版本至27.1.1
  • Loading branch information
yuzhiqiang1993 committed May 29, 2018
1 parent c417556 commit ee993ee
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 102 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
36 changes: 36 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
compileSdkVersion compile_sdk_version

defaultConfig {
applicationId "com.yzq.zxing"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
minSdkVersion min_sdk_version
targetSdkVersion target_sdk_version
versionCode version_code
versionName version_name
vectorDrawables.useSupportLibrary = true
}
buildTypes {
Expand All @@ -21,11 +21,11 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "com.android.support:appcompat-v7:$support_version"
implementation "com.android.support:design:$support_version"
implementation "com.android.support:support-vector-drawable:$support_version"
implementation "com.android.support:appcompat-v7:$android_support"
implementation "com.android.support:design:$android_support"
implementation "com.android.support:support-vector-drawable:$android_support"
implementation 'com.yanzhenjie:permission:2.0.0-rc4'
//implementation project(':zxinglibrary')
implementation project(':zxinglibrary')

implementation 'com.github.yuzhiqiang1993:zxing:2.1.6'
// implementation 'com.github.yuzhiqiang1993:zxing:2.1.6'
}
1 change: 1 addition & 0 deletions app/src/main/java/com/yzq/zxing/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public void onAction(List<String> permissions) {
ZxingConfig config = new ZxingConfig();
config.setPlayBeep(true);
config.setShake(true);
config.setDecodeBarCode(false);
intent.putExtra(Constant.INTENT_ZXING_CONFIG, config);

startActivityForResult(intent, REQUEST_CODE_SCAN);
Expand Down
19 changes: 15 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,27 @@
buildscript {


ext {
/*sdk and version*/
compile_sdk_version = 27
build_tools_version = '27.1.1'
min_sdk_version = 16
target_sdk_version = 27
constraint_version = '1.1.0'
version_code = 1_00_00
version_name = '1.0.0'// E.g 1.9.72 == 1,09,72

/*support*/
android_support = '27.1.1'

}

repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'com.android.tools.build:gradle:3.1.2'

classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
// NOTE: Do not place your application dependencies here; they belong
Expand All @@ -25,9 +39,6 @@ allprojects {
}
}

ext{
support_version='27.1.0'
}

task clean(type: Delete) {
delete rootProject.buildDir
Expand Down
21 changes: 9 additions & 12 deletions zxinglibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ apply plugin: 'com.github.dcendents.android-maven'
group = 'com.github.yuzhiqiang1993'

android {
compileSdkVersion 27
buildToolsVersion '27.0.3'

compileSdkVersion compile_sdk_version

defaultConfig {
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
minSdkVersion min_sdk_version
targetSdkVersion target_sdk_version
versionCode version_code
versionName version_name
vectorDrawables.useSupportLibrary = true

}


Expand All @@ -23,10 +20,10 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
api files('libs/core-3.3.0.jar')
implementation "com.android.support:appcompat-v7:$support_version"
implementation "com.android.support:design:$support_version"
implementation "com.android.support:support-v4:$support_version"
implementation "com.android.support:support-vector-drawable:$support_version"
implementation "com.android.support:appcompat-v7:$android_support"
implementation "com.android.support:design:$android_support"
implementation "com.android.support:support-v4:$android_support"
implementation "com.android.support:support-vector-drawable:$android_support"

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
public class CaptureActivity extends AppCompatActivity implements SurfaceHolder.Callback, View.OnClickListener {

private static final String TAG = CaptureActivity.class.getSimpleName();
private ZxingConfig config;
public ZxingConfig config;
private SurfaceView previewView;
private ViewfinderView viewfinderView;
private AppCompatImageView flashLightIv;
Expand Down Expand Up @@ -103,7 +103,7 @@ protected void onCreate(Bundle savedInstanceState) {
if (config == null) {
config = new ZxingConfig();
}


setContentView(R.layout.activity_capture);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,17 @@ public class ZxingConfig implements Serializable {
private boolean isShowFlashLight = true;
/*是否显示相册按钮*/
private boolean isShowAlbum = true;
/*是否解析条形码*/
private boolean isDecodeBarCode=true;


public boolean isDecodeBarCode() {
return isDecodeBarCode;
}

public void setDecodeBarCode(boolean decodeBarCode) {
isDecodeBarCode = decodeBarCode;
}

public boolean isPlayBeep() {
return isPlayBeep;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,76 +32,80 @@

public final class DecodeFormatManager {

private static final Pattern COMMA_PATTERN = Pattern.compile(",");
private static final Pattern COMMA_PATTERN = Pattern.compile(",");

public static final Set<BarcodeFormat> PRODUCT_FORMATS;
static final Set<BarcodeFormat> INDUSTRIAL_FORMATS;
static final Set<BarcodeFormat> ONE_D_FORMATS;
static final Set<BarcodeFormat> QR_CODE_FORMATS = EnumSet.of(BarcodeFormat.QR_CODE);
static final Set<BarcodeFormat> DATA_MATRIX_FORMATS = EnumSet.of(BarcodeFormat.DATA_MATRIX);
static final Set<BarcodeFormat> AZTEC_FORMATS = EnumSet.of(BarcodeFormat.AZTEC);
static final Set<BarcodeFormat> PDF417_FORMATS = EnumSet.of(BarcodeFormat.PDF_417);
static {
PRODUCT_FORMATS = EnumSet.of(BarcodeFormat.UPC_A,
BarcodeFormat.UPC_E,
BarcodeFormat.EAN_13,
BarcodeFormat.EAN_8,
BarcodeFormat.RSS_14,
BarcodeFormat.RSS_EXPANDED);
INDUSTRIAL_FORMATS = EnumSet.of(BarcodeFormat.CODE_39,
BarcodeFormat.CODE_93,
BarcodeFormat.CODE_128,
BarcodeFormat.ITF,
BarcodeFormat.CODABAR);
ONE_D_FORMATS = EnumSet.copyOf(PRODUCT_FORMATS);
ONE_D_FORMATS.addAll(INDUSTRIAL_FORMATS);
}
private static final Map<String,Set<BarcodeFormat>> FORMATS_FOR_MODE;
static {
FORMATS_FOR_MODE = new HashMap<String,Set<BarcodeFormat>>();
FORMATS_FOR_MODE.put(Intents.Scan.ONE_D_MODE, ONE_D_FORMATS);
FORMATS_FOR_MODE.put(Intents.Scan.PRODUCT_MODE, PRODUCT_FORMATS);
FORMATS_FOR_MODE.put(Intents.Scan.QR_CODE_MODE, QR_CODE_FORMATS);
FORMATS_FOR_MODE.put(Intents.Scan.DATA_MATRIX_MODE, DATA_MATRIX_FORMATS);
FORMATS_FOR_MODE.put(Intents.Scan.AZTEC_MODE, AZTEC_FORMATS);
FORMATS_FOR_MODE.put(Intents.Scan.PDF417_MODE, PDF417_FORMATS);
}
public static final Set<BarcodeFormat> PRODUCT_FORMATS;
static final Set<BarcodeFormat> INDUSTRIAL_FORMATS;
static final Set<BarcodeFormat> ONE_D_FORMATS;
static final Set<BarcodeFormat> QR_CODE_FORMATS = EnumSet.of(BarcodeFormat.QR_CODE);
static final Set<BarcodeFormat> DATA_MATRIX_FORMATS = EnumSet.of(BarcodeFormat.DATA_MATRIX);
static final Set<BarcodeFormat> AZTEC_FORMATS = EnumSet.of(BarcodeFormat.AZTEC);
static final Set<BarcodeFormat> PDF417_FORMATS = EnumSet.of(BarcodeFormat.PDF_417);

private DecodeFormatManager() {}
static {
PRODUCT_FORMATS = EnumSet.of(BarcodeFormat.UPC_A,
BarcodeFormat.UPC_E,
BarcodeFormat.EAN_13,
BarcodeFormat.EAN_8,
BarcodeFormat.RSS_14,
BarcodeFormat.RSS_EXPANDED);
INDUSTRIAL_FORMATS = EnumSet.of(BarcodeFormat.CODE_39,
BarcodeFormat.CODE_93,
BarcodeFormat.CODE_128,
BarcodeFormat.ITF,
BarcodeFormat.CODABAR);
ONE_D_FORMATS = EnumSet.copyOf(PRODUCT_FORMATS);
ONE_D_FORMATS.addAll(INDUSTRIAL_FORMATS);
}

private static final Map<String, Set<BarcodeFormat>> FORMATS_FOR_MODE;

static {
FORMATS_FOR_MODE = new HashMap<String, Set<BarcodeFormat>>();
FORMATS_FOR_MODE.put(Intents.Scan.ONE_D_MODE, ONE_D_FORMATS);
FORMATS_FOR_MODE.put(Intents.Scan.PRODUCT_MODE, PRODUCT_FORMATS);
FORMATS_FOR_MODE.put(Intents.Scan.QR_CODE_MODE, QR_CODE_FORMATS);
FORMATS_FOR_MODE.put(Intents.Scan.DATA_MATRIX_MODE, DATA_MATRIX_FORMATS);
FORMATS_FOR_MODE.put(Intents.Scan.AZTEC_MODE, AZTEC_FORMATS);
FORMATS_FOR_MODE.put(Intents.Scan.PDF417_MODE, PDF417_FORMATS);
}

public static Set<BarcodeFormat> parseDecodeFormats(Intent intent) {
Iterable<String> scanFormats = null;
CharSequence scanFormatsString = intent.getStringExtra(Intents.Scan.FORMATS);
if (scanFormatsString != null) {
scanFormats = Arrays.asList(COMMA_PATTERN.split(scanFormatsString));
private DecodeFormatManager() {
}
return parseDecodeFormats(scanFormats, intent.getStringExtra(Intents.Scan.MODE));
}

public static Set<BarcodeFormat> parseDecodeFormats(Uri inputUri) {
List<String> formats = inputUri.getQueryParameters(Intents.Scan.FORMATS);
if (formats != null && formats.size() == 1 && formats.get(0) != null){
formats = Arrays.asList(COMMA_PATTERN.split(formats.get(0)));
public static Set<BarcodeFormat> parseDecodeFormats(Intent intent) {
Iterable<String> scanFormats = null;
CharSequence scanFormatsString = intent.getStringExtra(Intents.Scan.FORMATS);
if (scanFormatsString != null) {
scanFormats = Arrays.asList(COMMA_PATTERN.split(scanFormatsString));
}
return parseDecodeFormats(scanFormats, intent.getStringExtra(Intents.Scan.MODE));
}
return parseDecodeFormats(formats, inputUri.getQueryParameter(Intents.Scan.MODE));
}

private static Set<BarcodeFormat> parseDecodeFormats(Iterable<String> scanFormats, String decodeMode) {
if (scanFormats != null) {
Set<BarcodeFormat> formats = EnumSet.noneOf(BarcodeFormat.class);
try {
for (String format : scanFormats) {
formats.add(BarcodeFormat.valueOf(format));
public static Set<BarcodeFormat> parseDecodeFormats(Uri inputUri) {
List<String> formats = inputUri.getQueryParameters(Intents.Scan.FORMATS);
if (formats != null && formats.size() == 1 && formats.get(0) != null) {
formats = Arrays.asList(COMMA_PATTERN.split(formats.get(0)));
}
return formats;
} catch (IllegalArgumentException iae) {
// ignore it then
}
return parseDecodeFormats(formats, inputUri.getQueryParameter(Intents.Scan.MODE));
}
if (decodeMode != null) {
return FORMATS_FOR_MODE.get(decodeMode);

private static Set<BarcodeFormat> parseDecodeFormats(Iterable<String> scanFormats, String decodeMode) {
if (scanFormats != null) {
Set<BarcodeFormat> formats = EnumSet.noneOf(BarcodeFormat.class);
try {
for (String format : scanFormats) {
formats.add(BarcodeFormat.valueOf(format));
}
return formats;
} catch (IllegalArgumentException iae) {
// ignore it then
}
}
if (decodeMode != null) {
return FORMATS_FOR_MODE.get(decodeMode);
}
return null;
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ private void decode(byte[] data, int width, int height) {

byte[] rotatedData = new byte[data.length];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
for (int x = 0; x < width; x++) {
rotatedData[x * height + height - y - 1] = data[x + y * width];
}
}
int tmp = width; // Here we are swapping, that's the difference to #11
width = height;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ public void run() {

options.inJustDecodeBounds = false; // 获取新的大小
int sampleSize = (int) (options.outHeight / (float) 400);
if (sampleSize <= 0)
if (sampleSize <= 0) {
sampleSize = 1;
}
options.inSampleSize = sampleSize;
scanBitmap = BitmapFactory.decodeFile(imgPath, options);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ public DecodeThread(CaptureActivity activity, ResultPointCallback resultPointCal

hints = new Hashtable<>();


decodeFormats = new Vector<BarcodeFormat>();
decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);


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

decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);
hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
Expand Down
Loading

0 comments on commit ee993ee

Please sign in to comment.