summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJim Miller <jaggies@google.com>2012-09-23 19:03:19 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-09-23 19:03:20 -0700
commit26c5686b7e3bf0ba238c55caa3e86447bab7cc61 (patch)
treed2be4b6a2d842870ce298f5888dbbcbc066a4de7 /core
parent49397ac93ce3cf4fc38d00b1099a6cd9075cee8a (diff)
parentb499884ba1fa9577363524d1f28100627926d3b6 (diff)
downloadframeworks_base-26c5686b7e3bf0ba238c55caa3e86447bab7cc61.zip
frameworks_base-26c5686b7e3bf0ba238c55caa3e86447bab7cc61.tar.gz
frameworks_base-26c5686b7e3bf0ba238c55caa3e86447bab7cc61.tar.bz2
Merge "Better handling of multiple touch events in GlowPadView" into jb-mr1-dev
Diffstat (limited to 'core')
-rw-r--r--core/java/com/android/internal/widget/multiwaveview/GlowPadView.java33
1 files changed, 26 insertions, 7 deletions
diff --git a/core/java/com/android/internal/widget/multiwaveview/GlowPadView.java b/core/java/com/android/internal/widget/multiwaveview/GlowPadView.java
index 7c1f266..549d74c 100644
--- a/core/java/com/android/internal/widget/multiwaveview/GlowPadView.java
+++ b/core/java/com/android/internal/widget/multiwaveview/GlowPadView.java
@@ -196,6 +196,7 @@ public class GlowPadView extends View {
private Tweener mBackgroundAnimator;
private PointCloud mPointCloud;
private float mInnerRadius;
+ private int mPointerId;
public GlowPadView(Context context) {
this(context, null);
@@ -736,9 +737,10 @@ public class GlowPadView extends View {
@Override
public boolean onTouchEvent(MotionEvent event) {
- final int action = event.getAction();
+ final int action = event.getActionMasked();
boolean handled = false;
switch (action) {
+ case MotionEvent.ACTION_POINTER_DOWN:
case MotionEvent.ACTION_DOWN:
if (DEBUG) Log.v(TAG, "*** DOWN ***");
handleDown(event);
@@ -752,6 +754,7 @@ public class GlowPadView extends View {
handled = true;
break;
+ case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_UP:
if (DEBUG) Log.v(TAG, "*** UP ***");
handleMove(event);
@@ -765,6 +768,7 @@ public class GlowPadView extends View {
handleCancel(event);
handled = true;
break;
+
}
invalidate();
return handled ? true : super.onTouchEvent(event);
@@ -776,19 +780,24 @@ public class GlowPadView extends View {
}
private void handleDown(MotionEvent event) {
- float eventX = event.getX();
- float eventY = event.getY();
+ int actionIndex = event.getActionIndex();
+ float eventX = event.getX(actionIndex);
+ float eventY = event.getY(actionIndex);
switchToState(STATE_START, eventX, eventY);
if (!trySwitchToFirstTouchState(eventX, eventY)) {
mDragging = false;
} else {
+ mPointerId = event.getPointerId(actionIndex);
updateGlowPosition(eventX, eventY);
}
}
private void handleUp(MotionEvent event) {
if (DEBUG && mDragging) Log.v(TAG, "** Handle RELEASE");
- switchToState(STATE_FINISH, event.getX(), event.getY());
+ int actionIndex = event.getActionIndex();
+ if (event.getPointerId(actionIndex) == mPointerId) {
+ switchToState(STATE_FINISH, event.getX(actionIndex), event.getY(actionIndex));
+ }
}
private void handleCancel(MotionEvent event) {
@@ -801,7 +810,9 @@ public class GlowPadView extends View {
// mActiveTarget = -1; // Drop the active target if canceled.
- switchToState(STATE_FINISH, event.getX(), event.getY());
+ int actionIndex = event.findPointerIndex(mPointerId);
+ actionIndex = actionIndex == -1 ? 0 : actionIndex;
+ switchToState(STATE_FINISH, event.getX(actionIndex), event.getY(actionIndex));
}
private void handleMove(MotionEvent event) {
@@ -811,9 +822,17 @@ public class GlowPadView extends View {
int ntargets = targets.size();
float x = 0.0f;
float y = 0.0f;
+ int actionIndex = event.findPointerIndex(mPointerId);
+
+ if (actionIndex == -1) {
+ return; // no data for this pointer
+ }
+
for (int k = 0; k < historySize + 1; k++) {
- float eventX = k < historySize ? event.getHistoricalX(k) : event.getX();
- float eventY = k < historySize ? event.getHistoricalY(k) : event.getY();
+ float eventX = k < historySize ? event.getHistoricalX(actionIndex, k)
+ : event.getX(actionIndex);
+ float eventY = k < historySize ? event.getHistoricalY(actionIndex, k)
+ : event.getY(actionIndex);
// tx and ty are relative to wave center
float tx = eventX - mWaveCenterX;
float ty = eventY - mWaveCenterY;