diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/MotionAlertDialog.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/MotionAlertDialog.java index bb83a7f1ae..33efbde2c5 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/MotionAlertDialog.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/MotionAlertDialog.java @@ -3,13 +3,14 @@ package org.dolphinemu.dolphinemu.dialogs; import android.app.AlertDialog; import android.content.Context; import android.content.SharedPreferences; -import android.preference.Preference; import android.preference.PreferenceManager; import android.view.InputDevice; import android.view.KeyEvent; import android.view.MotionEvent; import org.dolphinemu.dolphinemu.NativeLibrary; +import org.dolphinemu.dolphinemu.model.settings.StringSetting; +import org.dolphinemu.dolphinemu.model.settings.view.InputBindingSetting; import org.dolphinemu.dolphinemu.utils.Log; import java.util.ArrayList; @@ -22,7 +23,7 @@ import java.util.List; public final class MotionAlertDialog extends AlertDialog { // The selected input preference - private final Preference inputPref; + private final InputBindingSetting setting; private boolean firstEvent = true; private final ArrayList m_values = new ArrayList<>(); @@ -30,14 +31,14 @@ public final class MotionAlertDialog extends AlertDialog /** * Constructor * - * @param ctx The current {@link Context}. - * @param inputPref The Preference to show this dialog for. + * @param context The current {@link Context}. + * @param setting The Preference to show this dialog for. */ - public MotionAlertDialog(Context ctx, Preference inputPref) + public MotionAlertDialog(Context context, InputBindingSetting setting) { - super(ctx); + super(context); - this.inputPref = inputPref; + this.setting = setting; } @Override @@ -150,7 +151,7 @@ public final class MotionAlertDialog extends AlertDialog if (bindStr != null) { - NativeLibrary.SetConfig("Dolphin.ini", "Android", inputPref.getKey(), bindStr); + setting.setValue(bindStr); } else { @@ -163,10 +164,8 @@ public final class MotionAlertDialog extends AlertDialog SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences.Editor editor = preferences.edit(); - editor.putString(inputPref.getKey(), uiString); + editor.putString(setting.getKey(), uiString); editor.apply(); - - inputPref.setSummary(uiString); } else { diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/settings/view/InputBindingSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/settings/view/InputBindingSetting.java new file mode 100644 index 0000000000..4537ed2028 --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/settings/view/InputBindingSetting.java @@ -0,0 +1,53 @@ +package org.dolphinemu.dolphinemu.model.settings.view; + +import org.dolphinemu.dolphinemu.model.settings.BooleanSetting; +import org.dolphinemu.dolphinemu.model.settings.Setting; +import org.dolphinemu.dolphinemu.model.settings.StringSetting; + +public final class InputBindingSetting extends SettingsItem +{ + public InputBindingSetting(String key, String section, int file, int titleId, Setting setting) + { + super(key, section, file, setting, titleId, 0); + } + + public String getValue() + { + if (getSetting() == null) + { + return ""; + } + + StringSetting setting = (StringSetting) getSetting(); + return setting.getValue(); + } + + /** + * Write a value to the backing string. If that string was previously null, + * initializes a new one and returns it, so it can be added to the Hashmap. + * + * @param bind The input that will be bound + * @return null if overwritten successfully; otherwise, a newly created StringSetting. + */ + public StringSetting setValue(String bind) + { + if (getSetting() == null) + { + StringSetting setting = new StringSetting(getKey(), getSection(), getFile(), bind); + setSetting(setting); + return setting; + } + else + { + StringSetting setting = (StringSetting) getSetting(); + setting.setValue(bind); + return null; + } + } + + @Override + public int getType() + { + return TYPE_INPUT_BINDING; + } +} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/settings/view/SettingsItem.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/settings/view/SettingsItem.java index ebb800f4f0..094e8be91d 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/settings/view/SettingsItem.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/settings/view/SettingsItem.java @@ -16,6 +16,7 @@ public abstract class SettingsItem public static final int TYPE_SINGLE_CHOICE = 2; public static final int TYPE_SLIDER = 3; public static final int TYPE_SUBMENU = 4; + public static final int TYPE_INPUT_BINDING = 5; private String mKey; private String mSection; diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsAdapter.java index dcd2c821e4..94d190ba8f 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/settings/SettingsAdapter.java @@ -2,6 +2,8 @@ package org.dolphinemu.dolphinemu.ui.settings; import android.content.Context; import android.content.DialogInterface; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; import android.support.v7.app.AlertDialog; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; @@ -11,17 +13,20 @@ import android.widget.SeekBar; import android.widget.TextView; import org.dolphinemu.dolphinemu.R; +import org.dolphinemu.dolphinemu.dialogs.MotionAlertDialog; import org.dolphinemu.dolphinemu.model.settings.BooleanSetting; import org.dolphinemu.dolphinemu.model.settings.FloatSetting; import org.dolphinemu.dolphinemu.model.settings.IntSetting; import org.dolphinemu.dolphinemu.model.settings.StringSetting; import org.dolphinemu.dolphinemu.model.settings.view.CheckBoxSetting; +import org.dolphinemu.dolphinemu.model.settings.view.InputBindingSetting; import org.dolphinemu.dolphinemu.model.settings.view.SettingsItem; import org.dolphinemu.dolphinemu.model.settings.view.SingleChoiceSetting; import org.dolphinemu.dolphinemu.model.settings.view.SliderSetting; import org.dolphinemu.dolphinemu.model.settings.view.SubmenuSetting; import org.dolphinemu.dolphinemu.ui.settings.viewholder.CheckBoxSettingViewHolder; import org.dolphinemu.dolphinemu.ui.settings.viewholder.HeaderViewHolder; +import org.dolphinemu.dolphinemu.ui.settings.viewholder.InputBindingSettingViewHolder; import org.dolphinemu.dolphinemu.ui.settings.viewholder.SettingViewHolder; import org.dolphinemu.dolphinemu.ui.settings.viewholder.SingleChoiceViewHolder; import org.dolphinemu.dolphinemu.ui.settings.viewholder.SliderViewHolder; @@ -78,6 +83,10 @@ public final class SettingsAdapter extends RecyclerView.AdapterNo OK Cancel + Clear Disabled Other