package com.abbidot.tracker.widget

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import com.abbidot.tracker.R
import com.abbidot.tracker.util.ViewUtil
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton

/**
 * Created  by .yzq on 2021/12/10/010.
 *
 * @link
 * @description: 自定义椭圆button 方便设置字体
 */
class TypefaceRoundButton @JvmOverloads constructor(context: Context,
                                                    attrs: AttributeSet? = null,
                                                    defStyleAttr: Int = 0) :
    QMUIRoundButton(context, attrs, defStyleAttr) {
    @SuppressLint("CustomViewStyleable")
    private fun initTypefaceTextView(context: Context, attrs: AttributeSet?) {
        val typedArray = context.obtainStyledAttributes(attrs, R.styleable.TypefaceTextView)
        val type = typedArray.getString(R.styleable.TypefaceTextView_typeface) ?: return
        val typeface = ViewUtil.instance.setTypeface(context, type)
        setTypeface(typeface)
        typedArray.recycle()
    }

    init {
        initTypefaceTextView(context, attrs)
    }
}