package com.develop.base.widgets

import android.content.Context
import android.graphics.Canvas
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatSeekBar
import kotlin.jvm.Synchronized
import android.view.MotionEvent

class ForbidDragSeekBar : AppCompatSeekBar {
    /**
     * 是否支持拖动进度
     */
    private var touch = false

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

    @Synchronized
    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
    }

    fun setTouch(touch: Boolean) {
        this.touch = touch
    }

    /**
     * onTouchEvent 是在 SeekBar 继承的抽象类 AbsSeekBar
     */
    override fun onTouchEvent(event: MotionEvent): Boolean {
        return if (touch) {
            super.onTouchEvent(event)
        } else false
    }
}