Class Contact

java.lang.Object
com.codename1.contacts.Contact

public class Contact extends Object

Represents a Contact entry from the device Address Book.

The sample below demonstrates listing all the contacts within the device with their photos

Form hi = new Form("Contacts", new BoxLayout(BoxLayout.Y_AXIS));
hi.add(new InfiniteProgress());
int size = Display.getInstance().convertToPixels(5, true);
FontImage fi = FontImage.createFixed("" + FontImage.MATERIAL_PERSON, FontImage.getMaterialDesignFont(), 0xff, size, size);

Display.getInstance().scheduleBackgroundTask(() -> {
    Contact[] contacts = Display.getInstance().getAllContacts(true, true, false, true, false, false);
    Display.getInstance().callSerially(() -> {
        hi.removeAll();
        for(Contact c : contacts) {
            MultiButton mb = new MultiButton(c.getDisplayName());
            mb.setIcon(fi);
            mb.setTextLine2(c.getPrimaryPhoneNumber());
            hi.add(mb);
            mb.putClientProperty("id", c.getId());
            Display.getInstance().scheduleBackgroundTask(() -> {
                Contact cc = ContactsManager.getContactById(c.getId(), false, true, false, false, false);
                Display.getInstance().callSerially(() -> {
                    Image photo = cc.getPhoto();
                    if(photo != null) {
                        mb.setIcon(photo.fill(size, size));
                        mb.revalidate();
                    }
                });
            });
        }
        hi.getContentPane().animateLayout(150);
    });
});
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the Contact Addresses, the Hashtable contains key/value pairs where the key is a String which represents the type of the Address, types can be: "home", "work", "other" the value is an Address Object.
    long
    Gets the Contact birthday
    Gets the Contact Display Name
    Gets the Contact Emails, the Hashtable contains key/value pairs where the key is a String which represents the type of the Email, types can be: "home", "mobile", "work", "other" the value is String of the email.
    Gets Contact family name
    Gets Contact First Name
    Gets the Contact unique id
    Returns the IDs of all contacts that are linked to this contact.
    Gets Contact Note
    Gets the Contact phone numbers, the Hashtable contains key/value pairs where the key is a String which represents the type of the phone number, types can be: "home", "mobile", "work", "fax", "other" the value is String of the phone number.
    Gets the Contact photo
    Gets the primary email of this Contact, notice this can be null even though the Contact has emails declared
    Gets the primary phone number of this Contact, notice this can be null even though the Contact has phone numbers declared
    Gets Contact urls
    void
    Sets the Contact Addresses
    void
    setBirthday(long birthday)
    Sets the Contact birthday date
    void
    setDisplayName(String displayName)
    Sets the Contact display name
    void
    Sets the Contact emails
    void
    setFamilyName(String familyName)
    Sets Contact family name
    void
    Sets Contact first name
    void
    Sets the Contact unique id
    void
    Sets Contact note
    void
    setPhoneNumbers(Hashtable phoneNumbers)
    Sets Contact phone numbers
    void
    setPhoto(Image photo)
    Sets Contact photo
    void
    setPrimaryEmail(String primaryEmail)
    Sets Contact primary email
    void
    setPrimaryPhoneNumber(String primaryPhoneNumber)
    Sets Contact primary phone number
    void
    setUrls(String[] urls)
    Sets Contact urls

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    Modifier and Type
    Method
    Description
    protected Object
     
    boolean
    Indicates whether some other object is "equal to" this one.
    final Class
    Returns the runtime class of an object.
    int
    Returns a hash code value for the object.
    final void
    Wakes up a single thread that is waiting on this object's monitor.
    final void
    Wakes up all threads that are waiting on this object's monitor.
    Returns a string representation of the object.
    final void
    Causes current thread to wait until another thread invokes the method or the method for this object.
    final void
    wait(long timeout)
    Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.
    final void
    wait(long timeout, int nanos)
    Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
  • Constructor Details

    • Contact

      public Contact()
  • Method Details

    • getAddresses

      public Hashtable getAddresses()

      Gets the Contact Addresses, the Hashtable contains key/value pairs where the key is a String which represents the type of the Address, types can be: "home", "work", "other" the value is an Address Object.

      Returns

      Hashtable of available addresses

    • setAddresses

      public void setAddresses(Hashtable addresses)

      Sets the Contact Addresses

      Parameters
      • addresses: @param addresses the Hashtable contains key/value pairs where the key is a String that represents the type of the Address, types can be: "home", "work", "other" the value is an Address Object.
    • getBirthday

      public long getBirthday()

      Gets the Contact birthday

      Returns

      birth time

    • setBirthday

      public void setBirthday(long birthday)

      Sets the Contact birthday date

      Parameters
      • birthday
    • getDisplayName

      public String getDisplayName()

      Gets the Contact Display Name

      Returns

      Display Name

    • setDisplayName

      public void setDisplayName(String displayName)

      Sets the Contact display name

      Parameters
      • displayName
    • getEmails

      public Hashtable getEmails()

      Gets the Contact Emails, the Hashtable contains key/value pairs where the key is a String which represents the type of the Email, types can be: "home", "mobile", "work", "other" the value is String of the email.

      Returns

      Hashtable of available emails

    • setEmails

      public void setEmails(Hashtable emails)

      Sets the Contact emails

      Parameters
      • emails: @param emails the Hashtable contains key/value pairs where the key is a String which represents the type of the Email, types can be: "home", "mobile", "work", "other" the value is String of the email.
    • getId

      public String getId()

      Gets the Contact unique id

      Returns

      Contact unique id

    • setId

      public void setId(String id)

      Sets the Contact unique id

      Parameters
      • id
    • getFirstName

      public String getFirstName()

      Gets Contact First Name

      Returns

      Contact Name

    • setFirstName

      public void setFirstName(String name)

      Sets Contact first name

      Parameters
      • name
    • getFamilyName

      public String getFamilyName()
      Gets Contact family name
    • setFamilyName

      public void setFamilyName(String familyName)

      Sets Contact family name

      Parameters
      • familyName
    • getNote

      public String getNote()

      Gets Contact Note

      Returns

      Contact Note

    • setNote

      public void setNote(String note)

      Sets Contact note

      Parameters
      • note
    • getPhoneNumbers

      public Hashtable getPhoneNumbers()

      Gets the Contact phone numbers, the Hashtable contains key/value pairs where the key is a String which represents the type of the phone number, types can be: "home", "mobile", "work", "fax", "other" the value is String of the phone number.

      Returns

      Hashtable of available phone numbers

    • setPhoneNumbers

      public void setPhoneNumbers(Hashtable phoneNumbers)

      Sets Contact phone numbers

      Parameters
      • phoneNumbers: @param phoneNumbers the Hashtable contains key/value pairs where the key is a String which represents the type of the phone number, types can be: "home", "mobile", "work", "fax", "other" the value is String of the phone number.
    • getPhoto

      public Image getPhoto()

      Gets the Contact photo

      Returns

      the Contact Photo or null if not available

    • setPhoto

      public void setPhoto(Image photo)

      Sets Contact photo

      Parameters
      • photo
    • getPrimaryEmail

      public String getPrimaryEmail()

      Gets the primary email of this Contact, notice this can be null even though the Contact has emails declared

      Returns

      the Contact primary email or null if not declared

    • setPrimaryEmail

      public void setPrimaryEmail(String primaryEmail)

      Sets Contact primary email

      Parameters
      • primaryEmail
    • getPrimaryPhoneNumber

      public String getPrimaryPhoneNumber()

      Gets the primary phone number of this Contact, notice this can be null even though the Contact has phone numbers declared

      Returns

      the Contact primary phone number or null if not declared

    • setPrimaryPhoneNumber

      public void setPrimaryPhoneNumber(String primaryPhoneNumber)

      Sets Contact primary phone number

      Parameters
      • primaryPhoneNumber
    • getUrls

      public String[] getUrls()
      Gets Contact urls
    • setUrls

      public void setUrls(String[] urls)

      Sets Contact urls

      Parameters
      • urls
    • getLinkedContactIds

      public String[] getLinkedContactIds()

      Returns the IDs of all contacts that are linked to this contact.

      Returns

      IDs of all contacts that are linked to this contact.