Code example for AtomicBoolean

Methods: compareAndSetset

    protected void onDraw(Canvas canvas) {
    	if (canvas==null) throw new NullPointerException();
        if (!drawing.compareAndSet(false, true)) return; 
        float bearing = GlobalData.getBearing();
        int bitmapWidth = bitmap.getWidth();
        int bitmapHeight = bitmap.getHeight();
        int canvasWidth = canvas.getWidth();
        int canvasHeight = canvas.getHeight();
        if (bitmap.getWidth()>canvasWidth || bitmap.getHeight()>canvasHeight) {        
            //Resize the bitmap to the size of the canvas 
            bitmap = Bitmap.createScaledBitmap(bitmap, (int)(bitmapWidth*.9), (int)(bitmapHeight*.9), true);
        int bitmapX = bitmap.getWidth()/2;
        int bitmapY = bitmap.getHeight()/2;
        int parentX = parentWidth/2;
        int parentY = parentHeight/2;
        int centerX = parentX-bitmapX;
        int centerY = parentY-bitmapY;
        int rotation = (int)(360-bearing);
        //Rotate the bitmap around it's center point so it's always pointing north 
        matrix.setRotate(rotation, bitmapX, bitmapY);
        //Move the bitmap to the center of the canvas 
        matrix.postTranslate(centerX, centerY);
        canvas.drawBitmap(bitmap, matrix, paint);