aggiunta configurazione scanner barcode tramite preferenze app
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package it.integry.keyobardemulatorscannerlibrary;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Pair;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import it.integry.barcode_base_android_library.exception.BarcodeAdapterNotFoundException;
|
||||
import it.integry.barcode_base_android_library.extension.RunnableArgs;
|
||||
import it.integry.barcode_base_android_library.interfaces.BarcodeReaderInterface;
|
||||
@@ -91,7 +94,7 @@ public class KeyboardEmulatorBarcodeReader implements BarcodeReaderInterface {
|
||||
if (barcode.length() == 8) {
|
||||
try {
|
||||
int checksum = getEanChecksum(barcode);
|
||||
if (checksum == Integer.parseInt(barcode.substring(7))){
|
||||
if (checksum == Integer.parseInt(barcode.substring(7))) {
|
||||
return BarcodeType.EAN8;
|
||||
}
|
||||
} catch (WrongFormatException e) {
|
||||
@@ -100,7 +103,7 @@ public class KeyboardEmulatorBarcodeReader implements BarcodeReaderInterface {
|
||||
} else if (barcode.length() == 13) {
|
||||
try {
|
||||
int checksum = getEanChecksum(barcode);
|
||||
if (checksum == Integer.parseInt(barcode.substring(12))){
|
||||
if (checksum == Integer.parseInt(barcode.substring(12))) {
|
||||
return BarcodeType.EAN13;
|
||||
}
|
||||
} catch (WrongFormatException e) {
|
||||
@@ -109,7 +112,7 @@ public class KeyboardEmulatorBarcodeReader implements BarcodeReaderInterface {
|
||||
} else if (barcode.length() == 14) {
|
||||
try {
|
||||
int checksum = getEanChecksum(barcode);
|
||||
if (checksum == Integer.parseInt(barcode.substring(13))){
|
||||
if (checksum == Integer.parseInt(barcode.substring(13))) {
|
||||
return BarcodeType.INTERLEAVED_2OF5;
|
||||
}
|
||||
} catch (WrongFormatException e) {
|
||||
@@ -122,19 +125,24 @@ public class KeyboardEmulatorBarcodeReader implements BarcodeReaderInterface {
|
||||
private static int getEanChecksum(String barcode) throws WrongFormatException {
|
||||
int odds = 0;
|
||||
int evens = 0;
|
||||
barcode = barcode.substring(0,barcode.length()-1);
|
||||
barcode = barcode.substring(0, barcode.length() - 1);
|
||||
int pos = 0;
|
||||
for (int i = barcode.length() -1; i >=0 ; i--) {
|
||||
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)+"");
|
||||
evens += Integer.parseInt(barcode.charAt(i) + "");
|
||||
} else {
|
||||
odds += Integer.parseInt(barcode.charAt(i)+"");
|
||||
odds += Integer.parseInt(barcode.charAt(i) + "");
|
||||
}
|
||||
}
|
||||
return ((10 - (((3 * odds) + evens) % 10)) % 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeSettings(List<Pair<String, Object>> settings) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user