Skip to content

Commit

Permalink
XServerDisplayActivity: Fixed cannot see changes of input controls un…
Browse files Browse the repository at this point in the history
…til reset.
  • Loading branch information
longjunyu2 committed Aug 26, 2024
1 parent f6beb35 commit b3e6353
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions app/src/main/java/com/winlator/XServerDisplayActivity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.winlator;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
Expand All @@ -13,14 +12,14 @@
import android.view.MotionEvent;
import android.view.PointerIcon;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.FrameLayout;
import android.widget.Spinner;

import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
Expand Down Expand Up @@ -341,17 +340,6 @@ public void onFailed(Exception e) {
runnable.run();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == MainActivity.EDIT_INPUT_CONTROLS_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
if (editInputControlsCallback != null) {
editInputControlsCallback.run();
editInputControlsCallback = null;
}
}
}

@Override
public void onResume() {
super.onResume();
Expand Down Expand Up @@ -641,6 +629,16 @@ private void setupUI() {
AppUtils.observeSoftKeyboardVisibility(drawerLayout, renderer::setScreenOffsetYRelativeToCursor);
}

private ActivityResultLauncher<Intent> controlsEitorActivityResultLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
result -> {
if (editInputControlsCallback != null) {
editInputControlsCallback.run();
editInputControlsCallback = null;
}
}
);

private void showInputControlsDialog() {
final ContentDialog dialog = new ContentDialog(this, R.layout.input_controls_dialog);
dialog.setTitle(R.string.input_controls);
Expand All @@ -654,7 +652,8 @@ private void showInputControlsDialog() {
profileItems.add("-- "+getString(R.string.disabled)+" --");
for (int i = 0; i < profiles.size(); i++) {
ControlsProfile profile = profiles.get(i);
if (profile == inputControlsView.getProfile()) selectedPosition = i + 1;
if (inputControlsView.getProfile() != null && profile.id == inputControlsView.getProfile().id)
selectedPosition = i + 1;
profileItems.add(profile.getName());
}

Expand All @@ -672,30 +671,37 @@ private void showInputControlsDialog() {
final CheckBox cbShowTouchscreenControls = dialog.findViewById(R.id.CBShowTouchscreenControls);
cbShowTouchscreenControls.setChecked(inputControlsView.isShowTouchscreenControls());

final Runnable updateProfile = () -> {
int position = sProfile.getSelectedItemPosition();
if (position > 0) {
showInputControls(inputControlsManager.getProfiles().get(position - 1));
}
else hideInputControls();
};

dialog.findViewById(R.id.BTSettings).setOnClickListener((v) -> {
int position = sProfile.getSelectedItemPosition();
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("edit_input_controls", true);
intent.putExtra("selected_profile_id", position > 0 ? inputControlsManager.getProfiles().get(position - 1).id : 0);
editInputControlsCallback = () -> {
hideInputControls();
inputControlsManager.loadProfiles(true);
loadProfileSpinner.run();
updateProfile.run();
};
startActivityForResult(intent, MainActivity.EDIT_INPUT_CONTROLS_REQUEST_CODE);
controlsEitorActivityResultLauncher.launch(intent);
});

dialog.setOnConfirmCallback(() -> {
xServer.setRelativeMouseMovement(cbRelativeMouseMovement.isChecked());
inputControlsView.setShowTouchscreenControls(cbShowTouchscreenControls.isChecked());
int position = sProfile.getSelectedItemPosition();
if (position > 0) {
showInputControls(inputControlsManager.getProfiles().get(position - 1));
}
else hideInputControls();
touchpadView.setSimTouchScreen(cbSimTouchScreen.isChecked());
updateProfile.run();
});

dialog.setOnCancelCallback(updateProfile::run);

dialog.setCanceledOnTouchOutside(false);
dialog.show();
}

Expand Down

0 comments on commit b3e6353

Please sign in to comment.