Example usage for android.view InputDevice SOURCE_GAMEPAD

List of usage examples for android.view InputDevice SOURCE_GAMEPAD

Introduction

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

Prototype

int SOURCE_GAMEPAD

To view the source code for android.view InputDevice SOURCE_GAMEPAD.

Click Source Link

Document

The input source is a game pad.

Usage

From source file:Main.java

@SuppressLint("InlinedApi")
public static String getSourcesString(int sources) {
    List<String> names = new ArrayList<String>();
    addString(sources, InputDevice.SOURCE_KEYBOARD, names);
    addString(sources, InputDevice.SOURCE_DPAD, names);
    addString(sources, InputDevice.SOURCE_GAMEPAD, names);
    addString(sources, InputDevice.SOURCE_TOUCHSCREEN, names);
    addString(sources, InputDevice.SOURCE_MOUSE, names);
    addString(sources, InputDevice.SOURCE_STYLUS, names);
    addString(sources, InputDevice.SOURCE_TOUCHPAD, names);
    addString(sources, InputDevice.SOURCE_JOYSTICK, names);
    return TextUtils.join(", ", names);
}

From source file:Main.java

/**
 * Gets the name of the source performing an action.
 * /*w w  w .  j a  v  a  2  s . c om*/
 * @param source A number representing the source.
 * 
 * @return The name of the source.
 */
public static String getSourceName(int source) {
    switch (source) {
    case InputDevice.SOURCE_CLASS_BUTTON:
        return "BUTTON";
    case InputDevice.SOURCE_CLASS_POINTER:
        return "POINTER";
    case InputDevice.SOURCE_CLASS_TRACKBALL:
        return "TRACKBALL";
    case InputDevice.SOURCE_CLASS_POSITION:
        return "POSITION";
    case InputDevice.SOURCE_CLASS_JOYSTICK:
        return "JOYSTICK";
    case InputDevice.SOURCE_DPAD:
        return "dpad";
    case InputDevice.SOURCE_GAMEPAD:
        return "gamepad";
    case InputDevice.SOURCE_JOYSTICK:
        return "joystick";
    case InputDevice.SOURCE_KEYBOARD:
        return "keyboard";
    case InputDevice.SOURCE_MOUSE:
        return "mouse";
    case InputDevice.SOURCE_STYLUS:
        return "stylus";
    case InputDevice.SOURCE_TOUCHPAD:
        return "touchpad";
    case InputDevice.SOURCE_TOUCHSCREEN:
        return "touchscreen";
    case InputDevice.SOURCE_TRACKBALL:
        return "trackball";
    case InputDevice.SOURCE_UNKNOWN:
        return "unknown";
    default:
        return "source_" + source;
    }
}

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

/**
 * Check for any game controllers that are connected already.
 */// w ww  . ja  v  a  2  s .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: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  ww  .  j a  v a  2s. c  om*/
 * @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:org.mozilla.gecko.BrowserApp.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (AndroidGamepadManager.handleKeyEvent(event)) {
        return true;
    }/*from w w w.  j  a v a  2s .c om*/

    // Global onKey handler. This is called if the focused UI doesn't
    // handle the key event, and before Gecko swallows the events.
    if (event.getAction() != KeyEvent.ACTION_DOWN) {
        return false;
    }

    if ((event.getSource() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_BUTTON_Y:
            // Toggle/focus the address bar on gamepad-y button.
            if (mBrowserChrome.getVisibility() == View.VISIBLE) {
                if (mDynamicToolbar.isEnabled() && !isHomePagerVisible()) {
                    mDynamicToolbar.setVisible(false, VisibilityTransition.ANIMATE);
                    if (mLayerView != null) {
                        mLayerView.requestFocus();
                    }
                } else {
                    // Just focus the address bar when about:home is visible
                    // or when the dynamic toolbar isn't enabled.
                    mBrowserToolbar.requestFocusFromTouch();
                }
            } else {
                mDynamicToolbar.setVisible(true, VisibilityTransition.ANIMATE);
                mBrowserToolbar.requestFocusFromTouch();
            }
            return true;
        case KeyEvent.KEYCODE_BUTTON_L1:
            // Go back on L1
            Tabs.getInstance().getSelectedTab().doBack();
            return true;
        case KeyEvent.KEYCODE_BUTTON_R1:
            // Go forward on R1
            Tabs.getInstance().getSelectedTab().doForward();
            return true;
        }
    }

    // Check if this was a shortcut. Meta keys exists only on 11+.
    final Tab tab = Tabs.getInstance().getSelectedTab();
    if (Versions.feature11Plus && tab != null && event.isCtrlPressed()) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_LEFT_BRACKET:
            tab.doBack();
            return true;

        case KeyEvent.KEYCODE_RIGHT_BRACKET:
            tab.doForward();
            return true;

        case KeyEvent.KEYCODE_R:
            tab.doReload();
            return true;

        case KeyEvent.KEYCODE_PERIOD:
            tab.doStop();
            return true;

        case KeyEvent.KEYCODE_T:
            addTab();
            return true;

        case KeyEvent.KEYCODE_W:
            Tabs.getInstance().closeTab(tab);
            return true;

        case KeyEvent.KEYCODE_F:
            mFindInPageBar.show();
            return true;
        }
    }

    return false;
}

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

private static boolean isGamepadEvent(MotionEvent event) {
    return (isFromSource(event, InputDevice.SOURCE_JOYSTICK) || isFromSource(event, InputDevice.SOURCE_GAMEPAD))
            && event.getActionMasked() == MotionEvent.ACTION_MOVE;
}

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

private static boolean isGamepadEvent(KeyEvent event) {
    return isFromSource(event, InputDevice.SOURCE_JOYSTICK) || isFromSource(event, InputDevice.SOURCE_GAMEPAD);
}