Finish keyboard_emulator_scanType
This commit is contained in:
commit
fa6892828a
@ -85,31 +85,51 @@ public class KeyboardEmulatorBarcodeReader implements BarcodeReaderInterface {
|
||||
}
|
||||
|
||||
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 patternUPCE1 = Pattern.compile("");
|
||||
Pattern patternEAN8 = Pattern.compile("^[0-9]{8}$");
|
||||
Pattern patternEAN13 = Pattern.compile("^[0-9]{13}$");
|
||||
Pattern patternCODE11 = Pattern.compile("");
|
||||
Pattern patternCODE39 = Pattern.compile("");
|
||||
if(){
|
||||
return BarcodeType.CODE11;
|
||||
}else if(){
|
||||
return BarcodeType.CODE39;
|
||||
}else if(){
|
||||
return BarcodeType.EAN13;
|
||||
}else if(){
|
||||
Pattern patternCODE39 = Pattern.compile("");*/
|
||||
if (barcode.length() == 8) {
|
||||
try {
|
||||
int checksum = getEanChecksum(barcode);
|
||||
if (checksum == Integer.parseInt(barcode.substring(7))){
|
||||
return BarcodeType.EAN8;
|
||||
}else if(){
|
||||
return BarcodeType.UPCA;
|
||||
}else if(){
|
||||
return BarcodeType.UPCE;
|
||||
}else if(false){
|
||||
return BarcodeType.UPCE1;
|
||||
}
|
||||
} catch (WrongFormatException e) {
|
||||
return BarcodeType.CODE128;
|
||||
}
|
||||
} else if (barcode.length() == 13) {
|
||||
try {
|
||||
int checksum = getEanChecksum(barcode);
|
||||
if (checksum == Integer.parseInt(barcode.substring(12))){
|
||||
return BarcodeType.EAN13;
|
||||
}
|
||||
} catch (WrongFormatException e) {
|
||||
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 {
|
||||
return BarcodeType.CODE128;
|
||||
}*/
|
||||
return BarcodeType.CODE128;
|
||||
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