private void returnHandleToCenter() { if (autoReturnToCenter) { final int numberOfFrames = 5; final double intervalsX = (0 - (this.xPosition - this.centerX)) / numberOfFrames; final double intervalsY = (0 - (this.yPosition - this.centerY)) / numberOfFrames; for (int i = 0; i < numberOfFrames; i++) { final int j = i; postDelayed( new Runnable() { public void run() { xPosition += intervalsX; yPosition += intervalsY; reportOnMoved(); invalidate(); if (onJoystickMoveListener != null && j == numberOfFrames - 1) { onJoystickMoveListener.OnReturnedToCenter(); } } }, i * 40); } if (onJoystickMoveListener != null) { onJoystickMoveListener.OnReleased(); } } }
private void reportOnMoved() { int currentDir = getDirection(); // int currentPow = getPower(); int currentPow = getAngle(); if (currentDir != lastDirection || Math.abs(currentPow - lastPower) >= powerResolution) { onJoystickMoveListener.onValueChanged(currentPow, currentDir); lastDirection = currentDir; lastPower = currentPow; } }