Tuesday, 5 July 2022

how to catch all GenericMotionEvent when a DialogFragment is shown?

I need to show a preference dialog that wait for Joypad keypress.

I know that DialogFragment has its own Window then has its own onKeyListener.

I can easily catch Joypad press by setting a listener like that.

public class MyDialogFragment extends PreferenceDialogFragmentCompat  {

    @Override
    protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
        super.onPrepareDialogBuilder(builder);

        builder.setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {

                // do stuff with intercepted key press

                return true;
            }
        });

    }
}

But, i have trouble catching GenericMotionEvents. In order to intercept them, i've overridden onGenericMotionEvents in the Activity class and eventually forward the Event by calling a method on MyDialogFragment class.

It works 100% correctly when MyDialogFragment is not shown as when an analog trigger/direction stick is moved, i can get an event.

The weird part is that IF MyDialogFragment is shown, then i can get only analog direction stick events BUT NOT left/right analog triggers events.

Does someone know why and how to fix this behaviour?



from how to catch all GenericMotionEvent when a DialogFragment is shown?

No comments:

Post a Comment