Walkthrough: Game

Date:February 19, 2014
Version:1.5.0.0
Description:This tutorial shows how to send a game rawdata, detailing the different required functions with its parameters.

Introduction

Dependencies

This SDK requires the library LoopJ v1.4.3 to be included in the project for proper functioning. You can find it in the following link: LoopJ Library 1.4.3

Android Permissions

The present SDK requires the following Android Permissions in the App manifest:

Singleton Pattern

Infantium_SDK has been created using a Singleton pattern, so the only way to get an instance of the class is by calling the function: getInfantium_SDK(Context context). The SDK requires the Context of the Android Activity.

Example:

Infantium_SDK infantium = Infantium_SDK.getInfantium_SDK(this.getBaseContext());

The Handler

As most functions work asynchronously, an HttpHandler must be implemented. In order to simplify this task Infantium created a class called InfantiumAsyncResponseHandler that provides the methods that must be implemented by the Developers. Its methods are called after making a request to the API, such as creating a new player, getting logged or sending an e-book rawdata.

Here we can see an example of how to implement an InfantiumasyncResponseHandler:

InfantiumAsyncResponseHandler infantiumHandler = new InfantiumAsyncResponseHandler() {
               @Override
               public void onSuccessCloseGameplay(){
                       System.out.println("---Gameplay closed successfully---");
               }

               @Override
               public void onFailureCloseGameplay(String description){
                       System.out.println(description);
               }
};

In this example, if the user creates the Gameplay successfully, the SDK will call the onSuccessCloseGameplay(). If a problem comes up, it will call the onFailureCloseGameplay(String description). The description is a short descriptive message that explains where or why the problem has arised.

Walkthrough

1. Configure the SDK

First of all, we have to configure the SDK with some data. This data will be, on one hand, the developer API credentials for contacting with Infantium (setDeveloperCredentials(String api_user, String api_key)). The other function we should call is the setDeviceInfo(w_dev, h_dev) function in order to set the current device pixels. Finally, if you want to receive feedback from the SDK, you will need to implement a Handler. This will be further explained in the Handler section. You can do that with the setDeveloperHandler(InfantiumAsyncResponseHandler handler) function.

// Configure the SDK
infantium.setDeveloperCredentials(api_user, api_key);
infantium.setDeviceInfo(w_dev, h_dev);
infantium.setDeveloperHandler(handler);

2. Set Game ContentApp UUID

The next step if to set the contentapp_uuid, which will identify the App against the server. To configure it the method setContentAppUUID(String contentapp_uuid) should be used.

// Set the App contentapp_uuid
infantium.setContentAppUUID(contentapp_uuid);

3. Create Gameplay:

When we have set the contentapp_uuid we can create a Gameplay with: createGameplay(String subcontent_uuid). The subcontent_uuid will be provided to you by Infantium, which will be a unique identifier for your activity.

// Send the previously introduced data
infantium.createGameplay(subcontent_uuid);

4. Rawdata Functions:

The GamePlay is created once everytime the kid starts a game session. Now, for every activity played during that time, a RawData object is sent, which will contain the information we need to analyze. This contains, among other generic stats, the elements in the screen, the actions the kid performs, and some info about the results.

When the kid enters one of the activities of the game (i.e. starts playing the game), the RawData is filled in three phases:

  1. Register the elements in the screen.

This is done adding the Elements in the screen (addElement(Element element)) and the Sounds if there are any (addSound(Sound sound)).

An example element and sound could be:

// Add an element for a dog drawing
List<Integer> size = Arrays.asList(10, 10);
List<Integer> pos = Arrays.asList(20, 20);
Element dog_element = new Element(
    "dog_figure",
    size,
    "[0,255,0]",
    "animal",
    "dog",
    pos
);
infantium.addElement(dog_element);

// Add the sound the dog makes when it is tapped
Sound dog_sound = new Sound(
    "barking"
);
infantium.addSound(dog_sound);

Once registered, it is very important to point out the elements to evaluate on the screen (there may be different elements, but only a few important for the activity):

// Add an element for a dog drawing
List<String> evaluate = Arrays.asList("dog_figure");
infantium.setEvaluate(evaluate);
  1. Start the timers and register the actions of the kid.

When the kid starts interacting with the screen, we will call the startPlaying() method. This will trigger the timers inside the SDK. The SDK will automatically handle the timestamps when the kid taps the screen and the elements show up, which will allow us to get a lot of statistics about the child’s development, with no effort at all on the developer side.

For each time the kid taps on the screen, this will be registered with the tapOnObjects(String element_id) method. In this method, it must be pointed out if the interaction represents a success, an error or none of both. Here is an example for the previous dog with its sound:

// Tapping the dog is the goal of the activity, and thus is represented a "success". When the dog is tapped,
//  the "barking" sound is triggered.
infantium.tapOnObjects("dog_figure", "success", "barking");

// Another example, if the kid taps on the "cat_figure" element, but was not the goal of this activity.
infantium.tapOnObjects("cat_figure", "error", "error_sound");
  1. Add some general info about the scores.

When the kid has completed the activity, some conclusions about the activity are registered. This is done with the setSuccesses(int successes) and setFailures(int failures) methods.

// Finally one "success" and one "failure"
infantium.setSuccesses(1);
infantium.setFailures(1);

5. Send Game Rawdata:

We finally call sendGameRawData() when we want to send the RawData. After sending the data, and the kid starts a new activity, the flow would go again to the 4th step! If the kid goes back to the main menu, proceed to step 6.

// Send the previously introduced data
infantium.sendGameRawData();

6. Close Gameplay

Last step but not least important: closeGameplay(). If the GamePlay is not closed, the SDK will not be able to create new ones.

7. Conclusions

And with this