Code example for Canvas

Methods: drawRGB, drawRect, drawText, restore, save, translate

0
            mColorFilter = new LightingColorFilter(0x0060ffff, 0x00101030);
  
            mLargePaint = new Paint();
            mLargePaint.setAntiAlias(true);
            mLargePaint.setTextSize(36.0f);
            mLargePaint.setColor(0xff000000);
            mLargePaint.setShadowLayer(3.0f, 0.0f, 3.0f, 0x7f00ff00);
 
            mPaint = new Paint();
        } 
 
        @Override 
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            canvas.drawRGB(255, 255, 255);
 
            canvas.save();
            canvas.translate(40.0f, 40.0f);
 
            mPaint.setShader(mComposeShader);
            canvas.drawRect(0.0f, 0.0f, mDrawWidth, mDrawHeight, mPaint);
             
            canvas.translate(0.0f, 40.0f + mDrawHeight);
            mPaint.setShader(mCompose2Shader);
            canvas.drawRect(0.0f, 0.0f, mDrawWidth, mDrawHeight, mPaint);
 
            canvas.restore();
 
            canvas.save();
            canvas.translate(40.0f + mDrawWidth + 40.0f, 40.0f);
 
            mLargePaint.setShader(mHorGradient);
            canvas.drawText("OpenGL rendering", 0.0f, 20.0f, mLargePaint);
 
            mLargePaint.setShader(mScaled2Shader);
            canvas.drawText("OpenGL rendering", 0.0f, 60.0f, mLargePaint);
 
            mLargePaint.setShader(mCompose2Shader);
            mLargePaint.setColorFilter(mColorFilter);
            canvas.drawText("OpenGL rendering", 0.0f, 100.0f, mLargePaint);
            mLargePaint.setColorFilter(null);
 
            canvas.translate(0.0f, 40.0f + mDrawHeight);