You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Yeah, i was also thought about adding an annotation like this.
However, we have to carefully design the details. What annotation parameter we provide (action(s) and keycode(s))? Also how we combine these parameters to create the condition?
I am not sure we should add so much annotations. Also we may use one annotation and add the action/flag as annotation parameter for better configurability.
We defnetly want this feature, but this is not totally ready yet for implementation, because we did not created the exact specification. Let's wait for @yDelouis's answer.
In the meantime, you can initialize the environment and examine the existing codebase, try to add an annotation etc.
We should add one annotation for each method (@KeyDown, @KeyLongPress, @KeyMultiple, ...) because the methods have different parameter, so the validation will be different. For example, onKeyMutiple has a parameter int repeatCount and the user may want to use it.
The value of the annotations should be an array of keyCode and we should check if the actual keyCode is in this array, so that we can use the same annotation for different key codes.
@jiongxuan feel free to contribute the feature, but first write down all annotations with all parameters and corresponding method signatures and generated code.
(1) Each KeyCode can have only one correspondence method. Even if there are "Multi-Keycodes"
Wrong:
@KeyDownpublicbooleanbackPressed() {}
// ERROR: Same keycode used in this activity@KeyDown(KeyEvent.KEYCODE_BACK)
publicbooleanonBackPressed(KeyEventevent) {}
// ERROR: Also apply for Multi-Keycodes@KeyDown({KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_MENU})
publicbooleanonKeyPressed(intkeyCode) {}
(2) OnKeyLongPress can only used on Android 2.0+. OnKeyShortcut on Android 3.0+.
We'll report an error at compile time. Also, we need to specify in the Wiki
(3) At the moment, we don't support Fragment, because it does not support onKeyXX methods which write more complex.
If I have more free time, I will consider write it in future releases (4.0+, maybe).
i think this is because of the posibility to return a boolean if the key has been handled. what to do if a method wants to return true or false here? when there would be an ensured calling order that might be something that the developer could workaround, but due to the current nature of random order i think this limitation is valid.
Actually KeyEvent.Callback is implemented in lot of classes, not just in Activity. I think we should allow them in everywhere where they can be called and validate against whether it is implemented in the current class or not.
It is not implemented in Fragments, but it would be definitely useful. You can call getActivity().onKeyXXX there instead of onKeyXXXif (getActvity() != null).
@WonderCsabo
I'm sorry about that. I really do not have time to do it recently. Because there are some unforeseen circumstances I need to deal with.
I do this feature is expected to be completed after the Spring Festival (the end of February) .
If you want this feature anxiously, you can let someone else do it.
Activity
WonderCsabo commentedon Nov 12, 2014
Yeah, i was also thought about adding an annotation like this.
However, we have to carefully design the details. What annotation parameter we provide (action(s) and keycode(s))? Also how we combine these parameters to create the condition?
jiongxuan commentedon Nov 12, 2014
"Action(s)" can be:
"@KeyDown/@KeyUp/@KeyLongPress/@KeyShortcut"
Each of them can be Annotation(s)
"Keycode" is annotation's value, because it has too many choice, so more suitable as a parameter.
The KeyEvent can be used as the method parameter.
WonderCsabo commentedon Nov 12, 2014
I am not sure we should add so much annotations. Also we may use one annotation and add the action/flag as annotation parameter for better configurability.
@yDelouis WDYT?
jiongxuan commentedon Nov 12, 2014
Hmm. I don't think so.
("OnKeyDown/OnKeyUp/OnKeyLongPress/OnKeyShortcut")
BTW:
WonderCsabo commentedon Nov 12, 2014
Click events is another situation, they use different listeners.
jiongxuan commentedon Nov 13, 2014
onKeyXXX is the same.
Look at this one:
You don't need to care about "KeyEvent.getAction()", because onKeyDown itself shows what is your own Action.
That's to say, each Action corresponding to each kind of method, which is the same as onClick/onLongClick.
jiongxuan commentedon Nov 13, 2014
In addition, I also hope to contribute some code to AA for everyone. It benefit to my own project too.
I can't just use AA. Because: No pain ,no gain 👍
jiongxuan commentedon Nov 13, 2014
Excuse me , another question:
What's the "Enhancement" means? Ready to write? or under consideration?
WonderCsabo commentedon Nov 13, 2014
We defnetly want this feature, but this is not totally ready yet for implementation, because we did not created the exact specification. Let's wait for @yDelouis's answer.
In the meantime, you can initialize the environment and examine the existing codebase, try to add an annotation etc.
jiongxuan commentedon Nov 14, 2014
Okay!
Do you have any idea @yDelouis will be back? I haven't seen him lately
WonderCsabo commentedon Nov 14, 2014
He was around three days ago. I do not know when he can get to this issue.
yDelouis commentedon Nov 17, 2014
I think :
@KeyDown,@KeyLongPress,@KeyMultiple, ...) because the methods have different parameter, so the validation will be different. For example,onKeyMutiplehas a parameterint repeatCountand the user may want to use it.keyCodeand we should check if the actualkeyCodeis in this array, so that we can use the same annotation for different key codes.Any thoughts ?
jiongxuan commentedon Nov 18, 2014
@yDelouis I meeting you at last. :)
That's just what I was thinking.
What would you suggest I do for this issue? If not, I will do as you say :)
WonderCsabo commentedon Nov 19, 2014
@yDelouis OK, let's go with this way.
@jiongxuan feel free to contribute the feature, but first write down all annotations with all parameters and corresponding method signatures and generated code.
1 remaining item
jiongxuan commentedon Nov 20, 2014
(1) OnKeyDown
Generate:
(2) OnKeyUp/OnKeyLongPress/OnKeyShortcut are very similar to OnKeyDown
(3) OnKeyMultiple
Generate:
(4) Multi-Keycodes
Generate:
jiongxuan commentedon Nov 20, 2014
Limitation:
(1) Each
KeyCodecan have only one correspondence method. Even if there are "Multi-Keycodes"Wrong:
You should do it manually:
(2)
OnKeyLongPresscan only used on Android 2.0+.OnKeyShortcuton Android 3.0+.We'll report an error at compile time. Also, we need to specify in the Wiki
(3) At the moment, we don't support
Fragment, because it does not supportonKeyXXmethods which write more complex.If I have more free time, I will consider write it in future releases (4.0+, maybe).
@WonderCsabo @yDelouis @dodgex
Any great idea? :)
yDelouis commentedon Nov 20, 2014
Looks good to me.
jiongxuan commentedon Nov 20, 2014
My English is not good, in order to avoid such problems such as English grammar, I still want to you to write down the Wiki and Cookbook part. :)
I take charge of to help you write the code, etc.
WonderCsabo commentedon Nov 20, 2014
I have several comments:
On Nov 20, 2014 9:39 AM, "Jiongxuan Zhang" notifications@github.com wrote:
dodgex commentedon Nov 20, 2014
i think this is because of the posibility to
returna boolean if the key has been handled. what to do if a method wants to return true or false here? when there would be an ensured calling order that might be something that the developer could workaround, but due to the current nature of random order i think this limitation is valid.jiongxuan commentedon Nov 20, 2014
I Edit it for a while
Okay
For ex.
If we consider to run
onBackPressed1first, Is there no need to performonBackPressed2?There are ruled out the "random call" situation
Fragmentdoes not haveonKeyXXmethods, we must:onKeyXXmethods which is own writtenActivity(you know i mean)There was too mixed up for me, in fact :)
Sure.
WonderCsabo commentedon Nov 20, 2014
Actually
KeyEvent.Callbackis implemented in lot of classes, not just inActivity. I think we should allow them in everywhere where they can be called and validate against whether it is implemented in the current class or not.It is not implemented in
Fragments, but it would be definitely useful. You can callgetActivity().onKeyXXXthere instead ofonKeyXXXif (getActvity() != null).WonderCsabo commentedon Dec 23, 2014
@jiongxuan any news on this?
jiongxuan commentedon Dec 26, 2014
@WonderCsabo
I'm sorry about that. I really do not have time to do it recently. Because there are some unforeseen circumstances I need to deal with.
I do this feature is expected to be completed after the Spring Festival (the end of February) .
If you want this feature anxiously, you can let someone else do it.
Thank you for understanding. :)
WonderCsabo commentedon Sep 12, 2015
Finally implemented.