Skip to content

Commit

Permalink
WebView: use sensitivity threshold for joy d-pad
Browse files Browse the repository at this point in the history
  • Loading branch information
AntumDeluge committed Feb 21, 2022
1 parent f529c00 commit 1d1833b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
1 change: 0 additions & 1 deletion android/TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -57,6 +58,8 @@ private DPadJoy() {
outerButton = new OuterButton(ctx);
outerButton.addToLayout();

setSensitivity(PreferencesActivity.getInt("joypad_sensitivity", 25));

// hidden by default
hide();
}
Expand Down Expand Up @@ -101,6 +104,10 @@ public Pair<Integer, Integer> getSize() {
return new Pair<Integer, Integer>(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();
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions android/app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
android:dependency="show_dpad"
/>

<EditTextPreference
android:key="joypad_sensitivity"
android:inputType="numberDecimal"
android:digits="0123456789"
android:defaultValue="25"
android:title="Joypad Sensitivity"
android:summary="Threshold, in pixels, at which joypad will dispatch move event (lower = more sensitive)."
android:dependency="dpad_joy"
/>

<EditTextPreference
android:key="dpad_offset_x"
android:inputType="numberDecimal"
Expand Down

0 comments on commit 1d1833b

Please sign in to comment.