private static void realizeStringArrayField( Contact contact, int field, int indexField, int index, int attributes, java.lang.String value, int action) throws PIMException { if (s_PIMList.isSupportedArrayElement(field, indexField)) { Logger.println( "DEBUG : realizeStringArrayField " + field + " and " + attributes + " supported"); String[] values = new String[s_PIMList.stringArraySize(field)]; for (int i = 0; i < values.length; i++) { values[i] = ""; } values[indexField] = value; if (action == ADD_FIELD) { contact.addStringArray(field, attributes, values); } else { contact.setStringArray(field, index, attributes, values); } contact.commit(); } else Logger.println( "DEBUG : realizeStringArrayField " + field + " and " + attributes + "not supported"); }
private void getName(PIMList list, Contact c) { if (list.isSupportedField(Contact.NAME)) { if (c.countValues(Contact.NAME) != 0) { String[] array = c.getStringArray(Contact.NAME, Contact.ATTR_NONE); if (list.isSupportedArrayElement(Contact.NAME, Contact.NAME_FAMILY)) { if (array[Contact.NAME_FAMILY] != null) { m_info[PIM_LAST_NAME] = array[Contact.NAME_FAMILY]; } } if (list.isSupportedArrayElement(Contact.NAME, Contact.NAME_GIVEN)) { if (array[Contact.NAME_GIVEN] != null) { m_info[PIM_FIRST_NAME] = array[Contact.NAME_GIVEN]; } } } } if (list.isSupportedField(Contact.FORMATTED_NAME)) { m_info[PIM_FULL_NAME] = getString(c, Contact.FORMATTED_NAME, Contact.ATTR_NONE); } else { m_info[PIM_FULL_NAME] = m_info[PIM_LAST_NAME] + " " + m_info[PIM_FIRST_NAME]; } }
// Create a new contact and returns a contactId used to add new fields by // using setInfo. static int createContact() { // #ifdef api.pim Contact contact = ((ContactList) s_PIMList).createContact(); String[] name = new String[s_PIMList.stringArraySize(Contact.NAME)]; name[Contact.NAME_GIVEN] = ""; name[Contact.NAME_FAMILY] = ""; Logger.println("DEBUG createContact : init"); String[] addr = new String[s_PIMList.stringArraySize(Contact.ADDR)]; addr[Contact.ADDR_COUNTRY] = ""; addr[Contact.ADDR_LOCALITY] = ""; addr[Contact.ADDR_POSTALCODE] = ""; addr[Contact.ADDR_STREET] = ""; if (s_PIMList.isSupportedField(Contact.FORMATTED_NAME)) contact.addString(Contact.FORMATTED_NAME, PIMItem.ATTR_NONE, ""); else Logger.println("DEBUG createContact not supported : FORMATTED_NAME"); if (s_PIMList.isSupportedArrayElement(Contact.NAME, Contact.NAME_FAMILY)) name[Contact.NAME_FAMILY] = ""; else Logger.println("DEBUG createContact not supported : NAME_FAMILY"); if (s_PIMList.isSupportedArrayElement(Contact.NAME, Contact.NAME_GIVEN)) name[Contact.NAME_GIVEN] = ""; else Logger.println("DEBUG createContact not supported : NAME_GIVEN"); contact.addStringArray(Contact.NAME, PIMItem.ATTR_NONE, name); if (s_PIMList.isSupportedArrayElement(Contact.ADDR, Contact.ADDR_COUNTRY)) addr[Contact.ADDR_COUNTRY] = ""; else Logger.println("DEBUG createContact not supported : ADDR_COUNTRY"); if (s_PIMList.isSupportedArrayElement(Contact.ADDR, Contact.ADDR_LOCALITY)) addr[Contact.ADDR_LOCALITY] = ""; else Logger.println("DEBUG createContact not supported : ADDR_LOCALITY"); if (s_PIMList.isSupportedArrayElement(Contact.ADDR, Contact.ADDR_POSTALCODE)) addr[Contact.ADDR_POSTALCODE] = ""; else Logger.println("DEBUG createContact not supported : ADDR_POSTALCODE"); if (s_PIMList.isSupportedArrayElement(Contact.ADDR, Contact.ADDR_STREET)) addr[Contact.ADDR_STREET] = ""; else Logger.println("DEBUG createContact not supported : ADDR_STREET"); if (s_PIMList.isSupportedField(Contact.ADDR)) contact.addStringArray(Contact.ADDR, Contact.ATTR_HOME, addr); else Logger.println("DEBUG createContact not supported : ADDR ATTR_HOME"); if (s_PIMList.isSupportedField(Contact.ADDR)) contact.addStringArray(Contact.ADDR, Contact.ATTR_WORK, addr); else Logger.println("DEBUG createContact not supported : ADDR ATTR_WORK"); if (s_PIMList.isSupportedField(Contact.FORMATTED_ADDR)) contact.addString(Contact.FORMATTED_ADDR, Contact.ATTR_HOME, ""); else Logger.println("DEBUG createContact not supported : FORMATTED_ADDR ATTR_HOME"); if (s_PIMList.isSupportedField(Contact.FORMATTED_ADDR)) contact.addString(Contact.FORMATTED_ADDR, Contact.ATTR_WORK, ""); else Logger.println("DEBUG createContact not supported : FORMATTED_ADDR ATTR_WORK"); // if (s_PIMList.isSupportedField(Contact.TEL)) // contact.addString(Contact.TEL, Contact.ATTR_HOME, ""); if (s_PIMList.isSupportedAttribute(Contact.TEL, Contact.ATTR_HOME)) contact.addString(Contact.TEL, Contact.ATTR_HOME, ""); else Logger.println("DEBUG createContact not supported : TEL ATTR_HOME"); if (s_PIMList.isSupportedAttribute(Contact.TEL, Contact.ATTR_WORK)) contact.addString(Contact.TEL, Contact.ATTR_WORK, ""); else Logger.println("DEBUG createContact not supported : TEL ATTR_WORK"); if (s_PIMList.isSupportedAttribute(Contact.TEL, Contact.ATTR_FAX)) contact.addString(Contact.TEL, Contact.ATTR_FAX, ""); else Logger.println("DEBUG createContact not supported : TEL ATTR_FAX"); if (s_PIMList.isSupportedAttribute(Contact.TEL, Contact.ATTR_MOBILE | Contact.ATTR_HOME)) contact.addString(Contact.TEL, Contact.ATTR_MOBILE | Contact.ATTR_HOME, ""); else Logger.println("DEBUG createContact not supported : TEL ATTR_MOBILE ATTR_HOME"); if (s_PIMList.isSupportedAttribute(Contact.TEL, Contact.ATTR_MOBILE | Contact.ATTR_WORK)) contact.addString(Contact.TEL, Contact.ATTR_MOBILE | Contact.ATTR_WORK, ""); else Logger.println("DEBUG createContact not supported : TEL ATTR_MOBILE ATTR_WORK"); if (s_PIMList.isSupportedField(Contact.EMAIL)) contact.addString(Contact.EMAIL, PIMItem.ATTR_NONE, ""); else Logger.println("DEBUG createContact not supported : EMAIL"); if (s_PIMList.isSupportedField(Contact.PHOTO_URL)) contact.addString(Contact.PHOTO_URL, PIMItem.ATTR_NONE, ""); else Logger.println("DEBUG createContact not supported : PHOTO_URL"); // Logger.println("DEBUG createContact : NOTE"); if (s_PIMList.isSupportedField(Contact.NOTE)) contact.addString(Contact.NOTE, PIMItem.ATTR_NONE, ""); else Logger.println("DEBUG createContact not supported : NOTE"); try { // contact.addString(Contact.FORMATTED_NAME, PIMItem.ATTR_NONE, ""); // contact.addStringArray(Contact.NAME, PIMItem.ATTR_NONE, name); // contact.addStringArray(Contact.ADDR, Contact.ATTR_HOME, addr); // contact.addStringArray(Contact.ADDR, Contact.ATTR_WORK, addr); // contact.addString(Contact.FORMATTED_ADDR, Contact.ATTR_WORK, ""); // contact.addString(Contact.FORMATTED_ADDR, Contact.ATTR_HOME, ""); // contact.addString(Contact.TEL, Contact.ATTR_HOME, ""); // contact.addString(Contact.TEL, Contact.ATTR_WORK, ""); // contact.addString(Contact.TEL, Contact.ATTR_FAX, ""); // contact.addString(Contact.TEL, Contact.ATTR_MOBILE | Contact.ATTR_HOME, ""); // contact.addString(Contact.TEL, Contact.ATTR_MOBILE | Contact.ATTR_WORK, ""); // contact.addString(Contact.EMAIL, PIMItem.ATTR_NONE, ""); // contact.addString(Contact.NOTE, PIMItem.ATTR_NONE, ""); // contact.addString(Contact.PHOTO_URL, PIMItem.ATTR_NONE, ""); // contact.addToCategory(""); // todo : catcher exception pour passer outre en // cas d'exception ca dépend des plateformes supportés pour "" vide. // // String [] cat = contact.getCategories(); // for (int i=0; i< cat.length; i++) { // Logger.println("DEBUG categories "+i+"-"+cat[i]); // } // contact.commit(); // // } catch (UnsupportedFieldException e) { // // In this case, we choose not to save the contact at all if any of the // // fields are not supported on this platform. // Logger.println("createContact() tests Contact not saved :"+e); // return 0; } catch (javax.microedition.pim.PIMException e) { Logger.println("createContacttests PIMException"); return 0; } addContact((ContactList) s_PIMList, contact); // #endif return s_nbContacts; }