本文整理汇总了Java中io.reactivex.Observable.subscribeOn方法的典型用法代码示例。如果您正苦于以下问题:Java Observable.subscribeOn方法的具体用法?Java Observable.subscribeOn怎么用?Java Observable.subscribeOn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.Observable
的用法示例。
在下文中一共展示了Observable.subscribeOn方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreateView
import io.reactivex.Observable; //导入方法依赖的package包/类
@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;
}
示例2: adapt
import io.reactivex.Observable; //导入方法依赖的package包/类
@Override public Object adapt(Call<R> call) {
Observable<Response<R>> responseObservable = isAsync
? new CallEnqueueObservable<>(call)
: new CallExecuteObservable<>(call);
Observable<?> observable;
if (isResult) {
observable = new ResultObservable<>(responseObservable);
} else if (isBody) {
observable = new BodyObservable<>(responseObservable);
} else {
observable = responseObservable;
}
if (scheduler != null) {
observable = observable.subscribeOn(scheduler);
}
if (isFlowable) {
return observable.toFlowable(BackpressureStrategy.LATEST);
}
if (isSingle) {
return observable.singleOrError();
}
if (isMaybe) {
return observable.singleElement();
}
if (isCompletable) {
return observable.ignoreElements();
}
return observable;
}
示例3: adapt
import io.reactivex.Observable; //导入方法依赖的package包/类
@Override public Object adapt(Call<R> call) {
if (call.request().body() == null) {
throw new IllegalStateException("can't execute requestbody progress task, specify request not exist requestbody: " + call.request());
}
Observable<ProgressBean<Response<R>>> responseObservable = isAsync
? new CallEnqueueWithProgressObservable<>(call)
: new CallExecuteWithProgressObservable<>(call);
Observable<?> observable;
if (isResult) {
observable = new ResultWithProgressObservable<>(responseObservable);
} else if (isBody) {
observable = new BodyWithProgressObservable<>(responseObservable);
} else {
observable = responseObservable;
}
if (scheduler != null) {
observable = observable.subscribeOn(scheduler);
}
if (isFlowable) {
return observable.toFlowable(BackpressureStrategy.LATEST);
}
if (isSingle) {
return observable.singleOrError();
}
if (isMaybe) {
return observable.singleElement();
}
if (isCompletable) {
return observable.ignoreElements();
}
return observable;
}
开发者ID:imfms,项目名称:retrofit-rxjava-request-with-progress,代码行数:38,代码来源:RxJava2WithProgressCallAdapter.java
示例4: adapt
import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public Object adapt(Call<R> call) {
Observable<Response<R>> responseObservable = new CallObservable<>(call);
Observable<?> observable;
if (isResult) {
observable = new ResultObservable<>(responseObservable);
} else if (isBody) {
observable = new BodyObservable<>(responseObservable);
} else {
observable = responseObservable;
}
if (scheduler != null) {
observable = observable.subscribeOn(scheduler);
}
if (isFlowable) {
return observable.toFlowable(BackpressureStrategy.LATEST);
}
if (isSingle) {
return observable.singleOrError();
}
if (isMaybe) {
return observable.singleElement();
}
if (isCompletable) {
return observable.ignoreElements();
}
return observable;
}
示例5: observe
import io.reactivex.Observable; //导入方法依赖的package包/类
/**
* RxNetworkInfo connectivity observable with all the original {@link NetworkInfo} information
* that uses custom defined {@link NetworkObservingStrategy strategy}.
*
* @param strategy custom {@link NetworkObservingStrategy} instance
*
* @return RxJava Observable with {@link RxNetworkInfo} containing network information
*/
@NonNull
@RequiresPermission(ACCESS_NETWORK_STATE)
public Observable<RxNetworkInfo> observe(@NonNull NetworkObservingStrategy strategy) {
checkNotNullWithMessage(strategy, "Please provide network observing strategy or initialize"
+ " RxNetwork with proper Context to use the default one");
final Observable<RxNetworkInfo> observable = strategy.observe();
if (scheduler != null) {
observable.subscribeOn(scheduler);
}
return observable;
}
示例6: observeInternetAccess
import io.reactivex.Observable; //导入方法依赖的package包/类
/**
* Real internet access observable with custom defined {@link InternetObservingStrategy strategy}.
*
* @param strategy custom {@link InternetObservingStrategy} instance
*
* @return RxJava Observable with {@code Boolean} ( {@code true} if there is real internet access,
* {@code false} if not )
*/
@NonNull
@RequiresPermission(INTERNET)
public Observable<Boolean> observeInternetAccess(@NonNull InternetObservingStrategy strategy) {
checkNotNull(strategy, "internet observing strategy");
final Observable<Boolean> observable = strategy.observe();
if (scheduler != null) {
observable.subscribeOn(scheduler);
}
return observable;
}
示例7: download
import io.reactivex.Observable; //导入方法依赖的package包/类
public static Observable<DownloadProgress> download(final URI url, final OutputStream output) {
Preconditions.checkNotNull(url);
Preconditions.checkNotNull(output);
final Observable<DownloadProgress> observable = Observable.create(emitter -> {
final OkHttpClient client = new OkHttpClient.Builder()
.followRedirects(true)
.followSslRedirects(true)
.build();
final Request request = new Request.Builder()
.url(url.toURL())
.build();
final Response response = client.newCall(request).execute();
try {
if (!response.isSuccessful()) {
throw new IOException("Unexpected code " + response);
}
final InputStream input = new BufferedInputStream(response.body().byteStream());
final byte[] data = new byte[1024];
final long contentLength = response.body().contentLength();
long total = 0;
if (!emitter.isDisposed()) {
emitter.onNext(DownloadProgress.of(total, contentLength));
}
int count;
long lastCount = 0;
long lastEmissionCount = 0;
while ((count = input.read(data)) != -1) {
if (emitter.isDisposed()) {
break;
}
total += count;
output.write(data, 0, count);
if ((total - lastCount) >= PROGRESS_REPORT_EVERY_N_BYTES) {
lastEmissionCount = total;
emitter.onNext(DownloadProgress.of(total, contentLength));
}
lastCount = total;
}
output.flush();
output.close();
input.close();
if (emitter.isDisposed()) {
return;
}
if (lastEmissionCount != total) {
emitter.onNext(DownloadProgress.of(total, contentLength));
}
emitter.onComplete();
} catch (final Throwable e) {
if (!emitter.isDisposed()) {
emitter.onError(e);
}
}
});
return observable.subscribeOn(Schedulers.io());
}