[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:
1
keyobardemulatorscannerlibrary/.gitignore
vendored
Normal file
1
keyobardemulatorscannerlibrary/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
||||
35
keyobardemulatorscannerlibrary/build.gradle
Normal file
35
keyobardemulatorscannerlibrary/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"
|
||||
consumerProguardFiles 'consumer-rules.pro'
|
||||
}
|
||||
|
||||
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.1.0'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
implementation project(':barcode_base_android_library')
|
||||
}
|
||||
0
keyobardemulatorscannerlibrary/consumer-rules.pro
Normal file
0
keyobardemulatorscannerlibrary/consumer-rules.pro
Normal file
21
keyobardemulatorscannerlibrary/proguard-rules.pro
vendored
Normal file
21
keyobardemulatorscannerlibrary/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.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