Android快速开发工具:AndroidAnnotations:

00Android.jpg
github 地址:https://github.com/excilys/androidannotations
目标:
--加快安卓开发
--减少重复代码
--使开发者有更多的事件去思考核心业务代码
实现:
基于Java的注解原理,开发者直接使用注解展示他们的意图,然后AndroidAnnotations会自动帮我们生成代码,使得很多重复冗余的代码只需要一行代码就解决掉。
特征:
--1.依赖注入: inject(注解) views, extras, system services, resources, ...
--2.简化的线程模型:annotate your methods so that they execute on the UI thread or on a background thread.
--3.事件绑定:annotate methods to handle events on views, no more ugly anonymous listener classes!
--4.REST client:REST client: create a client interface, AndroidAnnotations generates the implementation
--5.AndroidAnnotations 这个工具比较小,低于150kb
Code Example:
==================================================
@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);
}
// [...
}