Android: Update touch buttons on down as well as move

This commit is contained in:
Connor McLaughlin 2021-03-06 15:59:02 +10:00
parent 977f5b69c2
commit b80d4d5675

View file

@ -440,35 +440,7 @@ public class TouchscreenControllerView extends FrameLayout {
return false;
}
private boolean handleTouchEvent(MotionEvent event) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_UP: {
if (!AndroidHostInterface.hasInstanceAndEmulationThreadIsRunning())
return false;
mGlidePairs.clear();
for (TouchscreenControllerButtonView buttonView : mButtonViews) {
buttonView.setPressed(false);
}
for (TouchscreenControllerAxisView axisView : mAxisViews) {
axisView.setUnpressed();
}
return true;
}
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
case MotionEvent.ACTION_POINTER_UP: {
int pointerID = event.getPointerId(event.getActionIndex());
if (mGlidePairs.containsKey(pointerID))
mGlidePairs.remove(pointerID);
return true;
}
case MotionEvent.ACTION_MOVE: {
private boolean updateTouchButtonsFromEvent(MotionEvent event) {
if (!AndroidHostInterface.hasInstanceAndEmulationThreadIsRunning())
return false;
@ -530,6 +502,38 @@ public class TouchscreenControllerView extends FrameLayout {
return true;
}
private boolean handleTouchEvent(MotionEvent event) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_UP: {
if (!AndroidHostInterface.hasInstanceAndEmulationThreadIsRunning())
return false;
mGlidePairs.clear();
for (TouchscreenControllerButtonView buttonView : mButtonViews) {
buttonView.setPressed(false);
}
for (TouchscreenControllerAxisView axisView : mAxisViews) {
axisView.setUnpressed();
}
return true;
}
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
case MotionEvent.ACTION_POINTER_UP: {
int pointerID = event.getPointerId(event.getActionIndex());
if (mGlidePairs.containsKey(pointerID))
mGlidePairs.remove(pointerID);
return updateTouchButtonsFromEvent(event);
}
case MotionEvent.ACTION_MOVE: {
return updateTouchButtonsFromEvent(event);
}
}
return false;