This file contains 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); |
This file contains 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 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 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 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 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
mBackground.execute(new Runnable() { | |
@Override | |
public void run() { | |
try { | |
initDatabaseInternal(); | |
mBackground.post(new DatabaseLoadedEvent()); | |
} catch (Exception e) { | |
Log.e("Failed to init db", e); |
This file contains 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 SplashActivity extends Activity { | |
@Override | |
protected void onStart() { | |
super.onStart(); | |
eventBus.register(this); | |
} | |
@Override | |
protected void onStop() { |
This file contains 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 void postEventOnUiThread(final Object event) { | |
mUiHandler.post(new Runnable() { | |
@Override | |
public void run() { | |
mEventBus.post(event); | |
} | |
}); | |
} |
This file contains 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 SplashActivity extends Activity { | |
@Subscribe | |
public void on(DatabaseLoadedEvent event) { | |
runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
progressBar.setVisibility(View.GONE); | |
showMainActivity(); | |
} |
This file contains 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 abstract class Scheduler { | |
@NonNull | |
public Disposable scheduleDirect(@NonNull Runnable run) { ... } | |
@NonNull | |
public Disposable scheduleDirect(@NonNull Runnable run, long delay, @NonNull TimeUnit unit) { ... } | |
@NonNull | |
public Disposable schedulePeriodicallyDirect(@NonNull Runnable run, long initialDelay, long period, @NonNull TimeUnit unit) { ... } { |
OlderNewer