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);
}
}
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();
}
Aggregations