Implementata libreria di lettura di Zebra.
This commit is contained in:
2
zebrascannerlibrary/src/main/AndroidManifest.xml
Normal file
2
zebrascannerlibrary/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,2 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="it.integry.zebrascannerlibrary" />
|
||||
@@ -0,0 +1,101 @@
|
||||
package it.integry.zebrascannerlibrary;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Build;
|
||||
|
||||
import it.integry.plugins.barcode_base_library.exception.BarcodeAdapterNotFoundException;
|
||||
import it.integry.plugins.barcode_base_library.extension.RunnableArgs;
|
||||
import it.integry.plugins.barcode_base_library.interfaces.BarcodeReaderInterface;
|
||||
import it.integry.plugins.barcode_base_library.model.BarcodeScanDTO;
|
||||
|
||||
public class ZebraBarcodeReader implements BarcodeReaderInterface {
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
private static RunnableArgs<BarcodeScanDTO> mOnScanSuccessfull;
|
||||
private static RunnableArgs<Exception> mOnScanFailed;
|
||||
|
||||
private static final String TAG = ZebraBarcodeReader.class.getName();
|
||||
private static final String INTENT_FILTER_STRING = "it.integry.scan_filter";
|
||||
|
||||
public ZebraBarcodeReader(Context context) {
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRightAdapter() {
|
||||
String model = Build.MODEL;
|
||||
if(model.equalsIgnoreCase("TC700H")) {
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws BarcodeAdapterNotFoundException {
|
||||
if(isRightAdapter()) {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addCategory(Intent.CATEGORY_DEFAULT);
|
||||
filter.addAction(INTENT_FILTER_STRING);
|
||||
mContext.registerReceiver(myBroadcastReceiver, filter);
|
||||
} else {
|
||||
throw new BarcodeAdapterNotFoundException(getAdapterName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deinit() {
|
||||
mContext.unregisterReceiver(myBroadcastReceiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(RunnableArgs<BarcodeScanDTO> onScanSuccessfull, RunnableArgs<Exception> onScanFailed) {
|
||||
mOnScanSuccessfull = onScanSuccessfull;
|
||||
mOnScanFailed = onScanFailed;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getAdapterName() {
|
||||
return "Zebra";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private BroadcastReceiver myBroadcastReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
|
||||
if (action.equals(INTENT_FILTER_STRING)) {
|
||||
try {
|
||||
dispatchEvent(intent);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private void dispatchEvent(Intent initiatingIntent)
|
||||
{
|
||||
|
||||
String decodedSource = initiatingIntent.getStringExtra(mContext.getResources().getString(R.string.datawedge_intent_key_source));
|
||||
String decodedData = initiatingIntent.getStringExtra(mContext.getResources().getString(R.string.datawedge_intent_key_data));
|
||||
String decodedLabelType = initiatingIntent.getStringExtra(mContext.getResources().getString(R.string.datawedge_intent_key_label_type));
|
||||
|
||||
BarcodeScanDTO barcodeScanDTO = new BarcodeScanDTO()
|
||||
.setByteValue(decodedData.getBytes())
|
||||
.setStringValue(decodedData)
|
||||
.setType(ZebraBarcodeTypeMapper.map(decodedLabelType))
|
||||
.setName(decodedLabelType);
|
||||
// .setDecodingTime(mDecodeResult.decodeTimeMillisecond);
|
||||
|
||||
mOnScanSuccessfull.run(barcodeScanDTO);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package it.integry.zebrascannerlibrary;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import it.integry.plugins.barcode_base_library.model.BarcodeType;
|
||||
|
||||
public class ZebraBarcodeTypeMapper {
|
||||
|
||||
|
||||
public static BarcodeType map(String inputType) {
|
||||
|
||||
switch (inputType) {
|
||||
case "LABEL-TYPE-CODE11":
|
||||
return BarcodeType.CODE11;
|
||||
case "LABEL-TYPE-CODE128":
|
||||
return BarcodeType.CODE128;
|
||||
case "LABEL-TYPE-CODE39":
|
||||
return BarcodeType.CODE39;
|
||||
|
||||
case "LABEL-TYPE-EAN13":
|
||||
return BarcodeType.EAN13;
|
||||
case "LABEL-TYPE-EAN8":
|
||||
return BarcodeType.EAN8;
|
||||
|
||||
case "LABEL-TYPE-UPCA":
|
||||
return BarcodeType.UPCA;
|
||||
case "LABEL-TYPE-UPCE0":
|
||||
return BarcodeType.UPCE;
|
||||
case "LABEL-TYPE-UPCE1":
|
||||
return BarcodeType.UPCE1;
|
||||
default:
|
||||
Log.d("SCAN TYPE", inputType);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
7
zebrascannerlibrary/src/main/res/values/strings.xml
Normal file
7
zebrascannerlibrary/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<resources>
|
||||
<string name="app_name">Zebra ScannerLibrary</string>
|
||||
|
||||
<string name="datawedge_intent_key_source">com.symbol.datawedge.source</string>
|
||||
<string name="datawedge_intent_key_label_type">com.symbol.datawedge.label_type</string>
|
||||
<string name="datawedge_intent_key_data">com.symbol.datawedge.data_string</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user