give move-made notifications ids based on the games they belong to so

that there can be more than one, then use those ids to dismiss them if
the game's opened other than through the notifications.
This commit is contained in:
Eric House 2012-04-17 20:08:37 -07:00
parent 3d60ee701e
commit 019a053df0
7 changed files with 63 additions and 14 deletions

View file

@ -971,7 +971,7 @@ public class BTService extends Service {
Intent intent = new Intent( this, DispatchNotify.class );
intent.putExtra( DispatchNotify.GAMEID_EXTRA, gameID );
Utils.postNotification( this, intent, R.string.new_btmove_title,
body );
body, gameID );
}
private Thread killSocketIn( final BluetoothSocket socket )

View file

@ -129,7 +129,8 @@ public class BoardActivity extends XWActivity
private int m_dlgTitle;
private String m_dlgTitleStr;
private String[] m_texts;
private CommsAddrRec.CommsConnType m_missingType;
private CommsAddrRec.CommsConnType m_connType =
CommsAddrRec.CommsConnType.COMMS_CONN_NONE;
private String[] m_missingDevs;
private String m_curTiles;
private boolean m_canUndoTiles;
@ -1348,6 +1349,8 @@ public class BoardActivity extends XWActivity
CommsAddrRec.CommsConnType connType,
final int nMissingPlayers )
{
m_connType = connType;
int msgID = 0;
int action = 0;
if ( 0 < nMissingPlayers && isServer && !m_haveInvited ) {
@ -1364,7 +1367,6 @@ public class BoardActivity extends XWActivity
}
if ( 0 != action ) {
m_haveInvited = true;
m_missingType = connType;
final int faction = action;
final int fmsgID = msgID;
post( new Runnable() {
@ -1553,7 +1555,8 @@ public class BoardActivity extends XWActivity
if ( null != m_xport ) {
trySendChats();
m_xport.tickle();
removeNotifications();
m_xport.tickle( m_connType );
tryInvites();
}
}
@ -1725,6 +1728,24 @@ public class BoardActivity extends XWActivity
}
}
private void removeNotifications()
{
int id = 0;
switch( m_connType ) {
case COMMS_CONN_BT:
case COMMS_CONN_SMS:
id = m_gi.gameID;
break;
case COMMS_CONN_RELAY:
String relayID = DBUtils.getRelayID( this, m_rowid );
id = relayID.hashCode();
break;
}
if ( 0 != id ) {
Utils.cancelNotification( this, id );
}
}
private void tryInvites()
{
if ( XWApp.BTSUPPORTED || XWApp.SMSSUPPORTED ) {
@ -1733,7 +1754,7 @@ public class BoardActivity extends XWActivity
boolean doProgress = false;
m_invitesPending = m_missingDevs.length;
for ( String dev : m_missingDevs ) {
switch( m_missingType ) {
switch( m_connType ) {
case COMMS_CONN_BT:
BTService.inviteRemote( this, dev, m_gi.gameID,
gameName, m_gi.dictLang,

View file

@ -222,7 +222,7 @@ public class CommsTransport implements TransportProcs,
}
}
public void tickle()
public void tickle( CommsConnType connType )
{
m_jniThread.handle( JNIThread.JNICmd.CMD_RESEND_ACK );
// CommsAddrRec addr = new CommsAddrRec( m_context );

View file

@ -391,6 +391,26 @@ public class DBUtils {
return 0 == getInt( context, rowid, DBHelper.CONTRACTED, 0 );
}
public static String getRelayID( Context context, long rowid )
{
String result = null;
initDB( context );
synchronized( s_dbHelper ) {
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
String[] columns = { DBHelper.RELAYID };
String selection = String.format( ROW_ID_FMT, rowid );
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
selection, null, null, null, null );
if ( 1 == cursor.getCount() && cursor.moveToFirst() ) {
result =
cursor.getString( cursor.getColumnIndex(DBHelper.RELAYID) );
}
cursor.close();
db.close();
}
return result;
}
public static long getRowIDFor( Context context, String relayID )
{
long result = ROWID_NOTFOUND;

View file

@ -63,8 +63,10 @@ public class RelayService extends Service {
Intent intent = new Intent( this, DispatchNotify.class );
intent.putExtra( DispatchNotify.RELAYIDS_EXTRA, relayIDs );
Utils.postNotification( this, intent, R.string.notify_title,
R.string.notify_body );
for ( String id : relayIDs ) {
Utils.postNotification( this, intent, R.string.notify_title,
R.string.notify_body, id.hashCode() );
}
}
private String[] collectIDs( int[] nBytes )

View file

@ -516,7 +516,7 @@ public class SMSService extends Service {
{
Intent intent = new Intent( this, DispatchNotify.class );
intent.putExtra( DispatchNotify.GAMEID_EXTRA, gameID );
Utils.postNotification( this, intent, title, body );
Utils.postNotification( this, intent, title, body, gameID );
}
// Runs in separate thread

View file

@ -99,14 +99,14 @@ public class Utils {
}
public static void postNotification( Context context, Intent intent,
int titleID, int bodyID )
int titleID, int bodyID, int id )
{
postNotification( context, intent, titleID,
context.getString( bodyID ) );
context.getString( bodyID ), id );
}
public static void postNotification( Context context, Intent intent,
int titleID, String body )
int titleID, String body, int id )
{
PendingIntent pi = PendingIntent.
getActivity( context, 0, intent,
@ -129,8 +129,14 @@ public class Utils {
NotificationManager nm = (NotificationManager)
context.getSystemService( Context.NOTIFICATION_SERVICE );
nm.notify( titleID, // unique id; any will do
notification );
nm.notify( id, notification );
}
public static void cancelNotification( Context context, int id )
{
NotificationManager nm = (NotificationManager)
context.getSystemService( Context.NOTIFICATION_SERVICE );
nm.cancel( id );
}
public static View inflate( Context context, int layoutId )