Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新了zxing依赖库, 移除了对汉信码的支持, 增加属性decodeFormats 可配置扫描条码格式 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed doExt_do_BarcodeView/libs/do_zxing.jar
Binary file not shown.
Binary file removed doExt_do_BarcodeView/libs/hxcode.jar
Binary file not shown.
Binary file added doExt_do_BarcodeView/libs/zxing-3.3.3.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ public void onInit() throws Exception{
super.onInit();
//注册属性
this.registProperty(new DoProperty("scanArea", PropertyDataType.String, "", false));
this.registProperty(new DoProperty("decodeFormats", PropertyDataType.String, "", false));
}
}
43 changes: 37 additions & 6 deletions doExt_do_BarcodeView/src/doext/implement/do_BarcodeView_View.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,39 @@ public void onPropertiesChanged(Map<String, String> _changedValues) {
CameraManager.get().setRect(rect);
}
}
}else if (_changedValues.containsKey("decodeFormats")) {
String _decodeFormats = _changedValues.get("decodeFormats");
decodeFormats = null;
if (null != _decodeFormats && !"".equals(_decodeFormats)) {
String[] _formats = _decodeFormats.split(",");
if (null != _formats && _formats.length > 0) {
for (int i = 0; i < _formats.length; i++) {
switch(_formats[i]){
case "CODE_128": addFormats(BarcodeFormat.CODE_128);; break;
case "UPC_A": addFormats(BarcodeFormat.CODE_128);; break;
case "UPC_E": addFormats(BarcodeFormat.CODE_128);; break;
case "EAN_13": addFormats(BarcodeFormat.CODE_128);; break;
case "EAN_8": addFormats(BarcodeFormat.CODE_128);; break;
case "RSS_14": addFormats(BarcodeFormat.CODE_128);; break;
case "CODE_39": addFormats(BarcodeFormat.CODE_128);; break;
case "CODE_93": addFormats(BarcodeFormat.CODE_128);; break;
case "ITF": addFormats(BarcodeFormat.CODE_128);; break;
case "QR_CODE": addFormats(BarcodeFormat.CODE_128);; break;
case "DATA_MATRIX": addFormats(BarcodeFormat.CODE_128);; break;
}
}
}
}
}
}
private void addFormats(BarcodeFormat fmt){
if(null == decodeFormats){
decodeFormats = new Vector<BarcodeFormat>(1);
decodeFormats.add(fmt);
}else{
decodeFormats.addElement(fmt);
}

}

/**
* 同步方法,JS脚本调用该组件对象方法时会被调用,可以根据_methodName调用相应的接口实现方法;
*
Expand Down Expand Up @@ -241,8 +270,9 @@ public void start(JSONObject _dictParas, DoIScriptEngine _scriptEngine, String _
this.scriptEngine = _scriptEngine;
this.callbackFuncName = _callbackFuncName;
if (null != handler) {
handler.init(); // 启动线程解码
} else {
handler.init();
}else{
handler = new CaptureActivityHandler(this, decodeFormats, characterSet);
isStart = true;
}

Expand Down Expand Up @@ -359,8 +389,9 @@ public void onResume() {
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
decodeFormats = null;
characterSet = null;
// 如果要多次扫描就不能重置这两个参数
// decodeFormats = null;
// characterSet = null;
}

private void initCamera(SurfaceHolder surfaceHolder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
import com.google.zxing.ReaderException;
import com.google.zxing.Result;
import com.google.zxing.common.HybridBinarizer;
import com.hxcode.HxDecode;
// 移除汉信码
// import com.hxcode.HxDecode;

import doext.implement.do_BarcodeView_View;
import doext.zxing.barcodeview.camera.BracodeConstant;
Expand Down Expand Up @@ -75,25 +76,26 @@ public void handleMessage(Message message) {
*/
private void decode(byte[] data, int width, int height) {
Result rawResult = null;
//移除汉信码
//汉信码
HxDecode hxDecode = new HxDecode();
byte[] imgbytes = new byte[width * height];
int iwidth = hxDecode.preprocessImg(data, width, height, imgbytes);
if (iwidth > 0 && imgbytes != null) {
byte[] decodebytes = new byte[4 * 1024];
iwidth = hxDecode.DeCodeCsbyte(imgbytes, iwidth, decodebytes);
if (iwidth > 0) {
try {
if (isUTF8(decodebytes, 0, iwidth)) {
rawResult = new Result(new String(decodebytes, 0, iwidth, "UTF-8"), imgbytes, null, BarcodeFormat.HX_CODE);
} else {
rawResult = new Result(new String(decodebytes, 0, iwidth, "GBK"), imgbytes, null, BarcodeFormat.HX_CODE);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
// HxDecode hxDecode = new HxDecode();
// byte[] imgbytes = new byte[width * height];
// int iwidth = hxDecode.preprocessImg(data, width, height, imgbytes);
// if (iwidth > 0 && imgbytes != null) {
// byte[] decodebytes = new byte[4 * 1024];
// iwidth = hxDecode.DeCodeCsbyte(imgbytes, iwidth, decodebytes);
// if (iwidth > 0) {
// try {
// if (isUTF8(decodebytes, 0, iwidth)) {
// rawResult = new Result(new String(decodebytes, 0, iwidth, "UTF-8"), imgbytes, null, BarcodeFormat.HX_CODE);
// } else {
// rawResult = new Result(new String(decodebytes, 0, iwidth, "GBK"), imgbytes, null, BarcodeFormat.HX_CODE);
// }
// } catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// }
// }
// }
if (rawResult == null) {
//modify here
byte[] rotatedData = new byte[data.length];
Expand Down Expand Up @@ -124,137 +126,4 @@ private void decode(byte[] data, int width, int height) {
message.sendToTarget();
}
}

private boolean isUTF8(byte[] data, int start, int end) {
boolean canBeUTF8 = true;
for (int i = start; i < end; i++) {
int value = data[i] & 0xFF;

//两字节情况
if (value >= 0xC0 && value <= 0xDF) {
i++;
value = data[i] & 0xFF;
if (value >= 0x80 && value <= 0xBF) {

} else {
return false;
}
} else if (value >= 0xE0 && value <= 0xEF) { //三字节情况
i++;
value = data[i] & 0xFF;
if (value >= 0x80 && value <= 0xBF) {

} else {
return false;
}

i++;
value = data[i] & 0xFF;
if (value >= 0x80 && value <= 0xBF) {

} else {
return false;
}
} else if (value >= 0xF0 && value <= 0xF7) { //四字节情况
i++;
value = data[i] & 0xFF;
if (value >= 0x80 && value <= 0xBF) {

} else {
return false;
}

i++;
value = data[i] & 0xFF;
if (value >= 0x80 && value <= 0xBF) {

} else {
return false;
}

i++;
value = data[i] & 0xFF;
if (value >= 0x80 && value <= 0xBF) {

} else {
return false;
}
} else if (value >= 0xF8 && value <= 0xFB) { //五字节情况
i++;
value = data[i] & 0xFF;
if (value >= 0x80 && value <= 0xBF) {

} else {
return false;
}

i++;
value = data[i] & 0xFF;
if (value >= 0x80 && value <= 0xBF) {

} else {
return false;
}

i++;
value = data[i] & 0xFF;
if (value >= 0x80 && value <= 0xBF) {

} else {
return false;
}

i++;
value = data[i] & 0xFF;
if (value >= 0x80 && value <= 0xBF) {

} else {
return false;
}
} else if (value >= 0xFC && value <= 0xFD) { //六字节情况
i++;
value = data[i] & 0xFF;
if (value >= 0x80 && value <= 0xBF) {

} else {
return false;
}

i++;
value = data[i] & 0xFF;
if (value >= 0x80 && value <= 0xBF) {

} else {
return false;
}

i++;
value = data[i] & 0xFF;
if (value >= 0x80 && value <= 0xBF) {

} else {
return false;
}

i++;
value = data[i] & 0xFF;
if (value >= 0x80 && value <= 0xBF) {

} else {
return false;
}

i++;
value = data[i] & 0xFF;
if (value >= 0x80 && value <= 0xBF) {

} else {
return false;
}
}

}
return canBeUTF8;
}

}