Advertisement
Nathisgreen

MainActivity

Jun 7th, 2013
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.33 KB | None | 0 0
  1. package com.me.gdxGooglePlay;
  2.  
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5.  
  6. import com.badlogic.gdx.backends.android.AndroidApplication;
  7. import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
  8. import com.google.android.gms.games.leaderboard.LeaderboardBuffer;
  9. import com.google.android.gms.games.leaderboard.LeaderboardScoreBuffer;
  10. import com.google.android.gms.games.leaderboard.OnLeaderboardScoresLoadedListener;
  11. import com.google.example.games.basegameutils.GameHelper;
  12. import com.google.example.games.basegameutils.GameHelper.GameHelperListener;
  13.  
  14. public class MainActivity extends AndroidApplication implements GameHelperListener, GoogleInterface {
  15.    
  16.     private GameHelper aHelper;
  17.    
  18.     private OnLeaderboardScoresLoadedListener theLeaderboardListener;
  19.    
  20.     public MainActivity(){
  21.         aHelper = new GameHelper(this);
  22.         aHelper.enableDebugLog(true, "MYTAG");
  23.        
  24.         //create a listener for getting raw data back from leaderboard
  25.         theLeaderboardListener = new OnLeaderboardScoresLoadedListener() {
  26.            
  27.             public void onLeaderboardScoresLoaded(int arg0, LeaderboardBuffer arg1,
  28.                     LeaderboardScoreBuffer arg2) {
  29.                    
  30.                 System.out.println("In call back");
  31.                
  32.                 for(int i = 0; i < arg2.getCount(); i++){
  33.                     System.out.println(arg2.get(i).getScoreHolderDisplayName() + " : " + arg2.get(i).getDisplayScore());
  34.                 }
  35.             }
  36.         };
  37.     }
  38.    
  39.     @Override
  40.     public void onCreate(Bundle savedInstanceState) {
  41.         super.onCreate(savedInstanceState);
  42.        
  43.         AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
  44.         cfg.useGL20 = false;
  45.         aHelper.setup(this);
  46.         initialize(new Game(this), cfg);
  47.     }
  48.    
  49.     @Override
  50.     public void onStart(){
  51.         super.onStart();
  52.         aHelper.onStart(this);
  53.     }
  54.    
  55.     @Override
  56.     public void onStop(){
  57.         super.onStop();
  58.         aHelper.onStop();
  59.     }
  60.    
  61.     @Override
  62.     public void onActivityResult(int request, int response, Intent data) {
  63.         super.onActivityResult(request, response, data);
  64.         aHelper.onActivityResult(request, response, data);
  65.     }
  66.  
  67.     public void onSignInFailed() {
  68.         System.out.println("sign in failed");
  69.     }
  70.  
  71.     public void onSignInSucceeded() {
  72.         System.out.println("sign in succeeded");
  73.     }
  74.  
  75.     public void Login() {
  76.         try {
  77.         runOnUiThread(new Runnable(){
  78.            
  79.             //@Override
  80.             public void run(){
  81.                 aHelper.beginUserInitiatedSignIn();
  82.             }
  83.             });
  84.         }catch (final Exception ex){
  85.            
  86.         }
  87.     }
  88.  
  89.     public void LogOut() {
  90.         try {
  91.         runOnUiThread(new Runnable(){
  92.            
  93.             //@Override
  94.             public void run(){
  95.                 aHelper.signOut();
  96.             }
  97.             });
  98.         }catch (final Exception ex){
  99.            
  100.         }
  101.        
  102.     }
  103.  
  104.     public boolean getSignedIn() {
  105.         return aHelper.isSignedIn();
  106.     }
  107.  
  108.     public void submitScore(int _score) {
  109.         System.out.println("in submit score");
  110.         aHelper.getGamesClient().submitScore(getString(R.string.leaderBoardID), _score);   
  111.     }
  112.  
  113.     public void getScores() {
  114.         startActivityForResult(aHelper.getGamesClient().getLeaderboardIntent(getString(R.string.leaderBoardID)), 105); 
  115.     }
  116.  
  117.     public void getScoresData() {
  118.         aHelper.getGamesClient().loadPlayerCenteredScores(theLeaderboardListener,
  119.                 getString(R.string.leaderBoardID),
  120.                 1,
  121.                 1,
  122.                 25) ;
  123.     }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement