Android Open Source - spacegunner Game Result View Impl






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.gameresult;
/*w w w.ja v a2  s . c o m*/
import static com.example.spacegunner.constants.Constants.POINTS;
import static com.example.spacegunner.constants.Constants.TAG;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.spacegunner.R;
import com.example.spacegunner.ioservice.IOService;
import com.example.spacegunner.ioservice.PlayerHighscore;
import com.example.spacegunner.main.MainViewImpl;

public class GameResultViewImpl extends Activity implements GameResultView,
    OnClickListener {

  private GameResultPresenter presenter;
  
  private Button buttonSaveHighscore;
  private Button buttonReturnMainView;
  private Animation fadeIn;

  IOService ioService;

  @Override
  public void onCreate(Bundle savedInstance) {
    super.onCreate(savedInstance);
    Log.d(TAG, "Creating GameResultView");
    setContentView(R.layout.gameresult);
    this.ioService = new IOService(this);
    final int defaultScore = 0;
    final int highscore = getIntent().getIntExtra(POINTS, defaultScore);
    this.presenter = new GameResultPresenterImpl(this, highscore);
    this.buttonSaveHighscore = (Button) findViewById(R.id.buttonstartgame);
    this.buttonSaveHighscore.setOnClickListener(this);
    this.buttonReturnMainView = (Button) findViewById(R.id.buttonreturnmain);
    this.buttonReturnMainView.setOnClickListener(this);
    this.fadeIn = AnimationUtils.loadAnimation(this, R.anim.fadein);
  }

  @Override
  public void onResume() {
    super.onResume();
    View gameResultBackground = findViewById(R.id.gameresult_background);
    gameResultBackground.startAnimation(fadeIn);
  }
  
  @Override
  public void hideSaveHighscoreLayout() {
    LinearLayout layout = (LinearLayout) findViewById(R.id.layoutHighscore);
    layout.setVisibility(View.GONE);
  }

  @Override
  public void onClick(View button) {
    if (button.getId() == R.id.buttonstartgame) {
      final TextView textViewName = (TextView) findViewById(R.id.textname);
      final String playerName = textViewName.getText().toString().trim();
      this.presenter.saveHighscoreButtonClicked(playerName);
    } else if (button.getId() == R.id.buttonreturnmain) {
      this.presenter.buttonReturnMainViewClicked();
    }

  }

  @Override
  public PlayerHighscore readHighscore() {
    return this.ioService.readHighscore();
  }

  @Override
  public void saveHighscore(final PlayerHighscore playerHighscore) {
    this.ioService.saveHighscore(playerHighscore);
  }

  @Override
  public void showHighscoreSavedToast() {
    Toast.makeText(this,
        getResources().getString(R.string.highscore_saved),
        Toast.LENGTH_SHORT).show();
  }

  @Override
  public void startMainView() {
    startActivity(new Intent(this, MainViewImpl.class));
  }

  @Override
  public void onBackPressed() {
    this.presenter.backButtonPressed();
  }

}




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