orbotix.achievement
Class AchievementManager

java.lang.Object
  extended by orbotix.achievement.AchievementManager

public class AchievementManager
extends java.lang.Object

Achievement manager class for interacting with SpheroWorld and using SpheroWorld achievements Use this class to connect your application to SpheroWorld so that ball stats are tracked and shown on your users' SpheroWorld profiles. Do not create an instance of this class, use the static methods instead.

Basic SpheroWorld Integration

To integrate your app with SpheroWorld you need to set your app's identifier and secret string that were assigned by SpheroWorld when you created the application on the website. Add this code the onStart() method of your main activity before you make calls to any other RobotLibrary methods. Basic SpheroWorld integration is required for all apps that control Sphero.
      protected void onStart() {
              super.onStart();
              AchievementManager.setupApplication("APP_ID_GOES_HERE", "APP_SECRET_GOES_HERE", this);
          }
      
  
You need to let the achievement manager know when your application enters the background by calling the onPause() method. Do this by overriding the onPause() method of your main activity.
      protected void onStop() {
   	        super.onStop();
              AchievementManager.onStop();
          }
      
  

SpheroWorld Achievement Integration

In order to allow the user to track their achievements in your application you will need to allow the user to login to SpheroWorld and authorize your app. You can do this using the SpheroWorldWebView activity in the RobotUILibrary. SpheroWorld achievement meta data and progress will be automatically loaded from SpheroWorld once you have set your app id and secret. You can setup achievements on the SpheroWorld website. In order to track achievements in your app you will need to call the recordEvent method to record instances of the event associated with achievements. Listen for the AchievementEarnedIntent to be notified when an achievement is earned by the user. The achievement will be passed as a JSON string extra. You can show a list of the achievements in your application and the progress of a user by displaying the SpheroWorldWebView activity in the RobotUILibrary after the user has logged in.


Field Summary
static java.lang.String AchievementEarnedIntent
          Broadcast intent sent when an achievement is earned
 
Constructor Summary
AchievementManager()
           
 
Method Summary
static int getAccumulatedDistanceSinceLastQuery()
          Get the total distance accumulated since the last time this method was called.
static java.lang.String getAppID()
          Get the app id for the current app
static int getColorChangesSinceLastQuery()
          Get the total number of color changes accumulated since the last time this method was called.
static void onStop()
          Should be called in the onStop method of your main activity so AchievementManager can close the database and cleanup properly.
static void recordEvent(java.lang.String eventName)
          Call to log events related to earning achievements.
static void recordEvent(java.lang.String eventName, int count)
          Call to log events related to earning achievements.
static void setupApplication(java.lang.String appId, java.lang.String appSecret, android.content.Context context)
          The main call to setup and authorize your application with SpheroWorld
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AchievementEarnedIntent

public static final java.lang.String AchievementEarnedIntent
Broadcast intent sent when an achievement is earned

See Also:
Constant Field Values
Constructor Detail

AchievementManager

public AchievementManager()
Method Detail

getAppID

public static java.lang.String getAppID()
Get the app id for the current app

Returns:
the app id for the current app

setupApplication

public static void setupApplication(java.lang.String appId,
                                    java.lang.String appSecret,
                                    android.content.Context context)
The main call to setup and authorize your application with SpheroWorld

Parameters:
appId - assigned to your app on SpheroWorld
appSecret - assigned to your app on SpheroWorld
context - the context of your main activity (used for sending broadcast intents)

onStop

public static void onStop()
Should be called in the onStop method of your main activity so AchievementManager can close the database and cleanup properly.


recordEvent

public static void recordEvent(java.lang.String eventName)
Call to log events related to earning achievements. This call sets count to 1 when recording the event.

Parameters:
eventName - The event name string associated with the achievement in SpheroWorld

recordEvent

public static void recordEvent(java.lang.String eventName,
                               int count)
Call to log events related to earning achievements. This call lets you specify a count.

Parameters:
eventName - The event name string associated with the achievement in SpheroWorld
count - The number of times the event happened

getAccumulatedDistanceSinceLastQuery

public static int getAccumulatedDistanceSinceLastQuery()
Get the total distance accumulated since the last time this method was called. The first time this is called it will return the amount of distance accumulated since the AchievementManager was set up.

Returns:
the total number of cm traveled since the previous call to this method.

getColorChangesSinceLastQuery

public static int getColorChangesSinceLastQuery()
Get the total number of color changes accumulated since the last time this method was called. The first time this is called it will return the number of color changes since the AchievementManager was set up.

Returns:
the total number of discrete color changes since the previous call to this method.