diff --git a/virtualjoystick/src/main/java/io/github/controlwear/virtual/joystick/android/JoystickView.java b/virtualjoystick/src/main/java/io/github/controlwear/virtual/joystick/android/JoystickView.java index bcf400d..f6c0fcb 100644 --- a/virtualjoystick/src/main/java/io/github/controlwear/virtual/joystick/android/JoystickView.java +++ b/virtualjoystick/src/main/java/io/github/controlwear/virtual/joystick/android/JoystickView.java @@ -222,6 +222,11 @@ public interface OnMultipleLongPressListener { */ private int mButtonDirection = 0; + /* + * Detect if joystick has been pressed, even if strength and angle are 0 + */ + private boolean isPressed = false; + /* CONSTRUCTORS @@ -438,7 +443,7 @@ public boolean onTouchEvent(MotionEvent event) { mPosX = mButtonDirection > 0 ? mCenterX : (int) event.getX(); // direction positive is vertical axe if (event.getAction() == MotionEvent.ACTION_UP) { - + isPressed = false; // stop listener because the finger left the touch screen mThread.interrupt(); @@ -456,6 +461,7 @@ public boolean onTouchEvent(MotionEvent event) { } if (event.getAction() == MotionEvent.ACTION_DOWN) { + isPressed = true; if (mThread != null && mThread.isAlive()) { mThread.interrupt(); } @@ -845,6 +851,13 @@ public void setButtonDirection(int direction) { mButtonDirection = direction; } + /* + * Returns whether or not joystick is pressed, independent of angle/strength + */ + public boolean isPressed(){ + return isPressed; + } + /* IMPLEMENTS @@ -868,4 +881,4 @@ public void run() { } } } -} \ No newline at end of file +}