Esempio n. 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");
 }
Esempio n. 2
0
 // #ifdef api.pim
 private static void realizeStringField(
     Contact contact, int field, int index, int attributes, java.lang.String value, int action)
     throws PIMException {
   if (s_PIMList.isSupportedAttribute(field, attributes)) {
     Logger.println("DEBUG : realizeStringField " + field + " and " + attributes + " supported");
     inputStringField(contact, field, index, attributes, value, action);
   } else
     Logger.println(
         "DEBUG : realizeStringField " + field + " and " + attributes + "not supported");
 }
Esempio n. 3
0
 private static int realizeStringField(
     Contact contact, int field, int index, java.lang.String value, int action)
     throws PIMException {
   if (s_PIMList.isSupportedField(field)) {
     Logger.println("DEBUG : realizeStringField " + field + " supported");
     inputStringField(contact, field, index, PIMItem.ATTR_NONE, value, action);
     return 1;
   } else {
     Logger.println("DEBUG : realizeStringField " + field + " not supported");
     return -1;
   }
 }
Esempio n. 4
0
 static void closeContacts() {
   // #ifdef api.pim
   Logger.println("DEBUG : closeContacts IN");
   for (int i = 0; i < s_nbContacts; i++) {
     s_contacts[i] = null;
   }
   Logger.println("DEBUG : closeContacts init null for");
   s_contacts = null;
   Logger.println("DEBUG : closeContacts s_contacts null. Now try s_PIMList.close()");
   try {
     s_PIMList.close();
   } catch (Exception e) {
     Logger.println("Exception while closing list: " + e);
   }
   Logger.println("DEBUG : closeContacts OUT");
   // #endif
 }
Esempio n. 5
0
 static int openContacts() {
   // #ifdef api.pim
   s_contacts = new JSContact[s_nbContacts + 64];
   s_nbContacts = 0;
   try {
     s_PIMList = PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
     Enumeration itemEnum = s_PIMList.items();
     while (itemEnum.hasMoreElements()) {
       try {
         addContact(s_PIMList, (Contact) itemEnum.nextElement());
       } catch (Exception e) {
         Logger.println("Exception while opening contacts: " + e);
       }
     }
   } catch (Exception e) {
     Logger.println("Exception while opening list: " + e);
   }
   // #endif
   return s_nbContacts;
 }
Esempio n. 6
0
 // Modify info_string in a contact given by contactId (between 0 and
 // max contacts). The info_constant can be one of the constants.
 static void addInfo(int contactId, int info_constant, String info_string) {
   // #ifdef api.pim
   if (contactId >= 0
       && contactId < s_nbContacts
       && info_constant > 0
       && info_constant <= PIM_LAST) {
     s_contacts[contactId].m_info[info_constant] = new String(info_string);
     Logger.println(
         "DEBUG : addInfo (id:"
             + contactId
             + ", info:"
             + info_constant
             + ", string:"
             + info_string
             + ")");
     realizeField(s_contacts[contactId].m_contact, info_constant, info_string, ADD_FIELD);
   }
   // #endif
 }
Esempio n. 7
0
 // Delete a contact given by contactId (between 0 and max contacts). Returns
 // 1 if success otherwish returns 0.
 static int deleteContact(int contactId) {
   // #ifdef api.pim
   if (contactId >= 0 && contactId < s_contacts.length) {
     try {
       ContactList list = (ContactList) s_contacts[contactId].m_contact.getPIMList();
       list.removeContact((s_contacts[contactId].m_contact));
       s_contacts[contactId] = null;
       s_nbContacts--;
       for (int i = contactId; i < s_nbContacts; i++) {
         s_contacts[i] = s_contacts[i + 1];
       }
       return 1;
     } catch (Exception e) {
       Logger.println("Exception while deleting contact: " + e);
     }
   }
   // #endif
   return 0;
 }
Esempio n. 8
0
 private static void realizeField(
     Contact contact, int info_constant, String info_string, int action) {
   Logger.println("DEBUG : addField " + info_string);
   try {
     switch (info_constant) {
       case PIM_FULL_NAME:
         realizeStringField(contact, Contact.FORMATTED_NAME, 0, info_string, action);
         break;
       case PIM_FIRST_NAME:
         realizeStringArrayField(
             contact, Contact.NAME, Contact.NAME_GIVEN, 0, PIMItem.ATTR_NONE, info_string, action);
         break;
       case PIM_LAST_NAME:
         realizeStringArrayField(
             contact,
             Contact.NAME,
             Contact.NAME_FAMILY,
             0,
             PIMItem.ATTR_NONE,
             info_string,
             action);
         break;
       case PIM_ADDRESS:
         int state = realizeStringField(contact, Contact.FORMATTED_ADDR, 0, info_string, action);
         if (state == -1) {
           realizeStringField(contact, Contact.ADDR, 0, info_string, action);
         }
         break;
       case PIM_MOBILE:
         realizeStringField(contact, Contact.TEL, 0, Contact.ATTR_MOBILE, info_string, action);
         break;
       case PIM_MOBILE_HOME:
         realizeStringField(
             contact,
             Contact.TEL,
             0,
             Contact.ATTR_MOBILE & Contact.ATTR_HOME,
             info_string,
             action);
         break;
       case PIM_MOBILE_WORK:
         realizeStringField(
             contact,
             Contact.TEL,
             0,
             Contact.ATTR_MOBILE & Contact.ATTR_WORK,
             info_string,
             action);
         break;
       case PIM_HOME:
         realizeStringField(contact, Contact.TEL, 0, Contact.ATTR_HOME, info_string, action);
         break;
       case PIM_WORK:
         realizeStringField(contact, Contact.TEL, 0, Contact.ATTR_WORK, info_string, action);
         break;
       case PIM_FAX:
         realizeStringField(contact, Contact.TEL, 0, Contact.ATTR_FAX, info_string, action);
         break;
       case PIM_OTHER:
         realizeStringField(contact, Contact.NOTE, 0, info_string, action);
         break;
       case PIM_PREFERRED:
         // TODO : return Contact.ATTR_PREFERRED; NOT YET IMPLEMENTED
         break;
       case PIM_EMAIL:
         realizeStringField(contact, Contact.EMAIL, 0, info_string, action);
         break;
       case PIM_PHOTO_URL:
         realizeStringField(contact, Contact.PHOTO_URL, 0, info_string, action);
         break;
       case PIM_LAST:
       default:
         break;
     }
   } catch (PIMException e) {
     // An error occured
     Logger.println("DEBUG exception realizeField : " + e);
   }
 }
Esempio n. 9
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;
  }