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 --- .../inputmethodservice/SoftInputWindow.java | 57 +++++----------------- 1 file changed, 11 insertions(+), 46 deletions(-) (limited to 'core/java/android/inputmethodservice/SoftInputWindow.java') diff --git a/core/java/android/inputmethodservice/SoftInputWindow.java b/core/java/android/inputmethodservice/SoftInputWindow.java index 343242ec39aa..7159260f2648 100644 --- a/core/java/android/inputmethodservice/SoftInputWindow.java +++ b/core/java/android/inputmethodservice/SoftInputWindow.java @@ -73,8 +73,17 @@ class SoftInputWindow extends Dialog { @Override public boolean dispatchTouchEvent(MotionEvent ev) { getWindow().getDecorView().getHitRect(mBounds); - final MotionEvent event = clipMotionEvent(ev, mBounds); - return super.dispatchTouchEvent(event); + + if (ev.isWithinBoundsNoHistory(mBounds.left, mBounds.top, + mBounds.right - 1, mBounds.bottom - 1)) { + return super.dispatchTouchEvent(ev); + } else { + MotionEvent temp = ev.clampNoHistory(mBounds.left, mBounds.top, + mBounds.right - 1, mBounds.bottom - 1); + boolean handled = super.dispatchTouchEvent(temp); + temp.recycle(); + return handled; + } } /** @@ -163,48 +172,4 @@ class SoftInputWindow extends Dialog { WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_DIM_BEHIND); } - - private static MotionEvent clipMotionEvent(MotionEvent me, Rect bounds) { - final int pointerCount = me.getPointerCount(); - boolean shouldClip = false; - for (int pointerIndex = 0; pointerIndex < pointerCount; pointerIndex++) { - final int x = (int)me.getX(pointerIndex); - final int y = (int)me.getY(pointerIndex); - if (!bounds.contains(x, y)) { - shouldClip = true; - break; - } - } - if (!shouldClip) - return me; - - if (pointerCount == 1) { - final int x = (int)me.getX(); - final int y = (int)me.getY(); - me.setLocation( - Math.max(bounds.left, Math.min(x, bounds.right - 1)), - Math.max(bounds.top, Math.min(y, bounds.bottom - 1))); - return me; - } - - final int[] pointerIds = new int[pointerCount]; - final MotionEvent.PointerCoords[] pointerCoords = - new MotionEvent.PointerCoords[pointerCount]; - for (int pointerIndex = 0; pointerIndex < pointerCount; pointerIndex++) { - pointerIds[pointerIndex] = me.getPointerId(pointerIndex); - final MotionEvent.PointerCoords coords = new MotionEvent.PointerCoords(); - me.getPointerCoords(pointerIndex, coords); - pointerCoords[pointerIndex] = coords; - final int x = (int)coords.x; - final int y = (int)coords.y; - if (!bounds.contains(x, y)) { - coords.x = Math.max(bounds.left, Math.min(x, bounds.right - 1)); - coords.y = Math.max(bounds.top, Math.min(y, bounds.bottom - 1)); - } - } - return MotionEvent.obtain( - me.getDownTime(), me.getEventTime(), me.getAction(), pointerCount, pointerIds, - pointerCoords, me.getMetaState(), me.getXPrecision(), me.getYPrecision(), - me.getDeviceId(), me.getEdgeFlags(), me.getSource(), me.getFlags()); - } } -- cgit v1.2.3