104 lines
3.5 KiB
Java
104 lines
3.5 KiB
Java
package it.integry.pointmobilescannerlibrary;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.util.Log;
|
|
|
|
import device.common.DecodeResult;
|
|
import device.common.ScanConst;
|
|
import device.sdk.ScanManager;
|
|
import it.integry.plugins.barcode_base_library.exception.BarcodeAdapterNotFoundException;
|
|
import it.integry.plugins.barcode_base_library.interfaces.BarcodeReaderInterface;
|
|
import it.integry.plugins.barcode_base_library.model.BarcodeScanDTO;
|
|
import it.integry.plugins.barcode_base_library.extension.RunnableArgs;
|
|
import it.integry.plugins.barcode_base_library.model.BarcodeType;
|
|
|
|
public class PointMobileBarcodeReader implements BarcodeReaderInterface {
|
|
|
|
private Context mContext;
|
|
private static ScanManager mScanManager;
|
|
private static DecodeResult mDecodeResult;
|
|
|
|
private static RunnableArgs<BarcodeScanDTO> mOnScanSuccessfull;
|
|
private static RunnableArgs<Exception> mOnScanFailed;
|
|
|
|
private static String TAG = PointMobileBarcodeReader.class.getName();
|
|
|
|
|
|
private int mBackupResultType = ScanConst.ResultType.DCD_RESULT_COPYPASTE;
|
|
|
|
public PointMobileBarcodeReader(Context context) {
|
|
this.mContext = context;
|
|
|
|
mScanManager = new ScanManager();
|
|
mDecodeResult = new DecodeResult();
|
|
}
|
|
|
|
@Override
|
|
public boolean isRightAdapter() {
|
|
return mScanManager != null;
|
|
}
|
|
|
|
@Override
|
|
public void init() throws BarcodeAdapterNotFoundException {
|
|
if(isRightAdapter()){
|
|
mBackupResultType = mScanManager.aDecodeGetResultType();
|
|
mScanManager.aDecodeSetResultType(ScanConst.ResultType.DCD_RESULT_USERMSG);
|
|
} else {
|
|
throw new BarcodeAdapterNotFoundException(getAdapterName());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void register(RunnableArgs<BarcodeScanDTO> onScanSuccessfull, RunnableArgs<Exception> onScanFailed) {
|
|
mOnScanSuccessfull = onScanSuccessfull;
|
|
mOnScanFailed = onScanFailed;
|
|
}
|
|
|
|
@Override
|
|
public String getAdapterName() {
|
|
return "PointMobile";
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static class ScanResultReceiver extends BroadcastReceiver {
|
|
@Override
|
|
public void onReceive(Context context, Intent intent) {
|
|
if (mScanManager != null) {
|
|
if (ScanConst.INTENT_USERMSG.equals(intent.getAction())) {
|
|
mScanManager.aDecodeGetResult(mDecodeResult.recycle());
|
|
|
|
if (mOnScanSuccessfull != null) {
|
|
|
|
try {
|
|
if(mDecodeResult.symName.equalsIgnoreCase("READ_FAIL")){
|
|
throw new Exception("Barcode non riconosciuto");
|
|
}
|
|
|
|
BarcodeScanDTO barcodeScanDTO = new BarcodeScanDTO()
|
|
.setByteValue(mDecodeResult.decodeValue)
|
|
.setStringValue(mDecodeResult.toString().replaceAll("\n", "").replaceAll("\r", "").trim())
|
|
.setType(BarcodeType.fromInt(mDecodeResult.symType))
|
|
.setName(mDecodeResult.symName)
|
|
.setDecodingTime(mDecodeResult.decodeTimeMillisecond);
|
|
|
|
mOnScanSuccessfull.run(barcodeScanDTO);
|
|
|
|
} catch (Exception ex) {
|
|
Log.e(TAG, ex.getMessage());
|
|
|
|
if(mOnScanFailed != null) mOnScanFailed.run(ex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|