DroidFish: If DroidFish is started with a FEN intent corresponding to an illegal chess position, go automatically into edit board mode, so the user can correct the position.

This commit is contained in:
Peter Osterlund
2013-01-20 11:10:51 +00:00
parent 1b80487254
commit b297eb1086
2 changed files with 19 additions and 6 deletions

View File

@@ -406,6 +406,13 @@ public class DroidFish extends Activity implements GUIInterface {
ctrl.setFENOrPGN(intentPgnOrFen);
setBoardFlip(true);
} catch (ChessParseError e) {
// If FEN corresponds to illegal chess position, go into edit board mode.
try {
TextIO.readFEN(intentPgnOrFen);
} catch (ChessParseError e2) {
if (e2.pos != null)
startEditBoard(intentPgnOrFen);
}
}
} else if (intentFilename != null) {
loadPGNFromFile(intentFilename);
@@ -1160,9 +1167,7 @@ public class DroidFish extends Activity implements GUIInterface {
showDialog(NEW_GAME_DIALOG);
return true;
case R.id.item_editboard: {
Intent i = new Intent(DroidFish.this, EditBoard.class);
i.setAction(ctrl.getFEN());
startActivityForResult(i, RESULT_EDITBOARD);
startEditBoard(ctrl.getFEN());
return true;
}
case R.id.item_settings: {
@@ -1216,6 +1221,12 @@ public class DroidFish extends Activity implements GUIInterface {
return false;
}
private void startEditBoard(String fen) {
Intent i = new Intent(DroidFish.this, EditBoard.class);
i.setAction(fen);
startActivityForResult(i, RESULT_EDITBOARD);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {

View File

@@ -90,13 +90,15 @@ public class EditBoard extends Activity {
Util.setFullScreenMode(this, settings);
Intent i = getIntent();
Position pos;
Position pos = null;
try {
pos = TextIO.readFEN(i.getAction());
cb.setPosition(pos);
checkValidAndUpdateMaterialDiff();
} catch (ChessParseError e) {
pos = e.pos;
}
if (pos != null)
cb.setPosition(pos);
checkValidAndUpdateMaterialDiff();
}
@Override