Android Open Source - noughts-and-crosses-android Loading Gloabal High Scores Activity






From Project

Back to project page noughts-and-crosses-android.

License

The source code is released under:

MIT License

If you think the Android project noughts-and-crosses-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.JamesWhite.NoughtsAndCrosses;
/* w w w.j  a  v  a2 s.  com*/
/**
 * LoadingGlobalHighScoresActivity Handles loading the global high scores JSON async
 * 
 * @author James White
 */

import org.json.JSONArray;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;

public class LoadingGloabalHighScoresActivity extends Activity {

  private ProgressDialog progress;

  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.globalhighscores);

    progress = new ProgressDialog(this);
    progress.setMessage("Loading...");
    new AsyncLoadJSON(progress).execute();

  }

  public class AsyncLoadJSON extends AsyncTask<Context, Void, JSONArray> {

    private ProgressDialog progress;

    public AsyncLoadJSON(ProgressDialog progress) {

      this.progress = progress;

    }
    
    /**
     * doInBackground Overridden to change data type
     * 
     * @return json
     * @author James White
     */
    @Override
    protected JSONArray doInBackground(Context... params) {

      // Get the JSON using our RemoteDatabase class
      Database db = new Database(getApplicationContext());
      JSONArray json = db.getGlobalScores();

      return json;

    }
    
    /**
     * onPreExecute Shows progress spinner
     * 
     * @author James White
     */
    public void onPreExecute() {

      progress.show();

    }
    
    /**
     * onPostExecute Overridden to change data type
     * 
     * @return result the JSON
     * @author James White
     */
    public void onPostExecute(JSONArray result) {
      
      // Hide the progress box
      progress.dismiss();
      
      // Finish this activity
      finish();

      // Pass the JSON back to our activity
      Intent globalHighScoreIntent = new Intent(LoadingGloabalHighScoresActivity.this, GlobalHighScoreActivity.class);
      globalHighScoreIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      globalHighScoreIntent.putExtra("jsonArray", result.toString());
      startActivity(globalHighScoreIntent);

    }

  }

}




Java Source Code List

com.JamesWhite.NoughtsAndCrosses.AsyncSubmitGloabalHighScoresActivity.java
com.JamesWhite.NoughtsAndCrosses.ComputerPlayer.java
com.JamesWhite.NoughtsAndCrosses.Database.java
com.JamesWhite.NoughtsAndCrosses.GameActivity.java
com.JamesWhite.NoughtsAndCrosses.Game.java
com.JamesWhite.NoughtsAndCrosses.GlobalHighScoreActivity.java
com.JamesWhite.NoughtsAndCrosses.LoadingGloabalHighScoresActivity.java
com.JamesWhite.NoughtsAndCrosses.LocalDatabase.java
com.JamesWhite.NoughtsAndCrosses.LocalHighScoreActivity.java
com.JamesWhite.NoughtsAndCrosses.MenuActivity.java
com.JamesWhite.NoughtsAndCrosses.Player.java
com.JamesWhite.NoughtsAndCrosses.RemoteDatabase.java