From ad4c061cd29041b3cc94a93ff0e861fc0a52439c Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 30 May 2019 21:24:00 +0200 Subject: [PATCH] Use custom class Point The framework class android.graphics.Point cannot be used in unit tests. Implement our own Point. --- .../java/com/genymobile/scrcpy/Device.java | 5 +- .../genymobile/scrcpy/EventController.java | 5 +- .../java/com/genymobile/scrcpy/Point.java | 47 +++++++++++++++++++ .../java/com/genymobile/scrcpy/Position.java | 2 - 4 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 server/src/main/java/com/genymobile/scrcpy/Point.java diff --git a/server/src/main/java/com/genymobile/scrcpy/Device.java b/server/src/main/java/com/genymobile/scrcpy/Device.java index 60122c5a..57496363 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Device.java +++ b/server/src/main/java/com/genymobile/scrcpy/Device.java @@ -2,7 +2,6 @@ package com.genymobile.scrcpy; import com.genymobile.scrcpy.wrappers.ServiceManager; -import android.graphics.Point; import android.graphics.Rect; import android.os.Build; import android.os.RemoteException; @@ -107,8 +106,8 @@ public final class Device { } Rect contentRect = screenInfo.getContentRect(); Point point = position.getPoint(); - int scaledX = contentRect.left + point.x * contentRect.width() / videoSize.getWidth(); - int scaledY = contentRect.top + point.y * contentRect.height() / videoSize.getHeight(); + int scaledX = contentRect.left + point.getX() * contentRect.width() / videoSize.getWidth(); + int scaledY = contentRect.top + point.getY() * contentRect.height() / videoSize.getHeight(); return new Point(scaledX, scaledY); } diff --git a/server/src/main/java/com/genymobile/scrcpy/EventController.java b/server/src/main/java/com/genymobile/scrcpy/EventController.java index 762d3b7a..5bb79de3 100644 --- a/server/src/main/java/com/genymobile/scrcpy/EventController.java +++ b/server/src/main/java/com/genymobile/scrcpy/EventController.java @@ -2,7 +2,6 @@ package com.genymobile.scrcpy; import com.genymobile.scrcpy.wrappers.InputManager; -import android.graphics.Point; import android.os.SystemClock; import android.view.InputDevice; import android.view.InputEvent; @@ -43,8 +42,8 @@ public class EventController { private void setPointerCoords(Point point) { MotionEvent.PointerCoords coords = pointerCoords[0]; - coords.x = point.x; - coords.y = point.y; + coords.x = point.getX(); + coords.y = point.getY(); } private void setScroll(int hScroll, int vScroll) { diff --git a/server/src/main/java/com/genymobile/scrcpy/Point.java b/server/src/main/java/com/genymobile/scrcpy/Point.java new file mode 100644 index 00000000..9ef2db03 --- /dev/null +++ b/server/src/main/java/com/genymobile/scrcpy/Point.java @@ -0,0 +1,47 @@ +package com.genymobile.scrcpy; + +import java.util.Objects; + +public class Point { + private final int x; + private final int y; + + public Point(int x, int y) { + this.x = x; + this.y = y; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Point point = (Point) o; + return x == point.x + && y == point.y; + } + + @Override + public int hashCode() { + return Objects.hash(x, y); + } + + @Override + public String toString() { + return "Point{" + + "x=" + x + + ", y=" + y + + '}'; + } +} diff --git a/server/src/main/java/com/genymobile/scrcpy/Position.java b/server/src/main/java/com/genymobile/scrcpy/Position.java index e00a6355..757fa36e 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Position.java +++ b/server/src/main/java/com/genymobile/scrcpy/Position.java @@ -1,7 +1,5 @@ package com.genymobile.scrcpy; -import android.graphics.Point; - import java.util.Objects; public class Position {