RectProgress.java 文件源码

java
阅读 26 收藏 0 点赞 0 评论 0

项目:IOS11RectProgress 作者:
private void init(Context context, AttributeSet attrs) {
    //关闭硬件加速,不然setXfermode()可能会不生效
    setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    if (attrs != null) {
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RectProgress);
        bgColor = typedArray.getColor(R.styleable.RectProgress_bgColor, defaultBgColor);
        progressColor = typedArray.getColor(R.styleable.RectProgress_progressColor, defaultProgressColor);
        progress = typedArray.getInteger(R.styleable.RectProgress_progressValue, progress);
        max = typedArray.getInteger(R.styleable.RectProgress_progressMax, max);
        if (max <= 0)
            throw new RuntimeException("Max 必须大于 0");
        orientation = typedArray.getInteger(R.styleable.RectProgress_progressOrientation, VERTICAL);
        int imgSrc = typedArray.getResourceId(R.styleable.RectProgress_iconSrc, 0);
        iconPadding = typedArray.getDimensionPixelSize(R.styleable.RectProgress_iconPadding, 10);
        rectRadius = typedArray.getDimensionPixelSize(R.styleable.RectProgress_rectRadius, 20);
        if (max < progress) {
            progress = max;
        }
        typedArray.recycle();

        if (imgSrc != 0) {
            bitmap = ((BitmapDrawable) getResources().getDrawable(imgSrc)).getBitmap();
        }
    }

    bgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    bgPaint.setColor(bgColor);

    progressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    progressPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
    progressPaint.setColor(progressColor);


}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号