DroidFish: Added support for intent type SEND with mime type application/x-chess-fen.

This commit is contained in:
Peter Osterlund 2013-01-20 08:54:20 +00:00
parent 97ebf52b9a
commit c3be2de8f3
2 changed files with 18 additions and 12 deletions

View File

@ -32,6 +32,11 @@
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/x-chess-pgn" /> <data android:mimeType="application/x-chess-pgn" />
</intent-filter> </intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/x-chess-fen" />
</intent-filter>
</activity> </activity>
<activity android:name=".activities.Preferences" <activity android:name=".activities.Preferences"
android:label="@string/preferences"> android:label="@string/preferences">

View File

@ -347,8 +347,8 @@ public class DroidFish extends Activity implements GUIInterface {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Pair<String,String> pair = getPgnIntent(); Pair<String,String> pair = getPgnOrFenIntent();
String intentPgn = pair.first; String intentPgnOrFen = pair.first;
String intentFilename = pair.second; String intentFilename = pair.second;
createDirectories(); createDirectories();
@ -401,9 +401,9 @@ public class DroidFish extends Activity implements GUIInterface {
ctrl.setGuiPaused(true); ctrl.setGuiPaused(true);
ctrl.setGuiPaused(false); ctrl.setGuiPaused(false);
ctrl.startGame(); ctrl.startGame();
if (intentPgn != null) { if (intentPgnOrFen != null) {
try { try {
ctrl.setFENOrPGN(intentPgn); ctrl.setFENOrPGN(intentPgnOrFen);
setBoardFlip(true); setBoardFlip(true);
} catch (ChessParseError e) { } catch (ChessParseError e) {
} }
@ -439,19 +439,20 @@ public class DroidFish extends Activity implements GUIInterface {
} }
/** /**
* Return PGN data or filename from the Intent. Both can not be non-null. * Return PGN/FEN data or filename from the Intent. Both can not be non-null.
* @return Pair of pgndata and filename. * @return Pair of PGN/FEN data and filename.
*/ */
private final Pair<String,String> getPgnIntent() { private final Pair<String,String> getPgnOrFenIntent() {
String pgn = null; String pgnOrFen = null;
String filename = null; String filename = null;
try { try {
Intent intent = getIntent(); Intent intent = getIntent();
Uri data = intent.getData(); Uri data = intent.getData();
if (data == null) { if (data == null) {
if (Intent.ACTION_SEND.equals(intent.getAction()) && if (Intent.ACTION_SEND.equals(intent.getAction()) &&
"application/x-chess-pgn".equals(intent.getType())) ("application/x-chess-pgn".equals(intent.getType()) ||
pgn = intent.getStringExtra(Intent.EXTRA_TEXT); "application/x-chess-fen".equals(intent.getType())))
pgnOrFen = intent.getStringExtra(Intent.EXTRA_TEXT);
} else { } else {
String scheme = intent.getScheme(); String scheme = intent.getScheme();
if ("file".equals(scheme)) { if ("file".equals(scheme)) {
@ -472,14 +473,14 @@ public class DroidFish extends Activity implements GUIInterface {
break; break;
sb.append(new String(buffer, 0, len)); sb.append(new String(buffer, 0, len));
} }
pgn = sb.toString(); pgnOrFen = sb.toString();
} }
} }
} catch (IOException e) { } catch (IOException e) {
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 new Pair<String,String>(pgn,filename); return new Pair<String,String>(pgnOrFen,filename);
} }
private final byte[] strToByteArr(String str) { private final byte[] strToByteArr(String str) {