Android: remove duplicate code in SDLGenericMotionListener_API24
authorSylvain Becker
Thu, 17 Jan 2019 16:30:19 +0100
changeset 12560a7d52e2db27a
parent 12559 d88be7fb81a0
child 12561 d4d5e1272239
Android: remove duplicate code in SDLGenericMotionListener_API24
and use parent method
android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
     1.1 --- a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java	Thu Jan 17 14:59:46 2019 +0100
     1.2 +++ b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java	Thu Jan 17 16:30:19 2019 +0100
     1.3 @@ -620,51 +620,24 @@
     1.4  
     1.5      @Override
     1.6      public boolean onGenericMotion(View v, MotionEvent event) {
     1.7 -        float x, y;
     1.8 -        int action;
     1.9  
    1.10 -        switch ( event.getSource() ) {
    1.11 -            case InputDevice.SOURCE_JOYSTICK:
    1.12 -            case InputDevice.SOURCE_GAMEPAD:
    1.13 -            case InputDevice.SOURCE_DPAD:
    1.14 -                return SDLControllerManager.handleJoystickMotionEvent(event);
    1.15 -
    1.16 -            case InputDevice.SOURCE_MOUSE:
    1.17 -                if (!SDLActivity.mSeparateMouseAndTouch) {
    1.18 -                    break;
    1.19 -                }
    1.20 -                action = event.getActionMasked();
    1.21 -                switch (action) {
    1.22 -                    case MotionEvent.ACTION_SCROLL:
    1.23 -                        x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0);
    1.24 -                        y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0);
    1.25 -                        SDLActivity.onNativeMouse(0, action, x, y, false);
    1.26 +        // Handle relative mouse mode
    1.27 +        if (mRelativeModeEnabled) {
    1.28 +            if (event.getSource() == InputDevice.SOURCE_MOUSE) {
    1.29 +                if (SDLActivity.mSeparateMouseAndTouch) {
    1.30 +                    int action = event.getActionMasked();
    1.31 +                    if (action == MotionEvent.ACTION_HOVER_MOVE) {
    1.32 +                        float x = event.getAxisValue(MotionEvent.AXIS_RELATIVE_X);
    1.33 +                        float y = event.getAxisValue(MotionEvent.AXIS_RELATIVE_Y);
    1.34 +                        SDLActivity.onNativeMouse(0, action, x, y, true);
    1.35                          return true;
    1.36 -
    1.37 -                    case MotionEvent.ACTION_HOVER_MOVE:
    1.38 -                        if (mRelativeModeEnabled) {
    1.39 -                            x = event.getAxisValue(MotionEvent.AXIS_RELATIVE_X);
    1.40 -                            y = event.getAxisValue(MotionEvent.AXIS_RELATIVE_Y);
    1.41 -                        }
    1.42 -                        else {
    1.43 -                            x = event.getX(0);
    1.44 -                            y = event.getY(0);
    1.45 -                        }
    1.46 -
    1.47 -                        SDLActivity.onNativeMouse(0, action, x, y, mRelativeModeEnabled);
    1.48 -                        return true;
    1.49 -
    1.50 -                    default:
    1.51 -                        break;
    1.52 +                    }
    1.53                  }
    1.54 -                break;
    1.55 -
    1.56 -            default:
    1.57 -                break;
    1.58 +            }
    1.59          }
    1.60  
    1.61 -        // Event was not managed
    1.62 -        return false;
    1.63 +        // Event was not managed, call SDLGenericMotionListener_API12 method
    1.64 +        return super.onGenericMotion(v, event);
    1.65      }
    1.66  
    1.67      @Override