Skip to content

Commit

Permalink
Indicate eventConsumed when MotionEvent.ACTION_UP
Browse files Browse the repository at this point in the history
  • Loading branch information
pmartinbTEF committed Nov 6, 2024
1 parent e7bf4e8 commit 3dfb532
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ class ProgressButton : FrameLayout {
}
}

@SuppressLint("ClickableViewAccessibility")
private fun setButtonBackground() {
buttonBackground.apply {
id = NO_ID
Expand All @@ -204,29 +203,38 @@ class ProgressButton : FrameLayout {
setTextColor(Color.TRANSPARENT)
visibility = VISIBLE
setOnTouchListener { view, event ->
var eventConsumed = false
when (event.action) {
MotionEvent.ACTION_DOWN -> {
buttonNormal.isPressed = true
buttonLoading.isPressed = true
setButtonPressed(true)
}

MotionEvent.ACTION_MOVE -> {
val outsideBounds =
event.x < 0 || event.y < 0 || event.x > view.measuredWidth || event.y > view.measuredHeight
buttonNormal.isPressed = !outsideBounds
buttonLoading.isPressed = !outsideBounds
setButtonPressed(!outsideBounds)
}

MotionEvent.ACTION_UP -> {
setButtonPressed(false)
view.performClick()
eventConsumed = true
}

MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
buttonNormal.isPressed = false
buttonLoading.isPressed = false
MotionEvent.ACTION_CANCEL -> {
setButtonPressed(false)
}
}
false
eventConsumed
}
}
}

private fun setButtonPressed(pressed: Boolean) {
buttonNormal.isPressed = pressed
buttonLoading.isPressed = pressed
}

private fun addViews() {
addView(buttonBackground)
addView(buttonNormal)
Expand Down

0 comments on commit 3dfb532

Please sign in to comment.