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
1 changed files with 65 additions and 61 deletions

View File

@ -440,35 +440,7 @@ public class TouchscreenControllerView extends FrameLayout {
return false; return false;
} }
private boolean handleTouchEvent(MotionEvent event) { private boolean updateTouchButtonsFromEvent(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: {
if (!AndroidHostInterface.hasInstanceAndEmulationThreadIsRunning()) if (!AndroidHostInterface.hasInstanceAndEmulationThreadIsRunning())
return false; return false;
@ -530,6 +502,38 @@ public class TouchscreenControllerView extends FrameLayout {
return true; 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; return false;