Androidannotations——Home主页,了解AndroidAnnotations

翻译 2013年12月04日 15:11:00

做好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.

AndroidAnnotations——BackgroundTasksAndActivityBinding后台任务和activity绑定

BackgroundTasksAndActivityBinding Since AndroidAnnotations 2.5 Like an AsyncTask, @Background...

Androidannotations——开源框架简介&简易使用准备

Androidannotations是一个Github上的开源框架,使用java注解(依赖注入)的方式,意图使Android开发代码更简洁。 下载地址:https://github.com/exci...

Android快速开发必备——依赖注入(DI)类库的选择ButterKnife,AndroidAnnotations,RoboGuice

现在做移动端开发的开发者,不管是Android和IOS,公司一般都是喜欢那种具备独立开发能力的人,因为APP项目相对较小,有时候一个人完全可以单独胜任一个项目。所以如果我们要能够具备独立开发的能力,快...

AndroidAnnotations——How It Works,AndroidAnnotation是如何工作的

How It Works Overview 概述 AndroidAnnotations works in a very simple way. It automatically adds ...

AndroidAnnotations——Enhance custom classes 优化自定义类

Enhance custom classes Since AndroidAnnotations 2.4 Enhancing custom classes 优化自定义类 You c...

AndroidAnnotations——WorkingWithThreads线程操作

WorkingWithThreads 04/03/2013 The 2.7.1 release is out Using AndroidAnnotations Get started!Do...

AndroidAnnotations——SeekBarEventsSeekBar事件

SeekBarEvents Since AndroidAnnotations 2.7 You can bind methods to handle spec...

AndroidAnnotations——Injecting Views视图注入

Injecting Views视图注入 Since AndroidAnnotations 1.0 @ViewById The @ViewById annota...

AndroidAnnotations——Injecting project Resources注入项目资源

Resources Since AndroidAnnotations 1.0 All @XXXRes annotations indicate that an ac...

AndroidAnnotations——Enhance custom views 优化自定义组件

Enhance custom views 优化自定义组件 @EView and @EViewGroup are the annotations to use if you want to c...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Androidannotations——Home主页,了解AndroidAnnotations
举报原因:
原因补充:

(最多只允许输入30个字)