From fe9f8ab03a63b1037f07dd85799fbea80ec6adaa Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Fri, 6 May 2011 18:20:01 -0700 Subject: Add initial API for stylus and mouse buttons. Added the concept of pointer properties in a MotionEvent. This is currently used to track the pointer tool type to enable applications to distinguish finger touches from a stylus. Button states are also reported to application as part of touch events. There are no new actions for detecting changes in button states. The application should instead query the button state from the MotionEvent and take appropriate action as needed. A good time to check the button state is on ACTION_DOWN. As a side-effect, applications that do not support multiple buttons will treat primary, secondary and tertiary buttons identically for all touch events. The back button on the mouse is mapped to KEYCODE_BACK and the forward button is mapped to KEYCODE_FORWARD. Added basic plumbing for the secondary mouse button to invoke the context menu, particularly in lists. Added clamp and split methods on MotionEvent to take care of common filtering operations so we don't have them scattered in multiple places across the framework. Bug: 4260011 Change-Id: Ie992b4d4e00c8f2e76b961da0a902145b27f6d83 --- .../internal/widget/PointerLocationView.java | 34 +++++++--------------- 1 file changed, 11 insertions(+), 23 deletions(-) (limited to 'core/java/com/android/internal/widget/PointerLocationView.java') diff --git a/core/java/com/android/internal/widget/PointerLocationView.java b/core/java/com/android/internal/widget/PointerLocationView.java index c34cb9e..d789584 100644 --- a/core/java/com/android/internal/widget/PointerLocationView.java +++ b/core/java/com/android/internal/widget/PointerLocationView.java @@ -320,7 +320,8 @@ public class PointerLocationView extends View { } } - private void logPointerCoords(int action, int index, MotionEvent.PointerCoords coords, int id) { + private void logPointerCoords(int action, int index, MotionEvent.PointerCoords coords, int id, + int toolType, int buttonState) { final String prefix; switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: @@ -386,26 +387,16 @@ public class PointerLocationView extends View { .append("deg") .append(" VScroll=").append(coords.getAxisValue(MotionEvent.AXIS_VSCROLL), 1) .append(" HScroll=").append(coords.getAxisValue(MotionEvent.AXIS_HSCROLL), 1) + .append(" ToolType=").append(MotionEvent.toolTypeToString(toolType)) + .append(" ButtonState=").append(MotionEvent.buttonStateToString(buttonState)) .toString()); } public void addPointerEvent(MotionEvent event) { synchronized (mPointers) { - int action = event.getAction(); - - //Log.i(TAG, "Motion: action=0x" + Integer.toHexString(action) - // + " pointers=" + event.getPointerCount()); - + final int action = event.getAction(); int NP = mPointers.size(); - - //mRect.set(0, 0, getWidth(), mHeaderBottom+1); - //invalidate(mRect); - //if (mCurDown) { - // mRect.set(mCurX-mCurWidth-3, mCurY-mCurWidth-3, - // mCurX+mCurWidth+3, mCurY+mCurWidth+3); - //} else { - // mRect.setEmpty(); - //} + if (action == MotionEvent.ACTION_DOWN || (action & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_DOWN) { final int index = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) @@ -456,7 +447,8 @@ public class PointerLocationView extends View { final PointerCoords coords = ps != null ? ps.mCoords : mHoverCoords; event.getHistoricalPointerCoords(i, historyPos, coords); if (mPrintCoords) { - logPointerCoords(action, i, coords, id); + logPointerCoords(action, i, coords, id, + event.getToolType(i), event.getButtonState()); } if (ps != null) { ps.addTrace(coords.x, coords.y); @@ -469,7 +461,8 @@ public class PointerLocationView extends View { final PointerCoords coords = ps != null ? ps.mCoords : mHoverCoords; event.getPointerCoords(i, coords); if (mPrintCoords) { - logPointerCoords(action, i, coords, id); + logPointerCoords(action, i, coords, id, + event.getToolType(i), event.getButtonState()); } if (ps != null) { ps.addTrace(coords.x, coords.y); @@ -500,12 +493,7 @@ public class PointerLocationView extends View { ps.addTrace(Float.NaN, Float.NaN); } } - - //if (mCurDown) { - // mRect.union(mCurX-mCurWidth-3, mCurY-mCurWidth-3, - // mCurX+mCurWidth+3, mCurY+mCurWidth+3); - //} - //invalidate(mRect); + postInvalidate(); } } -- cgit v1.1