From 15f8cd5b33ed240e1152d73e12c0dc51b3016ee7 Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 7 Feb 2012 18:41:56 -0800 Subject: [PATCH] post notifications when moves arrive and game isn't open. And handle BAD_PROTO event (untested). --- .../android/XWords4/res/values/strings.xml | 9 ++++++++- .../org/eehouse/android/xw4/BTService.java | 19 ++++++++++++++++--- .../org/eehouse/android/xw4/DlgDelegate.java | 13 +++++++++++++ .../org/eehouse/android/xw4/XWActivity.java | 2 +- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index ae3e569df..f60e02527 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -1852,8 +1852,15 @@ Not yet connected Game over Game in play - New Bluetooth game + New game via Bluetooth Paired device %s has invited you to play + Crosswords on %s wrong version for + Bluetooth play. + + New move via Bluetooth + One or more moves has arrived + + diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BTService.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BTService.java index 4709bb5c0..590257d28 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BTService.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BTService.java @@ -596,10 +596,8 @@ public class BTService extends Service { lang, nPlayersT, nPlayersH ); result = BTCmd.INVITE_ACCPT; - Intent intent = new Intent( this, DispatchNotify.class ); - intent.putExtra( DispatchNotify.GAMEID_EXTRA, gameID ); String body = Utils.format( this, R.string.new_bt_bodyf, sender ); - Utils.postNotification( this, intent, R.string.new_bt_title, body ); + postNotification( gameID, R.string.new_bt_title, body ); } else { result = BTCmd.INVITE_DUPID; } @@ -642,6 +640,8 @@ public class BTService extends Service { } else if ( GameUtils.feedMessage( this, gameID, buffer, addr, m_btMsgSink ) ) { DbgUtils.logf( "GameUtils.feedMessage took it" ); + postNotification( gameID, R.string.new_btmove_title, + R.string.new_btmove_body ); // do nothing } else { DbgUtils.logf( "nobody to take message for gameID", gameID ); @@ -741,6 +741,19 @@ public class BTService extends Service { return dos; } + private void postNotification( int gameID, int title, int body ) + { + postNotification( gameID, title, getString( body ) ); + } + + private void postNotification( int gameID, int title, String body ) + { + Intent intent = new Intent( this, DispatchNotify.class ); + intent.putExtra( DispatchNotify.GAMEID_EXTRA, gameID ); + Utils.postNotification( this, intent, R.string.new_btmove_title, + body ); + } + private Thread killSocketIn( final BluetoothSocket socket, int seconds ) { final int millis = seconds * 1000; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java index 6d828ab81..cc51d7e9c 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java @@ -277,6 +277,19 @@ public class DlgDelegate { } } + public void eventOccurred( BTService.BTEvent event, final Object ... args ) + { + switch( event ) { + case BAD_PROTO: + String msg = Utils.format( m_activity, R.string.bt_bad_protof, + (String)args[0] ); + DbgUtils.showf( m_activity, msg ); + break; + default: + DbgUtils.logf( "eventOccurred: unhandled event %s", event.toString() ); + } + } + private Dialog createAboutDialog() { final View view = Utils.inflate( m_activity, R.layout.about_dlg ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java index 2c0912d00..dc7a4d315 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java @@ -177,7 +177,7 @@ public class XWActivity extends Activity // BTService.BTEventListener interface public void eventOccurred( BTService.BTEvent event, final Object ... args ) { - DbgUtils.logf( "eventOccurred: unhandled event %s", event.toString() ); + m_delegate.eventOccurred( event, args ); } }