當前位置: 首頁>>代碼示例>>Java>>正文


Java SingleEmitter類代碼示例

本文整理匯總了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();
                }
            });
        }
    });
}
 
開發者ID:greenrobot,項目名稱:ObjectBoxRxJava,代碼行數:25,代碼來源:RxQuery.java

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

        }
    });

}
 
開發者ID:penghuanliang,項目名稱:Rxjava2.0Demo,代碼行數:23,代碼來源:CreateActivity.java

示例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());
}
 
開發者ID:d4rken,項目名稱:RxShell,代碼行數:19,代碼來源:RxProcess.java

示例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();
}
 
開發者ID:TechIsFun,項目名稱:RxJava2-weather-example,代碼行數:18,代碼來源:SettingsCheckHandleSingleOnSubscribe.java

示例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();
        }
    });
}
 
開發者ID:TechIsFun,項目名稱:RxJava2-weather-example,代碼行數:22,代碼來源:RxLocationSingleOnSubscribe.java

示例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);
            }
        }));
}
 
開發者ID:nichbar,項目名稱:Aequorea,代碼行數:25,代碼來源:ArticlePresenter.java

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

            }
        });
    }
 
開發者ID:nitiwari-dev,項目名稱:android-contact-extractor,代碼行數:20,代碼來源:CListExtractorAbstract.java

示例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());
        }
    });
}
 
開發者ID:newbiechen1024,項目名稱:NovelReader,代碼行數:18,代碼來源:BookRepository.java

示例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);
}
 
開發者ID:btrautmann,項目名稱:RxFirestore,代碼行數:22,代碼來源:GetCollectionOnSubscribe.java

示例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);
                        }
                    }
            );
        }
    });
}
 
開發者ID:florent37,項目名稱:Android-OkGraphQl,代碼行數:21,代碼來源:AbstractQuery.java

示例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();
    });
}
 
開發者ID:florent37,項目名稱:RxGps,代碼行數:19,代碼來源:RxLocationSingleOnSubscribe.java

示例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());
                }
            }
        }
    };
}
 
開發者ID:yongjhih,項目名稱:rxtasks,代碼行數:23,代碼來源:RxTask.java

示例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);
}
 
開發者ID:b3er,項目名稱:RxFirebase2,代碼行數:19,代碼來源:UserGetTokenOnSubscribe.java

示例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);
}
 
開發者ID:b3er,項目名稱:RxFirebase2,代碼行數:18,代碼來源:BaseAuthOnSubscribe.java

示例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());
      }
    }
  };
}
 
開發者ID:b3er,項目名稱:RxFirebase2,代碼行數:17,代碼來源:GmsTaskListeners.java


注:本文中的io.reactivex.SingleEmitter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。