Android Open Source - androidtbsgame Shared Preferences Manager






From Project

Back to project page androidtbsgame.

License

The source code is released under:

MIT License

If you think the Android project androidtbsgame 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 de.mmssb.androidtbsgame.andengine.managers;
//from   ww  w.ja  va2 s  . c  om
import java.util.Map;
import java.util.TreeMap;

import android.content.Context;
import android.content.SharedPreferences;
import de.mmssb.androidtbsgame.andengine.BoardMap;
import de.mmssb.androidtbsgame.andengine.Model;

/**
 * @author Manu
 * 
 */
public class SharedPreferencesManager extends Manager {
  public static final String KEYFRONT_MAP = String
      .valueOf("<MAP>".hashCode());
  private Map<String, BoardMap> mapStorage;
  private int dollars;

  /**
   * Creates an instance of {@link SharedPreferencesManager}
   * 
   * @param model
   *            {@link Model} reference
   */
  public SharedPreferencesManager(Model model) {
    super(model);
    mapStorage
        .put("Level 1",
            new BoardMap(
                "[60/60]PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPFPPPFPFPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPFPPPFPFPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPFPPPFPFPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPFFFFFPFPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPFPPPFPFPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPFPPPFPFPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPFPPPFPFPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPF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{
    mapStorage = new TreeMap<String, BoardMap>();
    SharedPreferences prefs = getModel().getMainActivity().getPreferences(
        Context.MODE_PRIVATE);
    for (String key : prefs.getAll().keySet()) {
      if (key.startsWith(KEYFRONT_MAP)) {
        mapStorage.put(key.substring(KEYFRONT_MAP.length()),
            new BoardMap(prefs.getString(key, null)));
      }
    }
    dollars = prefs.getInt("dollars", 0);
  }

  public void save() {
    SharedPreferences.Editor editor = getModel().getMainActivity()
        .getPreferences(Context.MODE_PRIVATE).edit();
    for (String key : mapStorage.keySet()) {
      editor.putString(KEYFRONT_MAP + key, mapStorage.get(key).toString());
    }
    editor.putInt("dollars", dollars);
    editor.commit();
  }

  public Map<String, BoardMap> getMapStorage() {
    return mapStorage;
  }

  public int getDollars() {
    return dollars;
  }

  public void setDollars(int dollars) {
    this.dollars = dollars;
  }
}




Java Source Code List

de.mmssb.androidtbsgame.andengine.BoardMap.java
de.mmssb.androidtbsgame.andengine.GameControl.java
de.mmssb.androidtbsgame.andengine.MainActivity.java
de.mmssb.androidtbsgame.andengine.Model.java
de.mmssb.androidtbsgame.andengine.entities.board.Board.java
de.mmssb.androidtbsgame.andengine.entities.board.Cell.java
de.mmssb.androidtbsgame.andengine.entities.board.Mark.java
de.mmssb.androidtbsgame.andengine.hud.ImageButtonSprite.java
de.mmssb.androidtbsgame.andengine.hud.ModelHUD.java
de.mmssb.androidtbsgame.andengine.managers.CellControl.java
de.mmssb.androidtbsgame.andengine.managers.Manager.java
de.mmssb.androidtbsgame.andengine.managers.ResourceManager.java
de.mmssb.androidtbsgame.andengine.managers.SceneManager.java
de.mmssb.androidtbsgame.andengine.managers.SharedPreferencesManager.java
de.mmssb.androidtbsgame.andengine.scenes.GameScene.java
de.mmssb.androidtbsgame.andengine.scenes.ModelScene.java
de.mmssb.androidtbsgame.andengine.units.AnimationProperties.java