Android Open Source - septica-for-android Persistence Adapter






From Project

Back to project page septica-for-android.

License

The source code is released under:

MIT License

If you think the Android project septica-for-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 fera.costin.alexandru.db;
//  www  .jav  a  2  s  .  co  m
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import fera.costin.alexandru.logic.Game;

import android.content.Context;
import android.util.Log;

/**
 * 
 * @author Alexandru Fera
 *
 */
public class PersistenceAdapter
{
  public static final String TAG = "septica";
  public static final String FILE_NAME = "septicaSaveFile";

  private Context appContext;

  public PersistenceAdapter(Context c)
  {
    super();
    appContext = c;
  }

  public Object getSavedGameData()
  {
    try
    {
      FileInputStream fis = appContext.openFileInput(FILE_NAME);
      ObjectInputStream ois = new ObjectInputStream(fis);
      Object o = ois.readObject();
      return o;
    } catch (Exception ex)
    {
      Log.d(TAG, ex.getMessage());
      ex.printStackTrace();
    }
    return null;
  }

  public void setSavedGameData(Game gd)
  {
    try
    {
      FileOutputStream fos = appContext.openFileOutput(FILE_NAME,
          Context.MODE_PRIVATE);
      ObjectOutputStream oos = new ObjectOutputStream(fos);
      oos.writeObject(gd);
      oos.flush(); // Ensure all the information was written.
      oos.close();
    } catch (Exception ex)
    {
      Log.d(TAG, ex.getMessage());
      ex.printStackTrace();
    }
  }

  public static boolean isSavedGameDataValid(Context c)
  {
    boolean retVal = true;
    try
    {
      c.openFileInput(FILE_NAME);
    } catch (FileNotFoundException e)
    {
      retVal = false;
    }
    return retVal;
  }

  public static void deleteSavedGameData(Context c)
  {
    c.deleteFile(FILE_NAME);
  }

}




Java Source Code List

fera.costin.alexandru.ai.AI.java
fera.costin.alexandru.ai.BaseAI.java
fera.costin.alexandru.ai.EasyAI.java
fera.costin.alexandru.ai.HardAI.java
fera.costin.alexandru.ai.MediumAI.java
fera.costin.alexandru.db.PersistenceAdapter.java
fera.costin.alexandru.logic.CardDeck.java
fera.costin.alexandru.logic.Card.java
fera.costin.alexandru.logic.Game.java
fera.costin.alexandru.logic.ICard.java
fera.costin.alexandru.ui.MainActivity.java
fera.costin.alexandru.ui.PreferencesActivity.java
fera.costin.alexandru.ui.SepticaActivity.java