Android快速开发工具:AndroidAnnotations:

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);
}

// [...

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,724评论 2 45
  • Correctness AdapterViewChildren Summary: AdapterViews can...
    MarcusMa阅读 12,871评论 0 6
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,823评论 25 709
  • 现在关了窗吧,让原野安静下来; 如果必须,就让树木悄悄摇晃; 现在,没有鸟叫,如果有, 那一定是我错了。 在泥泞重...
    东丰林波阅读 1,079评论 0 0
  • 「原创第 147 篇」 早晨一进办公室,看见同事小美坐在办公桌前捂着肚子,我以为她是生理期马上给了她一包红糖姜茶冲...
    顾小宝阅读 4,310评论 0 6