Skip to content

Instantly share code, notes, and snippets.

@plateaukao
Created November 3, 2023 14:46
Show Gist options
  • Save plateaukao/e81faa0797243aaf33bada07bee65824 to your computer and use it in GitHub Desktop.
Save plateaukao/e81faa0797243aaf33bada07bee65824 to your computer and use it in GitHub Desktop.
simulate long click
private fun simulateLongClick(point: Point) {
isSelectingText = true
val downTime = SystemClock.uptimeMillis()
val downEvent =
MotionEvent.obtain(
downTime, downTime, KeyEvent.ACTION_DOWN,
(point.x + 20).toFloat(), point.y.toFloat(), 0
)
(this.parent as ViewGroup).dispatchTouchEvent(downEvent)
val upEvent =
MotionEvent.obtain(
downTime, downTime + 700, KeyEvent.ACTION_UP,
point.x.toFloat(), point.y.toFloat(), 0
)
postDelayed(
{
(this.parent as ViewGroup).dispatchTouchEvent(upEvent)
downEvent.recycle()
upEvent.recycle()
}, 700
)
postDelayed(
{
evaluateJavascript(
"""
var tt = w._touchTarget;
if(tt){
tt.setAttribute("href", w._hrefAttr);
}
""".trimIndent(), null
)
isSelectingText = false
}, 1000
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment