snapshot: invite by BT now works well enough that moves can be

exchanged. Haven't checked whether the relay's also seeing traffic.
This commit is contained in:
Eric House 2014-11-14 07:12:03 -08:00
parent 1d1af9ffb3
commit 15e380291b
10 changed files with 261 additions and 224 deletions

View file

@ -77,6 +77,7 @@ public class BTService extends XWService {
private static final String CLEAR_STR = "CLR";
private static final String GAMEID_STR = "GMI";
private static final String GAMEDATA_STR = "GD";
private static final String LANG_STR = "LNG";
private static final String DICT_STR = "DCT";
@ -114,15 +115,16 @@ public class BTService extends XWService {
String m_dict;
int m_nPlayersT;
int m_nPlayersH;
NetLaunchInfo m_nli;
public BTQueueElem( BTCmd cmd ) { m_cmd = cmd; m_failCount = 0; }
public BTQueueElem( BTCmd cmd, String btAddr,
int gameID, String gameName, int lang,
String dict, int nPlayersT, int nPlayersH ) {
this( cmd, null, btAddr, gameID );
m_lang = lang; m_dict = dict; m_nPlayersT = nPlayersT;
m_nPlayersH = nPlayersH; m_gameName = gameName;
}
// public BTQueueElem( BTCmd cmd, String btAddr,
// int gameID, String gameName, int lang,
// String dict, int nPlayersT, int nPlayersH ) {
// this( cmd, null, btAddr, gameID );
// m_lang = lang; m_dict = dict; m_nPlayersT = nPlayersT;
// m_nPlayersH = nPlayersH; m_gameName = gameName;
// }
public BTQueueElem( BTCmd cmd, byte[] buf, String btAddr, int gameID ) {
this( cmd );
Assert.assertTrue( null != btAddr && 0 < btAddr.length() );
@ -136,6 +138,12 @@ public class BTService extends XWService {
m_gameID = gameID;
}
public BTQueueElem( BTCmd cmd, NetLaunchInfo nli, String btAddr ) {
this( cmd );
m_nli = nli;
m_btAddr = btAddr;
}
public int incrFailCount() { return ++m_failCount; }
public boolean failCountExceeded() { return m_failCount >= MAX_SEND_FAIL; }
}
@ -234,19 +242,30 @@ public class BTService extends XWService {
context.startService( intent );
}
// public static void inviteRemote( Context context, String btAddr,
// int gameID, String initialName, int lang,
// String dict, int nPlayersT, int nPlayersH )
// {
// Intent intent = getIntentTo( context, INVITE );
// intent.putExtra( GAMEID_STR, gameID );
// intent.putExtra( ADDR_STR, btAddr );
// Assert.assertNotNull( initialName );
// intent.putExtra( GAMENAME_STR, initialName );
// intent.putExtra( LANG_STR, lang );
// intent.putExtra( DICT_STR, dict );
// intent.putExtra( NTO_STR, nPlayersT );
// intent.putExtra( NHE_STR, nPlayersH );
// context.startService( intent );
// }
public static void inviteRemote( Context context, String btAddr,
int gameID, String initialName, int lang,
String dict, int nPlayersT, int nPlayersH )
NetLaunchInfo nli )
{
Intent intent = getIntentTo( context, INVITE );
intent.putExtra( GAMEID_STR, gameID );
String nliData = nli.toString();
intent.putExtra( GAMEDATA_STR, nliData );
intent.putExtra( ADDR_STR, btAddr );
Assert.assertNotNull( initialName );
intent.putExtra( GAMENAME_STR, initialName );
intent.putExtra( LANG_STR, lang );
intent.putExtra( DICT_STR, dict );
intent.putExtra( NTO_STR, nPlayersT );
intent.putExtra( NHE_STR, nPlayersH );
context.startService( intent );
}
@ -337,33 +356,35 @@ public class BTService extends XWService {
m_sender.add( new BTQueueElem( BTCmd.SCAN ) );
break;
case INVITE:
int gameID = intent.getIntExtra( GAMEID_STR, -1 );
String jsonData = intent.getStringExtra( GAMEDATA_STR );
NetLaunchInfo nli = new NetLaunchInfo( jsonData );
DbgUtils.logf( "onStartCommand: nli: %s", nli.toString() );
// int gameID = intent.getIntExtra( GAMEID_STR, -1 );
// String btAddr = intent.getStringExtra( ADDR_STR );
// String gameName = intent.getStringExtra( GAMENAME_STR );
// int lang = intent.getIntExtra( LANG_STR, -1 );
// String dict = intent.getStringExtra( DICT_STR );
// int nPlayersT = intent.getIntExtra( NTO_STR, -1 );
String btAddr = intent.getStringExtra( ADDR_STR );
String gameName = intent.getStringExtra( GAMENAME_STR );
int lang = intent.getIntExtra( LANG_STR, -1 );
String dict = intent.getStringExtra( DICT_STR );
int nPlayersT = intent.getIntExtra( NTO_STR, -1 );
int nPlayersH = intent.getIntExtra( NHE_STR, -1 );
m_sender.add( new BTQueueElem( BTCmd.INVITE, btAddr,
gameID, gameName, lang,
dict, nPlayersT, nPlayersH ) );
m_sender.add( new BTQueueElem( BTCmd.INVITE, nli, btAddr ) );
break;
case PINGHOST:
btAddr = intent.getStringExtra( ADDR_STR );
gameID = intent.getIntExtra( GAMEID_STR, 0 );
int gameID = intent.getIntExtra( GAMEID_STR, 0 );
m_sender.add( new BTQueueElem( BTCmd.PING, btAddr, gameID ) );
break;
case NFCINVITE:
gameID = intent.getIntExtra( GAMEID_STR, -1 );
lang = intent.getIntExtra( LANG_STR, -1 );
dict = intent.getStringExtra( DICT_STR );
nPlayersT = intent.getIntExtra( NTO_STR, -1 );
int lang = intent.getIntExtra( LANG_STR, -1 );
String dict = intent.getStringExtra( DICT_STR );
int nPlayersT = intent.getIntExtra( NTO_STR, -1 );
String btName = intent.getStringExtra( BT_NAME_STR );
btAddr = intent.getStringExtra( BT_ADDRESS_STR );
/*(void)*/makeOrNotify( this, gameID, null, lang, dict,
nPlayersT, 1, btName, btAddr );
// /*(void)*/makeOrNotify( this, gameID, null, lang, dict,
// nPlayersT, 1, btName, btAddr );
Assert.fail();
break;
case SEND:
@ -510,19 +531,20 @@ public class BTService extends XWService {
throws IOException
{
BTCmd result;
int gameID = is.readInt();
String gameName = is.readUTF();
int lang = is.readInt();
String dict = is.readUTF();
int nPlayersT = is.readInt();
int nPlayersH = is.readInt();
String asJson = is.readUTF();
NetLaunchInfo nli = new NetLaunchInfo( asJson );
DbgUtils.logf( "receiveInvitation: nli: %s", nli.toString() );
// int gameID = is.readInt();
// String gameName = is.readUTF();
// int lang = is.readInt();
// String dict = is.readUTF();
// int nPlayersT = is.readInt();
// int nPlayersH = is.readInt();
BluetoothDevice host = socket.getRemoteDevice();
addAddr( host );
result = makeOrNotify( context, gameID, gameName, lang, dict,
nPlayersT, nPlayersH, host.getName(),
host.getAddress() );
result = makeOrNotify( context, nli, host.getName(), host.getAddress() );
DataOutputStream os = new DataOutputStream( socket.getOutputStream() );
os.writeByte( result.ordinal() );
@ -773,12 +795,13 @@ public class BTService extends XWService {
BTCmd reply = null;
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.writeUTF( elem.m_dict );
outStream.writeInt( elem.m_nPlayersT );
outStream.writeInt( elem.m_nPlayersH );
outStream.writeUTF( elem.m_nli.toString() );
// outStream.writeInt( elem.m_gameID );
// outStream.writeUTF( elem.m_gameName );
// outStream.writeInt( elem.m_lang );
// outStream.writeUTF( elem.m_dict );
// outStream.writeInt( elem.m_nPlayersT );
DbgUtils.logf( "<eeh>sending invite for %d players", elem.m_nPlayersH );
outStream.flush();
DataInputStream inStream =
@ -1018,49 +1041,44 @@ public class BTService extends XWService {
m_sender = null;
}
private BTCmd makeOrNotify( Context context, int gameID, String gameName,
int lang, String dict, int nPlayersT,
int nPlayersH, String btName, String btAddr )
private BTCmd makeOrNotify( Context context, NetLaunchInfo nli,
String btName, String btAddr )
{
BTCmd result;
if ( DictLangCache.haveDict( context, lang, dict ) ) {
result = makeGame( context, gameID, gameName, lang, dict,
nPlayersT, nPlayersH, btName, btAddr );
if ( DictLangCache.haveDict( context, nli.lang, nli.dict ) ) {
result = makeGame( context, nli, btName, btAddr );
} else {
Intent intent = MultiService
.makeMissingDictIntent( context, gameName, lang, dict,
nPlayersT, nPlayersH );
Intent intent = MultiService.makeMissingDictIntent( context, nli );
Assert.fail();
// NetLaunchInfo.putExtras( intent, gameID, btName, btAddr );
MultiService.postMissingDictNotification( context, intent,
gameID );
nli.gameID );
result = BTCmd.INVITE_ACCPT; // ???
}
return result;
}
private BTCmd makeGame( Context context, int gameID, String gameName,
int lang, String dict, int nPlayersT, int nPlayersH,
private BTCmd makeGame( Context context, NetLaunchInfo nli,
String sender, String senderAddress )
{
BTCmd result;
long[] rowids = DBUtils.getRowIDsFor( BTService.this, gameID );
long[] rowids = DBUtils.getRowIDsFor( BTService.this, nli.gameID );
if ( null == rowids || 0 == rowids.length ) {
CommsAddrRec addr = new CommsAddrRec( sender, senderAddress );
long rowid = GameUtils.makeNewBTGame( context, m_btMsgSink, gameID,
addr, lang, dict, nPlayersT,
nPlayersH );
long rowid = GameUtils.makeNewGame( context, m_btMsgSink, nli.gameID,
addr, nli.lang, nli.dict, nli.nPlayersT,
nli.nPlayersH );
if ( DBUtils.ROWID_NOTFOUND == rowid ) {
result = BTCmd.INVITE_FAILED;
} else {
if ( null != gameName && 0 < gameName.length() ) {
DBUtils.setName( context, rowid, gameName );
if ( null != nli.gameName && 0 < nli.gameName.length() ) {
DBUtils.setName( context, rowid, nli.gameName );
}
result = BTCmd.INVITE_ACCPT;
String body = LocUtils.getString( BTService.this,
R.string.new_bt_body_fmt,
sender );
postNotification( gameID, R.string.new_bt_title, body, rowid );
postNotification( nli.gameID, R.string.new_bt_title, body, rowid );
sendResult( MultiEvent.BT_GAME_CREATED, rowid );
}
} else {

View file

@ -2245,6 +2245,7 @@ public class BoardDelegate extends DelegateBase
Assert.assertNotNull( m_missingMeans );
String gameName = GameUtils.getName( m_activity, m_rowid );
m_invitesPending = m_missingDevs.length;
NetLaunchInfo nli = new NetLaunchInfo( m_summary, m_gi, 1 );
for ( String dev : m_missingDevs ) {
switch ( m_missingMeans ) {
case BLUETOOTH:
@ -2259,16 +2260,11 @@ public class BoardDelegate extends DelegateBase
}
});
BTService.inviteRemote( m_activity, dev, m_gi.gameID,
gameName, m_gi.dictLang,
m_gi.dictName, m_gi.nPlayers,
1 );
BTService.inviteRemote( m_activity, dev, nli );
break;
case SMS:
SMSService.inviteRemote( m_activity, dev, m_gi.gameID,
gameName, m_gi.dictLang,
m_gi.dictName, m_gi.nPlayers,
1 );
Assert.fail();
// SMSService.inviteRemote( m_activity, dev, nli );
break;
}
}

View file

@ -2137,7 +2137,7 @@ public class DBUtils {
private static final int BIT_VECTOR_MASK = 0x8000;
public static CommsConnTypeSet intToConnTypeSet( int asInt )
{
DbgUtils.logf( "intToConnTypeSet(in: %s)", asInt );
// DbgUtils.logf( "intToConnTypeSet(in: %s)", asInt );
CommsConnTypeSet result = new CommsConnTypeSet();
boolean isVector = 0 != (BIT_VECTOR_MASK & asInt);
asInt &= ~BIT_VECTOR_MASK;
@ -2146,7 +2146,7 @@ public class DBUtils {
for ( CommsConnType value : values ) {
int ord = value.ordinal();
if ( 0 != (asInt & (1 << (ord - 1)))) {
DbgUtils.logf( "intToConnTypeSet: adding %s", value.toString() );
// DbgUtils.logf( "intToConnTypeSet: adding %s", value.toString() );
result.add( value );
}
}
@ -2162,7 +2162,7 @@ public class DBUtils {
int result = BIT_VECTOR_MASK;
for ( Iterator<CommsConnType> iter = set.iterator(); iter.hasNext(); ) {
CommsConnType typ = iter.next();
DbgUtils.logf( "connTypeSetToInt: adding %s", typ.toString() );
// DbgUtils.logf( "connTypeSetToInt: adding %s", typ.toString() );
result |= 1 << (typ.ordinal() - 1);
}
return result;

View file

@ -515,11 +515,26 @@ public class GameUtils {
int nPlayersH )
{
long rowid = -1;
String relayName = XWPrefs.getDefaultRelayHost( context );
int relayPort = XWPrefs.getDefaultRelayPort( context );
CommsAddrRec addr = new CommsAddrRec( relayName, relayPort );
addr.ip_relay_invite = room;
addr.conTypes.add( CommsConnType.COMMS_CONN_BT );
CommsAddrRec addr = new CommsAddrRec();
for ( CommsConnType typ : XWPrefs.getAddrTypes( context ).getTypes() ) {
addr.conTypes.add( typ );
switch( typ ) {
case COMMS_CONN_RELAY:
String name = XWPrefs.getDefaultRelayHost( context );
int port = XWPrefs.getDefaultRelayPort( context );
addr.setRelayParams( name, port, room );
break;
case COMMS_CONN_BT:
// String[] strs = BTService.getBTNameAndAddress();
// addr.bt_hostName = strs[0];
// addr.bt_btAddr = strs[1];
break;
default:
// Assert.fail();
break;
}
}
return makeNewMultiGame( context, groupID, addr, lang, dict,
nPlayersT, nPlayersH, inviteID, 0, true );
@ -542,88 +557,86 @@ public class GameUtils {
info.nPlayersT );
}
public static long makeNewBTGame( Context context, MultiMsgSink sink,
int gameID, CommsAddrRec addr, int lang,
String dict, int nPlayersT,
int nPlayersH )
public static long makeNewGame( Context context, MultiMsgSink sink,
int gameID, CommsAddrRec addr, int lang,
String dict, int nPlayersT,
int nPlayersH )
{
return makeNewBTGame( context, sink, DBUtils.GROUPID_UNSPEC, gameID, addr,
lang, dict, nPlayersT, nPlayersH );
return makeNewGame( context, sink, DBUtils.GROUPID_UNSPEC, gameID, addr,
lang, dict, nPlayersT, nPlayersH );
}
public static long makeNewBTGame( Context context, int gameID,
CommsAddrRec addr, int lang,
String dict, int nPlayersT,
int nPlayersH )
public static long makeNewGame( Context context, int gameID,
CommsAddrRec addr, int lang,
String dict, int nPlayersT,
int nPlayersH )
{
return makeNewBTGame( context, DBUtils.GROUPID_UNSPEC, gameID, addr,
lang, dict, nPlayersT, nPlayersH );
return makeNewGame( context, DBUtils.GROUPID_UNSPEC, gameID, addr,
lang, dict, nPlayersT, nPlayersH );
}
public static long makeNewBTGame( Context context, long groupID, int gameID,
CommsAddrRec addr, int lang, String dict,
int nPlayersT, int nPlayersH )
public static long makeNewGame( Context context, long groupID, int gameID,
CommsAddrRec addr, int lang, String dict,
int nPlayersT, int nPlayersH )
{
return makeNewBTGame( context, null, groupID, gameID, addr,
lang, dict, nPlayersT, nPlayersH );
return makeNewGame( context, null, groupID, gameID, addr,
lang, dict, nPlayersT, nPlayersH );
}
public static long makeNewBTGame( Context context, NetLaunchInfo nli )
{
Assert.fail();
return -1;
// return makeNewBTGame( context, null, DBUtils.GROUPID_UNSPEC, nli.gameID,
// nli.btAddress, nli.lang, nli.dict,
// nli.nPlayersT, 1 );
}
// public static long makeNewBTGame( Context context, NetLaunchInfo nli )
// {
// Assert.fail();
// return -1;
// // return makeNewBTGame( context, null, DBUtils.GROUPID_UNSPEC, nli.gameID,
// // nli.btAddress, nli.lang, nli.dict,
// // nli.nPlayersT, 1 );
// }
public static long makeNewBTGame( Context context, MultiMsgSink sink,
long groupID, int gameID, CommsAddrRec addr,
int lang, String dict,
int nPlayersT, int nPlayersH )
{
Assert.fail();
return -1;
// long rowid = -1;
// int[] langa = { lang };
// String[] dicta = { dict };
// boolean isHost = null == addr;
// if ( isHost ) {
// addr = new CommsAddrRec( null, null );
// }
// String inviteID = GameUtils.formatGameID( gameID );
// return makeNewMultiGame( context, sink, groupID, addr, langa, dicta,
// nPlayersT, nPlayersH, inviteID, gameID,
// isHost );
}
public static long makeNewSMSGame( Context context, int gameID,
CommsAddrRec addr,
int lang, String dict, int nPlayersT,
int nPlayersH )
{
return makeNewSMSGame( context, DBUtils.GROUPID_UNSPEC, gameID, addr,
lang, dict, nPlayersT, nPlayersH );
}
public static long makeNewSMSGame( Context context, long groupID,
int gameID, CommsAddrRec addr,
int lang, String dict, int nPlayersT,
int nPlayersH )
public static long makeNewGame( Context context, MultiMsgSink sink,
long groupID, int gameID, CommsAddrRec addr,
int lang, String dict,
int nPlayersT, int nPlayersH )
{
long rowid = -1;
int[] langa = { lang };
String[] dicta = { dict };
boolean isHost = null == addr;
if ( isHost ) {
addr = new CommsAddrRec( CommsConnType.COMMS_CONN_SMS );
addr = new CommsAddrRec( null, null );
}
String inviteID = GameUtils.formatGameID( gameID );
return makeNewMultiGame( context, groupID, addr, langa, dicta,
return makeNewMultiGame( context, sink, groupID, addr, langa, dicta,
nPlayersT, nPlayersH, inviteID, gameID,
isHost );
}
// public static long makeNewSMSGame( Context context, int gameID,
// CommsAddrRec addr,
// int lang, String dict, int nPlayersT,
// int nPlayersH )
// {
// return makeNewSMSGame( context, DBUtils.GROUPID_UNSPEC, gameID, addr,
// lang, dict, nPlayersT, nPlayersH );
// }
// public static long makeNewSMSGame( Context context, long groupID,
// int gameID, CommsAddrRec addr,
// int lang, String dict, int nPlayersT,
// int nPlayersH )
// {
// long rowid = -1;
// int[] langa = { lang };
// String[] dicta = { dict };
// boolean isHost = null == addr;
// if ( isHost ) {
// addr = new CommsAddrRec( CommsConnType.COMMS_CONN_SMS );
// }
// String inviteID = GameUtils.formatGameID( gameID );
// return makeNewMultiGame( context, groupID, addr, langa, dicta,
// nPlayersT, nPlayersH, inviteID, gameID,
// isHost );
// }
public static void launchEmailInviteActivity( Activity activity, NetLaunchInfo nli )
{
DbgUtils.logf( "launchEmailInviteActivity: nli=%s", nli.makeLaunchJSON() );

View file

@ -1829,11 +1829,11 @@ public class GamesListDelegate extends ListDelegateBase
launchGame( rowid, true );
}
private void makeNewBTGame( NetLaunchInfo nli )
{
long rowid = GameUtils.makeNewBTGame( m_activity, nli );
launchGame( rowid, true );
}
// private void makeNewBTGame( NetLaunchInfo nli )
// {
// long rowid = GameUtils.makeNewBTGame( m_activity, nli );
// launchGame( rowid, true );
// }
private void tryStartsFromIntent( Intent intent )
{

View file

@ -25,11 +25,11 @@ import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import java.net.URLEncoder;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.Iterator;
import org.json.JSONObject;
import org.json.JSONException;
import org.json.JSONObject;
import junit.framework.Assert;
@ -43,9 +43,11 @@ import org.eehouse.android.xw4.jni.CurGameInfo;
public class NetLaunchInfo {
private static final String ADDRS_KEY = "ADDRS";
protected String gameName;
protected String dict;
protected int lang;
protected int nPlayersT;
protected int nPlayersH;
protected String room; // relay
protected String inviteID; // relay
protected String btName;
@ -75,7 +77,9 @@ public class NetLaunchInfo {
lang = m_json.optInt( MultiService.LANG, -1 );
dict = m_json.optString( MultiService.DICT );
gameName = m_json.optString( MultiService.GAMENAME );
nPlayersT = m_json.optInt( MultiService.NPLAYERST, -1 );
nPlayersH = m_json.optInt( MultiService.NPLAYERSH, -1 );
gameID = m_json.optInt( MultiService.GAMEID, -1 );
for ( CommsConnType typ : m_addrs.getTypes() ) {
@ -109,7 +113,16 @@ public class NetLaunchInfo {
{
room = bundle.getString( MultiService.ROOM );
inviteID = bundle.getString( MultiService.INVITEID );
Assert.fail();
lang = bundle.getInt( MultiService.LANG );
dict = bundle.getString( MultiService.DICT );
gameName= bundle.getString( MultiService.GAMENAME );
nPlayersT = bundle.getInt( MultiService.NPLAYERST );
nPlayersH = bundle.getInt( MultiService.NPLAYERSH );
gameID = bundle.getInt( MultiService.GAMEID );
btName = bundle.getString( MultiService.BT_NAME );
btAddress = bundle.getString( MultiService.BT_ADDRESS );
m_addrs = DBUtils.intToConnTypeSet( bundle.getInt( ADDRS_KEY ) );
}
public NetLaunchInfo( Context context, Uri data )
@ -153,7 +166,9 @@ public class NetLaunchInfo {
inviteID = intent.getStringExtra( MultiService.INVITEID );
lang = intent.getIntExtra( MultiService.LANG, -1 );
dict = intent.getStringExtra( MultiService.DICT );
gameName = intent.getStringExtra( MultiService.GAMENAME );
nPlayersT = intent.getIntExtra( MultiService.NPLAYERST, -1 );
nPlayersH = intent.getIntExtra( MultiService.NPLAYERSH, -1 );
gameID = intent.getIntExtra( MultiService.GAMEID, -1 );
btName = intent.getStringExtra( MultiService.BT_NAME );
btAddress = intent.getStringExtra( MultiService.BT_ADDRESS );
@ -168,9 +183,16 @@ public class NetLaunchInfo {
dict = dictName;
lang = dictLang;
nPlayersT = nPlayers;
nPlayersH = 1;
gameID = gamID;
}
public NetLaunchInfo( GameSummary summary, CurGameInfo gi, int numHere )
{
this( summary, gi );
nPlayersH = numHere;
}
public NetLaunchInfo( GameSummary summary, CurGameInfo gi )
{
this( gi.gameID, gi.dictLang, gi.dictName, gi.nPlayers );
@ -200,7 +222,9 @@ public class NetLaunchInfo {
bundle.putString( MultiService.INVITEID, inviteID );
bundle.putInt( MultiService.LANG, lang );
bundle.putString( MultiService.DICT, dict );
bundle.putString( MultiService.GAMENAME, gameName );
bundle.putInt( MultiService.NPLAYERST, nPlayersT );
bundle.putInt( MultiService.NPLAYERSH, nPlayersH );
bundle.putInt( MultiService.GAMEID, gameID );
bundle.putString( MultiService.BT_NAME, btName );
bundle.putString( MultiService.BT_ADDRESS, btAddress );
@ -216,7 +240,9 @@ public class NetLaunchInfo {
result = new JSONObject()
.put( MultiService.LANG, lang )
.put( MultiService.DICT, dict )
.put( MultiService.GAMENAME, gameName )
.put( MultiService.NPLAYERST, nPlayersT )
.put( MultiService.NPLAYERSH, nPlayersH )
.put( MultiService.ROOM, room )
.put( MultiService.INVITEID, inviteID )
.put( MultiService.GAMEID, gameID )
@ -227,7 +253,7 @@ public class NetLaunchInfo {
} catch ( org.json.JSONException jse ) {
DbgUtils.loge( jse );
}
DbgUtils.logf( "makeLaunchJSON() => %s", result );
// DbgUtils.logf( "makeLaunchJSON() => %s", result );
return result;
}
@ -255,6 +281,7 @@ public class NetLaunchInfo {
LocUtils.getString(context, R.string.invite_prefix) ) )
.appendQueryParameter( "lang", String.format("%d", lang ) )
.appendQueryParameter( "np", String.format( "%d", nPlayersT ) )
.appendQueryParameter( "nh", String.format( "%d", nPlayersH ) )
.appendQueryParameter( "gid", String.format( "%d", nPlayersT ) );
if ( null != dict ) {
ub.appendQueryParameter( "wl", dict );
@ -292,30 +319,6 @@ public class NetLaunchInfo {
}
return ub.build();
}
// public static String makeLaunchJSON( String curJson, String room, String inviteID,
// int lang, String dict, int nPlayersT )
// {
// Assert.assertNull( curJson );
// String result = null;
// try {
// result = new JSONObject()
// .put( MultiService.LANG, lang )
// .put( MultiService.DICT, dict )
// .put( MultiService.NPLAYERST, nPlayersT )
// .put( MultiService.ROOM, room )
// .put( MultiService.INVITEID, inviteID )
// .put( MultiService.GAMEID, gameID )
// .put( MultiService.BT_NAME, name )
// .put( MultiService.BT_ADDRESS, address )
// .put( ADDRS_KEY, DBUtils.connTypeSetToInt( m_addrs ) )
// .toString();
// } catch ( org.json.JSONException jse ) {
// DbgUtils.loge( jse );
// }
// DbgUtils.logf( "makeLaunchJSON() => %s", result );
// return result;
// }
public void addRelayInfo( String aRoom, String anInviteID )
{

View file

@ -213,21 +213,18 @@ public class NewGameDelegate extends DelegateBase {
long rowid;
CommsAddrRec addr = null;
rowid = GameUtils
.makeNewGame( m_activity, m_groupID, m_gameID,
addr, m_lang, m_dict, 2, 1 );
Assert.fail();
if ( m_nameForBT ) {
rowid = GameUtils
.makeNewBTGame( m_activity, m_groupID, m_gameID,
addr, m_lang, m_dict, 2, 1 );
BTService.inviteRemote( m_activity, m_remoteDev,
m_gameID, m_gameName,
m_lang, m_dict, 2, 1 );
// BTService.inviteRemote( m_activity, m_remoteDev,
// m_gameID, m_gameName,
// m_lang, m_dict, 2, 1 );
} else {
SMSService.inviteRemote( m_activity, m_remoteDev,
m_gameID, m_gameName,
m_lang, m_dict, 2, 1 );
rowid = GameUtils.
makeNewSMSGame( m_activity, m_groupID, m_gameID,
addr, m_lang, m_dict, 2, 1 );
// SMSService.inviteRemote( m_activity, m_remoteDev,
// m_gameID, m_gameName,
// m_lang, m_dict, 2, 1 );
}
DBUtils.setName( m_activity, rowid, m_gameName );
GameUtils.launchGame( m_activity, rowid, true );
@ -306,36 +303,36 @@ public class NewGameDelegate extends DelegateBase {
}
}
private void makeNewBTGame( boolean useDefaults )
{
if ( XWApp.BTSUPPORTED ) {
int gameID = GameUtils.newGameID();
if ( !useDefaults ) {
m_newRowID = GameUtils.makeNewBTGame( m_activity,
m_groupID, gameID, null,
m_lang, m_dict, 2, 1 );
GameConfigDelegate.editForResult( m_activity, CONFIG_FOR_BT, m_newRowID );
} else {
BTInviteDelegate.launchForResult( m_activity, 1, INVITE_FOR_BT );
}
}
}
// private void makeNewBTGame( boolean useDefaults )
// {
// if ( XWApp.BTSUPPORTED ) {
// int gameID = GameUtils.newGameID();
// if ( !useDefaults ) {
// m_newRowID = GameUtils.makeNewBTGame( m_activity,
// m_groupID, gameID, null,
// m_lang, m_dict, 2, 1 );
// GameConfigDelegate.editForResult( m_activity, CONFIG_FOR_BT, m_newRowID );
// } else {
// BTInviteDelegate.launchForResult( m_activity, 1, INVITE_FOR_BT );
// }
// }
// }
private void makeNewSMSGame( boolean useDefaults )
{
int gameID = GameUtils.newGameID();
if ( !useDefaults ) {
m_newRowID = GameUtils.makeNewSMSGame( m_activity,
m_groupID, gameID, null,
m_lang, m_dict, 2, 1 );
String name = getString( R.string.dft_sms_name_fmt, gameID & 0xFFFF );
DBUtils.setName( m_activity, m_newRowID, name );
// private void makeNewSMSGame( boolean useDefaults )
// {
// int gameID = GameUtils.newGameID();
// if ( !useDefaults ) {
// m_newRowID = GameUtils.makeNewSMSGame( m_activity,
// m_groupID, gameID, null,
// m_lang, m_dict, 2, 1 );
// String name = getString( R.string.dft_sms_name_fmt, gameID & 0xFFFF );
// DBUtils.setName( m_activity, m_newRowID, name );
GameConfigDelegate.editForResult( m_activity, CONFIG_FOR_SMS, m_newRowID );
} else {
SMSInviteDelegate.launchForResult( m_activity, 1, INVITE_FOR_SMS );
}
}
// GameConfigDelegate.editForResult( m_activity, CONFIG_FOR_SMS, m_newRowID );
// } else {
// SMSInviteDelegate.launchForResult( m_activity, 1, INVITE_FOR_SMS );
// }
// }
private static final int HIDE_MASK_LOCAL = 1;
private static final int HIDE_MASK_NET = 2;

View file

@ -673,9 +673,9 @@ public class SMSService extends XWService {
int nPlayersH )
{
long rowid =
GameUtils.makeNewSMSGame( this, gameID,
new CommsAddrRec( phone ),
lang, dict, nPlayersT, nPlayersH );
GameUtils.makeNewGame( this, gameID,
new CommsAddrRec( phone ),
lang, dict, nPlayersT, nPlayersH );
if ( null != gameName && 0 < gameName.length() ) {
DBUtils.setName( this, rowid, gameName );

View file

@ -37,7 +37,6 @@ import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet;
public class XWConnAddrPreference extends DialogPreference {
private int m_flags;
private CommsConnTypeSet m_curSet;
private Context m_context;
// This stuff probably belongs in CommsConnType
@ -58,8 +57,6 @@ public class XWConnAddrPreference extends DialogPreference {
setDialogLayoutResource( R.layout.conn_types_display );
setNegativeButtonText( LocUtils.getString( context, R.string.button_cancel ) );
m_flags = XWPrefs.getPrefsInt( context, R.string.key_addrs_pref, 0 );
}
@Override
@ -68,7 +65,7 @@ public class XWConnAddrPreference extends DialogPreference {
LocUtils.xlateView( m_context, view );
LinearLayout list = (LinearLayout)view.findViewById( R.id.conn_types );
m_curSet = DBUtils.intToConnTypeSet( m_flags );
m_curSet = XWPrefs.getAddrTypes( m_context );
for ( CommsConnType typ : s_supported.getTypes() ) {
CheckBox box = (CheckBox)LocUtils.inflate( m_context, R.layout.btinviter_item );
box.setText( typ.longName() );
@ -95,8 +92,7 @@ public class XWConnAddrPreference extends DialogPreference {
{
if ( AlertDialog.BUTTON_POSITIVE == which ) {
DbgUtils.logf( "ok pressed" );
m_flags = DBUtils.connTypeSetToInt( m_curSet );
XWPrefs.setPrefsInt( m_context, R.string.key_addrs_pref, m_flags );
XWPrefs.setAddrTypes( m_context, m_curSet );
}
super.onClick( dialog, which );
}

View file

@ -30,6 +30,8 @@ import java.util.ArrayList;
import junit.framework.Assert;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet;
public class XWPrefs {
// No reason to put this in xml if they're private to this file!
@ -462,6 +464,18 @@ public class XWPrefs {
getPrefsBoolean( context, R.string.key_force_tablet, false );
}
public static CommsConnTypeSet getAddrTypes( Context context )
{
int flags = getPrefsInt( context, R.string.key_addrs_pref, 0 );
return DBUtils.intToConnTypeSet( flags );
}
public static void setAddrTypes( Context context, CommsConnTypeSet set )
{
int flags = DBUtils.connTypeSetToInt( set );
setPrefsInt( context, R.string.key_addrs_pref, flags );
}
private static Boolean s_isTablet = null;
private static boolean isTablet( Context context )
{