Skip to content

Commit

Permalink
[mediaplayer] Workaround for too sensitive touch move
Browse files Browse the repository at this point in the history
When tapping youtube video play button we need
MotionEvent.ACTION_DOWN and MotionEvent.ACTION_UP sequence.
But we get MotionEvent.ACTION_DOWN, MotionEvent.ACTION_MOVE...,
MotionEvent.ACTION_UP and that doesn't work with play button.

This patch adds some treshold to motion event detection.

This is a temporary fix on application level. Issue should
be fixed properly in WPEView or in WebKit.
  • Loading branch information
zhani committed Oct 16, 2024
1 parent 8a3221f commit 409187f
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.content.res.AssetManager;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowInsets;
import android.widget.Toast;
Expand Down Expand Up @@ -81,4 +82,35 @@ public void onWindowFocusChanged(boolean hasFocus) {
}
}
}

// Workaround for too sensitive touch move events which break
// embedded youtube view touch tap detection.
// When tapping play button we need MotionEvent.ACTION_DOWN and MotionEvent.ACTION_UP
// in sequence. Without this workaround we get MotionEvent.ACTION_DOWN, MotionEvent.ACTION_MOVE...,
// MotionEvent.ACTION_UP and that doesn't work with play button
private static final int TOUCH_MOVE_THRESHOLD = 10;
private float initialX;
private float initialY;

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
// Store the initial touch coordinates
initialX = ev.getX();
initialY = ev.getY();
break;
case MotionEvent.ACTION_MOVE:
// Calculate the movement distance
float deltaX = Math.abs(ev.getX() - initialX);
float deltaY = Math.abs(ev.getY() - initialY);
// If movement is within the threshold, ignore the MOVE event
if (deltaX < TOUCH_MOVE_THRESHOLD && deltaY < TOUCH_MOVE_THRESHOLD) {
return true; // Consume the event and stop it from propagating
}
break;
}

return super.dispatchTouchEvent(ev);
}
}

0 comments on commit 409187f

Please sign in to comment.