From 9ac1847cbd08024b2da8e201b2d5c03cc94595c6 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Sat, 10 Jun 2023 05:08:08 -0400 Subject: [PATCH] Android: Convert NumericSetting to Kotlin --- .../model/controlleremu/NumericSetting.java | 104 ------------------ .../model/controlleremu/NumericSetting.kt | 97 ++++++++++++++++ .../settings/ui/SettingsFragmentPresenter.kt | 14 +-- Source/Android/jni/AndroidCommon/IDCache.cpp | 2 +- 4 files changed, 105 insertions(+), 112 deletions(-) delete mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/NumericSetting.java create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/NumericSetting.kt diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/NumericSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/NumericSetting.java deleted file mode 100644 index bcb9dce181..0000000000 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/NumericSetting.java +++ /dev/null @@ -1,104 +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::NumericSetting. - * - * 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 NumericSetting -{ - public static final int TYPE_INT = 0; - public static final int TYPE_DOUBLE = 1; - public static final int TYPE_BOOLEAN = 2; - - @Keep - private final long mPointer; - - @Keep - private NumericSetting(long pointer) - { - mPointer = pointer; - } - - /** - * @return The name used in the UI. - */ - public native String getUiName(); - - /** - * @return A string applied to the number in the UI (unit of measure). - */ - public native String getUiSuffix(); - - /** - * @return Detailed description of the setting. - */ - public native String getUiDescription(); - - /** - * @return TYPE_INT, TYPE_DOUBLE or TYPE_BOOLEAN - */ - public native int getType(); - - public native ControlReference getControlReference(); - - /** - * If the type is TYPE_INT, gets the current value. Otherwise, undefined behavior! - */ - public native int getIntValue(); - - /** - * If the type is TYPE_INT, sets the current value. Otherwise, undefined behavior! - */ - public native void setIntValue(int value); - - /** - * If the type is TYPE_INT, gets the default value. Otherwise, undefined behavior! - */ - public native int getIntDefaultValue(); - - /** - * If the type is TYPE_DOUBLE, gets the current value. Otherwise, undefined behavior! - */ - public native double getDoubleValue(); - - /** - * If the type is TYPE_DOUBLE, sets the current value. Otherwise, undefined behavior! - */ - public native void setDoubleValue(double value); - - /** - * If the type is TYPE_DOUBLE, gets the default value. Otherwise, undefined behavior! - */ - public native double getDoubleDefaultValue(); - - /** - * If the type is TYPE_DOUBLE, returns the minimum valid value. Otherwise, undefined behavior! - */ - public native double getDoubleMin(); - - /** - * If the type is TYPE_DOUBLE, returns the maximum valid value. Otherwise, undefined behavior! - */ - public native double getDoubleMax(); - - /** - * If the type is TYPE_BOOLEAN, gets the current value. Otherwise, undefined behavior! - */ - public native boolean getBooleanValue(); - - /** - * If the type is TYPE_BOOLEAN, sets the current value. Otherwise, undefined behavior! - */ - public native void setBooleanValue(boolean value); - - /** - * If the type is TYPE_BOOLEAN, gets the default value. Otherwise, undefined behavior! - */ - public native boolean getBooleanDefaultValue(); -} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/NumericSetting.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/NumericSetting.kt new file mode 100644 index 0000000000..0a2485deab --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/NumericSetting.kt @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.dolphinemu.dolphinemu.features.input.model.controlleremu + +import androidx.annotation.Keep + +/** + * Represents a C++ ControllerEmu::NumericSetting. + * + * 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 NumericSetting private constructor(private val pointer: Long) { + /** + * @return The name used in the UI. + */ + external fun getUiName(): String + + /** + * @return A string applied to the number in the UI (unit of measure). + */ + external fun getUiSuffix(): String + + /** + * @return Detailed description of the setting. + */ + external fun getUiDescription(): String + + /** + * @return TYPE_INT, TYPE_DOUBLE or TYPE_BOOLEAN + */ + external fun getType(): Int + + external fun getControlReference(): ControlReference + + /** + * If the type is TYPE_INT, gets the current value. Otherwise, undefined behavior! + */ + external fun getIntValue(): Int + + /** + * If the type is TYPE_INT, sets the current value. Otherwise, undefined behavior! + */ + external fun setIntValue(value: Int) + + /** + * If the type is TYPE_INT, gets the default value. Otherwise, undefined behavior! + */ + external fun getIntDefaultValue(): Int + + /** + * If the type is TYPE_DOUBLE, gets the current value. Otherwise, undefined behavior! + */ + external fun getDoubleValue(): Double + + /** + * If the type is TYPE_DOUBLE, sets the current value. Otherwise, undefined behavior! + */ + external fun setDoubleValue(value: Double) + + /** + * If the type is TYPE_DOUBLE, gets the default value. Otherwise, undefined behavior! + */ + external fun getDoubleDefaultValue(): Double + + /** + * If the type is TYPE_DOUBLE, returns the minimum valid value. Otherwise, undefined behavior! + */ + external fun getDoubleMin(): Double + + /** + * If the type is TYPE_DOUBLE, returns the maximum valid value. Otherwise, undefined behavior! + */ + external fun getDoubleMax(): Double + + /** + * If the type is TYPE_BOOLEAN, gets the current value. Otherwise, undefined behavior! + */ + external fun getBooleanValue(): Boolean + + /** + * If the type is TYPE_BOOLEAN, sets the current value. Otherwise, undefined behavior! + */ + external fun setBooleanValue(value: Boolean) + + /** + * If the type is TYPE_BOOLEAN, gets the default value. Otherwise, undefined behavior! + */ + external fun getBooleanDefaultValue(): Boolean + + companion object { + const val TYPE_INT = 0 + const val TYPE_DOUBLE = 1 + const val TYPE_BOOLEAN = 2 + } +} 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 8cb63c420e..2ec27cff72 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 @@ -2295,23 +2295,23 @@ class SettingsFragmentPresenter( } private fun addNumericSetting(sl: ArrayList, setting: NumericSetting) { - when (setting.type) { + when (setting.getType()) { NumericSetting.TYPE_DOUBLE -> sl.add( FloatSliderSetting( InputMappingDoubleSetting(setting), - setting.uiName, + setting.getUiName(), "", - ceil(setting.doubleMin).toInt(), - floor(setting.doubleMax).toInt(), - setting.uiSuffix + ceil(setting.getDoubleMin()).toInt(), + floor(setting.getDoubleMax()).toInt(), + setting.getUiSuffix() ) ) NumericSetting.TYPE_BOOLEAN -> sl.add( SwitchSetting( InputMappingBooleanSetting(setting), - setting.uiName, - setting.uiDescription + setting.getUiName(), + setting.getUiDescription() ) ) } diff --git a/Source/Android/jni/AndroidCommon/IDCache.cpp b/Source/Android/jni/AndroidCommon/IDCache.cpp index 67b6af4d71..2b437c10c0 100644 --- a/Source/Android/jni/AndroidCommon/IDCache.cpp +++ b/Source/Android/jni/AndroidCommon/IDCache.cpp @@ -732,7 +732,7 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) const jclass numeric_setting_class = env->FindClass("org/dolphinemu/dolphinemu/features/input/model/controlleremu/NumericSetting"); s_numeric_setting_class = reinterpret_cast(env->NewGlobalRef(numeric_setting_class)); - s_numeric_setting_pointer = env->GetFieldID(numeric_setting_class, "mPointer", "J"); + s_numeric_setting_pointer = env->GetFieldID(numeric_setting_class, "pointer", "J"); s_numeric_setting_constructor = env->GetMethodID(numeric_setting_class, "", "(J)V"); env->DeleteLocalRef(numeric_setting_class);