Android Open Source - android-chess pgntool






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.tools;
//from w w w  . j  av a  2s . co  m
import java.io.File;
import java.io.FileOutputStream;

import jwtc.android.chess.HtmlActivity;
import jwtc.android.chess.MyPGNProvider;
import jwtc.android.chess.R;
import jwtc.chess.PGNColumns;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.*;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class pgntool extends ListActivity {
  
  protected static final String MODE_IMPORT = "import";
  protected static final String MODE_DB_IMPORT = "db_import";
  protected static final String MODE_DB_POINT = "db_point";
  protected static final String MODE_UCI_INSTALL = "uci_install";
  protected static final String MODE_CREATE_PRACTICE = "create_practice";
  protected static final String MODE_IMPORT_PRACTICE = "import_practice";
  protected static final String MODE_IMPORT_PUZZLE = "import_puzzle";
  protected static final String MODE_IMPORT_OPENINGDATABASE = "import_openingdatabase";
  
  protected static final String EXTRA_MODE = "jwtc.android.chess.tools.Mode";
  
  private ListView _lvStart;
  
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.pgntool);
        
    _lvStart =(ListView)findViewById(android.R.id.list);
            
    final CharSequence[] arrString;
    
    arrString = getResources().getTextArray(R.array.pgn_tool_menu); 

        _lvStart.setOnItemClickListener(new OnItemClickListener(){

      @Override
      public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        if(arrString[arg2].equals(getString(R.string.pgntool_export_explanation))){
          doExport();
          
        } else if(arrString[arg2].equals(getString(R.string.pgntool_import_explanation))){
          Intent i = new Intent();
          i.setClass(pgntool.this, FileListView.class);
          i.putExtra(EXTRA_MODE, MODE_IMPORT);
          pgntool.this.startActivity(i);
          
        } else if(arrString[arg2].equals(getString(R.string.pgntool_create_db_explanation))){
          Intent i = new Intent();
          i.setClass(pgntool.this, FileListView.class);
          i.putExtra(EXTRA_MODE, MODE_DB_IMPORT);
          pgntool.this.startActivity(i);
          
        } else if(arrString[arg2].equals(getString(R.string.pgntool_point_db_explanation))){ 
        
          Intent i = new Intent();
          i.setClass(pgntool.this, FileListView.class);
          i.putExtra(EXTRA_MODE, MODE_DB_POINT);
          pgntool.this.startActivity(i);
        } /*else if(arrString[arg2].equals(getString(R.string.pgntool_engine_test))){
          
          Intent i = new Intent();
          i.setClass(pgntool.this, EngineTester.class);
          pgntool.this.startActivity(i);
          
        }*/ else if(arrString[arg2].equals(getString(R.string.pgntool_delete_explanation))){
          AlertDialog.Builder builder = new AlertDialog.Builder(pgntool.this);
          builder.setTitle(getString(R.string.pgntool_confirm_delete));
          
          builder.setPositiveButton(getString(R.string.button_ok), new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialog, int which) {
              dialog.dismiss();
              pgntool.this.getContentResolver().delete(MyPGNProvider.CONTENT_URI, "1=1", null);
              doToast(getString(R.string.pgntool_deleted));
            }
          });
          builder.setNegativeButton(getString(R.string.button_cancel), new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialog, int which) {
              dialog.dismiss();
            }
          });
          
          AlertDialog alert = builder.create();
          alert.show();
          
        } else if(arrString[arg2].equals(getString(R.string.pgntool_help))){
          Intent i = new Intent();
             i.setClass(pgntool.this, HtmlActivity.class);
             i.putExtra(HtmlActivity.HELP_MODE, "help_pgntool");
             startActivity(i); 
        } else if(arrString[arg2].equals(getString(R.string.pgntool_point_uci_engine))){
          
          Intent i = new Intent();
          i.setClass(pgntool.this, FileListView.class);
          i.putExtra(EXTRA_MODE, MODE_UCI_INSTALL);
          pgntool.this.startActivity(i);
          
        }else if(arrString[arg2].equals(getString(R.string.pgntool_unset_uci_engine))){
          SharedPreferences prefs = getSharedPreferences("ChessPlayer", MODE_PRIVATE);
          String sEngine = prefs.getString("UCIEngine", null);
          if(sEngine != null){
            File f = new File("/data/data/jwtc.android.chess/" + sEngine);
            f.delete();
            SharedPreferences.Editor editor = prefs.edit();
            editor.putString("UCIEngine", null);
            editor.commit();
            doToast("Engine " + sEngine + " uninstalled");
          } else {
            doToast("No engine installed");
          }
        }else if(arrString[arg2].equals(getString(R.string.pgntool_reset_practice))){
          
          AlertDialog.Builder builder = new AlertDialog.Builder(pgntool.this);
          builder.setTitle(getString(R.string.pgntool_confirm_practice_reset));
          
          builder.setPositiveButton(getString(R.string.button_ok), new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialog, int which) {
              dialog.dismiss();
              
              SharedPreferences prefs = getSharedPreferences("ChessPlayer", MODE_PRIVATE);
              SharedPreferences.Editor editor = prefs.edit();
              editor.putInt("practicePos", 0);
              editor.putInt("practiceTicks", 0);
              editor.commit();
              
              doToast("Practice set has been reset");
              
            }
          });
          builder.setNegativeButton(getString(R.string.button_cancel), new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialog, int which) {
              dialog.dismiss();
            }
          });
          
          AlertDialog alert = builder.create();
          alert.show();
          
          
            } else if(arrString[arg2].equals(getString(R.string.pgntool_import_practice))){
              Intent i = new Intent();
          i.setClass(pgntool.this, FileListView.class);
          i.putExtra(EXTRA_MODE, MODE_IMPORT_PRACTICE);
          pgntool.this.startActivity(i);
            } else if(arrString[arg2].equals(getString(R.string.pgntool_create_practice_explanation))){
              Intent i = new Intent();
          i.setClass(pgntool.this, FileListView.class);
          i.putExtra(EXTRA_MODE, MODE_CREATE_PRACTICE);
          pgntool.this.startActivity(i);
            } else if(arrString[arg2].equals(getString(R.string.pgntool_import_puzzle))){
              Intent i = new Intent();
          i.setClass(pgntool.this, FileListView.class);
          i.putExtra(EXTRA_MODE, MODE_IMPORT_PUZZLE);
          pgntool.this.startActivity(i);
            }
             else if(arrString[arg2].equals(getString(R.string.pgntool_import_opening))){
               Intent i = new Intent();
           i.setClass(pgntool.this, FileListView.class);
           i.putExtra(EXTRA_MODE, MODE_IMPORT_OPENINGDATABASE);
           pgntool.this.startActivity(i);
             }
        // 
          }
    });
    }
    
    public void doExport(){
      try {
        if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
          
        String sFile = Environment.getExternalStorageDirectory() + "/chess.pgn";
        int i = 0;
        Cursor cursor = managedQuery(MyPGNProvider.CONTENT_URI, PGNColumns.COLUMNS, null, null, PGNColumns.DEFAULT_SORT_ORDER);
        if(cursor != null){
          
          if(cursor.getCount() > 0){
    
            cursor.moveToFirst();
            String s = "";
            
            while(cursor.isAfterLast() == false){
              
              s += cursor.getString(cursor.getColumnIndex(PGNColumns.PGN)) + "\n\n\n";
              cursor.moveToNext();
              i++;
            }
            
            FileOutputStream fos;
            fos = new FileOutputStream(sFile);
            fos.write(s.getBytes());
            fos.flush();
            fos.close();
          }
        }
        doToast(String.format(getString(R.string.pgntool_numexport), i));

        } else {
          doToast(getString(R.string.err_sd_not_mounted));
        }
      } catch (Exception e) {
      
      //doToast(getString(R.string.err_send_email));
      Log.e("ex", e.toString());
      return;
    } 
    }
    public void doToast(String s){
      Toast t = Toast.makeText(this, s, Toast.LENGTH_LONG);
    t.setGravity(Gravity.CENTER, 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