This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Background { | |
private final Bus mEventBus; | |
public void postEvent(final Object event) { | |
mEventBus.post(event); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Background { | |
... | |
private final Handler mUiHandler; | |
public void postOnUiThread(final Runnable runnable) { | |
mUiHandler.post(runnable); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Background { | |
private final ExecutorService mService = new ScheduledThreadPoolExecutor(5); | |
public Future<?> execute(Runnable runnable) { | |
return mService.submit(runnable); | |
} | |
public <T> Future<T> submit(Callable<T> runnable) { | |
return mService.submit(runnable); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final class PerThreadQueuedDispatcher extends Dispatcher { | |
private final ThreadLocal<Queue<Event>> queue = | |
new ThreadLocal<Queue<Event>>() { | |
@Override | |
protected Queue<Event> initialValue() { | |
return Queues.newArrayDeque(); | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EventBus { | |
private final SubscriberRegistry subscribers = new SubscriberRegistry(this); | |
public void register(Object object) { | |
subscribers.register(object); | |
} | |
public void unregister(Object object) { | |
subscribers.unregister(object); |
NewerOlder