summaryrefslogtreecommitdiffstats
path: root/core/java/android/inputmethodservice/SoftInputWindow.java
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2011-05-06 18:20:01 -0700
committerJeff Brown <jeffbrown@google.com>2011-05-13 12:11:17 -0700
commitfe9f8ab03a63b1037f07dd85799fbea80ec6adaa (patch)
treec0cfa91d0537321eeee0ede693fb414d8778a1a2 /core/java/android/inputmethodservice/SoftInputWindow.java
parent1abf1c59f8b15d5b4b198063b884e268bd79fb32 (diff)
downloadframeworks_base-fe9f8ab03a63b1037f07dd85799fbea80ec6adaa.zip
frameworks_base-fe9f8ab03a63b1037f07dd85799fbea80ec6adaa.tar.gz
frameworks_base-fe9f8ab03a63b1037f07dd85799fbea80ec6adaa.tar.bz2
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
Diffstat (limited to 'core/java/android/inputmethodservice/SoftInputWindow.java')
-rw-r--r--core/java/android/inputmethodservice/SoftInputWindow.java57
1 files changed, 11 insertions, 46 deletions
diff --git a/core/java/android/inputmethodservice/SoftInputWindow.java b/core/java/android/inputmethodservice/SoftInputWindow.java
index 343242e..7159260 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());
- }
}