Back to project page android-tic-tac-toe.
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.
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(); } }