Android Open Source - android-tic-tac-toe Settings Activity






From Project

Back to project page android-tic-tac-toe.

License

The source code is released under:

MIT License

If you think the Android project android-tic-tac-toe 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 org.shaon.android.tictactoe.activity;
/* ww w  . j a v  a 2  s .  co m*/
import org.shaon.android.tictactoe.R;
import org.shaon.android.tictactoe.TicTacToeApplication;
import org.shaon.android.tictactoe.board.Board.GameMode;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import static org.shaon.android.tictactoe.TicTacToeApplication.*;

public class SettingsActivity extends Activity {
  
  private RadioButton greenRobotRadioButton;
  private RadioButton humanRadioButton;
  private GameMode gameMode;
  private TicTacToeApplication ticTacToeApplication;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.settings);
    
    ticTacToeApplication = (TicTacToeApplication) getApplication();
    gameMode = ticTacToeApplication.getGameMode(); 
    
    setUpViews();
  }

  private void setUpViews() {
    
      greenRobotRadioButton = (RadioButton) findViewById(R.id.settings_vs_green_robot);
      humanRadioButton = (RadioButton) findViewById(R.id.settings_vs_human);
      
      if(gameMode == null) {
        greenRobotRadioButton.setChecked(true);
      }else if(gameMode.equals(GameMode.VS_GREEN_ROBOT)) {
        greenRobotRadioButton.setChecked(true);
      }else if(gameMode.equals(GameMode.VS_HUMAN)){
        humanRadioButton.setChecked(true);
      }
  }
  
  public void saveButtonClicked(View view) {

        // We need an Editor object to make preference changes.
        // All objects are from android.context.Context
        SharedPreferences settings = getSharedPreferences(PREFERENCE_TIC_TAC_TOE, 0);
        SharedPreferences.Editor editor = settings.edit();
        
        String gameModeStr = GameMode.VS_GREEN_ROBOT.toString();
        if(humanRadioButton.isChecked()) {
          gameModeStr = GameMode.VS_HUMAN.toString();
        }
        
        editor.putString(PREFERENCE_GAME_MODE, gameModeStr);

        // Commit the edits!
        editor.commit();
        
        ticTacToeApplication.loadGameMode();
        finish();
  }
  
  public void discardButtonClicked(View view) {
    finish();
  }
}




Java Source Code List

org.shaon.android.tictactoe.TicTacToeApplication.java
org.shaon.android.tictactoe.activity.SettingsActivity.java
org.shaon.android.tictactoe.activity.TicTacToeActivity.java
org.shaon.android.tictactoe.board.Board.java
org.shaon.android.tictactoe.board.Cell.java
org.shaon.android.tictactoe.exception.InvalidTurn.java
org.shaon.android.tictactoe.model.ActionState.java
org.shaon.android.tictactoe.model.Action.java
org.shaon.android.tictactoe.model.AlphaBetaSearch.java
org.shaon.android.tictactoe.model.MinMax.java
org.shaon.android.tictactoe.model.PlayerConfig.java
org.shaon.android.tictactoe.model.SearchAlgorithm.java
org.shaon.android.tictactoe.model.State.java
org.shaon.android.tictactoe.model.TerminatingCondition.java
org.shaon.android.tictactoe.model.WinningCombination.java