Java Code Examples for io.reactivex.Observable.observeOn()

The following are Jave code examples for showing how to use observeOn() of the io.reactivex.Observable class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: SimpleMarkdown   File: EditFragment.java   View Source Code Vote up 6 votes
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_edit, container, false);
    unbinder = ButterKnife.bind(this, view);
    ((MarkdownApplication) getActivity().getApplication()).getComponent().inject(this);
    Observable<String> obs = RxTextView.textChanges(markdownEditor)
            .debounce(50, TimeUnit.MILLISECONDS).map(CharSequence::toString);
    obs.subscribeOn(Schedulers.io());
    obs.observeOn(AndroidSchedulers.mainThread());
    obs.subscribe(markdown -> {
        presenter.onMarkdownEdited(markdown);
    });
    return view;
}
 
Example 2
Project: GitHub   File: RxSchedulers.java   View Source Code Vote up 5 votes
public <T> ObservableTransformer<T, T> applyObservableMainThread() {
    return new ObservableTransformer<T, T>() {
        @Override
        public ObservableSource<T> apply(Observable<T> observable) {
            return observable.observeOn(AndroidSchedulers.mainThread());
        }
    };
}
 
Example 3
Project: super-volley   File: ObserveOnMainCallAdapterFactory.java   View Source Code Vote up 5 votes
@Override
public CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, SuperVolley volley) {
    if (getRawType(returnType) != Observable.class) {
        return null; // Ignore non-Observable types.
    }

    // Look up the next call adapter which would otherwise be used if this one was not present.
    //noinspection unchecked returnType checked above to be Observable.
    final CallAdapter<Object, Observable<?>> delegate =
            (CallAdapter<Object, Observable<?>>) volley.nextCallAdapter(this, returnType,
                    annotations);

    return new CallAdapter<Object, Object>() {
        @Override
        public Object adapt(Call<Object> call) {
            // Delegate to get the normal Observable...
            Observable<?> o = delegate.adapt(call);
            // ...and change it to send notifications to the observer on the specified scheduler.
            return o.observeOn(scheduler);
        }

        @Override
        public Type responseType() {
            return delegate.responseType();
        }
    };
}
 
Example 4
Project: RxJava2-Android-Sample   File: RxSchedulers.java   View Source Code Vote up 5 votes
public <T> ObservableTransformer<T, T> applyObservableMainThread() {
    return new ObservableTransformer<T, T>() {
        @Override
        public ObservableSource<T> apply(Observable<T> observable) {
            return observable.observeOn(AndroidSchedulers.mainThread());
        }
    };
}