Buggy code:
public class JoystickView extends View { public static final int INVALID_POINTER_ID = - 1 ; private final boolean D = false ; String TAG = "JoystickView" ; private Paint dbgPaint1 ; private Paint dbgPaint2 ; private Paint bgPaint ; private Paint handlePaint ; private int innerPadding ; private int bgRadius ; private int handleRadius ; private int movementRadius ; private int handleInnerBoundaries ; private JoystickMovedListener moveListener ; private JoystickClickedListener clickListener ; private float moveResolution ; private boolean yAxisInverted ; private boolean autoReturnToCenter ; public static final int CONSTRAIN_BOX = 0 ; public static final int CONSTRAIN_CIRCLE = 1 ; private int movementConstraint ; private float movementRange ; public static final int COORDINATE_CARTESIAN = 0 ; public static final int COORDINATE_DIFFERENTIAL = 1 ; private int userCoordinateSystem ; private float touchPressure ; private boolean clicked ; private float clickThreshold ; private int pointerId = JoystickView . INVALID_POINTER_ID ; private float touchX ; private float touchY ; private float reportX ; private float reportY ; private float handleX ; private float handleY ; private int cX ; private int cY ; private int dimX ; private int cartX ; private int cartY ; private double radial ; private double angle ; private int userX ; private int userY ; private int offsetX ; private int offsetY ; public JoystickView ( Context context ) { } public JoystickView ( Context context , AttributeSet attrs ) { } public JoystickView ( Context context , AttributeSet attrs , int defStyle ) { } private void initJoystickView ( ) { } public void setAutoReturnToCenter ( boolean autoReturnToCenter ) { } public boolean isAutoReturnToCenter ( ) { } public void setUserCoordinateSystem ( int userCoordinateSystem ) { } public int getUserCoordinateSystem ( ) { } public void setMovementConstraint ( int movementConstraint ) { } public int getMovementConstraint ( ) { } public boolean isYAxisInverted ( ) { } public void setYAxisInverted ( boolean yAxisInverted ) { } public void setClickThreshold ( float clickThreshold ) { } public float getClickThreshold ( ) { } public void setMovementRange ( float movementRange ) { } public float getMovementRange ( ) { } public void setMoveResolution ( float moveResolution ) { } public float getMoveResolution ( ) { } public void setOnJostickMovedListener ( JoystickMovedListener listener ) { } public void setOnJostickClickedListener ( JoystickClickedListener listener ) { } @ Override protected void onMeasure ( int widthMeasureSpec , int heightMeasureSpec ) { } @ Override protected void onLayout ( boolean changed , int left , int top , int right , int bottom ) { } private int measure ( int measureSpec ) { } @ Override protected void onDraw ( Canvas canvas ) { } private void constrainBox ( ) { } private void constrainCircle ( ) { } public void setPointerId ( int id ) { } public int getPointerId ( ) { } @ Override public boolean onTouchEvent ( MotionEvent ev ) { final int action = ev . getAction ( ) ; switch ( action & ( MotionEvent . ACTION_MASK ) ) { case MotionEvent . ACTION_MOVE : { return processMoveEvent ( ev ) ; } case MotionEvent . ACTION_CANCEL : case MotionEvent . ACTION_UP : { if ( ( pointerId ) != ( JoystickView . INVALID_POINTER_ID ) ) { returnHandleToCenter ( ) ; setPointerId ( JoystickView . INVALID_POINTER_ID ) ; } break ; } case MotionEvent . ACTION_POINTER_UP : { if ( ( pointerId ) != ( JoystickView . INVALID_POINTER_ID ) ) { final int pointerIndex = ( action & ( MotionEvent . ACTION_POINTER_INDEX_MASK ) ) > > ( MotionEvent . ACTION_POINTER_INDEX_SHIFT ) ; final int pointerId = ev . getPointerId ( pointerIndex ) ; if ( pointerId == ( this . pointerId ) ) { returnHandleToCenter ( ) ; setPointerId ( JoystickView . INVALID_POINTER_ID ) ; return true ; } } break ; } case MotionEvent . ACTION_DOWN : { if ( ( pointerId ) == ( JoystickView . INVALID_POINTER_ID ) ) { int x = ( ( int ) ( ev . getX ( ) ) ) ; if ( ( x >= ( offsetX ) ) && ( x < ( ( offsetX ) + ( dimX ) ) ) ) { setPointerId ( ev . getPointerId ( 0 ) ) ; return true ; } } break ; } case MotionEvent . ACTION_POINTER_DOWN : { if ( ( pointerId ) == ( JoystickView . INVALID_POINTER_ID ) ) { final int pointerIndex = ( action & ( MotionEvent . ACTION_POINTER_INDEX_MASK ) ) > > ( MotionEvent . ACTION_POINTER_INDEX_SHIFT ) ; final int pointerId = ev . getPointerId ( pointerIndex ) ; <START_BUG> int x = ( ( int ) ( ev . getX ( pointerId ) ) ) ; <END_BUG> if ( ( x >= ( offsetX ) ) && ( x < ( ( offsetX ) + ( dimX ) ) ) ) { setPointerId ( pointerId ) ; return true ; } } break ; } } return false ; } private boolean processMoveEvent ( MotionEvent ev ) { } private void reportOnMoved ( ) { } private void calcUserCoordinates ( ) { } private void reportOnPressure ( ) { } private void returnHandleToCenter ( ) { } public void setTouchOffset ( int x , int y ) { } }

Fix:
int x = ( ( int ) ( ev . getX ( pointerIndex ) ) ) ;