aggiunta configurazione scanner barcode tramite preferenze app

This commit is contained in:
2022-09-26 11:52:24 +02:00
parent f8c0852cb7
commit 0e6f4a7892
18 changed files with 300 additions and 77 deletions

View File

@@ -2,6 +2,7 @@ package it.integry.honeywellscannerlibrary;
import android.content.Context;
import android.os.Build;
import android.util.Pair;
import android.view.KeyEvent;
import com.honeywell.aidc.AidcManager;
@@ -19,6 +20,7 @@ import it.integry.barcode_base_android_library.exception.BarcodeAdapterNotFoundE
import it.integry.barcode_base_android_library.extension.RunnableArgs;
import it.integry.barcode_base_android_library.interfaces.BarcodeReaderInterface;
import it.integry.barcode_base_android_library.model.BarcodeScanDTO;
import it.integry.barcode_base_android_library.model.BarcodeSetting;
public class HoneyWellBarcodeReader implements BarcodeReaderInterface {
@@ -43,24 +45,23 @@ public class HoneyWellBarcodeReader implements BarcodeReaderInterface {
compatibleModels.add("EDA51");
compatibleModels.add("CT60");
if(compatibleModels.contains(model)) {
if (compatibleModels.contains(model)) {
return true;
} else return false;
}
@Override
public void init(final Runnable onDeviceReady) throws BarcodeAdapterNotFoundException {
if(isRightAdapter()) {
if (isRightAdapter()) {
AidcManager.create(mContext, aidcManager -> {
manager = aidcManager;
try{
try {
barcodeReader = manager.createBarcodeReader();
registerListenersInternal();
}
catch (Exception e){
} catch (Exception e) {
// throw new Exception("Invalid Scanner Name Exception: " + e.getMessage());
}
@@ -129,7 +130,24 @@ public class HoneyWellBarcodeReader implements BarcodeReaderInterface {
// } catch (UnsupportedPropertyException e) {
// throw new Exception("Failed to apply properties");
// }
}
private void dispatchEvent(BarcodeReadEvent barcodeReadEvent) {
// mContext.runOnUiThread(() -> {
BarcodeScanDTO barcodeScanDTO = new BarcodeScanDTO()
.setByteValue(barcodeReadEvent.getBarcodeData().getBytes())
.setStringValue(barcodeReadEvent.getBarcodeData())
.setType(HoneywellBarcodeTypeMapper.map(barcodeReadEvent.getCodeId()))
.setName(HoneywellBarcodeTypeMapper.map(barcodeReadEvent.getCodeId()).toString());
mOnScanSuccessfull.run(barcodeScanDTO);
// });
}
private Map<String, Object> getDefaultProperties() {
Map<String, Object> properties = new HashMap<>();
// Set Symbologies On/Off
@@ -145,33 +163,53 @@ public class HoneyWellBarcodeReader implements BarcodeReaderInterface {
properties.put(BarcodeReader.PROPERTY_EAN_13_CHECK_DIGIT_TRANSMIT_ENABLED, true);
properties.put(BarcodeReader.PROPERTY_UPC_A_CHECK_DIGIT_TRANSMIT_ENABLED, true);
properties.put(BarcodeReader.PROPERTY_TRIGGER_SCAN_MODE, BarcodeReader.TRIGGER_SCAN_MODE_READ_ON_RELEASE);
return properties;
}
@Override
public void changeSettings(List<Pair<String, Object>> settings) {
Map<String, Object> properties = getDefaultProperties();
String scanValue;
for (Pair<String, Object> setting : settings) {
switch (setting.first) {
case BarcodeSetting.P_TRIGGER_SCAN_MODE:
scanValue = setting.second != null ? (String) setting.second : "";
String scanMode;
switch (scanValue) {
case BarcodeSetting.V_TRIGGER_SCAN_MODE_ONE_SHOT:
scanMode = BarcodeReader.TRIGGER_SCAN_MODE_ONESHOT;
break;
case BarcodeSetting.V_TRIGGER_SCAN_MODE_CONTINUOS:
scanMode = BarcodeReader.TRIGGER_SCAN_MODE_CONTINUOUS;
break;
case BarcodeSetting.V_TRIGGER_SCAN_MODE_READ_ON_SECOND_TRIGGER_PRESS:
scanMode = BarcodeReader.TRIGGER_SCAN_MODE_READ_ON_SECOND_TRIGGER_PRESS;
break;
case BarcodeSetting.V_TRIGGER_SCAN_MODE_READ_ON_RELEASE:
scanMode = BarcodeReader.TRIGGER_SCAN_MODE_READ_ON_RELEASE;
break;
default:
scanMode = BarcodeReader.TRIGGER_SCAN_MODE_ONESHOT;
}
properties.put(BarcodeReader.PROPERTY_TRIGGER_SCAN_MODE, scanMode);
break;
case BarcodeSetting.P_TRIGGER_SCAN_DELAY:
scanValue = setting.second != null ? (String) setting.second : "0";
properties.put(BarcodeReader.PROPERTY_TRIGGER_SCAN_DELAY, Integer.parseInt(scanValue));
break;
}
}
// properties.put(BarcodeReader.PROPERTY_TRIGGER_SCAN_DELAY, 500);
// properties.put(BarcodeReader.PROPERTY_TRIGGER_SCAN_MODE, BarcodeReader.TRIGGER_SCAN_MODE_READ_ON_SECOND_TRIGGER_PRESS);
// Apply the settings
barcodeReader.setProperties(properties);
try {
barcodeReader.claim();
} catch (ScannerUnavailableException e) {
e.printStackTrace();
}
}
private void dispatchEvent(BarcodeReadEvent barcodeReadEvent)
{
// mContext.runOnUiThread(() -> {
BarcodeScanDTO barcodeScanDTO = new BarcodeScanDTO()
.setByteValue(barcodeReadEvent.getBarcodeData().getBytes())
.setStringValue(barcodeReadEvent.getBarcodeData())
.setType(HoneywellBarcodeTypeMapper.map(barcodeReadEvent.getCodeId()))
.setName(HoneywellBarcodeTypeMapper.map(barcodeReadEvent.getCodeId()).toString());
mOnScanSuccessfull.run(barcodeScanDTO);
// });
}
}