androidannotations摘要
2015-12-17 22:12
429 查看
Activity
@EActivity(R.layout.main) public class MyActivity extends Activity { } //在AndroidManifest.xml中这样注册activity <activity android:name=".MyListActivity_" />
—— startActivity
startActivity(this, MyListActivity_.class);
MyListActivity_.intent(context).start();
Intent intent = MyListActivity_.intent(context).get();
MyListActivity_.intent(context).flags(FLAG_ACTIVITY_CLEAR_TOP).start();//以指定启动方式启动
MyListActivity_.intent(context).myDateExtra(someDate).start();//传递数据
MyListActivity_.intent(context).startForResult(REQUEST_CODE);
MyListActivity_.intent(context).withOptions(bundle).start();
MyListActivity_.intent(context).start().withAnimation(enterAnimRes, exitAnimRes));//打开动画启动
@OnActivityResult(REQUEST_CODE) void onResult(int resultCode) { }
Services
@EService public class MyService extends IntentService { }
MyService_.intent(getApplication()).start();
Intent intent = MyService_.intent(context).build();
MyService_.intent(getApplication()).stop();//停止services
MyService_.intent(context).flags(Intent.FLAG_GRANT_READ_URI_PERMISSION).start();
IntentServices
MyIntentService_.intent(getApplication()) .myAction(“test”) .start();@EIntentService public class MyIntentService extends IntentService { public MyIntentService() { super("MyIntentService"); } @ServiceAction void mySimpleAction() { // ... } @ServiceAction void myAction(String param) { // ... } @Override protected void onHandleIntent(Intent intent) { // Do nothing here } }
Application
@EApplication public class MyApplication extends Application }
@EBean//普通类 public class MyBean { @App//application变量的声明 MyApplication application; }
Fragment
<fragment android:id="@+id/myFragment" android:name="com.company.MyFragment_"//指定name属性 android:layout_width="fill_parent" android:layout_height="fill_parent" />
@EFragment(R.layout.my_fragment_layout)//这里的要用上面指定的name public class MyFragment extends Fragment { @FragmentById(R.id.myFragment) MyFragment myFragment2; @FragmentByTag("myFragmentTag") MyFragment myFragmentTag2; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return null;//当复写oncreateview时应该return null } }
MyFragment fragment = new MyFragment_();
MyFragment fragment = MyFragment_.builder().build();
普通类 class
@EBean public class MyClass { @Bean//其它类的引用 MyOtherClass dependency; public MyClass() { // notificationManager and dependency are null } }
——-单例设计模式
@EBean(scope = Scope.Singleton) public class MySingleton { }
Receiver
@EReceiver public class MyIntentService extends BroadcastReceiver { @ReceiverAction("BROADCAST_ACTION_NAME") void mySimpleAction(Intent intent) { // ... } @ReceiverAction void myAction(@ReceiverAction.Extra String valueString, Context context) { // ... } @ReceiverAction void anotherAction(@ReceiverAction.Extra("specialExtraName") String valueString, @ReceiverAction.Extra long valueLong) {//Parcelable 和Serializable // ... } @Override public void onReceive(Context context, Intent intent) { // empty, will be overridden in generated subclass } }
View
@EView public class CustomButton extends Button { public CustomButton(Context context, AttributeSet attrs) { super(context, attrs); } }
//在xml中这样使用
<com.androidannotations.view.CustomButton_ android:layout_width="match_parent" android:layout_height="wrap_content" />
CustomButton button = CustomButton_.build(context);
ViewGroup
<?xml version="1.0" encoding="utf-8"?> <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/check" /> <TextView android:id="@+id/title" android:layout_toLeftOf="@+id/image" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="@android:color/white" android:textSize="12pt" /> <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="10pt" /> </merge>
//自定义组合控件
@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); } }
//使用
<com.androidannotations.viewgroup.TitleWithSubtitle_ android:id="@+id/firstTitle" android:layout_width="match_parent" android:layout_height="wrap_content" />
ContentProvider
@EProvider public class MyContentProvider extends ContentProvider { }
Injection
@ViewById@ViewById(R.id.myTextView) TextView textView;
@AfterViews
//这个可替代activity中的initView,操作ui要在这个方法中,不能在oncreate(),
void updateTextWithDate() { myTextView.setText("Date: " + new Date()); }
@AfterInject
//在类中声明的其它的构造函数调用后,还没有注射字段这之间做的事
public void doSomethingAfterInjection() { // notificationManager and dependency are set }
@ViewsById
//用于list和view
@ViewsById({R.id.myTextView1, R.id.myOtherTextView}) List<TextView> textViews;
@AfterExtras
//在注射额外代码之后执行
@AfterExtras public void doSomethingAfterExtrasInjection() { // someExtra and anotherExtra are set to the value contained in the incoming intent // if an intent does not contain one of the extra values the field remains unchanged }
@SystemService
@SystemService NotificationManager notificationManager;
@RootContext
@RootContext Context context;
相关文章推荐
- Android 对话框简单写法
- Ubuntu15.10 编译 Android5.0 源码
- 谷歌安卓官方文档之已知的问题
- 国内android资源备份很全的一个站
- Android系统各版本号及代号
- Android如何设置背景透明、开关输入法、改变标题栏颜色、layer-list
- Android SlidingMenu 开源项目 侧拉菜单的使用(详细配置)
- Android SlidingMenu 使用详解
- Android中获取全局Context
- android WebView加载 assets html文件
- Android 最简单的导航栏实现
- 1、Android代码命名规范
- android--调用系统相机拍照,显示并保存照片 - zhengwen
- Android高效率编码-细节,控件,架包,功能,工具,开源汇总,你想要的这里都有
- Android中JNI的使用方法
- Android 判断当前网络状态
- Android AsyncTask onProgressUpdate 方法的些许研究
- Android之取消ViewPage+Fragment的预加载
- 【Android图片加载框架】制作自己的图片加载框架
- Android学习之核心组件Activity的生命周期