mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
Recipient of BT new-game invitation puts up Notification after
creating it that will launch it.
This commit is contained in:
parent
3026a7e4f8
commit
6982545f59
5 changed files with 90 additions and 17 deletions
|
@ -1852,5 +1852,8 @@
|
|||
<string name="summary_bt_wait">Not yet connected</string>
|
||||
<string name="summary_bt_gameover">Game over</string>
|
||||
<string name="summary_bt_conn">Game in play</string>
|
||||
<string name="new_bt_title">New Bluetooth game</string>
|
||||
<string name="new_bt_bodyf">Paired device %s has invited you to
|
||||
play</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -86,6 +86,7 @@ public class BTService extends Service {
|
|||
INVITE,
|
||||
INVITE_ACCPT,
|
||||
INVITE_DECL,
|
||||
INVITE_DUPID,
|
||||
MESG_SEND,
|
||||
MESG_ACCPT,
|
||||
MESG__DECL,
|
||||
|
@ -516,6 +517,7 @@ public class BTService extends Service {
|
|||
BluetoothSocket socket )
|
||||
throws java.io.IOException
|
||||
{
|
||||
BTCmd result;
|
||||
int gameID = is.readInt();
|
||||
DbgUtils.logf( "receiveInvitation: got gameID of %d", gameID );
|
||||
int lang = is.readInt();
|
||||
|
@ -523,18 +525,29 @@ public class BTService extends Service {
|
|||
int nPlayersH = is.readInt();
|
||||
|
||||
BluetoothDevice host = socket.getRemoteDevice();
|
||||
CommsAddrRec addr = new CommsAddrRec( context, host.getName(),
|
||||
host.getAddress() );
|
||||
GameUtils.makeNewBTGame( context, gameID, addr,
|
||||
lang, nPlayersT, nPlayersH );
|
||||
|
||||
addAddr( host );
|
||||
|
||||
if ( DBUtils.ROWID_NOTFOUND == DBUtils.getRowIDFor( this, gameID ) ) {
|
||||
String sender = host.getName();
|
||||
CommsAddrRec addr = new CommsAddrRec( context, sender,
|
||||
host.getAddress() );
|
||||
GameUtils.makeNewBTGame( context, gameID, addr,
|
||||
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 );
|
||||
} else {
|
||||
result = BTCmd.INVITE_DUPID;
|
||||
}
|
||||
|
||||
// Post notification that, when selected, will create a game
|
||||
// -- or ask if user wants to create one.
|
||||
|
||||
DataOutputStream os = new DataOutputStream( socket.getOutputStream() );
|
||||
os.writeByte( BTCmd.INVITE_ACCPT.ordinal() );
|
||||
os.writeByte( result.ordinal() );
|
||||
os.flush();
|
||||
|
||||
socket.close();
|
||||
|
|
|
@ -35,10 +35,12 @@ import org.eehouse.android.xw4.jni.CommonPrefs;
|
|||
public class DispatchNotify extends Activity {
|
||||
|
||||
public static final String RELAYIDS_EXTRA = "relayids";
|
||||
public static final String GAMEID_EXTRA = "gameid";
|
||||
|
||||
public interface HandleRelaysIface {
|
||||
void HandleRelaysIDs( final String[] relayIDs );
|
||||
void HandleInvite( final Uri invite );
|
||||
void handleRelaysIDs( final String[] relayIDs );
|
||||
void handleInvite( final Uri invite );
|
||||
void handleGameID( int gameID );
|
||||
}
|
||||
|
||||
private static HashSet<HandleRelaysIface> s_running =
|
||||
|
@ -52,12 +54,17 @@ public class DispatchNotify extends Activity {
|
|||
super.onCreate( savedInstanceState );
|
||||
|
||||
String[] relayIDs = getIntent().getStringArrayExtra( RELAYIDS_EXTRA );
|
||||
int gameID = getIntent().getIntExtra( GAMEID_EXTRA, -1 );
|
||||
Uri data = getIntent().getData();
|
||||
|
||||
if ( null != relayIDs ) {
|
||||
if ( !tryHandle( relayIDs ) ) {
|
||||
mustLaunch = true;
|
||||
}
|
||||
} else if ( -1 != gameID ) {
|
||||
if ( !tryHandle( gameID ) ) {
|
||||
mustLaunch = true;
|
||||
}
|
||||
} else if ( null != data ) {
|
||||
if ( DBUtils.isNewInvite( this, data ) ) {
|
||||
if ( !tryHandle( data ) ) {
|
||||
|
@ -87,6 +94,8 @@ public class DispatchNotify extends Activity {
|
|||
| Intent.FLAG_ACTIVITY_NEW_TASK );
|
||||
if ( null != relayIDs ) {
|
||||
intent.putExtra( RELAYIDS_EXTRA, relayIDs );
|
||||
} else if ( -1 != gameID ) {
|
||||
intent.putExtra( GAMEID_EXTRA, gameID );
|
||||
} else if ( null != data ) {
|
||||
intent.setData( data );
|
||||
} else {
|
||||
|
@ -122,11 +131,11 @@ public class DispatchNotify extends Activity {
|
|||
boolean handled = false;
|
||||
if ( null != s_handler ) {
|
||||
// This means the GamesList activity is frontmost
|
||||
s_handler.HandleInvite( data );
|
||||
s_handler.handleInvite( data );
|
||||
handled = true;
|
||||
} else {
|
||||
for ( HandleRelaysIface iface : s_running ) {
|
||||
iface.HandleInvite( data );
|
||||
iface.handleInvite( data );
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
|
@ -138,11 +147,27 @@ public class DispatchNotify extends Activity {
|
|||
boolean handled = false;
|
||||
if ( null != s_handler ) {
|
||||
// This means the GamesList activity is frontmost
|
||||
s_handler.HandleRelaysIDs( relayIDs );
|
||||
s_handler.handleRelaysIDs( relayIDs );
|
||||
handled = true;
|
||||
} else {
|
||||
for ( HandleRelaysIface iface : s_running ) {
|
||||
iface.HandleRelaysIDs( relayIDs );
|
||||
iface.handleRelaysIDs( relayIDs );
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
public static boolean tryHandle( int gameID )
|
||||
{
|
||||
boolean handled = false;
|
||||
if ( null != s_handler ) {
|
||||
// This means the GamesList activity is frontmost
|
||||
s_handler.handleGameID( gameID );
|
||||
handled = true;
|
||||
} else {
|
||||
for ( HandleRelaysIface iface : s_running ) {
|
||||
iface.handleGameID( gameID );
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -297,6 +297,7 @@ public class GamesList extends XWListActivity
|
|||
getStringArrayExtra( DispatchNotify.RELAYIDS_EXTRA ) );
|
||||
startFirstHasDict( intent );
|
||||
startNewNetGame( intent );
|
||||
startHasGameID( intent );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -382,7 +383,7 @@ public class GamesList extends XWListActivity
|
|||
}
|
||||
|
||||
// DispatchNotify.HandleRelaysIface interface
|
||||
public void HandleRelaysIDs( final String[] relayIDs )
|
||||
public void handleRelaysIDs( final String[] relayIDs )
|
||||
{
|
||||
m_handler.post( new Runnable() {
|
||||
public void run() {
|
||||
|
@ -392,7 +393,7 @@ public class GamesList extends XWListActivity
|
|||
} );
|
||||
}
|
||||
|
||||
public void HandleInvite( Uri invite )
|
||||
public void handleInvite( Uri invite )
|
||||
{
|
||||
final NetLaunchInfo nli = new NetLaunchInfo( invite );
|
||||
if ( nli.isValid() ) {
|
||||
|
@ -405,6 +406,15 @@ public class GamesList extends XWListActivity
|
|||
}
|
||||
}
|
||||
|
||||
public void handleGameID( final int gameID )
|
||||
{
|
||||
m_handler.post( new Runnable() {
|
||||
public void run() {
|
||||
startHasGameID( gameID );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
// DBUtils.DBChangeListener interface
|
||||
public void gameSaved( final long rowid )
|
||||
{
|
||||
|
@ -743,6 +753,22 @@ public class GamesList extends XWListActivity
|
|||
}
|
||||
} // startNewNetGame
|
||||
|
||||
private void startHasGameID( int gameID )
|
||||
{
|
||||
long rowid = DBUtils.getRowIDFor( this, gameID );
|
||||
if ( DBUtils.ROWID_NOTFOUND != rowid ) {
|
||||
GameUtils.launchGame( this, rowid );
|
||||
}
|
||||
}
|
||||
|
||||
private void startHasGameID( Intent intent )
|
||||
{
|
||||
int gameID = intent.getIntExtra( DispatchNotify.GAMEID_EXTRA, -1 );
|
||||
if ( -1 != gameID ) {
|
||||
startHasGameID( gameID );
|
||||
}
|
||||
}
|
||||
|
||||
private void askDefaultNameIf()
|
||||
{
|
||||
if ( null == CommonPrefs.getDefaultPlayerName( this, 0, false ) ) {
|
||||
|
|
|
@ -77,6 +77,13 @@ public class Utils {
|
|||
|
||||
public static void postNotification( Context context, Intent intent,
|
||||
int titleID, int bodyID )
|
||||
{
|
||||
postNotification( context, intent, titleID,
|
||||
context.getString( bodyID ) );
|
||||
}
|
||||
|
||||
public static void postNotification( Context context, Intent intent,
|
||||
int titleID, String body )
|
||||
{
|
||||
PendingIntent pi = PendingIntent.
|
||||
getActivity( context, 0, intent,
|
||||
|
@ -95,12 +102,11 @@ public class Utils {
|
|||
notification.defaults |= Notification.DEFAULT_VIBRATE;
|
||||
}
|
||||
|
||||
notification.setLatestEventInfo( context, title,
|
||||
context.getString(bodyID), pi );
|
||||
notification.setLatestEventInfo( context, title, body, pi );
|
||||
|
||||
NotificationManager nm = (NotificationManager)
|
||||
context.getSystemService( Context.NOTIFICATION_SERVICE );
|
||||
nm.notify( bodyID, // unique id; any will do
|
||||
nm.notify( titleID, // unique id; any will do
|
||||
notification );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue