Code example for Paint

Methods: setShadersetXfermode

0
	@Override 
	protected void onDraw(final Canvas canvas) {
		final int width = getWidth(), height = getHeight();
		if (mShader == null) return;
		super.onDraw(canvas);
		mPaint.setShader(mShader);
		if (supportXfermode()) { 
			mPaint.setXfermode(DST_IN);
		} 
		canvas.drawRect(0, 0, width, height, mPaint);
	} 
 
	@SuppressLint("DrawAllocation") 
	@Override 
	protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
		final int width = MeasureSpec.getSize(widthMeasureSpec), height = width / 2;
		setMeasuredDimension(width, height);
		if (width > 0) {
			final int[] colors = supportXfermode() ? COLORS : COLORS_REVERSED;
			mShader = new LinearGradient(width / 2, 0, width / 2, height, colors, POSITIONS, Shader.TileMode.CLAMP);
Experience pair programming with AI  Get Codota for Java