Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
commit
8124382b8b
@ -17,8 +17,8 @@ apply plugin: 'com.google.gms.google-services'
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
|
|
||||||
def appVersionCode = 112
|
def appVersionCode = 113
|
||||||
def appVersionName = '1.10.9'
|
def appVersionName = '1.10.10'
|
||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
release {
|
release {
|
||||||
|
|||||||
@ -55,28 +55,28 @@ public class KeyboardEmulatorBarcodeReader implements BarcodeReaderInterface {
|
|||||||
@Override
|
@Override
|
||||||
public void onKeyEvent(KeyEvent keyEvent) {
|
public void onKeyEvent(KeyEvent keyEvent) {
|
||||||
|
|
||||||
if (keyEvent.getEventTime() - mLastCharInsertTime > 500){
|
if (keyEvent.getEventTime() - mLastCharInsertTime > 500) {
|
||||||
mLastCharInsertTime =keyEvent.getEventTime();
|
mLastCharInsertTime = keyEvent.getEventTime();
|
||||||
mTextBarcode = "";
|
mTextBarcode = "";
|
||||||
}
|
}
|
||||||
if (keyEvent.getKeyCode() != KeyEvent.KEYCODE_ENTER){
|
if (keyEvent.getKeyCode() != KeyEvent.KEYCODE_ENTER) {
|
||||||
if (keyEvent.getKeyCode() != KeyEvent.KEYCODE_SHIFT_LEFT){
|
if (keyEvent.getKeyCode() != KeyEvent.KEYCODE_SHIFT_LEFT) {
|
||||||
mLastCharInsertTime =keyEvent.getEventTime();
|
mLastCharInsertTime = keyEvent.getEventTime();
|
||||||
if (keyEvent.getUnicodeChar() > 0){
|
if (keyEvent.getUnicodeChar() > 0) {
|
||||||
mTextBarcode+= (char) keyEvent.getUnicodeChar();
|
mTextBarcode += (char) keyEvent.getUnicodeChar();
|
||||||
}else if (keyEvent.getCharacters() != null){
|
} else if (keyEvent.getCharacters() != null) {
|
||||||
mTextBarcode = keyEvent.getCharacters();
|
mTextBarcode = keyEvent.getCharacters();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
if (mTextBarcode.length() > 0){
|
if (mTextBarcode.length() > 0) {
|
||||||
|
|
||||||
BarcodeType barcodeType = decodeBarcode(mTextBarcode);
|
BarcodeType barcodeType = decodeBarcode(mTextBarcode);
|
||||||
BarcodeScanDTO barcodeScanDTO = new BarcodeScanDTO()
|
BarcodeScanDTO barcodeScanDTO = new BarcodeScanDTO()
|
||||||
.setByteValue(mTextBarcode.getBytes())
|
.setByteValue(mTextBarcode.getBytes())
|
||||||
.setStringValue(mTextBarcode)
|
.setStringValue(mTextBarcode)
|
||||||
.setType(barcodeType)
|
.setType(barcodeType)
|
||||||
.setName(barcodeType != null ? barcodeType.toString():"");
|
.setName(barcodeType != null ? barcodeType.toString() : "");
|
||||||
|
|
||||||
mOnScanSuccessfull.run(barcodeScanDTO);
|
mOnScanSuccessfull.run(barcodeScanDTO);
|
||||||
}
|
}
|
||||||
@ -84,32 +84,52 @@ public class KeyboardEmulatorBarcodeReader implements BarcodeReaderInterface {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BarcodeType decodeBarcode(String barcode){
|
public BarcodeType decodeBarcode(String barcode) {
|
||||||
/*
|
/*Pattern patternUPCA = Pattern.compile("^[0-9]{12}$");
|
||||||
Pattern patternUPCA = Pattern.compile("^[0-9]{12}$");
|
|
||||||
Pattern patternUPCE = Pattern.compile("^[0-1][0-9]{7}$");
|
Pattern patternUPCE = Pattern.compile("^[0-1][0-9]{7}$");
|
||||||
Pattern patternUPCE1 = Pattern.compile("");
|
Pattern patternUPCE1 = Pattern.compile("");
|
||||||
Pattern patternEAN8 = Pattern.compile("^[0-9]{8}$");
|
Pattern patternEAN8 = Pattern.compile("^[0-9]{8}$");
|
||||||
Pattern patternEAN13 = Pattern.compile("^[0-9]{13}$");
|
Pattern patternEAN13 = Pattern.compile("^[0-9]{13}$");
|
||||||
Pattern patternCODE11 = Pattern.compile("");
|
Pattern patternCODE11 = Pattern.compile("");
|
||||||
Pattern patternCODE39 = Pattern.compile("");
|
Pattern patternCODE39 = Pattern.compile("");*/
|
||||||
if(){
|
if (barcode.length() == 8) {
|
||||||
return BarcodeType.CODE11;
|
try {
|
||||||
}else if(){
|
int checksum = getEanChecksum(barcode);
|
||||||
return BarcodeType.CODE39;
|
if (checksum == Integer.parseInt(barcode.substring(7))){
|
||||||
}else if(){
|
return BarcodeType.EAN8;
|
||||||
return BarcodeType.EAN13;
|
}
|
||||||
}else if(){
|
} catch (WrongFormatException e) {
|
||||||
return BarcodeType.EAN8;
|
return BarcodeType.CODE128;
|
||||||
}else if(){
|
}
|
||||||
return BarcodeType.UPCA;
|
} else if (barcode.length() == 13) {
|
||||||
}else if(){
|
try {
|
||||||
return BarcodeType.UPCE;
|
int checksum = getEanChecksum(barcode);
|
||||||
}else if(false){
|
if (checksum == Integer.parseInt(barcode.substring(12))){
|
||||||
return BarcodeType.UPCE1;
|
return BarcodeType.EAN13;
|
||||||
}else{
|
}
|
||||||
return BarcodeType.CODE128;
|
} catch (WrongFormatException e) {
|
||||||
}*/
|
return BarcodeType.CODE128;
|
||||||
|
}
|
||||||
|
}
|
||||||
return BarcodeType.CODE128;
|
return BarcodeType.CODE128;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int getEanChecksum(String barcode) throws WrongFormatException {
|
||||||
|
int odds = 0;
|
||||||
|
int evens = 0;
|
||||||
|
barcode = barcode.substring(0,barcode.length()-1);
|
||||||
|
int pos = 0;
|
||||||
|
for (int i = barcode.length() -1; i >=0 ; i--) {
|
||||||
|
pos++;
|
||||||
|
if (!Character.isDigit(barcode.charAt(i))) {
|
||||||
|
throw new WrongFormatException();
|
||||||
|
}
|
||||||
|
if (pos % 2 == 0) {
|
||||||
|
evens += Integer.parseInt(barcode.charAt(i)+"");
|
||||||
|
} else {
|
||||||
|
odds += Integer.parseInt(barcode.charAt(i)+"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ((10 - (((3 * odds) + evens) % 10)) % 10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,4 @@
|
|||||||
|
package it.integry.keyobardemulatorscannerlibrary;
|
||||||
|
|
||||||
|
public class WrongFormatException extends Exception {
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user