Moved CuckooChessAPK project to trunk/

This commit is contained in:
Peter Osterlund 2011-11-12 19:44:02 +00:00
parent 0461be164f
commit 7a793cd44e
16 changed files with 950 additions and 0 deletions

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="src" path="/CuckooChessEngine"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

34
CuckooChessAPK/.project Normal file
View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>CuckooChessAPK</name>
<comment></comment>
<projects>
<project>CuckooChessEngine</project>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="org.petero.cuckoochess"
android:versionCode="2"
android:versionName="1.05"
xmlns:android="http://schemas.android.com/apk/res/android">
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:debuggable="false">
<activity android:name=".CuckooChess"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="Preferences" android:label="Preferences"></activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>

Binary file not shown.

View File

@ -0,0 +1,13 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "ant.properties", and override values to adapt the script to your
# project structure.
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-4

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<view
class="org.petero.cuckoochess.ChessBoard"
android:id="@+id/chessboard"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/status"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:includeFontPadding="true"
android:typeface="monospace"
android:textSize="10dip"/>
<ScrollView
android:id="@+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="@+id/moveList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:includeFontPadding="true"
android:typeface="monospace"
android:textSize="10dip"/>
</ScrollView>
<TextView
android:id="@+id/thinking"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:includeFontPadding="true"
android:typeface="monospace"
android:textSize="10dip"/>
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<view
class="org.petero.cuckoochess.ChessBoard"
android:id="@+id/chessboard"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<TextView
android:id="@+id/status"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:includeFontPadding="true"
android:typeface="monospace"
android:textSize="10dip"/>
<ScrollView
android:id="@+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="@+id/moveList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:includeFontPadding="true"
android:typeface="monospace"
android:textSize="10dip"/>
</ScrollView>
<TextView
android:id="@+id/thinking"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:includeFontPadding="true"
android:typeface="monospace"
android:textSize="10dip"/>
</LinearLayout>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/item_new_game" android:title="New Game"></item>
<item android:id="@+id/item_settings" android:title="Settings"></item>
<item android:id="@+id/item_undo" android:title="Undo"></item>
<item android:id="@+id/item_redo" android:title="Redo"></item>
</menu>

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">CuckooChess</string>
<string-array name="thinking_times_texts">
<item>Easy</item>
<item>1s</item>
<item>5s</item>
<item>10s</item>
<item>30s</item>
<item>60s</item>
</string-array>
<string-array name="thinking_times_values">
<item>-1</item>
<item>1000</item>
<item>5000</item>
<item>10000</item>
<item>30000</item>
<item>60000</item>
</string-array>
<string-array name="font_size_texts">
<item>Small</item>
<item>Medium</item>
<item>Large</item>
</string-array>
<string-array name="font_size_values">
<item>10</item>
<item>12</item>
<item>16</item>
</string-array>
</resources>

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:title="Play White"
android:key="playerWhite"
android:defaultValue="true">
</CheckBoxPreference>
<CheckBoxPreference
android:title="Flip Board"
android:key="boardFlipped"
android:defaultValue="false">
</CheckBoxPreference>
<ListPreference
android:title="Thinking Time"
android:key="timeLimit"
android:entryValues="@array/thinking_times_values"
android:entries="@array/thinking_times_texts"
android:defaultValue="5000">
</ListPreference>
<CheckBoxPreference
android:title="Show Computer Thinking"
android:key="showThinking"
android:defaultValue="false">
</CheckBoxPreference>
<ListPreference
android:title="Text Size"
android:key="fontSize"
android:entryValues="@array/font_size_values"
android:entries="@array/font_size_texts"
android:defaultValue="12">
</ListPreference>
</PreferenceScreen>

View File

@ -0,0 +1,323 @@
/*
CuckooChess - A java chess program.
Copyright (C) 2011 Peter Österlund, peterosterlund2@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.petero.cuckoochess;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import chess.Move;
import chess.Piece;
import chess.Position;
public class ChessBoard extends View {
private Position pos;
private int selectedSquare;
private float cursorX, cursorY;
private boolean cursorVisible;
private int x0, y0, sqSize;
private boolean flipped;
private Paint darkPaint;
private Paint brightPaint;
private Paint redOutline;
private Paint greenOutline;
private Paint whitePiecePaint;
private Paint blackPiecePaint;
public ChessBoard(Context context, AttributeSet attrs) {
super(context, attrs);
pos = new Position();
selectedSquare = -1;
cursorX = cursorY = 0;
cursorVisible = false;
x0 = y0 = sqSize = 0;
flipped = false;
darkPaint = new Paint();
darkPaint.setARGB(255, 128, 128, 128);
brightPaint = new Paint();
brightPaint.setARGB(255, 190, 190, 90);
redOutline = new Paint();
redOutline.setARGB(255, 255, 0, 0);
redOutline.setStyle(Paint.Style.STROKE);
redOutline.setAntiAlias(true);
greenOutline = new Paint();
greenOutline.setARGB(255, 0, 255, 0);
greenOutline.setStyle(Paint.Style.STROKE);
greenOutline.setAntiAlias(true);
whitePiecePaint = new Paint();
whitePiecePaint.setARGB(255, 255, 255, 255);
whitePiecePaint.setAntiAlias(true);
blackPiecePaint = new Paint();
blackPiecePaint.setARGB(255, 0, 0, 0);
blackPiecePaint.setAntiAlias(true);
}
public void setFont(Typeface tf) {
whitePiecePaint.setTypeface(tf);
blackPiecePaint.setTypeface(tf);
invalidate();
}
/**
* Set the board to a given state.
* @param pos
*/
final public void setPosition(Position pos) {
this.pos = pos;
invalidate();
}
/**
* Set/clear the board flipped status.
* @param flipped
*/
final public void setFlipped(boolean flipped) {
this.flipped = flipped;
invalidate();
}
/**
* Set/clear the selected square.
* @param square The square to select, or -1 to clear selection.
*/
final public void setSelection(int square) {
if (square != selectedSquare) {
selectedSquare = square;
invalidate();
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = getMeasuredWidth();
int height = getMeasuredHeight();
int minSize = Math.min(width, height);
setMeasuredDimension(minSize, minSize);
}
@Override
protected void onDraw(Canvas canvas) {
final int width = getWidth();
final int height = getHeight();
sqSize = (Math.min(width, height) - 4) / 8;
x0 = (width - sqSize * 8) / 2;
y0 = (height - sqSize * 8) / 2;
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
final int xCrd = getXCrd(x);
final int yCrd = getYCrd(y);
Paint paint = Position.darkSquare(x, y) ? darkPaint : brightPaint;
canvas.drawRect(xCrd, yCrd, xCrd+sqSize, yCrd+sqSize, paint);
int sq = Position.getSquare(x, y);
int p = pos.getPiece(sq);
drawPiece(canvas, xCrd + sqSize / 2, yCrd + sqSize / 2, p);
}
}
if (selectedSquare >= 0) {
int selX = Position.getX(selectedSquare);
int selY = Position.getY(selectedSquare);
redOutline.setStrokeWidth(sqSize/(float)16);
int x0 = getXCrd(selX);
int y0 = getYCrd(selY);
canvas.drawRect(x0, y0, x0 + sqSize, y0 + sqSize, redOutline);
}
if (cursorVisible) {
int x = Math.round(cursorX);
int y = Math.round(cursorY);
int x0 = getXCrd(x);
int y0 = getYCrd(y);
greenOutline.setStrokeWidth(sqSize/(float)16);
canvas.drawRect(x0, y0, x0 + sqSize, y0 + sqSize, greenOutline);
}
}
private final void drawPiece(Canvas canvas, int xCrd, int yCrd, int p) {
String ps;
switch (p) {
case Piece.EMPTY:
ps = "";
break;
case Piece.WKING:
ps = "k";
break;
case Piece.WQUEEN:
ps = "q";
break;
case Piece.WROOK:
ps = "r";
break;
case Piece.WBISHOP:
ps = "b";
break;
case Piece.WKNIGHT:
ps = "n";
break;
case Piece.WPAWN:
ps = "p";
break;
case Piece.BKING:
ps = "l";
break;
case Piece.BQUEEN:
ps = "w";
break;
case Piece.BROOK:
ps = "t";
break;
case Piece.BBISHOP:
ps = "v";
break;
case Piece.BKNIGHT:
ps = "m";
break;
case Piece.BPAWN:
ps = "o";
break;
default:
ps = "?";
break;
}
if (ps.length() > 0) {
Paint paint = Piece.isWhite(p) ? whitePiecePaint : blackPiecePaint;
paint.setTextSize(sqSize);
Rect bounds = new Rect();
paint.getTextBounds(ps, 0, ps.length(), bounds);
int xCent = bounds.centerX();
int yCent = bounds.centerY();
canvas.drawText(ps, xCrd - xCent, yCrd - yCent, paint);
}
}
private final int getXCrd(int x) {
return x0 + sqSize * (flipped ? 7 - x : x);
}
private final int getYCrd(int y) {
return y0 + sqSize * (flipped ? y : (7 - y));
}
/**
* Compute the square corresponding to the coordinates of a mouse event.
* @param evt Details about the mouse event.
* @return The square corresponding to the mouse event, or -1 if outside board.
*/
final int eventToSquare(MotionEvent evt) {
int xCrd = (int)(evt.getX());
int yCrd = (int)(evt.getY());
int sq = -1;
if ((xCrd >= x0) && (yCrd >= y0) && (sqSize > 0)) {
int x = (xCrd - x0) / sqSize;
int y = 7 - (yCrd - y0) / sqSize;
if ((x >= 0) && (x < 8) && (y >= 0) && (y < 8)) {
if (flipped) {
x = 7 - x;
y = 7 - y;
}
sq = Position.getSquare(x, y);
}
}
return sq;
}
final Move mousePressed(int sq) {
if (sq < 0)
return null;
cursorVisible = false;
if (selectedSquare >= 0) {
int p = pos.getPiece(selectedSquare);
if ((p == Piece.EMPTY) || (Piece.isWhite(p) != pos.whiteMove)) {
setSelection(-1); // Remove selection of opponents last moving piece
}
}
int p = pos.getPiece(sq);
if (selectedSquare >= 0) {
if (sq != selectedSquare) {
if ((p == Piece.EMPTY) || (Piece.isWhite(p) != pos.whiteMove)) {
Move m = new Move(selectedSquare, sq, Piece.EMPTY);
setSelection(sq);
return m;
}
}
setSelection(-1);
} else {
boolean myColor = (p != Piece.EMPTY) && (Piece.isWhite(p) == pos.whiteMove);
if (myColor) {
setSelection(sq);
}
}
return null;
}
public static class OnTrackballListener {
public void onTrackballEvent(MotionEvent event) { }
}
OnTrackballListener otbl = null;
public void setOnTrackballListener(OnTrackballListener onTrackballListener) {
otbl = onTrackballListener;
}
@Override
public boolean onTrackballEvent(MotionEvent event) {
if (otbl != null) {
otbl.onTrackballEvent(event);
return true;
}
return false;
}
public Move handleTrackballEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
invalidate();
if (cursorVisible) {
int x = Math.round(cursorX);
int y = Math.round(cursorY);
cursorX = x;
cursorY = y;
int sq = Position.getSquare(x, y);
return mousePressed(sq);
}
return null;
}
cursorVisible = true;
int c = flipped ? -1 : 1;
cursorX += c * event.getX();
cursorY -= c * event.getY();
if (cursorX < 0) cursorX = 0;
if (cursorX > 7) cursorX = 7;
if (cursorY < 0) cursorY = 0;
if (cursorY > 7) cursorY = 7;
invalidate();
return null;
}
}

View File

@ -0,0 +1,366 @@
/*
CuckooChess - A java chess program.
Copyright (C) 2011 Peter Österlund, peterosterlund2@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.petero.cuckoochess;
import java.util.ArrayList;
import java.util.List;
import guibase.ChessController;
import guibase.GUIInterface;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.graphics.Typeface;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.ClipboardManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.View.OnTouchListener;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import chess.ChessParseError;
import chess.Move;
import chess.Position;
import chess.TextIO;
public class CuckooChess extends Activity implements GUIInterface {
ChessBoard cb;
ChessController ctrl;
boolean mShowThinking;
int mTimeLimit;
boolean playerWhite;
static final int ttLogSize = 16; // Use 2^ttLogSize hash entries.
TextView status;
ScrollView moveListScroll;
TextView moveList;
TextView thinking;
SharedPreferences settings;
private void readPrefs() {
mShowThinking = settings.getBoolean("showThinking", false);
String timeLimitStr = settings.getString("timeLimit", "5000");
mTimeLimit = Integer.parseInt(timeLimitStr);
playerWhite = settings.getBoolean("playerWhite", true);
boolean boardFlipped = settings.getBoolean("boardFlipped", false);
cb.setFlipped(boardFlipped);
ctrl.setTimeLimit();
String fontSizeStr = settings.getString("fontSize", "12");
int fontSize = Integer.parseInt(fontSizeStr);
status.setTextSize(fontSize);
moveList.setTextSize(fontSize);
thinking.setTextSize(fontSize);
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
settings = PreferenceManager.getDefaultSharedPreferences(this);
settings.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
readPrefs();
ctrl.setHumanWhite(playerWhite);
}
});
setContentView(R.layout.main);
status = (TextView)findViewById(R.id.status);
moveListScroll = (ScrollView)findViewById(R.id.scrollView);
moveList = (TextView)findViewById(R.id.moveList);
thinking = (TextView)findViewById(R.id.thinking);
cb = (ChessBoard)findViewById(R.id.chessboard);
status.setFocusable(false);
moveListScroll.setFocusable(false);
moveList.setFocusable(false);
thinking.setFocusable(false);
ctrl = new ChessController(this);
ctrl.setThreadStackSize(32768);
readPrefs();
Typeface chessFont = Typeface.createFromAsset(getAssets(), "casefont.ttf");
cb.setFont(chessFont);
cb.setFocusable(true);
cb.requestFocus();
cb.setClickable(true);
ctrl.newGame(playerWhite, ttLogSize, false);
{
String fen = "";
String moves = "";
String numUndo = "0";
String tmp;
if (savedInstanceState != null) {
tmp = savedInstanceState.getString("startFEN");
if (tmp != null) fen = tmp;
tmp = savedInstanceState.getString("moves");
if (tmp != null) moves = tmp;
tmp = savedInstanceState.getString("numUndo");
if (tmp != null) numUndo = tmp;
} else {
tmp = settings.getString("startFEN", null);
if (tmp != null) fen = tmp;
tmp = settings.getString("moves", null);
if (tmp != null) moves = tmp;
tmp = settings.getString("numUndo", null);
if (tmp != null) numUndo = tmp;
}
List<String> posHistStr = new ArrayList<String>();
posHistStr.add(fen);
posHistStr.add(moves);
posHistStr.add(numUndo);
ctrl.setPosHistory(posHistStr);
}
ctrl.startGame();
cb.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (ctrl.humansTurn() && (event.getAction() == MotionEvent.ACTION_UP)) {
int sq = cb.eventToSquare(event);
Move m = cb.mousePressed(sq);
if (m != null) {
ctrl.humanMove(m);
}
return false;
}
return false;
}
});
cb.setOnTrackballListener(new ChessBoard.OnTrackballListener() {
public void onTrackballEvent(MotionEvent event) {
if (ctrl.humansTurn()) {
Move m = cb.handleTrackballEvent(event);
if (m != null) {
ctrl.humanMove(m);
}
}
}
});
cb.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (!ctrl.computerThinking())
showDialog(CLIPBOARD_DIALOG);
return true;
}
});
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
List<String> posHistStr = ctrl.getPosHistory();
outState.putString("startFEN", posHistStr.get(0));
outState.putString("moves", posHistStr.get(1));
outState.putString("numUndo", posHistStr.get(2));
}
@Override
protected void onPause() {
List<String> posHistStr = ctrl.getPosHistory();
Editor editor = settings.edit();
editor.putString("startFEN", posHistStr.get(0));
editor.putString("moves", posHistStr.get(1));
editor.putString("numUndo", posHistStr.get(2));
editor.commit();
super.onPause();
}
@Override
protected void onDestroy() {
ctrl.stopComputerThinking();
super.onDestroy();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.options_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.item_new_game:
ctrl.newGame(playerWhite, ttLogSize, false);
ctrl.startGame();
return true;
case R.id.item_undo:
ctrl.takeBackMove();
return true;
case R.id.item_redo:
ctrl.redoMove();
return true;
case R.id.item_settings:
{
Intent i = new Intent(CuckooChess.this, Preferences.class);
startActivityForResult(i, 0);
return true;
}
}
return false;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0) {
readPrefs();
ctrl.setHumanWhite(playerWhite);
}
}
// FIXME!!! Implement "edit board"
// FIXME!!! Implement analysis mode
@Override
public void setPosition(Position pos) {
cb.setPosition(pos);
ctrl.setHumanWhite(playerWhite);
}
@Override
public void setSelection(int sq) {
cb.setSelection(sq);
}
@Override
public void setStatusString(String str) {
status.setText(str);
}
@Override
public void setMoveListString(String str) {
moveList.setText(str);
moveListScroll.fullScroll(ScrollView.FOCUS_DOWN);
}
@Override
public void setThinkingString(String str) {
thinking.setText(str);
}
@Override
public int timeLimit() {
return mTimeLimit;
}
@Override
public boolean randomMode() {
return mTimeLimit == -1;
}
@Override
public boolean showThinking() {
return mShowThinking;
}
static final int PROMOTE_DIALOG = 0;
static final int CLIPBOARD_DIALOG = 1;
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case PROMOTE_DIALOG: {
final CharSequence[] items = {"Queen", "Rook", "Bishop", "Knight"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Promote pawn to?");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
ctrl.reportPromotePiece(item);
}
});
AlertDialog alert = builder.create();
return alert;
}
case CLIPBOARD_DIALOG: {
final CharSequence[] items = {"Copy Game", "Copy Position", "Paste"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Clipboard");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
switch (item) {
case 0: {
String pgn = ctrl.getPGN();
ClipboardManager clipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(pgn);
break;
}
case 1: {
String fen = ctrl.getFEN() + "\n";
ClipboardManager clipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(fen);
break;
}
case 2: {
ClipboardManager clipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
if (clipboard.hasText()) {
String fenPgn = clipboard.getText().toString();
try {
ctrl.setFENOrPGN(fenPgn);
} catch (ChessParseError e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
break;
}
}
}
});
AlertDialog alert = builder.create();
return alert;
}
}
return null;
}
@Override
public void requestPromotePiece() {
runOnUIThread(new Runnable() {
public void run() {
showDialog(PROMOTE_DIALOG);
}
});
}
@Override
public void reportInvalidMove(Move m) {
String msg = String.format("Invalid move %s-%s", TextIO.squareToString(m.from), TextIO.squareToString(m.to));
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
}
@Override
public void runOnUIThread(Runnable runnable) {
runOnUiThread(runnable);
}
}

View File

@ -0,0 +1,31 @@
/*
CuckooChess - A java chess program.
Copyright (C) 2011 Peter Österlund, peterosterlund2@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.petero.cuckoochess;
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class Preferences extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}