Code example for Canvas

Methods: drawRGB, drawRect, restore, save, translate

0
        } 
 
        @Override 
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            canvas.drawRGB(255, 255, 255);
 
            canvas.save();
            canvas.translate(130.0f, 100.0f);
 
            mSweepGradient.setLocalMatrix(mMatrix3);
            mPaint.setShader(mSweepGradient);
            canvas.drawRect(0.0f, 0.0f, 200.0f, 200.0f, mPaint);
 
            canvas.translate(400.0f, 000.0f);
             
            mSweepGradient.setLocalMatrix(mMatrix);
            mPaint.setShader(mSweepGradient);
            canvas.drawRect(0.0f, 0.0f, 200.0f, 200.0f, mPaint);            
 
            canvas.translate(400.0f, 000.0f);
             
            mSweepGradient.setLocalMatrix(mMatrix2);
            mPaint.setShader(mSweepGradient);
            canvas.drawRect(0.0f, 0.0f, 200.0f, 200.0f, mPaint);
 
            canvas.translate(-800.0f, 300.0f);
 
            mRadialGradient.setLocalMatrix(null);
            mPaint.setShader(mRadialGradient);
            canvas.drawRect(0.0f, 0.0f, 200.0f, 200.0f, mPaint);
             
            canvas.translate(400.0f, 000.0f);
             
            mRadialGradient.setLocalMatrix(mMatrix);
            mPaint.setShader(mRadialGradient);
            canvas.drawRect(0.0f, 0.0f, 200.0f, 200.0f, mPaint);
 
            canvas.translate(400.0f, 000.0f);
             
            mRadialGradient.setLocalMatrix(mMatrix2);
            mPaint.setShader(mRadialGradient);
            canvas.drawRect(0.0f, 0.0f, 200.0f, 200.0f, mPaint);
             
             
            canvas.restore();
        } 
    } 
}