Android: Assign duplicate descriptors same controller index
This commit is contained in:
parent
71639d74b7
commit
c79d93fd53
|
@ -127,6 +127,7 @@ public class EmulationSurfaceView extends SurfaceView {
|
||||||
}
|
}
|
||||||
|
|
||||||
private InputDeviceData[] mInputDevices = null;
|
private InputDeviceData[] mInputDevices = null;
|
||||||
|
private String[] mControllerDescriptors = null;
|
||||||
private boolean mHasAnyGamepads = false;
|
private boolean mHasAnyGamepads = false;
|
||||||
|
|
||||||
public boolean hasAnyGamePads() {
|
public boolean hasAnyGamePads() {
|
||||||
|
@ -135,9 +136,12 @@ public class EmulationSurfaceView extends SurfaceView {
|
||||||
|
|
||||||
public synchronized void updateInputDevices() {
|
public synchronized void updateInputDevices() {
|
||||||
mInputDevices = null;
|
mInputDevices = null;
|
||||||
|
mControllerDescriptors = null;
|
||||||
mHasAnyGamepads = false;
|
mHasAnyGamepads = false;
|
||||||
|
|
||||||
final ArrayList<InputDeviceData> inputDeviceIds = new ArrayList<>();
|
final ArrayList<InputDeviceData> inputDeviceIds = new ArrayList<>();
|
||||||
|
final ArrayList<String> controllerDescriptors = new ArrayList<>();
|
||||||
|
|
||||||
for (int deviceId : InputDevice.getDeviceIds()) {
|
for (int deviceId : InputDevice.getDeviceIds()) {
|
||||||
final InputDevice device = InputDevice.getDevice(deviceId);
|
final InputDevice device = InputDevice.getDevice(deviceId);
|
||||||
if (device == null || !isBindableDevice(device)) {
|
if (device == null || !isBindableDevice(device)) {
|
||||||
|
@ -151,9 +155,22 @@ public class EmulationSurfaceView extends SurfaceView {
|
||||||
if (isGamepadDevice(device))
|
if (isGamepadDevice(device))
|
||||||
mHasAnyGamepads = true;
|
mHasAnyGamepads = true;
|
||||||
|
|
||||||
final int controllerIndex = inputDeviceIds.size();
|
// Some phones seem to have duplicate descriptors for multiple devices.
|
||||||
Log.d("EmulationSurfaceView", String.format("Tracking device %d/%s (%s, sources %d)",
|
// Combine them all into one controller index if so.
|
||||||
controllerIndex, device.getDescriptor(), device.getName(), device.getSources()));
|
final String descriptor = device.getDescriptor();
|
||||||
|
int controllerIndex = controllerDescriptors.size();
|
||||||
|
for (int i = 0; i < controllerDescriptors.size(); i++) {
|
||||||
|
if (controllerDescriptors.get(i).equals(descriptor)) {
|
||||||
|
controllerIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (controllerIndex == controllerDescriptors.size()) {
|
||||||
|
controllerDescriptors.add(descriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.d("EmulationSurfaceView", String.format("Tracking device %d/%s (%s, sources %d, controller %d)",
|
||||||
|
controllerIndex, descriptor, device.getName(), device.getSources(), controllerIndex));
|
||||||
inputDeviceIds.add(new InputDeviceData(device, controllerIndex));
|
inputDeviceIds.add(new InputDeviceData(device, controllerIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,18 +179,13 @@ public class EmulationSurfaceView extends SurfaceView {
|
||||||
|
|
||||||
mInputDevices = new InputDeviceData[inputDeviceIds.size()];
|
mInputDevices = new InputDeviceData[inputDeviceIds.size()];
|
||||||
inputDeviceIds.toArray(mInputDevices);
|
inputDeviceIds.toArray(mInputDevices);
|
||||||
|
|
||||||
|
mControllerDescriptors = new String[controllerDescriptors.size()];
|
||||||
|
controllerDescriptors.toArray(mControllerDescriptors);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized String[] getInputDeviceNames() {
|
public synchronized String[] getInputDeviceNames() {
|
||||||
if (mInputDevices == null)
|
return mControllerDescriptors;
|
||||||
return null;
|
|
||||||
|
|
||||||
final String[] deviceNames = new String[mInputDevices.length];
|
|
||||||
for (int i = 0; i < mInputDevices.length; i++) {
|
|
||||||
deviceNames[i] = mInputDevices[i].descriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
return deviceNames;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean hasInputDeviceVibration(int controllerIndex) {
|
public synchronized boolean hasInputDeviceVibration(int controllerIndex) {
|
||||||
|
|
Loading…
Reference in New Issue