Skip to content

Commit

Permalink
Control overlay support
Browse files Browse the repository at this point in the history
  • Loading branch information
airidosas252 authored Nov 13, 2024
1 parent e4395b7 commit d1c3b5c
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions app/src/main/java/com/termux/x11/MainActivity.java
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit d1c3b5c

Please sign in to comment.