From 31b65542f96dbeaa437d1e453a436852de077833 Mon Sep 17 00:00:00 2001
From: Xtr126 <80520774+Xtr126@users.noreply.github.com>
Date: Sat, 10 Aug 2024 18:21:30 +0530
Subject: [PATCH] feat: vertical/horizontal sensitivity adjustment for aiming
---
.../java/xtr/keymapper/editor/EditorUI.java | 41 +++++++++++--
.../keymapper/editor/ResizeableDpadView.java | 2 +-
.../xtr/keymapper/mouse/MouseAimHandler.java | 6 +-
.../xtr/keymapper/mouse/MouseAimSettings.java | 36 ------------
app/src/main/res/layout/mouse_aim_config.xml | 58 +++++++++++++++++++
app/src/main/res/values-zh-rCN/strings.xml | 5 ++
app/src/main/res/values/strings.xml | 5 ++
7 files changed, 108 insertions(+), 45 deletions(-)
delete mode 100644 app/src/main/java/xtr/keymapper/mouse/MouseAimSettings.java
create mode 100644 app/src/main/res/layout/mouse_aim_config.xml
diff --git a/app/src/main/java/xtr/keymapper/editor/EditorUI.java b/app/src/main/java/xtr/keymapper/editor/EditorUI.java
index facb61d5..13250e71 100644
--- a/app/src/main/java/xtr/keymapper/editor/EditorUI.java
+++ b/app/src/main/java/xtr/keymapper/editor/EditorUI.java
@@ -30,16 +30,17 @@
import xtr.keymapper.databinding.DpadArrowsBinding;
import xtr.keymapper.databinding.DpadBinding;
import xtr.keymapper.databinding.KeymapEditorBinding;
+import xtr.keymapper.databinding.MouseAimConfigBinding;
import xtr.keymapper.databinding.ResizableBinding;
import xtr.keymapper.dpad.Dpad;
import xtr.keymapper.dpad.DpadKeyCodes;
import xtr.keymapper.floatingkeys.MovableFloatingActionKey;
import xtr.keymapper.floatingkeys.MovableFrameLayout;
+import xtr.keymapper.keymap.KeymapConfig;
import xtr.keymapper.keymap.KeymapProfile;
import xtr.keymapper.keymap.KeymapProfileKey;
import xtr.keymapper.keymap.KeymapProfiles;
import xtr.keymapper.mouse.MouseAimConfig;
-import xtr.keymapper.mouse.MouseAimSettings;
import xtr.keymapper.server.RemoteServiceHelper;
import xtr.keymapper.swipekey.SwipeKey;
import xtr.keymapper.swipekey.SwipeKeyView;
@@ -322,7 +323,7 @@ private void moveResizeDpad(ViewGroup dpadLayout, Dpad dpad, float x, float y) {
// resize dpad from saved profile configuration
float x1 = dpad.getWidth() - dpadLayout.getLayoutParams().width;
float y1 = dpad.getHeight() - dpadLayout.getLayoutParams().height;
- resizeView(dpadLayout, x1, y1);
+ resizeView(dpadLayout, (int) x1, (int) y1);
}
}
@@ -353,6 +354,36 @@ public void onClick(View view) {
keyInFocus = key -> ((MovableFloatingActionKey)view).setText(key);
}
+ public void showMouseAimSettingsDialog() {
+ KeymapConfig keymapConfig = new KeymapConfig(context);
+ AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ MouseAimConfigBinding binding = MouseAimConfigBinding.inflate(layoutInflater, null, false);
+
+ // Load settings
+ binding.rightClickCheckbox.setChecked(keymapConfig.rightClickMouseAim);
+ binding.graveKeyCheckbox.setChecked(keymapConfig.keyGraveMouseAim);
+ binding.applyNonLinearScalingCheckbox.setChecked(profile.mouseAimConfig.applyNonLinearScaling);
+ binding.sliderXSensitivity.setValue(profile.mouseAimConfig.xSensitivity);
+ binding.sliderYSensitivity.setValue(profile.mouseAimConfig.ySensitivity);
+
+ View view = binding.getRoot();
+ builder.setView(view)
+ .setPositiveButton(R.string.ok, (dialog, which) -> {
+ // Save settings
+ keymapConfig.rightClickMouseAim = binding.rightClickCheckbox.isChecked();
+ keymapConfig.keyGraveMouseAim = binding.graveKeyCheckbox.isChecked();
+ keymapConfig.applySharedPrefs();
+
+ profile.mouseAimConfig.applyNonLinearScaling = binding.applyNonLinearScalingCheckbox.isChecked();
+ profile.mouseAimConfig.xSensitivity = binding.sliderXSensitivity.getValue();
+ profile.mouseAimConfig.ySensitivity = binding.sliderYSensitivity.getValue();
+ })
+ .setNegativeButton(R.string.cancel, null);
+ AlertDialog dialog = builder.create();
+ dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
+ dialog.show();
+ }
+
private void addCrosshair(float x, float y) {
if (crosshair == null) {
CrosshairBinding binding = CrosshairBinding.inflate(layoutInflater, mainView, true);
@@ -381,7 +412,7 @@ private void addCrosshair(float x, float y) {
if(overlayOpen) dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
dialog.show();
});
- binding.editButton.setOnClickListener(v -> MouseAimSettings.getKeyDialog(context).show());
+ binding.editButton.setOnClickListener(v -> showMouseAimSettingsDialog());
}
crosshair.animate().x(x).y(y)
.setDuration(500)
@@ -418,7 +449,7 @@ private void addSwipeKey() {
swipeKeyList.add(swipeKeyView);
}
- public static void resizeView(View view, float x, float y) {
+ public static void resizeView(View view, int x, int y) {
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
layoutParams.width += x;
layoutParams.height += y;
@@ -446,7 +477,7 @@ private void getDefaultPivotXY(){
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE) {
- resizeView(rootView, event.getX(), event.getY());
+ resizeView(rootView, (int) event.getX(), (int) event.getY());
// Resize View from center point
if (defaultPivotX > 0) {
float newPivotX = rootView.getPivotX() - defaultPivotX;
diff --git a/app/src/main/java/xtr/keymapper/editor/ResizeableDpadView.java b/app/src/main/java/xtr/keymapper/editor/ResizeableDpadView.java
index de3b1c31..0f201eb1 100644
--- a/app/src/main/java/xtr/keymapper/editor/ResizeableDpadView.java
+++ b/app/src/main/java/xtr/keymapper/editor/ResizeableDpadView.java
@@ -22,7 +22,7 @@ private void getDefaultPivotXY() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE) {
// Resize View in fixed ratio
- float newSize = (event.getX() + event.getY()) / 2;
+ int newSize = ((int)event.getX() + (int)event.getY()) / 2;
EditorUI.resizeView(rootView, newSize, newSize);
// Resize View from center point
diff --git a/app/src/main/java/xtr/keymapper/mouse/MouseAimHandler.java b/app/src/main/java/xtr/keymapper/mouse/MouseAimHandler.java
index f9480093..073750ff 100644
--- a/app/src/main/java/xtr/keymapper/mouse/MouseAimHandler.java
+++ b/app/src/main/java/xtr/keymapper/mouse/MouseAimHandler.java
@@ -68,13 +68,13 @@ public void resetPointer() {
public void handleEvent(int code, int value, OnButtonClickListener listener) {
switch (code) {
case REL_X:
- currentX += calculateScaledX(value);
+ currentX += (float) calculateScaledX(value);
if (config.limitedBounds && (currentX > area.right || currentX < area.left))
resetPointer();
service.injectEvent(currentX, currentY, MOVE, pointerIdAim);
break;
case REL_Y:
- currentY += calculateScaledY(value);;
+ currentY += calculateScaledY(value);
if (config.limitedBounds && (currentY > area.bottom || currentY < area.top))
resetPointer();
service.injectEvent(currentX, currentY, MOVE, pointerIdAim);
@@ -111,7 +111,7 @@ public double calculateScaledX(int value) {
}
}
- private double calculateScaledY(int value) {
+ private float calculateScaledY(int value) {
return value * config.ySensitivity;
}
diff --git a/app/src/main/java/xtr/keymapper/mouse/MouseAimSettings.java b/app/src/main/java/xtr/keymapper/mouse/MouseAimSettings.java
deleted file mode 100644
index f97a2257..00000000
--- a/app/src/main/java/xtr/keymapper/mouse/MouseAimSettings.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package xtr.keymapper.mouse;
-
-import android.app.Dialog;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.view.WindowManager;
-
-import androidx.appcompat.app.AlertDialog;
-
-import com.google.android.material.dialog.MaterialAlertDialogBuilder;
-
-import xtr.keymapper.keymap.KeymapConfig;
-
-public class MouseAimSettings {
-
- public static Dialog getKeyDialog(Context context) {
- KeymapConfig keymapConfig = new KeymapConfig(context);
- AlertDialog.Builder builder = new AlertDialog.Builder(context);
- CharSequence[] list = {"Mouse right click", "~ key"};
- boolean[] checkedItems = {keymapConfig.rightClickMouseAim, keymapConfig.keyGraveMouseAim};
- // Set the dialog title
- builder.setTitle("Activate with")
- .setMultiChoiceItems(list, checkedItems,
- (dialog, which, isChecked) -> {
- if (which == 0) {
- keymapConfig.rightClickMouseAim = isChecked;
- } else if (which == 1)
- keymapConfig.keyGraveMouseAim = isChecked;
-
- keymapConfig.applySharedPrefs();
- });
- AlertDialog dialog = builder.create();
- dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
- return dialog;
- }
-}
diff --git a/app/src/main/res/layout/mouse_aim_config.xml b/app/src/main/res/layout/mouse_aim_config.xml
new file mode 100644
index 00000000..a45b85d3
--- /dev/null
+++ b/app/src/main/res/layout/mouse_aim_config.xml
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml
index 44a03103..01a79b2b 100644
--- a/app/src/main/res/values-zh-rCN/strings.xml
+++ b/app/src/main/res/values-zh-rCN/strings.xml
@@ -85,4 +85,9 @@
Shizuku not authorized
Authorize XtMapper from Shizuku manager app to continue
+ Activate with
+ ~ key
+ X-Sensitivity
+ Y-Sensitivity
+ Apply non linear scaling
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index e3cd47d9..0e1a8702 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -86,4 +86,9 @@
Shizuku not authorized
Authorize XtMapper from Shizuku manager app to continue
+ Activate with
+ ~ key
+ X-Sensitivity
+ Y-Sensitivity
+ Apply non linear scaling
\ No newline at end of file