package com.abbidot.tracker.base

import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import com.abbidot.baselibrary.util.AppUtils

/**
 *Created  by .yzq on 2024/10/11/011.
 * @link
 * @description:
 */
open class BaseView : View {

    lateinit var mContext: Context
    var mWidth = 0
    var mHeight = 0
    var mValue = 0
    var mStrokeWidth = 0f

    lateinit var mPaint: Paint

    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
    constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
        context, attrs, defStyleAttr
    )

    open fun init(context: Context, attrs: AttributeSet?) {
        mContext = context

        //禁用硬件加速,防止返回到界面多次执行onDraw
        setLayerType(LAYER_TYPE_SOFTWARE, null)

        mStrokeWidth = AppUtils.dpToPx(1f)
        mPaint = Paint()
    }

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        canvas.apply {
            startDraw(this)
        }
    }

    open fun startDraw(canvas: Canvas) {

    }
}