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

The following examples show how to use android.view.InputDevice#getDescriptor() . 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: MotionAlertDialog.java    From citra_android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Saves the provided key input setting both to the INI file (so native code can use it) and as
 * an Android preference (so it persists correctly and is human-readable.)
 *
 * @param keyEvent KeyEvent of this key press.
 */
private void saveKeyInput(KeyEvent keyEvent)
{
  InputDevice device = keyEvent.getDevice();
  String bindStr = "Device '" + device.getDescriptor() + "'-Button " + keyEvent.getKeyCode();
  String uiString = device.getName() + ": Button " + keyEvent.getKeyCode();

  saveInput(bindStr, uiString);
}
 
Example 2
Source File: MotionAlertDialog.java    From citra_android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Saves the provided motion input setting both to the INI file (so native code can use it) and as
 * an Android preference (so it persists correctly and is human-readable.)
 *
 * @param device      InputDevice from which the input event originated.
 * @param motionRange MotionRange of the movement
 * @param axisDir     Either '-' or '+'
 */
private void saveMotionInput(InputDevice device, InputDevice.MotionRange motionRange,
        char axisDir)
{
  String bindStr =
          "Device '" + device.getDescriptor() + "'-Axis " + motionRange.getAxis() + axisDir;
  String uiString = device.getName() + ": Axis " + motionRange.getAxis() + axisDir;

  saveInput(bindStr, uiString);
}
 
Example 3
Source File: GameView.java    From bluetooth with Apache License 2.0 4 votes vote down vote up
/**
 * Uses the device descriptor to try to assign the same color to the same
 * joystick. If there are two joysticks of the same type connected over USB,
 * or the API is < API level 16, it will be unable to distinguish the two
 * devices.
 *
 * @param shipID
 * @return
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private Ship getShipForId(int shipID) {
    Ship currentShip = mShips.get(shipID);
    if (null == currentShip) {

        // do we know something about this ship already?
        InputDevice dev = InputDevice.getDevice(shipID);
        String deviceString = null;
        Integer shipColor = null;
        if (null != dev) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                deviceString = dev.getDescriptor();
            } else {
                deviceString = dev.getName();
            }
            shipColor = mDescriptorMap.get(deviceString);
        }

        if (null != shipColor) {
            int color = shipColor;
            int numShips = mShips.size();
            // do we already have a ship with this color?
            for (int i = 0; i < numShips; i++) {
                if (mShips.valueAt(i).getColor() == color) {
                    shipColor = null;
                    // we won't store this value either --- if the first
                    // controller gets disconnected/connected, it will get
                    // the same color.
                    deviceString = null;
                }
            }
        }
        if (null != shipColor) {
            currentShip = new Ship(shipColor);
            if (null != deviceString) {
                mDescriptorMap.remove(deviceString);
            }
        } else {
            currentShip = new Ship(getNextShipColor());
        }
        mShips.append(shipID, currentShip);
        currentShip.setInputDevice(dev);

        if (null != deviceString) {
            mDescriptorMap.put(deviceString, currentShip.getColor());
        }
    }
    return currentShip;
}