Skip to content

Repository files navigation

Green Annotations

An Android Annotations plugin to support the Greenrobot Eventbus.
It can inject the default EventBus and automatically handle the registration/unregistration.

Build StatusMaven CentralAndroid ArsenalJavadocslicenseJoin the chat at https://gitter.im/green-annotations/Lobby

Usage in your Android Studio project:

In the build.gradle file of the module project:

dependencies {
// Android Annotations for Greenrobot
apt 'com.tmtron:green-annotations:1.0.2'
compile 'com.tmtron:green-annotations-api:1.0.2'
}

Note: Green-Annotations version 1.0.2 requires Android-Annotations version 4.4.0

Details

Before

Shows the Activity without using AndroidAnnotations or GreenAnnotations:

publicclassActivityBeforeextendsActivity {
EventBuseventBus;
@OverrideprotectedvoidonCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
eventBus = EventBus.getDefault();
}
@OverridepublicvoidonStart() {
super.onStart();
eventBus.register(this);
}
@OverridepublicvoidonStop() {
eventBus.unregister(this);
super.onStop();
}
publicvoidfireEvent(Stringmessage) {
eventBus.post(newMessageEvent(message));
}
@Subscribe(threadMode = ThreadMode.MAIN)
publicvoidonMessageEvent(MessageEventevent) {
Toast.makeText(getApplicationContext(), event.message, Toast.LENGTH_SHORT).show();
}
}

After

Shows the same Activity with AndroidAnnotations and GreenAnnotations:

@EActivitypublicclassActivityAfterextendsActivity {
@EventBusGreenRobotEventBuseventBus;
publicvoidfireEvent(Stringmessage) {
eventBus.post(newMessageEvent(message));
}
@Subscribe(threadMode = ThreadMode.MAIN)
publicvoidonMessageEvent(MessageEventevent) {
Toast.makeText(getApplicationContext(), event.message, Toast.LENGTH_SHORT).show();
}
}

Note: green-annotations-test is a tiny test-project: a sample android app with only one single activity to show how to use green-annotations (and the gradle-setup).

License

This plugin is under the Apache 2.0 license. Copyright 2016, Martin Trummer

About

An Android Annotations plugin to support Green Robot.

Topics

Resources

Stars

21 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages