本文整理汇总了Java中rx.schedulers.Schedulers类的典型用法代码示例。如果您正苦于以下问题:Java Schedulers类的具体用法?Java Schedulers怎么用?Java Schedulers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Schedulers类属于rx.schedulers包,在下文中一共展示了Schedulers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scanBleDevices
import rx.schedulers.Schedulers; //导入依赖的package包/类
private void scanBleDevices() {
mScanSubscroption = mRxBleClient
.scanBleDevices()
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.filter(rxBleScanResult -> {
return FilterDeviceName.equals(rxBleScanResult.getBleDevice().getName());
})
.subscribe(rxBleScanResult -> {
int position = DeviceContext.AddorUpdateDevice(rxBleScanResult.getBleDevice()
.getMacAddress(),
rxBleScanResult.getRssi());
if (position >= 0)
mScanDevices.getAdapter().notifyItemChanged(position);
else
mScanDevices.getAdapter().notifyDataSetChanged();
}, this::onScanFailure);
}
示例2: onActivityCreated
import rx.schedulers.Schedulers; //导入依赖的package包/类
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mAccount = getArguments().getParcelable("account");
mUserListsModel = new UserListsModel(mAccount);
mSubscriptions.add(
mUserListsModel
.lists()
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(new DefaultObserver<List<UserList>>() {
@Override
public void onNext(List<UserList> userLists) {
super.onNext(userLists);
mRecyclerView.setAdapter(new ListAdapter(getActivity(), mAccount, userLists));
}
})
);
}
示例3: loadData
import rx.schedulers.Schedulers; //导入依赖的package包/类
@Override
public void loadData()
{
RetrofitHelper.getLiveAPI()
.getLiveAppIndex()
.compose(bindToLifecycle())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(liveAppIndexInfo -> {
mLiveAppIndexAdapter.setLiveInfo(liveAppIndexInfo);
finishTask();
}, throwable -> {
initEmptyView();
});
}
示例4: getRetrofit
import rx.schedulers.Schedulers; //导入依赖的package包/类
public static RetrofitInterface getRetrofit(String email, String password) {
String credentials = email + ":" + password;
String basic = "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(chain -> {
Request original = chain.request();
Request.Builder builder = original.newBuilder()
.addHeader("Authorization", basic)
.method(original.method(),original.body());
return chain.proceed(builder.build());
});
RxJavaCallAdapterFactory rxAdapter = RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io());
return new Retrofit.Builder()
.baseUrl(Constants.BASE_URL)
.client(httpClient.build())
.addCallAdapterFactory(rxAdapter)
.addConverterFactory(GsonConverterFactory.create())
.build().create(RetrofitInterface.class);
}
示例5: startScroll
import rx.schedulers.Schedulers; //导入依赖的package包/类
/**
* 图片开始轮播
*/
private void startScroll()
{
compositeSubscription = new CompositeSubscription();
isStopScroll = false;
Subscription subscription = Observable.timer(delayTime, TimeUnit.SECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(aLong -> {
if (isStopScroll)
return;
isStopScroll = true;
viewPager.setCurrentItem(viewPager.getCurrentItem() + 1);
});
compositeSubscription.add(subscription);
}
示例6: getUserInfo
import rx.schedulers.Schedulers; //导入依赖的package包/类
public void getUserInfo() {
RetrofitHelper.getAccountAPI()
.getUserInfoById(mid)
.compose(this.bindToLifecycle())
.doOnSubscribe(this::showProgressBar)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(userInfo -> {
mUserDetailsInfo = userInfo;
finishTask();
}, throwable -> {
hideProgressBar();
});
}
示例7: doSubscribe
import rx.schedulers.Schedulers; //导入依赖的package包/类
public void doSubscribe() {
subscription = Observable.just("Hello Reactive!").observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Subscriber<String>() {
@Override
public void onCompleted() {
Toast.makeText(MainActivity.this, "Finish Subscribing...", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(final Throwable e) {
e.printStackTrace();
}
@Override
public void onNext(final String s) {
Toast.makeText(MainActivity.this, s, Toast.LENGTH_SHORT).show();
}
});
}
示例8: initializeData
import rx.schedulers.Schedulers; //导入依赖的package包/类
private void initializeData() {
application.getWebService()
.getInteractionPosts(likeCounter, MySharedPreferences.getUserId(preferences), MySharedPreferences.getUserToken(preferences))
.retryWhen(new RetryWithDelay(3,2000))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new BaseSubscriber<PostSuperUserListModel>() {
@Override
public void onNext(PostSuperUserListModel response) {
showRecycleWithDataFilled(response);
progressFrame.setVisibility(View.GONE);
}
@Override
public void onError(Throwable e) {
progressFrame.setVisibility(View.GONE);
try {
Timber.e(e.getMessage());
// Toast.makeText(UserSameCounterActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}catch (Exception ex){
ex.printStackTrace();
}
}
});
}
示例9: getBookListDetail
import rx.schedulers.Schedulers; //导入依赖的package包/类
@Override
public void getBookListDetail(String bookListId) {
Subscription rxSubscription = bookApi.getBookListDetail(bookListId).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<BookListDetail>() {
@Override
public void onCompleted() {
mView.complete();
}
@Override
public void onError(Throwable e) {
LogUtils.e("getBookListDetail:" + e.toString());
mView.complete();
}
@Override
public void onNext(BookListDetail data) {
mView.showBookListDetail(data);
}
});
addSubscrebe(rxSubscription);
}
示例10: getBestComments
import rx.schedulers.Schedulers; //导入依赖的package包/类
@Override
public void getBestComments(String disscussionId) {
Subscription rxSubscription = bookApi.getBestComments(disscussionId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<CommentList>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
LogUtils.e("getBestComments:" + e.toString());
}
@Override
public void onNext(CommentList list) {
mView.showBestComments(list);
}
});
addSubscrebe(rxSubscription);
}
示例11: getOrders
import rx.schedulers.Schedulers; //导入依赖的package包/类
public void getOrders(int page,int pageNum,String startTime,String endTime){
checkViewAttached();
RxUtil.unsubscribe(mGetOrdersSubscription);
mGetOrdersSubscription = mDataManager.getOrderList(page,pageNum,startTime,endTime)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(new Subscriber<OrderResponse>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
getMvpView().showOrdersError();
}
@Override
public void onNext(OrderResponse orderResponse) {
getMvpView().showOrders(orderResponse);
}
});
}
示例12: changeMyName
import rx.schedulers.Schedulers; //导入依赖的package包/类
private void changeMyName() {
showWaitingDialog(UIUtils.getString(R.string.please_wait));
String nickName = mEtName.getText().toString().trim();
ApiRetrofit.getInstance().setName(nickName)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(setNameResponse -> {
hideWaitingDialog();
if (setNameResponse.getCode() == 200) {
Friend friend = DBManager.getInstance().getFriendById(UserCache.getId());
if (friend != null) {
friend.setName(nickName);
friend.setDisplayName(nickName);
DBManager.getInstance().saveOrUpdateFriend(friend);
BroadcastManager.getInstance(ChangeMyNameActivity.this).sendBroadcast(AppConst.CHANGE_INFO_FOR_ME);
BroadcastManager.getInstance(ChangeMyNameActivity.this).sendBroadcast(AppConst.CHANGE_INFO_FOR_CHANGE_NAME);
}
finish();
}
}, this::loadError);
}
示例13: sendLikeNotification
import rx.schedulers.Schedulers; //导入依赖的package包/类
protected void sendLikeNotification(String likeUrl) {
application.getWebService()
.sendLikeNotification(likeUrl)
.retryWhen(new RetryWithDelay(3,2000))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new BaseSubscriber<String>() {
@Override
public void onNext(String response) {
Timber.d("Got user details");
// followers.setText(String.valueOf(response.size()));
// Toast.makeText(ChangeProfileActivity.this, "Message Sent", Toast.LENGTH_SHORT).show();
// Timber.d("Message from server" + response);
}
@Override
public void onError(Throwable e) {
Crashlytics.logException(e);
try {
Toast.makeText(PostsDetailsActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}catch (Exception ex){
ex.printStackTrace();
}
}
});
}
示例14: loadData
import rx.schedulers.Schedulers; //导入依赖的package包/类
@Override
protected void loadData() {
RetrofitHelper.getBiliAppAPI()
.getRecommendedBannerInfo()
.compose(bindToLifecycle())
.map(RecommendBannerInfo::getData)
.flatMap(new Func1<List<RecommendBannerInfo.DataBean>, Observable<RecommendInfo>>() {
@Override
public Observable<RecommendInfo> call(List<RecommendBannerInfo.DataBean> dataBeans) {
mRecommendedBanners.addAll(dataBeans);
return RetrofitHelper.getBiliAppAPI().getRecommendedInfo();
}
})
.compose(bindToLifecycle())
.map(RecommendInfo::getResult)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(resultBeans -> {
mResults.addAll(resultBeans);
finishTask();
}, throwable -> {
initEmptyView();
});
}
示例15: dealApiReqest
import rx.schedulers.Schedulers; //导入依赖的package包/类
public void dealApiReqest(BaseApi baseApi) {
// 创建一个OkHttpClient
OkHttpClient.Builder builder = new OkHttpClient.Builder();
CommonSubscriber commonSubscriber = new CommonSubscriber(baseApi, mOnNextListenerSoftReference, mRxAppCompatActivitySoftReference);
builder.addInterceptor(new CacheInterceptor()).connectTimeout(baseApi.getConnectedTime(), TimeUnit.SECONDS)
.writeTimeout(baseApi.getWritedOutTime(), TimeUnit.SECONDS).addNetworkInterceptor(new CacheInterceptor())
.cache(new Cache(CustomApplication.getInstance().getCacheDir(), 10 * 1024 * 1024));
Retrofit retrofit = new Retrofit.Builder().client(builder.build()).baseUrl(baseApi.getBaseUrl()).addConverterFactory(ScalarsConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create()).build();
// .build();
// 这里原理是通过Java的动态代理创建接口的实例
HttpService httpService = retrofit.create(HttpService.class);
Observable observable = baseApi.getObservable(httpService);
observable.retryWhen(new RetryWhenNetWorkException()).subscribeOn(Schedulers.io()).unsubscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()).map(baseApi).subscribe(commonSubscriber);
}