Android GamesChart API Implementation - IDE

Android – API implementation Before you begin the process of implementing the GamesChart system in your game, you will need a unique game ID. This will be provided once you have registered as a developer and added your game. If you have not already done this, go here to get started If you already have your unique gameID, you’re ready to go ! If you make Android games using Eclipse (recommended) then follow this link for API implementation instructions: GamesChart Android API Implementation – Eclipse [hyperlink] If you make Android games using build.xml and build.properties files then follow this link for API implementation instructions: GamesChart Android API Implementation – build.xml and build.properties [hyperlink] [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 from the developer site. There are a couple of standard ways to include external jar files. These are not GamesChart specific operations, so whichever method you’re most comfortable with is just fine. Your Project > right click > Import > File System > (Browse to) GamesChartAPI.jar Your Project > right click > Properties > Java Build Path > Libraries > Add Jar >(Browse to) GamesChartAPI.jar CHECKPOINT – Before you go any further, make sure you have done this first correctly. Rebuild your game and check that the GamesChartAPI.jar file has been included in your .apk file* [Step 2 – Adding to the AndroidManifest.xml] In order for your GamesChart enabled app to pass information back and forth, we need to make sure it has the permission to carry out the operations needed. Luckily, this isn’t a difficult task. Simply add the following permissions* Note: You may already have some these permissions set. If you have, simply add the ones that you don’t have. code type="java" android.permission.INTERNET android.permission.WRITE_SETTINGS android.permission.ACCESS_COURSE_LOCATION android.permission.ACCESS_FINE_LOCATION /code The easiest way is to simply edit your AndroidManifest.xml manually. Just locate your AndroidManifest.xml file (it’ll be in the root of your project) and double click to open it. If it’s not already selected, select the “AndroidManifest.xml” tab at the bottom of the current window. This will display the content of the actual file. Now just add the following lines just before the block.     Finally, while we’re in here, we need to add one final line to enable your application to access the GamesChart code inside the jar file. Just before your closing application tag, add the following line:  That’s that part over with. [Step 3 - Adding the code] So far so good, GamesChart is now included in your game bundle, so we just need a few lines to hook it all up ! For this section GamesChart specific code will be shown in blue, existing code in grey, comments in green and method definitions in purple. 1) Setup Your application will have a main View type, most likely SurfaceView.. this is where you will initialise the Games Chart system and check for any relevant events. The setup method simply needs a reference to the view’s context and a String containing your unique gameID. public static void setup(Context context, String gameID) In this class, wherever you initialise your game, add the following line of code* // GAMESCHART CODE START: SETUP: setup GamesChart.setup(this.getContext, gameID); // GAMESCHART CODE END: SETUP: setup This will set up the Games Chart system for use. // GAMESCHART CODE START: SETUP: setup GamesChart.setup(this.getBaseContext,gameID); // GAMESCHART CODE END: SETUP: setup If your class already has a context explicitly defined, you can pass that instead, like this // GAMESCHART CODE START: SETUP: setup GamesChart.setup(mContext,gameID); // GAMESCHART CODE END: SETUP: setup 2) Draw The actual rendering of the Games Chart system is no different from your in-game graphics system. It uses a Canvas to draw itself on top of your game, so we need a reference to your game's canvas. The draw method just needs a Canvas to draw to public static void draw(Canvas canvas) Find your game's main draw method and add the following code at the end of your drawing code. // GAMESCHART CODE START: DRAW: draw  GamesChart.draw(canvas); // GAMESCHART CODE END: DRAW: draw This will show the GamesChart show/hide tab in the default position, which is the top right hand side of the screen. If you wish to change this position, simply add x and y parameters. // GAMESCHART CODE START: DRAW: draw GamesChart.draw(canvas, x, y); // GAMESCHART CODE END: DRAW: draw  This will show the GamesChart show/hide tab at the x and y position you pass
 * link**
 * Not sure how to check this? Read more here (link to appropriate site / text anchor)
 * Need more help with this step? Read more here (link to appropriate site / text anchor)
 * Alternatives: If you have trouble with getContext, try using getBaseContext in it’s place, so your code will look lke this

3) Check for Events Search your code for "onTouchEvent"*  You should have something like this:*  if (event.getAction == MotionEvent.ACTION_DOWN) {  You just need to add one small block here:  // GAMESCHART CODE START: CHECK EVENTS: onTouchEvent if (GamesChart.checkClick((int)event.getX, (int)event.getY)) {    this.getContext.startActivity(GamesChart.getIntent(true)); } // GAMESCHART CODE END: CHECK EVENTS: onTouchEvent

This checks with the GameChart API to see if the tab has been clicked. If it has, it will check to see which part of the chart has been clicked, then carry out any required actions. That’s it !! You’re done. Easy wasn’t it? code @Override public boolean onTouchEvent(MotionEvent event) {
 * Don’t have an onTouchEvent method? You do, but you don’t have MotionEvent.ACTION_DOWN events defined? No problem. The whole onTouchEvent section is listed below, so you can see clearly which parts you need to add.

if (event.getAction == MotionEvent.ACTION_DOWN) {

// START GAMES CHART EVENT: onTouchEvent if (GamesChart.checkClick((int)event.getX, (int)event.getY)) { this.getContext.startActivity(GamesChart.getIntent(true)); }         // END GAMES CHART EVENT: onTouchEvent }  return true; } /code

TIP: You may want to make sure that you call your game’s pause method just before you call startActivity.

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’d like to control when GamesChart is 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