Skip to content

Commit

Permalink
+):添加了EventBus 消息总线框架源码分析相关实例以及Otto框架性能对比文章
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangqqlmj committed Nov 4, 2015
1 parent d38e341 commit ad20848
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Android在线学习网站(项目驱动学习)网站:<a href="http://www.cniao5.c
<a href="http://blog.csdn.net/developer_jiangqq/article/details/49612399">非常漂亮的进度指示器AVLoadingIndicatorView的使用讲解(十八)</a></br>
<a href="http://blog.csdn.net/developer_jiangqq/article/details/49613861">Android MVP开发模式详解(十九)</a></br>
<a href="http://blog.csdn.net/developer_jiangqq/article/details/49617189">消息总线EventBus的基本使用(二十)</a></br>
<a href="http://blog.csdn.net/developer_jiangqq/article/details/49640153">消息总线EventBus源码分析以及与Otto框架对比(二十一)</a></br>
<a href="http://blog.csdn.net/developer_jiangqq">更多项目内容请详见CSDN博客!</a></br>

后期会持续不断进行更新最新的框架功能,如果有一起合作把这个Android快速开发框架完善起来的~请联系我哦<br/>
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/com/chinaztt/fda/event/TestEventSecond.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.chinaztt.fda.event;

/**
* 当前类注释:EventBus测试 First事件类
* 项目名:FastDev4Android
* 包名:com.chinaztt.fda.event
* 作者:江清清 on 15/11/4 10:54
* 邮箱:[email protected]
* QQ: 781931404
* 公司:江苏中天科技软件技术有限公司
*/
public class TestEventSecond {
private String msg;

public String getMsg() {
return msg;
}

public void setMsg(String msg) {
this.msg = msg;
}

public TestEventSecond(String msg){
this.msg=msg;
}
}
26 changes: 26 additions & 0 deletions app/src/main/java/com/chinaztt/fda/event/TestEventThird.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.chinaztt.fda.event;

/**
* 当前类注释:
* 项目名:FastDev4Android
* 包名:com.chinaztt.fda.event
* 作者:江清清 on 15/11/4 10:55
* 邮箱:[email protected]
* QQ: 781931404
* 公司:江苏中天科技软件技术有限公司
*/
public class TestEventThird {
private String msg;

public String getMsg() {
return msg;
}

public void setMsg(String msg) {
this.msg = msg;
}

public TestEventThird(String msg){
this.msg=msg;
}
}
30 changes: 27 additions & 3 deletions app/src/main/java/com/chinaztt/fda/test/EventBusTestActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import android.widget.Toast;

import com.chinaztt.fda.event.TestEventFirst;
import com.chinaztt.fda.event.TestEventSecond;
import com.chinaztt.fda.event.TestEventThird;
import com.chinaztt.fda.ui.R;
import com.chinaztt.fda.ui.base.BaseActivity;
import com.chinaztt.fda.utils.Log;
Expand All @@ -30,7 +32,7 @@
@EActivity
public class EventBusTestActivity extends BaseActivity{
Button button_one;
TextView textView_one;
TextView textView_one,textView_two,textView_third;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -39,6 +41,8 @@ protected void onCreate(Bundle savedInstanceState) {
EventBus.getDefault().register(this);
button_one=(Button)this.findViewById(R.id.button_one);
textView_one=(TextView)this.findViewById(R.id.textView_one);
textView_two=(TextView)this.findViewById(R.id.textView_two);
textView_third=(TextView)this.findViewById(R.id.textView_third);
button_one.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -51,9 +55,29 @@ public void onClick(View v) {
* @param event
*/
public void onEventMainThread(TestEventFirst event) {

Log.d("zttjiangqq","onEventMainThread收到消息:"+event.getMsg());
textView_one.setText(event.getMsg());
showToastMsgShort(event.getMsg());
//showToastMsgShort(event.getMsg());
}
/**
* 收到消息 进行相关处理
* @param event
*/
public void onEventMainThread(TestEventSecond event) {

Log.d("zttjiangqq","onEventMainThread收到消息:"+event.getMsg());
textView_two.setText(event.getMsg());
//showToastMsgShort(event.getMsg());
}
/**
* 收到消息 进行相关处理
* @param event
*/
public void onEventMainThread(TestEventThird event) {

Log.d("zttjiangqq","onEventMainThread收到消息:"+event.getMsg());
textView_third.setText(event.getMsg());
//showToastMsgShort(event.getMsg());
}
@Override
protected void onDestroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.widget.Button;

import com.chinaztt.fda.event.TestEventFirst;
import com.chinaztt.fda.event.TestEventSecond;
import com.chinaztt.fda.event.TestEventThird;
import com.chinaztt.fda.ui.R;
import com.chinaztt.fda.ui.base.BaseActivity;

Expand All @@ -25,17 +27,33 @@
*/
@EActivity
public class EventBusTestTwoActivity extends BaseActivity {
Button button_two;
Button button_one,button_two,button_third;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.event_bus_test_two_layout);
button_one=(Button)this.findViewById(R.id.button_one);
button_two=(Button)this.findViewById(R.id.button_two);
button_third=(Button)this.findViewById(R.id.button_third);
button_one.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EventBus.getDefault().post(new TestEventFirst("One Event button"));
//EventBusTestTwoActivity.this.finish();
}
});
button_two.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EventBus.getDefault().post(new TestEventFirst("我是第二个Activity回传的信息...."));
EventBusTestTwoActivity.this.finish();
EventBus.getDefault().post(new TestEventSecond("Two Event button"));
//EventBusTestTwoActivity.this.finish();
}
});
button_third.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EventBus.getDefault().post(new TestEventThird("Third Event button"));
//EventBusTestTwoActivity.this.finish();
}
});
}
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout/event_bus_test_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,14 @@
android:layout_height="45dp"
android:text="这边显示消息内容..."
android:id="@+id/textView_one" />
<TextView
android:layout_width="wrap_content"
android:layout_height="45dp"
android:text="这边显示消息内容..."
android:id="@+id/textView_two" />
<TextView
android:layout_width="wrap_content"
android:layout_height="45dp"
android:text="这边显示消息内容..."
android:id="@+id/textView_third" />
</LinearLayout>
17 changes: 11 additions & 6 deletions app/src/main/res/layout/event_bus_test_two_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第二个Activity的按钮"
android:id="@+id/button_two" />
android:text="One Event Button"
android:id="@+id/button_one" />

<TextView
<Button
android:layout_width="wrap_content"
android:layout_height="45dp"
android:text="当前为第二个Activity"
android:id="@+id/textView_two" />
android:layout_height="wrap_content"
android:text="Two Event Button"
android:id="@+id/button_two" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Third Event Button"
android:id="@+id/button_third" />
</LinearLayout>

0 comments on commit ad20848

Please sign in to comment.