@Override public boolean onTouchEvent(MotionEvent event) { int actionType = event.getAction(); if (actionType == MotionEvent.ACTION_MOVE) { int px = getMeasuredWidth() / 2; int py = getMeasuredHeight() / 2; int radius = Math.min(px, py) - handleInnerBoundaries; touchX = (event.getX() - px); touchX = Math.max(Math.min(touchX, radius), -radius); touchY = (event.getY() - py); touchY = Math.max(Math.min(touchY, radius), -radius); // Coordinates Log.d(TAG, "X:" + touchX + "|Y:" + touchY); // Pressure if (listener != null) { listener.OnMoved( (int) (touchX / radius * sensitivity), (int) (touchY / radius * sensitivity)); } invalidate(); } else if (actionType == MotionEvent.ACTION_UP) { returnHandleToCenter(); Log.d(TAG, "X:" + touchX + "|Y:" + touchY); } return true; }
private void reportOnMoved() { if (movementConstraint == CONSTRAIN_CIRCLE) constrainCircle(); else constrainBox(); calcUserCoordinates(); if (moveListener != null) { boolean rx = Math.abs(touchX - reportX) >= moveResolution; boolean ry = Math.abs(touchY - reportY) >= moveResolution; if (rx || ry) { this.reportX = touchX; this.reportY = touchY; // Log.d(TAG, String.format("moveListener.OnMoved(%d,%d)", (int)userX, (int)userY)); moveListener.OnMoved(userX, userY); } } }