Description#
This section describes usage patterns and guidelines for common integration scenarios enabled using RaveSocial APIs that venture beyond the drop-in experience found in the included scene pack.
The scene pack provides a built in user profile experience, for example, but you may create an app-specific profile experience and this guide explains some common scenarios you may encounter.
Using App Data Keys for Save Game or Cloud Storage ID#
To get a stable index for data lookup, especially if RaveID was used in the past, then RaveAppDataKeys is the recommended API to use. Simply implement the protocol RaveAppDataKeysStateObserver.
public static void appDataKeyStateChanged(String selectedKey, List<String> unresolvedKeys)
By default the selected key returned by this interface will be the current key for the current user. In a typical case, it will be a randomly generated key in a 32 character hex format. If no key had been previously selected for the current application this random key will be the default. The selected key will be non-nil provided that unresolvedKeys is empty, which will usually be the case. When there are unresolved keys, and you are online, then your integration will need to choose between the unresolved keys. Rave will never make a choice between unresolved keys, this is strictly up to the developers discretion.
The integration will choose between unresolved keys when a merge takes place between two users that have already used the current application. At this point either present the user with a choice between the unresolved keys or choose one automatically. With both keys the application can look up information about the two indexes to choose from or present the information to the user. Once a key has been chosen call RaveAppDataKeys.selectKey()
(see selectKey for more information).
User Profile Scenarios#
Code samples for custom user profile scenarios are provided in SampleRaveProfileScene.java included in your distribution package.
Accessing the current user#
RaveSocial.getCurrentUser()
is a shortcut method for accessing the current user.
Provided RaveSettings.General.AutoGuestLogin
is enabled this value should never be null, even after a log out operation. You can access a variety of fields to populate your profile screen including display name, email, and profile picture URL.
Observing the current user#
New in Rave 3.0.2 is an API to register observers for changes to the current user: RaveUsersManager.addCurrentUserObserver(). When a change occurs, usually as the result of an asynchronous operation, all registered observers will be notified with the an array of the changed properties of the current user.
It is recommended that you leverage this feature in your custom profile scene for displayName and pictureURL (or pictureImage) since they may change as a result of an asynchronous operation that you’ve triggered that didn’t explicitly change those user fields.
Observers should implement the RaveCurrentUserObserver interface, which consists of one method: RaveCurrentUserObserver.userChanged(Collection<String>).
@Override
void userChanged(Collection<String> changedKeys) {
if (changedKeys.contains("displayName")) {
// Update UI with new display name
} else if (changedKeys.contains("pictureImage")) {
// Update UI with new profile picture
} else if (changedKeys.contains("pictureURL")) {
// Update picture image
}
}
Displaying the profile picture#
The current user has a reference to the pictureURL, it is always a remotely stored image. It will either be stored on Rave’s servers or on a third party’s server, depending on the source of the image.
Android provides access to the image URL through RaveSocial.getCurrentUser().getPictureURL()
Changing the profile picture#
There is a common method on all platforms that takes a local file url and pushes the binary data for the image to the Rave backend so that the profile picture is available on any device.
String imageURL = someLocalImageURL;
RaveSocial.usersManager.pushProfilePicture(imageURL, new RaveCompletionListener() {
@Override
public void onComplete(RaveException exception) {
if (exception) {
// do something in the error case
}
}
});
Changing the display name#
New in Rave 3.0.2 is an API to modify the current user without staging the changes in the model. RaveUsersManager.pushUserChanges(RaveUserChanges changes, RaveCompletionListener listener).
RaveUserChanges changes = new RaveUserChanges();
changes.displayName = someOtherName;
RaveSocial.usersManager.pushUserChanges(changes, new RaveCompletionListener() {
@Override
public void onComplete(RaveException exception) {
if (exception) {
// do something to handle the exception
}
}
});
Use this new method rather than the legacy method RaveUsersManager.pushCurrent().
Logging out#
If RaveSettings.General.AutoGuestLogin
is enabled a new anonymous user will automatically be created when you log out. Prior to the logOut completion listener firing it is suggested that you prevent the user from interacting with Rave similar to what is shown in the snippet below.
RaveSocial.getProgressDisplay().show("Signing out...", null);
RaveSocial.logOut(new RaveCompletionListener() {
@Override
public void onComplete(RaveException exception) {
RaveSocial.getProgressDisplay().dismiss();
if (exception) {
// do something to handle the exception
}
}
});
Opening common scenes#
Opening the login scene#
Opening the login scene allows the user to sign in using their BigFish account. It also provides the user with a convenient shortcut to the create account scene through a button. The following example code shows an example of showing the scene and also capturing the result of any login or account creation that occurs. In the case that an account is created the result will be successful and the signup data will be valid. For details of the signup data see the appropriate documentation in the BigFishScenePack.
RaveLoginScene loginScene = new RaveLoginScene(context);
loginScene.setListener(new BigFishSignUpDataListener() {
@Override
public void onComplete(RaveCallbackResult result, BigFishSignUpData signUpData, RaveException exception) {
if (result == RESULT_SUCCESSFUL && signUpData != null) {
// do something
} else if (result == RESULT_CANCELED) {
// do something else
} else {
// show error message if deemed appropriate
}
});
loginScene.show();
Opening the create account scene#
Opening the sign up email scene allows the user to create a BigFish account. It also provides the user with a convenient shortcut to the login scene through a button. The following example code shows an example of showing the scene and also capturing the result of any login or account creation that occurs. In the case that an account is created the result will be successful and the signup data will be valid. For details of the signup data see the appropriate documentation in the BigFishScenePack.
RaveSignUpEmailScene signUpScene = new RaveSignUpEmailScene(context);
signUpScene.setListener(new BigFishSignUpDataListener() {
@Override
public void onComplete(RaveCallbackResult result, BigFishSignUpData signUpData, RaveException exception) {
if (result == RESULT_SUCCESSFUL && signUpData != null) {
// do something?
} else if (result == RESULT_CANCELED) {
// do something else?
} else {
// show error message if deemed appropriate
}
}
});
signUpScene.show();
Opening the Find Friends scene#
You’ll want to show the Find Friends scene if you want an easy way to attract users to attaching Facebook, Google, Phonebook contacts, etc. to their Rave account.
RaveFindFriendsScene findFriendsScene = new RaveFindFriendsScene(context);
findFriendsScene.setListener(new RaveSceneListener() {
@Override
public void onSceneComplate(boolean cancelled, RaveException exception) {
// capture when this scene is closed if desired
}
});