当前位置: 首页>>代码示例>>Java>>正文


Java Observer类代码示例

本文整理汇总了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());
}
 
开发者ID:aliumujib,项目名称:Nibo,代码行数:22,代码来源:LocationAddress.java

示例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();
                }
            });
}
 
开发者ID:coderwjq,项目名称:ZhaZhaShop,代码行数:26,代码来源:MovieMoreRankPresenter.java

示例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() {

        }
    });
}
 
开发者ID:IlyaGulya,项目名称:rxlint,代码行数:24,代码来源:DanglingSubscriptionTest.java

示例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);
    }
}
 
开发者ID:fengzhizi715,项目名称:RxConditions,代码行数:18,代码来源:ObservableIfThen.java

示例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();
        }

    };
}
 
开发者ID:jklingsporn,项目名称:vertx-jooq-async,代码行数:25,代码来源:RXVertxDaoTestBase.java

示例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() {}
    };
}
 
开发者ID:twisstosin,项目名称:UdacityBakingAndroid,代码行数:25,代码来源:RecipeListPresenter.java

示例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();
                }
            };
        }
    };
}
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:37,代码来源:Ch9_7.java

示例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;
}
 
开发者ID:SimonScholz,项目名称:RxSWT,代码行数:15,代码来源:Preconditions.java

示例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() {

                }
            });
}
 
开发者ID:alidili,项目名称:Demos,代码行数:30,代码来源:RxLifecycleActivity.java

示例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);
}
 
开发者ID:WeGdufe,项目名称:MovingGdufe-Android,代码行数:8,代码来源:JwcApiFactory.java

示例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");
        }
    };
}
 
开发者ID:changjiashuai,项目名称:RxJava2-Android-Sample,代码行数:33,代码来源:ReplaySubjectExampleActivity.java

示例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;
}
 
开发者ID:yippeesoft,项目名称:NotifyTools,代码行数:33,代码来源:MainActivity.java

示例13: testWrap1Arg

import io.reactivex.Observer; //导入依赖的package包/类
@Test
public void testWrap1Arg() throws Exception {
    Observer<? super String> testObserver = createLambdaObserver(1);

    validateDisposableDelegated(testObserver);

    validateOnNext(testObserver);
}
 
开发者ID:jzallas,项目名称:RxDisposal,代码行数:9,代码来源:SubscriptionDecoratorTest.java

示例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() {

                }
            });
}
 
开发者ID:mayuroks,项目名称:Coin-Tracker,代码行数:33,代码来源:SplashActivity.java

示例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");
        }
    };
}
 
开发者ID:changjiashuai,项目名称:RxJava2-Android-Sample,代码行数:31,代码来源:DeferExampleActivity.java


注:本文中的io.reactivex.Observer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。