當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。