List of usage examples for android.view InputDevice getControllerNumber
public int getControllerNumber()
From source file:com.example.android.visualgamecontroller.FullscreenActivity.java
@Override public void onInputDeviceAdded(int deviceId) { Log.d(TAG, "onInputDeviceAdded: " + deviceId); if (!mConnectedDevices.contains(deviceId)) { mConnectedDevices.add(new Integer(deviceId)); }/*from w w w . j ava2 s .c om*/ if (mCurrentDeviceId == -1) { mCurrentDeviceId = deviceId; InputDevice dev = InputDevice.getDevice(mCurrentDeviceId); if (dev != null) { mControllerView.setCurrentControllerNumber(dev.getControllerNumber()); mControllerView.invalidate(); } } }
From source file:com.example.android.visualgamecontroller.FullscreenActivity.java
@Override public void onInputDeviceRemoved(int deviceId) { Log.d(TAG, "onInputDeviceRemoved: " + deviceId); mConnectedDevices.remove(new Integer(deviceId)); if (mCurrentDeviceId == deviceId) { mCurrentDeviceId = -1;/*from w w w .j a va 2s . c o m*/ } if (mConnectedDevices.size() == 0) { mControllerView.setCurrentControllerNumber(-1); mControllerView.invalidate(); } else { mCurrentDeviceId = mConnectedDevices.get(0); InputDevice dev = InputDevice.getDevice(mCurrentDeviceId); if (dev != null) { mControllerView.setCurrentControllerNumber(dev.getControllerNumber()); mControllerView.invalidate(); } } }
From source file:com.example.android.visualgamecontroller.FullscreenActivity.java
/** * Check for any game controllers that are connected already. *//*from w w w . j a v a 2s .c om*/ private void checkGameControllers() { Log.d(TAG, "checkGameControllers"); int[] deviceIds = mInputManager.getInputDeviceIds(); for (int deviceId : deviceIds) { InputDevice dev = InputDevice.getDevice(deviceId); int sources = dev.getSources(); // Verify that the device has gamepad buttons, control sticks, or // both. if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) || ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) { // This device is a game controller. Store its device ID. if (!mConnectedDevices.contains(deviceId)) { mConnectedDevices.add(deviceId); if (mCurrentDeviceId == -1) { mCurrentDeviceId = deviceId; mControllerView.setCurrentControllerNumber(dev.getControllerNumber()); mControllerView.invalidate(); } } } } }