mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 05:19:56 +00:00
Fix bug with device IDs on Android, causing the on-screen back button to be misinterpreted.
This commit is contained in:
parent
2cf9b3d51e
commit
527ec8eff2
@ -12,7 +12,7 @@ import android.view.MotionEvent;
|
||||
public class InputDeviceState {
|
||||
private static final String TAG = "InputDeviceState";
|
||||
|
||||
public static final int deviceId = NativeApp.DEVICE_ID_PAD_0;
|
||||
private int deviceId = NativeApp.DEVICE_ID_DEFAULT;
|
||||
|
||||
private InputDevice mDevice;
|
||||
private int[] mAxes;
|
||||
@ -27,6 +27,19 @@ public class InputDeviceState {
|
||||
}
|
||||
|
||||
public InputDeviceState(InputDevice device) {
|
||||
int sources = device.getSources();
|
||||
if ((sources & InputDevice.SOURCE_KEYBOARD) == InputDevice.SOURCE_KEYBOARD) {
|
||||
this.deviceId = NativeApp.DEVICE_ID_KEYBOARD;
|
||||
} else if ((sources & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) {
|
||||
this.deviceId = NativeApp.DEVICE_ID_MOUSE;
|
||||
} else if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD ||
|
||||
(sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK ||
|
||||
(sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD)) {
|
||||
this.deviceId = NativeApp.DEVICE_ID_PAD_0;
|
||||
} else {
|
||||
this.deviceId = NativeApp.DEVICE_ID_DEFAULT;
|
||||
}
|
||||
|
||||
mDevice = device;
|
||||
int numAxes = 0;
|
||||
for (MotionRange range : device.getMotionRanges()) {
|
||||
|
@ -1042,18 +1042,18 @@ public abstract class NativeActivity extends Activity {
|
||||
switch (keyCode) {
|
||||
case KeyEvent.KEYCODE_BACK:
|
||||
if (event.isAltPressed()) {
|
||||
NativeApp.keyDown(InputDeviceState.deviceId, 1004, repeat); // special custom keycode for the O button on Xperia Play
|
||||
NativeApp.keyDown(NativeApp.DEVICE_ID_PAD_0, 1004, repeat); // special custom keycode for the O button on Xperia Play
|
||||
} else if (NativeApp.isAtTopLevel()) {
|
||||
Log.i(TAG, "IsAtTopLevel returned true.");
|
||||
// Pass through the back event.
|
||||
return super.onKeyDown(keyCode, event);
|
||||
} else {
|
||||
NativeApp.keyDown(InputDeviceState.deviceId, keyCode, repeat);
|
||||
NativeApp.keyDown(NativeApp.DEVICE_ID_DEFAULT, keyCode, repeat);
|
||||
}
|
||||
return true;
|
||||
case KeyEvent.KEYCODE_MENU:
|
||||
case KeyEvent.KEYCODE_SEARCH:
|
||||
NativeApp.keyDown(InputDeviceState.deviceId, keyCode, repeat);
|
||||
NativeApp.keyDown(NativeApp.DEVICE_ID_DEFAULT, keyCode, repeat);
|
||||
return true;
|
||||
|
||||
case KeyEvent.KEYCODE_DPAD_UP:
|
||||
@ -1070,7 +1070,7 @@ public abstract class NativeActivity extends Activity {
|
||||
// send the rest of the keys through.
|
||||
// TODO: get rid of the three special cases above by adjusting the native side of the code.
|
||||
// Log.d(TAG, "Key down: " + keyCode + ", KeyEvent: " + event);
|
||||
return NativeApp.keyDown(InputDeviceState.deviceId, keyCode, repeat);
|
||||
return NativeApp.keyDown(NativeApp.DEVICE_ID_DEFAULT, keyCode, repeat);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1080,18 +1080,18 @@ public abstract class NativeActivity extends Activity {
|
||||
switch (keyCode) {
|
||||
case KeyEvent.KEYCODE_BACK:
|
||||
if (event.isAltPressed()) {
|
||||
NativeApp.keyUp(0, 1004); // special custom keycode
|
||||
NativeApp.keyUp(NativeApp.DEVICE_ID_PAD_0, 1004); // special custom keycode
|
||||
} else if (NativeApp.isAtTopLevel()) {
|
||||
Log.i(TAG, "IsAtTopLevel returned true.");
|
||||
return super.onKeyUp(keyCode, event);
|
||||
} else {
|
||||
NativeApp.keyUp(0, keyCode);
|
||||
NativeApp.keyUp(NativeApp.DEVICE_ID_DEFAULT, keyCode);
|
||||
}
|
||||
return true;
|
||||
case KeyEvent.KEYCODE_MENU:
|
||||
case KeyEvent.KEYCODE_SEARCH:
|
||||
// Search probably should also be ignored. We send it to the app.
|
||||
NativeApp.keyUp(0, keyCode);
|
||||
NativeApp.keyUp(NativeApp.DEVICE_ID_DEFAULT, keyCode);
|
||||
return true;
|
||||
|
||||
case KeyEvent.KEYCODE_DPAD_UP:
|
||||
@ -1106,7 +1106,7 @@ public abstract class NativeActivity extends Activity {
|
||||
default:
|
||||
// send the rest of the keys through.
|
||||
// Log.d(TAG, "Key down: " + keyCode + ", KeyEvent: " + event);
|
||||
return NativeApp.keyUp(0, keyCode);
|
||||
return NativeApp.keyUp(NativeApp.DEVICE_ID_DEFAULT, keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user