I am drawing a Rect to the screen and am trying to move it up/right/down/left when the user swipes in a direction. When the user swipes up, I want the rect to move 50px up, and the same for all four directions.

I have swipe detection working, however I have no clue how to actually move the Rect. How can I go about moving Rect r in the direction the user swipes? Ideally I would like it to smoothly move in a direction not just snap 50px in the direction swiped if possible.

What I currently have:

MainActivity.java

```
public class MainActivity extends Activity {

    float x1,x2;
    float y1, y2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        View v = new GameView(this);
        setContentView(v);
    }

    public boolean onTouchEvent(MotionEvent touchevent) {
        switch (touchevent.getAction())
        {
            case MotionEvent.ACTION_DOWN:
            {
                x1 = touchevent.getX();
                y1 = touchevent.getY();
                break;
            }
            case MotionEvent.ACTION_UP:
            {
                x2 = touchevent.getX();
                y2 = touchevent.getY();

                double r = Math.atan2(y2 - y1, x2 - x1);

                if (r > -2.25 && r < -0.75) {
                    Toast.makeText(getApplicationContext(), "Up", Toast.LENGTH_SHORT).show();
                    //Move rect 50px up
                } else if (r > -0.75 && r < 0.75) {
                    Toast.makeText(getApplicationContext(), "Right", Toast.LENGTH_SHORT).show();
                    //Move rect 50px right
                } else if (r > 0.75 && r < 2.25) {
                    Toast.makeText(getApplicationContext(), "Down", Toast.LENGTH_SHORT).show();
                    //Move rect 50px down
                } else if (r > 2.25 || r < -2.25) {
                    Toast.makeText(getApplicationContext(), "Left", Toast.LENGTH_SHORT).show();
                    //Move rect 50px Left
                }
                break;
            }
        }
        return false;
    }
}

```

I am creating the Rect here in GameView.java

```
public class GameView extends View {

    public Rect r = new Rect(100, 100, 300, 300);
    public Paint p = new Paint();

    public GameView(Context context) {
        super(context);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawColor(Color.WHITE);

        //Fill
        p.setStyle(Paint.Style.FILL);
        p.setColor(Color.MAGENTA);
        canvas.drawRect(r, p);
    }
}

```