From 3011c0dc64d3de8bc56b8bb73fb2addae2e6c484 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Sat, 10 Jun 2023 05:06:00 -0400 Subject: [PATCH] Android: Convert EmulatedController to Kotlin --- .../controlleremu/EmulatedController.java | 52 ------------------- .../model/controlleremu/EmulatedController.kt | 52 +++++++++++++++++++ .../features/settings/ui/SettingsAdapter.kt | 2 +- .../settings/ui/SettingsFragmentPresenter.kt | 4 +- Source/Android/jni/AndroidCommon/IDCache.cpp | 2 +- 5 files changed, 56 insertions(+), 56 deletions(-) delete mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/EmulatedController.java create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/EmulatedController.kt diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/EmulatedController.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/EmulatedController.java deleted file mode 100644 index 39645ffbba..0000000000 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/EmulatedController.java +++ /dev/null @@ -1,52 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later - -package org.dolphinemu.dolphinemu.features.input.model.controlleremu; - -import androidx.annotation.Keep; - -/** - * Represents a C++ ControllerEmu::EmulatedController. - * - * The lifetime of this class is managed by C++ code. Calling methods on it after it's destroyed - * in C++ is undefined behavior! - */ -public class EmulatedController -{ - @Keep - private final long mPointer; - - @Keep - private EmulatedController(long pointer) - { - mPointer = pointer; - } - - public native String getDefaultDevice(); - - public native void setDefaultDevice(String device); - - public native int getGroupCount(); - - public native ControlGroup getGroup(int index); - - public native void updateSingleControlReference(ControlReference controlReference); - - public native void loadDefaultSettings(); - - public native void clearSettings(); - - public native void loadProfile(String path); - - public native void saveProfile(String path); - - public static native EmulatedController getGcPad(int controllerIndex); - - public static native EmulatedController getWiimote(int controllerIndex); - - public static native EmulatedController getWiimoteAttachment(int controllerIndex, - int attachmentIndex); - - public static native int getSelectedWiimoteAttachment(int controllerIndex); - - public static native NumericSetting getSidewaysWiimoteSetting(int controllerIndex); -} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/EmulatedController.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/EmulatedController.kt new file mode 100644 index 0000000000..348e75b6a0 --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/EmulatedController.kt @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.dolphinemu.dolphinemu.features.input.model.controlleremu + +import androidx.annotation.Keep + +/** + * Represents a C++ ControllerEmu::EmulatedController. + * + * The lifetime of this class is managed by C++ code. Calling methods on it after it's destroyed + * in C++ is undefined behavior! + */ +@Keep +class EmulatedController private constructor(private val pointer: Long) { + external fun getDefaultDevice(): String + + external fun setDefaultDevice(device: String) + + external fun getGroupCount(): Int + + external fun getGroup(index: Int): ControlGroup + + external fun updateSingleControlReference(controlReference: ControlReference) + + external fun loadDefaultSettings() + + external fun clearSettings() + + external fun loadProfile(path: String) + + external fun saveProfile(path: String) + + companion object { + @JvmStatic + external fun getGcPad(controllerIndex: Int): EmulatedController + + @JvmStatic + external fun getWiimote(controllerIndex: Int): EmulatedController + + @JvmStatic + external fun getWiimoteAttachment( + controllerIndex: Int, + attachmentIndex: Int + ): EmulatedController + + @JvmStatic + external fun getSelectedWiimoteAttachment(controllerIndex: Int): Int + + @JvmStatic + external fun getSidewaysWiimoteSetting(controllerIndex: Int): NumericSetting + } +} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.kt index d5df7c0e09..e3e745fafa 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.kt @@ -258,7 +258,7 @@ class SettingsAdapter( } fun onInputMappingClick(item: InputMappingControlSetting, position: Int) { - if (item.controller.defaultDevice.isEmpty() && !fragmentView.isMappingAllDevices) { + if (item.controller.getDefaultDevice().isEmpty() && !fragmentView.isMappingAllDevices) { MaterialAlertDialogBuilder(fragmentView.fragmentActivity) .setMessage(R.string.input_binding_no_device) .setPositiveButton(R.string.ok, this) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.kt index 09298d0b8a..8cb63c420e 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.kt +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.kt @@ -2251,7 +2251,7 @@ class SettingsFragmentPresenter( ) { updateOldControllerSettingsWarningVisibility(controller) - val groupCount = controller.groupCount + val groupCount = controller.getGroupCount() for (i in 0 until groupCount) { val group = controller.getGroup(i) val groupType = group.getGroupType() @@ -2322,7 +2322,7 @@ class SettingsFragmentPresenter( } private fun updateOldControllerSettingsWarningVisibility(controller: EmulatedController) { - val defaultDevice = controller.defaultDevice + val defaultDevice = controller.getDefaultDevice() hasOldControllerSettings = defaultDevice.startsWith("Android/") && defaultDevice.endsWith("/Touchscreen") diff --git a/Source/Android/jni/AndroidCommon/IDCache.cpp b/Source/Android/jni/AndroidCommon/IDCache.cpp index 60c3933dc4..b5c91be10c 100644 --- a/Source/Android/jni/AndroidCommon/IDCache.cpp +++ b/Source/Android/jni/AndroidCommon/IDCache.cpp @@ -725,7 +725,7 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) "org/dolphinemu/dolphinemu/features/input/model/controlleremu/EmulatedController"); s_emulated_controller_class = reinterpret_cast(env->NewGlobalRef(emulated_controller_class)); - s_emulated_controller_pointer = env->GetFieldID(emulated_controller_class, "mPointer", "J"); + s_emulated_controller_pointer = env->GetFieldID(emulated_controller_class, "pointer", "J"); s_emulated_controller_constructor = env->GetMethodID(emulated_controller_class, "", "(J)V"); env->DeleteLocalRef(emulated_controller_class);