22 | * Unhandled errors will be delivered to the scheduler Thread's {@link java.lang.Thread.UncaughtExceptionHandler}. 23 | */ 24 | NEW_THREAD, 25 | 26 | /** 27 | * Creates and returns a {@link Scheduler} intended for IO-bound work. 28 | *
29 | * The implementation is backed by an {@link Executor} thread-pool that will grow as needed. 30 | *
31 | * This can be used for asynchronously performing blocking IO. 32 | *
33 | * Do not perform computational work on this scheduler. Use computation() instead. 34 | *
35 | * Unhandled errors will be delivered to the scheduler Thread's {@link java.lang.Thread.UncaughtExceptionHandler}. 36 | */ 37 | IO, 38 | 39 | /** 40 | * Creates and returns a {@link Scheduler} intended for computational work. 41 | *
42 | * This can be used for event-loops, processing callbacks and other computational work. 43 | *
44 | * Do not perform IO-bound work on this scheduler. Use io() instead. 45 | *
46 | * Unhandled errors will be delivered to the scheduler Thread's {@link java.lang.Thread.UncaughtExceptionHandler}.
47 | */
48 | COMPUTATION,
49 |
50 | /**
51 | * Creates and returns a {@link Scheduler} that queues work on the current thread to be executed after the
52 | * current work completes.
53 | */
54 | TRAMPOLINE,
55 |
56 | /**
57 | * Creates and returns a {@link Scheduler} that executes work immediately on the current thread.
58 | */
59 | IMMEDIATE,
60 |
61 | /**
62 | * Converts an {@link Executor} into a new Scheduler instance.
63 | */
64 | EXECUTOR,
65 |
66 | /**
67 | * {@link Scheduler} which uses the provided {@link Handler} to execute actions.
68 | */
69 | HANDLER
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/wangjie/rxandroideventssample/annotation/accept/AcceptType.java:
--------------------------------------------------------------------------------
1 | package com.wangjie.rxandroideventssample.annotation.accept;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Author: wangjie
10 | * Email: tiantian.china.2@gmail.com
11 | * Date: 6/11/15.
12 | */
13 | @Retention(RetentionPolicy.RUNTIME)
14 | @Target({ElementType.METHOD})
15 | public @interface AcceptType {
16 | String tag() default "";
17 |
18 | Class clazz() default Object.class;
19 | }
20 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/wangjie/rxandroideventssample/annotation/accept/DefaultAcceptConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.wangjie.rxandroideventssample.annotation.accept;
2 |
3 | import android.os.Handler;
4 |
5 | import java.util.concurrent.Executor;
6 |
7 | /**
8 | * Author: wangjie
9 | * Email: tiantian.china.2@gmail.com
10 | * Date: 6/15/15.
11 | */
12 | public class DefaultAcceptConfiguration {
13 | public interface OnDefaultAcceptConfiguration {
14 | /**
15 | * 配置默认的Accept Executor
16 | *
17 | * @return
18 | */
19 | Executor applyAcceptExecutor();
20 |
21 | /**
22 | * 配置默认的Handler
23 | *
24 | * @return
25 | */
26 | Handler applyAcceptHandler();
27 | }
28 |
29 | private static DefaultAcceptConfiguration configuration;
30 |
31 | public static DefaultAcceptConfiguration getInstance() {
32 | if (null == configuration) {
33 | configuration = new DefaultAcceptConfiguration();
34 | }
35 | return configuration;
36 | }
37 |
38 | private OnDefaultAcceptConfiguration onDefaultAcceptConfiguration;
39 |
40 | public void registerAcceptConfiguration(OnDefaultAcceptConfiguration onDefaultAcceptConfiguration) {
41 | this.onDefaultAcceptConfiguration = onDefaultAcceptConfiguration;
42 | }
43 |
44 | private DefaultAcceptConfiguration() {
45 | }
46 |
47 | /**
48 | * 配置默认的Accept Executor
49 | *
50 | * @return
51 | */
52 | public Executor applyAcceptExecutor() {
53 | return null == onDefaultAcceptConfiguration ? null : onDefaultAcceptConfiguration.applyAcceptExecutor();
54 | }
55 |
56 | /**
57 | * 配置默认的Handler
58 | *
59 | * @return
60 | */
61 | public Handler applyAcceptHandler() {
62 | return null == onDefaultAcceptConfiguration ? null : onDefaultAcceptConfiguration.applyAcceptHandler();
63 | }
64 |
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/wangjie/rxandroideventssample/application/MyApplication.java:
--------------------------------------------------------------------------------
1 | package com.wangjie.rxandroideventssample.application;
2 |
3 | import android.app.Application;
4 | import android.os.Handler;
5 | import android.os.Looper;
6 | import com.wangjie.rxandroideventssample.annotation.accept.DefaultAcceptConfiguration;
7 | import com.wangjie.rxandroideventssample.rxbus.RxBus;
8 |
9 | import java.util.concurrent.Executor;
10 | import java.util.concurrent.Executors;
11 |
12 | /**
13 | * Author: wangjie
14 | * Email: tiantian.china.2@gmail.com
15 | * Date: 6/15/15.
16 | */
17 | public class MyApplication extends Application {
18 | private Executor acceptExecutor = Executors.newCachedThreadPool();
19 | private Handler handler = new Handler(Looper.getMainLooper());
20 |
21 | @Override
22 | public void onCreate() {
23 | super.onCreate();
24 | RxBus.DEBUG = true;
25 |
26 | DefaultAcceptConfiguration.getInstance().registerAcceptConfiguration(new DefaultAcceptConfiguration.OnDefaultAcceptConfiguration() {
27 | @Override
28 | public Executor applyAcceptExecutor() {
29 | return acceptExecutor;
30 | }
31 |
32 | @Override
33 | public Handler applyAcceptHandler() {
34 | return handler;
35 | }
36 | });
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/wangjie/rxandroideventssample/base/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.wangjie.rxandroideventssample.base;
2 |
3 | import com.wangjie.androidinject.annotation.present.AIAppCompatActivity;
4 | import com.wangjie.rxandroideventssample.annotation.accept.Accept;
5 | import com.wangjie.rxandroideventssample.rxbus.RxBusAnnotationManager;
6 | import com.wangjie.rxandroideventssample.rxbus.RxBusSample;
7 |
8 | import java.lang.reflect.Method;
9 |
10 | /**
11 | * Author: wangjie
12 | * Email: tiantian.china.2@gmail.com
13 | * Date: 6/10/15.
14 | */
15 | public class BaseActivity extends AIAppCompatActivity implements RxBusSample{
16 |
17 | private RxBusAnnotationManager rxBusAnnotationManager;
18 |
19 | @Override
20 | public void parserMethodAnnotations(Method method) throws Exception {
21 | if (method.isAnnotationPresent(Accept.class)) {
22 | if (null == rxBusAnnotationManager) {
23 | rxBusAnnotationManager = new RxBusAnnotationManager(this);
24 | }
25 | rxBusAnnotationManager.parserObservableEventAnnotations(method);
26 | }
27 | }
28 |
29 |
30 | @Override
31 | protected void onDestroy() {
32 | super.onDestroy();
33 | if (null != rxBusAnnotationManager) {
34 | rxBusAnnotationManager.clear();
35 | }
36 | }
37 |
38 | @Override
39 | public void onPostAccept(Object tag, Object event) {
40 |
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/wangjie/rxandroideventssample/base/BasePresenter.java:
--------------------------------------------------------------------------------
1 | package com.wangjie.rxandroideventssample.base;
2 |
3 | import com.wangjie.androidbucket.log.Logger;
4 | import com.wangjie.androidbucket.mvp.ABActivityViewer;
5 | import com.wangjie.androidbucket.mvp.ABBasePresenter;
6 | import com.wangjie.androidbucket.mvp.ABInteractor;
7 | import rx.Subscription;
8 |
9 | import java.util.HashSet;
10 | import java.util.Iterator;
11 | import java.util.Set;
12 |
13 | /**
14 | * Author: wangjie
15 | * Email: tiantian.china.2@gmail.com
16 | * Date: 6/10/15.
17 | */
18 | public class BasePresenter