diff --git a/android/TODO.txt b/android/TODO.txt index faaa8010664..30da6eab07d 100644 --- a/android/TODO.txt +++ b/android/TODO.txt @@ -16,7 +16,6 @@ TODO: - add credits to about information - switch to Log4j for logging (maybe) - use center of d-pad for setting position -- add joypad sensitivity threshold for initiating keypress BUILD TODO: - script to download Android SDK diff --git a/android/app/src/main/java/org/arianne/stendhal/client/PreferencesActivity.java b/android/app/src/main/java/org/arianne/stendhal/client/PreferencesActivity.java index 987aefbc608..7ab6eb0de30 100644 --- a/android/app/src/main/java/org/arianne/stendhal/client/PreferencesActivity.java +++ b/android/app/src/main/java/org/arianne/stendhal/client/PreferencesActivity.java @@ -263,6 +263,8 @@ public void onSharedPreferenceChanged(final SharedPreferences sp, final String k currentPad.show(); currentPad.onRefreshView(); } + } else if (key.equals("joypad_sensitivity")) { + DPadJoy.get().setSensitivity(getInt("joypad_sensitivity", 25)); } } diff --git a/android/app/src/main/java/org/arianne/stendhal/client/input/DPadJoy.java b/android/app/src/main/java/org/arianne/stendhal/client/input/DPadJoy.java index 59ee1cfa6d5..08445530a31 100644 --- a/android/app/src/main/java/org/arianne/stendhal/client/input/DPadJoy.java +++ b/android/app/src/main/java/org/arianne/stendhal/client/input/DPadJoy.java @@ -39,6 +39,7 @@ public class DPadJoy extends DPad { private static ConstraintLayout layout; private static OuterButton outerButton; + private static int sensitivity; public static DPadJoy get() { @@ -57,6 +58,8 @@ private DPadJoy() { outerButton = new OuterButton(ctx); outerButton.addToLayout(); + setSensitivity(PreferencesActivity.getInt("joypad_sensitivity", 25)); + // hidden by default hide(); } @@ -101,6 +104,10 @@ public Pair getSize() { return new Pair(getWidth(), getHeight()); } + public void setSensitivity(final int value) { + sensitivity = value; + } + public void onRefreshView() { final Point size = new Point(); final Display disp = MainActivity.get().getWindowManager().getDefaultDisplay(); @@ -219,8 +226,15 @@ private DPad.Dir getTouchDirection() { final float offsetX = outerX - innerX; final float offsetY = outerY - innerY; - // horizontal directions take precedence - if (Math.abs(offsetX) >= Math.abs(offsetY)) { + final int absX = (int) Math.abs(offsetX); + final int absY = (int) Math.abs(offsetY); + + if (absX < sensitivity && absY < sensitivity) { + return DPad.Dir.NONE; + } + + // horizontal directions take precedence if they are the same as vertical + if (absX >= absY) { if (innerX < outerX) { return DPad.Dir.LEFT; } else if (innerX > outerX) { diff --git a/android/app/src/main/res/xml/preferences.xml b/android/app/src/main/res/xml/preferences.xml index 9176ee00e55..522d98f1e34 100644 --- a/android/app/src/main/res/xml/preferences.xml +++ b/android/app/src/main/res/xml/preferences.xml @@ -26,6 +26,16 @@ android:dependency="show_dpad" /> + +