Example usage for android.view InputDevice getDeviceIds

List of usage examples for android.view InputDevice getDeviceIds

Introduction

In this page you can find the example usage for android.view InputDevice getDeviceIds.

Prototype

public static int[] getDeviceIds() 

Source Link

Document

Gets the ids of all input devices in the system.

Usage

From source file:Main.java

public static int getConnectedInputDevices() {
    int[] deviceIDs = InputDevice.getDeviceIds();
    int result = 0;
    for (int i = 0; i < deviceIDs.length; i++) {
        InputDevice dev = InputDevice.getDevice(deviceIDs[i]);
        /*if (dev.isVirtual())
           continue;*///from   w  ww.  jav  a  2s  . c  o m

        int sources = dev.getSources();
        if ((sources & InputDevice.SOURCE_CLASS_BUTTON) != 0)
            result++;
    }
    return result;
}

From source file:info.bartowski.easteregg.MLand.java

public ArrayList getGameControllers() {
    mGameControllers.clear();// w  w w  .  j av  a 2  s  .  c  o m
    int[] deviceIds = InputDevice.getDeviceIds();
    for (int deviceId : deviceIds) {
        InputDevice dev = InputDevice.getDevice(deviceId);
        if (isGamePad(dev)) {
            if (!mGameControllers.contains(deviceId)) {
                mGameControllers.add(deviceId);
            }
        }
    }
    return mGameControllers;
}

From source file:com.goodhustle.ouyaunitybridge.OuyaUnityActivity.java

private ArrayList<Device> checkDevices() {
    //Get a list of all device id's and assign them to players.
    ArrayList<Device> devices = new ArrayList<Device>();
    int[] deviceIds = InputDevice.getDeviceIds();

    for (int count = 0; count < deviceIds.length; count++) {
        InputDevice d = InputDevice.getDevice(deviceIds[count]);
        if (!d.isVirtual()) {
            Device device = new Device();
            device.id = d.getId();//from ww w.j av a2  s .c o  m
            device.player = OuyaController.getPlayerNumByDeviceId(device.id);
            if (device.player != DEVICE_NOT_OUYACONTROLLER_COMPATIBLE) {
                device.name = d.getName();
                devices.add(device);
            }
        }
    }
    return devices;
}