Example usage for android.view InputDevice getSources

List of usage examples for android.view InputDevice getSources

Introduction

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

Prototype

public int getSources() 

Source Link

Document

Gets the input sources supported by this input device as a combined bitfield.

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  . ja va2 s.co m*/

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

From source file:com.google.fpl.voltair.VoltAirActivity.java

private static boolean isSourceType(InputDevice device, int querySource) {
    if (device == null) {
        return false;
    } else {//from  w w w.ja  v a 2  s .co  m
        return (device.getSources() & querySource) == querySource;
    }
}

From source file:org.gearvrf.weartouchpad.WearInputService.java

@Override
public void onCreate() {
    super.onCreate();
    apiClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).build();
    apiClient.connect();// w w  w.  j av  a 2  s  . c  o m
    nodes = new HashSet<Node>();
    receiveMessenger = new Messenger(new IncomingMsgHandler());
    broadcastManager = LocalBroadcastManager.getInstance(this);
    localBinder = new LocalBinder();
    connectedToWatch = false;
    int touchScreenDeviceId = 0;
    InputManager im = (InputManager) getSystemService(Context.INPUT_SERVICE);
    for (int inputDevId : im.getInputDeviceIds()) {
        InputDevice inputDevice = im.getInputDevice(inputDevId);
        if ((inputDevice.getSources() & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) {
            touchScreenDeviceId = inputDevId;
            break;
        }
    }
    motionEventGenerator = new MotionEventGenerator(touchScreenDeviceId);
}

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

public static boolean isGamePad(InputDevice dev) {
    int sources = dev.getSources();

    // Verify that the device has gamepad buttons, control sticks, or both.
    return (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
            || ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK));
}

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

/**
 * Utility method to determine if input device is a gamepad.
 * /*w w w. j a va  2  s.co m*/
 * @param device
 * @return
 */
private boolean isGamepad(InputDevice device) {
    if ((device.getSources() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD
            || (device.getSources() & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) {
        return true;
    }
    return false;
}

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

/**
 * Check for any game controllers that are connected already.
 *///from   w  w w.  jav  a 2s . c  o m
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();
                }
            }
        }
    }
}

From source file:org.ulteo.ovd.AndRdpActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    AudioManager audioManager;/*w w  w  .  j a v  a 2 s. c om*/

    if (Config.DEBUG)
        Log.i(Config.TAG, "AndRdpActivity.dispatchKeyEvent " + event);

    // Disable keypress if it is from a mouse or touchpad.
    if (event.getDeviceId() >= 0) {
        InputDevice dev = InputDevice.getDevice(event.getDeviceId());
        if (dev.getSources() == InputDevice.SOURCE_MOUSE || dev.getSources() == InputDevice.SOURCE_TOUCHPAD)
            return true;
    }

    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_MENU:
            OnThreeFingers(null);
            return true;
        case KeyEvent.KEYCODE_BACK:
            Log.i(Config.TAG, "Back key pressed");
            askLogoutDialog();
            return true;
        case KeyEvent.KEYCODE_VOLUME_UP:
            audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE,
                    AudioManager.FLAG_SHOW_UI);
            return true;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER,
                    AudioManager.FLAG_SHOW_UI);
            return true;
        }
    } else if (event.getAction() == KeyEvent.ACTION_UP) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_MENU:
        case KeyEvent.KEYCODE_BACK:
        case KeyEvent.KEYCODE_VOLUME_UP:
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            return true;
        }
    }

    if (isLoggedIn() && rdp.dispatchKeyEvent(event))
        return true;

    return super.dispatchKeyEvent(event);
}