本文整理匯總了Java中io.reactivex.Maybe.create方法的典型用法代碼示例。如果您正苦於以下問題:Java Maybe.create方法的具體用法?Java Maybe.create怎麽用?Java Maybe.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.reactivex.Maybe
的用法示例。
在下文中一共展示了Maybe.create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: findKeyPairFor
import io.reactivex.Maybe; //導入方法依賴的package包/類
@Override
public Maybe<AesKeyPair> findKeyPairFor(int accountId, long sessionId) {
return Maybe.create(e -> {
Uri uri = MessengerContentProvider.getKeysContentUriFor(accountId);
Cursor cursor = getContext().getContentResolver()
.query(uri, null, KeyColumns.SESSION_ID + " = ?",
new String[]{String.valueOf(sessionId)}, null);
AesKeyPair pair = null;
if(nonNull(cursor)){
if(cursor.moveToNext()){
pair = map(cursor).setAccountId(accountId);
}
cursor.close();
}
if(nonNull(pair)){
e.onSuccess(pair);
}
e.onComplete();
});
}
示例2: main
import io.reactivex.Maybe; //導入方法依賴的package包/類
public static void main(String[] args) {
// TODO Auto-generated method stub
Maybe<List<String>> month_maybe = Maybe.create(emitter -> {
try {
String[] monthArray = { "Jan", "Feb", "Mar", "Apl", "May", "Jun", "July", "Aug", "Sept", "Oct", "Nov",
"Dec" };
List<String> months = Arrays.asList(monthArray);
if (months != null && !months.isEmpty()) {
emitter.onSuccess(months);
} else {
emitter.onComplete();
}
} catch (Exception e) {
emitter.onError(e);
}
});
month_maybe.subscribe(s->System.out.println(s));
}
示例3: maybe
import io.reactivex.Maybe; //導入方法依賴的package包/類
/**
* @param task
* @param <R>
* @return
*/
@CheckReturnValue
@NonNull
public static <R> Maybe<R> maybe(@NonNull final Task<R> task) {
return Maybe.create(new MaybeOnSubscribe<R>() {
@Override
public void subscribe(@NonNull final MaybeEmitter<R> emit) throws Exception {
task.addOnCompleteListener(listener(emit));
}
});
}
示例4: putStream
import io.reactivex.Maybe; //導入方法依賴的package包/類
/**
* @param storageRef represents a reference to a Google Cloud Storage object.
* @param stream The InputStream to upload.
* @param metadata {@link StorageMetadata} containing additional information (MIME type, etc.) about the object being uploaded.
* @return a {@link Maybe} which emits an {@link UploadTask.TaskSnapshot} if success.
*/
@NonNull
public static Maybe<UploadTask.TaskSnapshot> putStream(@NonNull final StorageReference storageRef,
@NonNull final InputStream stream,
@NonNull final StorageMetadata metadata) {
return Maybe.create(new MaybeOnSubscribe<UploadTask.TaskSnapshot>() {
@Override
public void subscribe(MaybeEmitter<UploadTask.TaskSnapshot> emitter) throws Exception {
RxHandler.assignOnTask(emitter, storageRef.putStream(stream, metadata));
}
});
}
示例5: putFile
import io.reactivex.Maybe; //導入方法依賴的package包/類
/**
* Asynchronously uploads from a content URI to this {@link StorageReference}.
*
* @param storageRef represents a reference to a Google Cloud Storage object.
* @param uri The source of the upload. This can be a file:// scheme or any content URI. A content resolver will be used to load the data.
* @param metadata {@link StorageMetadata} containing additional information (MIME type, etc.) about the object being uploaded.
* @param existingUploadUri If set, an attempt is made to resume an existing upload session as defined by getUploadSessionUri().
* @return a {@link Maybe} which emits an {@link UploadTask.TaskSnapshot} if success.
*/
@NonNull
public static Maybe<UploadTask.TaskSnapshot> putFile(@NonNull final StorageReference storageRef,
@NonNull final Uri uri,
@NonNull final StorageMetadata metadata,
@NonNull final Uri existingUploadUri) {
return Maybe.create(new MaybeOnSubscribe<UploadTask.TaskSnapshot>() {
@Override
public void subscribe(MaybeEmitter<UploadTask.TaskSnapshot> emitter) throws Exception {
RxHandler.assignOnTask(emitter, storageRef.putFile(uri, metadata, existingUploadUri));
}
});
}
示例6: putBytes
import io.reactivex.Maybe; //導入方法依賴的package包/類
/**
* Asynchronously uploads byte data to this {@link StorageReference}.
*
* @param storageRef represents a reference to a Google Cloud Storage object.
* @param bytes The byte[] to upload.
* @return a {@link Maybe} which emits an {@link UploadTask.TaskSnapshot} if success.
*/
@NonNull
public static Maybe<UploadTask.TaskSnapshot> putBytes(@NonNull final StorageReference storageRef,
@NonNull final byte[] bytes) {
return Maybe.create(new MaybeOnSubscribe<UploadTask.TaskSnapshot>() {
@Override
public void subscribe(MaybeEmitter<UploadTask.TaskSnapshot> emitter) throws Exception {
RxHandler.assignOnTask(emitter, storageRef.putBytes(bytes));
}
});
}
示例7: getProfile
import io.reactivex.Maybe; //導入方法依賴的package包/類
@Override
public Maybe<Profile> getProfile(final String uid) {
return Maybe.create(
new MaybeOnSubscribe<Profile>() {
@Override
public void subscribe(final MaybeEmitter e) throws Exception {
final DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference idRef = rootRef.child(USER_PROFILES).child(uid);
idRef.addListenerForSingleValueEvent(new ValueEventListener() {
//does this check node for activeUser exists?
@Override
public void onDataChange(DataSnapshot snapshot) {
if (snapshot.exists()) {
//setUpProfilePageComponent(
Profile profile = snapshot.getValue(Profile.class);
e.onSuccess(profile);
} else {
e.onComplete();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.d("FIREBASE", databaseError.toString());
}
});
}
}
);
}
示例8: getThumbnails
import io.reactivex.Maybe; //導入方法依賴的package包/類
@Override
public Maybe<List<Photo>> getThumbnails(final ContentResolver resolver) {
return Maybe.create(
new MaybeOnSubscribe<List<Photo>>() {
@Override
public void subscribe(final MaybeEmitter<List<Photo>> e) throws Exception {
Uri uri;
List<Photo> listOfAllPhotos = new ArrayList<Photo>();
Cursor cursor;
int column_index_data;
Uri imageUri;
uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String[] projection = {MediaStore.MediaColumns.DATA};
cursor = resolver.query(uri, projection, null,
null, null);
try {
column_index_data = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
while (cursor.moveToNext()) {
imageUri = Uri.parse("file://" + cursor.getString(column_index_data));
listOfAllPhotos.add(new Photo(imageUri.toString()));
}
cursor.close();
} catch (Throwable t) {
if (cursor != null) {
cursor.close();
}
e.onError(t);
}
if (listOfAllPhotos.size() == 0) {
e.onComplete();
} else {
e.onSuccess(listOfAllPhotos);
}
}
}
);
}
示例9: getUser
import io.reactivex.Maybe; //導入方法依賴的package包/類
@Override
public Maybe<User> getUser() {
return Maybe.create(
new MaybeOnSubscribe<User>() {
@Override
public void subscribe(final MaybeEmitter<User> e) throws Exception {
if (auth == null) {
auth = FirebaseAuth.getInstance();
}
if (listener != null) {
auth.removeAuthStateListener(listener);
}
listener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
auth.removeAuthStateListener(listener);
if (firebaseUser != null) {
User user = new User(
firebaseUser.getEmail(),
firebaseUser.getUid()
);
Maybe.just(user);
e.onSuccess(user);
} else {
e.onComplete();
}
}
};
auth.addAuthStateListener(listener);
}
}
);
}
示例10: getToken
import io.reactivex.Maybe; //導入方法依賴的package包/類
/**
* Fetches a Firebase Auth ID Token for the user; useful when authenticating against your own backend.
*
* @param firebaseUser current firebaseUser instance.
* @param forceRefresh force to refresh the token ID.
* @return a {@link Maybe} which emits an {@link GetTokenResult} if success.
*/
@NonNull
public static Maybe<GetTokenResult> getToken(@NonNull final FirebaseUser firebaseUser,
final boolean forceRefresh) {
return Maybe.create(new MaybeOnSubscribe<GetTokenResult>() {
@Override
public void subscribe(MaybeEmitter<GetTokenResult> emitter) throws Exception {
RxHandler.assignOnTask(emitter, firebaseUser.getToken(forceRefresh));
}
});
}
示例11: linkWithCredential
import io.reactivex.Maybe; //導入方法依賴的package包/類
/**
* Attaches the given {@link AuthCredential} to the user.
*
* @param firebaseUser current firebaseUser instance.
* @param credential new {@link AuthCredential} to link.
* @return a {@link Maybe} which emits an {@link AuthResult} if success.
*/
@NonNull
public static Maybe<AuthResult> linkWithCredential(@NonNull final FirebaseUser firebaseUser,
@NonNull final AuthCredential credential) {
return Maybe.create(new MaybeOnSubscribe<AuthResult>() {
@Override public void subscribe(MaybeEmitter<AuthResult> emitter) throws Exception {
RxHandler.assignOnTask(emitter, firebaseUser.linkWithCredential(credential));
}
});
}
示例12: updateMetadata
import io.reactivex.Maybe; //導入方法依賴的package包/類
/**
* Asynchronously uploads a stream of data to this {@link StorageReference}.
*
* @param storageRef represents a reference to a Google Cloud Storage object.
* @param metadata {@link StorageMetadata} containing additional information (MIME type, etc.) about the object being uploaded.
* @return a {@link Maybe} which emits an {@link StorageMetadata} if success.
*/
@NonNull
public static Maybe<StorageMetadata> updateMetadata(@NonNull final StorageReference storageRef,
@NonNull final StorageMetadata metadata) {
return Maybe.create(new MaybeOnSubscribe<StorageMetadata>() {
@Override
public void subscribe(MaybeEmitter<StorageMetadata> emitter) throws Exception {
RxHandler.assignOnTask(emitter, storageRef.updateMetadata(metadata));
}
});
}
示例13: signInAnonymously
import io.reactivex.Maybe; //導入方法依賴的package包/類
/**
* Asynchronously signs in as an anonymous user.
* If there is already an anonymous user signed in, that user will be returned; otherwise, a new anonymous user identity will be created and returned.
*
* @param firebaseAuth firebaseAuth instance.
* @return a {@link Maybe} which emits an {@link AuthResult} if success.
* @see <a href="https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseAuth">Firebase Auth API</a>
*/
@NonNull
public static Maybe<AuthResult> signInAnonymously(@NonNull final FirebaseAuth firebaseAuth) {
return Maybe.create(new MaybeOnSubscribe<AuthResult>() {
@Override
public void subscribe(MaybeEmitter<AuthResult> emitter) throws Exception {
RxHandler.assignOnTask(emitter, firebaseAuth.signInAnonymously());
}
});
}
示例14: signInWithCredential
import io.reactivex.Maybe; //導入方法依賴的package包/類
/**
* Asynchronously signs in with the given credentials.
*
* @param firebaseAuth firebaseAuth instance.
* @param credential The auth credential. Value must not be null.
* @return a {@link Maybe} which emits an {@link AuthResult} if success.
* @see <a href="https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseAuth">Firebase Auth API</a>
*/
@NonNull
public static Maybe<AuthResult> signInWithCredential(@NonNull final FirebaseAuth firebaseAuth,
@NonNull final AuthCredential credential) {
return Maybe.create(new MaybeOnSubscribe<AuthResult>() {
@Override
public void subscribe(MaybeEmitter<AuthResult> emitter) throws Exception {
RxHandler.assignOnTask(emitter, firebaseAuth.signInWithCredential(credential));
}
});
}
示例15: getStream
import io.reactivex.Maybe; //導入方法依賴的package包/類
/**
* Asynchronously downloads the object at this {@link StorageReference} via a InputStream.
*
* @param storageRef represents a reference to a Google Cloud Storage object.
* @return a {@link Maybe} which emits an {@link StreamDownloadTask.TaskSnapshot} if success.
*/
@NonNull
public static Maybe<StreamDownloadTask.TaskSnapshot> getStream(@NonNull final StorageReference storageRef) {
return Maybe.create(new MaybeOnSubscribe<StreamDownloadTask.TaskSnapshot>() {
@Override
public void subscribe(MaybeEmitter<StreamDownloadTask.TaskSnapshot> emitter) throws Exception {
RxHandler.assignOnTask(emitter, storageRef.getStream());
}
});
}