Merge pull request #134 from NoblesseOblige/master

Feature request : key mapping / Rate reicast menu
This commit is contained in:
TwistedUmbrella 2014-01-24 06:34:46 -08:00
commit 960153d547
9 changed files with 980 additions and 232 deletions

View File

@ -252,6 +252,17 @@
android:text="@string/remove" /> android:text="@string/remove" />
</LinearLayout> </LinearLayout>
</TableRow> </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> </TableLayout>
</LinearLayout> </LinearLayout>

View File

@ -0,0 +1,361 @@
<?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:layout_marginTop="25dp"
android:gravity="center_vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:ems="10"
android:gravity="center_vertical|left"
android:text="@string/modified_layout" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<de.ankri.views.Switch
android:id="@+id/switchModifiedLayoutEnabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</TableRow>
<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>

View File

@ -70,6 +70,16 @@
android:layout_marginTop="2dp" android:layout_marginTop="2dp"
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:src="@drawable/question" /> android:src="@drawable/question" />
<ImageView
android:id="@+id/rate"
android:layout_width="48dp"
android:layout_height="fill_parent"
android:layout_marginBottom="2dp"
android:layout_marginLeft="2dp"
android:layout_marginTop="2dp"
android:scaleType="fitCenter"
android:src="@drawable/profiler" />
</LinearLayout> </LinearLayout>
<FrameLayout <FrameLayout

View File

@ -42,9 +42,17 @@
<string name="select_controller_title">Select Controller</string> <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="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="controller_already_in_use">This controller is already in use!</string>
<string name="modified_layout">Enable Custom Key Layout</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="moga_pro_connect">MOGA Pro Connected!</string>
<string name="moga_connect">MOGA Connected!</string>
<string name="about_title">About reicast</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> <string name="about_text">reicast is a dreamcast emulator\n\nVersion: %1$s\n\n</string>
<string-array name="images"> <string-array name="images">
<item>cdi</item> <item>cdi</item>
@ -69,6 +77,7 @@
<item>Paths</item> <item>Paths</item>
<item>Input</item> <item>Input</item>
<item>About</item> <item>About</item>
<item>Rate Me</item>
</string-array> </string-array>
<!-- Nav Drawer List Item Icons --> <!-- Nav Drawer List Item Icons -->
@ -79,6 +88,7 @@
<item>@drawable/open_folder</item> <item>@drawable/open_folder</item>
<item>@drawable/input</item> <item>@drawable/input</item>
<item>@drawable/question</item> <item>@drawable/question</item>
<item>@drawable/profiler</item>
</array> </array>
<!-- Content Description --> <!-- Content Description -->

View File

@ -39,8 +39,11 @@ public class GL2JNIActivity extends Activity {
PopupWindow popUp; PopupWindow popUp;
LayoutParams params; LayoutParams params;
MOGAInput moga = new MOGAInput(); MOGAInput moga = new MOGAInput();
static boolean[] xbox = { false, false, false, false }, nVidia = { false, false, false, false }; private SharedPreferences prefs;
float[] globalLS_X = new float[4], globalLS_Y = new float[4], previousLS_X = new float[4], previousLS_Y = new float[4]; 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<Integer, String> deviceId_deviceDescriptor = new HashMap<Integer, String>();
public static HashMap<String, Integer> deviceDescriptor_PlayerNum = new HashMap<String, Integer>(); 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() { hlay.addView(addbut(R.drawable.close, new OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
Intent inte = new Intent(GL2JNIActivity.this, MainActivity.class); Intent inte = new Intent(GL2JNIActivity.this,
MainActivity.class);
startActivity(inte); startActivity(inte);
GL2JNIActivity.this.finish(); GL2JNIActivity.this.finish();
} }
@ -151,17 +155,22 @@ public class GL2JNIActivity extends Activity {
map = new int[4][]; map = new int[4][];
// Populate device descriptor-to-player-map from preferences // Populate device descriptor-to-player-map from preferences
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs = PreferenceManager.getDefaultSharedPreferences(this);
deviceDescriptor_PlayerNum.put(prefs.getString("device_descriptor_player_1", null), 0); deviceDescriptor_PlayerNum.put(
deviceDescriptor_PlayerNum.put(prefs.getString("device_descriptor_player_2", null), 1); prefs.getString("device_descriptor_player_1", null), 0);
deviceDescriptor_PlayerNum.put(prefs.getString("device_descriptor_player_3", null), 2); deviceDescriptor_PlayerNum.put(
deviceDescriptor_PlayerNum.put(prefs.getString("device_descriptor_player_4", null), 3); 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 controllerTwoConnected = false;
boolean controllerThreeConnected = false; boolean controllerThreeConnected = false;
boolean controllerFourConnected = 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(); String descriptor = e.getKey();
Integer playerNum = e.getValue(); Integer playerNum = e.getValue();
@ -183,7 +192,8 @@ public class GL2JNIActivity extends Activity {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { 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(); int joys[] = InputDevice.getDeviceIds();
for (int i = 0; i < joys.length; i++) { for (int i = 0; i < joys.length; i++) {
@ -194,18 +204,22 @@ public class GL2JNIActivity extends Activity {
descriptor = InputDevice.getDevice(joys[i]).getName(); descriptor = InputDevice.getDevice(joys[i]).getName();
} }
Log.d("reidc", "InputDevice ID: " + joys[i]); Log.d("reidc", "InputDevice ID: " + joys[i]);
Log.d("reidc", "InputDevice Name: " Log.d("reidc",
"InputDevice Name: "
+ InputDevice.getDevice(joys[i]).getName()); + InputDevice.getDevice(joys[i]).getName());
Log.d("reidc", "InputDevice Descriptor: " + descriptor); Log.d("reidc", "InputDevice Descriptor: " + descriptor);
deviceId_deviceDescriptor.put(joys[i], descriptor); deviceId_deviceDescriptor.put(joys[i], descriptor);
} }
for (int i = 0; i < joys.length; i++) { for (int i = 0; i < joys.length; i++) {
Integer playerNum = deviceDescriptor_PlayerNum.get(deviceId_deviceDescriptor.get(joys[i])); Integer playerNum = deviceDescriptor_PlayerNum
.get(deviceId_deviceDescriptor.get(joys[i]));
if (playerNum != null) { if (playerNum != null) {
if (InputDevice.getDevice(joys[i]).getName() if (prefs.getBoolean("modified_key_layout", false)) {
map[playerNum] = setModifiedKeys();
} else if (InputDevice.getDevice(joys[i]).getName()
.equals("Sony PLAYSTATION(R)3 Controller")) { .equals("Sony PLAYSTATION(R)3 Controller")) {
map[playerNum] = new int[] { map[playerNum] = new int[] {
OuyaController.BUTTON_Y, key_CONT_Y, OuyaController.BUTTON_Y, key_CONT_Y,
@ -214,12 +228,9 @@ public class GL2JNIActivity extends Activity {
OuyaController.BUTTON_A, key_CONT_B, OuyaController.BUTTON_A, key_CONT_B,
OuyaController.BUTTON_DPAD_UP, key_CONT_DPAD_UP, OuyaController.BUTTON_DPAD_UP, key_CONT_DPAD_UP,
OuyaController.BUTTON_DPAD_DOWN, OuyaController.BUTTON_DPAD_DOWN, key_CONT_DPAD_DOWN,
key_CONT_DPAD_DOWN, OuyaController.BUTTON_DPAD_LEFT, key_CONT_DPAD_LEFT,
OuyaController.BUTTON_DPAD_LEFT, OuyaController.BUTTON_DPAD_RIGHT, key_CONT_DPAD_RIGHT,
key_CONT_DPAD_LEFT,
OuyaController.BUTTON_DPAD_RIGHT,
key_CONT_DPAD_RIGHT,
OuyaController.BUTTON_MENU, key_CONT_START, OuyaController.BUTTON_MENU, key_CONT_START,
OuyaController.BUTTON_R1, key_CONT_START OuyaController.BUTTON_R1, key_CONT_START
@ -234,15 +245,13 @@ public class GL2JNIActivity extends Activity {
OuyaController.BUTTON_U, key_CONT_X, OuyaController.BUTTON_U, key_CONT_X,
OuyaController.BUTTON_DPAD_UP, key_CONT_DPAD_UP, OuyaController.BUTTON_DPAD_UP, key_CONT_DPAD_UP,
OuyaController.BUTTON_DPAD_DOWN, OuyaController.BUTTON_DPAD_DOWN, key_CONT_DPAD_DOWN,
key_CONT_DPAD_DOWN, OuyaController.BUTTON_DPAD_LEFT, key_CONT_DPAD_LEFT,
OuyaController.BUTTON_DPAD_LEFT, OuyaController.BUTTON_DPAD_RIGHT, key_CONT_DPAD_RIGHT,
key_CONT_DPAD_LEFT,
OuyaController.BUTTON_DPAD_RIGHT,
key_CONT_DPAD_RIGHT,
OuyaController.BUTTON_MENU, key_CONT_START, OuyaController.BUTTON_MENU, key_CONT_START,
OuyaController.BUTTON_R1, key_CONT_START }; OuyaController.BUTTON_R1, key_CONT_START
};
xbox[playerNum] = true; xbox[playerNum] = true;
@ -257,20 +266,18 @@ public class GL2JNIActivity extends Activity {
OuyaController.BUTTON_U, key_CONT_X, OuyaController.BUTTON_U, key_CONT_X,
OuyaController.BUTTON_DPAD_UP, key_CONT_DPAD_UP, OuyaController.BUTTON_DPAD_UP, key_CONT_DPAD_UP,
OuyaController.BUTTON_DPAD_DOWN, OuyaController.BUTTON_DPAD_DOWN, key_CONT_DPAD_DOWN,
key_CONT_DPAD_DOWN, OuyaController.BUTTON_DPAD_LEFT, key_CONT_DPAD_LEFT,
OuyaController.BUTTON_DPAD_LEFT, OuyaController.BUTTON_DPAD_RIGHT, key_CONT_DPAD_RIGHT,
key_CONT_DPAD_LEFT,
OuyaController.BUTTON_DPAD_RIGHT,
key_CONT_DPAD_RIGHT,
OuyaController.BUTTON_MENU, key_CONT_START, OuyaController.BUTTON_MENU, key_CONT_START,
OuyaController.BUTTON_R1, key_CONT_START }; OuyaController.BUTTON_R1, key_CONT_START
};
nVidia[playerNum] = true; nVidia[playerNum] = true;
globalLS_X[playerNum] = previousLS_X[playerNum] = 0.0f; globalLS_X[playerNum] = previousLS_X[playerNum] = 0.0f;
globalLS_Y[playerNum] = previousLS_Y[playerNum] = 0.0f; globalLS_Y[playerNum] = previousLS_Y[playerNum] = 0.0f;
} else if (!moga.isActive) { // Ouya controller } else if (!moga.isActive[playerNum]) { // Ouya controller
map[playerNum] = new int[] { map[playerNum] = new int[] {
OuyaController.BUTTON_O, key_CONT_A, OuyaController.BUTTON_O, key_CONT_A,
OuyaController.BUTTON_A, key_CONT_B, OuyaController.BUTTON_A, key_CONT_B,
@ -278,15 +285,13 @@ public class GL2JNIActivity extends Activity {
OuyaController.BUTTON_U, key_CONT_X, OuyaController.BUTTON_U, key_CONT_X,
OuyaController.BUTTON_DPAD_UP, key_CONT_DPAD_UP, OuyaController.BUTTON_DPAD_UP, key_CONT_DPAD_UP,
OuyaController.BUTTON_DPAD_DOWN, OuyaController.BUTTON_DPAD_DOWN, key_CONT_DPAD_DOWN,
key_CONT_DPAD_DOWN, OuyaController.BUTTON_DPAD_LEFT, key_CONT_DPAD_LEFT,
OuyaController.BUTTON_DPAD_LEFT, OuyaController.BUTTON_DPAD_RIGHT, key_CONT_DPAD_RIGHT,
key_CONT_DPAD_LEFT,
OuyaController.BUTTON_DPAD_RIGHT,
key_CONT_DPAD_RIGHT,
OuyaController.BUTTON_MENU, key_CONT_START, OuyaController.BUTTON_MENU, key_CONT_START,
OuyaController.BUTTON_R1, key_CONT_START }; OuyaController.BUTTON_R1, key_CONT_START
};
} }
} }
@ -307,6 +312,22 @@ public class GL2JNIActivity extends Activity {
"Press the back button for a menu", Toast.LENGTH_SHORT).show(); "Press the back button for a menu", Toast.LENGTH_SHORT).show();
} }
private int[] setModifiedKeys() {
return new int[] {
prefs.getInt("a_button", OuyaController.BUTTON_O), key_CONT_A,
prefs.getInt("b_button", OuyaController.BUTTON_A), key_CONT_B,
prefs.getInt("y_button", OuyaController.BUTTON_Y), key_CONT_Y,
prefs.getInt("x_button", OuyaController.BUTTON_U), key_CONT_X,
prefs.getInt("dpad_up", OuyaController.BUTTON_DPAD_UP), key_CONT_DPAD_UP,
prefs.getInt("dpad_down", OuyaController.BUTTON_DPAD_DOWN), key_CONT_DPAD_DOWN,
prefs.getInt("dpad_left", OuyaController.BUTTON_DPAD_LEFT), key_CONT_DPAD_LEFT,
prefs.getInt("dpad_right", OuyaController.BUTTON_DPAD_RIGHT), key_CONT_DPAD_RIGHT,
prefs.getInt("start_button", OuyaController.BUTTON_MENU), key_CONT_START,
};
}
@Override @Override
public boolean onGenericMotionEvent(MotionEvent event) { public boolean onGenericMotionEvent(MotionEvent event) {
// Log.w("INPUT", event.toString() + " " + event.getSource()); // Log.w("INPUT", event.toString() + " " + event.getSource());
@ -314,12 +335,13 @@ public class GL2JNIActivity extends Activity {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { 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) if (playerNum == null)
return false; return false;
if (!moga.isActive) { if (!moga.isActive[playerNum]) {
// Joystick // Joystick
if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
@ -348,9 +370,10 @@ public class GL2JNIActivity extends Activity {
} }
if ((xbox[playerNum] || nVidia[playerNum]) && ((globalLS_X[playerNum] == previousLS_X[playerNum] && globalLS_Y[playerNum] == previousLS_Y[playerNum]) if ((xbox[playerNum] || nVidia[playerNum])
|| (previousLS_X[playerNum] == 0.0f && previousLS_Y[playerNum] == 0.0f))) && ((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, // 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 // so otherwise the event can be handled as a DPAD event
return false; return false;
else else
@ -410,7 +433,7 @@ public class GL2JNIActivity extends Activity {
if (playerNum == null) if (playerNum == null)
return false; return false;
if (!moga.isActive) { if (!moga.isActive[playerNum]) {
boolean rav = false; boolean rav = false;
for (int i = 0; i < map[playerNum].length; i += 2) { for (int i = 0; i < map[playerNum].length; i += 2) {
@ -433,16 +456,19 @@ public class GL2JNIActivity extends Activity {
} }
public boolean onKeyUp(int keyCode, KeyEvent event) { 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, keyCode, false)
|| super.onKeyUp(keyCode, event);
} }
public boolean onKeyDown(int keyCode, KeyEvent 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 (handle_key(playerNum, keyCode, true)) {
if(playerNum == 0) if (playerNum == 0)
JNIdc.hide_osd(); JNIdc.hide_osd();
return true; return true;
} }

View File

@ -153,6 +153,22 @@ public class InputFragment extends Fragment {
} }
updateVibration(); 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() { private void updateVibration() {

View File

@ -0,0 +1,265 @@
package com.reicast.emulator;
import de.ankri.views.Switch;
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.CompoundButton;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class InputModFragment extends Fragment {
private Activity parentActivity;
private SharedPreferences mPrefs;
private Switch switchModifiedLayoutEnabled;
// 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);
OnCheckedChangeListener modified_layout = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
mPrefs.edit()
.putBoolean("modified_key_layout", isChecked)
.commit();
}
};
switchModifiedLayoutEnabled = (Switch) getView().findViewById(
R.id.switchModifiedLayoutEnabled);
boolean layout = mPrefs.getBoolean(
"modified_key_layout", false);
if (layout) {
switchModifiedLayoutEnabled.setChecked(true);
} else {
switchModifiedLayoutEnabled.setChecked(false);
}
switchModifiedLayoutEnabled.setOnCheckedChangeListener(modified_layout);
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);
}
});
joystick.setEnabled(false);
mPrefs.edit().remove("joystick").commit();
// Still needs better support for identifying the entire stick
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 {
switchModifiedLayoutEnabled.setEnabled(false);
}
}
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;
}
}

View File

@ -4,7 +4,9 @@ package com.reicast.emulator;
/******************************************************************************/ /******************************************************************************/
import android.app.Activity; import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Handler; import android.os.Handler;
import android.preference.PreferenceManager;
import android.widget.Toast; import android.widget.Toast;
import com.bda.controller.Controller; import com.bda.controller.Controller;
@ -20,6 +22,8 @@ import com.bda.controller.StateEvent;
*/ */
public class MOGAInput public class MOGAInput
{ {
private SharedPreferences prefs;
static final int DELAY = 1000 / 50; // 50 Hz static final int DELAY = 1000 / 50; // 50 Hz
static final int ACTION_CONNECTED = Controller.ACTION_CONNECTED; static final int ACTION_CONNECTED = Controller.ACTION_CONNECTED;
@ -29,7 +33,8 @@ public class MOGAInput
Controller mController = null; Controller mController = null;
public boolean isActive = false; public boolean isActive[] = { false, false, false, false };
public boolean isMogaPro[] = { false, false, false, false };
private static final int key_CONT_B = 0x0002; private static final int key_CONT_B = 0x0002;
private static final int key_CONT_A = 0x0004; private static final int key_CONT_A = 0x0004;
@ -93,6 +98,7 @@ public class MOGAInput
protected void onCreate(Activity act) protected void onCreate(Activity act)
{ {
this.act = act; this.act = act;
setModifiedKeys();
mController = Controller.getInstance(act); mController = Controller.getInstance(act);
mController.init(); mController.init();
@ -137,6 +143,26 @@ public class MOGAInput
*/ */
} }
private void setModifiedKeys() {
prefs = PreferenceManager
.getDefaultSharedPreferences(act.getApplicationContext());
if (prefs.getBoolean("modified_key_layout", false)) {
map = new int[] {
prefs.getInt("b_button", KeyEvent.KEYCODE_BUTTON_B), key_CONT_B,
prefs.getInt("a_button", KeyEvent.KEYCODE_BUTTON_A), key_CONT_A,
prefs.getInt("x_button", KeyEvent.KEYCODE_BUTTON_X), key_CONT_X,
prefs.getInt("l_button", KeyEvent.KEYCODE_BUTTON_Y), key_CONT_Y,
prefs.getInt("dpad_up", KeyEvent.KEYCODE_DPAD_UP), key_CONT_DPAD_UP,
prefs.getInt("dpad_down", KeyEvent.KEYCODE_DPAD_DOWN), key_CONT_DPAD_DOWN,
prefs.getInt("dpad_left", KeyEvent.KEYCODE_DPAD_LEFT), key_CONT_DPAD_LEFT,
prefs.getInt("dpad_right", KeyEvent.KEYCODE_DPAD_RIGHT), key_CONT_DPAD_RIGHT,
prefs.getInt("start_button", KeyEvent.KEYCODE_BUTTON_START), key_CONT_START,
};
}
}
class ExampleControllerListener implements ControllerListener class ExampleControllerListener implements ControllerListener
{ {
public void onKeyEvent(KeyEvent event) public void onKeyEvent(KeyEvent event)
@ -202,8 +228,20 @@ public class MOGAInput
JNIdc.hide_osd(); JNIdc.hide_osd();
if (event.getState() == StateEvent.STATE_CONNECTION && event.getAction() == ACTION_CONNECTED) { if (event.getState() == StateEvent.STATE_CONNECTION && event.getAction() == ACTION_CONNECTED) {
Toast.makeText(act.getApplicationContext(), "MOGA Connected!", Toast.LENGTH_SHORT).show(); int mControllerVersion = mController.getState(Controller.STATE_CURRENT_PRODUCT_VERSION);
isActive = true; String notify = null;
if (mControllerVersion == Controller.ACTION_VERSION_MOGAPRO) {
isActive[playerNum] = true;
isMogaPro[playerNum] = true;
notify = act.getApplicationContext().getString(R.string.moga_pro_connect);
} else if (mControllerVersion == Controller.ACTION_VERSION_MOGA) {
isActive[playerNum] = true;
isMogaPro[playerNum] = false;
notify = act.getApplicationContext().getString(R.string.moga_connect);
}
if (notify != null && !notify.equals(null)) {
Toast.makeText(act.getApplicationContext(), notify, Toast.LENGTH_SHORT).show();
}
} }
} }
} }

View File

@ -128,6 +128,9 @@ public class MainActivity extends FragmentActivity implements
// About // About
navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons
.getResourceId(4, 0))); .getResourceId(4, 0)));
// Rate
navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons
.getResourceId(5, 0)));
// Recycle the typed array // Recycle the typed array
navMenuIcons.recycle(); navMenuIcons.recycle();
@ -236,21 +239,25 @@ public class MainActivity extends FragmentActivity implements
MainActivity.this); MainActivity.this);
// set title // set title
alertDialogBuilder.setTitle("About reicast"); alertDialogBuilder.setTitle(getString(R.string.about_title));
String versionName = "";
try {
PackageInfo pInfo = getPackageManager().getPackageInfo(
getPackageName(), 0);
versionName = pInfo.versionName;
} catch (NameNotFoundException e) {
e.printStackTrace();
}
// set dialog message
alertDialogBuilder alertDialogBuilder
.setMessage("reicast is a dreamcast emulator") .setMessage(getString(R.string.about_text, versionName))
.setCancelable(false) .setCancelable(false)
.setPositiveButton("Dismiss", .setPositiveButton("Dismiss",
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
public void onClick( public void onClick(DialogInterface dialog,
DialogInterface dialog,
int id) { int id) {
// if this button is clicked, dialog.dismiss();
// close
// current activity
// FileBrowser.this.finish();
} }
}); });
@ -264,6 +271,17 @@ public class MainActivity extends FragmentActivity implements
return false; return false;
} }
}); });
findViewById(R.id.rate).setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
// vib.vibrate(50);
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=" + getPackageName())));
return true;
} else
return false;
}
});
} }
} }
@ -483,21 +501,11 @@ public class MainActivity extends FragmentActivity implements
alertDialogBuilder alertDialogBuilder
.setMessage(getString(R.string.about_text, versionName)) .setMessage(getString(R.string.about_text, versionName))
.setCancelable(false) .setCancelable(false)
.setPositiveButton("Rate It", .setPositiveButton("Dismiss",
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, public void onClick(DialogInterface dialog,
int id) { int id) {
startActivity(new Intent( dialog.dismiss();
Intent.ACTION_VIEW,
Uri.parse("market://details?id="
+ getPackageName())));
}
})
.setNegativeButton("Dismiss",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
} }
}); });
@ -508,6 +516,9 @@ public class MainActivity extends FragmentActivity implements
alertDialog.show(); alertDialog.show();
break; break;
case 5:
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=" + getPackageName())));
default: default:
break; break;
} }