Skip to content

Commit 8e79ba0

Browse files
committed
rename
1 parent 63a17cf commit 8e79ba0

File tree

12 files changed

+59
-50
lines changed

12 files changed

+59
-50
lines changed

README-ch.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
## 基本结构
1010
![结构图](http://img.blog.csdn.net/20150203125508110)
11-
AndroidEventBus类似于观察者模式,通过register函数将需要订阅事件的对象注册到事件总线中,然后根据@Subcriber注解来查找对象中的订阅方法,并且将这些订阅方法和订阅对象存储在map中。当用户在某个地方发布一个事件时,事件总线根据事件的参数类型和tag找到对应的订阅者对象,最后执行订阅者对象中的方法。这些订阅方法会执行在用户指定的线程模型中,比如mode=ThreadMode.ASYNC则表示该订阅方法执行在子线程中,更多细节请看下面的说明。
11+
AndroidEventBus类似于观察者模式,通过register函数将需要订阅事件的对象注册到事件总线中,然后根据@Subscriber注解来查找对象中的订阅方法,并且将这些订阅方法和订阅对象存储在map中。当用户在某个地方发布一个事件时,事件总线根据事件的参数类型和tag找到对应的订阅者对象,最后执行订阅者对象中的方法。这些订阅方法会执行在用户指定的线程模型中,比如mode=ThreadMode.ASYNC则表示该订阅方法执行在子线程中,更多细节请看下面的说明。
1212

1313
## 使用AndroidEventBus
1414
你可以按照下面几个步骤来使用AndroidEventBus.
@@ -46,26 +46,26 @@ public class YourActivity extends Activity {
4646
// code ......
4747
4848
// 接收方法,默认的tag,执行在UI线程
49-
@Subcriber
49+
@Subscriber
5050
private void updateUser(User user) {
5151
Log.e("", "### update user name = " + user.name);
5252
}
5353
5454
// 含有my_tag,当用户post事件时,只有指定了"my_tag"的事件才会触发该函数,执行在UI线程
55-
@Subcriber(tag = "my_tag")
55+
@Subscriber(tag = "my_tag")
5656
private void updateUserWithTag(User user) {
5757
Log.e("", "### update user with my_tag, name = " + user.name);
5858
}
5959
6060
// 含有my_tag,当用户post事件时,只有指定了"my_tag"的事件才会触发该函数,
6161
// post函数在哪个线程执行,该函数就执行在哪个线程
62-
@Subcriber(tag = "my_tag", mode=ThreadMode.POST)
62+
@Subscriber(tag = "my_tag", mode=ThreadMode.POST)
6363
private void updateUserWithMode(User user) {
6464
Log.e("", "### update user with my_tag, name = " + user.name);
6565
}
6666
6767
// 含有my_tag,当用户post事件时,只有指定了"my_tag"的事件才会触发该函数,执行在一个独立的线程
68-
@Subcriber(tag = "my_tag", mode = ThreadMode.ASYNC)
68+
@Subscriber(tag = "my_tag", mode = ThreadMode.ASYNC)
6969
private void updateUserAsync(User user) {
7070
Log.e("", "### update user async , name = " + user.name + ", thread name = " + Thread.currentThread().getName());
7171
}
@@ -143,6 +143,14 @@ private void onEventMainThread(User aUser) {
143143

144144
这就是AndroidEventBus和greenrobot的EventBus的不同,当然greenrobot出于性能的考虑这么处理也可以理解,但是我们在应用中发布的事件数量是很有限的,性能差异可以忽略,但使用体验上却是很直接的。另外由于本人对greenrobot的EventBus前世今生并不是很了解,很可能上述我所说的有误,如果是那样,欢迎您指出。
145145

146+
### 与EventBus、otto的特性对比
147+
148+
| 名称 | 订阅函数是否可执行在其他线程 | 特点 |
149+
|---------------------|-----------------------|
150+
| [greenrobot的EventBus](https://github.com/greenrobot/EventBus) | 是 | 使用name pattern模式,效率高,但使用不方便。
151+
| [square的otto](https://github.com/square/otto) | 否 | 使用注解,使用方便,但效率比不了EventBus。
152+
| [AndroidEventBus]() || 使用注解,使用方便,但效率比不上EventBus。订阅函数支持tag(类似广播接收器的Action)使得事件的投递更加准确,能适应更多使用场景。 |
153+
146154

147155
## 使用了AndroidEventBus的已知App
148156
* [Accupass - Events around you](https://play.google.com/store/apps/details?id=com.accuvally.android.accupass)
@@ -164,7 +172,7 @@ private void onEventMainThread(User aUser) {
164172

165173

166174
### v1.0 ( 2015.2.9 )
167-
1. 事件总线框架发布,使用@Subcriber注解标识订阅方法
175+
1. 事件总线框架发布,使用@Subscriber注解标识订阅方法
168176
2. 订阅方法支持tag标识,使得事件投递更加精准。
169177

170178

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,28 @@ public class YourActivity extends Activity {
4646
// code ......
4747
4848
// A receiving method with a default tag will execute on UI thread.
49-
@Subcriber
49+
@Subscriber
5050
private void updateUser(User user) {
5151
Log.e("", "### update user name = " + user.name);
5252
}
5353
5454
// When there is a “my_tag”, only events designated with “my_tag” can
5555
// trigger the function and execute on UI thread when a user posts an event.
56-
@Subcriber(tag = "my_tag")
56+
@Subscriber(tag = "my_tag")
5757
private void updateUserWithTag(User user) {
5858
Log.e("", "### update user with my_tag, name = " + user.name);
5959
}
6060
6161
// When there is a “my_tag”, only events designated with “my_tag” can trigger the function.
6262
// The function will execute on the same thread as the one post function is executed on.
63-
@Subcriber(tag = "my_tag", mode=ThreadMode.POST)
63+
@Subscriber(tag = "my_tag", mode=ThreadMode.POST)
6464
private void updateUserWithMode(User user) {
6565
Log.e("", "### update user with my_tag, name = " + user.name);
6666
}
6767
6868
// When there is a “my_tag”, only events designated with “my_tag” can trigger
6969
// the function and execute on an independent thread when a user posts an event.
70-
@Subcriber(tag = "my_tag", mode = ThreadMode.ASYNC)
70+
@Subscriber(tag = "my_tag", mode = ThreadMode.ASYNC)
7171
private void updateUserAsync(User user) {
7272
Log.e("", "### update user async , name = " + user.name + ", thread name = " + Thread.currentThread().getName());
7373
}
@@ -181,3 +181,4 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
181181
See the License for the specific language governing permissions and
182182
limitations under the License.
183183
```
184+
Subscriber

Simple_Event_Test/src/org/simple/eventbus/test/DefaultMatchPolicyTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
import org.simple.eventbus.EventBus;
3030
import org.simple.eventbus.EventType;
31-
import org.simple.eventbus.Subcriber;
31+
import org.simple.eventbus.Subscriber;
3232
import org.simple.eventbus.matchpolicy.DefaultMatchPolicy;
3333
import org.simple.eventbus.matchpolicy.MatchPolicy;
3434
import org.simple.eventbus.test.mock.User;
@@ -54,12 +54,12 @@ protected void tearDown() throws Exception {
5454
EventBus.getDefault().unregister(this);
5555
}
5656

57-
@Subcriber
57+
@Subscriber
5858
private void whatEver(User user) {
5959

6060
}
6161

62-
@Subcriber
62+
@Subscriber
6363
private void singleObjectParam(Object obj) {
6464

6565
}

Simple_Event_Test/src/org/simple/eventbus/test/ThreadModeTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import android.util.Log;
2929

3030
import org.simple.eventbus.EventBus;
31-
import org.simple.eventbus.Subcriber;
31+
import org.simple.eventbus.Subscriber;
3232
import org.simple.eventbus.ThreadMode;
3333
import org.simple.eventbus.handler.AsyncEventHandler;
3434
import org.simple.eventbus.test.mock.User;
@@ -59,7 +59,7 @@ public void testExecuteMainThread() {
5959
waitDispatchEvent();
6060
}
6161

62-
@Subcriber(tag = MAIN_TAG)
62+
@Subscriber(tag = MAIN_TAG)
6363
private void executeOnUIThread(User user) {
6464
assertEquals("main-thread", user.name);
6565
// can not test main thread mode
@@ -71,7 +71,7 @@ public void testExecutePostThread() {
7171
waitDispatchEvent();
7272
}
7373

74-
@Subcriber(tag = POST_TAG, mode = ThreadMode.POST)
74+
@Subscriber(tag = POST_TAG, mode = ThreadMode.POST)
7575
private void executeOnPostThread(User user) {
7676
assertEquals("post-thread", user.name);
7777
assertEquals(uiThread, Thread.currentThread());
@@ -82,7 +82,7 @@ public void testExecuteAsyncThread() {
8282
waitDispatchEvent();
8383
}
8484

85-
@Subcriber(tag = ASYNC_TAG, mode = ThreadMode.ASYNC)
85+
@Subscriber(tag = ASYNC_TAG, mode = ThreadMode.ASYNC)
8686
private void executeOnAsyncThread(User user) {
8787
assertEquals("async-thread", user.name);
8888
Log.e(getName(), "### executeOnAsyncThread flag");

Simple_Event_Test/src/org/simple/eventbus/test/mock/MockSubcriber.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@
1616

1717
package org.simple.eventbus.test.mock;
1818

19-
import org.simple.eventbus.Subcriber;
19+
import org.simple.eventbus.Subscriber;
2020

2121
/**
2222
* @author mrsimple
2323
*/
2424
public class MockSubcriber {
2525

26-
@Subcriber
26+
@Subscriber
2727
void onEventNoParam() {
2828
}
2929

30-
@Subcriber
30+
@Subscriber
3131
void onEventTwoParam(User person, int id) {
3232

3333
}
3434

35-
@Subcriber
35+
@Subscriber
3636
void onEvent(User person) {
3737
System.out.println("invoke onEvent(Person person) in " + this.getClass().getName());
3838
System.out.println("person name = " + person.name);
@@ -43,7 +43,7 @@ void onEvent(User person) {
4343
*
4444
* @param person
4545
*/
46-
@Subcriber
46+
@Subscriber
4747
void addPerson(User person) {
4848
System.out.println("invoke addPerson(Person person) in " + this.getClass().getName());
4949
System.out.println("person name = " + person.name);
@@ -54,7 +54,7 @@ void addPerson(User person) {
5454
*
5555
* @param person
5656
*/
57-
@Subcriber(tag = "test")
57+
@Subscriber(tag = "test")
5858
void methodWithTag(User person) {
5959

6060
}
@@ -64,7 +64,7 @@ void methodWithTag(User person) {
6464
*
6565
* @param person
6666
*/
67-
@Subcriber(tag = "another")
67+
@Subscriber(tag = "another")
6868
void methodWithAnotherTag(User person) {
6969

7070
}
@@ -74,7 +74,7 @@ void methodWithAnotherTag(User person) {
7474
*
7575
* @param object
7676
*/
77-
@Subcriber
77+
@Subscriber
7878
void onEvent(Object object) {
7979
System.out.println("invoke onEvent(Person person) in " + this.getClass().getName());
8080
}

Simple_Event_Test/src/org/simple/eventbus/test/mock/PrimitiveParamObject.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,33 @@
2424

2525
package org.simple.eventbus.test.mock;
2626

27-
import org.simple.eventbus.Subcriber;
27+
import org.simple.eventbus.Subscriber;
2828

2929
/**
3030
* @author mrsimple
3131
*/
3232
public class PrimitiveParamObject {
33-
@Subcriber
33+
@Subscriber
3434
public void intParam(int aInt) {
3535

3636
}
3737

38-
@Subcriber
38+
@Subscriber
3939
public void booleanParam(boolean ab) {
4040

4141
}
4242

43-
@Subcriber
43+
@Subscriber
4444
public void floatParam(float aFloat) {
4545

4646
}
4747

48-
@Subcriber
48+
@Subscriber
4949
public void doubleParam(double aDouble) {
5050

5151
}
5252

53-
@Subcriber
53+
@Subscriber
5454
public void intArrayParam(int[] ints) {
5555

5656
}

Simple_Event_Test/src/org/simple/eventbus/test/mock/SingleSubscriber.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616

1717
package org.simple.eventbus.test.mock;
1818

19-
import org.simple.eventbus.Subcriber;
19+
import org.simple.eventbus.Subscriber;
2020

2121
/**
2222
* @author mrsimple
2323
*/
2424
public class SingleSubscriber {
25-
@Subcriber
25+
@Subscriber
2626
void onEvent(Object event) {
2727
System.out.println("invoke onEvent(Object event) in " + this.getClass().getName());
2828
}

Simple_eventbus_demo/src/org/simple/eventbus/demo/fragment/BaseFragment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import android.support.v4.app.Fragment;
2828
import android.util.Log;
2929

30-
import org.simple.eventbus.Subcriber;
30+
import org.simple.eventbus.Subscriber;
3131
import org.simple.eventbus.demo.bean.User;
3232

3333
/**
@@ -37,7 +37,7 @@ public class BaseFragment extends Fragment {
3737

3838
static final String SUPER_TAG = "super_tag";
3939

40-
@Subcriber(tag = SUPER_TAG)
40+
@Subscriber(tag = SUPER_TAG)
4141
private void privateMethodInSuper(User user) {
4242
Log.e(getTag(), "### supper private Method In Super invoked ( default tag ) ");
4343
}

Simple_eventbus_demo/src/org/simple/eventbus/demo/fragment/ConstactFragment.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import android.widget.Toast;
3030

3131
import org.simple.eventbus.EventBus;
32-
import org.simple.eventbus.Subcriber;
32+
import org.simple.eventbus.Subscriber;
3333
import org.simple.eventbus.ThreadMode;
3434
import org.simple.eventbus.demo.R;
3535
import org.simple.eventbus.demo.bean.User;
@@ -72,18 +72,18 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
7272
});
7373
}
7474

75-
@Subcriber
75+
@Subscriber
7676
private void primitiveParam(int aInt) {
7777
Toast.makeText(getActivity(), "int = " + aInt, Toast.LENGTH_SHORT).show();
7878
}
7979

80-
@Subcriber
80+
@Subscriber
8181
private void primitiveArrayParam(int[] aInt) {
8282
Toast.makeText(getActivity(), "int array = " + aInt[0] + ", " + aInt[1], Toast.LENGTH_SHORT)
8383
.show();
8484
}
8585

86-
@Subcriber
86+
@Subscriber
8787
private void primitiveParam(boolean ab) {
8888
Toast.makeText(getActivity(), "boolean = " + ab, Toast.LENGTH_SHORT).show();
8989
}
@@ -103,7 +103,7 @@ private void mockDatas() {
103103
/**
104104
* @param person
105105
*/
106-
@Subcriber
106+
@Subscriber
107107
public void addPerson(User person) {
108108
mConstacts.add(person);
109109
mAdapter.notifyDataSetChanged();
@@ -114,7 +114,7 @@ public void addPerson(User person) {
114114
*
115115
* @param person
116116
*/
117-
@Subcriber(tag = MenuFragment.REMOVE_TAG)
117+
@Subscriber(tag = MenuFragment.REMOVE_TAG)
118118
private void removePersonPrivate(User person) {
119119
mConstacts.remove(person);
120120
mAdapter.notifyDataSetChanged();
@@ -125,7 +125,7 @@ private void removePersonPrivate(User person) {
125125
*
126126
* @param event
127127
*/
128-
@Subcriber(tag = MenuFragment.ASYNC_TAG, mode = ThreadMode.ASYNC)
128+
@Subscriber(tag = MenuFragment.ASYNC_TAG, mode = ThreadMode.ASYNC)
129129
private void asyncMethod(final User person) {
130130
try {
131131
final String threadName = Thread.currentThread().getName();

0 commit comments

Comments
 (0)