I am embedding a youtube video in an iFrame using a WebView. I am trying to avoid sending right mouse clicks to the webview and it seems long pressing a webview sends the event to show the menu.
I cant access the document of the iFrame from withing JavaScript, so I cant prevent right mouse clicks on the iFrame using JavaScript. Instead I am trying to prevent long presses from being sent to the webview. So have tried to override the webview's onTouch. It turns out the following doesn't pass the long click nor does it pass any click.
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent motionEvent) {
return true;
}
or
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent motionEvent) {
return false;
}
Adding super.onTouchEvent(motionEvent)
passes all clicks to the view. So I have tried to filter out long presses in the following way
private long startTime;
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN){
startTime = System.nanoTime();
} else if(motionEvent.getAction() == MotionEvent.ACTION_UP && System.nanoTime() - startTime < 19000000){
super.onTouchEvent(motionEvent);
}
}
return true;
}
Sadly this doesn't send click events if a user quickly lifts the finger after clicking.