Add a generic function to modify the button assignments
This should support a per-player option in the future.
This commit is contained in:
parent
9e56db72f4
commit
a63cede6bc
|
@ -252,6 +252,17 @@
|
|||
android:text="@string/remove" />
|
||||
</LinearLayout>
|
||||
</TableRow>
|
||||
<TableRow android:gravity="center_vertical" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonKeycodeEditor"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="25dp"
|
||||
android:layout_weight="1"
|
||||
android:ems="8"
|
||||
android:text="@string/menu_edit_keycodes" />
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -0,0 +1,335 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TableLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:stretchColumns="*" >
|
||||
|
||||
<TableRow android:gravity="center_vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/a_button_key"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="A button" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="right"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/a_button_edit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="8"
|
||||
android:text="@string/launch_editor" />
|
||||
</LinearLayout>
|
||||
</TableRow>
|
||||
|
||||
<TableRow android:gravity="center_vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/b_button_key"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="B button" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="right"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/b_button_edit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="8"
|
||||
android:text="@string/launch_editor" />
|
||||
</LinearLayout>
|
||||
</TableRow>
|
||||
|
||||
<TableRow android:gravity="center_vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/x_button_key"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="X button" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="right"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/x_button_edit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="8"
|
||||
android:text="@string/launch_editor" />
|
||||
</LinearLayout>
|
||||
</TableRow>
|
||||
<TableRow android:gravity="center_vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/y_button_key"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="Y button" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="right"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/y_button_edit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="8"
|
||||
android:text="@string/launch_editor" />
|
||||
</LinearLayout>
|
||||
</TableRow>
|
||||
<TableRow android:gravity="center_vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/l_button_key"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="L button" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="right"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/l_button_edit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="8"
|
||||
android:text="@string/launch_editor" />
|
||||
</LinearLayout>
|
||||
</TableRow>
|
||||
<TableRow android:gravity="center_vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/r_button_key"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="R button" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="right"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/r_button_edit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="8"
|
||||
android:text="@string/launch_editor" />
|
||||
</LinearLayout>
|
||||
</TableRow>
|
||||
<TableRow android:gravity="center_vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/joystick_key"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="Joystick" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="right"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/joystick_edit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="8"
|
||||
android:text="@string/launch_editor" />
|
||||
</LinearLayout>
|
||||
</TableRow>
|
||||
<TableRow android:gravity="center_vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dpad_left_key"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="DPad Left" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="right"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/dpad_left_edit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="8"
|
||||
android:text="@string/launch_editor" />
|
||||
</LinearLayout>
|
||||
</TableRow>
|
||||
<TableRow android:gravity="center_vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dpad_right_key"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="DPad Right" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="right"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/dpad_right_edit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="8"
|
||||
android:text="@string/launch_editor" />
|
||||
</LinearLayout>
|
||||
</TableRow>
|
||||
<TableRow android:gravity="center_vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dpad_up_key"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="DPad Up" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="right"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/dpad_up_edit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="8"
|
||||
android:text="@string/launch_editor" />
|
||||
</LinearLayout>
|
||||
</TableRow>
|
||||
<TableRow android:gravity="center_vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dpad_down_key"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="DPad Down" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="right"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/dpad_down_edit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="8"
|
||||
android:text="@string/launch_editor" />
|
||||
</LinearLayout>
|
||||
</TableRow>
|
||||
<TableRow android:gravity="center_vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/start_button_key"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="Start Button" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="right"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/start_button_edit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="8"
|
||||
android:text="@string/launch_editor" />
|
||||
</LinearLayout>
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
|
@ -42,6 +42,10 @@
|
|||
<string name="select_controller_title">Select Controller</string>
|
||||
<string name="select_controller_message">Press any button on the controller to assign to port</string>
|
||||
<string name="controller_already_in_use">This controller is already in use!</string>
|
||||
|
||||
<string name="menu_edit_keycodes">Edit Key Bindings</string>
|
||||
<string name="map_keycode_title">Modify Controller</string>
|
||||
<string name="map_keycode_message">Press the new controller button for %1$s</string>
|
||||
|
||||
<string name="about_title">About reicast</string>
|
||||
<string name="about_text">reicast is a dreamcast emulator\n\nVersion: %1$s\n\nWe work hard for you\nShare the love back and rate the app!</string>
|
||||
|
|
|
@ -39,8 +39,11 @@ public class GL2JNIActivity extends Activity {
|
|||
PopupWindow popUp;
|
||||
LayoutParams params;
|
||||
MOGAInput moga = new MOGAInput();
|
||||
static boolean[] xbox = { false, false, false, false }, nVidia = { false, false, false, false };
|
||||
float[] globalLS_X = new float[4], globalLS_Y = new float[4], previousLS_X = new float[4], previousLS_Y = new float[4];
|
||||
private SharedPreferences prefs;
|
||||
static boolean[] xbox = { false, false, false, false }, nVidia = { false,
|
||||
false, false, false };
|
||||
float[] globalLS_X = new float[4], globalLS_Y = new float[4],
|
||||
previousLS_X = new float[4], previousLS_Y = new float[4];
|
||||
|
||||
public static HashMap<Integer, String> deviceId_deviceDescriptor = new HashMap<Integer, String>();
|
||||
public static HashMap<String, Integer> deviceDescriptor_PlayerNum = new HashMap<String, Integer>();
|
||||
|
@ -81,7 +84,8 @@ public class GL2JNIActivity extends Activity {
|
|||
|
||||
hlay.addView(addbut(R.drawable.close, new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
Intent inte = new Intent(GL2JNIActivity.this, MainActivity.class);
|
||||
Intent inte = new Intent(GL2JNIActivity.this,
|
||||
MainActivity.class);
|
||||
startActivity(inte);
|
||||
GL2JNIActivity.this.finish();
|
||||
}
|
||||
|
@ -130,7 +134,7 @@ public class GL2JNIActivity extends Activity {
|
|||
protected void onCreate(Bundle icicle) {
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
moga.onCreate(this);
|
||||
|
||||
|
||||
createPopup();
|
||||
/*
|
||||
* try { //int rID =
|
||||
|
@ -151,146 +155,158 @@ public class GL2JNIActivity extends Activity {
|
|||
map = new int[4][];
|
||||
|
||||
// Populate device descriptor-to-player-map from preferences
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
deviceDescriptor_PlayerNum.put(prefs.getString("device_descriptor_player_1", null), 0);
|
||||
deviceDescriptor_PlayerNum.put(prefs.getString("device_descriptor_player_2", null), 1);
|
||||
deviceDescriptor_PlayerNum.put(prefs.getString("device_descriptor_player_3", null), 2);
|
||||
deviceDescriptor_PlayerNum.put(prefs.getString("device_descriptor_player_4", null), 3);
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
deviceDescriptor_PlayerNum.put(
|
||||
prefs.getString("device_descriptor_player_1", null), 0);
|
||||
deviceDescriptor_PlayerNum.put(
|
||||
prefs.getString("device_descriptor_player_2", null), 1);
|
||||
deviceDescriptor_PlayerNum.put(
|
||||
prefs.getString("device_descriptor_player_3", null), 2);
|
||||
deviceDescriptor_PlayerNum.put(
|
||||
prefs.getString("device_descriptor_player_4", null), 3);
|
||||
|
||||
boolean controllerTwoConnected = false;
|
||||
boolean controllerThreeConnected = false;
|
||||
boolean controllerFourConnected = false;
|
||||
|
||||
for (HashMap.Entry<String, Integer> e : deviceDescriptor_PlayerNum.entrySet()) {
|
||||
for (HashMap.Entry<String, Integer> e : deviceDescriptor_PlayerNum
|
||||
.entrySet()) {
|
||||
String descriptor = e.getKey();
|
||||
Integer playerNum = e.getValue();
|
||||
|
||||
switch (playerNum) {
|
||||
case 1:
|
||||
if (descriptor != null)
|
||||
controllerTwoConnected = true;
|
||||
break;
|
||||
case 2:
|
||||
if (descriptor != null)
|
||||
controllerThreeConnected = true;
|
||||
break;
|
||||
case 3:
|
||||
if (descriptor != null)
|
||||
controllerFourConnected = true;
|
||||
break;
|
||||
case 1:
|
||||
if (descriptor != null)
|
||||
controllerTwoConnected = true;
|
||||
break;
|
||||
case 2:
|
||||
if (descriptor != null)
|
||||
controllerThreeConnected = true;
|
||||
break;
|
||||
case 3:
|
||||
if (descriptor != null)
|
||||
controllerFourConnected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
|
||||
|
||||
JNIdc.initControllers(new boolean[] {controllerTwoConnected, controllerThreeConnected, controllerFourConnected});
|
||||
JNIdc.initControllers(new boolean[] { controllerTwoConnected,
|
||||
controllerThreeConnected, controllerFourConnected });
|
||||
|
||||
int joys[] = InputDevice.getDeviceIds();
|
||||
for (int i = 0; i < joys.length; i++) {
|
||||
String descriptor = null;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
descriptor = InputDevice.getDevice(joys[i]).getDescriptor();
|
||||
} else {
|
||||
descriptor = InputDevice.getDevice(joys[i]).getName();
|
||||
}
|
||||
Log.d("reidc", "InputDevice ID: " + joys[i]);
|
||||
Log.d("reidc", "InputDevice Name: "
|
||||
+ InputDevice.getDevice(joys[i]).getName());
|
||||
Log.d("reidc", "InputDevice Descriptor: " + descriptor);
|
||||
deviceId_deviceDescriptor.put(joys[i], descriptor);
|
||||
}
|
||||
|
||||
for (int i = 0; i < joys.length; i++) {
|
||||
Integer playerNum = deviceDescriptor_PlayerNum.get(deviceId_deviceDescriptor.get(joys[i]));
|
||||
|
||||
if (playerNum != null) {
|
||||
|
||||
if (InputDevice.getDevice(joys[i]).getName()
|
||||
.equals("Sony PLAYSTATION(R)3 Controller")) {
|
||||
map[playerNum] = new int[] {
|
||||
OuyaController.BUTTON_Y, key_CONT_Y,
|
||||
OuyaController.BUTTON_U, key_CONT_X,
|
||||
OuyaController.BUTTON_O, key_CONT_A,
|
||||
OuyaController.BUTTON_A, key_CONT_B,
|
||||
|
||||
OuyaController.BUTTON_DPAD_UP, key_CONT_DPAD_UP,
|
||||
OuyaController.BUTTON_DPAD_DOWN,
|
||||
key_CONT_DPAD_DOWN,
|
||||
OuyaController.BUTTON_DPAD_LEFT,
|
||||
key_CONT_DPAD_LEFT,
|
||||
OuyaController.BUTTON_DPAD_RIGHT,
|
||||
key_CONT_DPAD_RIGHT,
|
||||
|
||||
OuyaController.BUTTON_MENU, key_CONT_START,
|
||||
OuyaController.BUTTON_R1, key_CONT_START
|
||||
|
||||
};
|
||||
} else if (InputDevice.getDevice(joys[i]).getName()
|
||||
.equals("Microsoft X-Box 360 pad")) {
|
||||
map[playerNum] = new int[] {
|
||||
OuyaController.BUTTON_O, key_CONT_A,
|
||||
OuyaController.BUTTON_A, key_CONT_B,
|
||||
OuyaController.BUTTON_Y, key_CONT_Y,
|
||||
OuyaController.BUTTON_U, key_CONT_X,
|
||||
|
||||
OuyaController.BUTTON_DPAD_UP, key_CONT_DPAD_UP,
|
||||
OuyaController.BUTTON_DPAD_DOWN,
|
||||
key_CONT_DPAD_DOWN,
|
||||
OuyaController.BUTTON_DPAD_LEFT,
|
||||
key_CONT_DPAD_LEFT,
|
||||
OuyaController.BUTTON_DPAD_RIGHT,
|
||||
key_CONT_DPAD_RIGHT,
|
||||
|
||||
OuyaController.BUTTON_MENU, key_CONT_START,
|
||||
OuyaController.BUTTON_R1, key_CONT_START };
|
||||
|
||||
xbox[playerNum] = true;
|
||||
|
||||
globalLS_X[playerNum] = previousLS_X[playerNum] = 0.0f;
|
||||
globalLS_Y[playerNum] = previousLS_Y[playerNum] = 0.0f;
|
||||
} else if (InputDevice.getDevice(joys[i]).getName()
|
||||
.contains("NVIDIA Corporation NVIDIA Controller")) {
|
||||
map[playerNum] = new int[] {
|
||||
OuyaController.BUTTON_O, key_CONT_A,
|
||||
OuyaController.BUTTON_A, key_CONT_B,
|
||||
OuyaController.BUTTON_Y, key_CONT_Y,
|
||||
OuyaController.BUTTON_U, key_CONT_X,
|
||||
|
||||
OuyaController.BUTTON_DPAD_UP, key_CONT_DPAD_UP,
|
||||
OuyaController.BUTTON_DPAD_DOWN,
|
||||
key_CONT_DPAD_DOWN,
|
||||
OuyaController.BUTTON_DPAD_LEFT,
|
||||
key_CONT_DPAD_LEFT,
|
||||
OuyaController.BUTTON_DPAD_RIGHT,
|
||||
key_CONT_DPAD_RIGHT,
|
||||
|
||||
OuyaController.BUTTON_MENU, key_CONT_START,
|
||||
OuyaController.BUTTON_R1, key_CONT_START };
|
||||
nVidia[playerNum] = true;
|
||||
|
||||
globalLS_X[playerNum] = previousLS_X[playerNum] = 0.0f;
|
||||
globalLS_Y[playerNum] = previousLS_Y[playerNum] = 0.0f;
|
||||
} else if (!moga.isActive) { // Ouya controller
|
||||
map[playerNum] = new int[] {
|
||||
OuyaController.BUTTON_O, key_CONT_A,
|
||||
OuyaController.BUTTON_A, key_CONT_B,
|
||||
OuyaController.BUTTON_Y, key_CONT_Y,
|
||||
OuyaController.BUTTON_U, key_CONT_X,
|
||||
|
||||
OuyaController.BUTTON_DPAD_UP, key_CONT_DPAD_UP,
|
||||
OuyaController.BUTTON_DPAD_DOWN,
|
||||
key_CONT_DPAD_DOWN,
|
||||
OuyaController.BUTTON_DPAD_LEFT,
|
||||
key_CONT_DPAD_LEFT,
|
||||
OuyaController.BUTTON_DPAD_RIGHT,
|
||||
key_CONT_DPAD_RIGHT,
|
||||
|
||||
OuyaController.BUTTON_MENU, key_CONT_START,
|
||||
OuyaController.BUTTON_R1, key_CONT_START };
|
||||
int joys[] = InputDevice.getDeviceIds();
|
||||
for (int i = 0; i < joys.length; i++) {
|
||||
String descriptor = null;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
descriptor = InputDevice.getDevice(joys[i]).getDescriptor();
|
||||
} else {
|
||||
descriptor = InputDevice.getDevice(joys[i]).getName();
|
||||
}
|
||||
Log.d("reidc", "InputDevice ID: " + joys[i]);
|
||||
Log.d("reidc",
|
||||
"InputDevice Name: "
|
||||
+ InputDevice.getDevice(joys[i]).getName());
|
||||
Log.d("reidc", "InputDevice Descriptor: " + descriptor);
|
||||
deviceId_deviceDescriptor.put(joys[i], descriptor);
|
||||
}
|
||||
|
||||
for (int i = 0; i < joys.length; i++) {
|
||||
Integer playerNum = deviceDescriptor_PlayerNum
|
||||
.get(deviceId_deviceDescriptor.get(joys[i]));
|
||||
|
||||
if (playerNum != null) {
|
||||
|
||||
if (InputDevice.getDevice(joys[i]).getName()
|
||||
.equals("Sony PLAYSTATION(R)3 Controller")) {
|
||||
map[playerNum] = new int[] { OuyaController.BUTTON_Y,
|
||||
key_CONT_Y, OuyaController.BUTTON_U,
|
||||
key_CONT_X, OuyaController.BUTTON_O,
|
||||
key_CONT_A, OuyaController.BUTTON_A,
|
||||
key_CONT_B,
|
||||
|
||||
OuyaController.BUTTON_DPAD_UP,
|
||||
key_CONT_DPAD_UP,
|
||||
OuyaController.BUTTON_DPAD_DOWN,
|
||||
key_CONT_DPAD_DOWN,
|
||||
OuyaController.BUTTON_DPAD_LEFT,
|
||||
key_CONT_DPAD_LEFT,
|
||||
OuyaController.BUTTON_DPAD_RIGHT,
|
||||
key_CONT_DPAD_RIGHT,
|
||||
|
||||
OuyaController.BUTTON_MENU, key_CONT_START,
|
||||
OuyaController.BUTTON_R1, key_CONT_START
|
||||
|
||||
};
|
||||
} else if (InputDevice.getDevice(joys[i]).getName()
|
||||
.equals("Microsoft X-Box 360 pad")) {
|
||||
map[playerNum] = new int[] { OuyaController.BUTTON_O,
|
||||
key_CONT_A, OuyaController.BUTTON_A,
|
||||
key_CONT_B, OuyaController.BUTTON_Y,
|
||||
key_CONT_Y, OuyaController.BUTTON_U,
|
||||
key_CONT_X,
|
||||
|
||||
OuyaController.BUTTON_DPAD_UP,
|
||||
key_CONT_DPAD_UP,
|
||||
OuyaController.BUTTON_DPAD_DOWN,
|
||||
key_CONT_DPAD_DOWN,
|
||||
OuyaController.BUTTON_DPAD_LEFT,
|
||||
key_CONT_DPAD_LEFT,
|
||||
OuyaController.BUTTON_DPAD_RIGHT,
|
||||
key_CONT_DPAD_RIGHT,
|
||||
|
||||
OuyaController.BUTTON_MENU, key_CONT_START,
|
||||
OuyaController.BUTTON_R1, key_CONT_START };
|
||||
|
||||
xbox[playerNum] = true;
|
||||
|
||||
globalLS_X[playerNum] = previousLS_X[playerNum] = 0.0f;
|
||||
globalLS_Y[playerNum] = previousLS_Y[playerNum] = 0.0f;
|
||||
} else if (InputDevice.getDevice(joys[i]).getName()
|
||||
.contains("NVIDIA Corporation NVIDIA Controller")) {
|
||||
map[playerNum] = new int[] { OuyaController.BUTTON_O,
|
||||
key_CONT_A, OuyaController.BUTTON_A,
|
||||
key_CONT_B, OuyaController.BUTTON_Y,
|
||||
key_CONT_Y, OuyaController.BUTTON_U,
|
||||
key_CONT_X,
|
||||
|
||||
OuyaController.BUTTON_DPAD_UP,
|
||||
key_CONT_DPAD_UP,
|
||||
OuyaController.BUTTON_DPAD_DOWN,
|
||||
key_CONT_DPAD_DOWN,
|
||||
OuyaController.BUTTON_DPAD_LEFT,
|
||||
key_CONT_DPAD_LEFT,
|
||||
OuyaController.BUTTON_DPAD_RIGHT,
|
||||
key_CONT_DPAD_RIGHT,
|
||||
|
||||
OuyaController.BUTTON_MENU, key_CONT_START,
|
||||
OuyaController.BUTTON_R1, key_CONT_START };
|
||||
nVidia[playerNum] = true;
|
||||
|
||||
globalLS_X[playerNum] = previousLS_X[playerNum] = 0.0f;
|
||||
globalLS_Y[playerNum] = previousLS_Y[playerNum] = 0.0f;
|
||||
} else if (!moga.isActive) { // Ouya controller
|
||||
map[playerNum] = new int[] { OuyaController.BUTTON_O,
|
||||
key_CONT_A, OuyaController.BUTTON_A,
|
||||
key_CONT_B, OuyaController.BUTTON_Y,
|
||||
key_CONT_Y, OuyaController.BUTTON_U,
|
||||
key_CONT_X,
|
||||
|
||||
OuyaController.BUTTON_DPAD_UP,
|
||||
key_CONT_DPAD_UP,
|
||||
OuyaController.BUTTON_DPAD_DOWN,
|
||||
key_CONT_DPAD_DOWN,
|
||||
OuyaController.BUTTON_DPAD_LEFT,
|
||||
key_CONT_DPAD_LEFT,
|
||||
OuyaController.BUTTON_DPAD_RIGHT,
|
||||
key_CONT_DPAD_RIGHT,
|
||||
|
||||
OuyaController.BUTTON_MENU, key_CONT_START,
|
||||
OuyaController.BUTTON_R1, key_CONT_START };
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -307,54 +323,93 @@ public class GL2JNIActivity extends Activity {
|
|||
"Press the back button for a menu", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
private int getModifiedKey(int KeyCode) {
|
||||
if (prefs.getInt("a_button", -1) == KeyCode) {
|
||||
return OuyaController.BUTTON_O;
|
||||
}
|
||||
if (prefs.getInt("b_button", -1) == KeyCode) {
|
||||
return OuyaController.BUTTON_A;
|
||||
}
|
||||
if (prefs.getInt("x_button", -1) == KeyCode) {
|
||||
return OuyaController.BUTTON_U;
|
||||
}
|
||||
if (prefs.getInt("y_button", -1) == KeyCode) {
|
||||
return OuyaController.BUTTON_Y;
|
||||
}
|
||||
if (prefs.getInt("l_button", -1) == KeyCode) {
|
||||
return OuyaController.BUTTON_L1;
|
||||
}
|
||||
if (prefs.getInt("r_button", -1) == KeyCode) {
|
||||
return OuyaController.BUTTON_R1;
|
||||
}
|
||||
if (prefs.getInt("dpad_left", -1) == KeyCode) {
|
||||
return OuyaController.BUTTON_DPAD_LEFT;
|
||||
}
|
||||
if (prefs.getInt("dpad_right", -1) == KeyCode) {
|
||||
return OuyaController.BUTTON_DPAD_RIGHT;
|
||||
}
|
||||
if (prefs.getInt("dpad_up", -1) == KeyCode) {
|
||||
return OuyaController.BUTTON_DPAD_UP;
|
||||
}
|
||||
if (prefs.getInt("dpad_down", -1) == KeyCode) {
|
||||
return OuyaController.BUTTON_DPAD_DOWN;
|
||||
}
|
||||
if (prefs.getInt("start_button", -1) == KeyCode) {
|
||||
return OuyaController.BUTTON_MENU;
|
||||
}
|
||||
return KeyCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onGenericMotionEvent(MotionEvent event) {
|
||||
// Log.w("INPUT", event.toString() + " " + event.getSource());
|
||||
// Get all the axis for the KeyEvent
|
||||
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
|
||||
|
||||
Integer playerNum = deviceDescriptor_PlayerNum.get(deviceId_deviceDescriptor.get(event.getDeviceId()));
|
||||
Integer playerNum = deviceDescriptor_PlayerNum
|
||||
.get(deviceId_deviceDescriptor.get(event.getDeviceId()));
|
||||
|
||||
if (playerNum == null)
|
||||
return false;
|
||||
if (playerNum == null)
|
||||
return false;
|
||||
|
||||
if (!moga.isActive) {
|
||||
if (!moga.isActive) {
|
||||
|
||||
// Joystick
|
||||
if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
|
||||
// Joystick
|
||||
if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
|
||||
|
||||
// do other things with joystick
|
||||
float LS_X = event.getAxisValue(OuyaController.AXIS_LS_X);
|
||||
float LS_Y = event.getAxisValue(OuyaController.AXIS_LS_Y);
|
||||
float RS_X = event.getAxisValue(OuyaController.AXIS_RS_X);
|
||||
float RS_Y = event.getAxisValue(OuyaController.AXIS_RS_Y);
|
||||
float L2 = event.getAxisValue(OuyaController.AXIS_L2);
|
||||
float R2 = event.getAxisValue(OuyaController.AXIS_R2);
|
||||
// do other things with joystick
|
||||
float LS_X = event.getAxisValue(OuyaController.AXIS_LS_X);
|
||||
float LS_Y = event.getAxisValue(OuyaController.AXIS_LS_Y);
|
||||
float RS_X = event.getAxisValue(OuyaController.AXIS_RS_X);
|
||||
float RS_Y = event.getAxisValue(OuyaController.AXIS_RS_Y);
|
||||
float L2 = event.getAxisValue(OuyaController.AXIS_L2);
|
||||
float R2 = event.getAxisValue(OuyaController.AXIS_R2);
|
||||
|
||||
if (xbox[playerNum] || nVidia[playerNum]) {
|
||||
previousLS_X[playerNum] = globalLS_X[playerNum];
|
||||
previousLS_Y[playerNum] = globalLS_Y[playerNum];
|
||||
globalLS_X[playerNum] = LS_X;
|
||||
globalLS_Y[playerNum] = LS_Y;
|
||||
}
|
||||
|
||||
GL2JNIView.lt[playerNum] = (int) (L2 * 255);
|
||||
GL2JNIView.rt[playerNum] = (int) (R2 * 255);
|
||||
|
||||
GL2JNIView.jx[playerNum] = (int) (LS_X * 126);
|
||||
GL2JNIView.jy[playerNum] = (int) (LS_Y * 126);
|
||||
}
|
||||
|
||||
if (xbox[playerNum] || nVidia[playerNum]) {
|
||||
previousLS_X[playerNum] = globalLS_X[playerNum];
|
||||
previousLS_Y[playerNum] = globalLS_Y[playerNum];
|
||||
globalLS_X[playerNum] = LS_X;
|
||||
globalLS_Y[playerNum] = LS_Y;
|
||||
}
|
||||
|
||||
GL2JNIView.lt[playerNum] = (int) (L2 * 255);
|
||||
GL2JNIView.rt[playerNum] = (int) (R2 * 255);
|
||||
|
||||
GL2JNIView.jx[playerNum] = (int) (LS_X * 126);
|
||||
GL2JNIView.jy[playerNum] = (int) (LS_Y * 126);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ((xbox[playerNum] || nVidia[playerNum]) && ((globalLS_X[playerNum] == previousLS_X[playerNum] && globalLS_Y[playerNum] == previousLS_Y[playerNum])
|
||||
|| (previousLS_X[playerNum] == 0.0f && previousLS_Y[playerNum] == 0.0f)))
|
||||
// Only handle Left Stick on an Xbox 360 controller if there was some actual motion on the stick,
|
||||
// so otherwise the event can be handled as a DPAD event
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
if ((xbox[playerNum] || nVidia[playerNum])
|
||||
&& ((globalLS_X[playerNum] == previousLS_X[playerNum] && globalLS_Y[playerNum] == previousLS_Y[playerNum]) || (previousLS_X[playerNum] == 0.0f && previousLS_Y[playerNum] == 0.0f)))
|
||||
// Only handle Left Stick on an Xbox 360 controller if there was
|
||||
// some actual motion on the stick,
|
||||
// so otherwise the event can be handled as a DPAD event
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
|
||||
} else {
|
||||
return false;
|
||||
|
@ -362,15 +417,15 @@ public class GL2JNIActivity extends Activity {
|
|||
|
||||
}
|
||||
|
||||
private static final int key_CONT_B = 0x0002;
|
||||
private static final int key_CONT_A = 0x0004;
|
||||
private static final int key_CONT_START = 0x0008;
|
||||
private static final int key_CONT_DPAD_UP = 0x0010;
|
||||
private static final int key_CONT_DPAD_DOWN = 0x0020;
|
||||
private static final int key_CONT_DPAD_LEFT = 0x0040;
|
||||
private static final int key_CONT_DPAD_RIGHT = 0x0080;
|
||||
private static final int key_CONT_Y = 0x0200;
|
||||
private static final int key_CONT_X = 0x0400;
|
||||
private static final int key_CONT_B = 0x0002;
|
||||
private static final int key_CONT_A = 0x0004;
|
||||
private static final int key_CONT_START = 0x0008;
|
||||
private static final int key_CONT_DPAD_UP = 0x0010;
|
||||
private static final int key_CONT_DPAD_DOWN = 0x0020;
|
||||
private static final int key_CONT_DPAD_LEFT = 0x0040;
|
||||
private static final int key_CONT_DPAD_RIGHT = 0x0080;
|
||||
private static final int key_CONT_Y = 0x0200;
|
||||
private static final int key_CONT_X = 0x0400;
|
||||
|
||||
// TODO: Controller mapping in options. Trunk has Ouya layout. This is a DS3
|
||||
// layout.
|
||||
|
@ -407,48 +462,51 @@ public class GL2JNIActivity extends Activity {
|
|||
*/
|
||||
|
||||
boolean handle_key(Integer playerNum, int kc, boolean down) {
|
||||
if (playerNum == null)
|
||||
return false;
|
||||
if (playerNum == null)
|
||||
return false;
|
||||
|
||||
if (!moga.isActive) {
|
||||
if (!moga.isActive) {
|
||||
|
||||
boolean rav = false;
|
||||
for (int i = 0; i < map[playerNum].length; i += 2) {
|
||||
if (map[playerNum][i + 0] == kc) {
|
||||
if (down)
|
||||
GL2JNIView.kcode_raw[playerNum] &= ~map[playerNum][i + 1];
|
||||
else
|
||||
GL2JNIView.kcode_raw[playerNum] |= map[playerNum][i + 1];
|
||||
boolean rav = false;
|
||||
for (int i = 0; i < map[playerNum].length; i += 2) {
|
||||
if (map[playerNum][i + 0] == kc) {
|
||||
if (down)
|
||||
GL2JNIView.kcode_raw[playerNum] &= ~map[playerNum][i + 1];
|
||||
else
|
||||
GL2JNIView.kcode_raw[playerNum] |= map[playerNum][i + 1];
|
||||
|
||||
rav = true;
|
||||
break;
|
||||
rav = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rav;
|
||||
return rav;
|
||||
|
||||
} else {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
Integer playerNum = deviceDescriptor_PlayerNum.get(deviceId_deviceDescriptor.get(event.getDeviceId()));
|
||||
Integer playerNum = deviceDescriptor_PlayerNum
|
||||
.get(deviceId_deviceDescriptor.get(event.getDeviceId()));
|
||||
|
||||
return handle_key(playerNum, keyCode, false) || super.onKeyUp(keyCode, event);
|
||||
return handle_key(playerNum, getModifiedKey(keyCode), false)
|
||||
|| super.onKeyUp(getModifiedKey(keyCode), event);
|
||||
}
|
||||
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
Integer playerNum = deviceDescriptor_PlayerNum.get(deviceId_deviceDescriptor.get(event.getDeviceId()));
|
||||
Integer playerNum = deviceDescriptor_PlayerNum
|
||||
.get(deviceId_deviceDescriptor.get(event.getDeviceId()));
|
||||
|
||||
if (handle_key(playerNum, keyCode, true)) {
|
||||
if(playerNum == 0)
|
||||
if (handle_key(playerNum, getModifiedKey(keyCode), true)) {
|
||||
if (playerNum == 0)
|
||||
JNIdc.hide_osd();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_MENU
|
||||
|| keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
if (getModifiedKey(keyCode) == KeyEvent.KEYCODE_MENU
|
||||
|| getModifiedKey(keyCode) == KeyEvent.KEYCODE_BACK) {
|
||||
if (!popUp.isShowing()) {
|
||||
popUp.showAtLocation(mView, Gravity.BOTTOM, 0, 0);
|
||||
popUp.update(LayoutParams.WRAP_CONTENT,
|
||||
|
@ -460,7 +518,7 @@ public class GL2JNIActivity extends Activity {
|
|||
|
||||
return true;
|
||||
} else
|
||||
return super.onKeyDown(keyCode, event);
|
||||
return super.onKeyDown(getModifiedKey(keyCode), event);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -153,6 +153,22 @@ public class InputFragment extends Fragment {
|
|||
}
|
||||
|
||||
updateVibration();
|
||||
|
||||
Button buttonKeycodeEditor = (Button) getView().findViewById(
|
||||
R.id.buttonKeycodeEditor);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
|
||||
buttonKeycodeEditor.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
InputModFragment inputModFrag = new InputModFragment();
|
||||
getActivity().getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(R.id.fragment_container, inputModFrag,
|
||||
"INPUT_MOD_FRAG").addToBackStack(null).commit();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
buttonKeycodeEditor.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateVibration() {
|
||||
|
@ -172,7 +188,7 @@ public class InputFragment extends Fragment {
|
|||
InputDevice dev = InputDevice.getDevice(devideId);
|
||||
String descriptor = null;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
descriptor = dev.getDescriptor();
|
||||
descriptor = dev.getDescriptor();
|
||||
} else {
|
||||
descriptor = dev.getName();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,239 @@
|
|||
package com.reicast.emulator;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class InputModFragment extends Fragment {
|
||||
|
||||
private Activity parentActivity;
|
||||
private SharedPreferences mPrefs;
|
||||
|
||||
// Container Activity must implement this interface
|
||||
public interface OnClickListener {
|
||||
public void onMainBrowseSelected(String path_entry, boolean games);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.input_mod_fragment, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
parentActivity = getActivity();
|
||||
|
||||
mPrefs = PreferenceManager
|
||||
.getDefaultSharedPreferences(parentActivity);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
|
||||
|
||||
final TextView a_button_text = (TextView) getView()
|
||||
.findViewById(R.id.a_button_key);
|
||||
getKeyCode("a_button", a_button_text);
|
||||
Button a_button = (Button) getView()
|
||||
.findViewById(R.id.a_button_edit);
|
||||
a_button.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
mapKeyCode("a_button", a_button_text);
|
||||
}
|
||||
});
|
||||
|
||||
final TextView b_button_text = (TextView) getView()
|
||||
.findViewById(R.id.b_button_key);
|
||||
getKeyCode("b_button", b_button_text);
|
||||
Button b_button = (Button) getView()
|
||||
.findViewById(R.id.b_button_edit);
|
||||
b_button.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
mapKeyCode("b_button", b_button_text);
|
||||
}
|
||||
});
|
||||
|
||||
final TextView x_button_text = (TextView) getView()
|
||||
.findViewById(R.id.x_button_key);
|
||||
getKeyCode("x_button", x_button_text);
|
||||
Button x_button = (Button) getView()
|
||||
.findViewById(R.id.x_button_edit);
|
||||
x_button.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
mapKeyCode("x_button", x_button_text);
|
||||
}
|
||||
});
|
||||
|
||||
final TextView y_button_text = (TextView) getView()
|
||||
.findViewById(R.id.y_button_key);
|
||||
getKeyCode("y_button", y_button_text);
|
||||
Button y_button = (Button) getView()
|
||||
.findViewById(R.id.y_button_edit);
|
||||
y_button.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
mapKeyCode("y_button", y_button_text);
|
||||
}
|
||||
});
|
||||
|
||||
final TextView l_button_text = (TextView) getView()
|
||||
.findViewById(R.id.l_button_key);
|
||||
getKeyCode("l_button", l_button_text);
|
||||
Button l_button = (Button) getView()
|
||||
.findViewById(R.id.l_button_edit);
|
||||
l_button.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
mapKeyCode("l_button", l_button_text);
|
||||
}
|
||||
});
|
||||
|
||||
final TextView r_button_text = (TextView) getView()
|
||||
.findViewById(R.id.r_button_key);
|
||||
getKeyCode("r_button", r_button_text);
|
||||
Button r_button = (Button) getView()
|
||||
.findViewById(R.id.r_button_edit);
|
||||
r_button.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
mapKeyCode("r_button", r_button_text);
|
||||
}
|
||||
});
|
||||
|
||||
final TextView joystick_text = (TextView) getView()
|
||||
.findViewById(R.id.joystick_key);
|
||||
getKeyCode("joystick", joystick_text);
|
||||
Button joystick = (Button) getView()
|
||||
.findViewById(R.id.joystick_edit);
|
||||
joystick.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
mapKeyCode("joystick", joystick_text);
|
||||
}
|
||||
});
|
||||
|
||||
final TextView dpad_left_text = (TextView) getView()
|
||||
.findViewById(R.id.dpad_left_key);
|
||||
getKeyCode("dpad_left", dpad_left_text);
|
||||
Button dpad_left = (Button) getView()
|
||||
.findViewById(R.id.dpad_left_edit);
|
||||
dpad_left.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
mapKeyCode("dpad_left", dpad_left_text);
|
||||
}
|
||||
});
|
||||
|
||||
final TextView dpad_right_text = (TextView) getView()
|
||||
.findViewById(R.id.dpad_right_key);
|
||||
getKeyCode("dpad_right", dpad_right_text);
|
||||
Button dpad_right = (Button) getView()
|
||||
.findViewById(R.id.dpad_right_edit);
|
||||
dpad_right.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
mapKeyCode("dpad_right", dpad_right_text);
|
||||
}
|
||||
});
|
||||
|
||||
final TextView dpad_up_text = (TextView) getView()
|
||||
.findViewById(R.id.dpad_up_key);
|
||||
getKeyCode("dpad_up", dpad_up_text);
|
||||
Button dpad_up = (Button) getView()
|
||||
.findViewById(R.id.dpad_up_edit);
|
||||
dpad_up.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
mapKeyCode("dpad_up", dpad_up_text);
|
||||
}
|
||||
});
|
||||
|
||||
final TextView dpad_down_text = (TextView) getView()
|
||||
.findViewById(R.id.dpad_down_key);
|
||||
getKeyCode("dpad_down", dpad_down_text);
|
||||
Button dpad_down = (Button) getView()
|
||||
.findViewById(R.id.dpad_down_edit);
|
||||
dpad_down.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
mapKeyCode("dpad_down", dpad_down_text);
|
||||
}
|
||||
});
|
||||
|
||||
final TextView start_button_text = (TextView) getView()
|
||||
.findViewById(R.id.start_button_key);
|
||||
getKeyCode("start_button", start_button_text);
|
||||
Button start_button = (Button) getView()
|
||||
.findViewById(R.id.start_button_edit);
|
||||
start_button.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
mapKeyCode("start_button", start_button_text);
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
// Notify the user they got here by mistake
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void getKeyCode(final String button, final TextView output) {
|
||||
int keyCode = mPrefs.getInt(button, -1);
|
||||
if (keyCode != -1) {
|
||||
String label = output.getText().toString();
|
||||
if (label.contains(":")) {
|
||||
label = label.substring(0, label.indexOf(":"));
|
||||
}
|
||||
output.setText(label + ": " + String.valueOf(keyCode));
|
||||
}
|
||||
}
|
||||
|
||||
private void mapKeyCode(final String button, final TextView output) {
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
||||
builder.setTitle(getString(R.string.map_keycode_title));
|
||||
builder.setMessage(getString(R.string.map_keycode_message, button.replace("_", " ")));
|
||||
builder.setNegativeButton("Cancel",
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
builder.setOnKeyListener(new Dialog.OnKeyListener() {
|
||||
public boolean onKey(DialogInterface dialog, int keyCode,
|
||||
KeyEvent event) {
|
||||
int value = mapButton(keyCode, event, button);
|
||||
dialog.dismiss();
|
||||
if (value != -1) {
|
||||
String label = output.getText().toString();
|
||||
if (label.contains(":")) {
|
||||
label = label.substring(0, label.indexOf(":"));
|
||||
}
|
||||
output.setText(label + ": " + String.valueOf(value));
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
builder.create();
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private int mapButton(int keyCode, KeyEvent event, String button) {
|
||||
if (keyCode == KeyEvent.KEYCODE_MENU
|
||||
|| keyCode == KeyEvent.KEYCODE_BACK
|
||||
|| keyCode == KeyEvent.KEYCODE_VOLUME_UP
|
||||
|| keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
|
||||
return -1;
|
||||
|
||||
mPrefs.edit().putInt(button, keyCode).commit();
|
||||
|
||||
return keyCode;
|
||||
}
|
||||
}
|
|
@ -3,8 +3,11 @@ package com.reicast.emulator;
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
import tv.ouya.console.api.OuyaController;
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.bda.controller.Controller;
|
||||
|
@ -20,6 +23,8 @@ import com.bda.controller.StateEvent;
|
|||
*/
|
||||
public class MOGAInput
|
||||
{
|
||||
private SharedPreferences prefs;
|
||||
|
||||
static final int DELAY = 1000 / 50; // 50 Hz
|
||||
|
||||
static final int ACTION_CONNECTED = Controller.ACTION_CONNECTED;
|
||||
|
@ -93,6 +98,9 @@ public class MOGAInput
|
|||
protected void onCreate(Activity act)
|
||||
{
|
||||
this.act = act;
|
||||
|
||||
prefs = PreferenceManager
|
||||
.getDefaultSharedPreferences(act.getApplicationContext());
|
||||
|
||||
mController = Controller.getInstance(act);
|
||||
mController.init();
|
||||
|
@ -136,6 +144,43 @@ public class MOGAInput
|
|||
}
|
||||
*/
|
||||
}
|
||||
|
||||
private int getModifiedKey(int KeyCode) {
|
||||
if (prefs.getInt("a_button", -1) == KeyCode) {
|
||||
return KeyEvent.KEYCODE_BUTTON_A;
|
||||
}
|
||||
if (prefs.getInt("b_button", -1) == KeyCode) {
|
||||
return KeyEvent.KEYCODE_BUTTON_B;
|
||||
}
|
||||
if (prefs.getInt("x_button", -1) == KeyCode) {
|
||||
return KeyEvent.KEYCODE_BUTTON_X;
|
||||
}
|
||||
if (prefs.getInt("y_button", -1) == KeyCode) {
|
||||
return KeyEvent.KEYCODE_BUTTON_Y;
|
||||
}
|
||||
if (prefs.getInt("l_button", -1) == KeyCode) {
|
||||
return KeyEvent.KEYCODE_BUTTON_L2;
|
||||
}
|
||||
if (prefs.getInt("r_button", -1) == KeyCode) {
|
||||
return KeyEvent.KEYCODE_BUTTON_R2;
|
||||
}
|
||||
if (prefs.getInt("dpad_left", -1) == KeyCode) {
|
||||
return KeyEvent.KEYCODE_DPAD_LEFT;
|
||||
}
|
||||
if (prefs.getInt("dpad_right", -1) == KeyCode) {
|
||||
return KeyEvent.KEYCODE_DPAD_RIGHT;
|
||||
}
|
||||
if (prefs.getInt("dpad_up", -1) == KeyCode) {
|
||||
return KeyEvent.KEYCODE_DPAD_UP;
|
||||
}
|
||||
if (prefs.getInt("dpad_down", -1) == KeyCode) {
|
||||
return KeyEvent.KEYCODE_DPAD_DOWN;
|
||||
}
|
||||
if (prefs.getInt("start_button", -1) == KeyCode) {
|
||||
return KeyEvent.KEYCODE_BUTTON_START;
|
||||
}
|
||||
return KeyCode;
|
||||
}
|
||||
|
||||
class ExampleControllerListener implements ControllerListener
|
||||
{
|
||||
|
@ -150,7 +195,7 @@ public class MOGAInput
|
|||
JNIdc.hide_osd();
|
||||
|
||||
for (int i = 0; i < map.length; i += 2) {
|
||||
if (map[i + 0] == event.getKeyCode()) {
|
||||
if (map[i + 0] == getModifiedKey(event.getKeyCode())) {
|
||||
if (event.getAction() == 0) //FIXME to const
|
||||
GL2JNIView.kcode_raw[playerNum] &= ~map[i + 1];
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue