excilys/androidannotations — pull request #1092 by dodgex (2014-08-15 17:07:42+00:00)
Title: Implement @ReceiverAction for issue #851

As i got some free time today, i decided to do another contribution to AA. :)

I implemented the @ReceiverAction annotation suggested in https://github.com/excilys/androidannotations/issues/851.

The code is based on the `ServiceActionHandler`.

This class
```java
@EReceiver
public class MyReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

}

@ReceiverAction("MyAction")
public void doSomething() {
// Your code ...
}

@ReceiverAction(DownloadManager.ACTION_DOWNLOAD_COMPLETE)
public void onDownloadComplete(@ReceiverAction.Extra(DownloadManager.EXTRA_DOWNLOAD_ID) long extraDownloadId) {
// Your code ...
}

@ReceiverAction("anotherAction")
public void helloWorld(@ReceiverAction.Extra("hello_world") String heyWorldyWorld) {
// Your code ...
}
}
```

genereates the following code
```java
public final class MyReceiver_
extends MyReceiver
{

public final static String ACTION_HELLO_WORLD = "anotherAction";
private Context context_;
public final static String HELLO_WORLD_EXTRA = "hello_world";
public final static String ACTION_ON_DOWNLOAD_COMPLETE = "android.intent.action.DOWNLOAD_COMPLETE";
public final static String EXTRA_DOWNLOAD_ID_EXTRA = "extra_download_id";
public final static String ACTION_DO_SOMETHING = "MyAction";

@Override
public void onReceive(Context context, Intent intent) {
context_ = context;
init_();
super.onReceive(context, intent);
String action = intent.getAction();
if (ACTION_HELLO_WORLD.equals(action)) {
Bundle extras = intent.getExtras();
if (extras!= null) {
String hello_worldExtra = extras.getString(HELLO_WORLD_EXTRA);
super.helloWorld(hello_worldExtra);
}
return ;
}
if (ACTION_ON_DOWNLOAD_COMPLETE.equals(action)) {
Bundle extras = intent.getExtras();
if (extras!= null) {
long extra_download_idExtra = extras.getLong(EXTRA_DOWNLOAD_ID_EXTRA);
super.onDownloadComplete(extra_download_idExtra);
}
return ;
}
if (ACTION_DO_SOMETHING.equals(action)) {
super.doSomething();
return ;
}
}

private void init_() {
}

}

```