How to make the image bounce from all the sides of the emulator screen
<pre><code> public class GraphicsView extends View implements OnTouchListener{...}

        public void onDraw(Canvas canvas){
            Paint pint = new Paint();
            pint.setColor(Color.BLUE);
            pint.setStrokeWidth(5);

            canvas.drawBitmap(pic,an.getX2(),an.getY2(),null);
            //canvas.drawBitmap(pic,another.getX(),another.getY(),null);
            //canvas.drawPoint(another.getX(), another.getY(), pint);
            invalidate();

        }


    }
    class AnotherPosition implements Runnable {
        int x,y;
        Random rnd = new Random();
        public int getX(){return x;}
        public int getY(){return y;}

        public int setX(){return x;}
        public int setY(){return y;}

        public void start(){
            Thread t = new Thread(this);
            t.start(); //calls run method
        }
        public void run(){
            while(true){
                y+=13;
                if (y&gt;400){
                    y=5;
                    x=rnd.nextInt(240);
                }
                try{
                    Thread.sleep(100);

                }catch(Exception ex){

                }
            }
        }
</code></pre>

<p>What algorithm should i use to complete my code? The ball should bounce in all corners of the screen. Thank you for your time.</p>
