Androidannotations——Home主页,了解AndroidAnnotations

做好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 unneeded casts... can't we improve that?

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

How?如何改进?

Using Java annotations, developers can show their intent and let AndroidAnnotations generate the plumbing code at compile 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 runtime perf impact!
  • AndroidAnnotations在一个不到50kb的包中提供了这些好东西,并且没有任何运行时的性能影响

Next step下一步

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

    // [...]
}

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 to Google Permissions.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值