Search in sources :

Example 1 with OptionalPendingResult

use of com.google.android.gms.common.api.OptionalPendingResult in project Android-SDK by Backendless.

the class LoginWithGooglePlusSDKActivity method initUIBehaviour.

private void initUIBehaviour() {
    configureGooglePlusSDK();
    if (mGoogleApiClient.isConnected()) {
        OptionalPendingResult pendingResult = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
        if (pendingResult.isDone())
            handleSignInResult((GoogleSignInResult) pendingResult.get());
    }
    gpLogoutBackendlessButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (isLoggedInBackendless)
                logoutFromBackendless();
            if (isLoggedInGoogle)
                logoutFromGoogle();
        }
    });
    BackendlessUser user = Backendless.UserService.CurrentUser();
    if (user != null) {
        isLoggedInBackendless = true;
        backendlessUserInfo.setTextColor(getColor(android.R.color.black));
        backendlessUserInfo.setText("Current user: " + user.getEmail());
        loginGooglePlusButton.setVisibility(View.INVISIBLE);
        gpLogoutBackendlessButton.setVisibility(View.VISIBLE);
    }
}
Also used : BackendlessUser(com.backendless.BackendlessUser) OptionalPendingResult(com.google.android.gms.common.api.OptionalPendingResult) View(android.view.View) GoogleSignInResult(com.google.android.gms.auth.api.signin.GoogleSignInResult)

Example 2 with OptionalPendingResult

use of com.google.android.gms.common.api.OptionalPendingResult in project androidApp by InspectorIncognito.

the class GoogleAccountLoader method load.

@Override
public void load(final CredentialsListener listener) {
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().requestIdToken(TranSappApplication.getAppContext().getString(R.string.server_client_id)).build();
    final GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(TranSappApplication.getAppContext()).addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();
    mGoogleApiClient.registerConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {

        @Override
        public void onConnected(@Nullable Bundle bundle) {
            OptionalPendingResult<GoogleSignInResult> pendingResult = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
            if (pendingResult.isDone()) {
                loadDataFromSignInResult(pendingResult.get(), listener, mGoogleApiClient);
            } else {
                pendingResult.setResultCallback(new ResultCallback<GoogleSignInResult>() {

                    @Override
                    public void onResult(@NonNull GoogleSignInResult result) {
                        if (result.isSuccess()) {
                            loadDataFromSignInResult(result, listener, mGoogleApiClient);
                        } else {
                            listener.onError(new ServerStatusCode(LOGIN_API_ERROR));
                        }
                    }
                }, 5000, TimeUnit.MILLISECONDS);
            }
        }

        @Override
        public void onConnectionSuspended(int i) {
            listener.onError(new ServerStatusCode(LOGIN_API_ERROR));
        }
    });
    mGoogleApiClient.connect();
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) ResultCallback(com.google.android.gms.common.api.ResultCallback) Bundle(android.os.Bundle) ServerStatusCode(cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode) OptionalPendingResult(com.google.android.gms.common.api.OptionalPendingResult) GoogleSignInResult(com.google.android.gms.auth.api.signin.GoogleSignInResult) NonNull(android.support.annotation.NonNull) GoogleSignInOptions(com.google.android.gms.auth.api.signin.GoogleSignInOptions)

Aggregations

GoogleSignInResult (com.google.android.gms.auth.api.signin.GoogleSignInResult)2 OptionalPendingResult (com.google.android.gms.common.api.OptionalPendingResult)2 Bundle (android.os.Bundle)1 NonNull (android.support.annotation.NonNull)1 View (android.view.View)1 ServerStatusCode (cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode)1 BackendlessUser (com.backendless.BackendlessUser)1 GoogleSignInOptions (com.google.android.gms.auth.api.signin.GoogleSignInOptions)1 GoogleApiClient (com.google.android.gms.common.api.GoogleApiClient)1 ResultCallback (com.google.android.gms.common.api.ResultCallback)1