Java Code Examples for android.view.InputDevice#getId()

The following examples show how to use android.view.InputDevice#getId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FullscreenActivity.java    From androidtv-VisualGameController with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onGenericMotionEvent(final MotionEvent ev) {
    // Log.d(TAG, "onGenericMotionEvent: " + ev);
    InputDevice device = ev.getDevice();
    // Only care about game controllers.
    if (device != null && device.getId() == mCurrentDeviceId) {
        if (isGamepad(device)) {
            for (AxesMapping axesMapping : AxesMapping.values()) {
                mAxes[axesMapping.ordinal()] = getCenteredAxis(ev, device,
                        axesMapping.getMotionEvent());
            }
            mControllerView.invalidate();
            return true;
        }
    }
    return super.onGenericMotionEvent(ev);
}
 
Example 2
Source File: FullscreenActivity.java    From androidtv-VisualGameController with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKeyDown(final int keyCode, KeyEvent ev) {
    // Log.d(TAG, "onKeyDown: " + ev);
    InputDevice device = ev.getDevice();
    // Only care about game controllers.
    if (device != null && device.getId() == mCurrentDeviceId) {
        if (isGamepad(device)) {
            int index = getButtonMappingIndex(keyCode);
            if (index >= 0) {
                mButtons[index] = 1;
                mControllerView.invalidate();
            }
            return true;
        }
    }
    return super.onKeyDown(keyCode, ev);
}
 
Example 3
Source File: FullscreenActivity.java    From androidtv-VisualGameController with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKeyUp(final int keyCode, KeyEvent ev) {
    // Log.d(TAG, "onKeyUp: " + ev);
    InputDevice device = ev.getDevice();
    // Only care about game controllers.
    if (device != null && device.getId() == mCurrentDeviceId) {
        if (isGamepad(device)) {
            int index = getButtonMappingIndex(keyCode);
            if (index >= 0) {
                mButtons[index] = 0;
                mControllerView.invalidate();
            }
            return true;
        }
    }
    return super.onKeyUp(keyCode, ev);
}
 
Example 4
Source File: InputManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Gets information about the input device with the specified id.
 * @param deviceId The device id.
 * @return The input device or null if not found.
 */
@Override // Binder call
public InputDevice getInputDevice(int deviceId) {
    synchronized (mInputDevicesLock) {
        final int count = mInputDevices.length;
        for (int i = 0; i < count; i++) {
            final InputDevice inputDevice = mInputDevices[i];
            if (inputDevice.getId() == deviceId) {
                return inputDevice;
            }
        }
    }
    return null;
}