Rename "pointer" to "mouse pointer"

This will help to distinguish them from "touch pointers".
This commit is contained in:
Romain Vimont 2019-09-22 14:45:56 +02:00
parent 810ff80ba7
commit d90549d1e6

View file

@ -20,35 +20,35 @@ public class Controller {
private final KeyCharacterMap charMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD); private final KeyCharacterMap charMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
private long lastMouseDown; private long lastMouseDown;
private final MotionEvent.PointerProperties[] pointerProperties = {new MotionEvent.PointerProperties()}; private final MotionEvent.PointerProperties[] mousePointerProperties = {new MotionEvent.PointerProperties()};
private final MotionEvent.PointerCoords[] pointerCoords = {new MotionEvent.PointerCoords()}; private final MotionEvent.PointerCoords[] mousePointerCoords = {new MotionEvent.PointerCoords()};
public Controller(Device device, DesktopConnection connection) { public Controller(Device device, DesktopConnection connection) {
this.device = device; this.device = device;
this.connection = connection; this.connection = connection;
initPointer(); initMousePointer();
sender = new DeviceMessageSender(connection); sender = new DeviceMessageSender(connection);
} }
private void initPointer() { private void initMousePointer() {
MotionEvent.PointerProperties props = pointerProperties[0]; MotionEvent.PointerProperties props = mousePointerProperties[0];
props.id = 0; props.id = 0;
props.toolType = MotionEvent.TOOL_TYPE_FINGER; props.toolType = MotionEvent.TOOL_TYPE_FINGER;
MotionEvent.PointerCoords coords = pointerCoords[0]; MotionEvent.PointerCoords coords = mousePointerCoords[0];
coords.orientation = 0; coords.orientation = 0;
coords.pressure = 1; coords.pressure = 1;
coords.size = 1; coords.size = 1;
} }
private void setPointerCoords(Point point) { private void setMousePointerCoords(Point point) {
MotionEvent.PointerCoords coords = pointerCoords[0]; MotionEvent.PointerCoords coords = mousePointerCoords[0];
coords.x = point.getX(); coords.x = point.getX();
coords.y = point.getY(); coords.y = point.getY();
} }
private void setScroll(int hScroll, int vScroll) { private void setScroll(int hScroll, int vScroll) {
MotionEvent.PointerCoords coords = pointerCoords[0]; MotionEvent.PointerCoords coords = mousePointerCoords[0];
coords.setAxisValue(MotionEvent.AXIS_HSCROLL, hScroll); coords.setAxisValue(MotionEvent.AXIS_HSCROLL, hScroll);
coords.setAxisValue(MotionEvent.AXIS_VSCROLL, vScroll); coords.setAxisValue(MotionEvent.AXIS_VSCROLL, vScroll);
} }
@ -158,9 +158,9 @@ public class Controller {
// ignore event // ignore event
return false; return false;
} }
setPointerCoords(point); setMousePointerCoords(point);
MotionEvent event = MotionEvent.obtain(lastMouseDown, now, action, 1, pointerProperties, pointerCoords, 0, buttons, 1f, 1f, 0, 0, MotionEvent event = MotionEvent.obtain(lastMouseDown, now, action, 1, mousePointerProperties,
InputDevice.SOURCE_TOUCHSCREEN, 0); mousePointerCoords, 0, buttons, 1f, 1f, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
return injectEvent(event); return injectEvent(event);
} }
@ -171,23 +171,22 @@ public class Controller {
// ignore event // ignore event
return false; return false;
} }
setPointerCoords(point); setMousePointerCoords(point);
setScroll(hScroll, vScroll); setScroll(hScroll, vScroll);
MotionEvent event = MotionEvent.obtain(lastMouseDown, now, MotionEvent.ACTION_SCROLL, 1, pointerProperties, pointerCoords, 0, 0, 1f, 1f, 0, MotionEvent event = MotionEvent.obtain(lastMouseDown, now, MotionEvent.ACTION_SCROLL, 1,
0, InputDevice.SOURCE_MOUSE, 0); mousePointerProperties, mousePointerCoords, 0, 0, 1f, 1f, 0, 0, InputDevice.SOURCE_MOUSE, 0);
return injectEvent(event); return injectEvent(event);
} }
private boolean injectKeyEvent(int action, int keyCode, int repeat, int metaState) { private boolean injectKeyEvent(int action, int keyCode, int repeat, int metaState) {
long now = SystemClock.uptimeMillis(); long now = SystemClock.uptimeMillis();
KeyEvent event = new KeyEvent(now, now, action, keyCode, repeat, metaState, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, KeyEvent event = new KeyEvent(now, now, action, keyCode, repeat, metaState, KeyCharacterMap.VIRTUAL_KEYBOARD,
InputDevice.SOURCE_KEYBOARD); 0, 0, InputDevice.SOURCE_KEYBOARD);
return injectEvent(event); return injectEvent(event);
} }
private boolean injectKeycode(int keyCode) { private boolean injectKeycode(int keyCode) {
return injectKeyEvent(KeyEvent.ACTION_DOWN, keyCode, 0, 0) return injectKeyEvent(KeyEvent.ACTION_DOWN, keyCode, 0, 0) && injectKeyEvent(KeyEvent.ACTION_UP, keyCode, 0, 0);
&& injectKeyEvent(KeyEvent.ACTION_UP, keyCode, 0, 0);
} }
private boolean injectEvent(InputEvent event) { private boolean injectEvent(InputEvent event) {