Android: Clean input mod, Begin joystick settings
This commit is contained in:
parent
3e7dea537a
commit
1bd546c708
|
@ -60,8 +60,8 @@ public class InputModFragment extends Fragment {
|
|||
private TextView dpad_right_text;
|
||||
private TextView start_button_text;
|
||||
private TextView select_button_text;
|
||||
private TextView vert_axis_text;
|
||||
private TextView horz_axis_text;
|
||||
private TextView joystick_x_text;
|
||||
private TextView joystick_y_text;
|
||||
|
||||
private String player = "_A";
|
||||
private int sS = 2;
|
||||
|
@ -305,6 +305,40 @@ public class InputModFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
|
||||
joystick_x_text = (TextView) getView().findViewById(
|
||||
R.id.joystick_x_key);
|
||||
Button joystick_x = (Button) getView().findViewById(
|
||||
R.id.joystick_x_edit);
|
||||
joystick_x.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
mKey.mapAxis(Gamepad.pref_axis_x, joystick_x_text);
|
||||
}
|
||||
});
|
||||
Button joystick_x_remove = (Button) getView().findViewById(
|
||||
R.id.remove_joystick_x);
|
||||
joystick_x_remove.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
remKeyCode(Gamepad.pref_axis_x, joystick_x_text);
|
||||
}
|
||||
});
|
||||
|
||||
joystick_y_text = (TextView) getView().findViewById(
|
||||
R.id.joystick_y_key);
|
||||
Button joystick_y = (Button) getView().findViewById(
|
||||
R.id.joystick_y_edit);
|
||||
joystick_y.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
mKey.mapAxis(Gamepad.pref_axis_y, joystick_y_text);
|
||||
}
|
||||
});
|
||||
Button joystick_y_remove = (Button) getView().findViewById(
|
||||
R.id.remove_joystick_y);
|
||||
joystick_y_remove.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
remKeyCode(Gamepad.pref_axis_y, joystick_y_text);
|
||||
}
|
||||
});
|
||||
|
||||
ImageView start_button_icon = (ImageView) getView().findViewById(
|
||||
R.id.start_button_icon);
|
||||
start_button_icon.setImageDrawable(getButtonImage(0, 64 / sS));
|
||||
|
@ -456,9 +490,6 @@ public class InputModFragment extends Fragment {
|
|||
}
|
||||
|
||||
private class mapKeyCode extends AlertDialog.Builder {
|
||||
private String button;
|
||||
private TextView output;
|
||||
private boolean isMapping;
|
||||
|
||||
public mapKeyCode(Context c) {
|
||||
super(c);
|
||||
|
@ -473,23 +504,18 @@ public class InputModFragment extends Fragment {
|
|||
* The output display for the assigned button value
|
||||
*/
|
||||
public void intiateSearch(final String button, final TextView output) {
|
||||
this.button = button;
|
||||
this.output = output;
|
||||
isMapping = true;
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setTitle(R.string.map_keycode_title);
|
||||
builder.setMessage(getString(R.string.map_keycode_message, button.replace("_", " ")));
|
||||
builder.setNegativeButton(R.string.cancel,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
isMapping = false;
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
builder.setOnKeyListener(new Dialog.OnKeyListener() {
|
||||
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
|
||||
mapButton(keyCode, event);
|
||||
isMapping = false;
|
||||
mapButton(keyCode, button);
|
||||
dialog.dismiss();
|
||||
return getKeyCode(button, output);
|
||||
}
|
||||
|
@ -503,10 +529,10 @@ public class InputModFragment extends Fragment {
|
|||
*
|
||||
* @param keyCode
|
||||
* The keycode generated by the button being assigned
|
||||
* @param event
|
||||
* The keyevent generated by the button being assigned
|
||||
* @param button
|
||||
* The label of the button being assigned
|
||||
*/
|
||||
private int mapButton(int keyCode, KeyEvent event) {
|
||||
private int mapButton(int keyCode, String button) {
|
||||
if (Build.MODEL.startsWith("R800")) {
|
||||
if (keyCode == KeyEvent.KEYCODE_MENU)
|
||||
return -1;
|
||||
|
@ -520,16 +546,35 @@ public class InputModFragment extends Fragment {
|
|||
return keyCode;
|
||||
}
|
||||
|
||||
private void mapAxis(View view, final int axis) {
|
||||
if (isMapping) {
|
||||
view.setOnGenericMotionListener(new View.OnGenericMotionListener() {
|
||||
private void mapAxis(final String button, final TextView output) {
|
||||
getView().setOnGenericMotionListener(new View.OnGenericMotionListener() {
|
||||
@Override
|
||||
public boolean onGenericMotion(View view, MotionEvent event) {
|
||||
if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) ==
|
||||
InputDevice.SOURCE_JOYSTICK &&
|
||||
event.getAction() == MotionEvent.ACTION_MOVE) {
|
||||
mPrefs.edit().putInt(axis + player, event.getActionIndex ()).apply();
|
||||
isMapping = false;
|
||||
int axis = -1;
|
||||
if (event.getAxisValue(MotionEvent.AXIS_X) != 0) {
|
||||
axis = MotionEvent.AXIS_X;
|
||||
}
|
||||
if (event.getAxisValue(MotionEvent.AXIS_Y) != 0) {
|
||||
axis = MotionEvent.AXIS_Y;
|
||||
}
|
||||
if (event.getAxisValue(MotionEvent.AXIS_RX) != 0) {
|
||||
axis = MotionEvent.AXIS_RX;
|
||||
}
|
||||
if (event.getAxisValue(MotionEvent.AXIS_RY) != 0) {
|
||||
axis = MotionEvent.AXIS_RY;
|
||||
}
|
||||
if (event.getAxisValue(MotionEvent.AXIS_HAT_X) != 0) {
|
||||
axis = MotionEvent.AXIS_HAT_X;
|
||||
}
|
||||
if (event.getAxisValue(MotionEvent.AXIS_HAT_Y) != 0) {
|
||||
axis = MotionEvent.AXIS_HAT_Y;
|
||||
}
|
||||
mPrefs.edit().putInt(button + player, axis).apply();
|
||||
getView().setOnGenericMotionListener(null);
|
||||
getKeyCode(button, output);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -537,7 +582,6 @@ public class InputModFragment extends Fragment {
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateController(String player) {
|
||||
switchJoystickDpadEnabled.setChecked(mPrefs.getBoolean(
|
||||
|
@ -558,6 +602,8 @@ public class InputModFragment extends Fragment {
|
|||
getKeyCode(Gamepad.pref_dpad_down, dpad_down_text);
|
||||
getKeyCode(Gamepad.pref_dpad_left, dpad_left_text);
|
||||
getKeyCode(Gamepad.pref_dpad_right, dpad_right_text);
|
||||
getKeyCode(Gamepad.pref_axis_x, joystick_x_text);
|
||||
getKeyCode(Gamepad.pref_axis_y, joystick_y_text);
|
||||
getKeyCode(Gamepad.pref_button_start, start_button_text);
|
||||
getKeyCode(Gamepad.pref_button_select, select_button_text);
|
||||
}
|
||||
|
|
|
@ -47,6 +47,9 @@ public class Gamepad {
|
|||
public static final String pref_dpad_left = "dpad_left";
|
||||
public static final String pref_dpad_right = "dpad_right";
|
||||
|
||||
public static final String pref_axis_x = "x_axis";
|
||||
public static final String pref_axis_y = "y_axis";
|
||||
|
||||
public static final String pref_button_start = "start_button";
|
||||
public static final String pref_button_select = "select_button";
|
||||
|
||||
|
|
|
@ -111,7 +111,6 @@
|
|||
</LinearLayout>
|
||||
</TableRow>
|
||||
|
||||
|
||||
<TableRow
|
||||
android:layout_marginTop="25dp"
|
||||
android:gravity="center_vertical" >
|
||||
|
@ -456,7 +455,7 @@
|
|||
android:layout_marginLeft="4dp"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="DPad Up" />
|
||||
android:text="@string/dpad_up" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -494,7 +493,7 @@
|
|||
android:layout_marginLeft="4dp"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="DPad Down" />
|
||||
android:text="@string/dpad_down" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -532,7 +531,7 @@
|
|||
android:layout_marginLeft="4dp"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="DPad Left" />
|
||||
android:text="@string/dpad_left" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -570,7 +569,7 @@
|
|||
android:layout_marginLeft="4dp"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="DPad Right" />
|
||||
android:text="@string/dpad_right" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -597,6 +596,82 @@
|
|||
</LinearLayout>
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_marginTop="25dp"
|
||||
android:gravity="center_vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/joystick_x_key"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="@string/joystick_x" />
|
||||
|
||||
<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_x_edit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="6"
|
||||
android:text="@string/select" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/remove_joystick_x"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="6"
|
||||
android:text="@string/remove" />
|
||||
</LinearLayout>
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_marginTop="25dp"
|
||||
android:gravity="center_vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/joystick_y_key"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="@string/joystick_y" />
|
||||
|
||||
<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_y_edit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="6"
|
||||
android:text="@string/select" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/remove_joystick_y"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="6"
|
||||
android:text="@string/remove" />
|
||||
</LinearLayout>
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_marginTop="25dp"
|
||||
android:gravity="center_vertical" >
|
||||
|
@ -620,7 +695,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:ems="10"
|
||||
android:text="Start Button" />
|
||||
android:text="@string/start_button" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
@ -671,7 +746,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:ems="10"
|
||||
android:text="Select Button" />
|
||||
android:text="@string/select_button" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
@ -111,7 +111,6 @@
|
|||
</LinearLayout>
|
||||
</TableRow>
|
||||
|
||||
|
||||
<TableRow
|
||||
android:layout_marginTop="25dp"
|
||||
android:gravity="center_vertical" >
|
||||
|
@ -456,7 +455,7 @@
|
|||
android:layout_marginLeft="4dp"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="DPad Up" />
|
||||
android:text="@string/dpad_up" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -494,7 +493,7 @@
|
|||
android:layout_marginLeft="4dp"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="DPad Down" />
|
||||
android:text="@string/dpad_down" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -532,7 +531,7 @@
|
|||
android:layout_marginLeft="4dp"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="DPad Left" />
|
||||
android:text="@string/dpad_left" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -570,7 +569,7 @@
|
|||
android:layout_marginLeft="4dp"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="DPad Right" />
|
||||
android:text="@string/dpad_right" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -597,6 +596,82 @@
|
|||
</LinearLayout>
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_marginTop="25dp"
|
||||
android:gravity="center_vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/joystick_x_key"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="@string/joystick_x" />
|
||||
|
||||
<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_x_edit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="6"
|
||||
android:text="@string/select" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/remove_joystick_x"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="6"
|
||||
android:text="@string/remove" />
|
||||
</LinearLayout>
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_marginTop="25dp"
|
||||
android:gravity="center_vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/joystick_y_key"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:text="@string/joystick_y" />
|
||||
|
||||
<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_y_edit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="6"
|
||||
android:text="@string/select" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/remove_joystick_y"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="6"
|
||||
android:text="@string/remove" />
|
||||
</LinearLayout>
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_marginTop="25dp"
|
||||
android:gravity="center_vertical" >
|
||||
|
@ -620,7 +695,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:ems="10"
|
||||
android:text="Start Button" />
|
||||
android:text="@string/start_button" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
@ -671,7 +746,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:ems="10"
|
||||
android:text="Select Button" />
|
||||
android:text="@string/select_button" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
@ -99,6 +99,15 @@
|
|||
<string name="enable_microphone">Enable Microphone(s)</string>
|
||||
<string name="controller_1_vmu">Includes 2 VMUs (or 1 VMU / 1 Mic)</string>
|
||||
|
||||
<string name="dpad_up">D-Pad Up</string>
|
||||
<string name="dpad_down">D-Pad Down</string>
|
||||
<string name="dpad_left">D-Pad Left</string>
|
||||
<string name="dpad_right">D-Pad Right</string>
|
||||
<string name="joystick_x">JS X Axis</string>
|
||||
<string name="joystick_y">JS Y Axis</string>
|
||||
<string name="start_button">Start Button</string>
|
||||
<string name="select_button">Select Button</string>
|
||||
|
||||
<string name="customize_physical_controls">Customize Physical Controls</string>
|
||||
<string name="map_keycode_title">Modify Controller</string>
|
||||
<string name="map_keycode_message">Press the new controller button for %1$s</string>
|
||||
|
|
Loading…
Reference in New Issue