Skip to content

Commit

Permalink
feat: Add touchpad input mode selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtr126 committed Nov 17, 2023
1 parent 0633933 commit e6ccf6b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
return false;
});
mouseAimActions();
loadTouchpadInputSettings();
setDefaultVisibilty();
binding.sliders.setVisibility(View.VISIBLE);
}
Expand Down Expand Up @@ -137,6 +138,13 @@ private void mouseAimActions() {
((MaterialAutoCompleteTextView)binding.mouseAimAction).setSimpleItems(mouseAimActions);
}

private void loadTouchpadInputSettings() {
binding.touchpadInputMode.setText(keymapConfig.touchpadInputMode);

final String[] touchpadInputModes = {KeymapConfig.TOUCHPAD_DIRECT, KeymapConfig.TOUCHPAD_RELATIVE, KeymapConfig.TOUCHPAD_DISABLED};
((MaterialAutoCompleteTextView)binding.touchpadInputMode).setSimpleItems(touchpadInputModes);
}

public boolean onKey(View view, int keyCode, KeyEvent event) {
String key = String.valueOf(event.getDisplayLabel());
if ( key.matches("[a-zA-Z0-9]+" )) ((EditText) view).setText(key);
Expand Down Expand Up @@ -177,6 +185,7 @@ private void saveKeyboardShortcuts() {
public void onDestroyView() {
saveKeyboardShortcuts();
keymapConfig.mouseAimToggle = binding.mouseAimAction.getText().toString().equals(KeymapConfig.TOGGLE);
keymapConfig.touchpadInputMode = binding.touchpadInputMode.getText().toString();

keymapConfig.mouseSensitivity = binding.sliderMouse.getValue();
keymapConfig.scrollSpeed = binding.sliderScrollSpeed.getValue();
Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/xtr/keymapper/keymap/KeymapConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public class KeymapConfig implements Parcelable {

public static final String KEY_CTRL = "Ctrl", KEY_ALT = "Alt";
public static final String TOGGLE = "Toggle", HOLD = "Hold";
public static final int TOUCHPAD_DIRECT = 0;
public static final int TOUCHPAD_RELATIVE = 1;
public static final int TOUCHPAD_DISABLED = 2;
public static final String TOUCHPAD_DIRECT = "Direct";
public static final String TOUCHPAD_RELATIVE = "Relative";
public static final String TOUCHPAD_DISABLED = "Disabled";
public int mouseAimShortcutKey;
public boolean mouseAimToggle;
public int touchpadInputMode;
public String touchpadInputMode;

public KeymapConfig(Context context) {
sharedPref = context.getSharedPreferences("settings", MODE_PRIVATE);
Expand Down Expand Up @@ -64,7 +64,7 @@ protected KeymapConfig(Parcel in) {
mouseAimShortcutKey = in.readInt();
mouseAimToggle = in.readByte() != 0;
disableAutoProfiling = in.readByte() != 0;
touchpadInputMode = in.readInt();
touchpadInputMode = in.readString();
}

public static final Creator<KeymapConfig> CREATOR = new Creator<>() {
Expand Down Expand Up @@ -102,7 +102,7 @@ private void loadSharedPrefs() {
swipeDelayMs = sharedPref.getInt("swipe_delay_ms", 0);
dpadRadiusMultiplier = sharedPref.getFloat("dpad_radius", 1f);

touchpadInputMode = sharedPref.getInt("touchpad_input_mode", TOUCHPAD_RELATIVE);
touchpadInputMode = sharedPref.getString("touchpad_input_mode", TOUCHPAD_RELATIVE);
}

public void applySharedPrefs() {
Expand All @@ -122,8 +122,8 @@ public void applySharedPrefs() {
.putString("pause_resume_shortcut_modifier", pauseResumeShortcutKeyModifier)
.putString("launch_editor_shortcut_modifier", launchEditorShortcutKeyModifier)
.putString("switch_profile_shortcut_modifier", switchProfileShortcutKeyModifier)
.putString("touchpad_input_mode", touchpadInputMode)
.putInt("swipe_delay_ms", swipeDelayMs)
.putInt("touchpad_input_mode", touchpadInputMode)
.apply();
}

Expand Down Expand Up @@ -166,6 +166,6 @@ public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeInt(mouseAimShortcutKey);
dest.writeByte((byte) (mouseAimToggle ? 1 : 0));
dest.writeByte((byte) (disableAutoProfiling ? 1 : 0));
dest.writeInt(touchpadInputMode);
dest.writeString(touchpadInputMode);
}
}
28 changes: 28 additions & 0 deletions app/src/main/res/layout/fragment_settings_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,34 @@
android:layout_height="match_parent"
android:checked="true"
android:text="@string/disable_auto_profile" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="@string/touchpad_input" />


<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.Material3.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<AutoCompleteTextView
android:id="@+id/touchpad_input_mode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none" />

</com.google.android.material.textfield.TextInputLayout>

</LinearLayout>

</LinearLayout>

<com.google.android.material.bottomnavigation.BottomNavigationView
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@
<string name="root_not_found_title">Root access not found</string>
<string name="root_not_found_message">Root access is required for the keymapper to function. \n Please grant root access to XtMapper from KernelSU manager app:</string>
<string name="disable_auto_profile">Disable auto profiling</string>
<string name="touchpad_input">Touchpad Input</string>

</resources>

0 comments on commit e6ccf6b

Please sign in to comment.