GamesChart Android API Implementation - Hand Rolled

Implement the GamesChart API using the IDE method by following 3 simple steps: {|

Step 1 - Including the jar file
The entire Games Chart API is contained in 1 small jar file. This needs to be included in your application. You can download the latest API jar file here. [insert hyperlink]



Step 2 - AndroidManifest.xml
Locate your AndroidManifest.xml file Find the following line, and make sure you set the android target sdk version to 8.  Next add the required permissions. Below is the complete list of permissions that the GamesChart API requires, so add as many as you need.      Finally, add the following line after your activity block:  A complete AndroidManifext.xml should look something like this, once the GamesChart entries have been added:      </uses-permission> </uses-permission> </uses-permission> <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true"> <activity android:name=".Vortex" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <activity android:name="com.gcapi.GamesChart">

Step 3 - Code Setup
NOTE: Games Chart is implemented as a Linear Layout, so you'll need to identify your app's main Frame Layout in your resource file. Example : FrameLayout mainFrameLayout = (FrameLayout)findViewById(R.id.mainframe); We now have a handle to our main frame, so lets add the main Games Chart code block Once in here we can begin the set-up procedure. You should have something like this: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Add the following code block. /////////////////////////////////////////////////////////////////////////////////////////////////////// // STEP 1: INITIALISE GAMES CHART SYSTEM /////////////////////////////////////////////////////////////////////////////////////////////////////// String gameID = "bc055fe4f21c9617e6463b7c0ecc7101"; // given when you register your game GamesChart.setup(this.getBaseContext, gameID);

/////////////////////////////////////////////////////////////////////////////////////////////////////// // STEP 2: SET UP THE GAMES CHART LAYOUT /////////////////////////////////////////////////////////////////////////////////////////////////////// LinearLayout gc = GamesChart.getLayout(this); // get the GamesChart layout /////////////////////////////////////////////////////////////////////////////////////////////////////// // STEP 3: ADD A LISTENER TO HANDLE EVENTS /////////////////////////////////////////////////////////////////////////////////////////////////////// gc.setOnTouchListener(new OnTouchListener {    // we do this here to enable us to launch an activity from our app    @Override    public boolean onTouch(View v, MotionEvent event) {        switch(event.getAction)        {	            case MotionEvent.ACTION_MOVE:                GamesChart.touchMove(event.getX, event.getY);                break;            case MotionEvent.ACTION_UP:                if (GamesChart.touchRelease(event.getX,event.getY))                    startActivity(GamesChart.getIntent(true));                break;            case MotionEvent.ACTION_DOWN:                GamesChart.touchDown(event.getX, event.getY);                break;        }        return true;    } });

/////////////////////////////////////////////////////////////////////////////////////////////////////// // STEP 4: ADD THE GAMES CHART LAYOUT LAYER /////////////////////////////////////////////////////////////////////////////////////////////////////// mainFrameLayout.addView(gc);

Ok, nearly done. We just need to let the GamesChart system know that we're ready to go, so we need to add the following

/////////////////////////////////////////////////////////////////////////////////////////////////////// // STEP 5: TELL GAMES CHART THAT OUT GAME IS READY /////////////////////////////////////////////////////////////////////////////////////////////////////// GamesChart.gameStarted(true); // start in a new thread //GamesChart.gameStarted(false); // don't start a new thread NOTE: Be careful where you do this. We recommend waiting until your game has loaded and is displaying something before telling the GamesChart system to start loading up it's assets. If you add it directly after STEP 4, you may experience some lag whilst loading your game. Ok, that's all the code we need.

Additional Games Chart Functionality
If you’re happy with the way GamesChart looks and is working, great, you don’t need to do anything else. However, if you want to change the way GamesChart works for you, we’ve created some functions for you to use. These functions may be called at any point you like during your game flow. Open / Close Charts If you would like to control when the Charts are displayed in your game; at “Level Complete” or “Game Over” for example, you can simply use the open and close methods. GamesChart.openCharts; // forces the charts to be displayed

GamesChart.closeCharts; // forces the charts to be closed again