Skip to content

Commit

Permalink
refactor: Inline injectTouch() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtr126 committed Nov 5, 2023
1 parent 5359523 commit 5042a8f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
26 changes: 4 additions & 22 deletions app/src/main/java/xtr/keymapper/server/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,21 @@ private void initPointers() {
}
}

static class InjectEvent {
float x, y;
float pressure = 1.0f;
int pointerId;

InjectEvent(float x, float y, int pointerId) {
this.x = x;
this.y = y;
this.pointerId = pointerId;
}
}

public Input() {
initPointers();
}

private void injectTouch(int action, InjectEvent event) {
public void injectTouch(int action, int pointerId, float pressure, float x, float y) {
long now = SystemClock.uptimeMillis();
Point point = new Point(event.x, event.y);
Point point = new Point(x, y);

int pointerIndex = pointersState.getPointerIndex(event.pointerId);
int pointerIndex = pointersState.getPointerIndex(pointerId);
if (pointerIndex == -1) {
System.out.println("Too many pointers for touch event");
}
Pointer pointer = pointersState.get(pointerIndex);
pointer.setPoint(point);
pointer.setPressure(event.pressure);
pointer.setPressure(pressure);
pointer.setUp(action == MotionEvent.ACTION_UP);

int pointerCount = pointersState.update(pointerProperties, pointerCoords);
Expand Down Expand Up @@ -97,12 +85,6 @@ private void injectTouch(int action, InjectEvent event) {
}
}

public void injectTouch(int action, int pointerId, float pressure, float x, float y) {
InjectEvent event = new InjectEvent(x, y, pointerId);
event.pressure = pressure;
injectTouch(action, event);
}

public void onScrollEvent(float x, float y, int value){
if (mHandler == null) mHandler = new Handler(scrollHandler.getLooper());
scrollHandler.onScrollEvent(x, y, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ public void evAbsX(int x) {
}

public void stop() {
mouseAimHandler = null;
scrollZoomHandler = null;
pinchZoom = null;
mouseAimHandler = null;
}
}

0 comments on commit 5042a8f

Please sign in to comment.