Skip to content

Commit 3ad8c56

Browse files
committed
Merge pull request androidannotations#1539 from simopete/1238_Keyevents
Annotations to handle key events
2 parents fd38a3f + 1afe4d5 commit 3ad8c56

26 files changed

Lines changed: 1631 additions & 1 deletion

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/**
2+
* Copyright (C) 2010-2015 eBusiness Information, Excilys Group
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed To in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package org.androidannotations.annotations;
17+
18+
import java.lang.annotation.ElementType;
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.RetentionPolicy;
21+
import java.lang.annotation.Target;
22+
23+
/**
24+
* <p>
25+
* This annotation is intended to be used on methods to receive action down
26+
* event on a key. This annotation can be used on methods of classes which
27+
* implements {@link android.view.KeyEvent.Callback}.
28+
* </p>
29+
* <p>
30+
* The annotation value should be one or several of
31+
* {@link android.view.KeyEvent} constant fields which name contains KEYCODE. If
32+
* not set, the method name will be used as the {@link android.view.KeyEvent}
33+
* .KEYCODE_* field name.
34+
* </p>
35+
* <p>
36+
* The method may return a <code>boolean</code>, <code>void</code>, or a
37+
* {@link Boolean}. If returning void, it will be considered as
38+
* returning true (ie: the method has handled the event).
39+
* </p>
40+
* <p>
41+
* The method MAY have one parameter:
42+
* </p>
43+
* <ul>
44+
* <li>A {@link android.view.KeyEvent} parameter to know which key has been down
45+
* </li>
46+
* </ul>
47+
*
48+
* <p>
49+
* Example :
50+
* </p>
51+
*
52+
* <pre>
53+
* &#064;EActivity
54+
* public class MyActivity extends Activity {
55+
*
56+
* &#064;KeyDown
57+
* void enter() {
58+
* // ...
59+
* }
60+
*
61+
* &#064;KeyDown
62+
* void onEnter() {
63+
* // ...
64+
* }
65+
*
66+
* &#064;KeyDown
67+
* void onEnterPressed() {
68+
* // ...
69+
* }
70+
*
71+
* &#064;KeyDown
72+
* void enterPressed() {
73+
* // ...
74+
* }
75+
*
76+
* &#064;KeyDown(KeyEvent.KEYCODE_0)
77+
* void keyZeroIsDown(KeyEvent keyEvent) {
78+
* // ...
79+
* }
80+
*
81+
* &#064;KeyDown({ KeyEvent.KEYCODE_M, KeyEvent.KEYCODE_N })
82+
* boolean multipleKeys(KeyEvent keyEvent) {
83+
* return false;
84+
* }
85+
* }
86+
* </pre>
87+
*
88+
* @see android.view.KeyEvent
89+
* @see android.view.KeyEvent.Callback
90+
* @see android.view.KeyEvent.Callback#onKeyDown(int, android.view.KeyEvent)
91+
*/
92+
@Retention(RetentionPolicy.CLASS)
93+
@Target(ElementType.METHOD)
94+
public @interface KeyDown {
95+
96+
/**
97+
* The {@link android.view.KeyEvent} class constants which name contains
98+
* KEYCODE.
99+
*
100+
* @return the value of the key code
101+
*/
102+
int[] value() default {};
103+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/**
2+
* Copyright (C) 2010-2015 eBusiness Information, Excilys Group
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed To in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package org.androidannotations.annotations;
17+
18+
import java.lang.annotation.ElementType;
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.RetentionPolicy;
21+
import java.lang.annotation.Target;
22+
23+
/**
24+
* <p>
25+
* This annotation is intended to be used on methods to receive long press event
26+
* on a key. This annotation can be used on methods of classes which implements
27+
* {@link android.view.KeyEvent.Callback}.
28+
* </p>
29+
* <p>
30+
* The annotation value should be one or several of
31+
* {@link android.view.KeyEvent} constant fields which name contains KEYCODE. If
32+
* not set, the method name will be used as the {@link android.view.KeyEvent}
33+
* .KEYCODE_* field name.
34+
* </p>
35+
* <p>
36+
* The method may return a <code>boolean</code>, <code>void</code>, or a
37+
* {@link Boolean}. If returning void, it will be considered as
38+
* returning true (ie: the method has handled the event).
39+
* </p>
40+
* <p>
41+
* The method MAY have one parameter:
42+
* </p>
43+
* <ul>
44+
* <li>A {@link android.view.KeyEvent} parameter to know which key has been down
45+
* </li>
46+
* </ul>
47+
*
48+
* <p>
49+
* Example :
50+
* </p>
51+
*
52+
* <pre>
53+
* &#064;EActivity
54+
* public class MyActivity extends Activity {
55+
*
56+
* &#064;KeyLongPress
57+
* void enter() {
58+
* // ...
59+
* }
60+
*
61+
* &#064;KeyLongPress
62+
* void onEnter() {
63+
* // ...
64+
* }
65+
*
66+
* &#064;KeyLongPress
67+
* void onEnterPressed() {
68+
* // ...
69+
* }
70+
*
71+
* &#064;KeyLongPress
72+
* void enterPressed() {
73+
* // ...
74+
* }
75+
*
76+
* &#064;KeyLongPress(KeyEvent.KEYCODE_0)
77+
* void keyZeroIsLongPressed(KeyEvent keyEvent) {
78+
* // ...
79+
* }
80+
*
81+
* &#064;KeyLongPress({ KeyEvent.KEYCODE_M, KeyEvent.KEYCODE_N })
82+
* boolean multipleKeys(KeyEvent keyEvent) {
83+
* return false;
84+
* }
85+
* }
86+
* </pre>
87+
*
88+
* @see android.view.KeyEvent
89+
* @see android.view.KeyEvent.Callback
90+
* @see android.view.KeyEvent.Callback#onKeyLongPress(int, android.view.KeyEvent)
91+
*/
92+
@Retention(RetentionPolicy.CLASS)
93+
@Target(ElementType.METHOD)
94+
public @interface KeyLongPress {
95+
96+
/**
97+
* The {@link android.view.KeyEvent} class constants which name contains
98+
* KEYCODE.
99+
*
100+
* @return the value of the key code
101+
*/
102+
int[] value() default {};
103+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* Copyright (C) 2010-2015 eBusiness Information, Excilys Group
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed To in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package org.androidannotations.annotations;
17+
18+
import java.lang.annotation.ElementType;
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.RetentionPolicy;
21+
import java.lang.annotation.Target;
22+
23+
/**
24+
* <p>
25+
* This annotation is intended to be used on methods to receive action multiple
26+
* event on a key. This annotation can be used on methods of classes which
27+
* implements {@link android.view.KeyEvent.Callback}.
28+
* </p>
29+
* <p>
30+
* The annotation value should be one or several of
31+
* {@link android.view.KeyEvent} constant fields which name contains KEYCODE. If
32+
* not set, the method name will be used as the {@link android.view.KeyEvent}
33+
* .KEYCODE_* field name.
34+
* </p>
35+
* <p>
36+
* The method may return a <code>boolean</code>, <code>void</code>, or a
37+
* {@link Boolean}. If returning void, it will be considered as
38+
* returning true (ie: the method has handled the event).
39+
* </p>
40+
* <p>
41+
* The method MAY have one or two parameter:
42+
* </p>
43+
* <ul>
44+
* <li>A {@link android.view.KeyEvent} parameter to know which key has been down
45+
* </li>
46+
* <li>A <code>int</code> or {@link Integer} paramter to know the key is how
47+
* many times repeated</li>
48+
* </ul>
49+
*
50+
* <p>
51+
* Example :
52+
* </p>
53+
*
54+
* <pre>
55+
* &#064;EActivity
56+
* public class MyActivity extends Activity {
57+
*
58+
* &#064;KeyMultiple
59+
* void enter() {
60+
* // ...
61+
* }
62+
*
63+
* &#064;KeyMultiple
64+
* void onEnter() {
65+
* // ...
66+
* }
67+
*
68+
* &#064;KeyMultiple
69+
* void onEnterPressed() {
70+
* // ...
71+
* }
72+
*
73+
* &#064;KeyMultiple
74+
* void enterPressed() {
75+
* // ...
76+
* }
77+
*
78+
* &#064;KeyMultiple(KeyEvent.KEYCODE_0)
79+
* void keyZeroMultiple(KeyEvent keyEvent) {
80+
* // ...
81+
* }
82+
*
83+
* &#064;KeyMultiple({ KeyEvent.KEYCODE_M, KeyEvent.KEYCODE_N })
84+
* boolean multipleKeys(KeyEvent keyEvent) {
85+
* return false;
86+
* }
87+
* }
88+
* </pre>
89+
*
90+
* @see android.view.KeyEvent
91+
* @see android.view.KeyEvent.Callback
92+
* @see android.view.KeyEvent.Callback#onKeyMultiple(int, int, android.view.KeyEvent)
93+
*/
94+
@Retention(RetentionPolicy.CLASS)
95+
@Target(ElementType.METHOD)
96+
public @interface KeyMultiple {
97+
98+
/**
99+
* The {@link android.view.KeyEvent} class constants which name contains
100+
* KEYCODE.
101+
*
102+
* @return the value of the key code
103+
*/
104+
int[] value() default {};
105+
}

0 commit comments

Comments
 (0)