Writing custom shaders
A developer has the option to write a customized shader as per their requirements. Android provides the android.graphics.Shader
class. It is easy to create your own shader class using the primitive shaders provided.
The custom shader may not include only one shader. It can be a combination of various shaders. For example, consider masking an image with a circular view port with a motion-touch event:
private float touchX; private float touchY; private boolean shouldMask = false; private final float viewRadius; private Paint customPaint; @Override public boolean onTouchEvent(MotionEvent motionEvent) { int pointerAction = motionEvent.getAction(); if ( pointerAction == MotionEvent.ACTION_DOWN || pointerAction == MotionEvent.ACTION_MOVE ) shouldMask = true; else shouldMask = false; touchX = motionEvent.getX(); touchY = motionEvent.getY(); invalidate(); return true; } @Override protected void onDraw(Canvas canvas) { if (customPaint == null...