summaryrefslogtreecommitdiffstats
path: root/core/java/com/android/internal/widget/PointerLocationView.java
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2011-08-18 11:20:58 -0700
committerJeff Brown <jeffbrown@google.com>2011-08-19 15:02:26 -0700
commit65fd251c3913fc921468a3dad190810db19eb9df (patch)
tree7cc9e086b96a4e2c77ec5b77aab6bed5679e89f0 /core/java/com/android/internal/widget/PointerLocationView.java
parentc0a2222552f48a2543a64a4cbe913d0b9ffc3cbf (diff)
downloadframeworks_base-65fd251c3913fc921468a3dad190810db19eb9df.zip
frameworks_base-65fd251c3913fc921468a3dad190810db19eb9df.tar.gz
frameworks_base-65fd251c3913fc921468a3dad190810db19eb9df.tar.bz2
Input system bug fixes, particularly for stylus.
Bug: 5049148 Finished stylus support, including support for indirect stylus and mouse tools. Added TILT axis. When stylus tilt X/Y is available, it is transformed into an orientation and tilt inclination which is a more convenient representation and a simpler extension to the exiting API. Touch devices now only report touch data using a single input source. Previously touch devices in pointer mode would report both absolute touch pad data and cooked pointer gestures. Now we just pick one. The touch device switches modes as needed when the focused application enables/disables pointer gestures. This change greatly simplifies the code and reduces the load on the input dispatcher. Fixed an incorrect assumption that the value of ABS_(MT_)DISTANCE would be zero whenever the stylus was in direct contact. It appears that the correct way to determine whether the stylus is in direct contact (rather than hovering) is by checking for a non-zero reported pressure. Added code to read the initial state of tool buttons and axis values when the input devices are initialized or reset. This fixes problems where the input mapper state might have the wrong initial state. Moved responsibility for cancelling pending inputs (keys down, touches, etc.) to the InputDispatcher by sending it a device reset notification. This frees the InputReader from having to synthesize events during reset, which was cumbersome and somewhat brittle to begin with. Consolidated more of the common accumulator logic from SingleTouchInputMapper and MultiTouchInputMapper into TouchInputMapper. Improved the PointerLocation output. Change-Id: I595d3647f7fd7cb1e3eff8b3c76b85043b5fe2f0
Diffstat (limited to 'core/java/com/android/internal/widget/PointerLocationView.java')
-rw-r--r--core/java/com/android/internal/widget/PointerLocationView.java91
1 files changed, 70 insertions, 21 deletions
diff --git a/core/java/com/android/internal/widget/PointerLocationView.java b/core/java/com/android/internal/widget/PointerLocationView.java
index bf1c637..158291b 100644
--- a/core/java/com/android/internal/widget/PointerLocationView.java
+++ b/core/java/com/android/internal/widget/PointerLocationView.java
@@ -46,6 +46,7 @@ public class PointerLocationView extends View {
// Most recent coordinates.
private PointerCoords mCoords = new PointerCoords();
+ private int mToolType;
// Most recent velocity.
private float mXVelocity;
@@ -88,7 +89,7 @@ public class PointerLocationView extends View {
private int mMaxNumPointers;
private int mActivePointerId;
private final ArrayList<PointerState> mPointers = new ArrayList<PointerState>();
- private final PointerCoords mHoverCoords = new PointerCoords();
+ private final PointerCoords mTempCoords = new PointerCoords();
private final VelocityTracker mVelocity;
@@ -306,22 +307,66 @@ public class PointerLocationView extends View {
ps.mCoords.toolMinor, ps.mCoords.orientation, mPaint);
// Draw the orientation arrow.
+ float arrowSize = ps.mCoords.toolMajor * 0.7f;
+ if (arrowSize < 20) {
+ arrowSize = 20;
+ }
mPaint.setARGB(255, pressureLevel, 255, 0);
- float orientationVectorX = (float) (Math.sin(-ps.mCoords.orientation)
- * ps.mCoords.toolMajor * 0.7);
- float orientationVectorY = (float) (Math.cos(-ps.mCoords.orientation)
- * ps.mCoords.toolMajor * 0.7);
- canvas.drawLine(
- ps.mCoords.x - orientationVectorX, ps.mCoords.y - orientationVectorY,
- ps.mCoords.x + orientationVectorX, ps.mCoords.y + orientationVectorY,
- mPaint);
+ float orientationVectorX = (float) (Math.sin(ps.mCoords.orientation)
+ * arrowSize);
+ float orientationVectorY = (float) (-Math.cos(ps.mCoords.orientation)
+ * arrowSize);
+ if (ps.mToolType == MotionEvent.TOOL_TYPE_STYLUS
+ || ps.mToolType == MotionEvent.TOOL_TYPE_ERASER) {
+ // Show full circle orientation.
+ canvas.drawLine(ps.mCoords.x, ps.mCoords.y,
+ ps.mCoords.x + orientationVectorX,
+ ps.mCoords.y + orientationVectorY,
+ mPaint);
+ } else {
+ // Show half circle orientation.
+ canvas.drawLine(
+ ps.mCoords.x - orientationVectorX,
+ ps.mCoords.y - orientationVectorY,
+ ps.mCoords.x + orientationVectorX,
+ ps.mCoords.y + orientationVectorY,
+ mPaint);
+ }
+
+ // Draw the tilt point along the orientation arrow.
+ float tiltScale = (float) Math.sin(
+ ps.mCoords.getAxisValue(MotionEvent.AXIS_TILT));
+ canvas.drawCircle(
+ ps.mCoords.x + orientationVectorX * tiltScale,
+ ps.mCoords.y + orientationVectorY * tiltScale,
+ 3.0f, mPaint);
}
}
}
}
-
- private void logPointerCoords(int action, int index, MotionEvent.PointerCoords coords, int id,
- int toolType, int buttonState) {
+
+ private void logMotionEvent(String type, MotionEvent event) {
+ final int action = event.getAction();
+ final int N = event.getHistorySize();
+ final int NI = event.getPointerCount();
+ for (int historyPos = 0; historyPos < N; historyPos++) {
+ for (int i = 0; i < NI; i++) {
+ final int id = event.getPointerId(i);
+ event.getHistoricalPointerCoords(i, historyPos, mTempCoords);
+ logCoords(type, action, i, mTempCoords, id,
+ event.getToolType(i), event.getButtonState());
+ }
+ }
+ for (int i = 0; i < NI; i++) {
+ final int id = event.getPointerId(i);
+ event.getPointerCoords(i, mTempCoords);
+ logCoords(type, action, i, mTempCoords, id,
+ event.getToolType(i), event.getButtonState());
+ }
+ }
+
+ private void logCoords(String type, 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:
@@ -373,7 +418,7 @@ public class PointerLocationView extends View {
}
Log.i(TAG, mText.clear()
- .append("Pointer ").append(id + 1)
+ .append(type).append(" id ").append(id + 1)
.append(": ")
.append(prefix)
.append(" (").append(coords.x, 3).append(", ").append(coords.y, 3)
@@ -385,6 +430,9 @@ public class PointerLocationView extends View {
.append(" ToolMinor=").append(coords.toolMinor, 3)
.append(" Orientation=").append((float)(coords.orientation * 180 / Math.PI), 1)
.append("deg")
+ .append(" Tilt=").append((float)(
+ coords.getAxisValue(MotionEvent.AXIS_TILT) * 180 / Math.PI), 1)
+ .append("deg")
.append(" Distance=").append(coords.getAxisValue(MotionEvent.AXIS_DISTANCE), 1)
.append(" VScroll=").append(coords.getAxisValue(MotionEvent.AXIS_VSCROLL), 1)
.append(" HScroll=").append(coords.getAxisValue(MotionEvent.AXIS_HSCROLL), 1)
@@ -445,10 +493,10 @@ public class PointerLocationView extends View {
for (int i = 0; i < NI; i++) {
final int id = event.getPointerId(i);
final PointerState ps = mCurDown ? mPointers.get(id) : null;
- final PointerCoords coords = ps != null ? ps.mCoords : mHoverCoords;
+ final PointerCoords coords = ps != null ? ps.mCoords : mTempCoords;
event.getHistoricalPointerCoords(i, historyPos, coords);
if (mPrintCoords) {
- logPointerCoords(action, i, coords, id,
+ logCoords("Pointer", action, i, coords, id,
event.getToolType(i), event.getButtonState());
}
if (ps != null) {
@@ -459,16 +507,17 @@ public class PointerLocationView extends View {
for (int i = 0; i < NI; i++) {
final int id = event.getPointerId(i);
final PointerState ps = mCurDown ? mPointers.get(id) : null;
- final PointerCoords coords = ps != null ? ps.mCoords : mHoverCoords;
+ final PointerCoords coords = ps != null ? ps.mCoords : mTempCoords;
event.getPointerCoords(i, coords);
if (mPrintCoords) {
- logPointerCoords(action, i, coords, id,
+ logCoords("Pointer", action, i, coords, id,
event.getToolType(i), event.getButtonState());
}
if (ps != null) {
ps.addTrace(coords.x, coords.y);
ps.mXVelocity = mVelocity.getXVelocity(id);
ps.mYVelocity = mVelocity.getYVelocity(id);
+ ps.mToolType = event.getToolType(i);
}
}
@@ -515,11 +564,11 @@ public class PointerLocationView extends View {
if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) {
addPointerEvent(event);
} else if ((source & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
- Log.i(TAG, "Joystick: " + event);
+ logMotionEvent("Joystick", event);
} else if ((source & InputDevice.SOURCE_CLASS_POSITION) != 0) {
- Log.i(TAG, "Position: " + event);
+ logMotionEvent("Position", event);
} else {
- Log.i(TAG, "Generic: " + event);
+ logMotionEvent("Generic", event);
}
return true;
}
@@ -563,7 +612,7 @@ public class PointerLocationView extends View {
@Override
public boolean onTrackballEvent(MotionEvent event) {
- Log.i(TAG, "Trackball: " + event);
+ logMotionEvent("Trackball", event);
return true;
}