Implementata lettura barcode in Accettazione
This commit is contained in:
@@ -1,2 +1,25 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="it.integry.pointmobilescannerlibrary" />
|
||||
package="it.integry.pointmobilescannerlibrary">
|
||||
|
||||
|
||||
<permission
|
||||
android:name="it.integry.pointmobilescannerlibrary.permission.SCANNER_RESULT_RECEIVER"
|
||||
android:protectionLevel="normal" />
|
||||
|
||||
<uses-permission android:name="it.integry.pointmobilescannerlibrary.permission.SCANNER_RESULT_RECEIVER" />
|
||||
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
|
||||
|
||||
<application>
|
||||
<receiver
|
||||
android:name="it.integry.pointmobilescannerlibrary.PointMobileBarcodeReader$ScanResultReceiver"
|
||||
android:enabled="true"
|
||||
android:permission="it.integry.pointmobilescannerlibrary.permission.SCANNER_RESULT_RECEIVER"
|
||||
android:priority="0" >
|
||||
<intent-filter>
|
||||
<action android:name="device.common.USERMSG" />
|
||||
<action android:name="device.scanner.EVENT" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
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 {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user