excilys/androidannotations — Issue #117: Support of GreenDroid library
Author: sand1024
Created: 2012-02-24 16:33:56+00:00
State: open

Hi,

First of all, thank you for great library - I like it very much.

I suppose it will be great if GreenDroid (http://greendroid.cyrilmottier.com/) library will be also supported. That library offers rich set of functionality, however, has specifics which prohibits smooth usages of both Android Annotations as GreenDroid in the the same project.

The problem is as follows: GreenDroid provides own set of Activity classes as well as own Application class and requires that project-specific activities should be inherited from them. While in general it's quite transparent for development, there is one issue which is not compatible with Android annotations - they override setContentView for own purposes and obviously the clash between code generated by annotations processor and their code occurs.

From the other side, they use own method named "setActionBarContentView" which may be used for placing code generated by annotation processor in Android annotations.

One of projects we've developed started with using Android annotations and later support of GreenDroid was requested.
Therefore, for our needs we've made a quick patch (with quite a minor set of changes) of EActivityProcessor which handles clash described above and after that both these libraries worked together like a charm.

Here are content of patch:
1) change:

private void setContentViewMethod(JCodeModel codeModel, EBeanHolder holder, JType[] paramTypes, String[] paramNames) {
//******************************************************************************************
// GreenDroid support

//	JMethod method = holder.eBean.method(JMod.PUBLIC, codeModel.VOID, "setContentView");
// tmp - fix for GDDroidActivities
JMethod method = holder.eBean.method(JMod.PUBLIC, codeModel.VOID, "setActionBarContentView");
//******************************************************************************************

method.annotate(Override.class);

and

JFieldRef contentViewId;
if (layoutIdValue != Id.DEFAULT_VALUE) {
IRInnerClass rInnerClass = rClass.get(Res.LAYOUT);
contentViewId = rInnerClass.getIdStaticRef(layoutIdValue, holder);
} else {
contentViewId = null;
}
//******************************************************************************************
// GreenDroid support
if (contentViewId != null) {
// tmp - fix for GreenDroid specific activities
onCreateBody.invoke("setActionBarContentView").arg(contentViewId);
}
//******************************************************************************************

// Overriding setContentView (with layout id param)
JClass viewClass = holder.refClass("android.view.View");

Obviously, there is one important things which is omitted in our patch - yet it definitely need to be present in production version of Android Annotations library - it's a check for base class of activity. Basically, if activity is inherited from "greendroid.app.GDActivity" the code from our patch need to be invoked and original existing code should be used otherwise.

Hope that submission was helpful - and I'm sure that support of such integration will improve the library even more.

Regards,
Andrew Sazonov