Android Open Source - spacegunner I O Service






From Project

Back to project page spacegunner.

License

The source code is released under:

MIT License

If you think the Android project spacegunner 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.example.spacegunner.ioservice;
/*from w  w w  .  ja  v a 2s . com*/
import static com.example.spacegunner.constants.Constants.GAME;
import static com.example.spacegunner.constants.Constants.HIGHSCORE;
import static com.example.spacegunner.constants.Constants.PLAYERNAME;

import com.example.spacegunner.R;

import android.app.Activity;
import android.content.SharedPreferences;

public class IOService {

  private final SharedPreferences sharedPreferences;
  private final Activity activity;
  
  public IOService(final Activity activity) {
    this.activity = activity;
    this.sharedPreferences = this.activity.getSharedPreferences(GAME,
        Activity.MODE_PRIVATE);
  }

  public PlayerHighscore readHighscore() {
    final String defaultString = this.activity.getResources().getString(R.string.no_highscore);
    final String playerName = sharedPreferences.getString(PLAYERNAME,
        defaultString);
    final int defaultScore = 0;
    final int highscore = sharedPreferences.getInt(HIGHSCORE, defaultScore);
    return new PlayerHighscore(playerName, highscore);
  }

  public void saveHighscore(PlayerHighscore playerHighscore) {
    final SharedPreferences.Editor editor = this.sharedPreferences.edit();
    editor.putString(PLAYERNAME, playerHighscore.getPlayerName());
    editor.putInt(HIGHSCORE, playerHighscore.getHighscore());
    editor.commit();
  }

}




Java Source Code List

com.example.spacegunner.constants.Constants.java
com.example.spacegunner.game.GameModelImpl.java
com.example.spacegunner.game.GameModel.java
com.example.spacegunner.game.GamePresenterImpl.java
com.example.spacegunner.game.GamePresenter.java
com.example.spacegunner.game.GameViewImpl.java
com.example.spacegunner.game.GameView.java
com.example.spacegunner.gameresult.GameResultModelImpl.java
com.example.spacegunner.gameresult.GameResultModel.java
com.example.spacegunner.gameresult.GameResultPresenterImpl.java
com.example.spacegunner.gameresult.GameResultPresenter.java
com.example.spacegunner.gameresult.GameResultViewImpl.java
com.example.spacegunner.gameresult.GameResultView.java
com.example.spacegunner.ioservice.IOService.java
com.example.spacegunner.ioservice.PlayerHighscore.java
com.example.spacegunner.level.LevelModelImpl.java
com.example.spacegunner.level.LevelModel.java
com.example.spacegunner.level.LevelPresenterImpl.java
com.example.spacegunner.level.LevelPresenter.java
com.example.spacegunner.level.LevelViewImpl.java
com.example.spacegunner.level.LevelView.java
com.example.spacegunner.main.MainPresenterImpl.java
com.example.spacegunner.main.MainPresenter.java
com.example.spacegunner.main.MainViewImpl.java
com.example.spacegunner.main.MainView.java