English subtitles

← Click Handlers

Get Embed Code
4 Languages

Showing Revision 3 created 05/25/2016 by Udacity Robot.

  1. Here, you can see my on click function.
  2. I'm only going to process button clicks
    while the Google API client isn't in
  3. the midst of connecting.
  4. So this is just going to
    be a big switch statement.
  5. Because the on click
    will take in a view v.
  6. And v's ID will be the ID of
    the button that was pressed.
  7. So, in this case, when the v.getId
    gives me R.id.sign in button,
  8. the sign in button has been pressed.
  9. We just said we want to set
    the status to signing in,
  10. and then call this result
    sign-in error function.
  11. We'll write that function shortly,
  12. and then just break out
    of the switch statement.
  13. And then when we're signing out, we can
    clear the default accounts, just so
  14. that the Google services don't
    return an unconnected callback,
  15. without any interaction.
  16. And the result, so once you've
    signed out, it's good to clear
  17. any of the default information out, so
    that you don't have any security issues.
  18. So just going to call
    Plus.AccountApi.clearDefaultAccount and
  19. pass it the API client.
  20. We then disconnect the API client and
    reconnect it.
  21. And then break out of
    the switch statement.
  22. Finally, for
    revoking access on the plus account API,
  23. we call the default account for
    the same reason.
  24. And then also in the Plus.AccountApi,
    we call revokeAccessAndDisconnect and
  25. pass it the GoogleApiClient.
  26. Once we've done that, we'll start the
    process of building a new client ,and
  27. getting it ready to connect.
  28. So again, we just say mGoogleApiClient,
  29. and we call the same helper
    function that we had earlier.
  30. And then we reconnect that.
  31. So that's all we have to
    do in our three run-ins.
  32. So signing in is setting the text and
    resolving the errors.
  33. Signing out is clearing the default
    account, disconnecting and reconnecting.
  34. And revoking access to
    clearing the default account.
  35. Revoking access and disconnecting.
  36. And building a new API client and
    connecting that.