mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-23 14:25:37 +00:00
Android: Support binding volume buttons
This commit is contained in:
parent
37f9f118c4
commit
a27f220f79
|
@ -44,8 +44,8 @@ private:
|
||||||
enum : u32
|
enum : u32
|
||||||
{
|
{
|
||||||
NUM_CONTROLLERS = 1,
|
NUM_CONTROLLERS = 1,
|
||||||
NUM_AXISES = 10,
|
NUM_AXISES = 12,
|
||||||
NUM_BUTTONS = 18
|
NUM_BUTTONS = 23
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ControllerData
|
struct ControllerData
|
||||||
|
|
|
@ -75,6 +75,10 @@ public class EmulationSurfaceView extends SurfaceView {
|
||||||
KeyEvent.KEYCODE_BUTTON_R2, // 16
|
KeyEvent.KEYCODE_BUTTON_R2, // 16
|
||||||
KeyEvent.KEYCODE_BUTTON_C, // 17
|
KeyEvent.KEYCODE_BUTTON_C, // 17
|
||||||
KeyEvent.KEYCODE_BUTTON_Z, // 18
|
KeyEvent.KEYCODE_BUTTON_Z, // 18
|
||||||
|
KeyEvent.KEYCODE_VOLUME_DOWN, // 19
|
||||||
|
KeyEvent.KEYCODE_VOLUME_UP, // 20
|
||||||
|
KeyEvent.KEYCODE_MENU, // 21
|
||||||
|
KeyEvent.KEYCODE_POWER, // 22
|
||||||
};
|
};
|
||||||
private static final int[] axisCodes = new int[]{
|
private static final int[] axisCodes = new int[]{
|
||||||
MotionEvent.AXIS_X, // 0/LeftX
|
MotionEvent.AXIS_X, // 0/LeftX
|
||||||
|
@ -87,6 +91,8 @@ public class EmulationSurfaceView extends SurfaceView {
|
||||||
MotionEvent.AXIS_RY, // 7
|
MotionEvent.AXIS_RY, // 7
|
||||||
MotionEvent.AXIS_HAT_X, // 8
|
MotionEvent.AXIS_HAT_X, // 8
|
||||||
MotionEvent.AXIS_HAT_Y, // 9
|
MotionEvent.AXIS_HAT_Y, // 9
|
||||||
|
MotionEvent.AXIS_GAS, // 10
|
||||||
|
MotionEvent.AXIS_BRAKE, // 11
|
||||||
};
|
};
|
||||||
|
|
||||||
public static int getButtonIndexForKeyCode(int keyCode) {
|
public static int getButtonIndexForKeyCode(int keyCode) {
|
||||||
|
@ -161,14 +167,17 @@ public class EmulationSurfaceView extends SurfaceView {
|
||||||
private ArrayList<ButtonMapping> mControllerKeyMapping;
|
private ArrayList<ButtonMapping> mControllerKeyMapping;
|
||||||
private ArrayList<AxisMapping> mControllerAxisMapping;
|
private ArrayList<AxisMapping> mControllerAxisMapping;
|
||||||
|
|
||||||
private boolean handleControllerKey(int deviceId, int keyCode, boolean pressed) {
|
private boolean handleControllerKey(int deviceId, int keyCode, int repeatCount, boolean pressed) {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
for (ButtonMapping mapping : mControllerKeyMapping) {
|
for (ButtonMapping mapping : mControllerKeyMapping) {
|
||||||
if (mapping.deviceId != deviceId || mapping.deviceAxisOrButton != keyCode)
|
if (mapping.deviceId != deviceId || mapping.deviceAxisOrButton != keyCode)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
AndroidHostInterface.getInstance().handleControllerButtonEvent(0, mapping.buttonMapping, pressed);
|
if (repeatCount == 0) {
|
||||||
Log.d("EmulationSurfaceView", String.format("handleControllerKey %d -> %d %d", keyCode, mapping.buttonMapping, pressed ? 1 : 0));
|
AndroidHostInterface.getInstance().handleControllerButtonEvent(0, mapping.buttonMapping, pressed);
|
||||||
|
Log.d("EmulationSurfaceView", String.format("handleControllerKey %d -> %d %d", keyCode, mapping.buttonMapping, pressed ? 1 : 0));
|
||||||
|
}
|
||||||
|
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,24 +186,26 @@ public class EmulationSurfaceView extends SurfaceView {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
if (!isDPadOrButtonEvent(event) || isExternalKeyCode(keyCode))
|
if (!isDPadOrButtonEvent(event))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (event.getRepeatCount() == 0)
|
if (handleControllerKey(event.getDeviceId(), keyCode, event.getRepeatCount(), true))
|
||||||
handleControllerKey(event.getDeviceId(), keyCode, true);
|
return true;
|
||||||
|
|
||||||
return true;
|
// eat non-external button events anyway
|
||||||
|
return !isExternalKeyCode(keyCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||||
if (!isDPadOrButtonEvent(event) || isExternalKeyCode(keyCode))
|
if (!isDPadOrButtonEvent(event))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (event.getRepeatCount() == 0)
|
if (handleControllerKey(event.getDeviceId(), keyCode, 0, false))
|
||||||
handleControllerKey(event.getDeviceId(), keyCode, false);
|
return true;
|
||||||
|
|
||||||
return true;
|
// eat non-external button events anyway
|
||||||
|
return !isExternalKeyCode(keyCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue