Android Open Source - android-chess options






From Project

Back to project page android-chess.

License

The source code is released under:

MIT License

If you think the Android project android-chess 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 jwtc.android.chess;
/*from ww w .jav a  2s .c om*/
import jwtc.chess.GameControl;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.InputType;
import android.view.Gravity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TableRow;

public class options extends Activity {

  public static final int RESULT_960 = 1;
  
  private CheckBox _checkPlay, _checkAutoFlip, _checkMoves, _check960;
  private Spinner _spinLevel, _spinLevelPly;
  private Button _butCancel, _butOk;
  private RadioButton _radioTime, _radioPly;
  private TableRow _tableRowOption960;
  
  @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
     
        setContentView(R.layout.options);
     
        setTitle(R.string.title_options);

    _checkPlay = (CheckBox)findViewById(R.id.CheckBoxOptionsPlayAndroid);
    _checkPlay.setOnCheckedChangeListener(new OnCheckedChangeListener(){
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        _checkAutoFlip.setEnabled(false == isChecked);
      }    
    });

    _checkAutoFlip = (CheckBox)findViewById(R.id.CheckBoxOptionsAutoFlip);
    _checkMoves = (CheckBox)findViewById(R.id.CheckBoxOptionsShowMoves);
    
    _tableRowOption960 = (TableRow)findViewById(R.id.TableRowOptions960);
    _check960 = (CheckBox)findViewById(R.id.CheckBoxOptions960);
    
      ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.levels_time, android.R.layout.simple_spinner_item);
      adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

      _spinLevel = (Spinner)findViewById(R.id.SpinnerOptionsLevel);
      _spinLevel.setPrompt(getString(R.string.title_pick_level));
      _spinLevel.setAdapter(adapter);
      
      ArrayAdapter<CharSequence> adapterPly = ArrayAdapter.createFromResource(this, R.array.levels_ply, android.R.layout.simple_spinner_item);
      adapterPly.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      _spinLevelPly = (Spinner)findViewById(R.id.SpinnerOptionsLevelPly);
      _spinLevelPly.setPrompt(getString(R.string.title_pick_level));
      _spinLevelPly.setAdapter(adapterPly);
      
      _radioTime = (RadioButton)findViewById(R.id.RadioOptionsTime);
      _radioTime.setOnCheckedChangeListener(new OnCheckedChangeListener(){
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        _radioPly.setChecked(_radioTime.isChecked() ? false : true);
      }    
    });
      _radioPly = (RadioButton)findViewById(R.id.RadioOptionsPly);
      _radioPly.setOnCheckedChangeListener(new OnCheckedChangeListener(){
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        _radioTime.setChecked(_radioPly.isChecked() ? false : true);
      }    
    });
      
      _butCancel = (Button)findViewById(R.id.ButtonOptionsCancel);
    _butCancel.setOnClickListener(new View.OnClickListener() {
          public void onClick(View arg0) {
            setResult(RESULT_CANCELED);
            finish();
          }
    });
    
    _butOk = (Button)findViewById(R.id.ButtonOptionsOk);
    _butOk.setOnClickListener(new View.OnClickListener() {
          public void onClick(View arg0) {
            
            SharedPreferences.Editor editor = getSharedPreferences("ChessPlayer", MODE_PRIVATE).edit();
            
            editor.putInt("levelMode", _radioTime.isChecked() ? GameControl.LEVEL_TIME : GameControl.LEVEL_PLY);
            editor.putInt("level", _spinLevel.getSelectedItemPosition()+1);
            editor.putInt("levelPly", _spinLevelPly.getSelectedItemPosition()+1);
            editor.putInt("playMode", _checkPlay.isChecked() ? GameControl.HUMAN_PC : GameControl.HUMAN_HUMAN);
            editor.putBoolean("autoflipBoard", _checkAutoFlip.isChecked());
            editor.putBoolean("showMoves", _checkMoves.isChecked());
            
            editor.commit();
            
            if(_tableRowOption960.getVisibility() == View.VISIBLE && _check960.isChecked()){
              
              
              AlertDialog.Builder builder = new AlertDialog.Builder(options.this);
                builder.setTitle(getString(R.string.title_chess960_manual_random));
                final EditText input = new EditText(options.this);
                input.setInputType(InputType.TYPE_CLASS_PHONE);
                builder.setView(input);
                builder.setPositiveButton(getString(R.string.choice_manually), new DialogInterface.OnClickListener() {  
                    public void onClick(DialogInterface dialog, int whichButton) {
                      try{
                        int seed = Integer.parseInt(input.getText().toString());
                        
                        if(seed >= 0 && seed <= 960){
                          //_chessView.newGameRandomFischer(seed);
                          SharedPreferences.Editor editor = getSharedPreferences("ChessPlayer", MODE_PRIVATE).edit();
                            editor.putString("FEN", null);
                            editor.putInt("boardNum", 0);
                            editor.putInt("randomFischerSeed", seed % 960);
                            editor.commit();
                            
                            finish();
                        } else {
                          doToast(getString(R.string.err_chess960_position_range));
                        }
                      } catch(Exception ex){
                        doToast(getString(R.string.err_chess960_postion_format));
                      }
                    }
                });
                builder.setNegativeButton(getString(R.string.choice_random), new DialogInterface.OnClickListener() {

                      public void onClick(DialogInterface dialog, int which) {
                        int seed = -1;
                        //seed = _chessView.newGameRandomFischer(seed);
                        
                        SharedPreferences.Editor editor = getSharedPreferences("ChessPlayer", MODE_PRIVATE).edit();
                          editor.putString("FEN", null);
                          editor.putInt("boardNum", -1);
                          editor.putInt("randomFischerSeed", seed);
                          editor.commit();
                          
                          finish();
                      }
                });
                  
                  AlertDialog alert = builder.create();
              alert.show();
              
              setResult(RESULT_960);
              
            } else {
              setResult(RESULT_OK);
              finish();
            }
          }
    });
  }
  
  
   @Override
   protected void onResume() {
     
     final Intent intent = getIntent();

     if(intent.getExtras().getInt("requestCode") == main.REQUEST_NEWGAME){
       setTitle(R.string.menu_new);
       _tableRowOption960.setVisibility(View.VISIBLE);
     } else {
       _check960.setChecked(false);
       _tableRowOption960.setVisibility(View.GONE);
     }
     
     SharedPreferences prefs = getSharedPreferences("ChessPlayer", MODE_PRIVATE);
     
    _checkPlay.setChecked(prefs.getInt("playMode", GameControl.HUMAN_PC) == GameControl.HUMAN_PC);
     _checkAutoFlip.setChecked(prefs.getBoolean("autoflipBoard", false));
     _checkAutoFlip.setEnabled(false == _checkPlay.isChecked());
     _checkMoves.setChecked(prefs.getBoolean("showMoves", true));
     
     _radioTime.setChecked(prefs.getInt("levelMode", GameControl.LEVEL_TIME) == GameControl.LEVEL_TIME);
       _radioPly.setChecked(prefs.getInt("levelMode", GameControl.LEVEL_TIME) == GameControl.LEVEL_PLY);
       
     _spinLevel.setSelection(prefs.getInt("level", 2)-1);
     _spinLevelPly.setSelection(prefs.getInt("levelPly", 2)-1);
     
     super.onResume();
   }
   
   @Override
      protected void onPause() {
     
     super.onPause();
   }
   
   public void doToast(final String text){
    Toast t = Toast.makeText(this, text, Toast.LENGTH_LONG);
    t.setGravity(Gravity.BOTTOM, 0, 0);
    t.show();
    }
}




Java Source Code List

jwtc.android.chess.ChessFieldView.java
jwtc.android.chess.ChessImageView.java
jwtc.android.chess.ChessPreferences.java
jwtc.android.chess.ChessViewBase.java
jwtc.android.chess.ChessView.java
jwtc.android.chess.GamesListView.java
jwtc.android.chess.HtmlActivity.java
jwtc.android.chess.ImageCacheObject.java
jwtc.android.chess.MyBaseActivity.java
jwtc.android.chess.MyPGNProvider.java
jwtc.android.chess.PGNView.java
jwtc.android.chess.SaveGameDlg.java
jwtc.android.chess.UI.java
jwtc.android.chess.convergence.Connection.java
jwtc.android.chess.convergence.ConvergenceActivity.java
jwtc.android.chess.convergence.RestServer.java
jwtc.android.chess.iconifiedlist.IconifiedTextListAdapter.java
jwtc.android.chess.iconifiedlist.IconifiedTextView.java
jwtc.android.chess.iconifiedlist.IconifiedText.java
jwtc.android.chess.ics.CustomCommands.java
jwtc.android.chess.ics.ICSChatDlg.java
jwtc.android.chess.ics.ICSChessView.java
jwtc.android.chess.ics.ICSClient.java
jwtc.android.chess.ics.ICSConfirmDlg.java
jwtc.android.chess.ics.ICSMatchDlg.java
jwtc.android.chess.ics.TelnetSocket.java
jwtc.android.chess.ics.TimesealInputStream.java
jwtc.android.chess.ics.TimesealOutputStream.java
jwtc.android.chess.ics.TimesealPipe.java
jwtc.android.chess.ics.TimesealingSocket.java
jwtc.android.chess.puzzle.ChessViewPractice.java
jwtc.android.chess.puzzle.ChessViewPuzzle.java
jwtc.android.chess.puzzle.MyPuzzleProvider.java
jwtc.android.chess.puzzle.practice.java
jwtc.android.chess.puzzle.puzzle.java
jwtc.android.chess.tools.FileListView.java
jwtc.android.chess.tools.PGNProcessor.java
jwtc.android.chess.tools.importactivity.java
jwtc.android.chess.tools.pgntool.java
jwtc.android.chess.main.java
jwtc.android.chess.options.java
jwtc.android.chess.setup.java
jwtc.android.chess.start.java
jwtc.android.timeseal.TimesealingSocket.java
jwtc.android.timeseal.streams.a.java
jwtc.android.timeseal.streams.b.java
jwtc.android.timeseal.streams.c.java
jwtc.chess.ChessPuzzleProvider.java
jwtc.chess.GameControl.java
jwtc.chess.JNI.java
jwtc.chess.Move.java
jwtc.chess.PGNColumns.java
jwtc.chess.PGNEntry.java
jwtc.chess.PGNProvider.java
jwtc.chess.Pos.java
jwtc.chess.Valuation.java
jwtc.chess.algorithm.SearchAlgorithmRunner.java
jwtc.chess.algorithm.UCIWrapper.java
jwtc.chess.board.BoardConstants.java
jwtc.chess.board.BoardHashKeys.java
jwtc.chess.board.BoardMembers.java
jwtc.chess.board.BoardStatics.java
jwtc.chess.board.ChessBoard.java