public String printDevice(int id) {
   String s = "";
   s = "ID " + id;
   InputDevice dev = InputDevice.getDevice(id);
   if (dev == null) return s;
   s += " " + dev.getName() + " type " + String.format("0x%08x", dev.getSources());
   return s;
 }
  private void updateHardKeyboards() {
    mHardKeyboardPreferenceList.clear();
    if (getResources().getConfiguration().keyboard == Configuration.KEYBOARD_QWERTY) {
      final int[] devices = InputDevice.getDeviceIds();
      for (int i = 0; i < devices.length; i++) {
        InputDevice device = InputDevice.getDevice(devices[i]);
        if (device != null && !device.isVirtual() && device.isFullKeyboard()) {
          final String inputDeviceDescriptor = device.getDescriptor();
          final String keyboardLayoutDescriptor =
              mIm.getCurrentKeyboardLayoutForInputDevice(inputDeviceDescriptor);
          final KeyboardLayout keyboardLayout =
              keyboardLayoutDescriptor != null
                  ? mIm.getKeyboardLayout(keyboardLayoutDescriptor)
                  : null;

          final PreferenceScreen pref = new PreferenceScreen(getActivity(), null);
          pref.setTitle(device.getName());
          if (keyboardLayout != null) {
            pref.setSummary(keyboardLayout.toString());
          } else {
            pref.setSummary(R.string.keyboard_layout_default_label);
          }
          pref.setOnPreferenceClickListener(
              new Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                  showKeyboardLayoutDialog(inputDeviceDescriptor);
                  return true;
                }
              });
          mHardKeyboardPreferenceList.add(pref);
        }
      }
    }

    if (!mHardKeyboardPreferenceList.isEmpty()) {
      for (int i = mHardKeyboardCategory.getPreferenceCount(); i-- > 0; ) {
        final Preference pref = mHardKeyboardCategory.getPreference(i);
        if (pref.getOrder() < 1000) {
          mHardKeyboardCategory.removePreference(pref);
        }
      }

      Collections.sort(mHardKeyboardPreferenceList);
      final int count = mHardKeyboardPreferenceList.size();
      for (int i = 0; i < count; i++) {
        final Preference pref = mHardKeyboardPreferenceList.get(i);
        pref.setOrder(i);
        mHardKeyboardCategory.addPreference(pref);
      }

      getPreferenceScreen().addPreference(mHardKeyboardCategory);
    } else {
      getPreferenceScreen().removePreference(mHardKeyboardCategory);
    }
  }
Example #3
0
  @Override
  public void pollInputDevices() {
    int[] deviceIds = InputDevice.getDeviceIds();
    // It helps processing the device ids in reverse order
    // For example, in the case of the XBox 360 wireless dongle,
    // so the first controller seen by SDL matches what the receiver
    // considers to be the first controller

    for (int i = deviceIds.length - 1; i > -1; i--) {
      SDLJoystick joystick = getJoystick(deviceIds[i]);
      if (joystick == null) {
        joystick = new SDLJoystick();
        InputDevice joystickDevice = InputDevice.getDevice(deviceIds[i]);
        if ((joystickDevice.getSources() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
          joystick.device_id = deviceIds[i];
          joystick.name = joystickDevice.getName();
          joystick.axes = new ArrayList<InputDevice.MotionRange>();

          for (InputDevice.MotionRange range : joystickDevice.getMotionRanges()) {
            if ((range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
              joystick.axes.add(range);
            }
          }

          mJoysticks.add(joystick);
          SDLActivity.nativeAddJoystick(
              joystick.device_id, joystick.name, 0, -1, joystick.axes.size(), 0, 0);
        }
      }
    }

    /* Check removed devices */
    ArrayList<Integer> removedDevices = new ArrayList<Integer>();
    for (int i = 0; i < mJoysticks.size(); i++) {
      int device_id = mJoysticks.get(i).device_id;
      int j;
      for (j = 0; j < deviceIds.length; j++) {
        if (device_id == deviceIds[j]) break;
      }
      if (j == deviceIds.length) {
        removedDevices.add(device_id);
      }
    }

    for (int i = 0; i < removedDevices.size(); i++) {
      int device_id = removedDevices.get(i);
      SDLActivity.nativeRemoveJoystick(device_id);
      for (int j = 0; j < mJoysticks.size(); j++) {
        if (mJoysticks.get(j).device_id == device_id) {
          mJoysticks.remove(j);
          break;
        }
      }
    }
  }
  @Override
  public boolean onTouchEvent(MotionEvent ev) {
    if (isFinished()) return true;
    if (ev.getAction() != MotionEvent.ACTION_UP) return true;
    if (mDeviceName == null) {
      int devId = ev.getDeviceId();
      InputDevice dev = InputDevice.getDevice(devId);
      if (dev != null) {
        mDeviceName = dev.getName();
      }
    }

    mTargetPoints[mStep].calx = ev.getRawX() * ev.getXPrecision();
    mTargetPoints[mStep].caly = ev.getRawY() * ev.getYPrecision();
    mStep++;
    mContext.onCalTouchEvent(ev);
    return true;
  }