本文整理汇总了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());
}
});
}
});
}
示例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));
}
});
}
示例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);
}
});
}
示例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));
}
});
}
示例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));
}
示例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();
}
示例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);
}
}
});
}
});
}
示例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);
}
});
}
示例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);
}
示例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);
}
});
}
示例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());
}
示例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();
}
示例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);
}
});
}
示例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();
}
});
}
示例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()");
}
});
}