Android 最火高速开发框架AndroidAnnotations使用具体解释
Android
最火的高速开发框架androidannotations配置具体解释文章中有eclipse配置步骤,Android
最火高速开发框架AndroidAnnotations简介文章中的简介,本篇注重解说AndroidAnnotations中注解方法的使用。
@EActivity
演示样例:
@EActivity(R.layout.main)
public class MyActivity extends Activity { }
@fragment
演示样例:
@EFragment(R.layout.my_fragment_layout)
public class MyFragment extends Fragment {
}
注冊:
<fragment
android:id="@+id/myFragment"
android:name="com.company.MyFragment_"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
创建:
MyFragment fragment = new MyFragment_();
普通类:
@EBean
public class MyClass { }
注意:这个类必须只只能有一个构造函数,參数最多有一个context。
Activity中使用:
@EActivity
public class MyActivity extends Activity { @Bean
MyOtherClass myOtherClass; }
也能够用来声明接口:
@Bean(MyImplementation.class)
MyInterface myInterface;
在普通类中还能够注入根环境:
@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
MyActivity myActivity; }
假设想在类创建时期做一些操作能够:
@AfterInject
public void doSomethingAfterInjection() {
// notificationManager and dependency are set
}
单例类须要例如以下声明:
@EBean(scope = Scope.Singleton)
public class MySingleton { }
注意:在单例类里面不能够注入view和事件绑定,由于单例的生命周期比Activity和Service的要长,以免发生内存溢出。
@EView
@EView
public class CustomButton extends Button { @App
MyApplication application; @StringRes
String someStringResource; public CustomButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
}
注冊:
<com.androidannotations.view.CustomButton_
android:layout_width="match_parent"
android:layout_height="wrap_content" />
创建:
CustomButton button = CustomButton_.build(context);
@EViewGroup
@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" />
@EApplication
@EApplication
public class MyApplication extends Application {
}
public class MyApplication extends Application { }
@EActivity
public class MyActivity extends Activity { @App
MyApplication application; }
@EService
public class MyService extends Service { }
MyService_.intent(getApplication()).start();
MyService_.intent(getApplication()).stop();
@EReceiver
public class MyReceiver extends BroadcastReceiver { }
@EActivity
public class MyActivity extends Activity { @Receiver(actions = "org.androidannotations.ACTION_1")
protected void onAction1() { } }
@EProvider
public class MyContentProvider extends ContentProvider { }
@EActivity
public class MyActivity extends Activity { // Injects R.id.myEditText,变量名称必须和布局的id名称一致
@ViewById
EditText myEditText; @ViewById(R.id.myTextView)
TextView textView;
}
@EActivity(R.layout.main)
public class MyActivity extends Activity { @ViewById
TextView myTextView; @AfterViews
void updateTextWithDate() {//一定要在这里进行view的一些设置,不要在oncreate()中设置,由于oncreate()在运行时 view还没有注入myTextView.setText("Date: " + new Date()); }[...]
@EActivity
public class MyActivity extends Activity { @StringRes(R.string.hello)
String myHelloString;//不能设置成私有变量 @StringRes
String hello; }
@EActivity
public class MyActivity extends Activity { @ColorRes(R.color.backgroundColor)
int someColor; @ColorRes
int backgroundColor; }
@EActivity
public class MyActivity extends Activity { @AnimationRes(R.anim.fadein)
XmlResourceParser xmlResAnim; @AnimationRes
Animation fadein; }
@EActivity
public class MyActivity extends Activity { @DimensionRes(R.dimen.fontsize)
float fontSizeDimension; @DimensionRes
float fontsize; }
@EActivity
public class MyActivity extends Activity { @DimensionPixelOffsetRes(R.string.fontsize)
int fontSizeDimension; @DimensionPixelOffsetRes
int fontsize; }
@EActivity
public class MyActivity extends Activity { @DimensionPixelSizeRes(R.string.fontsize)
int fontSizeDimension; @DimensionPixelSizeRes
int fontsize; }
@BooleanRes@ColorStateListRes@DrawableRes@IntArrayRes@IntegerRes@LayoutRes@MovieRes@TextRes@TextArrayRes@StringArrayRes
@EActivity
public class MyActivity extends Activity { @Extra("myStringExtra")
String myMessage; @Extra("myDateExtra")
Date myDateExtraWithDefaultValue = new Date(); }
@EActivity
public class MyActivity extends Activity { // The name of the extra will be "myMessage",名字必须一致
@Extra
String myMessage;
}
MyActivity_.intent().myMessage("hello").start() ;
@EActivity
public class MyActivity extends Activity {//
@SystemService
NotificationManager notificationManager; }
@EActivity
public class MyActivity extends Activity { // Injects R.string.hello_html
@HtmlRes(R.string.hello_html)
Spanned myHelloString; // Also injects R.string.hello_html
@HtmlRes
CharSequence helloHtml; }
@EActivity
public class MyActivity extends Activity {//必须用在TextView @ViewById(R.id.my_text_view)
@FromHtml(R.string.hello_html)
TextView textView; // Injects R.string.hello_html into the R.id.hello_html view
@ViewById
@FromHtml
TextView helloHtml; }
public class MyActivity extends Activity {//等同于 Activity.onRetainNonConfigurationInstance()
@NonConfigurationInstance
Bitmap someBitmap;
@NonConfigurationInstance
@Bean
MyBackgroundTask myBackgroundTask;
}
@HttpsClient
HttpClient httpsClient;
@EActivity
public class MyActivity extends Activity { @HttpsClient(trustStore=R.raw.cacerts,
trustStorePwd="changeit",
hostnameVerif=true)
HttpClient httpsClient; @AfterInject
@Background
public void securedRequest() {
try {
HttpGet httpget = new HttpGet("https://www.verisign.com/");
HttpResponse response = httpsClient.execute(httpget);
doSomethingWithResponse(response);
} catch (Exception e) {
e.printStackTrace();
}
} @UiThread
public void doSomethingWithResponse(HttpResponse resp) {
Toast.makeText(this, "HTTP status " + resp.getStatusLine().getStatusCode(), Toast.LENGTH_LONG).show();
}
}
@EFragment
public class MyFragment extends Fragment {//等同于 Fragment Argument @FragmentArg("myStringArgument")
String myMessage; @FragmentArg
String anotherStringArgument; @FragmentArg("myDateExtra")
Date myDateArgumentWithDefaultValue = new Date(); }
MyFragment myFragment = MyFragment_.builder()
.myMessage("Hello")
.anotherStringArgument("World")
.build();
@Click(R.id.myButton)
void myButtonWasClicked() {
[...]
}
@Click
void anotherButton() {//假设不指定则函数名和id相应
[...]
}
@Click
void yetAnotherButton(View clickedView) {
[...]
}
- Clicks with
@Click - Long clicks with
@LongClick - Touches with
@Touch
AdapterViewEvents
- Item clicks with
@ItemClick - Long item clicks with
@ItemLongClick - Item selection with
@ItemSelect
有两种方式调用:
@EActivity(R.layout.my_list)
public class MyListActivity extends Activity { // ... @ItemClick
public void myListItemClicked(MyItem clickedItem) {//MyItem是adapter的实体类,等同于adapter.getItem(position) } @ItemLongClick
public void myListItemLongClicked(MyItem clickedItem) { } @ItemSelect
public void myListItemSelected(boolean selected, MyItem selectedItem) { } }
@EActivity(R.layout.my_list)
public class MyListActivity extends Activity { // ... @ItemClick
public void myListItemClicked(int position) {//位置id } @ItemLongClick
public void myListItemLongClicked(int position) { } @ItemSelect
public void myListItemSelected(boolean selected, int position) { } }
//等同于SeekBar.OnSeekBarChangeListener.onProgressChanged(SeekBar, int, boolean)
@SeekBarProgressChange(R.id.seekBar)
void onProgressChangeOnSeekBar(SeekBar seekBar, int progress, boolean fromUser) {
// Something Here
} @SeekBarProgressChange(R.id.seekBar)
void onProgressChangeOnSeekBar(SeekBar seekBar, int progress) {
// Something Here
} @SeekBarProgressChange({R.id.seekBar1, R.id.seekBar2})
void onProgressChangeOnSeekBar(SeekBar seekBar) {
// Something Here
} @SeekBarProgressChange({R.id.seekBar1, R.id.seekBar2})
void onProgressChangeOnSeekBar() {
// Something Here
}
@TextChange(R.id.helloTextView)
void onTextChangesOnHelloTextView(CharSequence text, TextView hello, int before, int start, int count) {
// Something Here
} @TextChange
void helloTextViewTextChanged(TextView hello) {
// Something Here
} @TextChange({R.id.editText, R.id.helloTextView})
void onTextChangesOnSomeTextViews(TextView tv, CharSequence text) {
// Something Here
} @TextChange(R.id.helloTextView)
void onTextChangesOnHelloTextView() {
// Something Here
}
@BeforeTextChange(R.id.helloTextView)
void beforeTextChangedOnHelloTextView(TextView hello, CharSequence text, int start, int count, int after) {
// Something Here
} @BeforeTextChange
void helloTextViewBeforeTextChanged(TextView hello) {
// Something Here
} @BeforeTextChange({R.id.editText, R.id.helloTextView})
void beforeTextChangedOnSomeTextViews(TextView tv, CharSequence text) {
// Something Here
} @BeforeTextChange(R.id.helloTextView)
void beforeTextChangedOnHelloTextView() {
// Something Here
}
@AfterTextChange(R.id.helloTextView)
void afterTextChangedOnHelloTextView(Editable text, TextView hello) {
// Something Here
} @AfterTextChange
void helloTextViewAfterTextChanged(TextView hello) {
// Something Here
} @AfterTextChange({R.id.editText, R.id.helloTextView})
void afterTextChangedOnSomeTextViews(TextView tv, Editable text) {
// Something Here
} @AfterTextChange(R.id.helloTextView)
void afterTextChangedOnHelloTextView() {
// Something Here
}
@EActivity
@OptionsMenu(R.menu.my_menu)
public class MyActivity extends Activity { @OptionMenuItem
MenuItem menuSearch; @OptionsItem(R.id.menuShare)
void myMethod() {
// You can specify the ID in the annotation, or use the naming convention
} @OptionsItem
void homeSelected() {
// home was selected in the action bar
// The "Selected" keyword is optional
} @OptionsItem
boolean menuSearch() {
menuSearch.setVisible(false);
// menuSearch was selected
// the return type may be void or boolean (false to allow normal menu processing to proceed, true to consume it here)
return true;
} @OptionsItem({ R.id.menu_search, R.id.menu_delete })
void multipleMenuItems() {
// You can specify multiple menu item IDs in @OptionsItem
} @OptionsItem
void menu_add(MenuItem item) {
// You can add a MenuItem parameter to access it
}
}
@EActivity
@OptionsMenu({R.menu.my_menu1, R.menu.my_menu2})
public class MyActivity extends Activity { }
void myMethod() {
someBackgroundWork("hello", 42);
}
@Background
void someBackgroundWork(String aParam, long anotherParam) {
[...]
}
void myMethod() {
someCancellableBackground("hello", 42);
[...]
boolean mayInterruptIfRunning = true;
BackgroundExecutor.cancelAll("cancellable_task", mayInterruptIfRunning);
}
@Background(id="cancellable_task")
void someCancellableBackground(String aParam, long anotherParam) {
[...]
}
void myMethod() {
for (int i = 0; i < 10; i++)
someSequentialBackgroundMethod(i);
}
@Background(serial = "test")
void someSequentialBackgroundMethod(int i) {
SystemClock.sleep(new Random().nextInt(2000)+1000);
Log.d("AA", "value : " + i);
}
@Background(delay=2000)
void doInBackgroundAfterTwoSeconds() {
}
void myMethod() {
doInUiThread("hello", 42);
}
@UiThread
void doInUiThread(String aParam, long anotherParam) {
[...]
}
@UiThread(delay=2000)
void doInUiThreadAfterTwoSeconds() {
}
@UiThread(propagation = Propagation.REUSE)
void runInSameThreadIfOnUiThread() {
}
@EActivity
public class MyActivity extends Activity { @Background
void doSomeStuffInBackground() {
publishProgress(0);
// Do some stuff
publishProgress(10);
// Do some stuff
publishProgress(100);
} @UiThread
void publishProgress(int progress) {
// Update progress views
} }
@OnActivityResult(REQUEST_CODE)
void onResult(int resultCode, Intent data) {
} @OnActivityResult(REQUEST_CODE)
void onResult(int resultCode) {
} @OnActivityResult(ANOTHER_REQUEST_CODE)
void onResult(Intent data) {
} @OnActivityResult(ANOTHER_REQUEST_CODE)
void onResult() {
}
Android 最火高速开发框架AndroidAnnotations使用具体解释的更多相关文章
- Android 最火高速开发框架AndroidAnnotations简单介绍
在上一篇Android 最火的高速开发框架androidannotations配置具体解释中介绍了在eclipse中配置androidannotation的步骤,如需配置请參考. 1.目标 andro ...
- Android 最火的高速开发框架AndroidAnnotations使用具体解释
Android 最火的高速开发框架androidannotations配置具体解释文章中有eclipse配置步骤.Android 最火高速开发框架AndroidAnnotations简介文章中的简介. ...
- Android框架之高速开发框架xUtil
做Android开发我们通常是从原生态的開始,就是调用默认那些Android代码来开发我们的应用,可是到了一定程度,我们就想着怎么来高速开发我们的应用.这个时候我们就要着手来研究框架了. 以下介绍一个 ...
- Android 最火的高速开发框架xUtils
Github下载地址:https://github.com/wyouflf/xUtils xUtils简单介绍 xUtils 包括了非常多有用的Android工具. xUtils 最初源于Afinal ...
- 9款Android经常使用的高速开发框架
1.Afinal框架 项目地址:https://github.com/yangfuhai/afinal 项目地址:http://www.oschina.net/p/afinal 主要有四大模块: ( ...
- Android开发框架androidannotations的使用
Android开发框架AndroidAnnotations,它除了有依赖注入的特性以外,还集成了Ormlite,Spring-android中的REST模板.使用起来非常方便,大大提高了开发效率. 使 ...
- 【转】Android 最火的快速开发框架XUtils
原文:http://blog.csdn.net/rain_butterfly/article/details/37812371 最近搜了一些框架供初学者学习,比较了一下XUtils是目前git上比较活 ...
- 看大师解说Android高速开发框架EasyAndroid
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u010966622/article/details/37601789 前几天做了小应用.感觉小有成就 ...
- android mvp高速开发框架介绍(dileber的简单介绍)
今天我为大家介绍一款android mvp框架:dileber(https://github.com/dileber/dileber.git) 官方交流qq群:171443726 我个人qq:2971 ...
随机推荐
- QQ邮箱添加公司邮箱步骤
经领导提示,发现QQ邮箱可以添加公司邮箱.这样,在有同事出差在外的时候,可以通过QQWEB邮箱,即可收发公司邮箱,不必安装邮箱客户端软件. 仅供各位同事参考使用. 1.打开QQ邮箱 2.点击其他邮箱, ...
- iOS开发App上传的三大步骤
上传流程 1.itunse connect中->“我的App”中新建创建应用,填写相关的信息 a.项目名称(多创建几个),避免重名 b.想好应用的类型 c.应用截图(5.5,4.7,4,3.5寸 ...
- Cpu实验
实验十一.基于符合ISO/IEC 7816 标准协议的CPU卡RATS.PPS请求指令操作 实验目的 1.学习和了解ISO/IEC 7816标准. 2.学习和了解ATS各字节的具体定义. 3.学习和了 ...
- BZOJ 1458: 士兵占领( 网络流 )
先判无解 把整个棋盘都放上士兵, 只需求最多可以拿走多少个士兵即可.每一行看做一个点r(i), 每一列看做一个点c(i) S->r(i), c(i)->T 连边, 容量为可以拿走的最大士兵 ...
- BZOJ 4034: [HAOI2015]T2( 树链剖分 )
树链剖分...子树的树链剖分序必定是一段区间 , 先记录一下就好了 ------------------------------------------------------------------ ...
- BZOJ 1742: [Usaco2005 nov]Grazing on the Run 边跑边吃草( dp )
dp... dp( l , r , k ) , 表示 吃了[ l , r ] 的草 , k = 1 表示最后在 r 处 , k = 0 表示最后在 l 处 . ------------------- ...
- Python之路Day9
摘要: 协程 Select\Poll\Epoll异步IO与事件驱动 Python连接MySQL数据库操作 RabbitMQ队列 Redis\Memcached缓存 Paramiko Twsited网络 ...
- 设计模式(七)组合模式Composite(结构型)
设计模式(七)组合模式Composite(结构型) 1. 概述 在数据结构里面,树结构是很重要,我们可以把树的结构应用到设计模式里面. 例子1:就是多级树形菜单. 例子2:文件和文件夹目录 2.问题 ...
- hdu 1528 Card Game Cheater ( 二分图匹配 )
题目:点击打开链接 题意:两个人纸牌游戏,牌大的人得分.牌大:2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < T < J < ...
- CentOS的配置文件
/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置. /etc/bashrc:为每一个 ...