diff --git a/DroidFish/res/values/strings.xml b/DroidFish/res/values/strings.xml
index 04a5cb9..bf4f59b 100644
--- a/DroidFish/res/values/strings.xml
+++ b/DroidFish/res/values/strings.xml
@@ -12,6 +12,7 @@
2
1000000
1
+ 5000
\
CPU Usage\n\
If you leave DroidFish running in the background and GameMode is set to \
@@ -114,6 +115,8 @@ you are not actively using the program.\
Goto End of Variation
Goto Next Variation
Load Next Game
+ Auto Forward
+ Auto Backward
No previous game
No next game
No previous position
@@ -270,6 +273,8 @@ you are not actively using the program.\
Maximum thinking time between time controls
Increment
Extra thinking time for each completed move
+ Auto Move Delay
+ Delay between moves in automatic forward/backward mode
Hints
Show Computer Thinking
Display computer algorithm information during search
@@ -549,6 +554,28 @@ you are not actively using the program.\
- 30000
- 60000
+
+ - 0.5s
+ - 1s
+ - 2s
+ - 3s
+ - 5s
+ - 10s
+ - 15s
+ - 30s
+ - 60s
+
+
+ - 500
+ - 1000
+ - 2000
+ - 3000
+ - 5000
+ - 10000
+ - 15000
+ - 30000
+ - 60000
+
- Sticky
- Toggle
diff --git a/DroidFish/res/xml/preferences.xml b/DroidFish/res/xml/preferences.xml
index 9030cd1..08fc4d7 100644
--- a/DroidFish/res/xml/preferences.xml
+++ b/DroidFish/res/xml/preferences.xml
@@ -509,6 +509,14 @@
android:summary="@string/prefs_invertScrollDirection_summary"
android:defaultValue="false">
+
+
0)
+ if (nUndo + nRedo > 0) {
scrollY = 0;
+ setAutoMode(AutoMode.OFF);
+ }
if (nRedo + nUndo > 1) {
boolean analysis = gameMode.analysisMode();
boolean human = gameMode.playerWhite() || gameMode.playerBlack();
@@ -796,6 +808,7 @@ public class DroidFish extends Activity implements GUIInterface {
}
if (varDelta != 0) {
scrollX = 0;
+ setAutoMode(AutoMode.OFF);
ctrl.changeVariation(varDelta);
}
return varDelta != 0;
@@ -808,8 +821,10 @@ public class DroidFish extends Activity implements GUIInterface {
public void onTrackballEvent(MotionEvent event) {
if (ctrl.humansTurn()) {
Move m = cb.handleTrackballEvent(event);
- if (m != null)
+ if (m != null) {
+ setAutoMode(AutoMode.OFF);
ctrl.makeHumanMove(m);
+ }
setEgtbHints(cb.getSelectedSquare());
}
}
@@ -859,6 +874,7 @@ public class DroidFish extends Activity implements GUIInterface {
undoButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
+ setAutoMode(AutoMode.OFF);
ctrl.undoMove();
}
});
@@ -874,6 +890,7 @@ public class DroidFish extends Activity implements GUIInterface {
redoButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
+ setAutoMode(AutoMode.OFF);
ctrl.redoMove();
}
});
@@ -911,6 +928,7 @@ public class DroidFish extends Activity implements GUIInterface {
@Override
protected void onPause() {
if (ctrl != null) {
+ setAutoMode(AutoMode.OFF);
ctrl.setGuiPaused(true);
byte[] data = ctrl.toByteArray();
Editor editor = settings.edit();
@@ -927,6 +945,7 @@ public class DroidFish extends Activity implements GUIInterface {
@Override
protected void onDestroy() {
+ setAutoMode(AutoMode.OFF);
if (ctrl != null)
ctrl.shutdownEngine();
setNotification(false);
@@ -975,6 +994,8 @@ public class DroidFish extends Activity implements GUIInterface {
movesPerSession = getIntSetting("movesPerSession", 60);
timeIncrement = getIntSetting("timeIncrement", 0);
+ autoMoveDelay = getIntSetting("autoDelay", 5000);
+
scrollSensitivity = Float.parseFloat(settings.getString("scrollSensitivity", "2"));
invertScrollDirection = settings.getBoolean("invertScrollDirection", false);
discardVariations = settings.getBoolean("discardVariations", false);
@@ -1299,6 +1320,7 @@ public class DroidFish extends Activity implements GUIInterface {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
+ setAutoMode(AutoMode.OFF);
switch (item.getItemId()) {
case R.id.item_new_game:
showDialog(NEW_GAME_DIALOG);
@@ -1469,6 +1491,7 @@ public class DroidFish extends Activity implements GUIInterface {
editor.putString("gameMode", gameModeStr);
editor.commit();
gameMode = new GameMode(gameModeType);
+ maybeAutoModeOff(gameMode);
ctrl.setGameMode(gameMode);
}
@@ -1888,6 +1911,7 @@ public class DroidFish extends Activity implements GUIInterface {
final int COPY_POSITION = 1;
final int PASTE = 2;
+ setAutoMode(AutoMode.OFF);
List lst = new ArrayList();
List actions = new ArrayList();
lst.add(getString(R.string.copy_game)); actions.add(COPY_GAME);
@@ -1937,6 +1961,7 @@ public class DroidFish extends Activity implements GUIInterface {
final int SHARE = 2;
final int GET_FEN = 3;
+ setAutoMode(AutoMode.OFF);
List lst = new ArrayList();
List actions = new ArrayList();
lst.add(getString(R.string.clipboard)); actions.add(CLIPBOARD);
@@ -1993,6 +2018,7 @@ public class DroidFish extends Activity implements GUIInterface {
final int LOAD_SCID_GAME = 3;
final int SAVE_GAME = 4;
+ setAutoMode(AutoMode.OFF);
List lst = new ArrayList();
List actions = new ArrayList();
if (currFileType() != FT_NONE) {
@@ -2040,6 +2066,7 @@ public class DroidFish extends Activity implements GUIInterface {
String path = currPathName();
if (path.length() == 0)
return;
+ setAutoMode(AutoMode.OFF);
switch (currFileType()) {
case FT_PGN:
loadPGNFromFile(path);
@@ -2077,6 +2104,7 @@ public class DroidFish extends Activity implements GUIInterface {
}
private final Dialog selectMoveDialog() {
+ setAutoMode(AutoMode.OFF);
View content = View.inflate(this, R.layout.select_move_number, null);
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(content);
@@ -2271,6 +2299,7 @@ public class DroidFish extends Activity implements GUIInterface {
private final Dialog selectFileDialog(final String defaultDir, int selectFileMsg, int noFilesMsg,
String settingsName, final Loader loader) {
+ setAutoMode(AutoMode.OFF);
final String[] fileNames = findFilesInDirectory(defaultDir, null);
final int numFiles = fileNames.length;
if (numFiles == 0) {
@@ -2304,6 +2333,7 @@ public class DroidFish extends Activity implements GUIInterface {
}
private final Dialog selectPgnFileSaveDialog() {
+ setAutoMode(AutoMode.OFF);
final String[] fileNames = findFilesInDirectory(pgnDir, null);
final int numFiles = fileNames.length;
int defaultItem = 0;
@@ -2342,6 +2372,7 @@ public class DroidFish extends Activity implements GUIInterface {
}
private final Dialog selectPgnSaveNewFileDialog() {
+ setAutoMode(AutoMode.OFF);
View content = View.inflate(this, R.layout.create_pgn_file, null);
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(content);
@@ -2430,6 +2461,7 @@ public class DroidFish extends Activity implements GUIInterface {
editor.putString("gameMode", gameModeStr);
editor.commit();
gameMode = new GameMode(gameModeType);
+ maybeAutoModeOff(gameMode);
ctrl.setGameMode(gameMode);
setBoardFlip(flipSite);
}
@@ -2447,6 +2479,7 @@ public class DroidFish extends Activity implements GUIInterface {
final int MOVE_VAR_DOWN = 4;
final int ADD_NULL_MOVE = 5;
+ setAutoMode(AutoMode.OFF);
List lst = new ArrayList();
List actions = new ArrayList();
lst.add(getString(R.string.edit_headers)); actions.add(EDIT_HEADERS);
@@ -2657,7 +2690,9 @@ public class DroidFish extends Activity implements GUIInterface {
final int GOTO_START_VAR = 1;
final int GOTO_PREV_VAR = 2;
final int LOAD_PREV_GAME = 3;
+ final int AUTO_BACKWARD = 4;
+ setAutoMode(AutoMode.OFF);
List lst = new ArrayList();
List actions = new ArrayList();
lst.add(getString(R.string.goto_start_game)); actions.add(GOTO_START_GAME);
@@ -2670,6 +2705,9 @@ public class DroidFish extends Activity implements GUIInterface {
if ((currFT != FT_NONE) && !gameMode.clocksActive()) {
lst.add(getString(R.string.load_prev_game)); actions.add(LOAD_PREV_GAME);
}
+ if (!gameMode.clocksActive()) {
+ lst.add(getString(R.string.auto_backward)); actions.add(AUTO_BACKWARD);
+ }
final List finalActions = actions;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.go_back);
@@ -2698,6 +2736,9 @@ public class DroidFish extends Activity implements GUIInterface {
startActivityForResult(i, RESULT_LOAD_FEN);
}
break;
+ case AUTO_BACKWARD:
+ setAutoMode(AutoMode.BACKWARD);
+ break;
}
}
});
@@ -2709,7 +2750,9 @@ public class DroidFish extends Activity implements GUIInterface {
final int GOTO_END_VAR = 0;
final int GOTO_NEXT_VAR = 1;
final int LOAD_NEXT_GAME = 2;
+ final int AUTO_FORWARD = 3;
+ setAutoMode(AutoMode.OFF);
List lst = new ArrayList();
List actions = new ArrayList();
lst.add(getString(R.string.goto_end_variation)); actions.add(GOTO_END_VAR);
@@ -2721,6 +2764,9 @@ public class DroidFish extends Activity implements GUIInterface {
if ((currFT != FT_NONE) && !gameMode.clocksActive()) {
lst.add(getString(R.string.load_next_game)); actions.add(LOAD_NEXT_GAME);
}
+ if (!gameMode.clocksActive()) {
+ lst.add(getString(R.string.auto_forward)); actions.add(AUTO_FORWARD);
+ }
final List finalActions = actions;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.go_forward);
@@ -2748,6 +2794,9 @@ public class DroidFish extends Activity implements GUIInterface {
startActivityForResult(i, RESULT_LOAD_FEN);
}
break;
+ case AUTO_FORWARD:
+ setAutoMode(AutoMode.FORWARD);
+ break;
}
}
});
@@ -3089,6 +3138,7 @@ public class DroidFish extends Activity implements GUIInterface {
/** Open a load/save file dialog. Uses OI file manager if available. */
private void selectFile(int titleMsg, int buttonMsg, String settingsName, String defaultDir,
int dialog, int result) {
+ setAutoMode(AutoMode.OFF);
String action = "org.openintents.action.PICK_FILE";
Intent i = new Intent(action);
String currentFile = settings.getString(settingsName, "");
@@ -3116,6 +3166,7 @@ public class DroidFish extends Activity implements GUIInterface {
}
private final void selectScidFile() {
+ setAutoMode(AutoMode.OFF);
Intent intent = new Intent();
intent.setComponent(new ComponentName("org.scid.android",
"org.scid.android.SelectFileActivity"));
@@ -3386,6 +3437,48 @@ public class DroidFish extends Activity implements GUIInterface {
handlerTimer.postDelayed(r, nextUpdate);
}
+ private Handler autoModeTimer = new Handler();
+ private Runnable amRunnable = new Runnable() {
+ @Override
+ public void run() {
+ switch (autoMode) {
+ case BACKWARD:
+ ctrl.undoMove();
+ setAutoMode(autoMode);
+ break;
+ case FORWARD:
+ ctrl.redoMove();
+ setAutoMode(autoMode);
+ break;
+ case OFF:
+ break;
+ }
+ }
+ };
+
+ /** Set automatic move forward/backward mode. */
+ void setAutoMode(AutoMode am) {
+// System.out.printf("%.3f DroidFish.setAutoMode(): %s\n",
+// System.currentTimeMillis() * 1e-3, am.toString());
+ autoMode = am;
+ switch (am) {
+ case BACKWARD:
+ case FORWARD:
+ if (autoMoveDelay > 0)
+ autoModeTimer.postDelayed(amRunnable, autoMoveDelay);
+ break;
+ case OFF:
+ autoModeTimer.removeCallbacks(amRunnable);
+ break;
+ }
+ }
+
+ /** Disable automatic move mode if clocks are active. */
+ void maybeAutoModeOff(GameMode gm) {
+ if (gm.clocksActive())
+ setAutoMode(AutoMode.OFF);
+ }
+
/** PngTokenReceiver implementation that renders PGN data for screen display. */
static class PgnScreenText implements PgnToken.PgnTokenReceiver {
private SpannableStringBuilder sb = new SpannableStringBuilder();
@@ -3397,6 +3490,7 @@ public class DroidFish extends Activity implements GUIInterface {
int currPos = 0, endPos = 0;
boolean upToDate = false;
PGNOptions options;
+ DroidFish df;
private static class NodeInfo {
int l0, l1;
@@ -3407,7 +3501,8 @@ public class DroidFish extends Activity implements GUIInterface {
}
HashMap nodeToCharPos;
- PgnScreenText(PGNOptions options) {
+ PgnScreenText(DroidFish df, PGNOptions options) {
+ this.df = df;
nodeToCharPos = new HashMap();
this.options = options;
}
@@ -3452,7 +3547,7 @@ public class DroidFish extends Activity implements GUIInterface {
boolean pendingNewLine = false;
/** Makes moves in the move list clickable. */
- private final static class MoveLink extends ClickableSpan {
+ private final class MoveLink extends ClickableSpan {
private Node node;
MoveLink(Node n) {
node = n;
@@ -3464,8 +3559,10 @@ public class DroidFish extends Activity implements GUIInterface {
// even when you long click the move list. The test
// below works around the problem.
Dialog mlmd = moveListMenuDlg;
- if ((mlmd == null) || !mlmd.isShowing())
+ if ((mlmd == null) || !mlmd.isShowing()) {
+ df.setAutoMode(AutoMode.OFF);
ctrl.goNode(node);
+ }
}
}
@Override