com.google.android.gms.common.api.OptionalPendingResult Java Examples

The following examples show how to use com.google.android.gms.common.api.OptionalPendingResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DriverHome.java    From UberClone with MIT License 6 votes vote down vote up
private void verifyGoogleAccount() {
    GoogleSignInOptions gso=new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().build();
    mGoogleApiClient=new GoogleApiClient.Builder(this)
            .enableAutoManage(this, this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();
    OptionalPendingResult<GoogleSignInResult> opr=Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
    if (opr.isDone()){
        GoogleSignInResult result= opr.get();
        handleSignInResult(result);
    }else {
        opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
            @Override
            public void onResult(@NonNull GoogleSignInResult googleSignInResult) {
                handleSignInResult(googleSignInResult);
            }
        });
    }
}
 
Example #2
Source File: DriverTracking.java    From UberClone with MIT License 6 votes vote down vote up
private void verifyGoogleAccount() {
    GoogleSignInOptions gso=new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().build();
    mGoogleApiClient=new GoogleApiClient.Builder(this)
            .enableAutoManage(this, this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();
    OptionalPendingResult<GoogleSignInResult> opr=Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
    if (opr.isDone()){
        GoogleSignInResult result= opr.get();
        handleSignInResult(result);
    }else {
        opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
            @Override
            public void onResult(@NonNull GoogleSignInResult googleSignInResult) {
                handleSignInResult(googleSignInResult);
            }
        });
    }
}
 
Example #3
Source File: Home.java    From UberClone with MIT License 6 votes vote down vote up
private void verifyGoogleAccount() {
    GoogleSignInOptions gso=new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().build();
    mGoogleApiClient=new GoogleApiClient.Builder(this)
            .enableAutoManage(this, this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();
    OptionalPendingResult<GoogleSignInResult> opr=Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
    if (opr.isDone()){
        GoogleSignInResult result= opr.get();
        handleSignInResult(result);
    }else {
        opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
            @Override
            public void onResult(@NonNull GoogleSignInResult googleSignInResult) {
                handleSignInResult(googleSignInResult);
            }
        });
    }
}
 
Example #4
Source File: UpdateFragment.java    From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void handleSilentSignIn(){

        OptionalPendingResult<GoogleSignInResult> pendingResult = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);

        if (pendingResult.isDone()) {
            // If the user's cached credentials are valid, the OptionalPendingResult will be "done"
            // and the GoogleSignInResult will be available instantly.
            Log.d(Utils.TAG, "Got cached sign-in");
            GoogleSignInResult result = pendingResult.get();
            handleSignInResult(result);
        } else {
            pendingResult.setResultCallback(new ResultCallback<GoogleSignInResult>() {
                @Override
                public void onResult(@NonNull GoogleSignInResult googleSignInResult) {
                    handleSignInResult(googleSignInResult);
                }
            });
        }
    }
 
Example #5
Source File: MainActivity.java    From friendspell with Apache License 2.0 6 votes vote down vote up
@Override
public void onConnected(Bundle connectionHint) {
  Timber.d("onConnected");
  if (shouldAutoLogin) {
    OptionalPendingResult<GoogleSignInResult> pendingResult =
            googleApiClientBridge.silentSignIn(googleApiClientToken);
    if (pendingResult.isDone()) {
      // There's immediate result available.
      handleSignInResult(pendingResult.get());
    } else {
      // There's no immediate result ready
      pendingResult.setResultCallback(new ResultCallback<GoogleSignInResult>() {
        @Override
        public void onResult(@NonNull GoogleSignInResult result) {
          handleSignInResult(result);
        }
      });
    }
  }
}
 
Example #6
Source File: Login.java    From UberClone with MIT License 5 votes vote down vote up
private void verifyGoogleAccount() {
    OptionalPendingResult<GoogleSignInResult> opr= Auth.GoogleSignInApi.silentSignIn(googleApiClient);
    if (opr.isDone()){
        GoogleSignInResult result= opr.get();
        if (result.isSuccess())
            firebaseHelper.loginSuccess();

    }
}
 
Example #7
Source File: Login.java    From UberClone with MIT License 5 votes vote down vote up
private void verifyGoogleAccount() {
    OptionalPendingResult<GoogleSignInResult> opr= Auth.GoogleSignInApi.silentSignIn(googleApiClient);
    if (opr.isDone()){
        GoogleSignInResult result= opr.get();
        if (result.isSuccess()) firebaseHelper.loginSuccess();
    }
}
 
Example #8
Source File: GooglePlusNetwork.java    From EasyLogin with MIT License 5 votes vote down vote up
public void silentSignIn() {
    OptionalPendingResult<GoogleSignInResult> pendingResult =
            Auth.GoogleSignInApi.silentSignIn(googleApiClient);
    if (pendingResult.isDone()) {
        // There's immediate result available.
        parseGoogleSignInResult(pendingResult.get());
    } else {
        pendingResult.setResultCallback(new ResultCallback<GoogleSignInResult>() {
            @Override
            public void onResult(@NonNull GoogleSignInResult result) {
                parseGoogleSignInResult(result);
            }
        });
    }
}
 
Example #9
Source File: RxGoogleAuthFragment.java    From RxSocialAuth with Apache License 2.0 5 votes vote down vote up
private void silentSignIn() {
    OptionalPendingResult<GoogleSignInResult> pendingResult =
            Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);

    if (pendingResult.isDone()) {
        handleSignInResult(pendingResult.get());
    } else {
        pendingResult.setResultCallback(new ResultCallback<GoogleSignInResult>() {
            @Override
            public void onResult(@NonNull GoogleSignInResult googleSignInResult) {
                handleSignInResult(googleSignInResult);
            }
        });
    }
}
 
Example #10
Source File: MainActivityTest.java    From friendspell with Apache License 2.0 5 votes vote down vote up
protected static void setupGoogleApiClientBridge(
    GoogleApiClientBridge googleApiClientBridge, final boolean initialStatus) {
  final String token = "token";
  final ArgumentCaptor<GoogleApiClient.ConnectionCallbacks> connectedArgument
      = ArgumentCaptor.forClass(GoogleApiClient.ConnectionCallbacks.class);
  final ArgumentCaptor<GoogleApiClient.OnConnectionFailedListener> failedArgument
      = ArgumentCaptor.forClass(GoogleApiClient.OnConnectionFailedListener.class);
  Mockito.when(googleApiClientBridge.init(Mockito.any(Activity.class),
      connectedArgument.capture(), failedArgument.capture())).thenReturn(token);
  Mockito.doAnswer(new Answer() {
    @Override public Object answer(InvocationOnMock invocation) throws Throwable {
        connectedArgument.getValue().onConnected(null);
        return null;
    }
  }).when(googleApiClientBridge).connect(Mockito.anyString());

  GoogleSignInAccount account = Mockito.mock(GoogleSignInAccount.class);
  Mockito.when(googleApiClientBridge.getCurrentAccount()).thenReturn(account);

  @SuppressWarnings("unchecked") OptionalPendingResult<GoogleSignInResult> mockPendingResult =
          Mockito.mock(OptionalPendingResult.class);
  GoogleSignInResult mockInitialSignInResult = Mockito.mock(GoogleSignInResult.class);
  Mockito.when(mockInitialSignInResult.isSuccess()).thenReturn(initialStatus);
  Mockito.when(mockInitialSignInResult.getSignInAccount()).thenReturn(account);
  GoogleSignInResult mockSuccessfulSignInResult = Mockito.mock(GoogleSignInResult.class);
  Mockito.when(mockSuccessfulSignInResult.isSuccess()).thenReturn(true);
  Mockito.when(mockSuccessfulSignInResult.getSignInAccount()).thenReturn(account);
  Mockito.when(mockPendingResult.isDone()).thenReturn(true);
  Mockito.when(mockPendingResult.get()).thenReturn(mockInitialSignInResult);
  Mockito.when(googleApiClientBridge.silentSignIn(Mockito.anyString()))
      .thenReturn(mockPendingResult);
  Mockito.when(googleApiClientBridge.isConnected(Mockito.anyString())).thenReturn(true);
  Mockito.when(googleApiClientBridge.isSignedIn()).thenReturn(initialStatus);
  Mockito.when(googleApiClientBridge
      .getSignInResultFromIntent(ArgumentMatchers.isNull(Intent.class)))
      .thenReturn(mockSuccessfulSignInResult);
  Mockito.when(googleApiClientBridge.getSignInIntent(Mockito.anyString()))
      .thenReturn(new Intent("com.google.android.gms.auth.GOOGLE_SIGN_IN"));
}
 
Example #11
Source File: SignIn.java    From easygoogle with Apache License 2.0 5 votes vote down vote up
/**
 * Get the currently signed in user as a GoogleSignInAccount.
 * @return a {@link GoogleSignInAccount} or null.
 */
public GoogleSignInAccount getCurrentUser() {
    OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(
            getFragment().getGoogleApiClient());
    if (opr.isDone()) {
        return opr.get().getSignInAccount();
    } else {
        return null;
    }
}
 
Example #12
Source File: LoginFragment.java    From androidpay-quickstart with Apache License 2.0 5 votes vote down vote up
private void silentSignIn() {
    OptionalPendingResult<GoogleSignInResult> opr =
            Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);

    if (opr.isDone()) {
        handleSignInResult(opr.get());
    }
}
 
Example #13
Source File: LoginWithGooglePlusSDKActivity.java    From Android-SDK with MIT License 5 votes vote down vote up
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);
	}
}
 
Example #14
Source File: GoogleApiClientBridge.java    From friendspell with Apache License 2.0 4 votes vote down vote up
public OptionalPendingResult<GoogleSignInResult> silentSignIn(String token) {
  GoogleApiClient googleApiClient = clients.get(token);
  return Auth.GoogleSignInApi.silentSignIn(googleApiClient);
}