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