Handle CANCEL touch events

Handling this event is part of the API but was never done. This caused
unstoppable key-repeat.

This event isn't common, the only way I found on Android 10 is to switch
to the emoji keyboard while holding a key. Some apps might cause this
event more often.
This commit is contained in:
Jules Aguillon 2022-03-15 20:44:02 +01:00
parent fadedfd58f
commit d53ee811d9
2 changed files with 16 additions and 3 deletions

View File

@ -115,7 +115,7 @@ public class Keyboard2View extends View
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
_pointers.onTouchUp(event.getPointerId(event.getActionIndex()));
break ;
break;
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
p = event.getActionIndex();
@ -124,11 +124,14 @@ public class Keyboard2View extends View
KeyboardData.Key key = getKeyAtPosition(tx, ty);
if (key != null)
_pointers.onTouchDown(tx, ty, event.getPointerId(p), key);
break ;
break;
case MotionEvent.ACTION_MOVE:
for (p = 0; p < event.getPointerCount(); p++)
_pointers.onTouchMove(event.getX(p), event.getY(p), event.getPointerId(p));
break ;
break;
case MotionEvent.ACTION_CANCEL:
_pointers.onTouchCancel(event.getPointerId(event.getActionIndex()));
break;
default:
return (false);
}

View File

@ -95,6 +95,16 @@ public final class Pointers implements Handler.Callback
}
}
public void onTouchCancel(int pointerId)
{
Pointer ptr = getPtr(pointerId);
if (ptr == null)
return;
stopKeyRepeat(ptr);
removePtr(ptr);
_handler.onPointerFlagsChanged();
}
public void onTouchDown(float x, float y, int pointerId, KeyboardData.Key key)
{
KeyValue value = key.key0;