I want to make a simple doodle application, for android, but I don't know how to get some data from android! I need:
The position of the mouse before and after the drag or if it is a simple touch how to get the position of the touch.
How should I go about drawing the lines?
Can somebody please help me?
Drag event listeners and callback methods A View receives drag events with either a drag event listener that implements View. OnDragListener or with the view's onDragEvent() callback method.
ACTION_DRAG_ENTERED. Action constant returned by getAction() : Signals to a View that the drag point has entered the bounding box of the View. If the View can accept a drop, it can react to ACTION_DRAG_ENTERED by changing its appearance in a way that tells the user that the View is the current drop target.
The draw() method is called by the framework when the view need to be re-drawn and the draw() method then calls the onDraw() to draw the view's content.
You can override the onTouchEvent
method in your View
:
@Override
public boolean onTouchEvent (MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
start_x = event.getX();
start_y = event.getY();
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
//create the line from start_x and start_y to the current location
//don't forget to invalidate the View otherwise your line won't get redrawn
} else if (event.getAction() == MotionEvent.ACTION_UP) {
//might not need anything here
}
return true;
}
I am assuming you want to draw a straight line from the start of the drag to the endpoint and you don't want to "doodle", but its pretty simple to modify this code to handle either.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With