[Android] Expand the input binding UI in the settings to handle 4 Gamecube controllers in the future.
Other changes: - Broke out MotionAlertDialog into it's own separate class. - Made a preference specifically for handling input bindings.
This commit is contained in:
parent
ae11fba069
commit
53ab104d5f
|
@ -46,6 +46,10 @@
|
|||
<string name="input_overlay_layout">入力オーバーレイレイアウト</string>
|
||||
<string name="input_overlay_layout_desc">入力オーバーレイのためのボタンのレイアウト。</string>
|
||||
<string name="gamecube_bindings">ゲームキューブの入力バインディング</string>
|
||||
<string name="controller_1">コントローラ1</string>
|
||||
<string name="controller_2">コントローラ2</string>
|
||||
<string name="controller_3">コントローラ3</string>
|
||||
<string name="controller_4">コントローラ4</string>
|
||||
<string name="input_binding">入力バインディング</string>
|
||||
<string name="input_binding_descrip">%1$sにバインドするための入力を移動または押してください。</string>
|
||||
<string name="button_a">Aボタン</string>
|
||||
|
|
|
@ -46,6 +46,10 @@
|
|||
<string name="input_overlay_layout">Input Overlay Layout</string>
|
||||
<string name="input_overlay_layout_desc">Button layout for the input overlay.</string>
|
||||
<string name="gamecube_bindings">Gamecube Input Bindings</string>
|
||||
<string name="controller_1">Controller 1</string>
|
||||
<string name="controller_2">Controller 2</string>
|
||||
<string name="controller_3">Controller 3</string>
|
||||
<string name="controller_4">Controller 4</string>
|
||||
<string name="input_binding">Input Binding</string>
|
||||
<string name="input_binding_descrip">Press or move an input to bind it to %1$s.</string>
|
||||
<string name="button_a">Button A</string>
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:title="@string/input_settings">
|
||||
|
||||
|
@ -11,84 +10,337 @@
|
|||
<PreferenceScreen
|
||||
android:key="gamecube_bindings"
|
||||
android:title="@string/gamecube_bindings">
|
||||
<Preference
|
||||
android:key="InputA"
|
||||
android:title="@string/button_a" />
|
||||
<PreferenceScreen
|
||||
android:key="gamecube_bindings_control_1"
|
||||
android:title="@string/controller_1">
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputA_1"
|
||||
android:title="@string/button_a" />
|
||||
|
||||
<Preference
|
||||
android:key="InputB"
|
||||
android:title="@string/button_b" />
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputB_1"
|
||||
android:title="@string/button_b" />
|
||||
|
||||
<Preference
|
||||
android:key="InputX"
|
||||
android:title="@string/button_x" />
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputX_1"
|
||||
android:title="@string/button_x" />
|
||||
|
||||
<Preference
|
||||
android:key="InputY"
|
||||
android:title="@string/button_y" />
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputY_1"
|
||||
android:title="@string/button_y" />
|
||||
|
||||
<Preference
|
||||
android:key="InputZ"
|
||||
android:title="@string/button_z" />
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputZ_1"
|
||||
android:title="@string/button_z" />
|
||||
|
||||
<Preference
|
||||
android:key="InputStart"
|
||||
android:title="@string/button_start" />
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputStart_1"
|
||||
android:title="@string/button_start" />
|
||||
|
||||
<Preference
|
||||
android:key="DPadUp"
|
||||
android:title="@string/dpad_up" />
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="DPadUp_1"
|
||||
android:title="@string/dpad_up" />
|
||||
|
||||
<Preference
|
||||
android:key="DPadDown"
|
||||
android:title="@string/dpad_down" />
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="DPadDown_1"
|
||||
android:title="@string/dpad_down" />
|
||||
|
||||
<Preference
|
||||
android:key="DPadLeft"
|
||||
android:title="@string/dpad_left" />
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="DPadLeft_1"
|
||||
android:title="@string/dpad_left" />
|
||||
|
||||
<Preference
|
||||
android:key="DPadRight"
|
||||
android:title="@string/dpad_right" />
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="DPadRight_1"
|
||||
android:title="@string/dpad_right" />
|
||||
|
||||
<Preference
|
||||
android:key="MainUp"
|
||||
android:title="@string/main_stick_up" />
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="MainUp_1"
|
||||
android:title="@string/main_stick_up" />
|
||||
|
||||
<Preference
|
||||
android:key="MainDown"
|
||||
android:title="@string/main_stick_down" />
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="MainDown_1"
|
||||
android:title="@string/main_stick_down" />
|
||||
|
||||
<Preference
|
||||
android:key="MainLeft"
|
||||
android:title="@string/main_stick_left" />
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="MainLeft_1"
|
||||
android:title="@string/main_stick_left" />
|
||||
|
||||
<Preference
|
||||
android:key="MainRight"
|
||||
android:title="@string/main_stick_right" />
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="MainRight_1"
|
||||
android:title="@string/main_stick_right" />
|
||||
|
||||
<Preference
|
||||
android:key="CStickUp"
|
||||
android:title="@string/c_stick_up" />
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="CStickUp_1"
|
||||
android:title="@string/c_stick_up" />
|
||||
|
||||
<Preference
|
||||
android:key="CStickDown"
|
||||
android:title="@string/c_stick_down" />
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="CStickDown_1"
|
||||
android:title="@string/c_stick_down" />
|
||||
|
||||
<Preference
|
||||
android:key="CStickLeft"
|
||||
android:title="@string/c_stick_left" />
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="CStickLeft_1"
|
||||
android:title="@string/c_stick_left" />
|
||||
|
||||
<Preference
|
||||
android:key="CStickRight"
|
||||
android:title="@string/c_stick_right" />
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="CStickRight_1"
|
||||
android:title="@string/c_stick_right" />
|
||||
|
||||
<Preference
|
||||
android:key="InputL"
|
||||
android:title="@string/trigger_left" />
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputL_1"
|
||||
android:title="@string/trigger_left" />
|
||||
|
||||
<Preference
|
||||
android:key="InputR"
|
||||
android:title="@string/trigger_right" />
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputR_1"
|
||||
android:title="@string/trigger_right" />
|
||||
</PreferenceScreen>
|
||||
<PreferenceScreen
|
||||
android:key="gamecube_bindings_control_2"
|
||||
android:title="@string/controller_2">
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputA_2"
|
||||
android:title="@string/button_a" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputB_2"
|
||||
android:title="@string/button_b" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputX_2"
|
||||
android:title="@string/button_x" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputY_2"
|
||||
android:title="@string/button_y" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputZ_2"
|
||||
android:title="@string/button_z" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputStart_2"
|
||||
android:title="@string/button_start" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="DPadUp_2"
|
||||
android:title="@string/dpad_up" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="DPadDown_2"
|
||||
android:title="@string/dpad_down" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="DPadLeft_2"
|
||||
android:title="@string/dpad_left" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="DPadRight_2"
|
||||
android:title="@string/dpad_right" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="MainUp_2"
|
||||
android:title="@string/main_stick_up" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="MainDown_2"
|
||||
android:title="@string/main_stick_down" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="MainLeft_2"
|
||||
android:title="@string/main_stick_left" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="MainRight_2"
|
||||
android:title="@string/main_stick_right" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="CStickUp_2"
|
||||
android:title="@string/c_stick_up" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="CStickDown_2"
|
||||
android:title="@string/c_stick_down" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="CStickLeft_2"
|
||||
android:title="@string/c_stick_left" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="CStickRight_2"
|
||||
android:title="@string/c_stick_right" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputL_2"
|
||||
android:title="@string/trigger_left" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputR_2"
|
||||
android:title="@string/trigger_right" />
|
||||
</PreferenceScreen>
|
||||
<PreferenceScreen
|
||||
android:key="gamecube_bindings_control_3"
|
||||
android:title="@string/controller_3">
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputA_3"
|
||||
android:title="@string/button_a" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputB_3"
|
||||
android:title="@string/button_b" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputX_3"
|
||||
android:title="@string/button_x" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputY_3"
|
||||
android:title="@string/button_y" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputZ_3"
|
||||
android:title="@string/button_z" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputStart_3"
|
||||
android:title="@string/button_start" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="DPadUp_3"
|
||||
android:title="@string/dpad_up" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="DPadDown_3"
|
||||
android:title="@string/dpad_down" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="DPadLeft_3"
|
||||
android:title="@string/dpad_left" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="DPadRight_3"
|
||||
android:title="@string/dpad_right" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="MainUp_3"
|
||||
android:title="@string/main_stick_up" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="MainDown_3"
|
||||
android:title="@string/main_stick_down" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="MainLeft_3"
|
||||
android:title="@string/main_stick_left" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="MainRight_3"
|
||||
android:title="@string/main_stick_right" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="CStickUp_3"
|
||||
android:title="@string/c_stick_up" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="CStickDown_3"
|
||||
android:title="@string/c_stick_down" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="CStickLeft_3"
|
||||
android:title="@string/c_stick_left" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="CStickRight_3"
|
||||
android:title="@string/c_stick_right" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputL_3"
|
||||
android:title="@string/trigger_left" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputR_3"
|
||||
android:title="@string/trigger_right" />
|
||||
</PreferenceScreen>
|
||||
<PreferenceScreen
|
||||
android:key="gamecube_bindings_control_4"
|
||||
android:title="@string/controller_4">
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputA_4"
|
||||
android:title="@string/button_a" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputB_4"
|
||||
android:title="@string/button_b" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputX_4"
|
||||
android:title="@string/button_x" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputY_4"
|
||||
android:title="@string/button_y" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputZ_4"
|
||||
android:title="@string/button_z" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputStart_4"
|
||||
android:title="@string/button_start" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="DPadUp_4"
|
||||
android:title="@string/dpad_up" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="DPadDown_4"
|
||||
android:title="@string/dpad_down" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="DPadLeft_4"
|
||||
android:title="@string/dpad_left" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="DPadRight_4"
|
||||
android:title="@string/dpad_right" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="MainUp_4"
|
||||
android:title="@string/main_stick_up" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="MainDown_4"
|
||||
android:title="@string/main_stick_down" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="MainLeft_4"
|
||||
android:title="@string/main_stick_left" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="MainRight_4"
|
||||
android:title="@string/main_stick_right" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="CStickUp_4"
|
||||
android:title="@string/c_stick_up" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="CStickDown_4"
|
||||
android:title="@string/c_stick_down" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="CStickLeft_4"
|
||||
android:title="@string/c_stick_left" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="CStickRight_4"
|
||||
android:title="@string/c_stick_right" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputL_4"
|
||||
android:title="@string/trigger_left" />
|
||||
|
||||
<org.dolphinemu.dolphinemu.settings.input.InputBindingPreference
|
||||
android:key="InputR_4"
|
||||
android:title="@string/trigger_right" />
|
||||
</PreferenceScreen>
|
||||
</PreferenceScreen>
|
||||
</PreferenceScreen>
|
|
@ -0,0 +1,55 @@
|
|||
package org.dolphinemu.dolphinemu.settings.input;
|
||||
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.preference.Preference;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
/**
|
||||
* {@link Preference} subclass that represents a preference
|
||||
* used for assigning a key bind.
|
||||
*/
|
||||
public final class InputBindingPreference extends Preference
|
||||
{
|
||||
/**
|
||||
* Constructor that is called when inflating an InputBindingPreference from XML.
|
||||
*
|
||||
* @param context The current {@link Context}.
|
||||
* @param attrs The attributes of the XML tag that is inflating the preference.
|
||||
*/
|
||||
public InputBindingPreference(Context context, AttributeSet attrs)
|
||||
{
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick()
|
||||
{
|
||||
// Begin the creation of the input alert.
|
||||
final MotionAlertDialog dialog = new MotionAlertDialog(getContext(), this);
|
||||
|
||||
// Set the cancel button.
|
||||
dialog.setButton(AlertDialog.BUTTON_NEGATIVE, getContext().getString(R.string.cancel), new AlertDialog.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
// Do nothing. Just makes the cancel button show up.
|
||||
}
|
||||
});
|
||||
|
||||
// Set the title and description message.
|
||||
dialog.setTitle(R.string.input_binding);
|
||||
dialog.setMessage(String.format(getContext().getString(R.string.input_binding_descrip), getTitle()));
|
||||
|
||||
// Don't allow the dialog to close when a user taps
|
||||
// outside of it. They must press cancel or provide an input.
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
|
||||
// Everything is set, show the dialog.
|
||||
dialog.show();
|
||||
}
|
||||
}
|
|
@ -6,21 +6,16 @@
|
|||
|
||||
package org.dolphinemu.dolphinemu.settings.input;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import java.util.List;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.util.Log;
|
||||
import android.view.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import android.view.InputDevice;
|
||||
|
||||
import org.dolphinemu.dolphinemu.NativeLibrary;
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
|
@ -31,6 +26,37 @@ import org.dolphinemu.dolphinemu.R;
|
|||
*/
|
||||
public final class InputConfigFragment extends PreferenceFragment
|
||||
{
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Expand the preferences from the XML.
|
||||
addPreferencesFromResource(R.xml.input_prefs);
|
||||
|
||||
// Set the summary messages of the preferences to whatever binding
|
||||
// is currently set within the Dolphin config.
|
||||
final String[] keys =
|
||||
{
|
||||
"InputA", "InputB", "InputX", "InputY", "InputZ", "InputStart",
|
||||
"DPadUp", "DPadDown", "DPadLeft", "DPadRight",
|
||||
"MainUp", "MainDown", "MainLeft", "MainRight",
|
||||
"CStickUp", "CStickDown", "CStickLeft", "CStickRight",
|
||||
"InputL", "InputR"
|
||||
};
|
||||
|
||||
// Loop through the keys for all 4 GameCube controllers.
|
||||
for (int i = 1; i <= 4; i++)
|
||||
{
|
||||
for (String key : keys)
|
||||
{
|
||||
final String binding = NativeLibrary.GetConfig("Dolphin.ini", "Android", key+"_"+i, "None");
|
||||
final Preference pref = findPreference(key+"_"+i);
|
||||
pref.setSummary(binding);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the descriptor for the given {@link InputDevice}.
|
||||
*
|
||||
|
@ -59,66 +85,9 @@ public final class InputConfigFragment extends PreferenceFragment
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Expand the preferences from the XML.
|
||||
addPreferencesFromResource(R.xml.input_prefs);
|
||||
|
||||
// Set the summary messages of the preferences to whatever binding
|
||||
// is currently set within the Dolphin config.
|
||||
final String[] keys =
|
||||
{
|
||||
"InputA", "InputB", "InputX", "InputY", "InputZ", "InputStart",
|
||||
"DPadUp", "DPadDown", "DPadLeft", "DPadRight",
|
||||
"MainUp", "MainDown", "MainLeft", "MainRight",
|
||||
"CStickUp", "CStickDown", "CStickLeft", "CStickRight",
|
||||
"InputL", "InputR",
|
||||
};
|
||||
|
||||
Preference pref;
|
||||
for (String key : keys)
|
||||
{
|
||||
String binding = NativeLibrary.GetConfig("Dolphin.ini", "Android", key, "None");
|
||||
pref = findPreference(key);
|
||||
pref.setSummary(binding);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference pref)
|
||||
{
|
||||
// If the user is on the preference screen to set Gamecube input bindings.
|
||||
if (screen.getTitle().equals(getString(R.string.gamecube_bindings)))
|
||||
{
|
||||
// Begin the creation of the input alert.
|
||||
final MotionAlertDialog dialog = new MotionAlertDialog(getActivity(), pref);
|
||||
|
||||
// Set the cancel button.
|
||||
dialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.cancel), new AlertDialog.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
// Do nothing. Just makes the cancel button show up.
|
||||
}
|
||||
});
|
||||
|
||||
// Set the title and description message.
|
||||
dialog.setTitle(R.string.input_binding);
|
||||
dialog.setMessage(String.format(getString(R.string.input_binding_descrip), pref.getTitle()));
|
||||
|
||||
// Don't allow the dialog to close when a user taps
|
||||
// outside of it. They must press cancel or provide an input.
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
|
||||
// Everything is set, show the dialog.
|
||||
dialog.show();
|
||||
return true;
|
||||
}
|
||||
|
||||
// If the user has clicked the option to configure the input overlay.
|
||||
if (pref.getTitle().equals(getString(R.string.input_overlay_layout)))
|
||||
{
|
||||
|
@ -129,119 +98,4 @@ public final class InputConfigFragment extends PreferenceFragment
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link AlertDialog} derivative that listens for
|
||||
* motion events from controllers and joysticks.
|
||||
*/
|
||||
private static final class MotionAlertDialog extends AlertDialog
|
||||
{
|
||||
// The selected input preference
|
||||
private final Preference inputPref;
|
||||
|
||||
private boolean firstEvent = true;
|
||||
private final ArrayList<Float> m_values = new ArrayList<Float>();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ctx The current {@link Context}.
|
||||
* @param inputPref The Preference to show this dialog for.
|
||||
*/
|
||||
public MotionAlertDialog(Context ctx, Preference inputPref)
|
||||
{
|
||||
super(ctx);
|
||||
|
||||
this.inputPref = inputPref;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event)
|
||||
{
|
||||
Log.d("InputConfigFragment", "Received key event: " + event.getAction());
|
||||
switch (event.getAction())
|
||||
{
|
||||
case KeyEvent.ACTION_DOWN:
|
||||
case KeyEvent.ACTION_UP:
|
||||
InputDevice input = event.getDevice();
|
||||
String bindStr = "Device '" + getInputDesc(input) + "'-Button " + event.getKeyCode();
|
||||
NativeLibrary.SetConfig("Dolphin.ini", "Android", inputPref.getKey(), bindStr);
|
||||
inputPref.setSummary(bindStr);
|
||||
dismiss();
|
||||
return true;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Method that will be called within dispatchGenericMotionEvent
|
||||
// that handles joystick/controller movements.
|
||||
private boolean onMotionEvent(MotionEvent event)
|
||||
{
|
||||
if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0)
|
||||
return false;
|
||||
|
||||
Log.d("InputConfigFragment", "Received motion event: " + event.getAction());
|
||||
|
||||
InputDevice input = event.getDevice();
|
||||
List<InputDevice.MotionRange> motions = input.getMotionRanges();
|
||||
if (firstEvent)
|
||||
{
|
||||
m_values.clear();
|
||||
|
||||
for (InputDevice.MotionRange range : motions)
|
||||
{
|
||||
m_values.add(event.getAxisValue(range.getAxis()));
|
||||
}
|
||||
|
||||
firstEvent = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int a = 0; a < motions.size(); ++a)
|
||||
{
|
||||
InputDevice.MotionRange range = motions.get(a);
|
||||
|
||||
if (m_values.get(a) > (event.getAxisValue(range.getAxis()) + 0.5f))
|
||||
{
|
||||
String bindStr = "Device '" + InputConfigFragment.getInputDesc(input) + "'-Axis " + range.getAxis() + "-";
|
||||
NativeLibrary.SetConfig("Dolphin.ini", "Android", inputPref.getKey(), bindStr);
|
||||
inputPref.setSummary(bindStr);
|
||||
dismiss();
|
||||
}
|
||||
else if (m_values.get(a) < (event.getAxisValue(range.getAxis()) - 0.5f))
|
||||
{
|
||||
String bindStr = "Device '" + InputConfigFragment.getInputDesc(input) + "'-Axis " + range.getAxis() + "+";
|
||||
NativeLibrary.SetConfig("Dolphin.ini", "Android", inputPref.getKey(), bindStr);
|
||||
inputPref.setSummary(bindStr);
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event)
|
||||
{
|
||||
if (onKeyDown(event.getKeyCode(), event))
|
||||
return true;
|
||||
|
||||
return super.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchGenericMotionEvent(MotionEvent event)
|
||||
{
|
||||
if (onMotionEvent(event))
|
||||
return true;
|
||||
|
||||
return super.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,127 @@
|
|||
package org.dolphinemu.dolphinemu.settings.input;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.dolphinemu.dolphinemu.NativeLibrary;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.preference.Preference;
|
||||
import android.util.Log;
|
||||
import android.view.InputDevice;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
/**
|
||||
* {@link AlertDialog} derivative that listens for
|
||||
* motion events from controllers and joysticks.
|
||||
*/
|
||||
final class MotionAlertDialog extends AlertDialog
|
||||
{
|
||||
// The selected input preference
|
||||
private final Preference inputPref;
|
||||
|
||||
private boolean firstEvent = true;
|
||||
private final ArrayList<Float> m_values = new ArrayList<Float>();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ctx The current {@link Context}.
|
||||
* @param inputPref The Preference to show this dialog for.
|
||||
*/
|
||||
public MotionAlertDialog(Context ctx, Preference inputPref)
|
||||
{
|
||||
super(ctx);
|
||||
|
||||
this.inputPref = inputPref;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event)
|
||||
{
|
||||
Log.d("InputConfigFragment", "Received key event: " + event.getAction());
|
||||
switch (event.getAction())
|
||||
{
|
||||
case KeyEvent.ACTION_DOWN:
|
||||
case KeyEvent.ACTION_UP:
|
||||
InputDevice input = event.getDevice();
|
||||
String bindStr = "Device '" + InputConfigFragment.getInputDesc(input) + "'-Button " + event.getKeyCode();
|
||||
NativeLibrary.SetConfig("Dolphin.ini", "Android", inputPref.getKey(), bindStr);
|
||||
inputPref.setSummary(bindStr);
|
||||
dismiss();
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Method that will be called within dispatchGenericMotionEvent
|
||||
// that handles joystick/controller movements.
|
||||
private boolean onMotionEvent(MotionEvent event)
|
||||
{
|
||||
if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0)
|
||||
return false;
|
||||
|
||||
Log.d("InputConfigFragment", "Received motion event: " + event.getAction());
|
||||
|
||||
InputDevice input = event.getDevice();
|
||||
List<InputDevice.MotionRange> motions = input.getMotionRanges();
|
||||
if (firstEvent)
|
||||
{
|
||||
m_values.clear();
|
||||
|
||||
for (InputDevice.MotionRange range : motions)
|
||||
{
|
||||
m_values.add(event.getAxisValue(range.getAxis()));
|
||||
}
|
||||
|
||||
firstEvent = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int a = 0; a < motions.size(); ++a)
|
||||
{
|
||||
InputDevice.MotionRange range = motions.get(a);
|
||||
|
||||
if (m_values.get(a) > (event.getAxisValue(range.getAxis()) + 0.5f))
|
||||
{
|
||||
String bindStr = "Device '" + InputConfigFragment.getInputDesc(input) + "'-Axis " + range.getAxis() + "-";
|
||||
NativeLibrary.SetConfig("Dolphin.ini", "Android", inputPref.getKey(), bindStr);
|
||||
inputPref.setSummary(bindStr);
|
||||
dismiss();
|
||||
}
|
||||
else if (m_values.get(a) < (event.getAxisValue(range.getAxis()) - 0.5f))
|
||||
{
|
||||
String bindStr = "Device '" + InputConfigFragment.getInputDesc(input) + "'-Axis " + range.getAxis() + "+";
|
||||
NativeLibrary.SetConfig("Dolphin.ini", "Android", inputPref.getKey(), bindStr);
|
||||
inputPref.setSummary(bindStr);
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event)
|
||||
{
|
||||
if (onKeyDown(event.getKeyCode(), event))
|
||||
return true;
|
||||
|
||||
return super.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchGenericMotionEvent(MotionEvent event)
|
||||
{
|
||||
if (onMotionEvent(event))
|
||||
return true;
|
||||
|
||||
return super.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue