Add option to remove specific custom button assignments

This commit is contained in:
TwistedUmbrella 2014-01-24 12:01:53 -05:00
parent 4af2a566f9
commit dd1d1ddcaf
2 changed files with 189 additions and 0 deletions

View File

@ -64,6 +64,14 @@
android:layout_weight="1"
android:ems="8"
android:text="@string/launch_editor" />
<Button
android:id="@+id/remove_a_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/remove" />
</LinearLayout>
</TableRow>
@ -91,6 +99,14 @@
android:layout_weight="1"
android:ems="8"
android:text="@string/launch_editor" />
<Button
android:id="@+id/remove_b_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/remove" />
</LinearLayout>
</TableRow>
@ -118,6 +134,14 @@
android:layout_weight="1"
android:ems="8"
android:text="@string/launch_editor" />
<Button
android:id="@+id/remove_x_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/remove" />
</LinearLayout>
</TableRow>
@ -145,6 +169,14 @@
android:layout_weight="1"
android:ems="8"
android:text="@string/launch_editor" />
<Button
android:id="@+id/remove_y_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/remove" />
</LinearLayout>
</TableRow>
@ -172,6 +204,14 @@
android:layout_weight="1"
android:ems="8"
android:text="@string/launch_editor" />
<Button
android:id="@+id/remove_l_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/remove" />
</LinearLayout>
</TableRow>
@ -199,6 +239,14 @@
android:layout_weight="1"
android:ems="8"
android:text="@string/launch_editor" />
<Button
android:id="@+id/remove_r_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/remove" />
</LinearLayout>
</TableRow>
@ -226,6 +274,14 @@
android:layout_weight="1"
android:ems="8"
android:text="@string/launch_editor" />
<Button
android:id="@+id/remove_joystick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/remove" />
</LinearLayout>
</TableRow>
@ -253,6 +309,14 @@
android:layout_weight="1"
android:ems="8"
android:text="@string/launch_editor" />
<Button
android:id="@+id/remove_dpad_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/remove" />
</LinearLayout>
</TableRow>
@ -280,6 +344,14 @@
android:layout_weight="1"
android:ems="8"
android:text="@string/launch_editor" />
<Button
android:id="@+id/remove_dpad_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/remove" />
</LinearLayout>
</TableRow>
@ -307,6 +379,14 @@
android:layout_weight="1"
android:ems="8"
android:text="@string/launch_editor" />
<Button
android:id="@+id/remove_dpad_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/remove" />
</LinearLayout>
</TableRow>
@ -334,6 +414,14 @@
android:layout_weight="1"
android:ems="8"
android:text="@string/launch_editor" />
<Button
android:id="@+id/remove_dpad_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/remove" />
</LinearLayout>
</TableRow>
@ -361,6 +449,14 @@
android:layout_weight="1"
android:ems="8"
android:text="@string/launch_editor" />
<Button
android:id="@+id/remove_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/remove" />
</LinearLayout>
</TableRow>
</TableLayout>

View File

@ -75,6 +75,13 @@ public class InputModFragment extends Fragment {
mapKeyCode("a_button", a_button_text);
}
});
Button a_remove = (Button) getView()
.findViewById(R.id.remove_a_button);
a_remove.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
remKeyCode("a_button", a_button_text);
}
});
final TextView b_button_text = (TextView) getView()
.findViewById(R.id.b_button_key);
@ -86,6 +93,13 @@ public class InputModFragment extends Fragment {
mapKeyCode("b_button", b_button_text);
}
});
Button b_remove = (Button) getView()
.findViewById(R.id.remove_b_button);
b_remove.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
remKeyCode("b_button", b_button_text);
}
});
final TextView x_button_text = (TextView) getView()
.findViewById(R.id.x_button_key);
@ -97,6 +111,13 @@ public class InputModFragment extends Fragment {
mapKeyCode("x_button", x_button_text);
}
});
Button x_remove = (Button) getView()
.findViewById(R.id.remove_x_button);
x_remove.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
remKeyCode("x_button", x_button_text);
}
});
final TextView y_button_text = (TextView) getView()
.findViewById(R.id.y_button_key);
@ -108,6 +129,13 @@ public class InputModFragment extends Fragment {
mapKeyCode("y_button", y_button_text);
}
});
Button y_remove = (Button) getView()
.findViewById(R.id.remove_y_button);
y_remove.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
remKeyCode("y_button", y_button_text);
}
});
final TextView l_button_text = (TextView) getView()
.findViewById(R.id.l_button_key);
@ -119,6 +147,13 @@ public class InputModFragment extends Fragment {
mapKeyCode("l_button", l_button_text);
}
});
Button l_remove = (Button) getView()
.findViewById(R.id.remove_l_button);
l_remove.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
remKeyCode("l_button", l_button_text);
}
});
final TextView r_button_text = (TextView) getView()
.findViewById(R.id.r_button_key);
@ -130,6 +165,13 @@ public class InputModFragment extends Fragment {
mapKeyCode("r_button", r_button_text);
}
});
Button r_remove = (Button) getView()
.findViewById(R.id.remove_r_button);
r_remove.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
remKeyCode("r_button", r_button_text);
}
});
final TextView joystick_text = (TextView) getView()
.findViewById(R.id.joystick_key);
@ -141,6 +183,13 @@ public class InputModFragment extends Fragment {
mapKeyCode("joystick", joystick_text);
}
});
Button joystick_remove = (Button) getView()
.findViewById(R.id.remove_joystick);
joystick_remove.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
remKeyCode("joystick", joystick_text);
}
});
joystick.setEnabled(false);
mPrefs.edit().remove("joystick").commit();
// Still needs better support for identifying the entire stick
@ -155,6 +204,13 @@ public class InputModFragment extends Fragment {
mapKeyCode("dpad_up", dpad_up_text);
}
});
Button up_remove = (Button) getView()
.findViewById(R.id.remove_dpad_up);
up_remove.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
remKeyCode("dpad_up", dpad_up_text);
}
});
final TextView dpad_down_text = (TextView) getView()
.findViewById(R.id.dpad_down_key);
@ -166,6 +222,13 @@ public class InputModFragment extends Fragment {
mapKeyCode("dpad_down", dpad_down_text);
}
});
Button down_remove = (Button) getView()
.findViewById(R.id.remove_dpad_down);
down_remove.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
remKeyCode("dpad_down", dpad_down_text);
}
});
final TextView dpad_left_text = (TextView) getView()
.findViewById(R.id.dpad_left_key);
@ -177,6 +240,13 @@ public class InputModFragment extends Fragment {
mapKeyCode("dpad_left", dpad_left_text);
}
});
Button left_remove = (Button) getView()
.findViewById(R.id.remove_dpad_left);
left_remove.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
remKeyCode("dpad_left", dpad_left_text);
}
});
final TextView dpad_right_text = (TextView) getView()
.findViewById(R.id.dpad_right_key);
@ -188,6 +258,13 @@ public class InputModFragment extends Fragment {
mapKeyCode("dpad_right", dpad_right_text);
}
});
Button right_remove = (Button) getView()
.findViewById(R.id.remove_dpad_right);
right_remove.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
remKeyCode("dpad_right", dpad_right_text);
}
});
final TextView start_button_text = (TextView) getView()
.findViewById(R.id.start_button_key);
@ -199,6 +276,13 @@ public class InputModFragment extends Fragment {
mapKeyCode("start_button", start_button_text);
}
});
Button start_remove = (Button) getView()
.findViewById(R.id.remove_start);
start_remove.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
remKeyCode("start_button", start_button_text);
}
});
} else {
@ -251,6 +335,15 @@ public class InputModFragment extends Fragment {
builder.show();
}
private void remKeyCode(final String button, final TextView output) {
mPrefs.edit().remove(button).commit();
String label = output.getText().toString();
if (label.contains(":")) {
label = label.substring(0, label.indexOf(":"));
}
output.setText(label);
}
private int mapButton(int keyCode, KeyEvent event, String button) {
if (keyCode == KeyEvent.KEYCODE_BACK)
return -1;