當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。