Android: remove duplicate code in SDLGenericMotionListener_API24
authorSylvain Becker <sylvain.becker@gmail.com>
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 +        // Handle relative mouse mode
    1.20 +        if (mRelativeModeEnabled) {
    1.21 +            if (event.getSource() == InputDevice.SOURCE_MOUSE) {
    1.22 +                if (SDLActivity.mSeparateMouseAndTouch) {
    1.23 +                    int action = event.getActionMasked();
    1.24 +                    if (action == MotionEvent.ACTION_HOVER_MOVE) {
    1.25 +                        float x = event.getAxisValue(MotionEvent.AXIS_RELATIVE_X);
    1.26 +                        float y = event.getAxisValue(MotionEvent.AXIS_RELATIVE_Y);
    1.27 +                        SDLActivity.onNativeMouse(0, action, x, y, true);
    1.28 +                        return true;
    1.29 +                    }
    1.30                  }
    1.31 -                action = event.getActionMasked();
    1.32 -                switch (action) {
    1.33 -                    case MotionEvent.ACTION_SCROLL:
    1.34 -                        x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0);
    1.35 -                        y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0);
    1.36 -                        SDLActivity.onNativeMouse(0, action, x, y, false);
    1.37 -                        return true;
    1.38 -
    1.39 -                    case MotionEvent.ACTION_HOVER_MOVE:
    1.40 -                        if (mRelativeModeEnabled) {
    1.41 -                            x = event.getAxisValue(MotionEvent.AXIS_RELATIVE_X);
    1.42 -                            y = event.getAxisValue(MotionEvent.AXIS_RELATIVE_Y);
    1.43 -                        }
    1.44 -                        else {
    1.45 -                            x = event.getX(0);
    1.46 -                            y = event.getY(0);
    1.47 -                        }
    1.48 -
    1.49 -                        SDLActivity.onNativeMouse(0, action, x, y, mRelativeModeEnabled);
    1.50 -                        return true;
    1.51 -
    1.52 -                    default:
    1.53 -                        break;
    1.54 -                }
    1.55 -                break;
    1.56 -
    1.57 -            default:
    1.58 -                break;
    1.59 +            }
    1.60          }
    1.61  
    1.62 -        // Event was not managed
    1.63 -        return false;
    1.64 +        // Event was not managed, call SDLGenericMotionListener_API12 method
    1.65 +        return super.onGenericMotion(v, event);
    1.66      }
    1.67  
    1.68      @Override