From b34e741e3086be40847fbe1be08845578cf96e3f Mon Sep 17 00:00:00 2001 From: Eric House Date: Mon, 23 Apr 2012 06:16:06 -0700 Subject: [PATCH] add param to phoneToContact controlling whether phone number is returned when name can't be found. --- xwords4/android/XWords4/res/values/strings.xml | 3 +-- .../org/eehouse/android/xw4/GameConfig.java | 3 ++- .../org/eehouse/android/xw4/SMSService.java | 18 ++++++++++-------- .../src/org/eehouse/android/xw4/Utils.java | 6 +++++- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index a63738a9c..4c64d8b7a 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -1899,8 +1899,7 @@ devs? (I won\'t ask again until you reopen this game.) New game via SMS - Phone with number %s has invited you to - play + %s has invited you to play New move via SMS Import contact diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java index 1ab085cb0..fb8d5e073 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java @@ -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 ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSService.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSService.java index 6a1d82cde..b94b30b67 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSService.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSService.java @@ -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() ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java index 2445c56d6..0b1f0f291 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java @@ -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; }