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 {}
注冊:
<fragmentandroid: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 {@BeanMyOtherClass myOtherClass;}
也能够用来声明接口:
@Bean(MyImplementation.class)MyInterface myInterface;
在普通类中还能够注入根环境:
@EBean public class MyClass {@RootContextContext context;// Only injected if the root context is an activity@RootContextActivity activity;// Only injected if the root context is a service@RootContextService service;// Only injected if the root context is an instance of MyActivity@RootContextMyActivity myActivity;}
假设想在类创建时期做一些操作能够:
@AfterInjectpublic void doSomethingAfterInjection() {// notificationManager and dependency are set}
单例类须要例如以下声明:
@EBean(scope = Scope.Singleton) public class MySingleton {}
注意:在单例类里面不能够注入view和事件绑定,由于单例的生命周期比Activity和Service的要长,以免发生内存溢出。
@EView
@EView public class CustomButton extends Button {@AppMyApplication application;@StringResString 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 {@ViewByIdprotected 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 {}
@EActivity public class MyActivity extends Activity {@AppMyApplication 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名称一致@ViewByIdEditText myEditText;@ViewById(R.id.myTextView)TextView textView; }
@EActivity(R.layout.main) public class MyActivity extends Activity {@ViewByIdTextView myTextView;@AfterViewsvoid updateTextWithDate() {
//一定要在这里进行view的一些设置,不要在oncreate()中设置,由于oncreate()在运行时 view还没有注入
myTextView.setText("Date: " + new Date()); }[...]
@EActivity public class MyActivity extends Activity {@StringRes(R.string.hello)String myHelloString;//不能设置成私有变量@StringResString hello;}
@EActivity public class MyActivity extends Activity {@ColorRes(R.color.backgroundColor)int someColor;@ColorResint backgroundColor;}
@EActivity public class MyActivity extends Activity {@AnimationRes(R.anim.fadein)XmlResourceParser xmlResAnim;@AnimationResAnimation fadein;}
@EActivity public class MyActivity extends Activity {@DimensionRes(R.dimen.fontsize)float fontSizeDimension;@DimensionResfloat fontsize;}
@EActivity public class MyActivity extends Activity {@DimensionPixelOffsetRes(R.string.fontsize)int fontSizeDimension;@DimensionPixelOffsetResint fontsize;}
@EActivity public class MyActivity extends Activity {@DimensionPixelSizeRes(R.string.fontsize)int fontSizeDimension;@DimensionPixelSizeResint 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",名字必须一致@ExtraString myMessage; }
MyActivity_.intent().myMessage("hello").start() ;
@EActivity public class MyActivity extends Activity {//@SystemServiceNotificationManager 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@HtmlResCharSequence 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@FromHtmlTextView helloHtml;}
public class MyActivity extends Activity {//等同于 Activity.onRetainNonConfigurationInstance()@NonConfigurationInstanceBitmap someBitmap;@NonConfigurationInstance@BeanMyBackgroundTask myBackgroundTask;}
@HttpsClient HttpClient httpsClient;
@EActivity public class MyActivity extends Activity {@HttpsClient(trustStore=R.raw.cacerts,trustStorePwd="changeit", hostnameVerif=true)HttpClient httpsClient;@AfterInject@Backgroundpublic void securedRequest() {try {HttpGet httpget = new HttpGet("https://www.verisign.com/");HttpResponse response = httpsClient.execute(httpget);doSomethingWithResponse(response);} catch (Exception e) {e.printStackTrace();}}@UiThreadpublic 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;@FragmentArgString 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 {// ...@ItemClickpublic void myListItemClicked(MyItem clickedItem) {//MyItem是adapter的实体类,等同于adapter.getItem(position)}@ItemLongClickpublic void myListItemLongClicked(MyItem clickedItem) {}@ItemSelectpublic void myListItemSelected(boolean selected, MyItem selectedItem) {}}
@EActivity(R.layout.my_list) public class MyListActivity extends Activity {// ...@ItemClickpublic void myListItemClicked(int position) {//位置id}@ItemLongClickpublic void myListItemLongClicked(int position) {}@ItemSelectpublic 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}@TextChangevoid 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}@BeforeTextChangevoid 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}@AfterTextChangevoid 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 {@OptionMenuItemMenuItem menuSearch;@OptionsItem(R.id.menuShare)void myMethod() {// You can specify the ID in the annotation, or use the naming convention}@OptionsItemvoid homeSelected() {// home was selected in the action bar// The "Selected" keyword is optional}@OptionsItemboolean 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}@OptionsItemvoid 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 {@Backgroundvoid doSomeStuffInBackground() {publishProgress(0);// Do some stuffpublishProgress(10);// Do some stuffpublishProgress(100);}@UiThreadvoid 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() {}
转载于:https://www.cnblogs.com/zfyouxi/p/4188005.html
Android 最火高速开发框架AndroidAnnotations使用具体解释相关推荐
- 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 最火的快速开发框架XUtils
最近搜了一些框架供初学者学习,比较了一下XUtils是目前git上比较活跃 功能比较完善的一个框架,是基于afinal开发的,比afinal稳定性提高了不少,下面是介绍: 鉴于大家的热情,我又写了一篇 ...
- 【转】Android 最火的快速开发框架XUtils
原文:http://blog.csdn.net/rain_butterfly/article/details/37812371 最近搜了一些框架供初学者学习,比较了一下XUtils是目前git上比较活 ...
- 【转】Android 最火框架XUtils之注解机制详解
原文:http://blog.csdn.net/rain_butterfly/article/details/37931031 在上一篇文章Android 最火的快速开发框架XUtils中简单介绍了x ...
- GitHub Android 最火开源项目Top20
GitHub Android 最火开源项目Top20 GitHub 上的开源项目不胜枚举,越来越多的开源项目正在迁移到GitHub平台上.基于不要重复造轮子的原则,了解当下比较流行的Android与i ...
- 9款Android常用的快速开发框架
9款Android常用的快速开发框架 Android 2015-08-24 11:05:08 发布 您的评价: 0.0 收藏 0收藏 1.Afinal框架 项目地址:https ...
- joa-framework 工作流高速开发框架(jeecg官方工作流版本号) 公布
-------------------------------------- version: joa-framework1.0.0.beta 版本号: JOA 工作流高速开发框架 Da ...
- 嘿,来做一个“币”的生意吗?Android仿火币K线图实现!
描述 Android仿火币K线图实现(包含MA,BOLL,MACD,KDJ,RSI,WR指标) 项目运行效果 配置使用 <com.github.fujianlian.klinechart.KLi ...
最新文章
- 如何禁用<textarea>的调整大小抓取器? [重复]
- ASP.NET自带的散列加密口令【转】
- Idea运行项目报错:java.lang.OutOfMemoryError: Java heap space/ java.lang.OutOfMemoryError: GC overhead 解决方法
- 路由器 VS OSI七层模型
- method java_解析Java中的Field类和Method类
- 华中科技大学计算机应用基础作业答案,《计算机应用基础》试题.doc
- 利用HTML+JS+CSS实现简单的网页计算器,附html所有源代码,可直接黏贴运行
- 大数据平台搭建包含哪些层级
- TagSL框架设计(1)----先来点简介
- JVM内存模型及CMS、G1和ZGC垃圾回收器详解
- 犹太人和你想的不一样
- 解决 EIGEN_STACK_ALLOCATION_LIMIT, OBJECT_ALLOCATED_ON_STACK_IS_TOO_BIG 报错
- 简单网络管理协议SNMP通讯基础篇-熊健-专题视频课程
- 黑马程序员----------Java新特性反射 泛型
- 【嵌入式系统】STM32时钟系统+时钟配置函数解析
- 计算机科学和交互设计,交互设计(超越人机交互原书第5版)/计算机科学丛书
- 8个Linux命令及开关机命令
- 基于Python的堆优化单源最短路径
- 期货交易的安全性分析
- YY一下微信线下支付的场景
热门文章
- 【java】画图和监听事件的应用
- python集合的定义方式_11-Python基础知识学习—集合类型
- 学了一年matlab,我到现在还不会读论文~
- 【新书】python+tensorflow机器学习实战,详解19种机器学习经典算法
- yum 安装mysql 5.0_CentOS 通过 yum 安装 Mysql 5.0
- leetcode链表中的两数相加问题
- python etree htm参数_使用etree.HTML的编码问题
- @configuration注解_Spring注解@Configuration
- 螺钉装弹垫平垫机器人_一种批量组装螺钉、弹垫、平垫的工装及使用方法
- 什么原数据更容易平稳_为什么老年人更容易患上艾滋病?