|
@@ -111,6 +111,18 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
|
|
init(translucent, depth, stencil);
|
|
|
}
|
|
|
|
|
|
+ public void initInputDevices() {
|
|
|
+ /* initially add input devices*/
|
|
|
+ int[] deviceIds = mInputManager.getInputDeviceIds();
|
|
|
+ for (int deviceId : deviceIds) {
|
|
|
+ InputDevice device = mInputManager.getInputDevice(deviceId);
|
|
|
+ if (DEBUG) {
|
|
|
+ Log.v("GodotView", String.format("init() deviceId:%d, Name:%s\n", deviceId, device.getName()));
|
|
|
+ }
|
|
|
+ onInputDeviceAdded(deviceId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
|
|
@Override
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
@@ -217,36 +229,42 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
|
|
// Check if the device has not been already added
|
|
|
if (id < 0) {
|
|
|
InputDevice device = mInputManager.getInputDevice(deviceId);
|
|
|
+ //device can be null if deviceId is not found
|
|
|
+ if (device != null) {
|
|
|
+ int sources = device.getSources();
|
|
|
+ if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) ||
|
|
|
+ ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) {
|
|
|
+ id = joy_devices.size();
|
|
|
+
|
|
|
+ joystick joy = new joystick();
|
|
|
+ joy.device_id = deviceId;
|
|
|
+ joy.name = device.getName();
|
|
|
+ joy.axes = new ArrayList<InputDevice.MotionRange>();
|
|
|
+ joy.hats = new ArrayList<InputDevice.MotionRange>();
|
|
|
+
|
|
|
+ List<InputDevice.MotionRange> ranges = device.getMotionRanges();
|
|
|
+ Collections.sort(ranges, new RangeComparator());
|
|
|
+
|
|
|
+ for (InputDevice.MotionRange range : ranges) {
|
|
|
+ if (range.getAxis() == MotionEvent.AXIS_HAT_X || range.getAxis() == MotionEvent.AXIS_HAT_Y) {
|
|
|
+ joy.hats.add(range);
|
|
|
+ } else {
|
|
|
+ joy.axes.add(range);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- id = joy_devices.size();
|
|
|
-
|
|
|
- joystick joy = new joystick();
|
|
|
- joy.device_id = deviceId;
|
|
|
- joy.name = device.getName();
|
|
|
- joy.axes = new ArrayList<InputDevice.MotionRange>();
|
|
|
- joy.hats = new ArrayList<InputDevice.MotionRange>();
|
|
|
-
|
|
|
- List<InputDevice.MotionRange> ranges = device.getMotionRanges();
|
|
|
- Collections.sort(ranges, new RangeComparator());
|
|
|
+ joy_devices.add(joy);
|
|
|
|
|
|
- for (InputDevice.MotionRange range : ranges) {
|
|
|
- if (range.getAxis() == MotionEvent.AXIS_HAT_X || range.getAxis() == MotionEvent.AXIS_HAT_Y) {
|
|
|
- joy.hats.add(range);
|
|
|
- } else {
|
|
|
- joy.axes.add(range);
|
|
|
+ final int device_id = id;
|
|
|
+ final String name = joy.name;
|
|
|
+ queueEvent(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ GodotLib.joyconnectionchanged(device_id, true, name);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- joy_devices.add(joy);
|
|
|
-
|
|
|
- final int device_id = id;
|
|
|
- final String name = joy.name;
|
|
|
- queueEvent(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- GodotLib.joyconnectionchanged(device_id, true, name);
|
|
|
- }
|
|
|
- });
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -269,6 +287,8 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
|
|
|
|
|
@Override
|
|
|
public void onInputDeviceChanged(int deviceId) {
|
|
|
+ onInputDeviceRemoved(deviceId);
|
|
|
+ onInputDeviceAdded(deviceId);
|
|
|
}
|
|
|
@Override
|
|
|
public boolean onKeyUp(final int keyCode, KeyEvent event) {
|