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 behaviuor?