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.setInputType(InputType.TYPE_NULL | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
editText.setSingleLine(false);
editText.setMinLines(10);
builder.setView(editText);
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);
break;
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;
case "R1":
doAutoBindingButton(buttonName, new int[]{KeyEvent.KEYCODE_BUTTON_R1}, null);
break;
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;
case "L3":
doAutoBindingButton(buttonName, new int[]{KeyEvent.KEYCODE_BUTTON_THUMBL}, null);
@ -262,10 +261,10 @@ public class ControllerAutoMapper {
doAutoBindingAxis(axisName, new int[]{MotionEvent.AXIS_Y});
break;
case "RightX":
doAutoBindingAxis(axisName, new int[]{MotionEvent.AXIS_Z, MotionEvent.AXIS_RX});
doAutoBindingAxis(axisName, new int[]{MotionEvent.AXIS_RX, MotionEvent.AXIS_Z});
break;
case "RightY":
doAutoBindingAxis(axisName, new int[]{MotionEvent.AXIS_RZ, MotionEvent.AXIS_RY});
doAutoBindingAxis(axisName, new int[]{MotionEvent.AXIS_RY, MotionEvent.AXIS_RZ});
break;
default:
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.");
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.KeyEvent;
import android.view.MotionEvent;
import android.widget.Toast;
import androidx.annotation.NonNull;
@ -72,16 +73,24 @@ public class ControllerBindingDialog extends AlertDialog {
@Override
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);
}
if (mType == ControllerBindingPreference.Type.BUTTON)
mCurrentBinding = String.format("%s/Button%d", event.getDevice().getDescriptor(), event.getKeyCode());
else if (mType == ControllerBindingPreference.Type.VIBRATION)
mCurrentBinding = event.getDevice().getDescriptor();
else
if (mType == ControllerBindingPreference.Type.BUTTON) {
mCurrentBinding = String.format("%s/Button%d", device.getDescriptor(), event.getKeyCode());
} else if (mType == ControllerBindingPreference.Type.VIBRATION) {
if (device.getVibrator() == null || !device.getVibrator().hasVibrator()) {
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);
}
updateMessage();
updateBinding();
@ -135,8 +144,9 @@ public class ControllerBindingDialog extends AlertDialog {
for (int axisIndex = 0; axisIndex < motionEventList.size(); axisIndex++) {
final int axisCode = motionEventList.get(axisIndex).getAxis();
final float newValue = event.getAxisValue(axisCode);
if (Math.abs(newValue - axisValues[axisIndex]) >= DETECT_THRESHOLD) {
setAxisCode(event.getDevice(), axisCode, newValue >= 0.0f);
final float delta = newValue - axisValues[axisIndex];
if (Math.abs(delta) >= DETECT_THRESHOLD) {
setAxisCode(event.getDevice(), axisCode, delta >= 0.0f);
break;
}
}

View File

@ -10,7 +10,7 @@ import androidx.annotation.Nullable;
import androidx.fragment.app.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;