com.google.android.gms.auth.api.credentials.CredentialRequest

Here are the examples of the java api class com.google.android.gms.auth.api.credentials.CredentialRequest taken from open source projects.

1. SmartLock#showCredentialPicker()

Project: easygoogle
File: SmartLock.java
/**
     * Show the dialog allowing the user to choose a Credential. This method shoud only be called
     * after you receive the {@link SmartLockListener#onShouldShowCredentialPicker()} callback.
     */
public void showCredentialPicker() {
    CredentialRequest request = buildCredentialRequest();
    Activity activity = getFragment().getActivity();
    int maskedCode = getFragment().maskRequestCode(RC_READ);
    Auth.CredentialsApi.request(getFragment().getGoogleApiClient(), request).setResultCallback(new ResolvingResultCallbacks<CredentialRequestResult>(activity, maskedCode) {

        @Override
        public void onSuccess(CredentialRequestResult result) {
            getListener().onCredentialRetrieved(result.getCredential());
        }

        @Override
        public void onUnresolvableFailure(Status status) {
            Log.e(TAG, "showCredentialPicker:onUnresolvableFailure:" + status);
        }
    });
}

2. SmartLock#getCredentials()

Project: easygoogle
File: SmartLock.java
/**
     * Begin the process of retrieving a {@link Credential} for the device user. This can have
     * a few different results:
     *   1) If the user has auto sign-in enabled and exactly one previously saved credential,
     *      {@link SmartLockListener#onCredentialRetrieved(Credential)} will be called and
     *      you can sign the user in immediately.
     *   2) If the user has multiple saved credentials or one saved credential and has disabled
     *      auto sign-in, you will get the callback {@link SmartLockListener#onShouldShowCredentialPicker()}
     *      at which point you can choose to show the picker dialog to continue.
     *   3) If the user has no saved credentials or cancels the operation, you will receive the
     *      {@link SmartLockListener#onCredentialRetrievalFailed()} callback.
     */
public void getCredentials() {
    CredentialRequest request = buildCredentialRequest();
    Auth.CredentialsApi.request(getFragment().getGoogleApiClient(), request).setResultCallback(new ResultCallback<CredentialRequestResult>() {

        @Override
        public void onResult(CredentialRequestResult result) {
            if (result.getStatus().isSuccess()) {
                // Single credential, auto sign-in
                Credential credential = result.getCredential();
                getListener().onCredentialRetrieved(credential);
            } else if (result.getStatus().hasResolution() && result.getStatus().getStatusCode() != CommonStatusCodes.SIGN_IN_REQUIRED) {
                // Multiple credentials or auto-sign in disabled.  If the status
                // code is SIGN_IN_REQUIRED then it is a hint credential, which we
                // do not want at this point.
                getListener().onShouldShowCredentialPicker();
            } else {
                // Could not retrieve credentials
                getListener().onCredentialRetrievalFailed();
            }
        }
    });
}

3. SmartLockHelper#smartLockAutoFill()

Project: WordPress-Android
File: SmartLockHelper.java
public void smartLockAutoFill(@NonNull final Callback callback) {
    Activity activity = getActivityAndCheckAvailability();
    if (activity == null || mCredentialsClient == null || !mCredentialsClient.isConnected()) {
        return;
    }
    CredentialRequest credentialRequest = new CredentialRequest.Builder().setPasswordLoginSupported(true).build();
    Auth.CredentialsApi.request(mCredentialsClient, credentialRequest).setResultCallback(new ResultCallback<CredentialRequestResult>() {

        @Override
        public void onResult(@NonNull CredentialRequestResult result) {
            Status status = result.getStatus();
            if (status.isSuccess()) {
                Credential credential = result.getCredential();
                callback.onCredentialRetrieved(credential);
            } else {
                if (status.getStatusCode() == CommonStatusCodes.RESOLUTION_REQUIRED) {
                    try {
                        Activity activity = getActivityAndCheckAvailability();
                        if (activity == null) {
                            return;
                        }
                        // Prompt the user to choose a saved credential
                        status.startResolutionForResult(activity, SignInActivity.SMART_LOCK_READ);
                    } catch (IntentSender.SendIntentException e) {
                        AppLog.d(T.NUX, "SmartLock: Failed to send resolution for credential request");
                    }
                } else {
                    // The user must create an account or sign in manually.
                    AppLog.d(T.NUX, "SmartLock: Unsuccessful credential request.");
                }
            }
        }
    });
}