當前位置: 首頁>>代碼示例>>Java>>正文


Java ObservableSource類代碼示例

本文整理匯總了Java中io.reactivex.ObservableSource的典型用法代碼示例。如果您正苦於以下問題:Java ObservableSource類的具體用法?Java ObservableSource怎麽用?Java ObservableSource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ObservableSource類屬於io.reactivex包,在下文中一共展示了ObservableSource類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: beaconsInRegion

import io.reactivex.ObservableSource; //導入依賴的package包/類
public Observable<RxBeaconRange> beaconsInRegion() {
    return startup()
            .flatMap(new Function<Boolean, ObservableSource<RxBeaconRange>>() {
                @Override
                public ObservableSource<RxBeaconRange> apply(@NonNull Boolean aBoolean) throws Exception {
                    return Observable.create(new ObservableOnSubscribe<RxBeaconRange>() {
                        @Override
                        public void subscribe(@NonNull final ObservableEmitter<RxBeaconRange> objectObservableEmitter) throws Exception {
                            beaconManager.addRangeNotifier(new RangeNotifier() {
                                @Override
                                public void didRangeBeaconsInRegion(Collection<Beacon> collection, Region region) {
                                    objectObservableEmitter.onNext(new RxBeaconRange(collection, region));
                                }
                            });
                            beaconManager.startRangingBeaconsInRegion(getRegion());
                        }
                    });
                }
            });
}
 
開發者ID:florent37,項目名稱:RxBeacon,代碼行數:21,代碼來源:RxBeacon.java

示例2: apply

import io.reactivex.ObservableSource; //導入依賴的package包/類
@Override
public ObservableSource<T> apply(@NonNull Observable<BaseHttpResult<T>> upstream) {
    return upstream.map(new Function<BaseHttpResult<T>, T>() {
        @Override
        public T apply(@NonNull BaseHttpResult<T> tBaseHttpResult) throws Exception {
            if (tBaseHttpResult == null) {
                throw new ServerException(ErrorType.EMPTY_BEAN, "解析對象為空");
            }
            LogUtils.e(TAG, tBaseHttpResult.toString());
            if (tBaseHttpResult.getStatus() != ErrorType.SUCCESS) {
                throw new ServerException(tBaseHttpResult.getStatus(),
                        tBaseHttpResult.getMessage());
            }
            return tBaseHttpResult.getData();
        }
    }).onErrorResumeNext(new Function<Throwable, ObservableSource<? extends T>>() {
        @Override
        public ObservableSource<? extends T> apply(@NonNull Throwable throwable)
                throws Exception {
            // ExceptionEngine 為處理異常的驅動器 throwable
            throwable.printStackTrace();
            return Observable.error(ExceptionEngine.handleException(throwable));
        }
    });

}
 
開發者ID:wang2016215,項目名稱:Bing,代碼行數:27,代碼來源:ErrorTransformer.java

示例3: seedDatabaseOptions

import io.reactivex.ObservableSource; //導入依賴的package包/類
@Override
public Observable<Boolean> seedDatabaseOptions() {

    GsonBuilder builder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
    final Gson gson = builder.create();

    return mDbHelper.isOptionEmpty()
            .concatMap(new Function<Boolean, ObservableSource<? extends Boolean>>() {
                @Override
                public ObservableSource<? extends Boolean> apply(Boolean isEmpty)
                        throws Exception {
                    if (isEmpty) {
                        Type type = new TypeToken<List<Option>>() {
                        }
                                .getType();
                        List<Option> optionList = gson.fromJson(
                                CommonUtils.loadJSONFromAsset(mContext,
                                        AppConstants.SEED_DATABASE_OPTIONS),
                                type);

                        return saveOptionList(optionList);
                    }
                    return Observable.just(false);
                }
            });
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:27,代碼來源:AppDataManager.java

示例4: existsType

import io.reactivex.ObservableSource; //導入依賴的package包/類
/**
 * Gets the download type of file existence.
 *
 * @param url file url
 * @return Download Type
 */
private Observable<DownloadType> existsType(final String url) {
    return Observable.just(1)
            .map(new Function<Integer, String>() {
                @Override
                public String apply(Integer integer) throws Exception {
                    return recordTable.readLastModify(url);
                }
            })
            .flatMap(new Function<String, ObservableSource<Object>>() {
                @Override
                public ObservableSource<Object> apply(String s) throws Exception {
                    return checkFile(url, s);
                }
            })
            .flatMap(new Function<Object, ObservableSource<DownloadType>>() {
                @Override
                public ObservableSource<DownloadType> apply(Object o)
                        throws Exception {
                    return Observable.just(recordTable.generateFileExistsType(url));
                }
            });
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:29,代碼來源:DownloadHelper.java

示例5: checkUrl

import io.reactivex.ObservableSource; //導入依賴的package包/類
/**
 * check url
 *
 * @param url url
 * @return empty
 */
private ObservableSource<Object> checkUrl(final String url) {
    return downloadApi.check(url)
            .flatMap(new Function<Response<Void>, ObservableSource<Object>>() {
                @Override
                public ObservableSource<Object> apply(@NonNull Response<Void> resp)
                        throws Exception {
                    if (!resp.isSuccessful()) {
                        return checkUrlByGet(url);
                    } else {
                        return saveFileInfo(url, resp);
                    }
                }
            })
            .compose(retry(REQUEST_RETRY_HINT, maxRetryCount));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:DownloadHelper.java

示例6: refreshPackages

import io.reactivex.ObservableSource; //導入依賴的package包/類
/**
 * Update and save the packages' status by accessing the Internet.
 * @return The observable packages whose status are the latest.
 */
@Override
public Observable<List<Package>> refreshPackages() {
    // It is necessary to build a new realm instance
    // in a different thread.
    Realm realm = Realm.getInstance(new RealmConfiguration.Builder()
            .deleteRealmIfMigrationNeeded()
            .name(DATABASE_NAME)
            .build());

    return Observable.fromIterable(realm.copyFromRealm(realm.where(Package.class).findAll()))
            .subscribeOn(Schedulers.io())
            .flatMap(new Function<Package, ObservableSource<Package>>() {
                @Override
                public ObservableSource<Package> apply(Package aPackage) throws Exception {
                    // A nested request.
                    return refreshPackage(aPackage.getNumber());
                }
            })
            .toList()
            .toObservable();
}
 
開發者ID:TonnyL,項目名稱:Espresso,代碼行數:26,代碼來源:PackagesRemoteDataSource.java

示例7: refreshPackage

import io.reactivex.ObservableSource; //導入依賴的package包/類
/**
 * Refresh one package.
 * Just call the remote data source and it will make everything done.
 * @param packageId The primary key(The package number).
 *                  See more @{@link Package#number}.
 * @return The observable package.
 */
@Override
public Observable<Package> refreshPackage(@NonNull final String packageId) {
    return packagesRemoteDataSource
            .refreshPackage(packageId)
            .flatMap(new Function<Package, ObservableSource<Package>>() {
                @Override
                public ObservableSource<Package> apply(Package p) throws Exception {
                    return Observable
                            .just(p)
                            .doOnNext(new Consumer<Package>() {
                                @Override
                                public void accept(Package aPackage) throws Exception {
                                    Package pkg = cachedPackages.get(aPackage.getNumber());
                                    if (pkg != null) {
                                        pkg.setData(aPackage.getData());
                                        pkg.setReadable(true);
                                    }
                                }
                            });
                }
            });
}
 
開發者ID:TonnyL,項目名稱:Espresso,代碼行數:30,代碼來源:PackagesRepository.java

示例8: apply

import io.reactivex.ObservableSource; //導入依賴的package包/類
@Override
public ObservableSource<?> apply(@NonNull Observable<Throwable> throwableObservable) throws Exception {
    return throwableObservable
            .flatMap(new Function<Throwable, ObservableSource<?>>() {
                @Override
                public ObservableSource<?> apply(@NonNull Throwable throwable) throws Exception {
                    if (++retryCount <= maxRetries) {
                        // When this Observable calls onNext, the original Observable will be retried (i.e. re-subscribed).
                        Log.d(TAG, "Observable get error, it will try after " + retryDelaySecond
                                + " second, retry count " + retryCount);
                        return Observable.timer(retryDelaySecond,
                                TimeUnit.SECONDS);
                    }
                    // Max retries hit. Just pass the error along.
                    return Observable.error(throwable);
                }
            });
}
 
開發者ID:goutham106,項目名稱:GmArchMvvm,代碼行數:19,代碼來源:RetryWithDelay.java

示例9: start

import io.reactivex.ObservableSource; //導入依賴的package包/類
private void start() {
    Disposable disposable = Observable.interval(1, TimeUnit.SECONDS)
            .take(1)
            .onErrorResumeNext(new Function<Throwable, ObservableSource<? extends Long>>() {
                @Override
                public ObservableSource<? extends Long> apply(Throwable throwable) throws Exception {
                    return null;
                }
            })
            .subscribe(new Consumer<Long>() {
                @Override
                public void accept(Long aLong) throws Exception {
                    Log.e(MainActivity.TAG, "accept: " + aLong);
                    startActivity(new Intent(SplashActivity.this, MainActivity.class));
                    finish();
                }
            });
    dLists.add(disposable);

}
 
開發者ID:penghuanliang,項目名稱:Rxjava2.0Demo,代碼行數:21,代碼來源:SplashActivity.java

示例10: initView

import io.reactivex.ObservableSource; //導入依賴的package包/類
private void initView() {
        subject = PublishSubject.create();
        subject.debounce(0, TimeUnit.MILLISECONDS)
//                .filter(new Predicate<Float>() {
//                    @Override
//                    public boolean test(Float contrast) throws Exception {
//                        return true;
//                    }
//                })
                .distinctUntilChanged()
                .switchMap(new Function<Float, ObservableSource<ColorMatrixColorFilter>>() {
                    @Override
                    public ObservableSource<ColorMatrixColorFilter> apply(Float value) throws Exception {
                        return postContrast(value);
                    }
                })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<ColorMatrixColorFilter>() {
                    @Override
                    public void accept(ColorMatrixColorFilter colorMatrixColorFilter) throws Exception {
                        setColorFilter(colorMatrixColorFilter);
                    }
                });
    }
 
開發者ID:hoanganhtuan95ptit,項目名稱:EditPhoto,代碼行數:26,代碼來源:ContrastView.java

示例11: setUp

import io.reactivex.ObservableSource; //導入依賴的package包/類
@Override protected void setUp() throws Exception {
  super.setUp();
  contentResolver = getMockContentResolver();

  SqlBrite.Logger logger = new SqlBrite.Logger() {
    @Override public void log(String message) {
      logs.add(message);
    }
  };
  ObservableTransformer<Query, Query> queryTransformer =
      new ObservableTransformer<Query, Query>() {
        @Override public ObservableSource<Query> apply(Observable<Query> upstream) {
          return upstream.takeUntil(killSwitch);
        }
      };
  db = new BriteContentResolver(contentResolver, logger, scheduler, queryTransformer);

  getProvider().init(getContext().getContentResolver());
}
 
開發者ID:jiechic,項目名稱:sqlbrite-sqlcipher,代碼行數:20,代碼來源:BriteContentResolverTest.java

示例12: getLatestActiveDateForIdpId

import io.reactivex.ObservableSource; //導入依賴的package包/類
/**
 * Given an Observable stream of DeviceAccess, get the unique IdentityProviders in the stream and their latest created date
 */
private ObservableSource<HashMap<Long, Date>> getLatestActiveDateForIdpId(Observable<DeviceAccess> deviceAccessObservable) {
    return deviceAccessObservable.collect(
            () -> new HashMap<Long, Date>(),
            (latestActiveDateByIdpId, _deviceAccess) -> {
                Long idpId = _deviceAccess.getIdentityProvider().getId();

                Date deviceAccessDate = _deviceAccess.getCreatedDate();
                Date latestActiveDate = latestActiveDateByIdpId.get(idpId);

                if (latestActiveDate == null) {
                    latestActiveDateByIdpId.put(idpId, deviceAccessDate);
                } else if (latestActiveDate.after(deviceAccessDate)) {
                    latestActiveDateByIdpId.put(idpId, latestActiveDate);
                } else {
                    latestActiveDateByIdpId.put(idpId, deviceAccessDate);
                }

            })
            .toObservable();
}
 
開發者ID:Atypon-OpenSource,項目名稱:wayf-cloud,代碼行數:24,代碼來源:IdentityProviderUsageFacadeImpl.java

示例13: debounceTest

import io.reactivex.ObservableSource; //導入依賴的package包/類
private static void debounceTest(int i) {
    Observable.just(i)
            .debounce(1000, TimeUnit.MILLISECONDS)
            /*以最近請求的數據為準*/
            .switchMap(new Function<Integer, ObservableSource<String>>() {
                @Override
                public ObservableSource<String> apply(Integer integer) throws Exception {
                    return Observable.just(String.valueOf(integer));
                }
            }).subscribe(new Consumer<String>() {
        @Override
        public void accept(String s) throws Exception {
            System.out.println(s);
        }
    });

}
 
開發者ID:InnoFang,項目名稱:Android-Code-Demos,代碼行數:18,代碼來源:OperatorTest.java

示例14: getGankioData

import io.reactivex.ObservableSource; //導入依賴的package包/類
public void getGankioData(GankioType type, int count, int page, boolean isProgress) {
  if (isProgress) {
    view.showProgress("");
  }
  wrap(gankioRepository.getAllGankioData(type, count, page)).flatMap(
      new Function<BaseResult<GankioData>, ObservableSource<BaseResult<GankioData>>>() {
        @Override public ObservableSource<BaseResult<GankioData>> apply(
            @NonNull BaseResult<GankioData> gankioDataBaseResult) throws Exception {
          //List<GankioData> results = ;
          for (GankioData gankioData : gankioDataBaseResult.getResults()) {
            boolean b = dbRepository.queryBrowseHistory(gankioData.get_id());
            gankioData.setBrowseHistory(b);
          }
          return Observable.just(gankioDataBaseResult);
        }
      }).subscribe(new ViewObserver<GankioData>(view) {
    @Override protected void onSuccess(List<GankioData> t) {
      view.display(t);
    }

    @Override public void onError(@NonNull Throwable e) {
      super.onError(e);
      view.displayError();
    }
  });
}
 
開發者ID:Lingzh0ng,項目名稱:BrotherWeather,代碼行數:27,代碼來源:GankioAllPresenter.java

示例15: test0

import io.reactivex.ObservableSource; //導入依賴的package包/類
@Override
public void test0() {
    Log.i(TAG, "test0() FlatMap simple demo, integer 1,2,3 transform to string 2,3,4,6,6,9");
    Observable.just(1, 2, 3).flatMap(new Function<Integer, ObservableSource<String>>() {
        @Override
        public ObservableSource<String> apply(@NonNull Integer integer) throws Exception {
            return Observable.just(integer * 2 + "", integer * 3 + "");
        }
    }).subscribe(new Consumer<String>() {
        @Override
        public void accept(String s) throws Exception {
            Log.d(TAG, "Consumer<String> accept() s: " + s);
        }
    }, new Consumer<Throwable>() {
        @Override
        public void accept(Throwable throwable) throws Exception {
            Log.d(TAG, "Consumer<Throwable> accept() throwable: " + throwable);
        }
    }, new Action() {
        @Override
        public void run() throws Exception {
            Log.d(TAG, "Action run() for onComplete()");
        }
    });
}
 
開發者ID:afunx,項目名稱:RxJava4AndroidDemos,代碼行數:26,代碼來源:FlatMap.java


注:本文中的io.reactivex.ObservableSource類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。