Migliorie nel KeyboardEmulatorBarcodeReader
This commit is contained in:
parent
fa695ca9a4
commit
bda1328dec
@ -1,5 +1,6 @@
|
||||
package it.integry.integrywmsnative.core.expansion;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
@ -18,7 +19,7 @@ import it.integry.integrywmsnative.core.barcode_reader.BarcodeManager;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityExceptions;
|
||||
import it.integry.integrywmsnative.view.dialogs.DialogProgressView;
|
||||
|
||||
public class BaseDialogFragment extends DialogFragment {
|
||||
public class BaseDialogFragment extends DialogFragment implements DialogInterface.OnShowListener {
|
||||
|
||||
@Inject
|
||||
public DialogProgressView mCurrentProgress;
|
||||
@ -41,20 +42,7 @@ public class BaseDialogFragment extends DialogFragment {
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
MainApplication.appComponent
|
||||
.baseDialogFragmentComponent()
|
||||
.create()
|
||||
.inject(this);
|
||||
|
||||
if (BarcodeManager.isEnabled() && BarcodeManager.isKeyboardEmulator()) {
|
||||
getDialog().setOnKeyListener((dialog, keyCode, event) -> {
|
||||
if (mBarcodeListener && (event.getAction() == KeyEvent.ACTION_DOWN || event.getAction() == KeyEvent.ACTION_MULTIPLE) && !isControlKey(event)) {
|
||||
return BarcodeManager.onKeyDown(event.getKeyCode(), event);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
this.initialize();
|
||||
}
|
||||
|
||||
public void onLoadingStarted() {
|
||||
@ -107,4 +95,24 @@ public class BaseDialogFragment extends DialogFragment {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onShow(DialogInterface dialogInterface) {
|
||||
this.initialize();
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
MainApplication.appComponent
|
||||
.baseDialogFragmentComponent()
|
||||
.create()
|
||||
.inject(this);
|
||||
|
||||
if (BarcodeManager.isEnabled() && BarcodeManager.isKeyboardEmulator() && getDialog() != null) {
|
||||
getDialog().setOnKeyListener((dialog, keyCode, event) -> {
|
||||
if (mBarcodeListener && (event.getAction() == KeyEvent.ACTION_DOWN || event.getAction() == KeyEvent.ACTION_MULTIPLE) && !isControlKey(event)) {
|
||||
return BarcodeManager.onKeyDown(event.getKeyCode(), event);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,6 +82,7 @@ public class DialogAskInfoInventarioView extends BaseDialogFragment {
|
||||
.create();
|
||||
|
||||
alertDialog.setCanceledOnTouchOutside(cancelable);
|
||||
alertDialog.setOnShowListener(this);
|
||||
return alertDialog;
|
||||
}
|
||||
}
|
||||
@ -72,6 +72,7 @@ public class DialogScanGrigliaAcquistoView extends BaseDialogFragment {
|
||||
|
||||
var alertDialog = alertDialogBuilder.create();
|
||||
alertDialog.setCanceledOnTouchOutside(true);
|
||||
alertDialog.setOnShowListener(this);
|
||||
return alertDialog;
|
||||
}
|
||||
|
||||
|
||||
@ -44,6 +44,7 @@ public class DialogBasketLUView extends BaseDialogFragment {
|
||||
.create();
|
||||
|
||||
alertDialog.setCanceledOnTouchOutside(false);
|
||||
alertDialog.setOnShowListener(this);
|
||||
this.initViewPager(alertDialog);
|
||||
|
||||
return alertDialog;
|
||||
|
||||
@ -7,7 +7,6 @@ import android.view.LayoutInflater;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
@ -15,12 +14,13 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import java.util.List;
|
||||
|
||||
import it.integry.integrywmsnative.R;
|
||||
import it.integry.integrywmsnative.core.expansion.BaseDialogFragment;
|
||||
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
|
||||
import it.integry.integrywmsnative.core.model.MtbAart;
|
||||
import it.integry.integrywmsnative.databinding.DialogChooseArtFromListaArtBinding;
|
||||
import it.integry.integrywmsnative.ui.SimpleDividerItemDecoration;
|
||||
|
||||
public class DialogChooseArtFromListaArtsView extends DialogFragment {
|
||||
public class DialogChooseArtFromListaArtsView extends BaseDialogFragment {
|
||||
|
||||
|
||||
private final List<MtbAart> mListaArts;
|
||||
@ -47,6 +47,7 @@ public class DialogChooseArtFromListaArtsView extends DialogFragment {
|
||||
.create();
|
||||
|
||||
alertDialog.setCanceledOnTouchOutside(false);
|
||||
alertDialog.setOnShowListener(this);
|
||||
return alertDialog;
|
||||
}
|
||||
|
||||
|
||||
@ -102,6 +102,7 @@ public class DialogChooseArtsFromMtbAartListView extends BaseDialogFragment impl
|
||||
|
||||
@Override
|
||||
public void onShow(DialogInterface dialogInterface) {
|
||||
super.onShow(dialogInterface);
|
||||
this.initList();
|
||||
}
|
||||
|
||||
|
||||
@ -144,6 +144,7 @@ public class DialogChooseArtsFromMtbColrList extends BaseDialogFragment implemen
|
||||
|
||||
@Override
|
||||
public void onShow(DialogInterface dialogInterface) {
|
||||
super.onShow(dialogInterface);
|
||||
this.initList();
|
||||
this.initFilter();
|
||||
this.setupBarcode();
|
||||
|
||||
@ -90,6 +90,7 @@ public class DialogInputPesoLUView extends BaseDialogFragment {
|
||||
.create();
|
||||
|
||||
alertDialog.setCanceledOnTouchOutside(cancelable);
|
||||
alertDialog.setOnShowListener(this);
|
||||
return alertDialog;
|
||||
}
|
||||
|
||||
|
||||
@ -103,11 +103,12 @@ public class DialogScanOrCreateLUView extends BaseDialogFragment implements Dial
|
||||
}).show(requireActivity().getSupportFragmentManager(), "tag");
|
||||
});
|
||||
|
||||
var alertDialog = new MaterialAlertDialogBuilder(requireContext())
|
||||
var alertDialog = new MaterialAlertDialogBuilder(requireContext())
|
||||
.setView(mBindings.getRoot())
|
||||
.setCancelable(false)
|
||||
.create();
|
||||
alertDialog.setCanceledOnTouchOutside(false);
|
||||
alertDialog.setOnShowListener(this);
|
||||
return alertDialog;
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package it.integry.keyobardemulatorscannerlibrary;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Pair;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
@ -18,7 +20,8 @@ public class KeyboardEmulatorBarcodeReader implements BarcodeReaderInterface {
|
||||
private RunnableArgs<BarcodeScanDTO> mOnScanSuccessfull;
|
||||
private RunnableArgs<Exception> mOnScanFailed;
|
||||
private String mTextBarcode = "";
|
||||
private long mLastCharInsertTime = 0;
|
||||
private final Handler handler = new Handler(Looper.getMainLooper());
|
||||
// private long mLastCharInsertTime = 0;
|
||||
|
||||
|
||||
public KeyboardEmulatorBarcodeReader(Context applicationContext) {
|
||||
@ -54,35 +57,56 @@ public class KeyboardEmulatorBarcodeReader implements BarcodeReaderInterface {
|
||||
@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();
|
||||
if (keyEvent.getUnicodeChar() > 0) {
|
||||
mTextBarcode += (char) keyEvent.getUnicodeChar();
|
||||
} else if (keyEvent.getCharacters() != null) {
|
||||
mTextBarcode = keyEvent.getCharacters();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (mTextBarcode.length() > 0) {
|
||||
// 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();
|
||||
|
||||
BarcodeType barcodeType = decodeBarcode(mTextBarcode);
|
||||
BarcodeScanDTO barcodeScanDTO = new BarcodeScanDTO()
|
||||
.setByteValue(mTextBarcode.getBytes())
|
||||
.setStringValue(mTextBarcode)
|
||||
.setType(barcodeType)
|
||||
.setName(barcodeType != null ? barcodeType.toString() : "");
|
||||
handler.removeCallbacks(dispatchBarcode);
|
||||
|
||||
mOnScanSuccessfull.run(barcodeScanDTO);
|
||||
}
|
||||
if (keyEvent.getUnicodeChar() > 0) {
|
||||
mTextBarcode += (char) keyEvent.getUnicodeChar();
|
||||
} else if (keyEvent.getCharacters() != null) {
|
||||
mTextBarcode = keyEvent.getCharacters();
|
||||
}
|
||||
|
||||
handler.postDelayed(dispatchBarcode, 500);
|
||||
// }
|
||||
// } 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);
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
private final Runnable dispatchBarcode = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
BarcodeType barcodeType = decodeBarcode(mTextBarcode);
|
||||
BarcodeScanDTO barcodeScanDTO = new BarcodeScanDTO()
|
||||
.setByteValue(mTextBarcode.getBytes())
|
||||
.setStringValue(mTextBarcode)
|
||||
.setType(barcodeType)
|
||||
.setName(barcodeType != null ? barcodeType.toString() : "");
|
||||
|
||||
mOnScanSuccessfull.run(barcodeScanDTO);
|
||||
mTextBarcode = "";
|
||||
}
|
||||
};
|
||||
|
||||
public BarcodeType decodeBarcode(String barcode) {
|
||||
/*Pattern patternUPCA = Pattern.compile("^[0-9]{12}$");
|
||||
Pattern patternUPCE = Pattern.compile("^[0-1][0-9]{7}$");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user