AndroidAnnotations
AndroidAnnotations is an Open Source framework that speeds up Android development. It takes care of the plumbing, and lets you concentrate on what's really important. By simplifying your code, it facilitates its maintenance.
Configuring Eclipse
Please note that there are two important JARs in AndroidAnnotations:
-
androidannotations-X.X.X-api.jar
is the API JAR, it must be in your build path and will be part of the final APK -
androidannotations-X.X.X.jar
is the processor JAR, it is only needed at compile time, and must be in the compiler classpath.
Steps
- Put
androidannotations-X.X.X-api.jar
in thelibs
folder - Put
androidannotations-X.X.X.jar
in a different folder, such ascompile-libs
.androidannotations-X.X.X.jar
must not go in thelibs
folder. - Right-click on your project, choose "Properties"
- Go to Java Compiler and make sure that Compiler compliance level is set to 1.6, otherwise the processor won't be activated
- Go to Java
Compiler > Annotation Processing
and chooseEnable annotation processing
- Go to Java
Compiler > Annotation Processing > Factory Path
and add the processor JAR :androidannotations-X.X.X.jar
. - Confirm the workspace rebuild
- Go to
Java Build Path > Libraries
and add the API JAR :androidannotations-X.X.X-api.jar
, unless it's already in the build path (ADT 17 automatically adds JARs that are in the libs folder).
You can start using AndroidAnnotations
Code sample
Is your Android code easy to write, read, and maintain?
@EActivity(R.layout.translate) // Sets content view to R.layout.translate
public class TranslateActivity extends Activity {
@ViewById // Injects R.id.textInput
EditText textInput;
@ViewById(R.id.myTextView) // Injects R.id.myTextView
TextView result;
@AnimationRes // Injects android.R.anim.fade_in
Animation fadeIn;
@Click // When R.id.doTranslate button is clicked
void doTranslate() {
translateInBackground(textInput.getText().toString());
}
@Background // Executed in a background thread
void translateInBackground(String textToTranslate) {
String translatedText = callGoogleTranslate(textToTranslate);
showResult(translatedText);
}
@UiThread // Executed in the ui thread
void showResult(String translatedText) {
result.setText(translatedText);
result.startAnimation(fadeIn);
}
// [...]
}
Download
Androidannotations-bundle-3.0.1.zip (2014-02-13)