本文整理汇总了Java中io.reactivex.Observer类的典型用法代码示例。如果您正苦于以下问题:Java Observer类的具体用法?Java Observer怎么用?Java Observer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Observer类属于io.reactivex包,在下文中一共展示了Observer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getObservableAddressFromLocation
import io.reactivex.Observer; //导入依赖的package包/类
public Observable<Address> getObservableAddressFromLocation(final double latitude, final double longitude,
final Context context) {
return new Observable<Address>() {
@Override
protected void subscribeActual(Observer<? super Address> observer) {
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
try {
List<Address> addressList = geocoder.getFromLocation(
latitude, longitude, 1);
if (addressList != null && addressList.size() > 0) {
address = addressList.get(0);
observer.onNext(address);
}
} catch (IOException e) {
Log.e(TAG, "Unable connect to Geocoder", e);
}
}
}.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread());
}
示例2: getOverseaComingMovieList
import io.reactivex.Observer; //导入依赖的package包/类
@Override
public void getOverseaComingMovieList(String area, int limit, int offset) {
mManager.getOverseaComingMovie(area, limit, offset)
.subscribe(new Observer<OverseaComingMovieBean>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
mView.showLoading();
}
@Override
public void onNext(@NonNull OverseaComingMovieBean data) {
mView.addOverseaComingMovieList(data.getData().getComing());
}
@Override
public void onError(@NonNull Throwable e) {
mView.showError(ErrorHanding.handleError(e));
}
@Override
public void onComplete() {
mView.showContent();
}
});
}
示例3: rx2WithObservable
import io.reactivex.Observer; //导入依赖的package包/类
public void rx2WithObservable() {
io.reactivex.Observable.just("test").subscribe(new Observer<String>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(String s) {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
}
示例4: subscribeActual
import io.reactivex.Observer; //导入依赖的package包/类
@Override
protected void subscribeActual(Observer<? super T> observer) {
boolean b;
try {
b = condition.getAsBoolean();
} catch (Throwable ex) {
EmptyDisposable.error(ex, observer);
return;
}
if (b) {
then.subscribe(observer);
} else {
orElse.subscribe(observer);
}
}
示例5: failOrCountDownPlainObserver
import io.reactivex.Observer; //导入依赖的package包/类
protected <T> Observer<T> failOrCountDownPlainObserver(CountDownLatch latch) {
return new Observer<T>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(T t) {
}
@Override
public void onError(Throwable e) {
fail(e);
}
@Override
public void onComplete() {
latch.countDown();
}
};
}
示例6: networkApiRecipeObserver
import io.reactivex.Observer; //导入依赖的package包/类
private Observer<ArrayList<Recipe>> networkApiRecipeObserver() {
return new Observer<ArrayList<Recipe>>() {
@Override
public void onSubscribe(Disposable d) {
mCompositeDisposable.add(d);
}
@Override
public void onNext(ArrayList<Recipe> networkRecipeResult) {
ArrayList<Recipe> recipeList = new ArrayList<>();
recipeList.addAll(networkRecipeResult);
if(mView.isActive()) {
mView.updateAdapter(recipeList);
}
}
@Override
public void onError(Throwable e) {
if(mView.isActive()) {
mView.displaySnackbarMessage(R.string.network_error_recipes);
}
}
@Override
public void onComplete() {}
};
}
示例7: doOnEmpty
import io.reactivex.Observer; //导入依赖的package包/类
public static <T> ObservableOperator<T, T> doOnEmpty(Action
action) {
return new ObservableOperator<T, T>() {
@Override
public Observer<? super T> apply(Observer<? super T>
observer) throws Exception {
return new DisposableObserver<T>() {
boolean isEmpty = true;
@Override
public void onNext(T value) {
isEmpty = false;
observer.onNext(value);
}
@Override
public void onError(Throwable t) {
observer.onError(t);
}
@Override
public void onComplete() {
if (isEmpty) {
try {
action.run();
} catch (Exception e) {
onError(e);
return;
}
}
observer.onComplete();
}
};
}
};
}
示例8: checkWidget
import io.reactivex.Observer; //导入依赖的package包/类
public static boolean checkWidget(Observer<?> observer, Widget widget) {
if (null == widget) {
observer.onError(new NullPointerException("The given widget was null"));
return false;
} else if (widget.isDisposed()) {
observer.onError(new IllegalStateException("The given widget is diposed"));
return false;
} else if (!(Thread.currentThread().equals(widget.getDisplay().getThread()))) {
observer.onError(new IllegalStateException(
"Expected to be called on the main thread but was " + Thread.currentThread().getName()));
return false;
}
return true;
}
示例9: onStart
import io.reactivex.Observer; //导入依赖的package包/类
@Override
protected void onStart() {
super.onStart();
Observable.interval(1, TimeUnit.SECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.compose(provider.<Long>bindToLifecycle())
.subscribe(new Observer<Long>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
}
@Override
public void onNext(@NonNull Long aLong) {
Log.i("接收数据", String.valueOf(aLong));
}
@Override
public void onError(@NonNull Throwable e) {
}
@Override
public void onComplete() {
}
});
}
示例10: getCet
import io.reactivex.Observer; //导入依赖的package包/类
public void getCet(String zkzh,String name, Observer<Cet> sub ) {
ApiUtils.getApi(AppConfig.jwPwd).create(JwcApi.class).getCet(zkzh,name)
.map(new HttpResultFunc<Cet>())
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(sub);
}
示例11: getSecondObserver
import io.reactivex.Observer; //导入依赖的package包/类
private Observer<Integer> getSecondObserver() {
return new Observer<Integer>() {
@Override
public void onSubscribe(Disposable d) {
textView.append(" Second onSubscribe : isDisposed :" + d.isDisposed());
Log.d(TAG, " Second onSubscribe : " + d.isDisposed());
textView.append(AppConstant.LINE_SEPARATOR);
}
@Override
public void onNext(Integer value) {
textView.append(" Second onNext : value : " + value);
textView.append(AppConstant.LINE_SEPARATOR);
Log.d(TAG, " Second onNext value : " + value);
}
@Override
public void onError(Throwable e) {
textView.append(" Second onError : " + e.getMessage());
textView.append(AppConstant.LINE_SEPARATOR);
Log.d(TAG, " Second onError : " + e.getMessage());
}
@Override
public void onComplete() {
textView.append(" Second onComplete");
textView.append(AppConstant.LINE_SEPARATOR);
Log.d(TAG, " Second onComplete");
}
};
}
示例12: bingObserver
import io.reactivex.Observer; //导入依赖的package包/类
public Observer<List<Net.BingWallBean>> bingObserver() {
Observer<List<Net.BingWallBean>> observer = new Observer<List<Net.BingWallBean>>() {
Disposable dd;
@Override
public void onSubscribe(Disposable d) {
// d.dispose();//断开订阅关系;
// d.isDisposed();//判断是否还有订阅关系
// dd = d;
Log.d(TAG, "onSubscribe: ");
}
@Override
public void onNext(List<Net.BingWallBean> ll) {
Log.d(TAG, "onNext: " + ll.size());
bingAdapter=new BingAdapter(ll);
rv.setAdapter(bingAdapter);
bingAdapter.notifyDataSetChanged();
}
@Override
public void onError(Throwable e) {
Log.d(TAG, "onError: ");
}
@Override
public void onComplete() {
Log.d(TAG, "onComplete: ");
}
};
return observer;
}
示例13: testWrap1Arg
import io.reactivex.Observer; //导入依赖的package包/类
@Test
public void testWrap1Arg() throws Exception {
Observer<? super String> testObserver = createLambdaObserver(1);
validateDisposableDelegated(testObserver);
validateOnNext(testObserver);
}
示例14: getAllCoins
import io.reactivex.Observer; //导入依赖的package包/类
private void getAllCoins() {
if (CoinHelper.getInstance().getAllCachedCoinTags().size() > 0) return;
service.getAllCoins()
.subscribeOn(Injection.provideSchedulerProvider().io())
.observeOn(Injection.provideSchedulerProvider().computation())
.subscribe(new Observer<CoinListResponse>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
}
@Override
public void onNext(@NonNull CoinListResponse coinListResponse) {
Logger.i("getAllCoins done");
CoinHelper coinHelper = CoinHelper.getInstance();
coinHelper.setContext(SplashActivity.this);
coinHelper.updateAllCachedCoins(coinListResponse.getData(), true);
}
@Override
public void onError(@NonNull Throwable e) {
Logger.i("getAllCoins error");
e.printStackTrace();
}
@Override
public void onComplete() {
}
});
}
示例15: getObserver
import io.reactivex.Observer; //导入依赖的package包/类
private Observer<String> getObserver() {
return new Observer<String>() {
@Override
public void onSubscribe(Disposable d) {
Log.d(TAG, " onSubscribe : " + d.isDisposed());
}
@Override
public void onNext(String value) {
textView.append(" onNext : value : " + value);
textView.append(AppConstant.LINE_SEPARATOR);
Log.d(TAG, " onNext : value : " + value);
}
@Override
public void onError(Throwable e) {
textView.append(" onError : " + e.getMessage());
textView.append(AppConstant.LINE_SEPARATOR);
Log.d(TAG, " onError : " + e.getMessage());
}
@Override
public void onComplete() {
textView.append(" onComplete");
textView.append(AppConstant.LINE_SEPARATOR);
Log.d(TAG, " onComplete");
}
};
}