Commit 3904f8a2 authored by TwistedUmbrella's avatar TwistedUmbrella
Browse files

Add visual counterpart to assigning unidentified controller

parent 0c45cc7d
......@@ -40,7 +40,7 @@
<string name="select">Select</string>
<string name="remove">Remove</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 %1$s to assign to port</string>
<string name="controller_already_in_use">This controller is already in use!</string>
<string name="modified_layout">Enable Custom Key Layout</string>
......
......@@ -275,13 +275,15 @@ public class InputFragment extends Fragment {
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
builder.setTitle(getString(R.string.select_controller_title));
builder.setMessage(getString(R.string.select_controller_message) + " " + String.valueOf(listenForButton) + ".");
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
listenForButton = 0;
dialog.dismiss();
}
});
builder.setMessage(getString(R.string.select_controller_message,
String.valueOf(listenForButton)));
builder.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
listenForButton = 0;
dialog.dismiss();
}
});
builder.setOnKeyListener(new Dialog.OnKeyListener() {
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
return mapDevice(keyCode, event);
......
......@@ -56,15 +56,16 @@ public class InputModFragment extends Fragment {
public void onViewCreated(View view, Bundle savedInstanceState) {
parentActivity = getActivity();
mPrefs = PreferenceManager
.getDefaultSharedPreferences(parentActivity);
String[] controllers = parentActivity.getResources().getStringArray(R.array.controllers);
mPrefs = PreferenceManager.getDefaultSharedPreferences(parentActivity);
String[] controllers = parentActivity.getResources().getStringArray(
R.array.controllers);
Spinner player_spnr = (Spinner) getView().findViewById(
R.id.player_spinner);
ArrayAdapter<String> playerAdapter = new ArrayAdapter<String>(
parentActivity, android.R.layout.simple_spinner_item, controllers);
parentActivity, android.R.layout.simple_spinner_item,
controllers);
playerAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
player_spnr.setAdapter(playerAdapter);
......@@ -74,275 +75,276 @@ public class InputModFragment extends Fragment {
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
String selection = parent.getItemAtPosition(pos).toString();
player = selection.substring(selection.lastIndexOf(" "), selection.length());
player = selection.substring(selection.lastIndexOf(" "),
selection.length());
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
OnCheckedChangeListener modified_layout = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
mPrefs.edit()
.putBoolean("modified_key_layout", isChecked)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
selectController();
}
mPrefs.edit().putBoolean("modified_key_layout", isChecked)
.commit();
}
};
switchModifiedLayoutEnabled = (Switch) getView().findViewById(
R.id.switchModifiedLayoutEnabled);
boolean layout = mPrefs.getBoolean(
"modified_key_layout", false);
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) {
ImageView a_button_icon = (ImageView) getView()
.findViewById(R.id.a_button_icon);
ImageView a_button_icon = (ImageView) getView().findViewById(
R.id.a_button_icon);
a_button_icon.setImageDrawable(getButtonImage(448 / sS, 0));
final TextView a_button_text = (TextView) getView()
.findViewById(R.id.a_button_key);
Button a_button = (Button) getView()
.findViewById(R.id.a_button_edit);
final TextView a_button_text = (TextView) getView().findViewById(
R.id.a_button_key);
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);
}
public void onClick(View v) {
mapKeyCode("a_button", a_button_text);
}
});
Button a_remove = (Button) getView()
.findViewById(R.id.remove_a_button);
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);
}
public void onClick(View v) {
remKeyCode("a_button", a_button_text);
}
});
ImageView b_button_icon = (ImageView) getView()
.findViewById(R.id.b_button_icon);
ImageView b_button_icon = (ImageView) getView().findViewById(
R.id.b_button_icon);
b_button_icon.setImageDrawable(getButtonImage(384 / sS, 0));
final TextView b_button_text = (TextView) getView()
.findViewById(R.id.b_button_key);
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);
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);
}
public void onClick(View v) {
mapKeyCode("b_button", b_button_text);
}
});
Button b_remove = (Button) getView()
.findViewById(R.id.remove_b_button);
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);
}
public void onClick(View v) {
remKeyCode("b_button", b_button_text);
}
});
ImageView x_button_icon = (ImageView) getView()
.findViewById(R.id.x_button_icon);
ImageView x_button_icon = (ImageView) getView().findViewById(
R.id.x_button_icon);
x_button_icon.setImageDrawable(getButtonImage(256 / sS, 0));
final TextView x_button_text = (TextView) getView()
.findViewById(R.id.x_button_key);
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);
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);
}
public void onClick(View v) {
mapKeyCode("x_button", x_button_text);
}
});
Button x_remove = (Button) getView()
.findViewById(R.id.remove_x_button);
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);
}
public void onClick(View v) {
remKeyCode("x_button", x_button_text);
}
});
ImageView y_button_icon = (ImageView) getView()
.findViewById(R.id.y_button_icon);
ImageView y_button_icon = (ImageView) getView().findViewById(
R.id.y_button_icon);
y_button_icon.setImageDrawable(getButtonImage(320 / sS, 0));
final TextView y_button_text = (TextView) getView()
.findViewById(R.id.y_button_key);
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);
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);
}
public void onClick(View v) {
mapKeyCode("y_button", y_button_text);
}
});
Button y_remove = (Button) getView()
.findViewById(R.id.remove_y_button);
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);
}
public void onClick(View v) {
remKeyCode("y_button", y_button_text);
}
});
ImageView l_button_icon = (ImageView) getView()
.findViewById(R.id.l_button_icon);
ImageView l_button_icon = (ImageView) getView().findViewById(
R.id.l_button_icon);
l_button_icon.setImageDrawable(getButtonImage(78 / sS, 64 / sS));
final TextView l_button_text = (TextView) getView()
.findViewById(R.id.l_button_key);
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);
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);
}
public void onClick(View v) {
mapKeyCode("l_button", l_button_text);
}
});
Button l_remove = (Button) getView()
.findViewById(R.id.remove_l_button);
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);
}
public void onClick(View v) {
remKeyCode("l_button", l_button_text);
}
});
ImageView r_button_icon = (ImageView) getView()
.findViewById(R.id.r_button_icon);
ImageView r_button_icon = (ImageView) getView().findViewById(
R.id.r_button_icon);
r_button_icon.setImageDrawable(getButtonImage(162 / sS, 64 / sS));
final TextView r_button_text = (TextView) getView()
.findViewById(R.id.r_button_key);
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);
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);
}
public void onClick(View v) {
mapKeyCode("r_button", r_button_text);
}
});
Button r_remove = (Button) getView()
.findViewById(R.id.remove_r_button);
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);
}
public void onClick(View v) {
remKeyCode("r_button", r_button_text);
}
});
final TextView joystick_text = (TextView) getView()
.findViewById(R.id.joystick_key);
final TextView joystick_text = (TextView) getView().findViewById(
R.id.joystick_key);
getKeyCode("joystick", joystick_text);
Button joystick = (Button) getView()
.findViewById(R.id.joystick_edit);
Button joystick = (Button) getView().findViewById(
R.id.joystick_edit);
joystick.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mapKeyCode("joystick", joystick_text);
}
public void onClick(View v) {
mapKeyCode("joystick", joystick_text);
}
});
Button joystick_remove = (Button) getView()
.findViewById(R.id.remove_joystick);
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);
}
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
final TextView dpad_up_text = (TextView) getView()
.findViewById(R.id.dpad_up_key);
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);
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);
}
public void onClick(View v) {
mapKeyCode("dpad_up", dpad_up_text);
}
});
Button up_remove = (Button) getView()
.findViewById(R.id.remove_dpad_up);
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);
}
public void onClick(View v) {
remKeyCode("dpad_up", dpad_up_text);
}
});
final TextView dpad_down_text = (TextView) getView()
.findViewById(R.id.dpad_down_key);
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);
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);
}
public void onClick(View v) {
mapKeyCode("dpad_down", dpad_down_text);
}
});
Button down_remove = (Button) getView()
.findViewById(R.id.remove_dpad_down);
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);
}
public void onClick(View v) {
remKeyCode("dpad_down", dpad_down_text);
}
});
final TextView dpad_left_text = (TextView) getView()
.findViewById(R.id.dpad_left_key);
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);
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);
}
public void onClick(View v) {
mapKeyCode("dpad_left", dpad_left_text);
}
});
Button left_remove = (Button) getView()
.findViewById(R.id.remove_dpad_left);
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);
}
public void onClick(View v) {
remKeyCode("dpad_left", dpad_left_text);
}
});
final TextView dpad_right_text = (TextView) getView()
.findViewById(R.id.dpad_right_key);
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);
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);
}
public void onClick(View v) {
mapKeyCode("dpad_right", dpad_right_text);
}
});
Button right_remove = (Button) getView()
.findViewById(R.id.remove_dpad_right);
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);
}
public void onClick(View v) {
remKeyCode("dpad_right", dpad_right_text);
}
});
ImageView start_button_icon = (ImageView) getView()
.findViewById(R.id.start_button_icon);
ImageView start_button_icon = (ImageView) getView().findViewById(
R.id.start_button_icon);
start_button_icon.setImageDrawable(getButtonImage(0, 64 / sS));
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);
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);
}
public void onClick(View v) {
mapKeyCode("start_button", start_button_text);
}
});
Button start_remove = (Button) getView()
.findViewById(R.id.remove_start);
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);
}
public void onClick(View v) {
remKeyCode("start_button", start_button_text);
}
});
} else {
switchModifiedLayoutEnabled.setEnabled(false);
......@@ -360,8 +362,8 @@ public class InputModFragment extends Fragment {
bitmap = null;
Matrix matrix = new Matrix();
matrix.postScale(32, 32);
Bitmap resizedBitmap = Bitmap.createBitmap(image, x, y, 64 / sS, 64 / sS,
matrix, true);
Bitmap resizedBitmap = Bitmap.createBitmap(image, x, y, 64 / sS,
64 / sS, matrix, true);
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
image.recycle();
image = null;
......@@ -371,7 +373,7 @@ public class InputModFragment extends Fragment {
}
return parentActivity.getResources().getDrawable(R.drawable.input);
}
private void getKeyCode(final String button, final TextView output) {
int keyCode = mPrefs.getInt(button + player, -1);
if (keyCode != -1) {
......@@ -382,12 +384,36 @@ public class InputModFragment extends Fragment {
output.setText(label + ": " + String.valueOf(keyCode));
}
}
private void selectController() {
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
builder.setTitle(getString(R.string.select_controller_title));
builder.setMessage(getString(R.string.select_controller_message, String.valueOf(player)));
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) {
dialog.dismiss();
mPrefs.edit()
.putInt("controller" + player, event.getDeviceId());
return true;
}
});
builder.create();
builder.show();
}
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.setMessage(getString(R.string.map_keycode_message,
button.replace("_", " ")));
builder.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
......@@ -409,7 +435,7 @@ public class InputModFragment extends Fragment {
} else {
return false;
}