本文整理汇总了Java中io.reactivex.android.schedulers.AndroidSchedulers类的典型用法代码示例。如果您正苦于以下问题:Java AndroidSchedulers类的具体用法?Java AndroidSchedulers怎么用?Java AndroidSchedulers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AndroidSchedulers类属于io.reactivex.android.schedulers包,在下文中一共展示了AndroidSchedulers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRelatedItems
import io.reactivex.android.schedulers.AndroidSchedulers; //导入依赖的package包/类
private Row getRelatedItems() {
ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new CardPresenter());
final Set<Long> related = mSelectedEvent.getMetadata().getRelated().keySet();
mDisposables.add(((LeanbackBaseActivity) getActivity()).getApiServiceObservable()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
mediaApiService -> {
for (long id : related) {
mDisposables.add(mediaApiService.getEvent(id)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(event -> listRowAdapter.add(event)));
}
listRowAdapter.notifyArrayItemRangeChanged(0, listRowAdapter.size());
}
)
);
HeaderItem header = new HeaderItem(0, getString(R.string.related_talks));
return new ListRow(header, listRowAdapter);
}
示例2: onHandleParseHTML
import io.reactivex.android.schedulers.AndroidSchedulers; //导入依赖的package包/类
@Override
public void onHandleParseHTML(final String url) {
mView.showLoading(true);
Observable.create(new ObservableOnSubscribe<ArrayList<ArticleItem>>() {
@Override
public void subscribe(ObservableEmitter<ArrayList<ArticleItem>> e) throws Exception {
ArrayList<ArticleItem> list = new ArrayList<>();
Document doc = Jsoup.connect(url).get();
Elements ul = doc.getElementsByClass("list_line");
for (Element u : ul) {
Elements li = u.getElementsByTag("li");
for (Element l : li) {
String text = l.getElementsByTag("a").text();
String href = l.getElementsByTag("a").attr("href");
String time = l.getElementsByTag("span").text();
list.add(new ArticleItem(text, href, time));
}
}
e.onNext(list);
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<ArrayList<ArticleItem>>() {
@Override
public void accept(@NonNull ArrayList<ArticleItem> articleItems) throws Exception {
mView.showList(articleItems);
mView.showLoading(false);
}
});
}
示例3: fetchRepositoryDetails
import io.reactivex.android.schedulers.AndroidSchedulers; //导入依赖的package包/类
private void fetchRepositoryDetails() {
ApolloCall<EntryDetailQuery.Data> entryDetailQuery = application.apolloClient()
.query(new EntryDetailQuery(repoFullName))
.cacheControl(CacheControl.CACHE_FIRST);
//Example call using Rx2Support
disposables.add(Rx2Apollo.from(entryDetailQuery)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver<Response<EntryDetailQuery.Data>>() {
@Override
public void onSuccess(Response<EntryDetailQuery.Data> dataResponse) {
setEntryData(dataResponse.data());
}
@Override
public void onError(Throwable e) {
Log.e(TAG, e.getMessage(), e);
}
}));
}
示例4: getCompanies
import io.reactivex.android.schedulers.AndroidSchedulers; //导入依赖的package包/类
private void getCompanies() {
Disposable disposable = companiesRepository
.getCompanies()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableObserver<List<Company>>() {
@Override
public void onNext(List<Company> value) {
view.showCompanies(value);
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
compositeDisposable.add(disposable);
}
示例5: onResume
import io.reactivex.android.schedulers.AndroidSchedulers; //导入依赖的package包/类
@Override
protected void onResume() {
super.onResume();
// Load all persons and start inserting them with 1 sec. intervals.
// All RealmObject access has to be done on the same thread `findAllAsync` was called on.
// Warning: This example doesn't handle back pressure well.
disposable = realm.where(Person.class).findAllAsync().asFlowable()
.flatMap(persons -> Flowable.fromIterable(persons))
.zipWith(Flowable.interval(1, TimeUnit.SECONDS), (person, tick) -> person)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(person -> {
TextView personView = new TextView(AnimationActivity.this);
personView.setText(person.getName());
container.addView(personView);
});
}
示例6: startLocationUpdates
import io.reactivex.android.schedulers.AndroidSchedulers; //导入依赖的package包/类
@SuppressWarnings("MissingPermission")
@RequiresPermission(anyOf = {
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION
})
public void startLocationUpdates(boolean checkLocationSettings) {
stopLocationUpdates();
locationUpdatesDisposable = locationSettingsCheck(checkLocationSettings)
.flatMapObservable(ignore -> locationUpdates()
.startWith(lastLocation()))
.map(this::transformLocation)
.toFlowable(BackpressureStrategy.LATEST)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::setLocation,
error -> Timber.e("Failed to get location updates", error));
}
示例7: refreshBookHelps
import io.reactivex.android.schedulers.AndroidSchedulers; //导入依赖的package包/类
@Override
public void refreshBookHelps(BookSort sort, int start, int limited, BookDistillate distillate) {
Disposable refreshDispo = RemoteRepository.getInstance()
.getBookHelps(sort.getNetName(), start, limited, distillate.getNetName())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
(beans)-> {
isLocalLoad = false;
mView.finishRefresh(beans);
mView.complete();
}
,
(e) ->{
mView.complete();
mView.showErrorTip();
e(e);
}
);
addDisposable(refreshDispo);
}
示例8: login
import io.reactivex.android.schedulers.AndroidSchedulers; //导入依赖的package包/类
public void login(String username, String password) {
checkViewAttached();
getMvpView().showLoadingProgress(true);
mSubscription.add(mDataManager.login(username, password, 1)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribeWith(new DisposableSingleObserver<Boolean>() {
@Override
public void onSuccess(Boolean success) {
if (success) {
loginWithCookie();
} else {
getMvpView().showError("Login Failed");
}
}
@Override
public void onError(Throwable error) {
getMvpView().showError(error.getMessage());
getMvpView().showLoadingProgress(false);
}
}));
}
示例9: updateWatchlist
import io.reactivex.android.schedulers.AndroidSchedulers; //导入依赖的package包/类
private Disposable updateWatchlist(List<WatchlistItem> watchlistItems) {
return ((LeanbackBaseActivity) getActivity()).getApiServiceObservable()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(mediaApiService -> {
showWatchlist();
watchListAdapter.clear();
if(watchlistItems.size() > 0){
// int i = Math.max(0,mRowsAdapter.indexOf(mConferencesSection));
// mRowsAdapter.add(i,mRecomendationsSectionsRow);
// mRowsAdapter.add(i+1,watchListAdapter);
Observable.fromIterable(watchlistItems)
.flatMap(watchlistItem -> mediaApiService.getEvent(watchlistItem.getEventId()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(event -> watchListAdapter.add(event));
} else {
// watchListAdapter.add("Watchlist empty");
hideWatchlist();
}
});
}
示例10: addCheckPointMarkers
import io.reactivex.android.schedulers.AndroidSchedulers; //导入依赖的package包/类
private void addCheckPointMarkers() {
getCheckPointDataSource().getAllCheckPoints()
.toObservable()
.doOnNext(checkPoints -> allCheckPoints = (ArrayList<CheckPoint>) checkPoints)
.flatMap(Observable::fromIterable)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableObserver<CheckPoint>() {
@Override public void onNext(CheckPoint checkPoint) {
getView().addMarkerOnMap(checkPoint);
}
@Override public void onError(Throwable e) {
getView().showError(e.getLocalizedMessage());
}
@Override public void onComplete() {
getView().notifyListAdapter();
}
});
}
示例11: generateFlowable
import io.reactivex.android.schedulers.AndroidSchedulers; //导入依赖的package包/类
public static Flowable<BaseUploadBean> generateFlowable(@NonNull RequestBodyWrapper uploadBeanEmitter, final String filePath){
Flowable<BaseUploadBean> flowable = uploadBeanEmitter.getUploadProcessor()
.publish()
.autoConnect();
return flowable
.filter(new Predicate<BaseUploadBean>() {
long oldProgress = 0;
@Override
public boolean test(BaseUploadBean baseUploadBean) throws Exception {
if(baseUploadBean instanceof UploadInfoBean){
long progress = ((UploadInfoBean) baseUploadBean).getData().getWrittenBytes();
if(progress - oldProgress > MIN_GRAD) {
oldProgress = progress;
return true;
}
return false;
}
oldProgress = 0;
return true;
}
})
//.throttleLast(100, TimeUnit.MILLISECONDS).mergeWith(flowable.takeLast(1))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
示例12: shareTo
import io.reactivex.android.schedulers.AndroidSchedulers; //导入依赖的package包/类
/**
* Share the package data.
*/
@Override
public void shareTo() {
Disposable disposable = packagesRepository
.getPackage(packageId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableObserver<Package>() {
@Override
public void onNext(Package value) {
view.shareTo(value);
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
compositeDisposable.add(disposable);
}
示例13: loadWithRetroJsoup
import io.reactivex.android.schedulers.AndroidSchedulers; //导入依赖的package包/类
public void loadWithRetroJsoup() {
final OkHttpClient okHttpClient = new OkHttpClient();
final TutosAndroidFrance tutosAndroidFrance = new RetroJsoup.Builder()
.url("http://tutos-android-france.com/")
.client(okHttpClient)
.build()
.create(TutosAndroidFrance.class);
tutosAndroidFrance.articles()
.toList()
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
adapter::addItems,
Throwable::printStackTrace
);
}
示例14: refreshTag
import io.reactivex.android.schedulers.AndroidSchedulers; //导入依赖的package包/类
private void refreshTag(){
Disposable refreshDispo = RemoteRepository.getInstance()
.getBookTags()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
(tagBeans)-> {
refreshHorizonTag(tagBeans);
refreshGroupTag(tagBeans);
},
(e) ->{
LogUtils.e(e);
}
);
mDisposable.add(refreshDispo);
}
示例15: onRefresh
import io.reactivex.android.schedulers.AndroidSchedulers; //导入依赖的package包/类
@Override
public void onRefresh() {
getBinding().swipeRefreshDaily.setRefreshing(true);
String baseUrl = "http://gank.io/api/";
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
ApiService apiService = retrofit.create(ApiService.class);
apiService.getDailyData(mDate)
.map(new BaseResFunc<GankDaily.Results>())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(mObserver);
}