Skip to content

Commit 2caa8cf

Browse files
committed
Add convenience abstract super classes
@ReceiverAction and @ServiceAction require to add an empty implementation of the corresponding event handling method, since the method is abstract in the super class. For convenience, we provide AbstractBroadcastReceiver and AbstractIntentService classes, which implement the corresponding method, so the client does not have to.
1 parent f86d7f1 commit 2caa8cf

7 files changed

Lines changed: 86 additions & 19 deletions

File tree

‎AndroidAnnotations/androidannotations-api/META-INF/MANIFEST.MF‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Export-Package: org.androidannotations.annotations,
1212
org.androidannotations.api.rest,
1313
org.androidannotations.api.roboguice,
1414
org.androidannotations.api.sharedpreferences,
15+
org.androidannotations.api.support.app,
16+
org.androidannotations.api.support.content,
1517
org.androidannotations.api.view
1618
Bundle-Vendor: androidannotations
1719
Bundle-Activator: org.androidannotations.api.Activator

‎AndroidAnnotations/androidannotations-api/src/main/java/org/androidannotations/annotations/ReceiverAction.java‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
*
5050
* <pre>
5151
* &#064;EReceiver
52-
* public class MyIntentService extends BroadcastReceiver {
52+
* public class MyReceiver extends BroadcastReceiver {
5353
*
5454
* &#064;ReceiverAction
5555
* void mySimpleAction(Intent intent) {
@@ -65,12 +65,29 @@
6565
* void anotherAction(@ReceiverAction.Extra(&quot;specialExtraName&quot;) String valueString, @ReceiverAction.Extra long valueLong) {
6666
* // ...
6767
* }
68+
*
69+
* &#064;Override
70+
* public void onReceive(Context context, Intent intent) {
71+
* // empty, will be overridden in generated subclass
72+
* }
6873
* }
6974
* </pre>
7075
*
7176
* </blockquote>
7277
*
78+
* <p>
79+
* Note: Since
80+
* {@link android.content.BroadcastReceiver#onReceive(android.content.Context, android.content.Intent)
81+
* BroadcastReceiver#onReceive} is abstract, you have to add an empty
82+
* implementation. For convenience, we provide the
83+
* {@link org.androidannotations.api.support.content.AbstractBroadcastReceiver
84+
* AbstractBroadcastReceiver} class, which implements that method, so you do not
85+
* have to do in your actual class if you derive it.
86+
* </p>
87+
*
7388
* @see EReceiver
89+
* @see org.androidannotations.api.support.content.AbstractBroadcastReceiver
90+
* AbstractBroadcastReceiver
7491
*/
7592
@Retention(RetentionPolicy.CLASS)
7693
@Target(ElementType.METHOD)

‎AndroidAnnotations/androidannotations-api/src/main/java/org/androidannotations/annotations/ServiceAction.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,29 @@
6565
* void &lt;b&gt;myAction&lt;/b&gt;(String valueString, long valueLong) {
6666
* // ...
6767
* }
68+
*
69+
* &#064;Override
70+
* protected void onHandleIntent(Intent intent) {
71+
* // empty, will be overridden in generated subclass
72+
* }
6873
* }
6974
* </pre>
7075
*
7176
* </blockquote>
7277
*
78+
* <p>
79+
* Note: Since
80+
* {@link android.app.IntentService#onHandleIntent(android.content.Intent)
81+
* IntentService#onHandleIntent} is abstract, you have to add an empty
82+
* implementation. For convenience, we provide the
83+
* {@link org.androidannotations.api.support.app.AbstractIntentService
84+
* AbstractIntentService} class, which implements that method, so you do not
85+
* have to do in your actual class if you derive it.
86+
* </p>
87+
*
7388
* @see EIntentService
89+
* @see org.androidannotations.api.support.app.AbstractIntentService
90+
* AbstractIntentService
7491
*/
7592
@Retention(RetentionPolicy.CLASS)
7693
@Target(ElementType.METHOD)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.androidannotations.api.support.app;
2+
3+
import android.app.IntentService;
4+
import android.content.Intent;
5+
6+
/**
7+
* Convenience class for
8+
* {@link org.androidannotations.annotations.EIntentService EIntentService}s.
9+
* This adds an empty implementation of
10+
* {@link IntentService#onHandleIntent(Intent) onHandleIntent}, so you do not
11+
* have to in your actual enhanced class.
12+
*/
13+
public abstract class AbstractIntentService extends IntentService {
14+
15+
public AbstractIntentService(String name) {
16+
super(name);
17+
}
18+
19+
@Override
20+
protected void onHandleIntent(Intent intent) {
21+
22+
}
23+
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.androidannotations.api.support.content;
2+
3+
import android.content.BroadcastReceiver;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
7+
/**
8+
* Convenience class for
9+
* {@link org.androidannotations.annotations.ReceiverAction ReceiverAction}. If
10+
* you extend from it, this adds an empty implementation of
11+
* {@link BroadcastReceiver#onReceive(Context, Intent) onReceive}, so you do not
12+
* have to do in your actual class.
13+
*/
14+
public abstract class AbstractBroadcastReceiver extends BroadcastReceiver {
15+
16+
@Override
17+
public void onReceive(Context context, Intent intent) {
18+
19+
}
20+
21+
}

‎AndroidAnnotations/functional-test-1-5/src/main/java/org/androidannotations/test15/eintentservice/MyIntentService.java‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@
1818
import org.androidannotations.annotations.Bean;
1919
import org.androidannotations.annotations.EIntentService;
2020
import org.androidannotations.annotations.ServiceAction;
21+
import org.androidannotations.api.support.app.AbstractIntentService;
2122
import org.androidannotations.test15.ebean.EnhancedClass;
2223

23-
import android.app.IntentService;
24-
import android.content.Intent;
25-
2624
@EIntentService
27-
public class MyIntentService extends IntentService {
25+
public class MyIntentService extends AbstractIntentService {
2826

2927
@Bean
3028
EnhancedClass dependency;
@@ -48,9 +46,4 @@ void actionThree(String valueString, long valueLong) {
4846

4947
}
5048

51-
@Override
52-
protected void onHandleIntent(Intent intent) {
53-
// Do nothing here
54-
}
55-
5649
}

‎AndroidAnnotations/functional-test-1-5/src/main/java/org/androidannotations/test15/ereceiver/ReceiverWithActions.java‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@
1717

1818
import org.androidannotations.annotations.EReceiver;
1919
import org.androidannotations.annotations.ReceiverAction;
20-
21-
import android.content.BroadcastReceiver;
22-
import android.content.Context;
23-
import android.content.Intent;
20+
import org.androidannotations.api.support.content.AbstractBroadcastReceiver;
2421

2522
@EReceiver
26-
public class ReceiverWithActions extends BroadcastReceiver {
23+
public class ReceiverWithActions extends AbstractBroadcastReceiver {
2724

2825
public static final String ACTION_SIMPLE_TEST = "ACTION_SIMPLE_TEST";
2926
public static final String ACTION_SCHEME_TEST = "ACTION_SCHEME_TEST";
@@ -46,10 +43,6 @@ public class ReceiverWithActions extends BroadcastReceiver {
4643

4744
public int multipleActionCall = 0;
4845

49-
@Override
50-
public void onReceive(Context context, Intent intent) {
51-
}
52-
5346
@ReceiverAction(ACTION_SIMPLE_TEST)
5447
public void onSimpleAction() {
5548
simpleActionReceived = true;

0 commit comments

Comments
 (0)