Android Open Source - android-shape-imageview Circle Shader






From Project

Back to project page android-shape-imageview.

License

The source code is released under:

Apache License

If you think the Android project android-shape-imageview listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.github.siyamed.shapeimageview.shader;
/*w  ww  .  ja v a2  s .  c o  m*/
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;

public class CircleShader extends ShaderHelper {
    private float center;
    private float bitmapCenterX;
    private float bitmapCenterY;
    private float borderRadius;
    private int bitmapRadius;

    public CircleShader() {
    }

    @Override
    public void init(Context context, AttributeSet attrs, int defStyle) {
        super.init(context, attrs, defStyle);
        square = true;
    }

    @Override
    public void draw(Canvas canvas, Paint imagePaint, Paint borderPaint) {
        canvas.drawCircle(center, center, borderRadius, borderPaint);
        canvas.save();
        canvas.concat(matrix);
        canvas.drawCircle(bitmapCenterX, bitmapCenterY, bitmapRadius, imagePaint);
        canvas.restore();
    }

    @Override
    public void onSizeChanged(int width, int height) {
        super.onSizeChanged(width, height);
        center = Math.round(viewWidth / 2f);
        borderRadius = Math.round((viewWidth - borderWidth) / 2f);
    }

    @Override
    public void calculate(int bitmapWidth, int bitmapHeight,
                          float width, float height,
                          float scale,
                          float translateX, float translateY) {
        bitmapCenterX = Math.round(bitmapWidth / 2f);
        bitmapCenterY = Math.round(bitmapHeight / 2f);
        bitmapRadius = Math.round(width / scale / 2f + 0.5f);
    }

    @Override
    public void reset() {
        bitmapRadius = 0;
        bitmapCenterX = 0;
        bitmapCenterY = 0;
    }
}




Java Source Code List

com.github.siyamed.shapeimageview.BubbleImageView.java
com.github.siyamed.shapeimageview.CircularImageView.java
com.github.siyamed.shapeimageview.DiamondImageView.java
com.github.siyamed.shapeimageview.HeartImageView.java
com.github.siyamed.shapeimageview.HexagonImageView.java
com.github.siyamed.shapeimageview.OctogonImageView.java
com.github.siyamed.shapeimageview.PentagonImageView.java
com.github.siyamed.shapeimageview.RoundedImageView.java
com.github.siyamed.shapeimageview.ShaderImageView.java
com.github.siyamed.shapeimageview.ShapeImageView.java
com.github.siyamed.shapeimageview.StarImageView.java
com.github.siyamed.shapeimageview.mask.PorterCircularImageView.java
com.github.siyamed.shapeimageview.mask.PorterImageView.java
com.github.siyamed.shapeimageview.mask.PorterShapeImageView.java
com.github.siyamed.shapeimageview.path.SvgUtil.java
com.github.siyamed.shapeimageview.path.parser.CopyInputStream.java
com.github.siyamed.shapeimageview.path.parser.IdHandler.java
com.github.siyamed.shapeimageview.path.parser.IoUtil.java
com.github.siyamed.shapeimageview.path.parser.NumberParse.java
com.github.siyamed.shapeimageview.path.parser.ParseUtil.java
com.github.siyamed.shapeimageview.path.parser.ParserHelper.java
com.github.siyamed.shapeimageview.path.parser.PathInfo.java
com.github.siyamed.shapeimageview.path.parser.PathParser.java
com.github.siyamed.shapeimageview.path.parser.SvgToPath.java
com.github.siyamed.shapeimageview.path.parser.TransformParser.java
com.github.siyamed.shapeimageview.sample.SampleActivity.java
com.github.siyamed.shapeimageview.sample.SampleBubbleFragment.java
com.github.siyamed.shapeimageview.sample.SampleFragment.java
com.github.siyamed.shapeimageview.sample.SampleListFragment.java
com.github.siyamed.shapeimageview.shader.BubbleShader.java
com.github.siyamed.shapeimageview.shader.CircleShader.java
com.github.siyamed.shapeimageview.shader.RoundedShader.java
com.github.siyamed.shapeimageview.shader.ShaderHelper.java
com.github.siyamed.shapeimageview.shader.SvgShader.java