本文整理汇总了Java中rx.android.schedulers.HandlerScheduler类的典型用法代码示例。如果您正苦于以下问题:Java HandlerScheduler类的具体用法?Java HandlerScheduler怎么用?Java HandlerScheduler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HandlerScheduler类属于rx.android.schedulers包,在下文中一共展示了HandlerScheduler类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onRunSchedulerExampleButtonClicked
import rx.android.schedulers.HandlerScheduler; //导入依赖的package包/类
void onRunSchedulerExampleButtonClicked() {
sampleObservable()
// Run on a background thread
.subscribeOn(HandlerScheduler.from(backgroundHandler))
// Be notified on the main thread
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<String>() {
@Override public void onCompleted() {
Log.d(TAG, "onCompleted()");
}
@Override public void onError(Throwable e) {
Log.e(TAG, "onError()", e);
}
@Override public void onNext(String string) {
Log.d(TAG, "onNext(" + string + ")");
}
});
}
示例2: onCreate
import rx.android.schedulers.HandlerScheduler; //导入依赖的package包/类
public void onCreate(PlaybackServiceProxy proxy) {
mProxy = proxy;
//fire up thread and init handler
mHandlerThread = new HandlerThread("PlaybackServiceHandler", Process.THREAD_PRIORITY_MORE_FAVORABLE);
mHandlerThread.start();
mHandler = new Handler(mHandlerThread.getLooper());
mHandlerScheduler = HandlerScheduler.from(mHandler);
mQueueChangeListener = new PlaybackQueueQueueChangeListener();
mSessionCallback = new MediaSessionCallback();
//tell everyone about ourselves
mQueue.setListener(mQueueChangeListener);
mSessionHolder.setCallback(mSessionCallback, mHandler);
proxy.setSessionToken(mSessionHolder.getSessionToken());
setupLocalRenderer();
mHandler.post(mLoadQueueRunnable);
}
示例3: start
import rx.android.schedulers.HandlerScheduler; //导入依赖的package包/类
public synchronized void start(long delay) {
running = true;
Timber.d("start(%d) lastEvent=%d", delay, lastEvent.get());
if (handlerThread == null) {
handlerThread = new HandlerThread("EventMonitor");
handlerThread.start();
scheduler = HandlerScheduler.from(new Handler(handlerThread.getLooper()));
}
//TODO check connectivity and fail fast
eventSubscription = eventsObservable
.subscribeOn(scheduler)
.subscribe(Subscribers.from(eventsObserver));
}
示例4: onRunSchedulerExampleButtonClicked
import rx.android.schedulers.HandlerScheduler; //导入依赖的package包/类
void onRunSchedulerExampleButtonClicked() {
sampleObservable()
// Run on a background thread
.subscribeOn(HandlerScheduler.from(backgroundHandler))
// Be notified on the main thread
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<String>() {
@Override
public void onCompleted() {
Log.d(TAG, "onCompleted()");
schedulerTv.setText("onCompleted");
schedulerTv.setClickable(false);
}
@Override
public void onError(Throwable e) {
Log.e(TAG, "onError()", e);
schedulerTv.setText("onError()");
schedulerTv.setClickable(false);
}
@Override
public void onNext(String string) {
Log.d(TAG, "onNext(" + string + ")");
schedulerTv.setText("onNext(" + string + ")");
schedulerTv.setClickable(false);
}
});
}
示例5: provideObserveOnScheduler
import rx.android.schedulers.HandlerScheduler; //导入依赖的package包/类
@Provides @ArtworkFetcherScope @Named("ObserveOnScheduler")
public Scheduler provideObserveOnScheduler() {
return HandlerScheduler.from(new Handler(service.getHandlerThread().getLooper()));
}
示例6: applyCustomSchedulers
import rx.android.schedulers.HandlerScheduler; //导入依赖的package包/类
/**
* <p>
* Apply the subscribeOn/observeOn transformation of {custom_handler}/mainThread
* to an observable via compose()
* </p>
*
* <p>
* Only apply this to observables that are handling computation tasks in the background. Basically
* all non-IO work
* </p>
*
* @param <T> the transformation type
* @return the observable post-transform
*/
public static <T> Observable.Transformer<T, T> applyCustomSchedulers(final Handler subscribeHandler) {
return new Observable.Transformer<T, T>() {
@Override
public Observable<T> call(Observable<T> observable) {
return observable.subscribeOn(HandlerScheduler.from(subscribeHandler))
.observeOn(AndroidSchedulers.mainThread());
}
};
}