Some questions on using the canvas in Java to draw shapes and paths for Android?
<p>How do I find the coordinates of the screen? I know e.g. a phone would have say a 960 x 540 resolution, but in the emulators some of the edges are not filled if I draw a shape to that resolution. Is there a way around this?</p>

<p>For the colour of the rectangle, it is seen there are two rectangles, and two of them have the same colour despite giving two separate colours for drawPaint. Just setting a new variable e.g. drawPaint2 returns errors. How to change the colour of both?</p>

<p>How to use the path function in the canvas. E.g. to draw a triangle? I have included my attempt in the code but it doesn't display a triangle.</p>

<pre><code>    public class DrawView extends View implements OnTouchListener
{

    private Paint backgroundPaint = new Paint();
    private Paint drawPaint = new Paint();
    private Paint circlePaint = new Paint();
    private Paint textPaint = new Paint();
    private Paint path = new Paint();
    private float sx, sy;

    public DrawView(Context context)
    {
        super(context);         

        setFocusable(true);
        setFocusableInTouchMode(true);

        backgroundPaint.setColor(Color.CYAN);
        backgroundPaint.setAntiAlias(true);
        backgroundPaint.setStyle(Style.FILL);

        drawPaint.setColor(Color.WHITE);
        drawPaint.setStyle(Style.FILL);

        circlePaint.setColor(Color.DKGRAY);
        circlePaint.setStyle(Style.FILL);

        textPaint.setColor(Color.WHITE);
        textPaint.setStyle(Style.FILL);

        drawPaint.setColor(Color.GREEN);
        drawPaint.setStyle(Style.FILL);

        circlePaint.setColor(Color.RED);
        circlePaint.setStyle(Style.FILL);

        path.setColor(android.graphics.Color.RED);
        path.setStyle(Paint.Style.FILL);            
        Path path = new Path();
        path.moveTo(1, 1);
        path.lineTo(20, 50);
        path.moveTo(20, 50);
        path.lineTo(100, 100);
        path.moveTo(100, 100);
        path.lineTo(1, 1);
        path.close();

        this.setOnTouchListener(this);
    }

    @Override
    public void onDraw(Canvas canvas)
    {

        //canvas.drawPath(path, paint); &lt;-- error

        // to draw background
        canvas.drawRect(this.getLeft(), this.getTop(), this.getRight(), this.getBottom(), backgroundPaint);

        //to draw two rectangle with blue and green paint
        canvas.drawRect(100,100, 340,540, drawPaint); 
        canvas.drawRect(00,00, 120,80, drawPaint); 

        //draw text with paint
        canvas.drawText("Hello Dear Leader!", 110, 160, textPaint);

        //draw a circle with green paint with the touch coordinates
        canvas.drawCircle(sx-30,sy-30, 30, circlePaint);

        //draw a circle with red paint with the touch coordinates
        canvas.drawCircle(sx-80, sy-80, 10, circlePaint);

    }

    public boolean onTouch(View v, MotionEvent event)
    {   
        //update the coordinates for the OnDraw method above, with wherever we touch
        sx = event.getX();
        sy = event.getY();

        invalidate();
        return true;
    }

}
</code></pre>
