public void drawStick(MotionEvent arg1) { position_x = (int) (arg1.getX() - (params.width / 2)); position_y = (int) (arg1.getY() - (params.height / 2)); distance = (float) Math.sqrt(Math.pow(position_x, 2) + Math.pow(position_y, 2)); angle = (float) cal_angle(position_x, position_y); if (arg1.getAction() == MotionEvent.ACTION_DOWN) { if (distance <= (params.width / 2) - OFFSET) { draw.position(arg1.getX(), arg1.getY()); draw(); touch_state = true; } } else if (arg1.getAction() == MotionEvent.ACTION_MOVE && touch_state) { if (distance <= (params.width / 2) - OFFSET) { draw.position(arg1.getX(), arg1.getY()); draw(); } else if (distance > (params.width / 2) - OFFSET) { float x = (float) (Math.cos(Math.toRadians(cal_angle(position_x, position_y))) * ((params.width / 2) - OFFSET)); float y = (float) (Math.sin(Math.toRadians(cal_angle(position_x, position_y))) * ((params.height / 2) - OFFSET)); x += (params.width / 2); y += (params.height / 2); draw.position(x, y); draw(); } else { mLayout.removeView(draw); } } else if (arg1.getAction() == MotionEvent.ACTION_UP) { mLayout.removeView(draw); touch_state = false; } }
public void drawStick(double x, double y) { draw.position(x, y); draw(); }