Merge mouse and touch events
Both are handled the very same way on the device.
This commit is contained in:
@@ -7,15 +7,14 @@ public final class ControlMessage {
|
||||
|
||||
public static final int TYPE_INJECT_KEYCODE = 0;
|
||||
public static final int TYPE_INJECT_TEXT = 1;
|
||||
public static final int TYPE_INJECT_MOUSE_EVENT = 2;
|
||||
public static final int TYPE_INJECT_TOUCH_EVENT = 3;
|
||||
public static final int TYPE_INJECT_SCROLL_EVENT = 4;
|
||||
public static final int TYPE_BACK_OR_SCREEN_ON = 5;
|
||||
public static final int TYPE_EXPAND_NOTIFICATION_PANEL = 6;
|
||||
public static final int TYPE_COLLAPSE_NOTIFICATION_PANEL = 7;
|
||||
public static final int TYPE_GET_CLIPBOARD = 8;
|
||||
public static final int TYPE_SET_CLIPBOARD = 9;
|
||||
public static final int TYPE_SET_SCREEN_POWER_MODE = 10;
|
||||
public static final int TYPE_INJECT_TOUCH_EVENT = 2;
|
||||
public static final int TYPE_INJECT_SCROLL_EVENT = 3;
|
||||
public static final int TYPE_BACK_OR_SCREEN_ON = 4;
|
||||
public static final int TYPE_EXPAND_NOTIFICATION_PANEL = 5;
|
||||
public static final int TYPE_COLLAPSE_NOTIFICATION_PANEL = 6;
|
||||
public static final int TYPE_GET_CLIPBOARD = 7;
|
||||
public static final int TYPE_SET_CLIPBOARD = 8;
|
||||
public static final int TYPE_SET_SCREEN_POWER_MODE = 9;
|
||||
|
||||
private int type;
|
||||
private String text;
|
||||
@@ -48,22 +47,15 @@ public final class ControlMessage {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public static ControlMessage createInjectMouseEvent(int action, int buttons, Position position) {
|
||||
ControlMessage msg = new ControlMessage();
|
||||
msg.type = TYPE_INJECT_MOUSE_EVENT;
|
||||
msg.action = action;
|
||||
msg.buttons = buttons;
|
||||
msg.position = position;
|
||||
return msg;
|
||||
}
|
||||
|
||||
public static ControlMessage createInjectTouchEvent(int action, long pointerId, Position position, float pressure) {
|
||||
public static ControlMessage createInjectTouchEvent(int action, long pointerId, Position position, float pressure,
|
||||
int buttons) {
|
||||
ControlMessage msg = new ControlMessage();
|
||||
msg.type = TYPE_INJECT_TOUCH_EVENT;
|
||||
msg.action = action;
|
||||
msg.pointerId = pointerId;
|
||||
msg.pressure = pressure;
|
||||
msg.position = position;
|
||||
msg.buttons = buttons;
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,9 +60,6 @@ public class ControlMessageReader {
|
||||
case ControlMessage.TYPE_INJECT_TEXT:
|
||||
msg = parseInjectText();
|
||||
break;
|
||||
case ControlMessage.TYPE_INJECT_MOUSE_EVENT:
|
||||
msg = parseInjectMouseEvent();
|
||||
break;
|
||||
case ControlMessage.TYPE_INJECT_TOUCH_EVENT:
|
||||
msg = parseInjectTouchEvent();
|
||||
break;
|
||||
@@ -124,16 +121,6 @@ public class ControlMessageReader {
|
||||
return ControlMessage.createInjectText(text);
|
||||
}
|
||||
|
||||
private ControlMessage parseInjectMouseEvent() {
|
||||
if (buffer.remaining() < INJECT_MOUSE_EVENT_PAYLOAD_LENGTH) {
|
||||
return null;
|
||||
}
|
||||
int action = toUnsigned(buffer.get());
|
||||
int buttons = buffer.getInt();
|
||||
Position position = readPosition(buffer);
|
||||
return ControlMessage.createInjectMouseEvent(action, buttons, position);
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:MagicNumber")
|
||||
private ControlMessage parseInjectTouchEvent() {
|
||||
if (buffer.remaining() < INJECT_TOUCH_EVENT_PAYLOAD_LENGTH) {
|
||||
@@ -146,7 +133,8 @@ public class ControlMessageReader {
|
||||
int pressureInt = toUnsigned(buffer.getShort());
|
||||
// convert it to a float between 0 and 1 (0x1p16f is 2^16 as float)
|
||||
float pressure = pressureInt == 0xffff ? 1f : (pressureInt / 0x1p16f);
|
||||
return ControlMessage.createInjectTouchEvent(action, pointerId, position, pressure);
|
||||
int buttons = buffer.getInt();
|
||||
return ControlMessage.createInjectTouchEvent(action, pointerId, position, pressure, buttons);
|
||||
}
|
||||
|
||||
private ControlMessage parseInjectScrollEvent() {
|
||||
|
||||
@@ -81,9 +81,6 @@ public class Controller {
|
||||
case ControlMessage.TYPE_INJECT_TEXT:
|
||||
injectText(msg.getText());
|
||||
break;
|
||||
case ControlMessage.TYPE_INJECT_MOUSE_EVENT:
|
||||
injectTouch(msg.getAction(), PointersState.POINTER_ID_MOUSE, msg.getPosition(), 1, msg.getButtons());
|
||||
break;
|
||||
case ControlMessage.TYPE_INJECT_TOUCH_EVENT:
|
||||
injectTouch(msg.getAction(), msg.getPointerId(), msg.getPosition(), msg.getPressure(), 0);
|
||||
break;
|
||||
|
||||
@@ -8,7 +8,6 @@ import java.util.List;
|
||||
public class PointersState {
|
||||
|
||||
public static final int MAX_POINTERS = 10;
|
||||
public static final long POINTER_ID_MOUSE = -1;
|
||||
|
||||
private final List<Pointer> pointers = new ArrayList<>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user