From d1c3b5cf6da7d9b8bb2e5d27019b6b4cc4a458e0 Mon Sep 17 00:00:00 2001 From: airidosas252 Date: Wed, 13 Nov 2024 13:39:44 +0200 Subject: [PATCH] Control overlay support --- .../java/com/termux/x11/MainActivity.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/app/src/main/java/com/termux/x11/MainActivity.java b/app/src/main/java/com/termux/x11/MainActivity.java index dadf80b8a..9a0afc90e 100644 --- a/app/src/main/java/com/termux/x11/MainActivity.java +++ b/app/src/main/java/com/termux/x11/MainActivity.java @@ -143,6 +143,37 @@ public static MainActivity getInstance() { @SuppressLint({"AppCompatMethod", "ObsoleteSdkInt", "ClickableViewAccessibility", "WrongConstant", "UnspecifiedRegisterReceiverFlag"}) protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + // Inflate and add overlay view if connected + if (mClientConnected) { + addOverlayControls(); + } +} + +private void addOverlayControls() { + if (overlayView == null) { + overlayView = getLayoutInflater().inflate(R.layout.overlay_controls, null); + addContentView(overlayView, new ViewGroup.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT + )); + + // Set up button listeners to inject events into LorieView + overlayView.findViewById(R.id.btn_up).setOnClickListener(v -> handleOverlayInput("up")); + overlayView.findViewById(R.id.btn_down).setOnClickListener(v -> handleOverlayInput("down")); + overlayView.findViewById(R.id.btn_left).setOnClickListener(v -> handleOverlayInput("left")); + overlayView.findViewById(R.id.btn_right).setOnClickListener(v -> handleOverlayInput("right")); + overlayView.findViewById(R.id.btn_action).setOnClickListener(v -> handleOverlayInput("action")); + } +} + +private void handleOverlayInput(String direction) { + // Pass the direction or action to your X11 view + if (getLorieView() != null) { + getLorieView().injectInput(direction); + } +} prefs = new Prefs(this); int modeValue = Integer.parseInt(prefs.touchMode.get()) - 1;