mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-04-22 12:02:47 +02:00
DroidFish: Handled PGN file intents with more than one game.
This commit is contained in:
parent
1de1e05025
commit
eba354ea8f
@ -147,7 +147,7 @@ public class DroidFish extends Activity implements GUIInterface {
|
|||||||
// FIXME!!! Option to display coordinates in border outside chess board.
|
// FIXME!!! Option to display coordinates in border outside chess board.
|
||||||
|
|
||||||
// FIXME!!! Better behavior if engine is terminated. How exactly?
|
// FIXME!!! Better behavior if engine is terminated. How exactly?
|
||||||
// FIXME!!! Handle PGN intents with more than one game.
|
// FIXME!!! Handle PGN non-file intents with more than one game.
|
||||||
// FIXME!!! File load/save of FEN data
|
// FIXME!!! File load/save of FEN data
|
||||||
// FIXME!!! Make engine hash size configurable.
|
// FIXME!!! Make engine hash size configurable.
|
||||||
|
|
||||||
@ -321,7 +321,9 @@ public class DroidFish extends Activity implements GUIInterface {
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
String pgn = getPgnIntent();
|
Pair<String,String> pair = getPgnIntent();
|
||||||
|
String intentPgn = pair.first;
|
||||||
|
String intentFilename = pair.second;
|
||||||
|
|
||||||
createDirectories();
|
createDirectories();
|
||||||
|
|
||||||
@ -371,12 +373,14 @@ public class DroidFish extends Activity implements GUIInterface {
|
|||||||
ctrl.setGuiPaused(true);
|
ctrl.setGuiPaused(true);
|
||||||
ctrl.setGuiPaused(false);
|
ctrl.setGuiPaused(false);
|
||||||
ctrl.startGame();
|
ctrl.startGame();
|
||||||
if (pgn != null) {
|
if (intentPgn != null) {
|
||||||
try {
|
try {
|
||||||
ctrl.setFENOrPGN(pgn);
|
ctrl.setFENOrPGN(intentPgn);
|
||||||
setBoardFlip(true);
|
setBoardFlip(true);
|
||||||
} catch (ChessParseError e) {
|
} catch (ChessParseError e) {
|
||||||
}
|
}
|
||||||
|
} else if (intentFilename != null) {
|
||||||
|
loadPGNFromFile(intentFilename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -390,13 +394,26 @@ public class DroidFish extends Activity implements GUIInterface {
|
|||||||
new File(extDir + sep + gtbDefaultDir).mkdirs();
|
new File(extDir + sep + gtbDefaultDir).mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String getPgnIntent() {
|
/**
|
||||||
|
* Return PGN data or filename from the Intent. Both can not be non-null.
|
||||||
|
* @return Pair of pgndata and filename.
|
||||||
|
*/
|
||||||
|
private final Pair<String,String> getPgnIntent() {
|
||||||
String pgn = null;
|
String pgn = null;
|
||||||
|
String filename = null;
|
||||||
try {
|
try {
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
if (intent.getData() != null) {
|
Uri data = intent.getData();
|
||||||
if ("content".equals(intent.getScheme()) ||
|
if (data != null) {
|
||||||
"file".equals(intent.getScheme())) {
|
String scheme = intent.getScheme();
|
||||||
|
if ("file".equals(scheme)) {
|
||||||
|
filename = data.getEncodedPath();
|
||||||
|
if (filename != null)
|
||||||
|
filename = Uri.decode(filename);
|
||||||
|
}
|
||||||
|
if ((filename == null) &&
|
||||||
|
("content".equals(scheme) ||
|
||||||
|
"file".equals(scheme))) {
|
||||||
ContentResolver resolver = getContentResolver();
|
ContentResolver resolver = getContentResolver();
|
||||||
InputStream in = resolver.openInputStream(intent.getData());
|
InputStream in = resolver.openInputStream(intent.getData());
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
@ -414,7 +431,7 @@ public class DroidFish extends Activity implements GUIInterface {
|
|||||||
Toast.makeText(getApplicationContext(), R.string.failed_to_read_pgn_data,
|
Toast.makeText(getApplicationContext(), R.string.failed_to_read_pgn_data,
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
return pgn;
|
return new Pair<String,String>(pgn,filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final byte[] strToByteArr(String str) {
|
private final byte[] strToByteArr(String str) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user