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.jaris the API JAR, it must be in your build path and will be part of the final APK -
androidannotations-X.X.X.jaris the processor JAR, it is only needed at compile time, and must be in the compiler classpath.
Steps
- Put
androidannotations-X.X.X-api.jarin thelibsfolder - Put
androidannotations-X.X.X.jarin a different folder, such ascompile-libs.androidannotations-X.X.X.jarmust not go in thelibsfolder. - 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 Processingand chooseEnable annotation processing - Go to Java
Compiler > Annotation Processing > Factory Pathand add the processor JAR :androidannotations-X.X.X.jar. - Confirm the workspace rebuild
- Go to
Java Build Path > Librariesand 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)