Androidannotations——Home主页,了解AndroidAnnotations

来源:互联网 发布:天猫魔盒自动删除软件 编辑:程序博客网 时间:2024/05/21 22:56
 

目录(?)[+]

  1. Download AndroidAnnotations 271
  2. Home主页
    1. Introduction简介
      1. Goals目标
      2. How如何改进
    2. Features功能
    3. Next step下一步
    4. Code sample示例代码

做好AndroidAnnotations的准备工作以后,就可以开始了解如何使用了

AndroidAnnotations在Github上有详细的说明文档,英文好的可以直接去阅读

下面文章的内容基本都是简单翻译说明文档,也是本人的一个学习过程

翻译仅供参考,不当之处,还请不吝指教

Download AndroidAnnotations 2.7.1

Home主页

Introduction简介

Goals目标

We want to facilitate the writing and the maintenance of Android applications.

我们的目标就是使得Android应用的编写维护更加容易。

We believe that simple code with clear intents is the best way to achieve those goals.

我们坚信,简洁的代码加上清晰的意图,是达成这些目标的最好方法。

Robert C. Martin wrote:

Robert C. Martin这样写道:

The ratio of time spent reading [code] versus writing is well over 10 to 1 [therefore] making it easy to read makes it easier to write.

阅读代码的时间和写代码的时间比率超过10:1,因此易读的代码使得写更简单。

While we all enjoy developing Android applications, we often wonder: Why do we always need to write the same code over and over? Why are our apps harder and harder to maintain?Contextand Activity god objects, complexity of juggling with threads, hard to discover API, loads ofanonymous listener classes, tons of unneededcasts... can't we improve that?

当我们享受开发Android程序时,经常会想到:为什么我们总是重复地写着相同的代码?为什么我们的app越来越难以维护?ContextActivity神奇的对象,特别是和threads混杂在一起后将会更加复杂,很难去暴露API,大量的匿名监听类和不必要的强制转换……我们不能改进这些状况吗?

How?如何改进?

Using Java annotations, developers can show theirintent and let AndroidAnnotations generate the plumbing code atcompile time.

使用Java注解,开发者可以指示他们的意图,并让Androidannotations在编译时生成样板代码。

Features功能

  • Dependency injection: inject views, extras, system services, resources, ...
  • 依赖注入:注入视图,附加数据,系统服务,资源……
  • Simplified threading model: annotate your methods so that they execute on the UI thread or on a background thread.
  • 简化线程模型:给你的方法加注解,以便他们在UI线程或者后台线程执行。
  • Event binding: annotate methods to handle events on views, no more ugly anonymous listener classes!
  • 事件绑定:给视图的处理事件添加注解,丑陋的匿名监听类将不再出现!
  • REST client: create a client interface, AndroidAnnotations generates the implementation.
  • REST客户端:创建客户端接口,Androidannotations生成实现。
  • No magic: As AndroidAnnotations generate subclasses at compile time, you can check the code to see how it works.
  • 实现并不神奇:当AndroidAnnotations在编译时生成子类后,你可以检查源代码,看它是怎么工作的。
  • AndroidAnnotations provide those good things and even more for less than 50kb, without any runtimeperf impact!
  • AndroidAnnotations在一个不到50kb的包中提供了这些好东西,并且没有任何运行时的性能影响

Next step下一步

  • Convinced? Get started!
  • Curious? Read how it works
  • Need proofs? See the apps already using AndroidAnnotations
  • Looking for recipes? Read the cookbook

Code sample示例代码

Is your Android code easy to write, read, and maintain?

Look at that:

@EActivity(R.layout.translate) // Sets content view to R.layout.translatepublic 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);    }    // [...]}

The project logo is based on the Android logo, created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.

Android is a trademark of Google Inc. Use of this trademark is subject toGoogle Permissions.

0 0
原创粉丝点击