码迷,mamicode.com
首页 > 移动开发 > 详细

Android应用开发框架:Android Annotations学习笔记总结

时间:2015-07-12 15:34:33      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:

 


Android应用开发框架:Android Annotations

 

Android Annotations是一个开源的框架,用于加速 Android应 用的开发,可以让你把重点放在功能的实现上,简化了代码,提升了可维护性。其实编程的开源的世界里有很多很多书本上没有但是github全球最大的程序员 社交网站和代码托管网站里有很多很多有用的项目和开源代码,比如这个Android应用开发框架Android Annotations,所以英语水平的提高势在必行啊,否则我永远只能等到翻译组翻译出来猜轮到我啃一啃新的知识,技术和应用,这样就晚了别人很多很多 步了。

特性:

•依赖注入: 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 runtime perf impact!

代码示例:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

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

    }

 

    // [...]

}

项目主页:http://www.open-open.com/lib/view/home/1367820981261

这个项目主页里可以找到下载Android Annotations的jar包。

 

然后下面就是截图示例怎么使用这Android Annotations的jar包:

技术分享

备注:一个api的jar 包放在原来已经有的libs文件夹下面,然后另一个jar 包放在自己新建一个compilb-lib文件夹下面。

 

技术分享

备注:在Java Complier中找到Anootation Processing.

如果没有很有可能的原因你使用的是安卓官方网站提供的专门用来开发安卓的配置好安卓sdk的adt-eclipse,所以就需要下载相关的配置。

技术分享

然 后选择juno安装,接着因为文件太多不易找到就在type filter text中输入要下载的Eclipse Java Development Tools,然后可能有不同版本,自然选最新的版本,或者下面勾选显示最新的版本,就会有唯一的这个Tools出来了,然后next继续点击知道联网下载 和安装,最后提示重新启动

技术分享

重新启动后,就能在Java Complier中找到Anootation Processing。

然后我们接着切入主题:

技术分享

选中Annotation Processing之后,然后勾选选中Enabel project specific settings。然后选中Annotation Processing下的Factory Path:

技术分享

也是勾选选中Enabel project specific settings,然后点击Add JARs,将文件夹下的compile-lib下的jar 包添加进去,然后应用,然后ok。这样就能使用这个Android Annotations开源jar包了。

 

下面就简单的说明怎么使用以及使用的效果,你可以和你原来正规情况下的安卓应用程序开发相对比,你就知道这个Android Annotations开源项目带来的好处是多么大了。

 

 

 

 

 

 

使用过程示例:

1、首先在Manifest清单文件中修改一下,就是在android:name=".MainActivity"后面加一个“_”变成android:name=".MainActivity_",先不要问为什么,这个知识点当然是Android Annotations开源项目的相关使用知识了。

技术分享

2、然后回到MainActivity.java中,实行以下的操作:

技术分享

3、然后通过自己手机运行可是成功。

技术分享

 


Android应用开发框架:Android Annotations学习笔记总结

标签:

原文地址:http://www.cnblogs.com/goodboy-heyang/p/4640899.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!