Android: Prevent stuck on-screen buttons
This commit is contained in:
parent
6190b1c4e2
commit
3bd8890486
|
@ -133,23 +133,22 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
|||
{
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
case MotionEvent.ACTION_POINTER_DOWN:
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
// If a pointer enters the bounds of a button, press that button.
|
||||
if (button.getBounds().contains((int)event.getX(pointerIndex), (int)event.getY(pointerIndex)))
|
||||
{
|
||||
button.setPressedState(true);
|
||||
button.setTrackId(event.getPointerId(pointerIndex));
|
||||
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, button.getId(), ButtonState.PRESSED);
|
||||
}
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
case MotionEvent.ACTION_POINTER_UP:
|
||||
// If a pointer ends, release the button it was pressing.
|
||||
if (button.getBounds().contains((int)event.getX(pointerIndex), (int)event.getY(pointerIndex)))
|
||||
if (button.getTrackId() == event.getPointerId(pointerIndex))
|
||||
{
|
||||
button.setPressedState(false);
|
||||
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, button.getId(), ButtonState.RELEASED);
|
||||
}
|
||||
|
||||
button.setPressedState(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +160,6 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
|||
{
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
case MotionEvent.ACTION_POINTER_DOWN:
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
// If a pointer enters the bounds of a button, press that button.
|
||||
if (dpad.getBounds().contains((int)event.getX(pointerIndex), (int)event.getY(pointerIndex)))
|
||||
{
|
||||
|
@ -191,19 +189,20 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
|||
}
|
||||
|
||||
setDpadState(dpad, up, down, left, right);
|
||||
dpad.setTrackId(event.getPointerId(pointerIndex));
|
||||
}
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
case MotionEvent.ACTION_POINTER_UP:
|
||||
// If a pointer ends, release the buttons.
|
||||
if (dpad.getBounds().contains((int)event.getX(pointerIndex), (int)event.getY(pointerIndex)))
|
||||
if (dpad.getTrackId() == event.getPointerId(pointerIndex))
|
||||
{
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
dpad.setState(InputOverlayDrawableDpad.STATE_DEFAULT);
|
||||
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(i), ButtonState.RELEASED);
|
||||
}
|
||||
}
|
||||
dpad.setState(InputOverlayDrawableDpad.STATE_DEFAULT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ public final class InputOverlayDrawableButton
|
|||
{
|
||||
// The ID identifying what type of button this Drawable represents.
|
||||
private int mButtonType;
|
||||
private int mTrackId;
|
||||
private int mPreviousTouchX, mPreviousTouchY;
|
||||
private int mControlPositionX, mControlPositionY;
|
||||
private int mWidth;
|
||||
|
@ -57,6 +58,16 @@ public final class InputOverlayDrawableButton
|
|||
return mButtonType;
|
||||
}
|
||||
|
||||
public void setTrackId(int trackId)
|
||||
{
|
||||
mTrackId = trackId;
|
||||
}
|
||||
|
||||
public int getTrackId()
|
||||
{
|
||||
return mTrackId;
|
||||
}
|
||||
|
||||
public boolean onConfigureTouch(MotionEvent event)
|
||||
{
|
||||
int pointerIndex = event.getActionIndex();
|
||||
|
|
|
@ -21,6 +21,7 @@ public final class InputOverlayDrawableDpad
|
|||
{
|
||||
// The ID identifying what type of button this Drawable represents.
|
||||
private int[] mButtonType = new int[4];
|
||||
private int mTrackId;
|
||||
private int mPreviousTouchX, mPreviousTouchY;
|
||||
private int mControlPositionX, mControlPositionY;
|
||||
private int mWidth;
|
||||
|
@ -135,6 +136,16 @@ public final class InputOverlayDrawableDpad
|
|||
return mButtonType[direction];
|
||||
}
|
||||
|
||||
public void setTrackId(int trackId)
|
||||
{
|
||||
mTrackId = trackId;
|
||||
}
|
||||
|
||||
public int getTrackId()
|
||||
{
|
||||
return mTrackId;
|
||||
}
|
||||
|
||||
public boolean onConfigureTouch(MotionEvent event)
|
||||
{
|
||||
int pointerIndex = event.getActionIndex();
|
||||
|
|
Loading…
Reference in New Issue