The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL joystick events are intercepted by WebView on Android
Noxalus


Joined: 06 Mar 2014
Posts: 26
Location: France
Hello everyone. Smile

I have an Android application using SDL in which I need to use a joystick, and this application has a WebView on top of the SDL rendering.

In this application, SDL joystick events are not triggered anymore from the moment when the WebView is added.

I figured out that the joystick inputs are intercepted by the WebView itself, and I've been able to retrieve joystick information using the Gamepad API. But this doesn't explain why SDL doesn't receive the joystick events anyway.

I did some research on the web and found the hint SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS that could be related to my problem, but it doesn't seem to have any impact, no joystick events are triggered. Crying or Very sad

Do you know what happen?
Noxalus


Joined: 06 Mar 2014
Posts: 26
Location: France
I finally found a way to solve my problem overriding some WebView methods:

Code:

    import android.webkit.WebView;
    import android.content.Context;
    import android.view.*;
    import org.libsdl.app.*;

    public class CustomWebView extends WebView
    {
        public CustomWebView(Context context)
        {
            super(context);
        }

        @Override
        public boolean dispatchKeyEvent(KeyEvent event)
        {
            // Dispatch the key events on the SDL canvas (including joystick buttons)
            SurfaceView surfaceView = (SurfaceView)SDLActivity.getLayout().getChildAt(0);

            return surfaceView.dispatchKeyEvent(event);
        }

        @Override
        public boolean onGenericMotionEvent(MotionEvent event)
        {
            // Dispatch the motion events on the SDL canvas (including joystick axes)
            SurfaceView surfaceView = (SurfaceView)SDLActivity.getLayout().getChildAt(0);

            return surfaceView.dispatchGenericMotionEvent(event);
        }
    }