Android Open Source - DemiGod Shared Prefs Manager






From Project

Back to project page DemiGod.

License

The source code is released under:

GNU General Public License

If you think the Android project DemiGod 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 high.caliber.productions.demigod.utils;
/* w  w w. ja  va  2 s  .  c om*/
import android.content.*;

public class SharedPrefsManager {

  Context context;

  public SharedPrefsManager(Context context) {
    this.context = context;
  }

  /**
   * Class that handles data in BattleLog SharedPreferences
   */
  public class BattleLogPrefs {

    private SharedPreferences prefs;
    private SharedPreferences.Editor editor;

    // BattleLog SharedPreference Constants
    public static final String BATTLE_LOG = "Battle Log";
    public static final String DAMAGE_DEALT = "Damage Dealt";
    public static final String LIFETIME_DAMAGE_DEALT = "Lifetime Damage Dealt";
    public static final String DAMAGE_RECIEVED = "Damage Recieved";
    public static final String LIFETIME_DAMAGE_RECIEVED = "Lifetime Damage Recieved";

    /**
     * Adds damageDealt to BattleLog SharedPreferences
     * 
     * @param damageDealt
     *            Desired value to add to damageDealt
     */
    public void addDamageDealt(int damageDealt) {

      prefs = context.getSharedPreferences(BATTLE_LOG, 0);
      editor = prefs.edit();

      editor.putInt(DAMAGE_DEALT, damageDealt);

      editor.commit();

    }

    /**
     * Retrieves damageDealt value from BattleLog SharedPreferences
     * 
     * @return damageDealt value
     */
    public int getDamageDealt() {
      prefs = context.getSharedPreferences(BATTLE_LOG, 0);

      return prefs.getInt(DAMAGE_DEALT, 0);

    }

    public void addLifetimeDamageDealt(int LifetimeDamageDealt) {
      prefs = context.getSharedPreferences(BATTLE_LOG, 0);
      editor = prefs.edit();

      editor.putInt(LIFETIME_DAMAGE_DEALT, LifetimeDamageDealt);
      editor.commit();
    }

    public int getLifetimeDamageDealt() {
      prefs = context.getSharedPreferences(BATTLE_LOG, 0);

      return prefs.getInt(LIFETIME_DAMAGE_DEALT, 0);
    }

    public void addDamageRecieved(int damageRecieved) {
      prefs = context.getSharedPreferences(BATTLE_LOG, 0);
      editor = prefs.edit();

      editor.putInt(DAMAGE_RECIEVED, damageRecieved);
      editor.commit();
    }

    public int getDamageRecieved() {
      prefs = context.getSharedPreferences(BATTLE_LOG, 0);

      return prefs.getInt(DAMAGE_RECIEVED, 0);
    }

    public void addLifetimeDamageRecieved(int lifetimeDamageRecieved) {
      prefs = context.getSharedPreferences(BATTLE_LOG, 0);
      editor = prefs.edit();

      editor.putInt(LIFETIME_DAMAGE_RECIEVED, lifetimeDamageRecieved);
      editor.commit();
    }

    public int getLifetimeDamageRecieved() {
      prefs = context.getSharedPreferences(BATTLE_LOG, 0);

      return prefs.getInt(LIFETIME_DAMAGE_RECIEVED, 0);
    }
  }

}




Java Source Code List

high.caliber.productions.demigod.Enemy.java
high.caliber.productions.demigod.Hero.java
high.caliber.productions.demigod.Item.java
high.caliber.productions.demigod.Map.java
high.caliber.productions.demigod.Tile.java
high.caliber.productions.demigod.XmlActivityTest.java
high.caliber.productions.demigod.activity.BattleLog.java
high.caliber.productions.demigod.activity.Battle_Activity.java
high.caliber.productions.demigod.activity.CreateHero.java
high.caliber.productions.demigod.activity.HomeTown.java
high.caliber.productions.demigod.activity.Home.java
high.caliber.productions.demigod.activity.Inventory.java
high.caliber.productions.demigod.activity.Status.java
high.caliber.productions.demigod.activity.TitleScreen.java
high.caliber.productions.demigod.database.EnemyDB.java
high.caliber.productions.demigod.database.HeroDB.java
high.caliber.productions.demigod.database.ItemDB.java
high.caliber.productions.demigod.settings.DpadPosition.java
high.caliber.productions.demigod.settings.DpadSizePref.java
high.caliber.productions.demigod.settings.SettingsMain.java
high.caliber.productions.demigod.utils.AnimationUtils.java
high.caliber.productions.demigod.utils.InventoryAdapter.java
high.caliber.productions.demigod.utils.LevelUpWorker.java
high.caliber.productions.demigod.utils.PixelUnitConverter.java
high.caliber.productions.demigod.utils.SharedPrefsManager.java
high.caliber.productions.demigod.utils.XmlMapAdapter.java