diff --git a/android/app/src/cpp/android_host_interface.cpp b/android/app/src/cpp/android_host_interface.cpp index 4eaa3107d..a999ac8da 100644 --- a/android/app/src/cpp/android_host_interface.cpp +++ b/android/app/src/cpp/android_host_interface.cpp @@ -1619,3 +1619,20 @@ DEFINE_JNI_ARGS_METHOD(jobjectArray, AndroidHostInterface_getSaveStateInfo, jobj return ret; } + +DEFINE_JNI_ARGS_METHOD(void, AndroidHostInterface_toggleControllerAnalogMode, jobject obj) { + // hacky way to toggle analog mode + for (u32 i = 0; i < NUM_CONTROLLER_AND_CARD_PORTS; i++) + { + Controller* ctrl = System::GetController(i); + if (!ctrl) + continue; + + std::optional code = Controller::GetButtonCodeByName(ctrl->GetType(), "Analog"); + if (!code.has_value()) + continue; + + ctrl->SetButtonState(code.value(), true); + ctrl->SetButtonState(code.value(), false); + } +} \ No newline at end of file diff --git a/android/app/src/main/java/com/github/stenzek/duckstation/AndroidHostInterface.java b/android/app/src/main/java/com/github/stenzek/duckstation/AndroidHostInterface.java index dab8a5840..04b374a58 100644 --- a/android/app/src/main/java/com/github/stenzek/duckstation/AndroidHostInterface.java +++ b/android/app/src/main/java/com/github/stenzek/duckstation/AndroidHostInterface.java @@ -86,6 +86,8 @@ public class AndroidHostInterface { public native void handleControllerAxisEvent(int controllerIndex, int axisIndex, float value); + public native void toggleControllerAnalogMode(); + public native String[] getInputProfileNames(); public native boolean loadInputProfile(String name); diff --git a/android/app/src/main/java/com/github/stenzek/duckstation/TouchscreenControllerButtonView.java b/android/app/src/main/java/com/github/stenzek/duckstation/TouchscreenControllerButtonView.java index cfb5e6305..410700824 100644 --- a/android/app/src/main/java/com/github/stenzek/duckstation/TouchscreenControllerButtonView.java +++ b/android/app/src/main/java/com/github/stenzek/duckstation/TouchscreenControllerButtonView.java @@ -15,7 +15,8 @@ public final class TouchscreenControllerButtonView extends View { public enum Hotkey { NONE, - FAST_FORWARD + FAST_FORWARD, + ANALOG_TOGGLE } private Drawable mUnpressedDrawable; @@ -131,6 +132,12 @@ public final class TouchscreenControllerButtonView extends View { AndroidHostInterface.getInstance().setFastForwardEnabled(mPressed); break; + case ANALOG_TOGGLE: { + if (mPressed) + AndroidHostInterface.getInstance().toggleControllerAnalogMode(); + } + break; + case NONE: default: break; diff --git a/android/app/src/main/java/com/github/stenzek/duckstation/TouchscreenControllerView.java b/android/app/src/main/java/com/github/stenzek/duckstation/TouchscreenControllerView.java index 0ce216a6a..c5c01f705 100644 --- a/android/app/src/main/java/com/github/stenzek/duckstation/TouchscreenControllerView.java +++ b/android/app/src/main/java/com/github/stenzek/duckstation/TouchscreenControllerView.java @@ -250,7 +250,9 @@ public class TouchscreenControllerView extends FrameLayout { linkAxis(mMainView, R.id.controller_axis_right, "RightAxis", "Right", true); linkHotkeyButton(mMainView, R.id.controller_button_fast_forward, "FastForward", - TouchscreenControllerButtonView.Hotkey.FAST_FORWARD, true); + TouchscreenControllerButtonView.Hotkey.FAST_FORWARD, false); + linkHotkeyButton(mMainView, R.id.controller_button_analog, "AnalogToggle", + TouchscreenControllerButtonView.Hotkey.ANALOG_TOGGLE, false); reloadButtonSettings(); updateOpacity(); diff --git a/android/app/src/main/res/drawable/ic_controller_analog_button.xml b/android/app/src/main/res/drawable/ic_controller_analog_button.xml new file mode 100644 index 000000000..fec0a0a6e --- /dev/null +++ b/android/app/src/main/res/drawable/ic_controller_analog_button.xml @@ -0,0 +1,17 @@ + + + + diff --git a/android/app/src/main/res/drawable/ic_controller_analog_button_pressed.xml b/android/app/src/main/res/drawable/ic_controller_analog_button_pressed.xml new file mode 100644 index 000000000..b08bd5e16 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_controller_analog_button_pressed.xml @@ -0,0 +1,17 @@ + + + + diff --git a/android/app/src/main/res/layout/layout_touchscreen_controller_analog_stick.xml b/android/app/src/main/res/layout/layout_touchscreen_controller_analog_stick.xml index f1482c2e0..39fd2b168 100644 --- a/android/app/src/main/res/layout/layout_touchscreen_controller_analog_stick.xml +++ b/android/app/src/main/res/layout/layout_touchscreen_controller_analog_stick.xml @@ -145,4 +145,16 @@ app:layout_constraintStart_toStartOf="parent" app:pressedDrawable="@drawable/ic_controller_fast_forward_pressed" app:unpressedDrawable="@drawable/ic_controller_fast_forward" /> + + \ No newline at end of file diff --git a/android/app/src/main/res/layout/layout_touchscreen_controller_analog_sticks.xml b/android/app/src/main/res/layout/layout_touchscreen_controller_analog_sticks.xml index 9b53250f6..70a468ffc 100644 --- a/android/app/src/main/res/layout/layout_touchscreen_controller_analog_sticks.xml +++ b/android/app/src/main/res/layout/layout_touchscreen_controller_analog_sticks.xml @@ -210,4 +210,16 @@ app:layout_constraintStart_toStartOf="parent" app:pressedDrawable="@drawable/ic_controller_fast_forward_pressed" app:unpressedDrawable="@drawable/ic_controller_fast_forward" /> + + \ No newline at end of file