Android快速开发工具:AndroidAnnotations:
16lz
2021-01-26
Android快速开发工具:AndroidAnnotations:
00Android.jpggithub 地址: https://github.com/excilys/androidannotations
目标:
--加快安卓开发
--减少重复代码
--使开发者有更多的事件去思考核心业务代码
实现:
基于Java的注解原理,开发者直接使用注解展示他们的意图,然后AndroidAnnotations会自动帮我们生成代码,使得很多重复冗余的代码只需要一行代码就解决掉。
特征:
--1.依赖注入: inject(注解) views, extras, system services, resources, ...
--2.简化的线程模型:annotate your methods so that they execute on the UI thread or on a background thread.
--3.事件绑定:annotate methods to handle events on views, no more ugly anonymous listener classes!
--4.REST client:REST client: create a client interface, AndroidAnnotations generates the implementation
--5.AndroidAnnotations 这个工具比较小,低于150kb
Code Example:
==================================================
@EActivity(R.layout.translate) // Sets content view to R.layout.translate
public class TranslateActivity extends Activity {
@ViewById // Injects R.id.textInputEditText textInput;@ViewById(R.id.myTextView) // Injects R.id.myTextViewTextView result;@AnimationRes // Injects android.R.anim.fade_inAnimation fadeIn;@Click // When R.id.doTranslate button is clicked void doTranslate() { translateInBackground(textInput.getText().toString());}@Background // Executed in a background threadvoid translateInBackground(String textToTranslate) { String translatedText = callGoogleTranslate(textToTranslate); showResult(translatedText);}@UiThread // Executed in the ui threadvoid showResult(String translatedText) { result.setText(translatedText); result.startAnimation(fadeIn);}// [...
}
更多相关文章
- 解决 Android(安卓)N 上报错:android.os.FileUriExposedException
- ContentProvider拾遗
- Android(安卓)studio button 按钮 四种绑定事件的方法【实例代码
- android上的JAVA8:使用retrolambda
- android创建optionsmenu的方法
- Android屏幕切换
- 小白学习android: google code 上源代码的下载方法
- Android(安卓)开发中使用Linux Shell实例详解
- Android(安卓)代码审计工具和常见问题