Skip to content

Commit b499884

Browse files
author
Jim Miller
committed
Better handling of multiple touch events in GlowPadView
This fixes a bug where a secondary touch event from the edge of the screen would cause GlowPadView to choose the wrong target. The issue is resolved by keeping track of pointer ids and only allowing the one that initiated the gesture to complete it. Fixes bug 7133500 Change-Id: If296b60af2421bfa1a9a082e608ba77b2392a218
1 parent 6eeff85 commit b499884

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

core/java/com/android/internal/widget/multiwaveview/GlowPadView.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ public void onAnimationEnd(Animator animator) {
197197
private Tweener mBackgroundAnimator;
198198
private PointCloud mPointCloud;
199199
private float mInnerRadius;
200+
private int mPointerId;
200201

201202
public GlowPadView(Context context) {
202203
this(context, null);
@@ -737,9 +738,10 @@ private void startBackgroundAnimation(int duration, float alpha) {
737738

738739
@Override
739740
public boolean onTouchEvent(MotionEvent event) {
740-
final int action = event.getAction();
741+
final int action = event.getActionMasked();
741742
boolean handled = false;
742743
switch (action) {
744+
case MotionEvent.ACTION_POINTER_DOWN:
743745
case MotionEvent.ACTION_DOWN:
744746
if (DEBUG) Log.v(TAG, "*** DOWN ***");
745747
handleDown(event);
@@ -753,6 +755,7 @@ public boolean onTouchEvent(MotionEvent event) {
753755
handled = true;
754756
break;
755757

758+
case MotionEvent.ACTION_POINTER_UP:
756759
case MotionEvent.ACTION_UP:
757760
if (DEBUG) Log.v(TAG, "*** UP ***");
758761
handleMove(event);
@@ -766,6 +769,7 @@ public boolean onTouchEvent(MotionEvent event) {
766769
handleCancel(event);
767770
handled = true;
768771
break;
772+
769773
}
770774
invalidate();
771775
return handled ? true : super.onTouchEvent(event);
@@ -777,19 +781,24 @@ private void updateGlowPosition(float x, float y) {
777781
}
778782

779783
private void handleDown(MotionEvent event) {
780-
float eventX = event.getX();
781-
float eventY = event.getY();
784+
int actionIndex = event.getActionIndex();
785+
float eventX = event.getX(actionIndex);
786+
float eventY = event.getY(actionIndex);
782787
switchToState(STATE_START, eventX, eventY);
783788
if (!trySwitchToFirstTouchState(eventX, eventY)) {
784789
mDragging = false;
785790
} else {
791+
mPointerId = event.getPointerId(actionIndex);
786792
updateGlowPosition(eventX, eventY);
787793
}
788794
}
789795

790796
private void handleUp(MotionEvent event) {
791797
if (DEBUG && mDragging) Log.v(TAG, "** Handle RELEASE");
792-
switchToState(STATE_FINISH, event.getX(), event.getY());
798+
int actionIndex = event.getActionIndex();
799+
if (event.getPointerId(actionIndex) == mPointerId) {
800+
switchToState(STATE_FINISH, event.getX(actionIndex), event.getY(actionIndex));
801+
}
793802
}
794803

795804
private void handleCancel(MotionEvent event) {
@@ -802,7 +811,9 @@ private void handleCancel(MotionEvent event) {
802811

803812
// mActiveTarget = -1; // Drop the active target if canceled.
804813

805-
switchToState(STATE_FINISH, event.getX(), event.getY());
814+
int actionIndex = event.findPointerIndex(mPointerId);
815+
actionIndex = actionIndex == -1 ? 0 : actionIndex;
816+
switchToState(STATE_FINISH, event.getX(actionIndex), event.getY(actionIndex));
806817
}
807818

808819
private void handleMove(MotionEvent event) {
@@ -812,9 +823,17 @@ private void handleMove(MotionEvent event) {
812823
int ntargets = targets.size();
813824
float x = 0.0f;
814825
float y = 0.0f;
826+
int actionIndex = event.findPointerIndex(mPointerId);
827+
828+
if (actionIndex == -1) {
829+
return; // no data for this pointer
830+
}
831+
815832
for (int k = 0; k < historySize + 1; k++) {
816-
float eventX = k < historySize ? event.getHistoricalX(k) : event.getX();
817-
float eventY = k < historySize ? event.getHistoricalY(k) : event.getY();
833+
float eventX = k < historySize ? event.getHistoricalX(actionIndex, k)
834+
: event.getX(actionIndex);
835+
float eventY = k < historySize ? event.getHistoricalY(actionIndex, k)
836+
: event.getY(actionIndex);
818837
// tx and ty are relative to wave center
819838
float tx = eventX - mWaveCenterX;
820839
float ty = eventY - mWaveCenterY;

0 commit comments

Comments
 (0)