Search in sources :

Example 11 with GoogleSignInAccount

use of com.google.android.gms.auth.api.signin.GoogleSignInAccount in project google-services by googlesamples.

the class SignInActivityWithDrive method handleSignInResult.

// [END onActivityResult]
// [START handleSignInResult]
private void handleSignInResult(GoogleSignInResult result) {
    Log.d(TAG, "handleSignInResult:" + result.isSuccess());
    if (result.isSuccess()) {
        // Signed in successfully, show authenticated UI.
        GoogleSignInAccount acct = result.getSignInAccount();
        mStatusTextView.setText(getString(R.string.signed_in_fmt, acct.getDisplayName()));
        updateUI(true);
    } else {
        // Signed out, show unauthenticated UI.
        updateUI(false);
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount)

Example 12 with GoogleSignInAccount

use of com.google.android.gms.auth.api.signin.GoogleSignInAccount in project iosched by google.

the class SwitchUserActivity method handleSignInResult.

/**
     * Update active account and inform calling task of result completion.
     * Invoked after after the GoogleSignInApi login process completes (which is itself invoked
     * in SignOutCallback).
     *
     * <p>In the event the user cancels login, the last known user is restored.
     *
     * @param result User data from GoogleSignInApi
     */
private void handleSignInResult(final GoogleSignInResult result) {
    if (result.isSuccess()) {
        final GoogleSignInAccount newUser = result.getSignInAccount();
        if (newUser != null) {
            AccountUtils.setActiveAccount(this, newUser.getEmail());
            LOGI(TAG, "Switched to user: " + newUser);
            setResult(Activity.RESULT_OK);
        }
    } else {
        // Login failed, revert to previous user to simulate spinner behavior
        LOGI(TAG, "Account switch aborted, re-enabling previous user: " + mPreviousUser);
        AccountUtils.setActiveAccount(this, mPreviousUser);
        setResult(Activity.RESULT_CANCELED);
    }
    finish();
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount)

Example 13 with GoogleSignInAccount

use of com.google.android.gms.auth.api.signin.GoogleSignInAccount in project iosched by google.

the class AccountFragment method handleSignInResult.

private void handleSignInResult(final GoogleSignInResult result) {
    Log.d(TAG, "handleSignInResult:" + result.isSuccess());
    if (result.isSuccess()) {
        // Signed in successfully, show authenticated UI.
        final GoogleSignInAccount acct = result.getSignInAccount();
        if (acct != null) {
            AccountUtils.setActiveAccount(getContext(), acct.getEmail());
            doNext();
        }
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount)

Example 14 with GoogleSignInAccount

use of com.google.android.gms.auth.api.signin.GoogleSignInAccount in project YourAppIdea by Michenux.

the class GoogleAuthDelegate method handleSignInResult.

private void handleSignInResult(GoogleSignInResult result) {
    if (BuildConfig.DEBUG) {
        Log.d(MCXApplication.LOG_TAG, "handleSignInResult:" + result.isSuccess() + " " + result.getStatus().getStatusCode() + result.getStatus().hasResolution());
    }
    if (result.isSuccess()) {
        // Signed in successfully, show authenticated UI.
        GoogleSignInAccount acct = result.getSignInAccount();
        User user = new User();
        user.setProvider(PROVIDER_NAME);
        user.setProviderDisplayName("Google+");
        user.setUserId(acct.getId());
        user.setUserName(acct.getId());
        user.setDisplayName(acct.getDisplayName());
        user.setMail(acct.getEmail());
        this.mUserHelper.setCurrentUser(user);
        if (this.mUserSessionCallback != null) {
            this.mUserSessionCallback.onLogin();
        }
    } else {
        // Signed out, show unauthenticated UI.
        this.mUserSessionCallback.onLogout();
    }
}
Also used : User(org.michenux.drodrolib.security.User) GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount)

Example 15 with GoogleSignInAccount

use of com.google.android.gms.auth.api.signin.GoogleSignInAccount in project Android by Tracman-org.

the class LoginActivity method handleGoogleSignInResult.

private void handleGoogleSignInResult(GoogleSignInResult result) {
    //Log.d(TAG, "handleSignInResult:" + result.isSuccess());
    if (result.isSuccess()) {
        // Signed in successfully
        GoogleSignInAccount acct = result.getSignInAccount();
        try {
            // Build request
            Request request = new Request.Builder().url(SERVER_ADDRESS + "login/app/google?id_token=" + acct.getIdToken()).build();
            // Send to server
            authenticateWithTracmanServer(request);
        } catch (Exception e) {
        //Log.e(TAG, "Error sending ID token to backend.", e);
        }
    } else {
        //Log.e(TAG, "Failed to log in: "+result.getStatus().getStatusCode());
        if (result.getStatus().getStatusCode() != 4) {
            showError(R.string.google_connection_error);
        }
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) Request(okhttp3.Request) JSONException(org.json.JSONException) IOException(java.io.IOException)

Aggregations

GoogleSignInAccount (com.google.android.gms.auth.api.signin.GoogleSignInAccount)16 GoogleSignInResult (com.google.android.gms.auth.api.signin.GoogleSignInResult)5 IOException (java.io.IOException)2 JSONException (org.json.JSONException)2 Response (com.android.volley.Response)1 VolleyError (com.android.volley.VolleyError)1 ConnectionResult (com.google.android.gms.common.ConnectionResult)1 GoogleApiClient (com.google.android.gms.common.api.GoogleApiClient)1 GoogleAuthorizationCodeTokenRequest (com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest)1 GoogleTokenResponse (com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse)1 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)1 CustomRequest (dz.easy.androidclient.Util.CustomRequest)1 HashMap (java.util.HashMap)1 Request (okhttp3.Request)1 JSONObject (org.json.JSONObject)1 User (org.michenux.drodrolib.security.User)1