-
-
Notifications
You must be signed in to change notification settings - Fork 37
Added support for intercepting key events #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Helio Perroni Filho <[email protected]>
|
Thanks for the contribution, but I'm not sure it's a good idea for the official template to implement Activity methods which aren't being used by Toga or any other higher-level library. They would have no test coverage, and there are dozens of such methods which could be useful for some app. However, there is a way for you to use a custom MainActivity: use the Briefcase |
|
I'll check the
Assuming that access to hardware buttons in toga-android would be a desirable feature, how to go about integrating it then? Because it wouldn't be possible to implement it there without also (first?) adding support for it here. |
|
Can you give more details of exactly what you're trying to achieve? What buttons do you want to detect, and for what purpose in your app? To add this to Toga, first we'd need to discuss what the public API would look like. There is already an enumeration for keys, but it's currently only being used for menu shortcuts. I can see a couple of design questions which would need to be answered in a consistent cross-platform way:
Given the complexity of this area, it might be better for you to keep this as an Android-only feature for now. |
Yes, that's exactly what I have in mind: an Android-specific feature for intercepting hardware button events. In its barest version, integrating the changes in this commit would allow client code to intercept hardware key press events as below: Alternatively, the following method could be added to This would allow applications to register an event handler as below: |
|
We prefer not to add platform-specific features to Toga, especially if they've only been requested by one person. So unless you're willing to put in the time to design an API which would at least in principle work across multiple platforms, I think using a custom template of your own is the best way forward. |
This commit overrides the
dispatchKeyEvent()method of theMainActivityclass, allowing Android applications to intercept key events.The main need for this change is to allow applications to intercept events from hardware buttons, either in the device itself or connected peripherals, e.g. a Bluetooth headset.
Fixes #100
PR Checklist: