- 浏览: 17677 次
- 性别:
- 来自: 沈阳
文章分类
最新评论
@EBean
注意:这个类必须仅仅只能有一个构造函数,参数最多有一个context。
你可以在@EBean标注的类里使用其他注解
使用与界面相关的的注解
还可以注入根环境
如果想在类创建时期做一些操作可以这样写
Scopes参数
这个参数有两种
default:每次都注入
singleton:只注入一次,单例的
@Bean
Activity中使用这个类
也可以注入到接口
@EService
示例代码
在这个类里你也可以使用其他的绝大多数的AndroidAnnotations 注解。
当你要运行这个Service是用如下代码
注意那个“_”,调用的时候不能写你类的名称,而是要在类名后面加上“_”
当然 你也能结束这个Service
@EIntentService
异步Service的注解,当然在这个类里你也可以使用其他的绝大多数的AndroidAnnotations 注解。
启动方式
@EReceiver
对于Android BroadcastReceiver类你可以使用这个注解,当然在这个类里你也可以使用其他的绝大多数的AndroidAnnotations 注解。
示例代码
@ReceiverAction
@ReceiverAction 简单的广播接收器,对接收到的消息进行处理
示例代码
@Receiver
你在 activity/fragment/service 中可以直接使用@Receiver,而不需要定义一个BroadcastReceiver
@EProvider
在Android Content Provider类中使用这个注解
@EView
定义之后,我们就能在我们的布局文件中使用这个View了,但值得注意的是类名后面工加上“_”
当然我们也可以通过代码的方式使用这个View
@EViewGroup
这里,我们先定义这个ViewGroup的布局文件
然后使用@EViewGroup注解开发ViewGroup类
这样,我们的自定义的ViewGroup类的完成了,我们可以这样使用这个类
在我们要使用这个ViewGroup的View布局文件中,增加如下代码
不知道你注意到没有,在这个ViewGroup的类名后同样增加了“_”
然后我们在这个Activity类中写如下代码
@EFragment
在一个Fragment上使用androidannotations 注解,使用@EFragment
当然,我们在这个类中也可以使用其他的androidannotations 注解
我们可以这样使用这个类,在我们要使用这个Fragment的View布局文件中,增加如下代码
不知道你注意到没有,在这个Fragment的类名后同样增加了“_”
当然我们也可以通过代码的方式使用这个Fragment
让Fragment与一个布局绑定的标准方式是这样的
当然使用@EFragment注解后我们可以这样写:
@FragmentById、@FragmentByTag
你可以在@EActivity, @EFragment, @EView, @EViewGroup, @EBean,中使用@FragmentById or @FragmentByTag这两个注解。如果你不指定注解的值,他将使用你定义的字段的名称。
官网推荐使用 @FragmentById,不推荐使用@FragmentByTag。
请注意,@FragmentById and @FragmentByTag 只是使用,而不是去创建,所以你们必须在布局或代码里定义出来。
@EActivity(R.layout.fragments)
public class MyFragmentActivity extends FragmentActivity {
@FragmentById
MyFragment myFragment;
@FragmentById(R.id.myFragment)
MyFragment myFragment2;
@FragmentByTag
MyFragment myFragmentTag;
@FragmentByTag("myFragmentTag")
MyFragment myFragmentTag2;
}
@EBean public class MyClass { }
注意:这个类必须仅仅只能有一个构造函数,参数最多有一个context。
你可以在@EBean标注的类里使用其他注解
@EBean public class MyClass { @SystemService NotificationManager notificationManager; @UiThread void updateUI() { } }
使用与界面相关的的注解
@EBean public class MyClass { @ViewById(R.id.tv_test) TextView myTextView; @Click(R.id.btOk) void handleButtonClick() { } }
还可以注入根环境
@EBean public class MyClass { @RootContext Context context; // Only injected if the root context is an activity @RootContext Activity activity; // Only injected if the root context is a service @RootContext Service service; // Only injected if the root context is an instance of MyActivity @RootContext TestActivity myActivity; }
如果想在类创建时期做一些操作可以这样写
@EBean public class MyClass { @AfterInject public void doSomethingAfterInjection() { // notificationManager and dependency are set } }
Scopes参数
这个参数有两种
default:每次都注入
singleton:只注入一次,单例的
@EBean(scope = Scope.Singleton) public class MyClass { }
@Bean
Activity中使用这个类
@EActivity(R.layout.activity_test) public class TestActivity extends Activity { @Bean MyClass myclass; }
也可以注入到接口
@EActivity(R.layout.activity_test) public class TestActivity extends Activity { @Bean MyClass myclass; @Bean(MyImplementation.class) myInterface myinterface; }
@EService
示例代码
@EService public class MusicService extends Service{ }
在这个类里你也可以使用其他的绝大多数的AndroidAnnotations 注解。
@EService public class MusicService extends Service{ @SystemService NotificationManager notificationManager; @RestService MyRestClient myRestClient; @UiThread void showToast() { Toast.makeText(getApplicationContext(), "Hello World!", Toast.LENGTH_LONG).show(); } }
当你要运行这个Service是用如下代码
MusicService_.intent(getApplication()).extra("op", op).start();
注意那个“_”,调用的时候不能写你类的名称,而是要在类名后面加上“_”
当然 你也能结束这个Service
MusicService_.intent(getApplication()).stop();
@EIntentService
异步Service的注解,当然在这个类里你也可以使用其他的绝大多数的AndroidAnnotations 注解。
@EIntentService public class MyIntentService extends IntentService { @ServiceAction void mySimpleAction() { // ... } @ServiceAction void myAction(String param) { // ... } @Override protected void onHandleIntent(Intent intent) { // Do nothing here } }
启动方式
MyIntentService.intent(getApplication()) // .myAction("test") // .start();
@EReceiver
对于Android BroadcastReceiver类你可以使用这个注解,当然在这个类里你也可以使用其他的绝大多数的AndroidAnnotations 注解。
示例代码
@EReceiver public class MyReceiver extends BroadcastReceiver { @SystemService NotificationManager notificationManager; @Bean SomeObject someObject; }
@ReceiverAction
@ReceiverAction 简单的广播接收器,对接收到的消息进行处理
示例代码
@EReceiver public class MyReceiver extends BroadcastReceiver { @ReceiverAction("BROADCAST_ACTION_NAME") void mySimpleAction(Intent intent) { } @ReceiverAction void myAction(@ReceiverAction.Extra String valueString, Context context) { } @ReceiverAction void anotherAction(Context context, @ReceiverAction.Extra("specialExtraName") String valueString, @ReceiverAction.Extra long valueLong) { Toast.makeText(context, "string:"+valueString + "<->" + valueLong, 1000).show(); } @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub String action = intent.getAction(); Toast.makeText(context, "静态:"+action, 1000).show(); } }
@Receiver
你在 activity/fragment/service 中可以直接使用@Receiver,而不需要定义一个BroadcastReceiver
@EActivity(R.layout.activity_test) public class TestActivity extends Activity { { @Receiver(actions = android.bluetooth.BluetoothAdapter.ACTION_STATE_CHANGED) protected void onAction1() { Toast.makeText(this, "show ", Toast.LENGTH_LONG).show(); } }
@EProvider
在Android Content Provider类中使用这个注解
@EProvider public class MyContentProvider extends ContentProvider { @SystemService NotificationManager notificationManager; @UiThread void showToast() { Toast.makeText(getContext().getApplicationContext(), "Hello World!", Toast.LENGTH_LONG).show(); } }
@EView
@EView public class CustomButton extends Button { @App MyApplication application; @StringRes String someStringResource; public CustomButton(Context context, AttributeSet attrs) { super(context, attrs); } }
定义之后,我们就能在我们的布局文件中使用这个View了,但值得注意的是类名后面工加上“_”
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <com.androidannotations.view.CustomButton_ android:layout_width="match_parent" android:layout_height="wrap_content" /> <!-- ... --> </LinearLayout>
当然我们也可以通过代码的方式使用这个View
CustomButton button = CustomButton_.build(context);
@EViewGroup
这里,我们先定义这个ViewGroup的布局文件
<merge xmlns:android="http://schemas.android.com/apk/res/android" > <ImageView android:id="@+id/image" android:layout_alignParentRight="true" android:layout_alignBottom="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <TextView android:id="@+id/title" android:layout_toLeftOf="@+id/image" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="6pt" /> <TextView android:id="@+id/subtitle" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/title" android:textColor="#FFdedede" android:textSize="5pt" /> </merge>
然后使用@EViewGroup注解开发ViewGroup类
@EViewGroup(R.layout.title_with_subtitle) public class TitleWithSubtitle extends RelativeLayout { @ViewById protected TextView title, subtitle; public TitleWithSubtitle(Context context, AttributeSet attrs) { super(context, attrs); } public void setTexts(String titleText, String subTitleText) { title.setText(titleText); subtitle.setText(subTitleText); } }
这样,我们的自定义的ViewGroup类的完成了,我们可以这样使用这个类
在我们要使用这个ViewGroup的View布局文件中,增加如下代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.hista.weiweilove.TestActivity" > <com.hista.weiweilove.bean.TitleWithSubtitle_ android:id="@+id/firstTitle" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout>
不知道你注意到没有,在这个ViewGroup的类名后同样增加了“_”
然后我们在这个Activity类中写如下代码
@EActivity(R.layout.activity_test) public class TestActivity extends Activity { { @ViewById protected TitleWithSubtitle firstTitle; @AfterViews void afterView(){ firstTitle.setTexts("decouple your code", "Hide the component logic from the code using it."); } }
@EFragment
在一个Fragment上使用androidannotations 注解,使用@EFragment
@EFragment public class MyFragment extends Fragment { }
当然,我们在这个类中也可以使用其他的androidannotations 注解
我们可以这样使用这个类,在我们要使用这个Fragment的View布局文件中,增加如下代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <fragment android:id="@+id/myFragment" android:name="com.company.MyFragment_" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout>
不知道你注意到没有,在这个Fragment的类名后同样增加了“_”
当然我们也可以通过代码的方式使用这个Fragment
MyFragment fragment = new MyFragment_();
让Fragment与一个布局绑定的标准方式是这样的
@EFragment public class MyFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.my_fragment_layout, container, false); return view; } }
当然使用@EFragment注解后我们可以这样写:
@EFragment(R.layout.my_fragment_layout) public class MyFragment extends Fragment { }
@FragmentById、@FragmentByTag
你可以在@EActivity, @EFragment, @EView, @EViewGroup, @EBean,中使用@FragmentById or @FragmentByTag这两个注解。如果你不指定注解的值,他将使用你定义的字段的名称。
官网推荐使用 @FragmentById,不推荐使用@FragmentByTag。
请注意,@FragmentById and @FragmentByTag 只是使用,而不是去创建,所以你们必须在布局或代码里定义出来。
@EActivity(R.layout.fragments)
public class MyFragmentActivity extends FragmentActivity {
@FragmentById
MyFragment myFragment;
@FragmentById(R.id.myFragment)
MyFragment myFragment2;
@FragmentByTag
MyFragment myFragmentTag;
@FragmentByTag("myFragmentTag")
MyFragment myFragmentTag2;
}
发表评论
-
AndroidAnnotations学习笔记(七)续
2015-01-29 16:39 0@InstanceState -
AndroidAnnotations学习笔记(七)
2015-01-29 15:04 1658@InstanceState 在onSaveInstance ... -
AndroidAnnotations学习笔记--资源(六)
2015-01-29 09:09 4812所有@XXXRes 注解都是你的res文件夹所对应的Andro ... -
AndroidAnnotations学习笔记--线程(五)
2015-01-28 14:43 1529@Background 这个注解表明,这个方法将运行现UI线程 ... -
AndroidAnnotations学习笔记--事件续(四)
2015-01-28 10:11 2185@OptionsMenu、@OptionsMenuItem、@ ... -
AndroidAnnotations学习笔记--事件(三)
2015-01-28 08:50 2163@TextChange 这个注解是用于接收 android.t ... -
AndroidAnnotations学习笔记(一)
2015-01-27 12:56 2652@EActivity 原来在没用(AndroidAnnotat ...
相关推荐
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
2024嵌入式大厂面经50套大厂高频面试题资料
eclipaint-eclipse插件
该TemplateAppProject是一个基于XUI、XUtil、XAOP等框架构建的Android模版空壳工程,包含172个文件,涵盖68个Java源文件、64个XML配置文件、17个PNG图片文件、6个Gradle脚本文件、2个YAML配置文件、2个Git忽略文件、2个文本文件和1个Markdown文件。该工程集成了XPage、XUpdate和XHttp2等功能,旨在快速搭建Android应用开发环境。
IEA乌克兰的能源安全和即将到来的冬天-乌克兰及其合作伙伴的能源行动计划(英).pdf
UC-GUI文档uCGUI中文手册UC-GUI文档uCGUI中文手册
微信小程序反编译_ xapkg解包器
微信小程序婚礼邀请函_婚礼邀请函
该项目是一款基于Html和TypeScript构建的2B2C礼品购买平台源码,包含958个文件,涵盖196个TypeScript文件、145个Java文件、119个JPG图片、118个CSS文件、85个JavaScript文件、54个HTML文件、47个类文件、44个XML文件、26个PNG图片、23个Vue组件。该平台采用现代化前端技术,旨在提供一个流畅的礼品选购体验。
Fedora-Workstation-Live-x86_64-40-1.14.iso.008
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
Fedora-Workstation-Live-x86_64-40-1.14.iso.002
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
【作品名称】:基于Matlab的单水箱液位的模糊控制系统设计【含课程设计报告+程序】 【适用人群】:适用于希望学习不同技术领域的小白或进阶学习者。可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。 【项目介绍】: 控制⽬标 控制⽬标:倒锥形容器的液位⾼度h=h0 检测装置:通过测量容器底部压⼒来间接测量液位 执⾏机构:控制进⽔电磁阀V1的开启度开启度 u ∈ [0, 90 ∘ ] 受控对象:模糊控制器最终影响倒锥形容器内的⽔量,所以受控对象是倒锥形容器 为简单起⻅,假设电磁阀V1的开启度与进⽔量间呈线性关系。所以控制进⽔量Qi实际上就是控制 电磁阀V1的开启度u。 因此对于整个系统⽽⾔,模糊控制器最终控制的是电磁阀V1的开启度u,从⽽控制倒锥形容器内 的⽔量。 注意:模糊控制器受控对象是倒锥形容器,其液位⾼度h和进⽔量Qi间的关系不是线性关系 电磁阀V2的开度固定,但出⽔量Qo与倒锥形容器的液位⾼ 【资源声明】:本资源作为“参考资料”而不是“定制需求”,代码只能作为参考,不能完全复制照搬。需要有一定的基础能够看懂代码,能够自行调试代码并解决报错,能够自行添加功能修改代码。
包含RMI服务所需的内容和测试使用的攻击FastJson1反序列化漏洞的Java文件
Wanandroid微信小程序w_x-Wanandroid
Fedora-Workstation-Live-x86_64-40-1.14.iso.005
全国大学生电子设计大赛项目合集全国电赛优秀作品STM32项目基于stm32和mpu9250的usbhid键盘,鼠标,游戏控制器
那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据
AutoLine是一个基于Python的通用自动化测试开源平台,包含了657个文件,涵盖228个PNG图片、209个CSS样式、95个JavaScript脚本、39个Python源代码、21个HTML文件、19个XML文件、14个GIF图片、6个DS_Store文件、5个文本文件、4个Markdown文件。该平台的设计源码由多种编程语言编写,旨在提供灵活高效的自动化测试解决方案。