diff options
author | Javier <dev.git@javispedro.com> | 2020-02-04 23:10:12 +0100 |
---|---|---|
committer | Javier <dev.git@javispedro.com> | 2020-02-04 23:10:12 +0100 |
commit | c6d7c9ab84616b4642c9dc6bcabc8f35ce5a099a (patch) | |
tree | 4bf6dd87a9f81cedb646c7f1a790d97b1de8a21d /app/src/main | |
parent | 3763f3b3bc2d57fc23dc4ccbe5caa6c0da052c84 (diff) | |
download | vndroid-c6d7c9ab84616b4642c9dc6bcabc8f35ce5a099a.tar.gz vndroid-c6d7c9ab84616b4642c9dc6bcabc8f35ce5a099a.zip |
right button clicks -> back gestures
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/com/javispedro/vndroid/PointerEventOutput.java | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/app/src/main/java/com/javispedro/vndroid/PointerEventOutput.java b/app/src/main/java/com/javispedro/vndroid/PointerEventOutput.java index f380671..ef4d98f 100644 --- a/app/src/main/java/com/javispedro/vndroid/PointerEventOutput.java +++ b/app/src/main/java/com/javispedro/vndroid/PointerEventOutput.java @@ -9,8 +9,6 @@ import android.util.Log; public class PointerEventOutput extends AccessibilityService.GestureResultCallback { private final String TAG = PointerEventOutput.class.getSimpleName(); - private boolean btnPressed = false; - private void dispatchGesture(GestureDescription gesture) { ControlService service = ControlService.getInstance(); if (service != null) { @@ -18,7 +16,16 @@ public class PointerEventOutput extends AccessibilityService.GestureResultCallba Log.w(TAG, "gesture not dispatched"); } } else { - Log.e(TAG, "no controlservice"); + Log.w(TAG, "accessibility service not enabled, cannot control gestures"); + } + } + + private void postGlobalAction(int action) { + ControlService service = ControlService.getInstance(); + if (service != null) { + if (!service.performGlobalAction(action)) { + Log.w(TAG, "global action not posted"); + } } } @@ -70,24 +77,37 @@ public class PointerEventOutput extends AccessibilityService.GestureResultCallba } } + private final int BTN_LEFT = 0; + private final int BTN_MIDDLE = 1; + private final int BTN_RIGHT = 2; + private byte prevButtonMask = 0; + + private boolean buttonPressed(byte mask, int btn) { + return (mask & (1 << btn)) != 0; + } + public void postPointerEvent(byte buttonMask, int x, int y) { final long curTime = SystemClock.uptimeMillis(); - if ((buttonMask & 1) != 0) { + if (buttonPressed(buttonMask, BTN_LEFT)) { // Main button pressed - if (!btnPressed) { + if (!buttonPressed(prevButtonMask, BTN_LEFT)) { pointerGesture(false, x, y, curTime, true); - btnPressed = true; } else { // Button moved while pressed pointerGesture(true, x, y, curTime, true); } - } else if (btnPressed) { + } else if (buttonPressed(prevButtonMask, BTN_LEFT)) { // Button was pressed but now released pointerGesture(true, x, y, curTime, false); + } - btnPressed = false; + if (buttonPressed(buttonMask, BTN_RIGHT) && + !buttonPressed(prevButtonMask, BTN_RIGHT)) { + postGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK); } + + prevButtonMask = buttonMask; } @Override |