Android Annotations(1)
2024-10-14 03:37:43
Android Annotations是一个开源的框架,用于加速 Android应用的开发,可以让你把重点放在功能的实现上,简化了代码,提升了可维护性。
特性:
- 依赖注入: 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 runtimeperf impact!
@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);
} // [...]
}
一些常用注释的使用方法:
@AfterInject 定义的方法在类的构造方法执行后执行
@AfterTextChange定义的方法在TextView及其子类的Text属性改变后执行
@AfterViews 定义的方法在setContentView后执行
@Background 定义的方法在后台线程执行
@BeforeTextChange 定义的方法在TextView及其子类的Text属性改变前执行
@Click 定义点击监听器
@EActivity 在Activity中启用Annotations
@EProvider 在 ContentProvider中启用Annotations
@EReceive 在BroadcastReceiver中启用Annotations
@EService 在Service中启用Annotations
@EView 在自定义的View的子类中启用Annotations
@Fullscreen 全屏
@NoTitle 无标题栏
掌握这些注视对读懂利用该第三方代码开发的代码非常有帮助,同时对利用该代码开发的APK文件反编译的解释能够有更深入的了解。
最新文章
- webconfig中配置各种数据库的连接字符串(转)
- Github的命令清除
- 关于UltraEdit的两个小问题
- jenkins 邮件配置
- iOS-UIView 之 layoutMargins &; preservesSuperviewLayoutMargins 解惑
- 数独检测器:帝国理工C++作业
- 【BZOJ】2084: [Poi2010]Antisymmetry
- poj 2823 Sliding Window (单调队列入门)
- 《Java核心技术卷二》笔记(二)文件操作和内存映射文件
- java基础:数据类型
- Redis安装与基本配置(转)
- 对于querystring取值时候发生+号变空格的问题
- Windows恢复Grub引导,用grub安装ubuntu
- TortoiseSVN使用简介
- WP8.1程序开发中,如何加载本地文件资源或安装在程序包中的资源。
- 微信小程序之微信登陆 —— 微信小程序教程系列(20)
- JavaScript大师必须掌握的12个知识点
- Git——入门操作加创建账号【三】
- html/css/js-layer弹出层的初次使用
- Head First Servlets &; JSP 学习笔记 第九章 —— 使用JSTL