本文整理匯總了Java中io.reactivex.SingleEmitter類的典型用法代碼示例。如果您正苦於以下問題:Java SingleEmitter類的具體用法?Java SingleEmitter怎麽用?Java SingleEmitter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SingleEmitter類屬於io.reactivex包,在下文中一共展示了SingleEmitter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: single
import io.reactivex.SingleEmitter; //導入依賴的package包/類
/**
* The returned Single emits one Query result as a List.
*/
public static <T> Single<List<T>> single(final Query<T> query) {
return Single.create(new SingleOnSubscribe<List<T>>() {
@Override
public void subscribe(final SingleEmitter<List<T>> emitter) throws Exception {
final DataSubscription dataSubscription = query.subscribe().single().observer(new DataObserver<List<T>>() {
@Override
public void onData(List<T> data) {
if (!emitter.isDisposed()) {
emitter.onSuccess(data);
}
}
});
emitter.setCancellable(new Cancellable() {
@Override
public void cancel() throws Exception {
dataSubscription.cancel();
}
});
}
});
}
示例2: single
import io.reactivex.SingleEmitter; //導入依賴的package包/類
private void single() {
Single.create(new SingleOnSubscribe<String>() {
@Override
public void subscribe(SingleEmitter<String> e) throws Exception {
e.onSuccess("1");
e.onSuccess("2");
e.onSuccess("3");
e.onSuccess("4");
}
}).subscribe(new Consumer<String>() {
@Override
public void accept(String s) throws Exception {
Log.e(TAG, "accept: success " + s);
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
}
});
}
示例3: isAlive
import io.reactivex.SingleEmitter; //導入依賴的package包/類
@SuppressLint("NewApi")
public Single<Boolean> isAlive() {
if (RXSDebug.isDebug()) Timber.tag(TAG).v("isAlive()");
return Single
.create((SingleEmitter<Boolean> emitter) -> {
if (ApiWrap.hasOreo()) {
emitter.onSuccess(process.isAlive());
} else {
try {
process.exitValue();
emitter.onSuccess(false);
} catch (IllegalThreadStateException e) {
emitter.onSuccess(true);
}
}
})
.subscribeOn(Schedulers.io());
}
示例4: onResolutionResult
import io.reactivex.SingleEmitter; //導入依賴的package包/類
static void onResolutionResult(String observableId, int resultCode) {
if (observableMap.containsKey(observableId)) {
SettingsCheckHandleSingleOnSubscribe observable = observableMap.get(observableId).get();
if (observable != null && observable.emitterWeakRef != null) {
SingleEmitter<Boolean> observer = observable.emitterWeakRef.get();
if (observer != null) {
observer.onSuccess(resultCode == Activity.RESULT_OK);
}
}
observableMap.remove(observableId);
}
observableMapCleanup();
}
示例5: subscribe
import io.reactivex.SingleEmitter; //導入依賴的package包/類
@Override
public final void subscribe(SingleEmitter<T> emitter) throws Exception {
final GoogleApiClient apiClient = createApiClient(new ApiClientConnectionCallbacks(emitter));
try {
apiClient.connect();
} catch (Throwable ex) {
emitter.onError(ex);
}
emitter.setCancellable(new Cancellable() {
@Override
public void cancel() throws Exception {
if (apiClient.isConnected()) {
RxLocationSingleOnSubscribe.this.onUnsubscribed(apiClient);
}
apiClient.disconnect();
}
});
}
示例6: saveSnapshotToStorage
import io.reactivex.SingleEmitter; //導入依賴的package包/類
public void saveSnapshotToStorage(final Bitmap bitmap, final String title) {
final int quality = SPUtils.getBoolean(Constants.SP_HD_SCREENSHOT) ? 100 : 90;
mComposite.add(Single.create(new SingleOnSubscribe<String>() {
@Override
public void subscribe(@NonNull SingleEmitter<String> e) throws Exception {
String address = IOUtils.saveBitmapToExternalStorage(bitmap, title, quality);
e.onSuccess(address);
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<String>() {
@Override
public void accept(String s) throws Exception {
mBaseView.onSnapshotSavedSucceeded(s);
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
mBaseView.onSnapshotSavedFailed(throwable);
}
}));
}
示例7: getList
import io.reactivex.SingleEmitter; //導入依賴的package包/類
public Single<List<CList>> getList(final int mFilterType, final String orderBy, final String limit, final String skip) {
return Single.create(new SingleOnSubscribe<List<CList>>() {
@Override
public void subscribe(SingleEmitter<List<CList>> emitter) throws Exception {
Cursor fetchCursor = getCursorByType(mFilterType, orderBy);
if (fetchCursor == null) {
emitter.onError(new Exception("Cursor is null"));
return;
}
Log.d(TAG, "|Start Filter Type = " + mFilterType + " " + new Date(System.currentTimeMillis()).toString() + "\n Cursor Count" + fetchCursor.getCount());
emitter.onSuccess(new ArrayList<>(fillMap(fetchCursor, mFilterType).values()));
}
});
}
示例8: deleteCollBookInRx
import io.reactivex.SingleEmitter; //導入依賴的package包/類
/************************************************************/
public Single<Void> deleteCollBookInRx(CollBookBean bean) {
return Single.create(new SingleOnSubscribe<Void>() {
@Override
public void subscribe(SingleEmitter<Void> e) throws Exception {
//查看文本中是否存在刪除的數據
deleteBook(bean.get_id());
//刪除任務
deleteDownloadTask(bean.get_id());
//刪除目錄
deleteBookChapter(bean.get_id());
//刪除CollBook
mCollBookDao.delete(bean);
e.onSuccess(new Void());
}
});
}
示例9: subscribe
import io.reactivex.SingleEmitter; //導入依賴的package包/類
@Override
public void subscribe(final SingleEmitter<QuerySnapshot> emitter) throws Exception {
OnCompleteListener<QuerySnapshot> listener = new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (!emitter.isDisposed()) {
if (task.isSuccessful()) {
emitter.onSuccess(task.getResult());
} else {
emitter.onError(task.getException());
}
}
}
};
collectionReference.get()
.addOnCompleteListener(listener);
}
示例10: toSingle
import io.reactivex.SingleEmitter; //導入依賴的package包/類
public Single<T> toSingle() {
return Single.create(new SingleOnSubscribe<T>() {
@Override
public void subscribe(final @NonNull SingleEmitter<T> e) throws Exception {
enqueue(new Callback<T>() {
@Override
public void onResponse(@NonNull T data) {
e.onSuccess(data);
}
}
, new ErrorCallback() {
@Override
public void onError(@NonNull Throwable error) {
e.onError(error);
}
}
);
}
});
}
示例11: subscribe
import io.reactivex.SingleEmitter; //導入依賴的package包/類
@Override
public final void subscribe(SingleEmitter<T> emitter) throws Exception {
final GoogleApiClient apiClient = createApiClient(new ApiClientConnectionCallbacks(emitter));
try {
apiClient.connect();
} catch (Throwable ex) {
emitter.onError(ex);
}
emitter.setCancellable(() -> {
if (apiClient.isConnected()) {
onUnsubscribed(apiClient);
}
apiClient.disconnect();
});
}
示例12: listener
import io.reactivex.SingleEmitter; //導入依賴的package包/類
/**
* @param emit
* @param <R>
* @return
*/
@NonNull
@CheckReturnValue
public static <R> OnCompleteListener<R> listener(@NonNull final SingleEmitter<R> emit) {
return new OnCompleteListener<R>() {
@Override
public void onComplete(@NonNull final Task<R> task) {
if (!emit.isDisposed()) {
if (task.isSuccessful()) {
emit.onSuccess(task.getResult());
} else {
Exception e = task.getException();
emit.onError(e != null ? e : new RuntimeException());
}
}
}
};
}
示例13: subscribe
import io.reactivex.SingleEmitter; //導入依賴的package包/類
@Override public void subscribe(final SingleEmitter<String> emitter) {
OnCompleteListener<GetTokenResult> listener = new OnCompleteListener<GetTokenResult>() {
@Override public void onComplete(@NonNull Task<GetTokenResult> task) {
if (!task.isSuccessful()) {
if (!emitter.isDisposed()) {
emitter.onError(task.getException());
}
return;
}
if (!emitter.isDisposed()) {
emitter.onSuccess(task.getResult().getToken());
}
}
};
user.getToken(forceRefresh).addOnCompleteListener(listener);
}
示例14: subscribe
import io.reactivex.SingleEmitter; //導入依賴的package包/類
@Override public void subscribe(final SingleEmitter<FirebaseUser> emitter) {
final OnCompleteListener<AuthResult> listener = new OnCompleteListener<AuthResult>() {
@Override public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
if (!emitter.isDisposed()) {
emitter.onError(task.getException());
}
return;
}
if (!emitter.isDisposed()) {
emitter.onSuccess(task.getResult().getUser());
}
}
};
createAuthTask(instance).addOnCompleteListener(listener);
}
示例15: listener
import io.reactivex.SingleEmitter; //導入依賴的package包/類
public static <T> OnCompleteListener<T> listener(@NonNull final SingleEmitter<T> emitter) {
return new OnCompleteListener<T>() {
@Override public void onComplete(@NonNull Task<T> task) {
if (!task.isSuccessful()) {
if (!emitter.isDisposed()) {
emitter.onError(task.getException());
}
return;
}
if (!emitter.isDisposed()) {
emitter.onSuccess(task.getResult());
}
}
};
}