package com.develop.common.widget

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView
import com.develop.common.R

class CircleBgImageView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null
) : AppCompatImageView(context, attrs) {

    private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
    init {
        paint.style = Paint.Style.FILL
        context.obtainStyledAttributes(attrs, R.styleable.CircleBgImageView).let {
            paint.color = it.getColor(R.styleable.CircleBgImageView_bgColor, Color.TRANSPARENT)
            it.recycle()
        }
    }

    override fun onDraw(canvas: Canvas?) {
        canvas?.drawCircle(width / 2f, height / 2f, width / 2f, paint)
        super.onDraw(canvas)
    }
}