VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
Classes | Public Member Functions | Static Public Attributes | List of all members
com.google.fpl.utils.GooglePlayServicesHelper Class Reference

Helper class responsible for setting up the GoogleApiClient object and managing its lifecycle for activities. More...

Inheritance diagram for com.google.fpl.utils.GooglePlayServicesHelper:

Classes

class  SignInFailureReason
 Represents the reason for a sign-in failure. More...
 
interface  SignInListener
 Listener for sign-in success or failure events. More...
 

Public Member Functions

 GooglePlayServicesHelper (Activity activity, int clientsToUse)
 Constructs a GooglePlayServicesHelper, initially tied to activity. More...
 
void setAutoSignIn (boolean autoSignIn)
 Sets whether or not the configuration should begin connecting automatically to the GoogleApiClient in onStart(). More...
 
int getMaxForcedSignInAttempts ()
 Returns the maximum number of times to automatically force sign-in flow on the user. More...
 
void setMaxForcedSignInAttempts (int max)
 Sets the maximum number of times to automatically force sign-in flow on the user. More...
 
boolean willForceSignInFlow ()
 Returns whether or not the configuration will force sign in flow. More...
 
int getSignInUserCancellations ()
 Returns the number of times the user has canceled the sign-in flow in the life of the application. More...
 
void resetSignInUserCancellations ()
 Resets the counter of how many times the user has canceled the sign-in. More...
 
void setShowErrorDialogs (boolean show)
 Sets whether or not to show error dialogs. More...
 
void setGamesApiOptions (GoogleApiClient.ApiOptions options)
 Sets the options to pass when setting up the Games API client. More...
 
void setAppStateApiOptions (GoogleApiClient.ApiOptions options)
 Sets the options to pass when setting up the AppState API client. More...
 
void setPlusApiOptions (GoogleApiClient.ApiOptions options)
 Sets the options to pass when setting up the Plus API client. More...
 
GoogleApiClient getApiClient ()
 Returns the GoogleApiClient object. More...
 
boolean isSignedIn ()
 Returns whether or not the user (i.e. the GoogleApiClient) is signed in. More...
 
boolean isConnecting ()
 Returns whether or not the GoogleApiClient is currently connecting. More...
 
boolean hasSignInError ()
 Returns whether or not there was a (non-recoverable) error during the sign-in process. More...
 
SignInFailureReason getSignInError ()
 Returns the error that happened during the sign-in process, null if no error occurred. More...
 
boolean hasInvitation ()
 Returns whether or not an invitation was in the connection bundle. More...
 
Invitation getInvitation ()
 Returns the invitation received in the connection bundle, or null if no invitation exists. More...
 
void clearInvitation ()
 Clears the invitation (if any) received in the connection bundle. More...
 
boolean hasTurnBasedMatch ()
 Returns whether or not a turn-based match was received in the connection bundle. More...
 
TurnBasedMatch getTurnBasedMatch ()
 Returns the turn-based match received in the connection bundle, or null if no turn-based match exists. More...
 
void clearTurnBasedMatch ()
 Clears the turn-based match (if any) received in the connection bundle. More...
 
boolean hasRequests ()
 Returns whether or not a list of game requests was received in the connection bundle. More...
 
ArrayList< GameRequest > getRequests ()
 Returns the list of game requests received in the connection bundle, or null if no requests exist. More...
 
void clearRequests ()
 Clears the list of game requests (if any) received in the connection bundle. More...
 
void setup (SignInListener listener)
 Performs setup on this GooglePlayServicesHelper. More...
 
void beginUserInitiatedSignIn ()
 Starts a user-initiated sign-in flow. More...
 
void signOut ()
 Sign out and disconnect from the API clients used in the GoogleApiClient. More...
 
void reconnect ()
 Disconnects the GoogleApiClient client, then connects again. More...
 
void onStart (Activity activity)
 Notifies this GooglePlayServicesHelper of the onStart activity lifecycle event. More...
 
void onStop ()
 Notifies this GooglePlayServicesHelper of the onStop activity lifecycle event. More...
 
void onActivityResult (int requestCode, int responseCode, Intent data)
 Notifies this GooglePlayServicesHelper of the onActivityResult event. More...
 
void onConnected (Bundle connectionHint)
 Called when a connection to the GoogleApiClient is successfully obtained. More...
 
void onConnectionFailed (ConnectionResult result)
 Called when a connection attempt to the GoogleApiClient fails. More...
 
void onConnectionSuspended (int cause)
 Called when a connection attempt to the GoogleApiClient is suspended due to falling into a temporarily disconnected state. More...
 

Static Public Attributes

static final int CLIENT_NONE = 0x00
 No clients. More...
 
static final int CLIENT_GAMES = 0x01
 Google Play Games client. More...
 
static final int CLIENT_PLUS = 0x02
 Google Plus client. More...
 
static final int CLIENT_APPSTATE = 0x04
 Google AppState client. More...
 
static final int CLIENT_ALL = CLIENT_GAMES | CLIENT_PLUS | CLIENT_APPSTATE
 All clients supported by GooglePlayServicesHelper. More...
 

Detailed Description

Helper class responsible for setting up the GoogleApiClient object and managing its lifecycle for activities.

Activities should instantiate the class in their onCreate() method and specify the requested clients (e.g. CLIENT_GAMES | CLIENT_APPSTATE) during setup. Additionally, those activities should implement the SignInListener interface and register themselves as listeners for changes in sign-in status.

Constructor & Destructor Documentation

com.google.fpl.utils.GooglePlayServicesHelper.GooglePlayServicesHelper ( Activity  activity,
int  clientsToUse 
)
inline

Constructs a GooglePlayServicesHelper, initially tied to activity.

Note
After constructing this object, call setup() from the onCreate() method of activity.
Parameters
activityActivity context to be used for the wrapped GoogleApiClient
clientsToUseFlags indicating which clients are requested

Member Function Documentation

void com.google.fpl.utils.GooglePlayServicesHelper.beginUserInitiatedSignIn ( )
inline

Starts a user-initiated sign-in flow.

As a result of calling this method, authentication / consent dialogs may be displayed. At the end of the process, the registered SignInListener's methods will be called to indicate success or failure.

Note
As a side effect of invocation, all previous user cancellations are discarded.
void com.google.fpl.utils.GooglePlayServicesHelper.clearInvitation ( )
inline

Clears the invitation (if any) received in the connection bundle.

Note
This method should be called after handling the invitation.
void com.google.fpl.utils.GooglePlayServicesHelper.clearRequests ( )
inline

Clears the list of game requests (if any) received in the connection bundle.

Note
This method should be called after handling the list of game requests.
void com.google.fpl.utils.GooglePlayServicesHelper.clearTurnBasedMatch ( )
inline

Clears the turn-based match (if any) received in the connection bundle.

Note
This method should be called after handling the turn-based match.
GoogleApiClient com.google.fpl.utils.GooglePlayServicesHelper.getApiClient ( )
inline

Returns the GoogleApiClient object.

Note
This function can only be called after having called setup().
Invitation com.google.fpl.utils.GooglePlayServicesHelper.getInvitation ( )
inline

Returns the invitation received in the connection bundle, or null if no invitation exists.

Note
This is probably best used in the SignInListener::onSignInSucceeded method to handle an available invitation, after which clearInvitation() should be called.
int com.google.fpl.utils.GooglePlayServicesHelper.getMaxForcedSignInAttempts ( )
inline

Returns the maximum number of times to automatically force sign-in flow on the user.

If a sign-in error occurred (e.g. user has not given permissions for sign-in), resolution (e.g. launching sign-in flow) will be forced up until getMaxForcedSignInFlowAttempts() times.

Note
Only explicitly user cancellations (and not other failures) will count against this maximum. Successful sign-ins will reset the recorded number of failed sign-in attempts.
ArrayList<GameRequest> com.google.fpl.utils.GooglePlayServicesHelper.getRequests ( )
inline

Returns the list of game requests received in the connection bundle, or null if no requests exist.

Note
This is probably best used in the SignInListener::onSignInSucceeded method to handle an available list of game requests, after which clearRequests() should be called.
SignInFailureReason com.google.fpl.utils.GooglePlayServicesHelper.getSignInError ( )
inline

Returns the error that happened during the sign-in process, null if no error occurred.

int com.google.fpl.utils.GooglePlayServicesHelper.getSignInUserCancellations ( )
inline

Returns the number of times the user has canceled the sign-in flow in the life of the application.

Note
This count resets after a successful sign-in.
TurnBasedMatch com.google.fpl.utils.GooglePlayServicesHelper.getTurnBasedMatch ( )
inline

Returns the turn-based match received in the connection bundle, or null if no turn-based match exists.

Note
This is probably best used in the SignInListener::onSignInSucceeded method to handle an available turn-based match, after which clearTurnBasedMatch() should be called.
boolean com.google.fpl.utils.GooglePlayServicesHelper.hasInvitation ( )
inline

Returns whether or not an invitation was in the connection bundle.

boolean com.google.fpl.utils.GooglePlayServicesHelper.hasRequests ( )
inline

Returns whether or not a list of game requests was received in the connection bundle.

boolean com.google.fpl.utils.GooglePlayServicesHelper.hasSignInError ( )
inline

Returns whether or not there was a (non-recoverable) error during the sign-in process.

boolean com.google.fpl.utils.GooglePlayServicesHelper.hasTurnBasedMatch ( )
inline

Returns whether or not a turn-based match was received in the connection bundle.

boolean com.google.fpl.utils.GooglePlayServicesHelper.isConnecting ( )
inline

Returns whether or not the GoogleApiClient is currently connecting.

boolean com.google.fpl.utils.GooglePlayServicesHelper.isSignedIn ( )
inline

Returns whether or not the user (i.e. the GoogleApiClient) is signed in.

void com.google.fpl.utils.GooglePlayServicesHelper.onActivityResult ( int  requestCode,
int  responseCode,
Intent  data 
)
inline

Notifies this GooglePlayServicesHelper of the onActivityResult event.

This method should be called from the onActivityResult method in the activity context used to create this GooglePlayServicesHelper. If the activity result pertains to the sign-in process, then it is processesed appropriately, otherwise it is ignored.

Parameters
requestCodeIdentifier supplied when the activity was originally launched that is used to identify if this result pertains to the sign-in process
responseCodeStatus returned by the activity
dataIntent which can be used to return result data to the caller
void com.google.fpl.utils.GooglePlayServicesHelper.onConnected ( Bundle  connectionHint)
inline

Called when a connection to the GoogleApiClient is successfully obtained.

Parameters
connectionHintBundle of data provided to clients by Google Play Games Services, or null if no content is provided by the service
void com.google.fpl.utils.GooglePlayServicesHelper.onConnectionFailed ( ConnectionResult  result)
inline

Called when a connection attempt to the GoogleApiClient fails.

Parameters
resultConnectionResult that can be used for resolving the sign-in error and / or deciding what sort of error occurred
void com.google.fpl.utils.GooglePlayServicesHelper.onConnectionSuspended ( int  cause)
inline

Called when a connection attempt to the GoogleApiClient is suspended due to falling into a temporarily disconnected state.

Parameters
causeCode that identifies the reason for the disconnection
void com.google.fpl.utils.GooglePlayServicesHelper.onStart ( Activity  activity)
inline

Notifies this GooglePlayServicesHelper of the onStart activity lifecycle event.

This method should be called from the onStart method in activity.

Parameters
activityActivity context to be used for the wrapped GoogleApiClient
void com.google.fpl.utils.GooglePlayServicesHelper.onStop ( )
inline

Notifies this GooglePlayServicesHelper of the onStop activity lifecycle event.

This method should be called from the onStop method in the activity context used to create this GooglePlayServicesHelper.

void com.google.fpl.utils.GooglePlayServicesHelper.reconnect ( )
inline

Disconnects the GoogleApiClient client, then connects again.

void com.google.fpl.utils.GooglePlayServicesHelper.resetSignInUserCancellations ( )
inline

Resets the counter of how many times the user has canceled the sign-in.

void com.google.fpl.utils.GooglePlayServicesHelper.setAppStateApiOptions ( GoogleApiClient.ApiOptions  options)
inline

Sets the options to pass when setting up the AppState API client.

Note
This function must be called before setup().
void com.google.fpl.utils.GooglePlayServicesHelper.setAutoSignIn ( boolean  autoSignIn)
inline

Sets whether or not the configuration should begin connecting automatically to the GoogleApiClient in onStart().

Auto sign-in occurs by default, so this method is used to disable auto sign-in.

Note
This method is not recommended for general use, but rather only when using this helper class in a non-standard sign-in flow.
Parameters
autoSignIntrue to automatically connect to GoogleApiClient in onStart()
void com.google.fpl.utils.GooglePlayServicesHelper.setGamesApiOptions ( GoogleApiClient.ApiOptions  options)
inline

Sets the options to pass when setting up the Games API client.

Note
This method must be called before setup().
void com.google.fpl.utils.GooglePlayServicesHelper.setMaxForcedSignInAttempts ( int  max)
inline

Sets the maximum number of times to automatically force sign-in flow on the user.

If set to 0, the user will not be forced through the sign-in flow automatically.

Note
Only explicitly user cancellations (and not other failures) will count against this maximum. Successful sign-ins will reset the recorded number of failed sign-in attempts.
void com.google.fpl.utils.GooglePlayServicesHelper.setPlusApiOptions ( GoogleApiClient.ApiOptions  options)
inline

Sets the options to pass when setting up the Plus API client.

Note
This function must be called before setup().
void com.google.fpl.utils.GooglePlayServicesHelper.setShowErrorDialogs ( boolean  show)
inline

Sets whether or not to show error dialogs.

Parameters
showtrue to show error dialogs
void com.google.fpl.utils.GooglePlayServicesHelper.setup ( SignInListener  listener)
inline

Performs setup on this GooglePlayServicesHelper.

Calling of this method will lead to the creation of the GoogleApiClient.

Note
This method should be called from the onCreate() method of the calling activity to ensure setup before onStart().
Custom setup is possible by extending this method to receive additional apis / scopes (e.g. YouTube and Google Maps) for use in building the GoogleApiClient.
Parameters
listenerSignInListener to be notified of sign-in events
void com.google.fpl.utils.GooglePlayServicesHelper.signOut ( )
inline

Sign out and disconnect from the API clients used in the GoogleApiClient.

boolean com.google.fpl.utils.GooglePlayServicesHelper.willForceSignInFlow ( )
inline

Returns whether or not the configuration will force sign in flow.

This is determined by two factors: having auto sign-in enabled and having not exceeded the maximum number of forced sign-in attempts.

Member Data Documentation

final int com.google.fpl.utils.GooglePlayServicesHelper.CLIENT_ALL = CLIENT_GAMES | CLIENT_PLUS | CLIENT_APPSTATE
static

All clients supported by GooglePlayServicesHelper.

final int com.google.fpl.utils.GooglePlayServicesHelper.CLIENT_APPSTATE = 0x04
static

Google AppState client.

final int com.google.fpl.utils.GooglePlayServicesHelper.CLIENT_GAMES = 0x01
static

Google Play Games client.

final int com.google.fpl.utils.GooglePlayServicesHelper.CLIENT_NONE = 0x00
static

No clients.

final int com.google.fpl.utils.GooglePlayServicesHelper.CLIENT_PLUS = 0x02
static

Google Plus client.