当前位置: 首页>>代码示例>>Java>>正文


Java OnCompleteListener类代码示例

本文整理汇总了Java中com.google.android.gms.tasks.OnCompleteListener的典型用法代码示例。如果您正苦于以下问题:Java OnCompleteListener类的具体用法?Java OnCompleteListener怎么用?Java OnCompleteListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


OnCompleteListener类属于com.google.android.gms.tasks包,在下文中一共展示了OnCompleteListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: firebaseAuthWithGoogle

import com.google.android.gms.tasks.OnCompleteListener; //导入依赖的package包/类
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGooogle:" + acct.getId());
    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mFirebaseAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());

                    // If sign in fails, display a message to the user. If sign in succeeds
                    // the auth state listener will be notified and logic to handle the
                    // signed in user can be handled in the listener.
                    if (!task.isSuccessful()) {
                        Log.w(TAG, "signInWithCredential", task.getException());
                        Toast.makeText(SignInActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    } else {
                        startActivity(new Intent(SignInActivity.this, MainActivity.class));
                        finish();
                    }
                }
            });
}
 
开发者ID:YoWenqin,项目名称:BuddiesGo,代码行数:24,代码来源:SignInActivity.java

示例2: LoginVersuch

import com.google.android.gms.tasks.OnCompleteListener; //导入依赖的package包/类
private void LoginVersuch() {
//  // https://firebase.google.com/docs/auth/android/password-auth
        email = et_mail.getText().toString();
        pwd = et_password.getText().toString();
        mAuth.signInWithEmailAndPassword(email, pwd)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if (!task.isSuccessful()) {
                            Log.w("AndroidLoginVersuch", "signInWithEmail:failed", task.getException());
                            Toast.makeText(LoginActivity.this, "Sorry, der Login ist leider fehlgeschlagen.",
                                    Toast.LENGTH_SHORT).show();
                        } else {
                            Log.d("AndroidLoginVersuch", "signInWithEmail:onComplete:");
                            startActivity(new Intent(LoginActivity.this, MainActivity.class));
                        }
                    }
                });

    }
 
开发者ID:burliEnterprises,项目名称:chapp-messenger,代码行数:21,代码来源:LoginActivity.java

示例3: onWriteClicked

import com.google.android.gms.tasks.OnCompleteListener; //导入依赖的package包/类
private void onWriteClicked() {
    String random = UUID.randomUUID().toString();
    Map<String, Object> map = new HashMap<>();
    map.put("text", random);

    mFirestore.collection(DEFAULT_COLLECTION)
            .document()
            .set(map)
            .addOnCompleteListener(this, new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    Log.d(TAG, "write:onComplete");
                    if (!task.isSuccessful()) {
                        Log.w(TAG, "write:onComplete:failed", task.getException());
                    }
                }
            });
}
 
开发者ID:firebase,项目名称:snippets-android,代码行数:19,代码来源:MainActivity.java

示例4: onCreate

import com.google.android.gms.tasks.OnCompleteListener; //导入依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_test);

    FirebaseApp.initializeApp(this);
    FirebaseAuth.getInstance().addAuthStateListener(this);

    FirebaseAuth.getInstance().signInAnonymously()
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d(TAG, "signInAnonymously:onComplete:" + task.isSuccessful());

                    // If sign in fails, display a message to the user. If sign in succeeds
                    // the auth state listener will be notified and logic to handle the
                    // signed in user can be handled in the listener.
                    if (!task.isSuccessful()) {
                        Log.w(TAG, "signInAnonymously", task.getException());
                        Toast.makeText(TestActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }
                }
            });
}
 
开发者ID:crysxd,项目名称:shared-firebase-preferences,代码行数:27,代码来源:TestActivity.java

示例5: updateProfile

import com.google.android.gms.tasks.OnCompleteListener; //导入依赖的package包/类
private void updateProfile() {
    // [START update_profile]
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

    UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
            .setDisplayName("Jane Q. User")
            .setPhotoUri(Uri.parse("https://example.com/jane-q-user/profile.jpg"))
            .build();

    user.updateProfile(profileUpdates)
            .addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if (task.isSuccessful()) {
                        Log.d(TAG, "User profile updated.");
                    }
                }
            });
    // [END update_profile]
}
 
开发者ID:firebase,项目名称:snippets-android,代码行数:21,代码来源:MainActivity.java

示例6: firebaseAuthWithGoogle

import com.google.android.gms.tasks.OnCompleteListener; //导入依赖的package包/类
/**
 * Authenticate Google user with Firebase
 * @param acct Google account
 */
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());

    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(mContext, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        // Sign in success, update UI with the signed-in user's information
                        Log.d(TAG, "signInWithCredential:success");
                        onSuccess();
                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w(TAG, "signInWithCredential:failure", task.getException());
                        onFailed();
                    }
                }
            });
}
 
开发者ID:CMPUT301F17T13,项目名称:cat-is-a-dog,代码行数:25,代码来源:GoogleAuthenticator.java

示例7: handleRatingUpdateAction

import com.google.android.gms.tasks.OnCompleteListener; //导入依赖的package包/类
@Override
public void handleRatingUpdateAction(int fontIndex, UrduFont font) {
    if (font == null) {
        handleError(R.string.error_message_unknown_font);
    } else {
        tracker.submitFontRating(font.getName(), font.getLastRatingValue());
        databaseReference.child(String.valueOf(fontIndex))
                .setValue(font)
                .addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {
                        if (task.isSuccessful()) {
                            view.showToast(R.string.thank_you);
                        } else {
                            handleError(R.string.error_unable_to_update_rating);
                        }
                    }
                });
    }
}
 
开发者ID:wahibhaq,项目名称:urdu-font-comparator-app,代码行数:21,代码来源:MainPresenter.java

示例8: createAccount

import com.google.android.gms.tasks.OnCompleteListener; //导入依赖的package包/类
/**
 * Method createAccount
 *
 * Allows an unregistered user to create himself an account.
 *
 * @param email mail address used for his account
 * @param password password to access his account
 */
private void createAccount(String email, String password)
{
    mFirebaseAuth.createUserWithEmailAndPassword(email, password)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful());

                        // If sign in fails, display a message to the user. If sign in succeeds
                        // the auth state listener will be notified and logic to handle the
                        // signed in user can be handled in the listener.
                        if (!task.isSuccessful()) {
                            Log.w(TAG, "signInWithEmail", task.getException());
                            Toast.makeText(LoginActivity.this, "Authentication failed.",
                                    Toast.LENGTH_SHORT).show();
                        } else {
                            startActivity(new Intent(LoginActivity.this, HomeActivity.class));
                            finish();
                        }
                    }
                });
}
 
开发者ID:jkobject,项目名称:PiPle,代码行数:31,代码来源:LoginActivity.java

示例9: listener

import com.google.android.gms.tasks.OnCompleteListener; //导入依赖的package包/类
/**
 * @param emit
 * @param <R>
 * @return
 */
@NonNull
@CheckReturnValue
public static <R> OnCompleteListener<R> listener(@NonNull final CompletableEmitter emit) {
    return new OnCompleteListener<R>() {
        @Override
        public void onComplete(@NonNull final Task<R> task) {
            if (!emit.isDisposed()) {
                if (task.isSuccessful()) {
                    emit.onComplete();
                } else {
                    Exception e = task.getException();
                    emit.onError(e != null ? e : new RuntimeException());
                }
            }
        }
    };
}
 
开发者ID:yongjhih,项目名称:rxtasks,代码行数:23,代码来源:RxTask.java

示例10: shotenLongLink

import com.google.android.gms.tasks.OnCompleteListener; //导入依赖的package包/类
public void shotenLongLink() {
    // [START shorten_long_link]
    Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()
            .setLongLink(Uri.parse("https://abc123.app.goo.gl/?link=https://example.com/&apn=com.example.android&ibn=com.example.ios"))
            .buildShortDynamicLink()
            .addOnCompleteListener(this, new OnCompleteListener<ShortDynamicLink>() {
                @Override
                public void onComplete(@NonNull Task<ShortDynamicLink> task) {
                    if (task.isSuccessful()) {
                        // Short link created
                        Uri shortLink = task.getResult().getShortLink();
                        Uri flowchartLink = task.getResult().getPreviewLink();
                    } else {
                        // Error
                        // ...
                    }
                }
            });
    // [END shorten_long_link]
}
 
开发者ID:firebase,项目名称:snippets-android,代码行数:21,代码来源:MainActivity.java

示例11: removePost

import com.google.android.gms.tasks.OnCompleteListener; //导入依赖的package包/类
public void removePost(final Post post, final OnTaskCompleteListener onTaskCompleteListener) {
    final DatabaseHelper databaseHelper = ApplicationHelper.getDatabaseHelper();
    Task<Void> removeImageTask = removeImage(post.getImageTitle());

    removeImageTask.addOnSuccessListener(new OnSuccessListener<Void>() {
        @Override
        public void onSuccess(Void aVoid) {
            databaseHelper.removePost(post).addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    onTaskCompleteListener.onTaskComplete(task.isSuccessful());
                    databaseHelper.updateProfileLikeCountAfterRemovingPost(post);
                    LogUtil.logDebug(TAG, "removePost(), is success: " + task.isSuccessful());
                }
            });
            LogUtil.logDebug(TAG, "removeImage(): success");
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception exception) {
            LogUtil.logError(TAG, "removeImage()", exception);
            onTaskCompleteListener.onTaskComplete(false);
        }
    });
}
 
开发者ID:rozdoum,项目名称:social-app-android,代码行数:26,代码来源:PostManager.java

示例12: getSignRequest

import com.google.android.gms.tasks.OnCompleteListener; //导入依赖的package包/类
private void getSignRequest() {
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS)
            == PackageManager.PERMISSION_GRANTED) {
        Log.i(TAG, "getSignRequest permission is granted");
        Task<SignRequestParams> getSignRequestTask = asyncGetSignRequest();
        getSignRequestTask.addOnCompleteListener(new OnCompleteListener<SignRequestParams>() {
            @Override
            public void onComplete(@NonNull Task<SignRequestParams> task) {
                SignRequestParams signRequest = task.getResult();
                if (signRequest == null) {
                    Log.i(TAG, "signRequest is null");
                    return;
                }
                sendSignRequestToClient(signRequest);
            }
        });
    } else {
        Log.i(TAG, "getSignRequest permission is requested");
        ActivityCompat.requestPermissions(
                this,
                new String[]{Manifest.permission.GET_ACCOUNTS},
                GET_ACCOUNTS_PERMISSIONS_REQUEST_SIGN);
    }
}
 
开发者ID:googlesamples,项目名称:android-fido,代码行数:25,代码来源:U2FDemoActivity.java

示例13: handleFacebookAccessToken

import com.google.android.gms.tasks.OnCompleteListener; //导入依赖的package包/类
private void handleFacebookAccessToken(AccessToken token) {
    Log.d(TAG, "handleFacebookAccessToken:" + token);
    AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
    fireBaseAuth.signInWithCredential(credential)
            .addOnCompleteListener(getActivity(), new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
                    // If sign in fails, display a message to the user. If sign in succeeds
                    // the auth state listener will be notified and logic to handle the
                    // signed in user can be handled in the listener.
                    if (!task.isSuccessful()) {
                        Log.w(TAG, "signInWithCredential", task.getException());
                        Toast.makeText(getApplicationContext(), "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }
                }
            });
}
 
开发者ID:Pavou,项目名称:Stalker,代码行数:20,代码来源:AuthenticateFragment.java

示例14: handleAccessToken

import com.google.android.gms.tasks.OnCompleteListener; //导入依赖的package包/类
public void handleAccessToken(AccessToken token) {
	Utils.d("FB:Handle:AccessToken: " + token.getToken());
	// showProgressDialog();

	AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());

	mAuth.signInWithCredential(credential)
	.addOnCompleteListener(activity, new OnCompleteListener<AuthResult>() {

		@Override
		public void onComplete(@NonNull Task<AuthResult> task) {
			Utils.d("FB:signInWithCredential:onComplete:" + task.isSuccessful());

			// If sign in fails, display a message to the user. If sign in succeeds
			// the auth state listener will be notified and logic to handle the
			// signed in user can be handled in the listener.

			if (!task.isSuccessful()) {
				Utils.w("FB:signInWithCredential" + 
					task.getException().toString());
			}

			// hideProgressDialog();
		}
	});
}
 
开发者ID:FrogSquare,项目名称:GodotFireBase,代码行数:27,代码来源:FacebookSignIn.java

示例15: firebaseAuthWithGoogle

import com.google.android.gms.tasks.OnCompleteListener; //导入依赖的package包/类
/**
 * Method firebaseAuthWithGoogle
 *
 * Authenticates in Firebase through a Google Account.
 */
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());

    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mFirebaseAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());

                    // If sign in fails, display a message to the user. If sign in succeeds
                    // the auth state listener will be notified and logic to handle the
                    // signed in user can be handled in the listener.
                    if (!task.isSuccessful()) {
                        Log.w(TAG, "signInWithCredential", task.getException());
                        Toast.makeText(LoginActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }
                    else {
                        startActivity(new Intent(LoginActivity.this, HomeActivity.class));
                        finish();
                    }
                }
            });
}
 
开发者ID:jkobject,项目名称:PiPle,代码行数:31,代码来源:LoginActivity.java


注:本文中的com.google.android.gms.tasks.OnCompleteListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。