Пример #1
0
 @Override
 public boolean handleMotionEvent(MotionEvent event) {
   if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) != 0) {
     int actionPointerIndex = event.getActionIndex();
     int action = event.getActionMasked();
     switch (action) {
       case MotionEvent.ACTION_MOVE:
         SDLJoystick joystick = getJoystick(event.getDeviceId());
         if (joystick != null) {
           for (int i = 0; i < joystick.axes.size(); i++) {
             InputDevice.MotionRange range = joystick.axes.get(i);
             /* Normalize the value to -1...1 */
             float value =
                 (event.getAxisValue(range.getAxis(), actionPointerIndex) - range.getMin())
                         / range.getRange()
                         * 2.0f
                     - 1.0f;
             SDLActivity.onNativeJoy(joystick.device_id, i, value);
           }
         }
         break;
       default:
         break;
     }
   }
   return true;
 }
Пример #2
0
  // Generic Motion (mouse hover, joystick...) events go here
  @Override
  public boolean onGenericMotion(View v, MotionEvent event) {
    float x, y;
    int mouseButton;
    int action;

    switch (event.getSource()) {
      case InputDevice.SOURCE_JOYSTICK:
      case InputDevice.SOURCE_GAMEPAD:
      case InputDevice.SOURCE_DPAD:
        SDLActivity.handleJoystickMotionEvent(event);
        return true;

      case InputDevice.SOURCE_MOUSE:
        action = event.getActionMasked();
        switch (action) {
          case MotionEvent.ACTION_SCROLL:
            x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0);
            y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0);
            SDLActivity.onNativeMouse(0, action, x, y);
            return true;

          case MotionEvent.ACTION_HOVER_MOVE:
            x = event.getX(0);
            y = event.getY(0);

            SDLActivity.onNativeMouse(0, action, x, y);
            return true;

          default:
            break;
        }

      default:
        break;
    }

    // Event was not managed
    return false;
  }