summaryrefslogtreecommitdiffstats
path: root/remoting/android
diff options
context:
space:
mode:
authorjoedow <joedow@chromium.org>2015-12-08 14:01:02 -0800
committerCommit bot <commit-bot@chromium.org>2015-12-08 22:02:29 +0000
commit2de28656801634fdb66b1d591596a6534404895d (patch)
tree41132cd2c2e0a28f9a53a13463f5cbe1af40cca7 /remoting/android
parent5ebd1587dad4f5ce3e670d4c26254b8a66badd7d (diff)
downloadchromium_src-2de28656801634fdb66b1d591596a6534404895d.zip
chromium_src-2de28656801634fdb66b1d591596a6534404895d.tar.gz
chromium_src-2de28656801634fdb66b1d591596a6534404895d.tar.bz2
Updated the TapGestureDetector to provide coordinates for tap events.
This change allows listeners to receive the coordinates of the initial fingerdown for tap and longpress events and use them for input injection. Note: The new parameters are not currently used in the TouchInputHandler class but will be hooked up in a future CL. BUG=454549 Review URL: https://codereview.chromium.org/1509983002 Cr-Commit-Position: refs/heads/master@{#363810}
Diffstat (limited to 'remoting/android')
-rw-r--r--remoting/android/java/src/org/chromium/chromoting/TapGestureDetector.java25
-rw-r--r--remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java4
-rw-r--r--remoting/android/javatests/src/org/chromium/chromoting/TapGestureDetectorTest.java35
3 files changed, 47 insertions, 17 deletions
diff --git a/remoting/android/java/src/org/chromium/chromoting/TapGestureDetector.java b/remoting/android/java/src/org/chromium/chromoting/TapGestureDetector.java
index 14cf558..45dab79 100644
--- a/remoting/android/java/src/org/chromium/chromoting/TapGestureDetector.java
+++ b/remoting/android/java/src/org/chromium/chromoting/TapGestureDetector.java
@@ -25,16 +25,20 @@ public class TapGestureDetector {
* Notified when a tap event occurs.
*
* @param pointerCount The number of fingers that were tapped.
+ * @param x The x coordinate of the initial finger tapped.
+ * @param y The y coordinate of the initial finger tapped.
* @return True if the event is consumed.
*/
- boolean onTap(int pointerCount);
+ boolean onTap(int pointerCount, float x, float y);
/**
* Notified when a long-touch event occurs.
*
* @param pointerCount The number of fingers held down.
+ * @param x The x coordinate of the initial finger tapped.
+ * @param y The y coordinate of the initial finger tapped.
*/
- void onLongPress(int pointerCount);
+ void onLongPress(int pointerCount, float x, float y);
}
/** The listener to which notifications are sent. */
@@ -46,6 +50,9 @@ public class TapGestureDetector {
/** The maximum number of fingers seen in the gesture. */
private int mPointerCount = 0;
+ /** The coordinates of the first finger down seen in the gesture. */
+ private PointF mInitialPoint;
+
/**
* Stores the location of each down MotionEvent (by pointer ID), for detecting motion of any
* pointer beyond the TouchSlop region.
@@ -74,7 +81,8 @@ public class TapGestureDetector {
public void handleMessage(Message message) {
TapGestureDetector detector = mDetector.get();
if (detector != null) {
- detector.mListener.onLongPress(detector.mPointerCount);
+ detector.mListener.onLongPress(
+ detector.mPointerCount, detector.mInitialPoint.x, detector.mInitialPoint.y);
detector.mTapCancelled = true;
}
}
@@ -117,8 +125,9 @@ public class TapGestureDetector {
case MotionEvent.ACTION_UP:
cancelLongTouchNotification();
if (!mTapCancelled) {
- handled = mListener.onTap(mPointerCount);
+ handled = mListener.onTap(mPointerCount, mInitialPoint.x, mInitialPoint.y);
}
+ mInitialPoint = null;
break;
case MotionEvent.ACTION_POINTER_UP:
@@ -143,8 +152,12 @@ public class TapGestureDetector {
pointerIndex = event.getActionIndex();
}
int pointerId = event.getPointerId(pointerIndex);
- mInitialPositions.put(pointerId,
- new PointF(event.getX(pointerIndex), event.getY(pointerIndex)));
+ PointF eventPosition = new PointF(event.getX(pointerIndex), event.getY(pointerIndex));
+ mInitialPositions.put(pointerId, eventPosition);
+
+ if (mInitialPoint == null) {
+ mInitialPoint = eventPosition;
+ }
}
/** Removes the ACTION_UP or ACTION_POINTER_UP event from the stored list. */
diff --git a/remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java b/remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java
index d7520f7..71c3be0 100644
--- a/remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java
+++ b/remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java
@@ -356,7 +356,7 @@ public class TouchInputHandler implements TouchInputHandlerInterface {
/** Called when the user taps the screen with one or more fingers. */
@Override
- public boolean onTap(int pointerCount) {
+ public boolean onTap(int pointerCount, float x, float y) {
int button = mouseButtonFromPointerCount(pointerCount);
if (button == BUTTON_UNDEFINED) {
return false;
@@ -370,7 +370,7 @@ public class TouchInputHandler implements TouchInputHandlerInterface {
/** Called when a long-press is triggered for one or more fingers. */
@Override
- public void onLongPress(int pointerCount) {
+ public void onLongPress(int pointerCount, float x, float y) {
mHeldButton = mouseButtonFromPointerCount(pointerCount);
if (mHeldButton != BUTTON_UNDEFINED) {
mInputStrategy.injectRemoteButtonEvent(mHeldButton, true);
diff --git a/remoting/android/javatests/src/org/chromium/chromoting/TapGestureDetectorTest.java b/remoting/android/javatests/src/org/chromium/chromoting/TapGestureDetectorTest.java
index ab66faa..3dd4b52 100644
--- a/remoting/android/javatests/src/org/chromium/chromoting/TapGestureDetectorTest.java
+++ b/remoting/android/javatests/src/org/chromium/chromoting/TapGestureDetectorTest.java
@@ -15,35 +15,52 @@ import org.chromium.base.test.util.Feature;
/** Tests for {@link TapGestureDetector}. */
public class TapGestureDetectorTest extends InstrumentationTestCase {
private static class MockListener implements TapGestureDetector.OnTapListener {
+ private static final float COMPARISON_DELTA = 0.01f;
int mTapCount = -1;
int mLongPressCount = -1;
+ float mTapX = -1;
+ float mTapY = -1;
@Override
- public boolean onTap(int pointerCount) {
+ public boolean onTap(int pointerCount, float x, float y) {
assertEquals(-1, mTapCount);
+ assertEquals(-1, mTapX, COMPARISON_DELTA);
+ assertEquals(-1, mTapY, COMPARISON_DELTA);
mTapCount = pointerCount;
+ mTapX = x;
+ mTapY = y;
return true;
}
@Override
- public void onLongPress(int pointerCount) {
+ public void onLongPress(int pointerCount, float x, float y) {
assertEquals(-1, mLongPressCount);
+ assertEquals(-1, mTapX, COMPARISON_DELTA);
+ assertEquals(-1, mTapY, COMPARISON_DELTA);
mLongPressCount = pointerCount;
+ mTapX = x;
+ mTapY = y;
}
- public void assertTapDetected(int expectedCount) {
+ public void assertTapDetected(int expectedCount, float expectedX, float expectedY) {
assertEquals(expectedCount, mTapCount);
+ assertEquals(expectedX, mTapX, COMPARISON_DELTA);
+ assertEquals(expectedY, mTapY, COMPARISON_DELTA);
assertEquals(-1, mLongPressCount);
}
- public void assertLongPressDetected(int expectedCount) {
+ public void assertLongPressDetected(int expectedCount, float expectedX, float expectedY) {
assertEquals(expectedCount, mLongPressCount);
+ assertEquals(expectedX, mTapX, COMPARISON_DELTA);
+ assertEquals(expectedY, mTapY, COMPARISON_DELTA);
assertEquals(-1, mTapCount);
}
public void assertNothingDetected() {
assertEquals(-1, mTapCount);
assertEquals(-1, mLongPressCount);
+ assertEquals(-1, mTapX, COMPARISON_DELTA);
+ assertEquals(-1, mTapY, COMPARISON_DELTA);
}
}
@@ -85,7 +102,7 @@ public class TapGestureDetectorTest extends InstrumentationTestCase {
public void testOneFingerDownUp() throws Exception {
injectDownEvent(0, 0, 0);
injectUpEvent(0);
- mListener.assertTapDetected(1);
+ mListener.assertTapDetected(1, 0, 0);
}
/** Verifies that a simple multi-finger down/up is detected as a tap. */
@@ -98,7 +115,7 @@ public class TapGestureDetectorTest extends InstrumentationTestCase {
injectUpEvent(0);
injectUpEvent(1);
injectUpEvent(2);
- mListener.assertTapDetected(3);
+ mListener.assertTapDetected(3, 0, 0);
}
/** Verifies that a multi-finger tap is detected when lifting the fingers in reverse order. */
@@ -111,7 +128,7 @@ public class TapGestureDetectorTest extends InstrumentationTestCase {
injectUpEvent(2);
injectUpEvent(1);
injectUpEvent(0);
- mListener.assertTapDetected(3);
+ mListener.assertTapDetected(3, 0, 0);
}
/** Verifies that small movement of multiple fingers is still detected as a tap. */
@@ -127,7 +144,7 @@ public class TapGestureDetectorTest extends InstrumentationTestCase {
injectUpEvent(0);
injectUpEvent(1);
injectUpEvent(2);
- mListener.assertTapDetected(3);
+ mListener.assertTapDetected(3, 0, 0);
}
/** Verifies that large motion of a finger prevents a tap being detected. */
@@ -169,6 +186,6 @@ public class TapGestureDetectorTest extends InstrumentationTestCase {
}
});
- mListener.assertLongPressDetected(1);
+ mListener.assertLongPressDetected(1, 0, 0);
}
}