small changes to GestureDectector usage to fix a race condition on motionEvents being used after they've been recycled

This commit is contained in:
gavine99
2025-01-16 19:48:18 +11:00
parent 5c9ad9851e
commit 67a59ddd4c
2 changed files with 10 additions and 3 deletions
@@ -183,6 +183,8 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
message.setOnTouchListener(object : OnTouchListener {
private val gestureDetector =
GestureDetector(this@ComposeActivity, object : SimpleOnGestureListener() {
private var lastUpEvent: MotionEvent? = null
override fun onDoubleTap(e: MotionEvent): Boolean {
val speechRecognizerIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
.putExtra(
@@ -195,11 +197,16 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
}
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
message.showKeyboard()
if (lastUpEvent !== null) {
message.onTouchEvent(lastUpEvent)
lastUpEvent?.recycle()
lastUpEvent = null
}
return true
}
override fun onSingleTapUp(e: MotionEvent): Boolean {
lastUpEvent = MotionEvent.obtain(e)
return true // don't show soft keyboard on this event
}
})