Example usage for android.view KeyEvent getDevice

List of usage examples for android.view KeyEvent getDevice

Introduction

In this page you can find the example usage for android.view KeyEvent getDevice.

Prototype

public final InputDevice getDevice() 

Source Link

Document

Gets the device that this event came from.

Usage

From source file:com.example.android.visualgamecontroller.FullscreenActivity.java

@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;/*  w  ww.  ja  v  a2  s.  com*/
                mControllerView.invalidate();
            }
            return true;
        }
    }
    return super.onKeyUp(keyCode, ev);
}

From source file:com.example.android.visualgamecontroller.FullscreenActivity.java

@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;/*from   w  w w . j  av  a 2 s. com*/
                mControllerView.invalidate();
            }
            return true;
        }
    }
    return super.onKeyDown(keyCode, ev);
}