mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-27 07:58:49 +01:00
complete the work of handling an incoming intent sent via a
new-game-invite URI. Seems to work, but requires two devices to test.
This commit is contained in:
parent
249402758a
commit
d407880dc1
5 changed files with 93 additions and 31 deletions
|
@ -296,6 +296,33 @@ public class DBUtils {
|
|||
return flags;
|
||||
}
|
||||
|
||||
public static String getPathFor( Context context, String room,
|
||||
int lang, int nPlayers )
|
||||
{
|
||||
String result = null;
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||
String[] columns = { DBHelper.FILE_NAME };
|
||||
String selection =
|
||||
String.format( "%s = '%s' AND %s = %d AND %s = %d",
|
||||
DBHelper.ROOMNAME, room,
|
||||
DBHelper.DICTLANG, lang,
|
||||
DBHelper.NUM_PLAYERS, nPlayers );
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||
selection, null, null, null, null );
|
||||
if ( 1 == cursor.getCount() && cursor.moveToFirst() ) {
|
||||
result = cursor.getString( cursor
|
||||
.getColumnIndex(DBHelper.FILE_NAME));
|
||||
|
||||
}
|
||||
cursor.close();
|
||||
db.close();
|
||||
}
|
||||
Utils.logf( "getPathFor(%s)=>%s", room, result );
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getPathFor( Context context, String relayID )
|
||||
{
|
||||
String result = null;
|
||||
|
|
|
@ -339,6 +339,40 @@ public class GameUtils {
|
|||
return lock;
|
||||
}
|
||||
|
||||
public static String saveNew( Context context, CurGameInfo gi )
|
||||
{
|
||||
String path = null;
|
||||
byte[] bytes = XwJNI.gi_to_stream( gi );
|
||||
if ( null != bytes ) {
|
||||
GameLock lock = saveGame( context, bytes );
|
||||
path = lock.getPath();
|
||||
lock.unlock();
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
public static String makeNewNetGame( Context context, String room,
|
||||
int[] lang, int nPlayers )
|
||||
{
|
||||
CommsAddrRec addr = new CommsAddrRec( context );
|
||||
addr.ip_relay_invite = room;
|
||||
|
||||
CurGameInfo gi = new CurGameInfo( context, true );
|
||||
gi.setLang( lang[0] );
|
||||
lang[0] = gi.dictLang;
|
||||
gi.juggle();
|
||||
// Will need to add a setNPlayers() method to gi to make this
|
||||
// work
|
||||
Assert.assertTrue( gi.nPlayers == nPlayers );
|
||||
String path = saveNew( context, gi );
|
||||
|
||||
GameLock lock = new GameLock( path, true ).lock();
|
||||
applyChanges( context, gi, addr, lock, false );
|
||||
lock.unlock();
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public static boolean gameDictsHere( Context context, String path )
|
||||
{
|
||||
return gameDictsHere( context, path, null, null );
|
||||
|
|
|
@ -210,7 +210,7 @@ public class GamesList extends XWListActivity
|
|||
|
||||
Intent intent = getIntent();
|
||||
startFirstHasDict( intent );
|
||||
startNewGameIf( intent );
|
||||
startNewNetGameIf( intent );
|
||||
|
||||
DBUtils.setDBChangeListener( this );
|
||||
} // onCreate
|
||||
|
@ -536,7 +536,7 @@ public class GamesList extends XWListActivity
|
|||
}
|
||||
}
|
||||
|
||||
private void startNewGameIf( Intent intent )
|
||||
private void startNewNetGameIf( Intent intent )
|
||||
{
|
||||
if ( null != intent ) {
|
||||
Uri data = intent.getData();
|
||||
|
@ -544,7 +544,24 @@ public class GamesList extends XWListActivity
|
|||
String room = data.getQueryParameter( "room" );
|
||||
String langStr = data.getQueryParameter( "lang" );
|
||||
int lang = Integer.decode( langStr );
|
||||
int nPlayers = 2; // Should this be a param?
|
||||
Utils.logf( "got data: lang: %d; room: %s", lang, room );
|
||||
|
||||
// Find out if the game already exists. If it does,
|
||||
// just open it. Otherwise create a new one and open
|
||||
// that. NOTE: this test makes it impossible to start
|
||||
// two halves of the same game on one device using
|
||||
// this feature. But it'd be worse to have a bunch of
|
||||
// games stacking up when somebody taps the same URL
|
||||
// multiple times.
|
||||
String path = DBUtils.getPathFor( this, room, lang, nPlayers );
|
||||
|
||||
if ( null == path ) {
|
||||
path = GameUtils.makeNewNetGame( this, room, lang,
|
||||
nPlayers );
|
||||
}
|
||||
|
||||
GameUtils.launchGame( this, path );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,21 +79,9 @@ public class NewGameActivity extends XWActivity {
|
|||
|
||||
}
|
||||
|
||||
private String saveNew( CurGameInfo gi )
|
||||
{
|
||||
String path = null;
|
||||
byte[] bytes = XwJNI.gi_to_stream( gi );
|
||||
if ( null != bytes ) {
|
||||
GameUtils.GameLock lock = GameUtils.saveGame( this, bytes );
|
||||
path = lock.getPath();
|
||||
lock.unlock();
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
private void newAndLaunch()
|
||||
{
|
||||
String path = saveNew( new CurGameInfo( this ) );
|
||||
String path = GameUtils.saveNew( this, new CurGameInfo( this ) );
|
||||
GameUtils.launchGame( this, path );
|
||||
finish();
|
||||
}
|
||||
|
@ -102,24 +90,17 @@ public class NewGameActivity extends XWActivity {
|
|||
// providing defaults.
|
||||
private void newNetworkedAndLaunch()
|
||||
{
|
||||
CommsAddrRec addr = new CommsAddrRec( this );
|
||||
Random random = new Random();
|
||||
addr.ip_relay_invite = String.format( "%X", random.nextInt() );
|
||||
Utils.logf( "room: %s", addr.ip_relay_invite );
|
||||
|
||||
CurGameInfo gi = new CurGameInfo( this, true );
|
||||
String path = saveNew( gi );
|
||||
|
||||
GameUtils.GameLock lock =
|
||||
new GameUtils.GameLock( path, true ).lock();
|
||||
GameUtils.applyChanges( this, gi, addr, lock, false );
|
||||
lock.unlock();
|
||||
String room = String.format( "%X", random.nextInt() );
|
||||
int[] lang = new int[1];
|
||||
lang[0] = 0;
|
||||
String path = GameUtils.makeNewNetGame( this, room, lang, 2 );
|
||||
|
||||
Intent intent = new Intent( Intent.ACTION_SEND );
|
||||
intent.setType( "plain/text" );
|
||||
intent.putExtra( Intent.EXTRA_SUBJECT, "Let's play Crosswords" );
|
||||
intent.putExtra( Intent.EXTRA_TEXT,
|
||||
mkMsgWithLink( addr.ip_relay_invite, gi.dictLang ) );
|
||||
mkMsgWithLink( room, lang[0] ) );
|
||||
|
||||
GameUtils.launchGame( this, path );
|
||||
|
||||
|
@ -139,7 +120,8 @@ public class NewGameActivity extends XWActivity {
|
|||
|
||||
private void newAndConfigure( boolean networked )
|
||||
{
|
||||
String path = saveNew( new CurGameInfo( this, networked ) );
|
||||
String path = GameUtils.saveNew( this, new CurGameInfo( this,
|
||||
networked ) );
|
||||
GameUtils.doConfig( this, path, GameConfig.class );
|
||||
finish();
|
||||
}
|
||||
|
|
|
@ -76,8 +76,6 @@ public class CurGameInfo {
|
|||
players = new LocalPlayer[MAX_NUM_PLAYERS];
|
||||
serverRole = isNetworked ? DeviceRole.SERVER_ISCLIENT
|
||||
: DeviceRole.SERVER_STANDALONE;
|
||||
dictName = CommonPrefs.getDefaultHumanDict( context );
|
||||
dictLang = DictLangCache.getDictLangCode( context, dictName );
|
||||
hintsNotAllowed = !CommonPrefs.getDefaultHintsAllowed( context );
|
||||
phoniesAction = CommonPrefs.getDefaultPhonies( context );
|
||||
timerEnabled = CommonPrefs.getDefaultTimerEnabled( context );
|
||||
|
@ -97,7 +95,7 @@ public class CurGameInfo {
|
|||
players[0].setRobotSmartness( 1 );
|
||||
}
|
||||
|
||||
assignDicts();
|
||||
setLang( 0 );
|
||||
}
|
||||
|
||||
public CurGameInfo( Context context, CurGameInfo src )
|
||||
|
@ -141,6 +139,10 @@ public class CurGameInfo {
|
|||
|
||||
public void setLang( int lang )
|
||||
{
|
||||
if ( 0 == lang ) {
|
||||
String dictName = CommonPrefs.getDefaultHumanDict( m_context );
|
||||
lang = DictLangCache.getDictLangCode( m_context, dictName );
|
||||
}
|
||||
if ( dictLang != lang ) {
|
||||
dictLang = lang;
|
||||
assignDicts();
|
||||
|
|
Loading…
Add table
Reference in a new issue