Exemple #1
0
 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");
 }
Exemple #2
0
  // 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;
  }