Walkthrough: E-Book

Date:February 19, 2014
Revision:1.5.0.0
Description:This tutorial show how to send an e-book 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. The other function we should call is the setDeviceInfo() function in order to set the current device pixels

2. Set e-book ContentApp UUID

We have to set the ContentApp UUID of the e-book before creating a gameplay.

Possible responses:

  • onSuccessContentApp(): the contentapp UUID is found in the Infantium market.
  • onFailureContentApp(String description): a problem occurred when trying to obtain the contentapp info from the market.

3. Set e-book Content UUID

This function will set the ebook content UUID, required before creating a new Gameplay.

If the content is not correct, the error will appear when calling the sendEbookRawdata.

4. Get Player UUID (from the Infantium App):

This function will get the UUID of the selected player in the InfantiumApp to be used by the SDK. This requires to add a few lines in the Android Manifest of the App adapting to Infantium. The following receiver should be added to the Manifest:

<receiver android:name="com.infantium.android.sdk.ReceivePlayer">
    <intent-filter>
        <action android:name="com.infantium.android.sdk.ReceivePlayer"></action>
    </intent-filter>
</receiver>

This receiver should be added inside of the <application> tag of your Manifest. Once this is added, the call to get the Player (and this is the step 3) is:

Possible responses:

  • onSuccessGetPlayerByUUID(): Player was successfully obtained, you can now proceed to the next step.
  • onFailureGetPlayerByUUID(String description): A problem occurred while obtaining the player, check the description for more details.

5. Create Gameplay:

When we have set the contentapp_uuid, content_uuid and the player_uuid we can create a gameplay.

Function:

createGameplay()

Note

the createGameplay(String subcontent_uuid, handler) is only used to create gameplays of games.

Possible responses:

  • onSuccessCreateGameplay(): The gameplay is created successfully.
  • onFailureCreateGameplay(String description): If the player is not selected, the content is not informed or there is another gameplay opened

6. Rawdata Functions:

Once the gameplay is created, we can call the rawdata functions to introduce elements or sounds. Additionally, when the ebook page is shown (the kid can see the objects in the screen), the function startPlaying() should be called. If any new elements, sounds or animations are displayed they can be added afterwards.

  • Required rawdata functions:
  • Optional rawdata functions:

7. Send Ebook Rawdata:

We finally call this function when we want to send the rawdata.

  • numPage: The number of the page in the e-book.
  • text - true if the page contains text or false if not.
  • readToMe - true if the book reads to the player or false if not.

Possible responses:

  • onSuccessEbookRawdata(): The ebook rawdata is posted successfully.
  • onFailureEbookRawdata(String description): A problem occurred when sending the ebook rawdata.

8. Close Gameplay

Last step but not least important. If the gameplay is not closed, the SDK will not be able to create new Gameplays.

Possible responses:

  • onSuccessCloseGameplay(): Gameplay closed succesfully.
  • onFailureCloseGameplay(String description): If the gameplay is not started or another problem occurs when closing the gameplay.