mirror of
https://github.com/oxen-io/session-android.git
synced 2025-04-17 01:01:25 +00:00
Better input event handling for waveform seek bar.
This commit is contained in:
parent
aacbe02327
commit
018e3288a4
@ -15,7 +15,7 @@ import android.view.animation.DecelerateInterpolator
|
|||||||
import androidx.core.math.MathUtils
|
import androidx.core.math.MathUtils
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
import org.thoughtcrime.securesms.loki.utilities.audio.byteToNormalizedFloat
|
import org.thoughtcrime.securesms.loki.utilities.audio.byteToNormalizedFloat
|
||||||
import java.lang.Math.abs
|
import kotlin.math.abs
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
@ -111,7 +111,9 @@ class WaveformSeekBar : View {
|
|||||||
|
|
||||||
private var canvasWidth = 0
|
private var canvasWidth = 0
|
||||||
private var canvasHeight = 0
|
private var canvasHeight = 0
|
||||||
|
|
||||||
private var touchDownX = 0f
|
private var touchDownX = 0f
|
||||||
|
private var touchDownProgress: Float = 0f
|
||||||
private var scaledTouchSlop = ViewConfiguration.get(context).scaledTouchSlop
|
private var scaledTouchSlop = ViewConfiguration.get(context).scaledTouchSlop
|
||||||
|
|
||||||
constructor(context: Context) : this(context, null)
|
constructor(context: Context) : this(context, null)
|
||||||
@ -185,47 +187,31 @@ class WaveformSeekBar : View {
|
|||||||
when (event.action) {
|
when (event.action) {
|
||||||
MotionEvent.ACTION_DOWN -> {
|
MotionEvent.ACTION_DOWN -> {
|
||||||
userSeeking = true
|
userSeeking = true
|
||||||
if (isParentScrolling()) {
|
|
||||||
touchDownX = event.x
|
touchDownX = event.x
|
||||||
} else {
|
touchDownProgress = progress
|
||||||
updateProgress(event, false)
|
updateProgress(event, false)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
MotionEvent.ACTION_MOVE -> {
|
MotionEvent.ACTION_MOVE -> {
|
||||||
|
// Prevent any parent scrolling if the user scrolled more
|
||||||
|
// than scaledTouchSlop on horizontal axis.
|
||||||
|
if (abs(event.x - touchDownX) > scaledTouchSlop) {
|
||||||
|
parent.requestDisallowInterceptTouchEvent(true)
|
||||||
|
}
|
||||||
updateProgress(event, false)
|
updateProgress(event, false)
|
||||||
}
|
}
|
||||||
MotionEvent.ACTION_UP -> {
|
MotionEvent.ACTION_UP -> {
|
||||||
userSeeking = false
|
userSeeking = false
|
||||||
if (abs(event.x - touchDownX) > scaledTouchSlop) {
|
|
||||||
updateProgress(event, true)
|
updateProgress(event, true)
|
||||||
}
|
|
||||||
performClick()
|
performClick()
|
||||||
}
|
}
|
||||||
MotionEvent.ACTION_CANCEL -> {
|
MotionEvent.ACTION_CANCEL -> {
|
||||||
|
updateProgress(touchDownProgress, false)
|
||||||
userSeeking = false
|
userSeeking = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isParentScrolling(): Boolean {
|
|
||||||
var parent = parent as View
|
|
||||||
val root = rootView
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
when {
|
|
||||||
parent.canScrollHorizontally(+1) -> return true
|
|
||||||
parent.canScrollHorizontally(-1) -> return true
|
|
||||||
parent.canScrollVertically(+1) -> return true
|
|
||||||
parent.canScrollVertically(-1) -> return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parent == root) return false
|
|
||||||
|
|
||||||
parent = parent.parent as View
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateProgress(event: MotionEvent, notify: Boolean) {
|
private fun updateProgress(event: MotionEvent, notify: Boolean) {
|
||||||
updateProgress(event.x / getAvailableWidth(), notify)
|
updateProgress(event.x / getAvailableWidth(), notify)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user