From d67614cd6959f12b7605a28c191d9b3cd19d87e7 Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 17 Apr 2012 21:46:57 -0700 Subject: [PATCH] send ack after creating game on receipt of SMS invitation. Thought about starting up the game so it could connect, but that'd make it impossible to change any settings, e.g. player name, on the accepting end. --- .../android/XWords4/res/values/strings.xml | 3 +++ .../eehouse/android/xw4/BoardActivity.java | 18 ++++++++++--- .../org/eehouse/android/xw4/SMSService.java | 25 +++++++++++++++++-- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index 083f9c0de..67bea15c1 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -1920,4 +1920,7 @@ Are you sure you want to delete the checked phone number[s]? + + Invitation accepted. + diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java index 69de82a15..beb20684f 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -843,16 +843,26 @@ public class BoardActivity extends XWActivity } ); } break; + + // This can be BT or SMS. In BT case there's a progress + // thing going. Not in SMS case. case NEWGAME_FAILURE: DbgUtils.logf( "failed to create game" ); case NEWGAME_SUCCESS: - if ( 0 == --m_invitesPending ) { - m_handler.post( new Runnable() { - public void run() { + final boolean success = + MultiService.MultiEvent.NEWGAME_SUCCESS == event; + final boolean allHere = 0 == --m_invitesPending; + m_handler.post( new Runnable() { + public void run() { + if ( allHere ) { stopProgress(); + } + if ( success ) { + DbgUtils.showf( BoardActivity.this, + R.string.invite_success ); + } } } ); - } break; default: diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSService.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSService.java index 8935260ae..6a1d82cde 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSService.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSService.java @@ -76,7 +76,7 @@ public class SMSService extends Service { // All messages are base64-encoded byte arrays. The first byte is // always one of these. What follows depends. - private enum SMS_CMD { NONE, INVITE, DATA, DEATH, }; + private enum SMS_CMD { NONE, INVITE, DATA, DEATH, ACK, }; private int m_nReceived = 0; private static int s_nSent = 0; @@ -273,6 +273,20 @@ public class SMSService extends Service { } } + private void ackInvite( String phone, int gameID ) + { + ByteArrayOutputStream bas = new ByteArrayOutputStream( 128 ); + DataOutputStream das = new DataOutputStream( bas ); + try { + das.writeInt( gameID ); + das.flush(); + + send( SMS_CMD.ACK, bas.toByteArray(), phone ); + } catch ( java.io.IOException ioe ) { + DbgUtils.logf( "ioe: %s", ioe.toString() ); + } + } + private void sendDiedPacket( String phone, int gameID ) { ByteArrayOutputStream bas = new ByteArrayOutputStream( 32 ); @@ -374,6 +388,8 @@ public class SMSService extends Service { } String body = Utils.format( this, R.string.new_sms_bodyf, phone ); postNotification( gameID, R.string.new_sms_title, body ); + + ackInvite( phone, gameID ); break; case DATA: gameID = dis.readInt(); @@ -385,8 +401,13 @@ public class SMSService extends Service { gameID = dis.readInt(); s_srcMgr.sendResult( MultiEvent.MESSAGE_NOGAME, gameID ); break; + case ACK: + gameID = dis.readInt(); + s_srcMgr.sendResult( MultiEvent.NEWGAME_SUCCESS, + gameID ); + break; default: - Assert.fail(); + DbgUtils.logf( "unexpected cmd %s", cmd.toString() ); break; } } catch ( java.io.IOException ioe ) {