Clean up captured pointer code to avoid logcat clutter on pre-8.0 systems (thanks Rachel!)
authorSam Lantinga <slouken@libsdl.org>
Fri, 13 Jul 2018 12:55:50 -0700
changeset 12061d7cb1131aada
parent 12060 c5ea08c1b9b6
child 12062 d31364f5afab
Clean up captured pointer code to avoid logcat clutter on pre-8.0 systems (thanks Rachel!)
android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
     1.1 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Thu Jul 12 13:28:15 2018 -0700
     1.2 +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Fri Jul 13 12:55:50 2018 -0700
     1.3 @@ -1382,10 +1382,6 @@
     1.4              setOnGenericMotionListener(SDLActivity.getMotionListener());
     1.5          }
     1.6  
     1.7 -        if ((Build.VERSION.SDK_INT >= 26) && !SDLActivity.isDeXMode()) {
     1.8 -            setOnCapturedPointerListener(new SDLCapturedPointerListener_API26());
     1.9 -        }
    1.10 -
    1.11          // Some arbitrary defaults to avoid a potential division by zero
    1.12          mWidth = 1.0f;
    1.13          mHeight = 1.0f;
    1.14 @@ -1740,6 +1736,49 @@
    1.15                                        event.values[2] / SensorManager.GRAVITY_EARTH);
    1.16          }
    1.17      }
    1.18 +
    1.19 +    // Captured pointer events for API 26.
    1.20 +    public boolean onCapturedPointerEvent(MotionEvent event)
    1.21 +    {
    1.22 +        int action = event.getActionMasked();
    1.23 +
    1.24 +        float x, y;
    1.25 +        switch (action) {
    1.26 +            case MotionEvent.ACTION_SCROLL:
    1.27 +                x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0);
    1.28 +                y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0);
    1.29 +                SDLActivity.onNativeMouse(0, action, x, y, false);
    1.30 +                return true;
    1.31 +
    1.32 +            case MotionEvent.ACTION_HOVER_MOVE:
    1.33 +            case MotionEvent.ACTION_MOVE:
    1.34 +                x = event.getX(0);
    1.35 +                y = event.getY(0);
    1.36 +                SDLActivity.onNativeMouse(0, action, x, y, true);
    1.37 +                return true;
    1.38 +
    1.39 +            case MotionEvent.ACTION_BUTTON_PRESS:
    1.40 +            case MotionEvent.ACTION_BUTTON_RELEASE:
    1.41 +
    1.42 +                // Change our action value to what SDL's code expects.
    1.43 +                if (action == MotionEvent.ACTION_BUTTON_PRESS) {
    1.44 +                    action = MotionEvent.ACTION_DOWN;
    1.45 +                }
    1.46 +                else if (action == MotionEvent.ACTION_BUTTON_RELEASE) {
    1.47 +                    action = MotionEvent.ACTION_UP;
    1.48 +                }
    1.49 +
    1.50 +                x = event.getX(0);
    1.51 +                y = event.getY(0);
    1.52 +                int button = event.getButtonState();
    1.53 +
    1.54 +                SDLActivity.onNativeMouse(button, action, x, y, true);
    1.55 +                return true;
    1.56 +        }
    1.57 +
    1.58 +        return false;
    1.59 +    }
    1.60 +
    1.61  }
    1.62  
    1.63  /* This is a fake invisible editor view that receives the input and defines the
     2.1 --- a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java	Thu Jul 12 13:28:15 2018 -0700
     2.2 +++ b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java	Fri Jul 13 12:55:50 2018 -0700
     2.3 @@ -749,7 +749,7 @@
     2.4  
     2.5      @Override
     2.6      public boolean supportsRelativeMouse() {
     2.7 -        return true;
     2.8 +        return !SDLActivity.isDeXMode();
     2.9      }
    2.10  
    2.11      @Override
    2.12 @@ -759,20 +759,26 @@
    2.13  
    2.14      @Override
    2.15      public boolean setRelativeMouseEnabled(boolean enabled) {
    2.16 -        if (enabled) {
    2.17 -            SDLActivity.getContentView().requestPointerCapture();
    2.18 +        if (!SDLActivity.isDeXMode()) {
    2.19 +            if (enabled) {
    2.20 +                SDLActivity.getContentView().requestPointerCapture();
    2.21 +            }
    2.22 +            else {
    2.23 +                SDLActivity.getContentView().releasePointerCapture();            
    2.24 +            }
    2.25 +            mRelativeModeEnabled = enabled;
    2.26 +            return true;
    2.27          }
    2.28 -        else {
    2.29 -            SDLActivity.getContentView().releasePointerCapture();            
    2.30 +        else 
    2.31 +        {
    2.32 +            return false;
    2.33          }
    2.34 -        mRelativeModeEnabled = enabled;
    2.35 -        return true;
    2.36      }
    2.37  
    2.38      @Override
    2.39      public void reclaimRelativeMouseModeIfNeeded()
    2.40      {
    2.41 -        if (mRelativeModeEnabled) {
    2.42 +        if (mRelativeModeEnabled && !SDLActivity.isDeXMode()) {
    2.43              SDLActivity.getContentView().requestPointerCapture();
    2.44          }
    2.45      }
    2.46 @@ -788,51 +794,4 @@
    2.47          // Relative mouse in capture mode will only have relative for X/Y
    2.48          return event.getY(0);
    2.49      }
    2.50 -}
    2.51 -
    2.52 -class SDLCapturedPointerListener_API26 implements View.OnCapturedPointerListener
    2.53 -{
    2.54 -    @Override
    2.55 -    public boolean onCapturedPointer(View view, MotionEvent event)
    2.56 -    {
    2.57 -        int action = event.getActionMasked();
    2.58 -
    2.59 -        float x, y;
    2.60 -        switch (action) {
    2.61 -            case MotionEvent.ACTION_SCROLL:
    2.62 -                x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0);
    2.63 -                y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0);
    2.64 -                SDLActivity.onNativeMouse(0, action, x, y, false);
    2.65 -                return true;
    2.66 -
    2.67 -            case MotionEvent.ACTION_HOVER_MOVE:
    2.68 -            case MotionEvent.ACTION_MOVE:
    2.69 -                x = event.getX(0);
    2.70 -                y = event.getY(0);
    2.71 -                SDLActivity.onNativeMouse(0, action, x, y, true);
    2.72 -                return true;
    2.73 -
    2.74 -            case MotionEvent.ACTION_BUTTON_PRESS:
    2.75 -            case MotionEvent.ACTION_BUTTON_RELEASE:
    2.76 -
    2.77 -                // Change our action value to what SDL's code expects.
    2.78 -                if (action == MotionEvent.ACTION_BUTTON_PRESS) {
    2.79 -                    action = MotionEvent.ACTION_DOWN;
    2.80 -                }
    2.81 -                else if (action == MotionEvent.ACTION_BUTTON_RELEASE) {
    2.82 -                    action = MotionEvent.ACTION_UP;
    2.83 -                }
    2.84 -
    2.85 -                x = event.getX(0);
    2.86 -                y = event.getY(0);
    2.87 -                int button = event.getButtonState();
    2.88 -
    2.89 -                SDLActivity.onNativeMouse(button, action, x, y, true);
    2.90 -                return true;
    2.91 -
    2.92 -        }
    2.93 -
    2.94 -        return false;
    2.95 -    }
    2.96 -}
    2.97 -
    2.98 +}
    2.99 \ No newline at end of file