mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-15 15:41:24 +01:00
add game name as something passed with invitation. Later will get it
from user. Idea is to make it easy to identify the games in GamesList on two devices side-by-side.
This commit is contained in:
parent
43dca99a2c
commit
f40f2bffcf
3 changed files with 46 additions and 18 deletions
|
@ -73,6 +73,7 @@ public class BTService extends Service {
|
|||
private static final String CMD_STR = "CMD";
|
||||
private static final String MSG_STR = "MSG";
|
||||
private static final String TARGET_STR = "TRG";
|
||||
private static final String GAMENAME_STR = "NAM";
|
||||
private static final String ADDR_STR = "ADR";
|
||||
private static final String RADIO_STR = "RDO";
|
||||
|
||||
|
@ -93,6 +94,7 @@ public class BTService extends Service {
|
|||
INVITE_ACCPT,
|
||||
INVITE_DECL,
|
||||
INVITE_DUPID,
|
||||
INVITE_FAILED, // generic error
|
||||
MESG_SEND,
|
||||
MESG_ACCPT,
|
||||
MESG_DECL,
|
||||
|
@ -105,6 +107,7 @@ public class BTService extends Service {
|
|||
byte[] m_msg;
|
||||
String m_recipient;
|
||||
String m_addr;
|
||||
String m_gameName;
|
||||
int m_gameID;
|
||||
int m_lang;
|
||||
int m_nPlayersT;
|
||||
|
@ -112,10 +115,11 @@ public class BTService extends Service {
|
|||
|
||||
public BTQueueElem( BTCmd cmd ) { m_cmd = cmd; }
|
||||
public BTQueueElem( BTCmd cmd, String targetName, String targetAddr,
|
||||
int gameID, int lang, int nPlayersT,
|
||||
int nPlayersH ) {
|
||||
int gameID, String gameName, int lang,
|
||||
int nPlayersT, int nPlayersH ) {
|
||||
this( cmd, null, targetName, targetAddr, gameID );
|
||||
m_lang = lang; m_nPlayersT = nPlayersT; m_nPlayersH = nPlayersH;
|
||||
m_gameName = gameName;
|
||||
}
|
||||
public BTQueueElem( BTCmd cmd, byte[] buf, String targetName,
|
||||
String targetAddr, int gameID ) {
|
||||
|
@ -168,12 +172,15 @@ public class BTService extends Service {
|
|||
}
|
||||
|
||||
public static void inviteRemote( Context context, String hostName,
|
||||
int gameID, int lang, int nPlayersT,
|
||||
int gameID, String initialName,
|
||||
int lang, int nPlayersT,
|
||||
int nPlayersH )
|
||||
{
|
||||
Intent intent = getIntentTo( context, INVITE );
|
||||
intent.putExtra( GAMEID_STR, gameID );
|
||||
intent.putExtra( TARGET_STR, hostName );
|
||||
Assert.assertNotNull( initialName );
|
||||
intent.putExtra( GAMENAME_STR, initialName );
|
||||
intent.putExtra( LANG_STR, lang );
|
||||
intent.putExtra( NTO_STR, nPlayersT );
|
||||
intent.putExtra( NHE_STR, nPlayersH );
|
||||
|
@ -242,12 +249,13 @@ public class BTService extends Service {
|
|||
case INVITE:
|
||||
int gameID = intent.getIntExtra( GAMEID_STR, -1 );
|
||||
String target = intent.getStringExtra( TARGET_STR );
|
||||
String gameName = intent.getStringExtra( GAMENAME_STR );
|
||||
String addr = addrFor( target );
|
||||
int lang = intent.getIntExtra( LANG_STR, -1 );
|
||||
int nPlayersT = intent.getIntExtra( NTO_STR, -1 );
|
||||
int nPlayersH = intent.getIntExtra( NHE_STR, -1 );
|
||||
m_sender.add( new BTQueueElem( BTCmd.INVITE, target, addr,
|
||||
gameID, lang,
|
||||
gameID, gameName, lang,
|
||||
nPlayersT, nPlayersH ) );
|
||||
break;
|
||||
case SEND:
|
||||
|
@ -255,6 +263,7 @@ public class BTService extends Service {
|
|||
target = intent.getStringExtra( TARGET_STR );
|
||||
addr = intent.getStringExtra( ADDR_STR );
|
||||
gameID = intent.getIntExtra( GAMEID_STR, -1 );
|
||||
addAddr( target, addr );
|
||||
if ( -1 != gameID ) {
|
||||
m_sender.add( new BTQueueElem( BTCmd.MESG_SEND, buf,
|
||||
target, addr, gameID ) );
|
||||
|
@ -414,6 +423,7 @@ public class BTService extends Service {
|
|||
DataOutputStream outStream = connect( socket, BTCmd.INVITE );
|
||||
if ( null != outStream ) {
|
||||
outStream.writeInt( elem.m_gameID );
|
||||
outStream.writeUTF( elem.m_gameName );
|
||||
outStream.writeInt( elem.m_lang );
|
||||
outStream.writeInt( elem.m_nPlayersT );
|
||||
outStream.writeInt( elem.m_nPlayersH );
|
||||
|
@ -487,9 +497,14 @@ public class BTService extends Service {
|
|||
}
|
||||
|
||||
private void addAddr( BluetoothDevice dev )
|
||||
{
|
||||
addAddr( dev.getName(), dev.getAddress() );
|
||||
}
|
||||
|
||||
private void addAddr( String name, String address )
|
||||
{
|
||||
synchronized( s_names ) {
|
||||
s_names.put( dev.getName(), dev.getAddress() );
|
||||
s_names.put( name, address );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -590,7 +605,7 @@ public class BTService extends Service {
|
|||
{
|
||||
BTCmd result;
|
||||
int gameID = is.readInt();
|
||||
DbgUtils.logf( "receiveInvitation: got gameID of %d", gameID );
|
||||
String gameName = is.readUTF();
|
||||
int lang = is.readInt();
|
||||
int nPlayersT = is.readInt();
|
||||
int nPlayersH = is.readInt();
|
||||
|
@ -602,12 +617,18 @@ public class BTService extends Service {
|
|||
String sender = host.getName();
|
||||
CommsAddrRec addr = new CommsAddrRec( context, sender,
|
||||
host.getAddress() );
|
||||
GameUtils.makeNewBTGame( context, gameID, addr,
|
||||
lang, nPlayersT, nPlayersH );
|
||||
result = BTCmd.INVITE_ACCPT;
|
||||
|
||||
String body = Utils.format( this, R.string.new_bt_bodyf, sender );
|
||||
postNotification( gameID, R.string.new_bt_title, body );
|
||||
long rowid = GameUtils.makeNewBTGame( context, gameID, addr,
|
||||
lang, nPlayersT, nPlayersH );
|
||||
if ( DBUtils.ROWID_NOTFOUND == rowid ) {
|
||||
result = BTCmd.INVITE_FAILED;
|
||||
} else {
|
||||
if ( null != gameName && 0 < gameName.length() ) {
|
||||
DBUtils.setName( context, rowid, gameName );
|
||||
}
|
||||
result = BTCmd.INVITE_ACCPT;
|
||||
String body = Utils.format( this, R.string.new_bt_bodyf, sender );
|
||||
postNotification( gameID, R.string.new_bt_title, body );
|
||||
}
|
||||
} else {
|
||||
result = BTCmd.INVITE_DUPID;
|
||||
}
|
||||
|
@ -804,8 +825,8 @@ public class BTService extends Service {
|
|||
{
|
||||
Assert.assertNotNull( addr );
|
||||
m_sender.add( new BTQueueElem( BTCmd.MESG_SEND, buf,
|
||||
addr.bt_hostName, addr.bt_btAddr,
|
||||
gameID ) );
|
||||
addr.bt_hostName, addr.bt_btAddr,
|
||||
gameID ) );
|
||||
return buf.length;
|
||||
}
|
||||
|
||||
|
|
|
@ -1696,10 +1696,11 @@ public class BoardActivity extends XWActivity
|
|||
private void tryBTInvites()
|
||||
{
|
||||
if ( null != m_btDevs ) {
|
||||
String gameName = DBUtils.getName( this, m_rowid );
|
||||
m_invitesPending = m_btDevs.length;
|
||||
for ( String dev : m_btDevs ) {
|
||||
BTService.inviteRemote( this, dev, m_gi.gameID, m_gi.dictLang,
|
||||
m_gi.nPlayers, 1 );
|
||||
BTService.inviteRemote( this, dev, m_gi.gameID, gameName,
|
||||
m_gi.dictLang, m_gi.nPlayers, 1 );
|
||||
}
|
||||
startProgress( R.string.invite_progress );
|
||||
m_btDevs = null;
|
||||
|
|
|
@ -56,6 +56,7 @@ public class NewGameActivity extends XWActivity {
|
|||
private int m_chosen;
|
||||
private int m_lang = 0;
|
||||
private long m_btRowID = -1;
|
||||
private String m_gameName;
|
||||
|
||||
@Override
|
||||
protected void onCreate( Bundle savedInstanceState )
|
||||
|
@ -147,11 +148,14 @@ public class NewGameActivity extends XWActivity {
|
|||
case INVITE_FOR_BT: // user selected device
|
||||
if ( Activity.RESULT_CANCELED != resultCode ) {
|
||||
int gameID = GameUtils.newGameID();
|
||||
// TODO: get this from user.
|
||||
m_gameName = String.format( "BT Game %X", gameID );
|
||||
String[] remoteDevs =
|
||||
data.getStringArrayExtra( BTInviteActivity.DEVS );
|
||||
DbgUtils.logf( "got %s", remoteDevs[0] );
|
||||
Assert.assertTrue( 1 == remoteDevs.length );
|
||||
BTService.inviteRemote( NewGameActivity.this, remoteDevs[0],
|
||||
gameID, m_lang, 2, 1 );
|
||||
gameID, m_gameName, m_lang, 2, 1 );
|
||||
startProgress( R.string.invite_progress );
|
||||
}
|
||||
break;
|
||||
|
@ -189,6 +193,8 @@ public class NewGameActivity extends XWActivity {
|
|||
GameUtils.makeNewBTGame( NewGameActivity.this,
|
||||
gameID, null, m_lang,
|
||||
2, 1 );
|
||||
DBUtils.setName( NewGameActivity.this,
|
||||
rowid, m_gameName );
|
||||
GameUtils.launchGame( NewGameActivity.this, rowid );
|
||||
finish();
|
||||
}
|
||||
|
@ -247,7 +253,7 @@ public class NewGameActivity extends XWActivity {
|
|||
if ( !useDefaults ) {
|
||||
m_btRowID = GameUtils.makeNewBTGame( NewGameActivity.this,
|
||||
gameID, null, m_lang,
|
||||
2, 1 );
|
||||
2, 1 ); // initial defaults
|
||||
Intent intent = new Intent( this, GameConfig.class );
|
||||
intent.setAction( Intent.ACTION_EDIT );
|
||||
intent.putExtra( GameUtils.INTENT_KEY_ROWID, m_btRowID );
|
||||
|
|
Loading…
Reference in a new issue