Assuming you have some sort of game loop set up where the UI is updated on intervals:
/**
* Onclick event for Touch Screen
*/
@Override
public boolean onTouchEvent(MotionEvent input) {
if (input.getAction() == MotionEvent.ACTION_MOVE) {
float currX = input.getX();
float currY = input.getY();
if (!swiping) {
swiping = true;
swipeStartY = currY;
swipeStartX = currX;
}
if (swiping) {
double newDirection = Math.atan2((currY-ball.getY()),currX-ball.getX());
ball.setDirection(newDirection);
}
} else if (input.getAction() == MotionEvent.ACTION_UP) {
if (swiping) {
swiping = false;
}
}
}
This way the ball's direction is updated on each tick of the game thread and moves towards your finger (the touch event X/Y location). I'm not sure how you have set up your drawing/physics/etc. so I can't provide meaningful function calls here. If you need to modify it so it swipes in a straight line after you lift your finger then store the initial X/Y point (swipeStartX/swipeStartY in this case) and only set the new direction after you stop swiping.
EDIT:
I should mention, my class definition that contains this code is as follows:
public class GameView extends SurfaceView implements SurfaceHolder.Callback {
....
}