当前位置: 首页>>代码示例>>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;未经允许,请勿转载。