mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-20 11:33:06 +00:00
Fix Shield's hardware back button
This commit is contained in:
parent
ee6edd2404
commit
e1e4ccf318
@ -299,10 +299,6 @@ public class Game extends Activity implements SurfaceHolder.Callback, OnGenericM
|
||||
return modifier;
|
||||
}
|
||||
|
||||
private static boolean isSourceFlagSet(int sourcesFlags, int flag) {
|
||||
return (sourcesFlags & flag) == flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
InputDevice dev = event.getDevice();
|
||||
@ -310,16 +306,15 @@ public class Game extends Activity implements SurfaceHolder.Callback, OnGenericM
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
int source = dev.getSources();
|
||||
boolean handled = false;
|
||||
if (isSourceFlagSet(source, InputDevice.SOURCE_DPAD) ||
|
||||
isSourceFlagSet(source, InputDevice.SOURCE_GAMEPAD) ||
|
||||
isSourceFlagSet(source, InputDevice.SOURCE_JOYSTICK))
|
||||
{
|
||||
handled = controllerHandler.handleButtonDown(keyCode, event);
|
||||
// Pass-through virtual navigation keys
|
||||
if ((event.getFlags() & KeyEvent.FLAG_VIRTUAL_HARD_KEY) != 0) {
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
// Try the controller handler first
|
||||
boolean handled = controllerHandler.handleButtonDown(keyCode, event);
|
||||
if (!handled) {
|
||||
// Try the keyboard handler
|
||||
short translated = keybTranslator.translate(event.getKeyCode());
|
||||
if (translated == 0) {
|
||||
return super.onKeyDown(keyCode, event);
|
||||
@ -349,16 +344,15 @@ public class Game extends Activity implements SurfaceHolder.Callback, OnGenericM
|
||||
return super.onKeyUp(keyCode, event);
|
||||
}
|
||||
|
||||
int source = dev.getSources();
|
||||
boolean handled = false;
|
||||
if (isSourceFlagSet(source, InputDevice.SOURCE_DPAD) ||
|
||||
isSourceFlagSet(source, InputDevice.SOURCE_GAMEPAD) ||
|
||||
isSourceFlagSet(source, InputDevice.SOURCE_JOYSTICK))
|
||||
{
|
||||
handled = controllerHandler.handleButtonUp(keyCode, event);
|
||||
// Pass-through virtual navigation keys
|
||||
if ((event.getFlags() & KeyEvent.FLAG_VIRTUAL_HARD_KEY) != 0) {
|
||||
return super.onKeyUp(keyCode, event);
|
||||
}
|
||||
|
||||
// Try the controller handler first
|
||||
boolean handled = controllerHandler.handleButtonUp(keyCode, event);
|
||||
if (!handled) {
|
||||
// Try the keyboard handler
|
||||
short translated = keybTranslator.translate(event.getKeyCode());
|
||||
if (translated == 0) {
|
||||
return super.onKeyUp(keyCode, event);
|
||||
|
@ -148,10 +148,6 @@ public class ControllerHandler {
|
||||
}
|
||||
}
|
||||
|
||||
mapping.isDpad = (dev.getSources() & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD;
|
||||
mapping.isGamepad = (dev.getSources() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD ||
|
||||
(dev.getSources() & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK;
|
||||
|
||||
return mapping;
|
||||
}
|
||||
|
||||
@ -181,47 +177,6 @@ public class ControllerHandler {
|
||||
leftStickX, leftStickY, rightStickX, rightStickY);
|
||||
}
|
||||
|
||||
private static boolean isEventExpected(ControllerMapping mapping, int keyCode) {
|
||||
if (mapping.isDpad) {
|
||||
switch (keyCode) {
|
||||
case KeyEvent.KEYCODE_DPAD_LEFT:
|
||||
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
||||
case KeyEvent.KEYCODE_DPAD_CENTER:
|
||||
case KeyEvent.KEYCODE_DPAD_UP:
|
||||
case KeyEvent.KEYCODE_DPAD_DOWN:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (mapping.isGamepad) {
|
||||
switch (keyCode) {
|
||||
case KeyEvent.KEYCODE_BUTTON_MODE:
|
||||
case KeyEvent.KEYCODE_BUTTON_START:
|
||||
case KeyEvent.KEYCODE_MENU:
|
||||
case KeyEvent.KEYCODE_BACK:
|
||||
case KeyEvent.KEYCODE_BUTTON_SELECT:
|
||||
case KeyEvent.KEYCODE_DPAD_LEFT:
|
||||
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
||||
case KeyEvent.KEYCODE_DPAD_UP:
|
||||
case KeyEvent.KEYCODE_DPAD_DOWN:
|
||||
case KeyEvent.KEYCODE_BUTTON_B:
|
||||
case KeyEvent.KEYCODE_DPAD_CENTER:
|
||||
case KeyEvent.KEYCODE_BUTTON_A:
|
||||
case KeyEvent.KEYCODE_BUTTON_X:
|
||||
case KeyEvent.KEYCODE_BUTTON_Y:
|
||||
case KeyEvent.KEYCODE_BUTTON_L1:
|
||||
case KeyEvent.KEYCODE_BUTTON_R1:
|
||||
case KeyEvent.KEYCODE_BUTTON_THUMBL:
|
||||
case KeyEvent.KEYCODE_BUTTON_THUMBR:
|
||||
case KeyEvent.KEYCODE_BUTTON_L2:
|
||||
case KeyEvent.KEYCODE_BUTTON_R2:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static int handleRemapping(ControllerMapping mapping, int keyCode) {
|
||||
if (mapping.isDualShock4) {
|
||||
switch (keyCode) {
|
||||
@ -362,10 +317,6 @@ public class ControllerHandler {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!isEventExpected(mapping, keyCode)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the button hasn't been down long enough, sleep for a bit before sending the up event
|
||||
// This allows "instant" button presses (like OUYA's virtual menu button) to work. This
|
||||
// path should not be triggered during normal usage.
|
||||
@ -489,10 +440,6 @@ public class ControllerHandler {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!isEventExpected(mapping, keyCode)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (keyCode) {
|
||||
case KeyEvent.KEYCODE_BUTTON_MODE:
|
||||
inputMap |= ControllerPacket.SPECIAL_BUTTON_FLAG;
|
||||
@ -602,7 +549,5 @@ public class ControllerHandler {
|
||||
public float hatYDeadzone;
|
||||
|
||||
public boolean isDualShock4;
|
||||
public boolean isDpad;
|
||||
public boolean isGamepad;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user