am e08c418f: Move motion event dispatcher to PointerTracker
* commit 'e08c418ff8b374244677960903cee8dd52a4d831': Move motion event dispatcher to PointerTrackermain
commit
197c60342b
|
@ -1055,26 +1055,10 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||||
ResearchLogger.mainKeyboardView_processMotionEvent(me);
|
ResearchLogger.mainKeyboardView_processMotionEvent(me);
|
||||||
}
|
}
|
||||||
|
|
||||||
final int action = me.getActionMasked();
|
final int index = me.getActionIndex();
|
||||||
final long eventTime = me.getEventTime();
|
final int id = me.getPointerId(index);
|
||||||
if (action == MotionEvent.ACTION_MOVE) {
|
final PointerTracker tracker = PointerTracker.getPointerTracker(id, this);
|
||||||
final int pointerCount = me.getPointerCount();
|
tracker.processMotionEvent(me, this);
|
||||||
for (int index = 0; index < pointerCount; index++) {
|
|
||||||
final int id = me.getPointerId(index);
|
|
||||||
final PointerTracker tracker = PointerTracker.getPointerTracker(id, this);
|
|
||||||
final int x = (int)me.getX(index);
|
|
||||||
final int y = (int)me.getY(index);
|
|
||||||
tracker.onMoveEvent(x, y, eventTime, me);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
final int index = me.getActionIndex();
|
|
||||||
final int id = me.getPointerId(index);
|
|
||||||
final int x = (int)me.getX(index);
|
|
||||||
final int y = (int)me.getY(index);
|
|
||||||
final PointerTracker tracker = PointerTracker.getPointerTracker(id, this);
|
|
||||||
tracker.processMotionEvent(action, x, y, eventTime, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -870,8 +870,23 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
||||||
mListener.onCancelBatchInput();
|
mListener.onCancelBatchInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processMotionEvent(final int action, final int x, final int y, final long eventTime,
|
public void processMotionEvent(final MotionEvent me, final KeyEventHandler handler) {
|
||||||
final KeyEventHandler handler) {
|
final int action = me.getActionMasked();
|
||||||
|
final long eventTime = me.getEventTime();
|
||||||
|
if (action == MotionEvent.ACTION_MOVE) {
|
||||||
|
final int pointerCount = me.getPointerCount();
|
||||||
|
for (int index = 0; index < pointerCount; index++) {
|
||||||
|
final int id = me.getPointerId(index);
|
||||||
|
final PointerTracker tracker = getPointerTracker(id, handler);
|
||||||
|
final int x = (int)me.getX(index);
|
||||||
|
final int y = (int)me.getY(index);
|
||||||
|
tracker.onMoveEvent(x, y, eventTime, me);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final int index = me.getActionIndex();
|
||||||
|
final int x = (int)me.getX(index);
|
||||||
|
final int y = (int)me.getY(index);
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
case MotionEvent.ACTION_POINTER_DOWN:
|
case MotionEvent.ACTION_POINTER_DOWN:
|
||||||
|
@ -881,16 +896,13 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
||||||
case MotionEvent.ACTION_POINTER_UP:
|
case MotionEvent.ACTION_POINTER_UP:
|
||||||
onUpEvent(x, y, eventTime);
|
onUpEvent(x, y, eventTime);
|
||||||
break;
|
break;
|
||||||
case MotionEvent.ACTION_MOVE:
|
|
||||||
onMoveEvent(x, y, eventTime, null);
|
|
||||||
break;
|
|
||||||
case MotionEvent.ACTION_CANCEL:
|
case MotionEvent.ACTION_CANCEL:
|
||||||
onCancelEvent(x, y, eventTime);
|
onCancelEvent(x, y, eventTime);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDownEvent(final int x, final int y, final long eventTime,
|
private void onDownEvent(final int x, final int y, final long eventTime,
|
||||||
final KeyEventHandler handler) {
|
final KeyEventHandler handler) {
|
||||||
if (DEBUG_EVENT) {
|
if (DEBUG_EVENT) {
|
||||||
printTouchEvent("onDownEvent:", x, y, eventTime);
|
printTouchEvent("onDownEvent:", x, y, eventTime);
|
||||||
|
@ -1005,7 +1017,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onMoveEvent(final int x, final int y, final long eventTime, final MotionEvent me) {
|
private void onMoveEvent(final int x, final int y, final long eventTime, final MotionEvent me) {
|
||||||
if (DEBUG_MOVE_EVENT) {
|
if (DEBUG_MOVE_EVENT) {
|
||||||
printTouchEvent("onMoveEvent:", x, y, eventTime);
|
printTouchEvent("onMoveEvent:", x, y, eventTime);
|
||||||
}
|
}
|
||||||
|
@ -1193,7 +1205,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onUpEvent(final int x, final int y, final long eventTime) {
|
private void onUpEvent(final int x, final int y, final long eventTime) {
|
||||||
if (DEBUG_EVENT) {
|
if (DEBUG_EVENT) {
|
||||||
printTouchEvent("onUpEvent :", x, y, eventTime);
|
printTouchEvent("onUpEvent :", x, y, eventTime);
|
||||||
}
|
}
|
||||||
|
@ -1293,7 +1305,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|
||||||
sPointerTrackerQueue.remove(this);
|
sPointerTrackerQueue.remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onCancelEvent(final int x, final int y, final long eventTime) {
|
private void onCancelEvent(final int x, final int y, final long eventTime) {
|
||||||
if (DEBUG_EVENT) {
|
if (DEBUG_EVENT) {
|
||||||
printTouchEvent("onCancelEvt:", x, y, eventTime);
|
printTouchEvent("onCancelEvt:", x, y, eventTime);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,56 +29,67 @@ public final class NonDistinctMultitouchHelper {
|
||||||
|
|
||||||
private int mOldPointerCount = 1;
|
private int mOldPointerCount = 1;
|
||||||
private Key mOldKey;
|
private Key mOldKey;
|
||||||
|
private int[] mLastCoords = CoordinateUtils.newInstance();
|
||||||
|
|
||||||
public void processMotionEvent(final MotionEvent me, final KeyEventHandler keyEventHandler) {
|
public void processMotionEvent(final MotionEvent me, final KeyEventHandler keyEventHandler) {
|
||||||
final int pointerCount = me.getPointerCount();
|
final int pointerCount = me.getPointerCount();
|
||||||
final int oldPointerCount = mOldPointerCount;
|
final int oldPointerCount = mOldPointerCount;
|
||||||
mOldPointerCount = pointerCount;
|
mOldPointerCount = pointerCount;
|
||||||
// Ignore continuous multitouch events because we can't trust the coordinates in mulitouch
|
// Ignore continuous multi-touch events because we can't trust the coordinates
|
||||||
// events.
|
// in multi-touch events.
|
||||||
if (pointerCount > 1 && oldPointerCount > 1) {
|
if (pointerCount > 1 && oldPointerCount > 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use only main (id=0) pointer tracker.
|
||||||
|
final PointerTracker mainTracker = PointerTracker.getPointerTracker(0, keyEventHandler);
|
||||||
final int action = me.getActionMasked();
|
final int action = me.getActionMasked();
|
||||||
final int index = me.getActionIndex();
|
final int index = me.getActionIndex();
|
||||||
final long eventTime = me.getEventTime();
|
final long eventTime = me.getEventTime();
|
||||||
final int x = (int)me.getX(index);
|
final long downTime = me.getDownTime();
|
||||||
final int y = (int)me.getY(index);
|
|
||||||
// Use only main (id=0) pointer tracker.
|
|
||||||
final PointerTracker mainTracker = PointerTracker.getPointerTracker(0, keyEventHandler);
|
|
||||||
|
|
||||||
// In single touch.
|
// In single-touch.
|
||||||
if (oldPointerCount == 1 && pointerCount == 1) {
|
if (oldPointerCount == 1 && pointerCount == 1) {
|
||||||
mainTracker.processMotionEvent(action, x, y, eventTime, keyEventHandler);
|
if (me.getPointerId(index) == mainTracker.mPointerId) {
|
||||||
|
mainTracker.processMotionEvent(me, keyEventHandler);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Inject a copied event.
|
||||||
|
injectMotionEvent(action, me.getX(index), me.getY(index), downTime, eventTime,
|
||||||
|
mainTracker, keyEventHandler);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Single-touch to multi-touch transition.
|
// Single-touch to multi-touch transition.
|
||||||
if (oldPointerCount == 1 && pointerCount == 2) {
|
if (oldPointerCount == 1 && pointerCount == 2) {
|
||||||
// Send an up event for the last pointer, be cause we can't trust the corrdinates of
|
// Send an up event for the last pointer, be cause we can't trust the coordinates of
|
||||||
// this multitouch event.
|
// this multi-touch event.
|
||||||
final int[] lastCoords = CoordinateUtils.newInstance();
|
mainTracker.getLastCoordinates(mLastCoords);
|
||||||
mainTracker.getLastCoordinates(lastCoords);
|
final int x = CoordinateUtils.x(mLastCoords);
|
||||||
mOldKey = mainTracker.getKeyOn(
|
final int y = CoordinateUtils.y(mLastCoords);
|
||||||
CoordinateUtils.x(lastCoords), CoordinateUtils.y(lastCoords));
|
mOldKey = mainTracker.getKeyOn(x, y);
|
||||||
// TODO: Stop calling PointerTracker.onUpEvent directly.
|
// Inject an artifact up event for the old key.
|
||||||
mainTracker.onUpEvent(
|
injectMotionEvent(MotionEvent.ACTION_UP, x, y, downTime, eventTime,
|
||||||
CoordinateUtils.x(lastCoords), CoordinateUtils.y(lastCoords), eventTime);
|
mainTracker, keyEventHandler);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Multi-touch to single touch transition.
|
// Multi-touch to single-touch transition.
|
||||||
if (oldPointerCount == 2 && pointerCount == 1) {
|
if (oldPointerCount == 2 && pointerCount == 1) {
|
||||||
// Send a down event for the latest pointer if the key is different from the
|
// Send a down event for the latest pointer if the key is different from the previous
|
||||||
// previous key.
|
// key.
|
||||||
|
final int x = (int)me.getX(index);
|
||||||
|
final int y = (int)me.getY(index);
|
||||||
final Key newKey = mainTracker.getKeyOn(x, y);
|
final Key newKey = mainTracker.getKeyOn(x, y);
|
||||||
if (mOldKey != newKey) {
|
if (mOldKey != newKey) {
|
||||||
// TODO: Stop calling PointerTracker.onDownEvent directly.
|
// Inject an artifact down event for the new key.
|
||||||
mainTracker.onDownEvent(x, y, eventTime, keyEventHandler);
|
// An artifact up event for the new key will usually be injected as a single-touch.
|
||||||
|
injectMotionEvent(MotionEvent.ACTION_DOWN, x, y, downTime, eventTime,
|
||||||
|
mainTracker, keyEventHandler);
|
||||||
if (action == MotionEvent.ACTION_UP) {
|
if (action == MotionEvent.ACTION_UP) {
|
||||||
// TODO: Stop calling PointerTracker.onUpEvent directly.
|
// Inject an artifact up event for the new key also.
|
||||||
mainTracker.onUpEvent(x, y, eventTime);
|
injectMotionEvent(MotionEvent.ACTION_UP, x, y, downTime, eventTime,
|
||||||
|
mainTracker, keyEventHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -87,4 +98,16 @@ public final class NonDistinctMultitouchHelper {
|
||||||
Log.w(TAG, "Unknown touch panel behavior: pointer count is "
|
Log.w(TAG, "Unknown touch panel behavior: pointer count is "
|
||||||
+ pointerCount + " (previously " + oldPointerCount + ")");
|
+ pointerCount + " (previously " + oldPointerCount + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void injectMotionEvent(final int action, final float x, final float y,
|
||||||
|
final long downTime, final long eventTime, final PointerTracker tracker,
|
||||||
|
final KeyEventHandler handler) {
|
||||||
|
final MotionEvent me = MotionEvent.obtain(
|
||||||
|
downTime, eventTime, action, x, y, 0 /* metaState */);
|
||||||
|
try {
|
||||||
|
tracker.processMotionEvent(me, handler);
|
||||||
|
} finally {
|
||||||
|
me.recycle();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue