Java 类rx.android.schedulers.HandlerScheduler 实例源码

项目:RxJava_RxAndroid    文件:MainActivity.java   
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 + ")");
                }
            });
}
项目:Orpheus    文件:PlaybackService.java   
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);
}
项目:SyncthingAndroid    文件:EventMonitor.java   
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));
}
项目:Android-Gradle-Samples    文件:DemoRxAndroidFragment.java   
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);
                }
            });
}
项目:Orpheus    文件:ArtworkFetcherModule.java   
@Provides @ArtworkFetcherScope @Named("ObserveOnScheduler")
public Scheduler provideObserveOnScheduler() {
    return HandlerScheduler.from(new Handler(service.getHandlerThread().getLooper()));
}
项目:android-52Kit    文件:RxUtils.java   
/**
 * <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());
        }
    };
}
项目:android-52Kit    文件:RxUtils.java   
/**
 * <p>
 * Apply the subscribeOn/observeOn transformation of computation/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, final Handler observeHandler) {
    return new Observable.Transformer<T, T>() {
        @Override
        public Observable<T> call(Observable<T> observable) {
            return observable.subscribeOn(HandlerScheduler.from(subscribeHandler))
                    .observeOn(HandlerScheduler.from(observeHandler));
        }
    };
}