Skip to content

Commit

Permalink
Update 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kduma committed Aug 16, 2023
1 parent 4b0991d commit 9a65b8f
Show file tree
Hide file tree
Showing 13 changed files with 352 additions and 584 deletions.
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,28 +178,28 @@ Remove a callback set by `setDebugHandler`.

#### HandleableKey

| Members | Value |
| -------------------------- | ----------------------------------- |
| **`Esc`** | <code>"ESC"</code> |
| **`F1`** | <code>"F1"</code> |
| **`F2`** | <code>"F2"</code> |
| **`F3`** | <code>"F3"</code> |
| **`F4`** | <code>"F4"</code> |
| **`F5`** | <code>"F5"</code> |
| **`F6`** | <code>"F6"</code> |
| **`F7`** | <code>"F7"</code> |
| **`F8`** | <code>"F8"</code> |
| **`F9`** | <code>"F9"</code> |
| **`F10`** | <code>"F10"</code> |
| **`Delete`** | <code>"DELETE"</code> |
| **`Home`** | <code>"HOME"</code> |
| **`End`** | <code>"END"</code> |
| **`PgUp`** | <code>"PGUP"</code> |
| **`PgDn`** | <code>"PGDN"</code> |
| **`Cash`** | <code>"CASH"</code> |
| **`L2s_Shortcut_or_RFID`** | <code>"L2S_SHORTCUT_OR_RFID"</code> |
| **`L2k_Shortcut`** | <code>"L2K_SHORTCUT"</code> |
| **`L2k_RFID`** | <code>"L2K_RFID"</code> |
| Members | Value |
| ------------------ | --------------------------- |
| **`Esc`** | <code>"ESC"</code> |
| **`F1`** | <code>"F1"</code> |
| **`F2`** | <code>"F2"</code> |
| **`F3`** | <code>"F3"</code> |
| **`F4`** | <code>"F4"</code> |
| **`F5`** | <code>"F5"</code> |
| **`F6`** | <code>"F6"</code> |
| **`F7`** | <code>"F7"</code> |
| **`F8`** | <code>"F8"</code> |
| **`F9`** | <code>"F9"</code> |
| **`F10`** | <code>"F10"</code> |
| **`Delete`** | <code>"DELETE"</code> |
| **`Home`** | <code>"HOME"</code> |
| **`End`** | <code>"END"</code> |
| **`PgUp`** | <code>"PGUP"</code> |
| **`PgDn`** | <code>"PGDN"</code> |
| **`Cash`** | <code>"CASH"</code> |
| **`L2s_Shortcut`** | <code>"L2S_SHORTCUT"</code> |
| **`L2k_Shortcut`** | <code>"L2K_SHORTCUT"</code> |
| **`RFID`** | <code>"RFID"</code> |


#### ModifierKey
Expand Down
17 changes: 9 additions & 8 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ext {
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.4.2'
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.3'
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.4.0'
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
}

buildscript {
Expand All @@ -11,17 +11,18 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.1'
classpath 'com.android.tools.build:gradle:8.0.0'
}
}

apply plugin: 'com.android.library'

android {
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 32
namespace "dev.duma.capacitor.sunmikeyboardhandler"
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 33
defaultConfig {
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 32
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -36,8 +37,8 @@ android {
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}

Expand Down
3 changes: 1 addition & 2 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ org.gradle.jvmargs=-Xmx1536m
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true

2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dev.duma.capacitor.sunmikeyboardhandler">
>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import dev.duma.capacitor.sunmikeyboardhandler.handlers.DebugKeyHandler;
import dev.duma.capacitor.sunmikeyboardhandler.handlers.SunmiBarcodeScannerKeyHandler;
import dev.duma.capacitor.sunmikeyboardhandler.handlers.SunmiKeyboardKeyHandler;
import dev.duma.capacitor.sunmikeyboardhandler.handlers.SunmiL2kRfidKeyHandler;
import dev.duma.capacitor.sunmikeyboardhandler.handlers.SunmiRfidKeyHandler;
import dev.duma.capacitor.sunmikeyboardhandler.handlers.SunmiL2kShortcutKeyHandler;
import dev.duma.capacitor.sunmikeyboardhandler.handlers.SunmiL2sShortcutKeyHandler;

Expand Down Expand Up @@ -108,7 +108,7 @@ public void setKeyHandler(PluginCall call) {
keyHandlers.put(key, new Pair<>(call.getCallbackId(), sunmiKeyboardKeyHandler));
break;

case L2s_Shortcut_or_RFID:
case L2s_Shortcut:
call.setKeepAlive(true);
bridge.saveCall(call);

Expand All @@ -121,14 +121,14 @@ public void setKeyHandler(PluginCall call) {

JSObject data = new JSObject();

data.put("key", HandleableKeyEnum.L2s_Shortcut_or_RFID.toString());
data.put("key", HandleableKeyEnum.L2s_Shortcut.toString());
data.put("modifiers", new JSONArray());
data.put("type", pressed ? KeyEventEnum.KeyDown.toString() : KeyEventEnum.KeyUp.toString());

c.resolve(data);
});

keyHandlers.put(HandleableKeyEnum.L2s_Shortcut_or_RFID, new Pair<>(call.getCallbackId(), sunmiL2sShortcutKeyHandler));
keyHandlers.put(HandleableKeyEnum.L2s_Shortcut, new Pair<>(call.getCallbackId(), sunmiL2sShortcutKeyHandler));
break;

case L2k_Shortcut:
Expand All @@ -154,27 +154,27 @@ public void setKeyHandler(PluginCall call) {
keyHandlers.put(HandleableKeyEnum.L2k_Shortcut, new Pair<>(call.getCallbackId(), sunmiL2kShortcutKeyHandler));
break;

case L2k_RFID:
case RFID:
call.setKeepAlive(true);
bridge.saveCall(call);

String L2kRfidCallbackId = call.getCallbackId();
SunmiL2kRfidKeyHandler sunmiL2kRfidKeyHandler = new SunmiL2kRfidKeyHandler((pressed) -> {
PluginCall c = bridge.getSavedCall(L2kRfidCallbackId);
String RfidCallbackId = call.getCallbackId();
SunmiRfidKeyHandler sunmiRfidKeyHandler = new SunmiRfidKeyHandler((pressed) -> {
PluginCall c = bridge.getSavedCall(RfidCallbackId);

if (c == null)
return;

JSObject data = new JSObject();

data.put("key", HandleableKeyEnum.L2k_RFID.toString());
data.put("key", HandleableKeyEnum.RFID.toString());
data.put("modifiers", new JSONArray());
data.put("type", pressed ? KeyEventEnum.KeyDown.toString() : KeyEventEnum.KeyUp.toString());

c.resolve(data);
});

keyHandlers.put(HandleableKeyEnum.L2k_RFID, new Pair<>(call.getCallbackId(), sunmiL2kRfidKeyHandler));
keyHandlers.put(HandleableKeyEnum.RFID, new Pair<>(call.getCallbackId(), sunmiRfidKeyHandler));
break;

case Barcode:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public enum HandleableKeyEnum implements Labeled {
PgDn("PGDN"),
Cash("CASH"),

L2s_Shortcut_or_RFID("L2S_SHORTCUT_OR_RFID"),
L2s_Shortcut("L2S_SHORTCUT"),
L2k_Shortcut("L2K_SHORTCUT"),
L2k_RFID("L2K_RFID"),
RFID("RFID"),

Barcode("BARCODE"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public synchronized boolean handle(KeyEvent event) {
if ((device.getVendorId() != 9300 || device.getProductId() != 25856) && !device.getName().contains("mtk-kpd")) // Sunmi built-in buttons
return false;

if (event.getKeyCode() != 288 && event.getKeyCode() != KEYCODE_F11) // Sunmi L2s Shortcut / Scan UHF button
if (event.getKeyCode() != KEYCODE_F11) // Sunmi L2s Shortcut
return false;

if (event.getAction() == ACTION_DOWN && !isButtonPressed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

import dev.duma.capacitor.sunmikeyboardhandler.KeyHandlerInterface;

public class SunmiL2kRfidKeyHandler implements KeyHandlerInterface {
public interface SunmiL2kRfidKeyHandlerCallback {
public class SunmiRfidKeyHandler implements KeyHandlerInterface {
public interface SunmiRfidKeyHandlerCallback {
void onKeyPressed(boolean pressed);
}

protected SunmiL2kRfidKeyHandlerCallback callback;
protected SunmiRfidKeyHandlerCallback callback;

public SunmiL2kRfidKeyHandler(SunmiL2kRfidKeyHandlerCallback callback) {
public SunmiRfidKeyHandler(SunmiRfidKeyHandlerCallback callback) {
this.callback = callback;
}

Expand All @@ -26,10 +26,13 @@ public synchronized boolean handle(KeyEvent event) {

InputDevice device = event.getDevice();

if ((device.getVendorId() != 1 || device.getProductId() != 1) && !device.getName().contains("pogo-keys"))
boolean l2kGun = device.getVendorId() == 1 && device.getProductId() == 1 && device.getName().contains("pogo-keys");
boolean l2sInternal = device.getVendorId() == 9300 && device.getProductId() == 25856 && device.getName().contains("mtk-kpd");

if (!l2kGun && !l2sInternal)
return false;

if (event.getKeyCode() != 288) // Sunmi L2k RFID Key
if (event.getKeyCode() != 288) // Sunmi RFID Key
return false;

if (event.getAction() == ACTION_DOWN && !isButtonPressed) {
Expand Down
10 changes: 5 additions & 5 deletions example/src/js/capacitor-welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ window.customElements.define(
output.innerHTML = "<b>l2k_shortcut_key_handler:</b><br><pre>" + JSON.stringify(e, null, 3) + "</pre><hr>" + output.innerHTML;
}

const l2k_rfid_key_handler = (e) => {
const rfid_key_handler = (e) => {
const output = self.shadowRoot.querySelector('#output');
output.innerHTML = "<b>l2k_rfid_key_handler:</b><br><pre>" + JSON.stringify(e, null, 3) + "</pre><hr>" + output.innerHTML;
output.innerHTML = "<b>rfid_key_handler:</b><br><pre>" + JSON.stringify(e, null, 3) + "</pre><hr>" + output.innerHTML;
}

const keyboard_press_handler = (e) => {
Expand All @@ -103,11 +103,10 @@ window.customElements.define(
}

await Promise.all([
SunmiKeyboardHandler.setDebugHandler(debug_handler),
SunmiKeyboardHandler.setBarcodeHandler(barcode_scan_handler),
SunmiKeyboardHandler.setKeyHandler({ key: HandleableKey.L2s_Shortcut_or_RFID }, l2s_shortcut_key_handler),
SunmiKeyboardHandler.setKeyHandler({ key: HandleableKey.L2s_Shortcut }, l2s_shortcut_key_handler),
SunmiKeyboardHandler.setKeyHandler({ key: HandleableKey.L2k_Shortcut }, l2k_shortcut_key_handler),
SunmiKeyboardHandler.setKeyHandler({ key: HandleableKey.L2k_RFID }, l2k_rfid_key_handler),
SunmiKeyboardHandler.setKeyHandler({ key: HandleableKey.RFID }, rfid_key_handler),
SunmiKeyboardHandler.setKeyHandler({ key: HandleableKey.Esc }, keyboard_press_handler),
SunmiKeyboardHandler.setKeyHandler({ key: HandleableKey.F1 }, keyboard_press_handler),
SunmiKeyboardHandler.setKeyHandler({ key: HandleableKey.F2 }, keyboard_press_handler),
Expand All @@ -125,6 +124,7 @@ window.customElements.define(
SunmiKeyboardHandler.setKeyHandler({ key: HandleableKey.PgUp }, keyboard_press_handler),
SunmiKeyboardHandler.setKeyHandler({ key: HandleableKey.PgDn }, keyboard_press_handler),
SunmiKeyboardHandler.setKeyHandler({ key: HandleableKey.Cash }, keyboard_press_handler),
SunmiKeyboardHandler.setDebugHandler(debug_handler),
]);
}
}
Expand Down
Loading

0 comments on commit 9a65b8f

Please sign in to comment.