• Android Annotations(1)


     

    Android Annotations是一个开源的框架,用于加速 Android应用的开发,可以让你把重点放在功能的实现上,简化了代码,提升了可维护性。

    特性:

    • 依赖注入: inject views, extras, system services, resources, ...
    • 简化的线程模型: annotate your methods so that they execute on the UI thread or on a background thread.
    • Event 绑定: annotate methods to handle events on views, no more ugly anonymous listener classes!
    • REST 客户端: create a client interface, AndroidAnnotations generates the implementation.
    • AndroidAnnotations provide those good things and even more for less than 50kb, without any runtimeperf impact!
    @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);
        }
     
        // [...]
    }
    

      


    一些常用注释的使用方法:
    @AfterInject 定义的方法在类的构造方法执行后执行
    @AfterTextChange定义的方法在TextView及其子类的Text属性改变后执行
    @AfterViews 定义的方法在setContentView后执行
    @Background 定义的方法在后台线程执行
    @BeforeTextChange 定义的方法在TextView及其子类的Text属性改变前执行
    @Click 定义点击监听器
    @EActivity 在Activity中启用Annotations
    @EProvider 在 ContentProvider中启用Annotations
    @EReceive 在BroadcastReceiver中启用Annotations
    @EService 在Service中启用Annotations
    @EView 在自定义的View的子类中启用Annotations
    @Fullscreen 全屏
    @NoTitle 无标题栏

    掌握这些注视对读懂利用该第三方代码开发的代码非常有帮助,同时对利用该代码开发的APK文件反编译的解释能够有更深入的了解。

    齊帥
  • 相关阅读:
    【转】安装VS2008:this application has requested the run
    【转】开源史上的8大交易
    PowerDesigner属性设置笔记
    国外威客网站大盘点
    [Java]单项链表与双端链表[原]
    Jenkins学习总结(3)——Jenkins+Maven+Git搭建持续集成和自动化部署的
    Jenkins学习总结(2)——Jenkins+Maven进行Java项目持续集成
    Jenkins学习总结(2)——Jenkins+Maven进行Java项目持续集成
    创业公司如何实施敏捷开发
    创业公司如何实施敏捷开发
  • 原文地址:https://www.cnblogs.com/qishuai/p/4438657.html
Copyright © 2020-2023  润新知