mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2026-04-22 16:26:41 +00:00
Make StreamView transparent to touch events and handle everything in the background view
This is much simpler than trying to play games with touch handling between 2 views
This commit is contained in:
@@ -84,7 +84,6 @@ import java.security.cert.CertificateException;
|
|||||||
import java.security.cert.CertificateFactory;
|
import java.security.cert.CertificateFactory;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Timer;
|
|
||||||
|
|
||||||
|
|
||||||
public class Game extends Activity implements SurfaceHolder.Callback,
|
public class Game extends Activity implements SurfaceHolder.Callback,
|
||||||
@@ -97,7 +96,6 @@ public class Game extends Activity implements SurfaceHolder.Callback,
|
|||||||
// Only 2 touches are supported
|
// Only 2 touches are supported
|
||||||
private final TouchContext[] touchContextMap = new TouchContext[2];
|
private final TouchContext[] touchContextMap = new TouchContext[2];
|
||||||
private long threeFingerDownTime = 0;
|
private long threeFingerDownTime = 0;
|
||||||
private View primaryTouchOwner;
|
|
||||||
|
|
||||||
private static final int REFERENCE_HORIZ_RES = 1280;
|
private static final int REFERENCE_HORIZ_RES = 1280;
|
||||||
private static final int REFERENCE_VERT_RES = 720;
|
private static final int REFERENCE_VERT_RES = 720;
|
||||||
@@ -234,13 +232,12 @@ public class Game extends Activity implements SurfaceHolder.Callback,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listen for events on the game surface
|
// Listen for non-touch events on the game surface
|
||||||
streamView = findViewById(R.id.surfaceView);
|
streamView = findViewById(R.id.surfaceView);
|
||||||
streamView.setOnGenericMotionListener(this);
|
streamView.setOnGenericMotionListener(this);
|
||||||
streamView.setOnTouchListener(this);
|
|
||||||
streamView.setInputCallbacks(this);
|
streamView.setInputCallbacks(this);
|
||||||
|
|
||||||
// Listen for touch events outside of the game surface to enable trackpad mode
|
// Listen for touch events on the background touch view to enable trackpad mode
|
||||||
// to work on areas outside of the StreamView itself. We use a separate View
|
// to work on areas outside of the StreamView itself. We use a separate View
|
||||||
// for this rather than just handling it at the Activity level, because that
|
// for this rather than just handling it at the Activity level, because that
|
||||||
// allows proper touch splitting, which the OSC relies upon.
|
// allows proper touch splitting, which the OSC relies upon.
|
||||||
@@ -641,37 +638,6 @@ public class Game extends Activity implements SurfaceHolder.Callback,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean handlePrimaryTouchOwner(View view, MotionEvent event) {
|
|
||||||
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
|
|
||||||
if (primaryTouchOwner == null) {
|
|
||||||
// This is the first dispatch, so we become the primary touch owner
|
|
||||||
primaryTouchOwner = view;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fall-through
|
|
||||||
}
|
|
||||||
else if (event.getActionMasked() == MotionEvent.ACTION_UP ||
|
|
||||||
event.getActionMasked() == MotionEvent.ACTION_CANCEL) {
|
|
||||||
if (primaryTouchOwner == view) {
|
|
||||||
// This is the concluding event on the primary touch owner, so we
|
|
||||||
// are no longer the primary touch owner now.
|
|
||||||
primaryTouchOwner = null;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (view != streamView && primaryTouchOwner == streamView) {
|
|
||||||
// If we hit this codepath, the StreamView didn't handle the UP/CANCEL event.
|
|
||||||
// This is unexpected, but we can recover by allowing the background view
|
|
||||||
// to handle it and resetting the primary touch owner.
|
|
||||||
LimeLog.warning("Unhandled StreamView touch event: "+event);
|
|
||||||
primaryTouchOwner = null;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// For all down/move events, handle the event if we're the primary touch owner.
|
|
||||||
return view == primaryTouchOwner;
|
|
||||||
}
|
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.O)
|
@TargetApi(Build.VERSION_CODES.O)
|
||||||
private PictureInPictureParams getPictureInPictureParams(boolean autoEnter) {
|
private PictureInPictureParams getPictureInPictureParams(boolean autoEnter) {
|
||||||
PictureInPictureParams.Builder builder =
|
PictureInPictureParams.Builder builder =
|
||||||
@@ -1804,12 +1770,6 @@ public class Game extends Activity implements SurfaceHolder.Callback,
|
|||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View view, MotionEvent event) {
|
public boolean onTouch(View view, MotionEvent event) {
|
||||||
// If we're not the primary touch owner, ignore this event to allow the original
|
|
||||||
// view to take care of it (allowing multi-finger gestures across views to work).
|
|
||||||
if (!handlePrimaryTouchOwner(view, event)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||||
// Tell the OS not to buffer input events for us
|
// Tell the OS not to buffer input events for us
|
||||||
|
|||||||
Reference in New Issue
Block a user