package com.xty.common.weight

import android.animation.ObjectAnimator
import android.animation.PointFEvaluator
import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.view.View
import android.view.animation.LinearInterpolator
import java.lang.Exception

class TestView (context: Context, attrs: AttributeSet?) : View(context, attrs) {


    var path=Path()

    var pointx=PointF()
    var pointy=PointF()
    var currentPoint=PointF()




    val xxxx by lazy{
        ObjectAnimator.ofObject(PointFEvaluator(),pointx,pointy).apply {
            interpolator=LinearInterpolator()
            duration=400
        }
    }

    init {
        xxxx.addUpdateListener {
            try {
                currentPoint=  it.animatedValue as PointF
                postInvalidate()
            }catch (e:Exception){
                e.printStackTrace()
            }

        }
    }

    private val paintCircle by lazy {
        Paint().apply {
            this.isAntiAlias=true
            this.isDither=true
            this.strokeWidth=20f
            this.typeface= Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)
            this.style= Paint.Style.STROKE
        }
    }
    var status=false
    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        if(status){
            try {
              path.lineTo(currentPoint.x,currentPoint.y)
              canvas.drawPath(path,paintCircle)
            }catch (e:Exception){
                e.printStackTrace()
            }
        }else{
            path.moveTo(0f,height/2f)
            canvas.drawPath(path,paintCircle)
        }
    }

    fun aa(){
        status=true
        pointx.x=0f
        pointx.y=height/2f

        pointy.x=500f
        pointy.y=200f

        xxxx.start()



    }


}