本文整理匯總了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());
}