Android: Minor binding improvements

- Auto bind vibration when supported.
 - Fix automatic mapping of L2/R2 for XBox Controller.
This commit is contained in:
Connor McLaughlin 2021-03-21 15:39:22 +10:00
parent da7fa835fe
commit 237c0a01b6
4 changed files with 30 additions and 15 deletions

View file

@ -169,7 +169,6 @@ public class ControllerAutoMapper {
editText.setText(log.toString()); editText.setText(log.toString());
editText.setInputType(InputType.TYPE_NULL | InputType.TYPE_TEXT_FLAG_MULTI_LINE); editText.setInputType(InputType.TYPE_NULL | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
editText.setSingleLine(false); editText.setSingleLine(false);
editText.setMinLines(10);
builder.setView(editText); builder.setView(editText);
builder.setPositiveButton(R.string.main_activity_ok, (dialog, which) -> dialog.dismiss()); builder.setPositiveButton(R.string.main_activity_ok, (dialog, which) -> dialog.dismiss());
@ -222,13 +221,13 @@ public class ControllerAutoMapper {
doAutoBindingButton(buttonName, new int[]{KeyEvent.KEYCODE_BUTTON_L1}, null); doAutoBindingButton(buttonName, new int[]{KeyEvent.KEYCODE_BUTTON_L1}, null);
break; break;
case "L2": case "L2":
doAutoBindingButton(buttonName, new int[]{KeyEvent.KEYCODE_BUTTON_L2}, new int[][]{{MotionEvent.AXIS_LTRIGGER, 1}, {MotionEvent.AXIS_BRAKE, 1}}); doAutoBindingButton(buttonName, new int[]{KeyEvent.KEYCODE_BUTTON_L2}, new int[][]{{MotionEvent.AXIS_LTRIGGER, 1}, {MotionEvent.AXIS_Z, 1}, {MotionEvent.AXIS_BRAKE, 1}});
break; break;
case "R1": case "R1":
doAutoBindingButton(buttonName, new int[]{KeyEvent.KEYCODE_BUTTON_R1}, null); doAutoBindingButton(buttonName, new int[]{KeyEvent.KEYCODE_BUTTON_R1}, null);
break; break;
case "R2": case "R2":
doAutoBindingButton(buttonName, new int[]{KeyEvent.KEYCODE_BUTTON_R2}, new int[][]{{MotionEvent.AXIS_RTRIGGER, 1}, {MotionEvent.AXIS_GAS, 1}}); doAutoBindingButton(buttonName, new int[]{KeyEvent.KEYCODE_BUTTON_R2}, new int[][]{{MotionEvent.AXIS_RTRIGGER, 1}, {MotionEvent.AXIS_RZ, 1}, {MotionEvent.AXIS_GAS, 1}});
break; break;
case "L3": case "L3":
doAutoBindingButton(buttonName, new int[]{KeyEvent.KEYCODE_BUTTON_THUMBL}, null); doAutoBindingButton(buttonName, new int[]{KeyEvent.KEYCODE_BUTTON_THUMBL}, null);
@ -262,10 +261,10 @@ public class ControllerAutoMapper {
doAutoBindingAxis(axisName, new int[]{MotionEvent.AXIS_Y}); doAutoBindingAxis(axisName, new int[]{MotionEvent.AXIS_Y});
break; break;
case "RightX": case "RightX":
doAutoBindingAxis(axisName, new int[]{MotionEvent.AXIS_Z, MotionEvent.AXIS_RX}); doAutoBindingAxis(axisName, new int[]{MotionEvent.AXIS_RX, MotionEvent.AXIS_Z});
break; break;
case "RightY": case "RightY":
doAutoBindingAxis(axisName, new int[]{MotionEvent.AXIS_RZ, MotionEvent.AXIS_RY}); doAutoBindingAxis(axisName, new int[]{MotionEvent.AXIS_RY, MotionEvent.AXIS_RZ});
break; break;
default: default:
log("Axis '%s' not supported by auto mapping.", axisName); log("Axis '%s' not supported by auto mapping.", axisName);
@ -286,5 +285,10 @@ public class ControllerAutoMapper {
log("Selected device has no vibrator, cannot bind vibration."); log("Selected device has no vibrator, cannot bind vibration.");
return; return;
} }
log("Binding vibration to device '%s'.", device.getDescriptor());
final String key = String.format("%sRumble", keyBase);
editor.putString(key, device.getDescriptor());
} }
} }

View file

@ -9,6 +9,7 @@ import android.util.ArraySet;
import android.view.InputDevice; import android.view.InputDevice;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -72,16 +73,24 @@ public class ControllerBindingDialog extends AlertDialog {
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
if (!EmulationSurfaceView.isBindableDevice(event.getDevice()) || !EmulationSurfaceView.isBindableKeyEvent(event)) { final InputDevice device = event.getDevice();
if (!EmulationSurfaceView.isBindableDevice(device) || !EmulationSurfaceView.isBindableKeyEvent(event)) {
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
} }
if (mType == ControllerBindingPreference.Type.BUTTON) if (mType == ControllerBindingPreference.Type.BUTTON) {
mCurrentBinding = String.format("%s/Button%d", event.getDevice().getDescriptor(), event.getKeyCode()); mCurrentBinding = String.format("%s/Button%d", device.getDescriptor(), event.getKeyCode());
else if (mType == ControllerBindingPreference.Type.VIBRATION) } else if (mType == ControllerBindingPreference.Type.VIBRATION) {
mCurrentBinding = event.getDevice().getDescriptor(); if (device.getVibrator() == null || !device.getVibrator().hasVibrator()) {
else Toast.makeText(getContext(), getContext().getString(R.string.controller_settings_vibration_unsupported), Toast.LENGTH_LONG).show();
dismiss();
return true;
}
mCurrentBinding = device.getDescriptor();
} else {
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
}
updateMessage(); updateMessage();
updateBinding(); updateBinding();
@ -135,8 +144,9 @@ public class ControllerBindingDialog extends AlertDialog {
for (int axisIndex = 0; axisIndex < motionEventList.size(); axisIndex++) { for (int axisIndex = 0; axisIndex < motionEventList.size(); axisIndex++) {
final int axisCode = motionEventList.get(axisIndex).getAxis(); final int axisCode = motionEventList.get(axisIndex).getAxis();
final float newValue = event.getAxisValue(axisCode); final float newValue = event.getAxisValue(axisCode);
if (Math.abs(newValue - axisValues[axisIndex]) >= DETECT_THRESHOLD) { final float delta = newValue - axisValues[axisIndex];
setAxisCode(event.getDevice(), axisCode, newValue >= 0.0f); if (Math.abs(delta) >= DETECT_THRESHOLD) {
setAxisCode(event.getDevice(), axisCode, delta >= 0.0f);
break; break;
} }
} }

View file

@ -10,7 +10,7 @@ import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
public class EmptyGameListFragment extends Fragment { public class EmptyGameListFragment extends Fragment {
private static final String SUPPORTED_FORMATS_STRING = "bin/cue, iso, img, ecm, mds, chd, pbp"; private static final String SUPPORTED_FORMATS_STRING = ".cue, .iso, .img, .ecm, .mds, .chd, .pbp";
private MainActivity parent; private MainActivity parent;

View file

@ -312,6 +312,7 @@
<string name="memory_card_editor_import_card_failed">Failed to import card \'%s\'. It may not be a supported format.</string> <string name="memory_card_editor_import_card_failed">Failed to import card \'%s\'. It may not be a supported format.</string>
<string name="memory_card_editor_import_card_success">Imported card \'%s\'.</string> <string name="memory_card_editor_import_card_success">Imported card \'%s\'.</string>
<string name="menu_game_list_entry_choose_cover_image">Choose Cover Image</string> <string name="menu_game_list_entry_choose_cover_image">Choose Cover Image</string>
<string name="controller_settings_vibration_unsupported">The selected device does not support vibration.</string>
<string name="controller_settings_automatic_mapping">Perform Automatic Mapping</string> <string name="controller_settings_automatic_mapping">Perform Automatic Mapping</string>
<string name="controller_settings_summary_automatic_mapping">Attempts to automatically bind all buttons/axes to a connected controller.</string> <string name="controller_settings_summary_automatic_mapping">Attempts to automatically bind all buttons/axes to a connected controller.</string>
<string name="controller_settings_clear_controller_bindings">Clear Bindings</string> <string name="controller_settings_clear_controller_bindings">Clear Bindings</string>
@ -326,5 +327,5 @@
<string name="main_activity_empty_game_list_add_directory">Add Game Directory</string> <string name="main_activity_empty_game_list_add_directory">Add Game Directory</string>
<string name="main_activity_empty_game_list_start_file">Start File</string> <string name="main_activity_empty_game_list_start_file">Start File</string>
<string name="update_notes_title">Update Notes</string> <string name="update_notes_title">Update Notes</string>
<string name="update_notes_message_version_controller_update">This DuckStation update includes support for multiple controllers, and binding devices such as keyboards/volume buttons.\n\nYou must re-bind your controllers, otherwise they will no longer function. Do you want to do this now?</string> <string name="update_notes_message_version_controller_update">This DuckStation update includes support for multiple controllers with vibration, and binding devices such as keyboards/volume buttons.\n\nYou must re-bind your controllers, otherwise they will no longer function. Do you want to do this now?</string>
</resources> </resources>