private static String translatePhone(Contact contact, String message) throws Exception { message = message.replaceAll( String.format(CONTACT_FIELD, "tel"), getValueForObject(contact.getPhone())); message = message.replaceAll( String.format(CONTACT_FIELD, "tel_e164"), getValueForObject(contact.getPhone())); return message; }
private static String translateCustomFields(Contact contact, String message) throws Exception { Set<String> fieldKeys = contact.getFields().keySet(); for (String fieldKey : fieldKeys) { Object value = contact.getFields().get(fieldKey); message = message.replaceAll(String.format(CONTACT_FIELD, fieldKey), getValueForObject(value)); } return message; }
private static String translateRootFields(Contact contact, String message) throws Exception { for (Field field : contact.getClass().getDeclaredFields()) { field.setAccessible(true); message = message.replaceAll( String.format(CONTACT_FIELD, field.getName()), getStringForField(contact, field)); } return message; }
public static String translateContactFields(Contact contact, String message) { try { message = translatePhone(contact, message); message = translateRootFields(contact, message); message = translateCustomFields(contact, message); return message.replaceAll(CONTACT_VARIABLE, contact.getName()); } catch (Exception exception) { Log.e(TAG, "translateContactFields ", exception); return message; } }