summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/javispedro/vndroid/PointerEventOutput.java36
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