当前位置: 首页>>代码示例>>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;未经允许,请勿转载。