Example #1
0
  /**
   * Starts a user-initiated sign-in flow. This should be called when the user clicks on a "Sign In"
   * button. As a result, authentication/consent dialogs may show up. At the end of the process, the
   * GameHelperListener's onSignInSucceeded() or onSignInFailed() methods will be called.
   */
  public void beginUserInitiatedSignIn() {
    debugLog("beginUserInitiatedSignIn: resetting attempt count.");
    resetSignInCancellations();
    mSignInCancelled = false;
    mConnectOnStart = true;

    if (mGoogleApiClient.isConnected()) {
      // nothing to do
      logWarn(
          "beginUserInitiatedSignIn() called when already connected. "
              + "Calling listener directly to notify of success.");
      notifyListener(true);
      return;
    } else if (mConnecting) {
      logWarn(
          "beginUserInitiatedSignIn() called when already connecting. "
              + "Be patient! You can only call this method after you get an "
              + "onSignInSucceeded() or onSignInFailed() callback. Suggestion: disable "
              + "the sign-in button on startup and also when it's clicked, and re-enable "
              + "when you get the callback.");
      // ignore call (listener will get a callback when the connection
      // process finishes)
      return;
    }

    debugLog("Starting USER-INITIATED sign-in flow.");

    // indicate that user is actively trying to sign in (so we know to
    // resolve
    // connection problems by showing dialogs)
    mUserInitiatedSignIn = true;

    if (mConnectionResult != null) {
      // We have a pending connection result from a previous failure, so
      // start with that.
      debugLog("beginUserInitiatedSignIn: continuing pending sign-in flow.");
      mConnecting = true;
      resolveConnectionResult();
    } else {
      // We don't have a pending connection result, so start anew.
      debugLog("beginUserInitiatedSignIn: starting new sign-in flow.");
      mConnecting = true;
      connect();
    }
  }