本文整理汇总了Java中io.reactivex.ObservableEmitter类的典型用法代码示例。如果您正苦于以下问题:Java ObservableEmitter类的具体用法?Java ObservableEmitter怎么用?Java ObservableEmitter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObservableEmitter类属于io.reactivex包,在下文中一共展示了ObservableEmitter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: observeNetworkConnectivity
import io.reactivex.ObservableEmitter; //导入依赖的package包/类
@Override public Observable<Connectivity> observeNetworkConnectivity(final Context context) {
final String service = Context.CONNECTIVITY_SERVICE;
final ConnectivityManager manager = (ConnectivityManager) context.getSystemService(service);
return Observable.create(new ObservableOnSubscribe<Connectivity>() {
@Override public void subscribe(ObservableEmitter<Connectivity> subscriber) throws Exception {
networkCallback = createNetworkCallback(subscriber, context);
final NetworkRequest networkRequest = new NetworkRequest.Builder().build();
manager.registerNetworkCallback(networkRequest, networkCallback);
}
}).doOnDispose(new Action() {
@Override public void run() {
tryToUnregisterCallback(manager);
}
}).startWith(Connectivity.create(context)).distinctUntilChanged();
}
示例2: getObservable
import io.reactivex.ObservableEmitter; //导入依赖的package包/类
private Observable<Integer> getObservable() {
return Observable.create(new ObservableOnSubscribe<Integer>() {
@Override
public void subscribe(ObservableEmitter<Integer> emitter) throws Exception {
// send events with simulated time wait
emitter.onNext(1); // skip
Thread.sleep(400);
emitter.onNext(2); // deliver
Thread.sleep(505);
emitter.onNext(3); // skip
Thread.sleep(100);
emitter.onNext(4); // deliver
Thread.sleep(605);
emitter.onNext(5); // deliver
Thread.sleep(510);
emitter.onComplete();
}
});
}
示例3: getObservable
import io.reactivex.ObservableEmitter; //导入依赖的package包/类
private Observable<Integer> getObservable() {
return Observable.create(new ObservableOnSubscribe<Integer>() {
@Override
public void subscribe(ObservableEmitter<Integer> emitter) throws Exception {
// send events with simulated time wait
Thread.sleep(0);
emitter.onNext(1); // skip
emitter.onNext(2); // deliver
Thread.sleep(505);
emitter.onNext(3); // skip
Thread.sleep(99);
emitter.onNext(4); // skip
Thread.sleep(100);
emitter.onNext(5); // skip
emitter.onNext(6); // deliver
Thread.sleep(305);
emitter.onNext(7); // deliver
Thread.sleep(510);
emitter.onComplete();
}
});
}
示例4: observe
import io.reactivex.ObservableEmitter; //导入依赖的package包/类
/**
* Observes Airplane Mode state of the device with BroadcastReceiver.
* RxJava2 Observable emits true if the airplane mode turns on and false otherwise.
*
* @param context of the Application or Activity
* @return RxJava2 Observable with Boolean value indicating state of the airplane mode
*/
public Observable<Boolean> observe(final Context context) {
checkContextIsNotNull(context);
final IntentFilter filter = createIntentFilter();
return Observable.create(new ObservableOnSubscribe<Boolean>() {
@Override public void subscribe(@NonNull final ObservableEmitter<Boolean> emitter)
throws Exception {
final BroadcastReceiver receiver = createBroadcastReceiver(emitter);
context.registerReceiver(receiver, filter);
final Disposable disposable = disposeInUiThread(new Action() {
@Override public void run() throws Exception {
tryToUnregisterReceiver(receiver, context);
}
});
emitter.setDisposable(disposable);
}
});
}
示例5: getInto
import io.reactivex.ObservableEmitter; //导入依赖的package包/类
private SimpleTarget<Bitmap> getInto(String iconUrl, final ObservableEmitter<Bitmap> emitter) {
return requestManager.load(Uri.parse(iconUrl)).asBitmap().into(new SimpleTarget<Bitmap>()
{
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation)
{
emitter.onNext(resource);
emitter.onComplete();
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
emitter.onError(e);
}
});
}
示例6: onCreate
import io.reactivex.ObservableEmitter; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Observable.create(new ObservableOnSubscribe<String>() {
@Override
public void subscribe(@NonNull ObservableEmitter<String> e) throws Exception {
FileUtils.getFileFromAsset(MainActivity.this, "1.jpg");
}
}).compose(RxUtil.<String>io_main()).subscribe(new Consumer<String>() {
@Override
public void accept(@NonNull String s) throws Exception {
}
});
}
示例7: onClick
import io.reactivex.ObservableEmitter; //导入依赖的package包/类
@OnClick({R.id.tv_cancel, R.id.tv_ok})
public void onClick(View view) {
switch (view.getId()) {
case R.id.tv_cancel:
onBackPressedSupport();
break;
case R.id.tv_ok:
Observable.create(new ObservableOnSubscribe<Uri>() {
@Override
public void subscribe(ObservableEmitter<Uri> e) throws
Exception {
e.onNext(generateUri());
e.onComplete();
}
}).compose(RxHelper.<Uri>rxSchedulerHelper())
.subscribe(new Consumer<Uri>() {
@Override
public void accept(Uri uri) throws Exception {
RxEventHeadBean rxEventHeadBean = new RxEventHeadBean(uri);
RxBus.get().send(RX_BUS_CODE_HEAD_IMAGE_URI, rxEventHeadBean);
onBackPressedSupport();
}
});
break;
}
}
示例8: saveData
import io.reactivex.ObservableEmitter; //导入依赖的package包/类
@Override
public boolean saveData(final Object obj) {
if (null == obj) {
return false;
}
Observable<String> observable = Observable.create(new ObservableOnSubscribe<String>() {
@Override
public void subscribe(ObservableEmitter<String> e) throws Exception {
e.onNext(new Gson().toJson(obj));
e.onComplete();
}
});
RouterWare.observerables.put(routerRequest.getUri().toString(), observable);
return true;
}
示例9: observable
import io.reactivex.ObservableEmitter; //导入依赖的package包/类
/**
* Using the returned Observable, you can be notified about data changes.
* Once a transaction is committed, you will get info on classes with changed Objects.
*/
public static <T> Observable<Class> observable(final BoxStore boxStore) {
return Observable.create(new ObservableOnSubscribe<Class>() {
@Override
public void subscribe(final ObservableEmitter<Class> emitter) throws Exception {
final DataSubscription dataSubscription = boxStore.subscribe().observer(new DataObserver<Class>() {
@Override
public void onData(Class data) {
if (!emitter.isDisposed()) {
emitter.onNext(data);
}
}
});
emitter.setCancellable(new Cancellable() {
@Override
public void cancel() throws Exception {
dataSubscription.cancel();
}
});
}
});
}
示例10: map
import io.reactivex.ObservableEmitter; //导入依赖的package包/类
private void map() {
Observable.create(new ObservableOnSubscribe<Integer>() {
@Override
public void subscribe(ObservableEmitter<Integer> e) throws Exception {
e.onNext(1);
e.onNext(2);
e.onNext(3);
}
}).map(new Function<Integer, String>() {
@Override
public String apply(Integer integer) throws Exception {
return "This is result " + integer;
}
}).subscribe(new Consumer<String>() {
@Override
public void accept(String s) throws Exception {
Log.e(MainActivity.TAG, "accept: " + Thread.currentThread().getName());
info += s + "\n";
tv.setText(info);
}
});
}
示例11: getAllRecipes
import io.reactivex.ObservableEmitter; //导入依赖的package包/类
public void getAllRecipes(Observer<ArrayList<Recipe>> observer){
Observable.create(new ObservableOnSubscribe<ArrayList<Recipe>>() {
@Override
public void subscribe(ObservableEmitter<ArrayList<Recipe>> e) throws Exception {
Cursor cursor = mContext.getContentResolver()
.query(RecipesContract.RecipeEntry.CONTENT_URI,
null,
null,
null,
RecipesContract.RecipeEntry.COLUMN_NAME + " DESC");
ArrayList<Recipe> recipes;
if(cursor != null){
recipes = buildRecipesFromCursor(cursor);
cursor.close();
e.onNext(recipes);
} else {
e.onError(new NullPointerException("Recipe cursor is null."));
}
e.onComplete();
}
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(observer);
}
示例12: requestLoadingList
import io.reactivex.ObservableEmitter; //导入依赖的package包/类
public void requestLoadingList() {
Observable.create(new ObservableOnSubscribe<List<ConfigBean>>() {
@Override
public void subscribe(ObservableEmitter<List<ConfigBean>> e) throws Exception {
mModel = ConfigModel.getInstance(configView.getContext());
e.onNext(mModel.getConfigList());
mModel.setConfigCallback(ConfigPresenter.this);
}
})
.observeOn(Schedulers.io())
.subscribeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<List<ConfigBean>>() {
@Override
public void accept(List<ConfigBean> list) throws Exception {
configView.displayConfigList(list);
}
});
}
示例13: doRxJavaWork
import io.reactivex.ObservableEmitter; //导入依赖的package包/类
private void doRxJavaWork() {
Observable.create(new ObservableOnSubscribe<Integer>() {
@Override
public void subscribe(ObservableEmitter<Integer> emitter) throws Exception {
for (;;) { // 无限循环发送事件
emitter.onNext(Integer.MAX_VALUE);
}
}
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<Integer>() {
@Override
public void accept(Integer integer) throws Exception {
Log.d(TAG, "" + integer);
}
});
}
示例14: getObservable
import io.reactivex.ObservableEmitter; //导入依赖的package包/类
public Observable<String> getObservable() {
return Observable.create(new ObservableOnSubscribe<String>() {
@Override
public void subscribe(ObservableEmitter<String> e) throws Exception {
e.onNext("Today's news update");
e.onNext("Today's topic is Study");
e.onComplete();
}
});
/* 下面两个方法作用类似,just 的内部调用的就是 fromArray */
// return Observable.just("Topic 1", "Heat 1", "News");
// return Observable.fromArray("Topic 1", "Heat 1", "News");
/* 只能发送一个数据 */
/*return Observable.fromCallable(new Callable<String>() {
@Override
public String call() throws Exception {
return "Topic is Study";
}
});*/
}
示例15: getLoadStandardBuildsIntoDBObservable
import io.reactivex.ObservableEmitter; //导入依赖的package包/类
/**
* Returns an observable on the progress of loading stock build orders into the local SQLite DB.
* Should be scheduled on a worker thread.
*
* @param c context
* @param forceLoad if false, builds are only copied if an upgrade is required. If true,
* standard builds are always copied.
* @return observable on load progress (percentage)
*/
public static Observable<Integer> getLoadStandardBuildsIntoDBObservable(final Context c, final boolean forceLoad) {
return Observable.create(new ObservableOnSubscribe<Integer>() {
@Override
public void subscribe(@NonNull final ObservableEmitter<Integer> emitter) throws Exception {
try {
if (!emitter.isDisposed()) {
loadStandardBuildsIntoDB(c, forceLoad, new DbAdapter.ProgressListener() {
@Override
public void onProgressUpdate(int percent) {
if (!emitter.isDisposed()) {
emitter.onNext(percent);
}
}
});
emitter.onComplete();
}
} catch (Exception e) {
emitter.onError(e);
}
}
});
}