Java Code Examples for com.google.android.gms.common.api.OptionalPendingResult#setResultCallback()

The following examples show how to use com.google.android.gms.common.api.OptionalPendingResult#setResultCallback() . 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: 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 7
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);
            }
        });
    }
}