add param to phoneToContact controlling whether phone number is

returned when name can't be found.
This commit is contained in:
Eric House 2012-04-23 06:16:06 -07:00
parent d5076e2167
commit b34e741e30
4 changed files with 18 additions and 12 deletions

View file

@ -1899,8 +1899,7 @@
devs? (I won\'t ask again until you reopen this game.)</string>
<string name="new_sms_title">New game via SMS</string>
<string name="new_sms_bodyf">Phone with number %s has invited you to
play</string>
<string name="new_name_bodyf">%s has invited you to play</string>
<string name="new_smsmove_title">New move via SMS</string>
<string name="button_sms_add">Import contact</string>

View file

@ -811,7 +811,8 @@ public class GameConfig extends XWActivity
XWListItem item =
(XWListItem)Utils.inflate( this, R.layout.list_item );
item.setText( addr.sms_phone );
String name = Utils.phoneToContact( this, addr.sms_phone );
String name = Utils.phoneToContact( this, addr.sms_phone,
false );
item.setComment( name );
item.setEnabled( false );
phoneList.addView( item );

View file

@ -269,7 +269,7 @@ public class SMSService extends Service {
send( SMS_CMD.INVITE, bas.toByteArray(), phone );
} catch ( java.io.IOException ioe ) {
DbgUtils.logf( "ioe: %s", ioe.toString() );
DbgUtils.logf( "inviteRemote: ioe: %s", ioe.toString() );
}
}
@ -283,7 +283,7 @@ public class SMSService extends Service {
send( SMS_CMD.ACK, bas.toByteArray(), phone );
} catch ( java.io.IOException ioe ) {
DbgUtils.logf( "ioe: %s", ioe.toString() );
DbgUtils.logf( "ackInvite: ioe: %s", ioe.toString() );
}
}
@ -296,7 +296,7 @@ public class SMSService extends Service {
das.flush();
send( SMS_CMD.DEATH, bas.toByteArray(), phone );
} catch ( java.io.IOException ioe ) {
DbgUtils.logf( "ioe: %s", ioe.toString() );
DbgUtils.logf( "sendDiedPacket: ioe: %s", ioe.toString() );
}
}
@ -314,7 +314,7 @@ public class SMSService extends Service {
nSent = bytes.length;
}
} catch ( java.io.IOException ioe ) {
DbgUtils.logf( "ioe: %s", ioe.toString() );
DbgUtils.logf( "sendPacket: ioe: %s", ioe.toString() );
}
return nSent;
}
@ -386,7 +386,9 @@ public class SMSService extends Service {
if ( null != gameName && 0 < gameName.length() ) {
DBUtils.setName( this, rowid, gameName );
}
String body = Utils.format( this, R.string.new_sms_bodyf, phone );
String owner = Utils.phoneToContact( this, phone, true );
String body = Utils.format( this, R.string.new_name_bodyf,
owner );
postNotification( gameID, R.string.new_sms_title, body );
ackInvite( phone, gameID );
@ -411,7 +413,7 @@ public class SMSService extends Service {
break;
}
} catch ( java.io.IOException ioe ) {
DbgUtils.logf( "ioe: %s", ioe.toString() );
DbgUtils.logf( "receive: ioe: %s", ioe.toString() );
}
}
@ -485,7 +487,7 @@ public class SMSService extends Service {
}
}
} catch ( java.io.IOException ioe ) {
DbgUtils.logf( "ioe: %s", ioe.toString() );
DbgUtils.logf( "disAssemble: ioe: %s", ioe.toString() );
}
}
@ -508,7 +510,7 @@ public class SMSService extends Service {
}
success = true;
} catch ( IllegalArgumentException iae ) {
DbgUtils.logf( "%s", iae.toString() );
DbgUtils.logf( "sendBuffers(%s): %s", phone, iae.toString() );
} catch ( Exception ee ) {
DbgUtils.logf( "sendDataMessage message failed: %s",
ee.toString() );

View file

@ -141,7 +141,8 @@ public class Utils {
// adapted from
// http://stackoverflow.com/questions/2174048/how-to-look-up-a-contacts-name-from-their-phone-number-on-android
public static String phoneToContact( Context context, String phone )
public static String phoneToContact( Context context, String phone,
boolean phoneStandsIn )
{
// I'm assuming that since context is passed this needn't
// worry about synchronization -- will always be called from
@ -166,6 +167,9 @@ public class Utils {
s_phonesHash.put( phone, name );
}
if ( null == name && phoneStandsIn ) {
name = phone;
}
return name;
}