Android: Add analog button to touchscreen controller

This commit is contained in:
Connor McLaughlin 2021-02-27 22:15:34 +10:00
parent 6e9a35806d
commit 2ce42cde5f
8 changed files with 88 additions and 2 deletions

View file

@ -1619,3 +1619,20 @@ DEFINE_JNI_ARGS_METHOD(jobjectArray, AndroidHostInterface_getSaveStateInfo, jobj
return ret; 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<s32> code = Controller::GetButtonCodeByName(ctrl->GetType(), "Analog");
if (!code.has_value())
continue;
ctrl->SetButtonState(code.value(), true);
ctrl->SetButtonState(code.value(), false);
}
}

View file

@ -86,6 +86,8 @@ public class AndroidHostInterface {
public native void handleControllerAxisEvent(int controllerIndex, int axisIndex, float value); public native void handleControllerAxisEvent(int controllerIndex, int axisIndex, float value);
public native void toggleControllerAnalogMode();
public native String[] getInputProfileNames(); public native String[] getInputProfileNames();
public native boolean loadInputProfile(String name); public native boolean loadInputProfile(String name);

View file

@ -15,7 +15,8 @@ public final class TouchscreenControllerButtonView extends View {
public enum Hotkey public enum Hotkey
{ {
NONE, NONE,
FAST_FORWARD FAST_FORWARD,
ANALOG_TOGGLE
} }
private Drawable mUnpressedDrawable; private Drawable mUnpressedDrawable;
@ -131,6 +132,12 @@ public final class TouchscreenControllerButtonView extends View {
AndroidHostInterface.getInstance().setFastForwardEnabled(mPressed); AndroidHostInterface.getInstance().setFastForwardEnabled(mPressed);
break; break;
case ANALOG_TOGGLE: {
if (mPressed)
AndroidHostInterface.getInstance().toggleControllerAnalogMode();
}
break;
case NONE: case NONE:
default: default:
break; break;

View file

@ -250,7 +250,9 @@ public class TouchscreenControllerView extends FrameLayout {
linkAxis(mMainView, R.id.controller_axis_right, "RightAxis", "Right", true); linkAxis(mMainView, R.id.controller_axis_right, "RightAxis", "Right", true);
linkHotkeyButton(mMainView, R.id.controller_button_fast_forward, "FastForward", 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(); reloadButtonSettings();
updateOpacity(); updateOpacity();

View file

@ -0,0 +1,17 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M0.6615,0.6614L23.7969,0.6614v23.0L0.6615,23.7969Z"
android:strokeAlpha="1"
android:strokeLineJoin="round"
android:strokeWidth="0.26458332"
android:fillColor="#00000000"
android:strokeColor="#e6e6e6"
android:strokeLineCap="round" />
<path
android:fillColor="#e6e6e6"
android:pathData="M12,2C6.49,2 2,6.49 2,12s4.49,10 10,10 10,-4.49 10,-10S17.51,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM15,12c0,1.66 -1.34,3 -3,3s-3,-1.34 -3,-3 1.34,-3 3,-3 3,1.34 3,3z"/>
</vector>

View file

@ -0,0 +1,17 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M0.6615,0.6614L23.7969,0.6614v23.0L0.6615,23.7969Z"
android:strokeAlpha="1"
android:strokeLineJoin="round"
android:strokeWidth="0.26458332"
android:fillColor="#4d4d4d"
android:strokeColor="#e6e6e6"
android:strokeLineCap="round" />
<path
android:fillColor="#e6e6e6"
android:pathData="M12,2C6.49,2 2,6.49 2,12s4.49,10 10,10 10,-4.49 10,-10S17.51,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM15,12c0,1.66 -1.34,3 -3,3s-3,-1.34 -3,-3 1.34,-3 3,-3 3,1.34 3,3z"/>
</vector>

View file

@ -145,4 +145,16 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:pressedDrawable="@drawable/ic_controller_fast_forward_pressed" app:pressedDrawable="@drawable/ic_controller_fast_forward_pressed"
app:unpressedDrawable="@drawable/ic_controller_fast_forward" /> app:unpressedDrawable="@drawable/ic_controller_fast_forward" />
<com.github.stenzek.duckstation.TouchscreenControllerButtonView
android:id="@+id/controller_button_analog"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginBottom="95dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:pressedDrawable="@drawable/ic_controller_analog_button_pressed"
app:unpressedDrawable="@drawable/ic_controller_analog_button" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -210,4 +210,16 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:pressedDrawable="@drawable/ic_controller_fast_forward_pressed" app:pressedDrawable="@drawable/ic_controller_fast_forward_pressed"
app:unpressedDrawable="@drawable/ic_controller_fast_forward" /> app:unpressedDrawable="@drawable/ic_controller_fast_forward" />
<com.github.stenzek.duckstation.TouchscreenControllerButtonView
android:id="@+id/controller_button_analog"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginBottom="95dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:pressedDrawable="@drawable/ic_controller_analog_button_pressed"
app:unpressedDrawable="@drawable/ic_controller_analog_button" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>