[SAPORI VERI]
- libreria scanner in emulazione di tastiera - nuova libreria dinamica per sapori veri per gestire gli ordini d'acquisto dai punti vendita
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package it.integry.keyobardemulatorscannerlibrary;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.ext.junit.runners.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.getInstrumentation().getTargetContext();
|
||||
|
||||
assertEquals("it.integry.keyobardemulatorscannerlibrary.test", appContext.getPackageName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="it.integry.keyobardemulatorscannerlibrary" />
|
||||
@@ -0,0 +1,111 @@
|
||||
package it.integry.keyobardemulatorscannerlibrary;
|
||||
|
||||
import android.view.KeyCharacterMap;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import it.integry.barcode_base_android_library.exception.BarcodeAdapterNotFoundException;
|
||||
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.BarcodeType;
|
||||
|
||||
public class KeyboardEmulatorBarcodeReader implements BarcodeReaderInterface {
|
||||
|
||||
private String barcode;
|
||||
private RunnableArgs<BarcodeScanDTO> mOnScanSuccessfull;
|
||||
private RunnableArgs<Exception> mOnScanFailed;
|
||||
private String mTextBarcode = "";
|
||||
private long mLastCharInsertTime = 0;
|
||||
|
||||
|
||||
public KeyboardEmulatorBarcodeReader(AppCompatActivity context) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRightAdapter() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Runnable onDeviceReady) throws BarcodeAdapterNotFoundException {
|
||||
onDeviceReady.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deinit() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(RunnableArgs<BarcodeScanDTO> onScanSuccessfull, RunnableArgs<Exception> onScanFailed) {
|
||||
mOnScanSuccessfull = onScanSuccessfull;
|
||||
mOnScanFailed = onScanFailed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAdapterName() {
|
||||
return "KeyboardEmulator";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyEvent(KeyEvent keyEvent) {
|
||||
|
||||
if (keyEvent.getEventTime() - mLastCharInsertTime > 500){
|
||||
mLastCharInsertTime =keyEvent.getEventTime();
|
||||
mTextBarcode = "";
|
||||
}
|
||||
if (keyEvent.getKeyCode() != KeyEvent.KEYCODE_ENTER){
|
||||
if (keyEvent.getKeyCode() != KeyEvent.KEYCODE_SHIFT_LEFT){
|
||||
mLastCharInsertTime =keyEvent.getEventTime();
|
||||
mTextBarcode+= (char) keyEvent.getUnicodeChar();
|
||||
}
|
||||
}else{
|
||||
if (mTextBarcode.length() > 0){
|
||||
|
||||
BarcodeType barcodeType = decodeBarcode(mTextBarcode);
|
||||
BarcodeScanDTO barcodeScanDTO = new BarcodeScanDTO()
|
||||
.setByteValue(mTextBarcode.getBytes())
|
||||
.setStringValue(mTextBarcode)
|
||||
.setType(barcodeType)
|
||||
.setName(barcodeType != null ? barcodeType.toString():"");
|
||||
|
||||
mOnScanSuccessfull.run(barcodeScanDTO);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public BarcodeType decodeBarcode(String barcode){
|
||||
/*
|
||||
Pattern patternUPCA = Pattern.compile("^[0-9]{12}$");
|
||||
Pattern patternUPCE = Pattern.compile("^[0-1][0-9]{7}$");
|
||||
Pattern patternUPCE1 = Pattern.compile("");
|
||||
Pattern patternEAN8 = Pattern.compile("^[0-9]{8}$");
|
||||
Pattern patternEAN13 = Pattern.compile("^[0-9]{13}$");
|
||||
Pattern patternCODE11 = Pattern.compile("");
|
||||
Pattern patternCODE39 = Pattern.compile("");
|
||||
if(){
|
||||
return BarcodeType.CODE11;
|
||||
}else if(){
|
||||
return BarcodeType.CODE39;
|
||||
}else if(){
|
||||
return BarcodeType.EAN13;
|
||||
}else if(){
|
||||
return BarcodeType.EAN8;
|
||||
}else if(){
|
||||
return BarcodeType.UPCA;
|
||||
}else if(){
|
||||
return BarcodeType.UPCE;
|
||||
}else if(false){
|
||||
return BarcodeType.UPCE1;
|
||||
}else{
|
||||
return BarcodeType.CODE128;
|
||||
}*/
|
||||
return BarcodeType.CODE128;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">keyobardemulatorscannerlibrary</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,17 @@
|
||||
package it.integry.keyobardemulatorscannerlibrary;
|
||||
|
||||
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