当前位置: 首页>>代码示例>>Java>>正文


Java ObservableEmitter类代码示例

本文整理汇总了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();
}
 
开发者ID:datalink747,项目名称:Rx_java2_soussidev,代码行数:17,代码来源:LollipopNetworkObservingStrategy.java

示例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();
        }
    });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:DebounceExampleActivity.java

示例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();
        }
    });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:ThrottleLastExampleActivity.java

示例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);
    }
  });
}
 
开发者ID:pwittchen,项目名称:ReactiveAirplaneMode,代码行数:28,代码来源:ReactiveAirplaneMode.java

示例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);
        }
    });
}
 
开发者ID:aschattney,项目名称:dagger-test-example,代码行数:18,代码来源:ImageRequestManager.java

示例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 {

        }
    });
}
 
开发者ID:zhou-you,项目名称:RxEasyHttp,代码行数:17,代码来源:MainActivity.java

示例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;
    }
}
 
开发者ID:Horrarndoo,项目名称:YiZhi,代码行数:27,代码来源:HeadSettingActivity.java

示例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;
}
 
开发者ID:qkcoder,项目名称:Assembler,代码行数:17,代码来源:_Router.java

示例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();
                }
            });
        }
    });
}
 
开发者ID:greenrobot,项目名称:ObjectBoxRxJava,代码行数:26,代码来源:RxBoxStore.java

示例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);
        }
    });
}
 
开发者ID:penghuanliang,项目名称:Rxjava2.0Demo,代码行数:23,代码来源:MapActivity.java

示例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);
}
 
开发者ID:harrynp,项目名称:BakingApp,代码行数:25,代码来源:RecipeDatabaseHelper.java

示例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);
                }
            });

}
 
开发者ID:piyell,项目名称:NeteaseCloudMusic,代码行数:20,代码来源:ConfigPresenter.java

示例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);
                }
            });
}
 
开发者ID:RyanHuen,项目名称:GetStartRxJava2.0,代码行数:18,代码来源:UnlimitPostActivity.java

示例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";
            }
        });*/
    }
 
开发者ID:InnoFang,项目名称:Android-Code-Demos,代码行数:21,代码来源:BasicTest.java

示例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);
			}
		}
	});
}
 
开发者ID:kiwiandroiddev,项目名称:starcraft-2-build-player,代码行数:32,代码来源:StandardBuildsService.java


注:本文中的io.reactivex.ObservableEmitter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。