Implementata libreria di lettura di Zebra.
This commit is contained in:
1
zebrascannerlibrary/.gitignore
vendored
Normal file
1
zebrascannerlibrary/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
||||
35
zebrascannerlibrary/build.gradle
Normal file
35
zebrascannerlibrary/build.gradle
Normal file
@@ -0,0 +1,35 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 28
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
implementation 'androidx.appcompat:appcompat:1.0.2'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test:runner:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
|
||||
implementation project(path: ':barcode_base_library')
|
||||
}
|
||||
21
zebrascannerlibrary/proguard-rules.pro
vendored
Normal file
21
zebrascannerlibrary/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
@@ -0,0 +1,27 @@
|
||||
package it.integry.zebrascannerlibrary;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||
|
||||
assertEquals("it.integry.zebrascannerlibrary.test", appContext.getPackageName());
|
||||
}
|
||||
}
|
||||
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>
|
||||
@@ -0,0 +1,17 @@
|
||||
package it.integry.zebrascannerlibrary;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user