| | |
| | | private var maxThumbX: Float = 0f |
| | | private var isDragging = false |
| | | private var slideThreshold: Float = 0.7f |
| | | //是否能够使用 |
| | | var enable: Boolean = true |
| | | set(value) { |
| | | field = value |
| | | invalidate() |
| | | } |
| | | |
| | | private val scroller = Scroller(context, DecelerateInterpolator()) |
| | | private var onSlideCompleteListener: (() -> Unit)? = null |
| | |
| | | thumbShape = getInt(R.styleable.SlideButtonView_thumbShape, SHAPE_ROUND_RECT) |
| | | thumbCornerRadius = getDimension(R.styleable.SlideButtonView_thumbCornerRadius, 0f) |
| | | slideThreshold = getFloat(R.styleable.SlideButtonView_slideThreshold, 0.7f) |
| | | enable = getBoolean(R.styleable.SlideButtonView_enable, enable) |
| | | } finally { |
| | | recycle() |
| | | } |
| | |
| | | } |
| | | |
| | | override fun onTouchEvent(event: MotionEvent): Boolean { |
| | | if (!enable) { |
| | | return super.onTouchEvent(event) |
| | | } |
| | | when (event.action) { |
| | | MotionEvent.ACTION_DOWN -> { |
| | | val touchX = event.x |