package alphaTab.platform.android

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.widget.ScrollView

internal class SuspendableScrollView(context: Context, attributeSet: AttributeSet) :
    ScrollView(context, attributeSet) {

    public var isUserScrollingEnabled = true

    @SuppressLint("ClickableViewAccessibility")
    override fun onTouchEvent(ev: MotionEvent): Boolean {
        return when (ev.action) {
            MotionEvent.ACTION_DOWN ->
                isUserScrollingEnabled && super.onTouchEvent(ev)
            else ->
                super.onTouchEvent(ev)
        }
    }

    override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
        return isUserScrollingEnabled && super.onInterceptTouchEvent(ev)
    }
}
