Android Open Source - noughts-and-crosses-android Database






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;
/*from w w w . j a  v  a  2 s .  com*/
/**
 * 
 * Database
 * 
 * @author James White
 * 
 * Parent class of the two databases, makes it easier to submit/retrieve scores
 * 
 */

import org.json.JSONArray;

import android.content.Context;
import android.database.Cursor;

public class Database {

  private Context context;
  private LocalDatabase localDb;
  private RemoteDatabase remoteDb;

  public Database(Context context) {

    this.context = context;

  };

  /**
   * localDb returns a LocalDatabase object
   * 
   * @return localDb a LocalDatabase object
   * @author James White
   */
  private LocalDatabase localDb() {

    return new LocalDatabase(context, "", null, 0);

  }

  /**
   * remoteDb returns a LocalDatabase object
   * 
   * @return remoteDb a RemoteDatabae object
   * @author James White
   */
  private RemoteDatabase remoteDb() {

    return new RemoteDatabase();

  }

  /**
   * postScore handles posting a score to both the local and remote databases
   * 
   * @param name
   *            player name
   * @param score
   *            the score to be inserted
   * @param date
   *            the date of the game
   * @author James White
   */
  public String postScore(String name, int score, int date) {

    localDb = this.localDb();
    remoteDb = this.remoteDb();

    localDb.insertScore(name, score, date);
    String returnRemote = remoteDb.insertScore(name, score, date);

    localDb.close();

    return returnRemote;

  }

  /**
   * getLocalScores accessor method for getting the LocalScores Cursor
   * 
   * @return localDb
   * @author James White
   */
  public Cursor getLocalScores() {

    localDb = this.localDb();
    return localDb.getScores();

  }

  /**
   * getGlobalScores accessor method for getting the JSON returned from the
   * RemoteDatabase HTTP POST request to the server
   * 
   * @return json
   * @author James White
   */
  public JSONArray getGlobalScores() {

    remoteDb = this.remoteDb();
    return remoteDb.getJSONArray();

  }

  /**
   * close self explanatory, close the SQLite database to prevent leaks
   * 
   * @author James White
   */
  public void close() {

    localDb = this.localDb();
    localDb.close();

  }

}




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