Search in sources :

Example 1 with Contact

use of com.codename1.contacts.Contact in project CodenameOne by codenameone.

the class ContactsModel method getContactAsHashtable.

private Hashtable getContactAsHashtable(Contact c) {
    Hashtable table = new Hashtable();
    String id = null;
    String fname;
    String lname;
    String displayName;
    Image image;
    String phone;
    String email;
    if (c == null) {
        fname = "Loading...";
        lname = "Loading...";
        displayName = "Loading...";
        image = placeHolder;
        phone = "Loading...";
        email = "Loading...";
    } else {
        id = c.getId();
        fname = c.getFirstName();
        lname = c.getFamilyName();
        displayName = c.getDisplayName();
        image = c.getPhoto();
        if (image == null) {
            image = placeHolder;
        }
        phone = getContactPhoneNumber(c);
        email = getContactEmail(c);
    }
    addAttribute(table, "id", id);
    addAttribute(table, "fname", fname);
    addAttribute(table, "lname", lname);
    addAttribute(table, "displayName", displayName);
    addAttribute(table, "icon", image);
    addAttribute(table, "phone", phone);
    addAttribute(table, "email", email);
    // something is missing there is the ability to get the Contact.
    if (c != null) {
        table.put("contact", c);
    }
    return table;
}
Also used : Hashtable(java.util.Hashtable) Image(com.codename1.ui.Image)

Example 2 with Contact

use of com.codename1.contacts.Contact in project CodenameOne by codenameone.

the class IOSImplementation method getContactById.

@Override
public Contact getContactById(String id, boolean includesFullName, boolean includesPicture, boolean includesNumbers, boolean includesEmail, boolean includeAddress) {
    if (!nativeInstance.checkContactsUsage()) {
        throw new RuntimeException("Please add the ios.NSContactsUsageDescription build hint");
    }
    int recId = Integer.parseInt(id);
    Contact c = new Contact();
    c.setId(id);
    c.setAddresses(new Hashtable());
    if (includeAddress) {
        // This is a hack to make sure that
        // Address and its methods aren't stripped out by the BytecodeCompiler
        Address tmp = new Address();
    }
    c.setEmails(new Hashtable());
    c.setPhoneNumbers(new Hashtable());
    nativeInstance.updatePersonWithRecordID(recId, c, includesFullName, includesPicture, includesNumbers, includesEmail, includeAddress);
    return c;
}
Also used : Address(com.codename1.contacts.Address) Hashtable(java.util.Hashtable) Contact(com.codename1.contacts.Contact)

Example 3 with Contact

use of com.codename1.contacts.Contact in project CodenameOne by codenameone.

the class JavaSEPort method createContact.

public String createContact(String firstName, String familyName, String officePhone, String homePhone, String cellPhone, String email) {
    if (!checkForPermission("android.permission.WRITE_CONTACTS", "This is required to create a contact")) {
        return null;
    }
    if (contacts == null) {
        contacts = initContacts();
    }
    // get a unique id for the new contact
    String id = "" + contacts.size();
    while (contacts.get(id) != null) {
        id = "" + (contacts.size() + 1);
    }
    Contact contact = new Contact();
    contact.setId(id);
    String displayName = "";
    if (firstName != null) {
        displayName += firstName;
    }
    if (familyName != null) {
        displayName += " " + familyName;
    }
    contact.setDisplayName(displayName);
    contact.setFirstName(firstName);
    contact.setFamilyName(familyName);
    Hashtable phones = new Hashtable();
    if (cellPhone != null) {
        phones.put("mobile", cellPhone);
        contact.setPrimaryPhoneNumber(cellPhone);
    }
    if (homePhone != null) {
        phones.put("home", homePhone);
    }
    if (officePhone != null) {
        phones.put("work", officePhone);
    }
    contact.setPhoneNumbers(phones);
    if (email != null) {
        Hashtable emails = new Hashtable();
        emails.put("work", email);
        contact.setEmails(emails);
        contact.setPrimaryEmail(email);
    }
    contacts.put(id, contact);
    return id;
}
Also used : Contact(com.codename1.contacts.Contact)

Example 4 with Contact

use of com.codename1.contacts.Contact in project CodenameOne by codenameone.

the class JavaSEPort method getContactById.

@Override
public Contact getContactById(String id, boolean includesFullName, boolean includesPicture, boolean includesNumbers, boolean includesEmail, boolean includeAddress) {
    if (!checkForPermission("android.permission.READ_CONTACTS", "This is required to get the contacts")) {
        return null;
    }
    Contact c = new Contact();
    Contact contact = getContactById(id);
    c.setId(contact.getId());
    c.setDisplayName(contact.getDisplayName());
    if (includesPicture) {
        c.setPhoto(contact.getPhoto());
    }
    if (includesFullName) {
        c.setFirstName(contact.getFirstName());
        c.setFamilyName(contact.getFamilyName());
    }
    if (includesNumbers) {
        c.setPhoneNumbers(contact.getPhoneNumbers());
    }
    if (includesEmail) {
        c.setEmails(contact.getEmails());
    }
    if (includeAddress) {
        c.setAddresses(contact.getAddresses());
    }
    return c;
}
Also used : Contact(com.codename1.contacts.Contact)

Example 5 with Contact

use of com.codename1.contacts.Contact in project CodenameOne by codenameone.

the class EmailShare method share.

/**
 * {@inheritDoc}
 */
public void share(final String toShare, final String image, final String mimeType) {
    final Form currentForm = Display.getInstance().getCurrent();
    final Form contactsForm = new Form("Contacts");
    contactsForm.setLayout(new BorderLayout());
    contactsForm.setScrollable(false);
    contactsForm.addComponent(BorderLayout.CENTER, new Label("Please wait..."));
    contactsForm.show();
    Display.getInstance().startThread(new Runnable() {

        public void run() {
            String[] ids = ContactsManager.getAllContacts();
            if (ids == null || ids.length == 0) {
                Display.getInstance().callSerially(new Runnable() {

                    public void run() {
                        Dialog.show("Failed to Share", "No Contacts Found", "Ok", null);
                        currentForm.showBack();
                    }
                });
                return;
            }
            ContactsModel model = new ContactsModel(ids);
            final List contacts = new List(model);
            contacts.setRenderer(createListRenderer());
            Display.getInstance().callSerially(new Runnable() {

                public void run() {
                    contacts.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent evt) {
                            final ShareForm[] f = new ShareForm[1];
                            Hashtable contact = (Hashtable) contacts.getSelectedItem();
                            if (image == null) {
                                f[0] = new ShareForm(contactsForm, "Send Email", (String) contact.get("email"), toShare, new ActionListener() {

                                    public void actionPerformed(ActionEvent evt) {
                                        String[] recieptents = new String[1];
                                        recieptents[0] = f[0].getTo();
                                        Message msg = new Message(toShare);
                                        Message.sendMessage(recieptents, "share", msg);
                                        finish();
                                    }
                                });
                                f[0].show();
                            } else {
                                f[0] = new ShareForm(contactsForm, "Send Email", (String) contact.get("email"), toShare, image, new ActionListener() {

                                    public void actionPerformed(ActionEvent evt) {
                                        String[] recieptents = new String[1];
                                        recieptents[0] = f[0].getTo();
                                        Message msg = new Message(toShare);
                                        msg.setAttachment(image);
                                        msg.setMimeType(mimeType);
                                        Message.sendMessage(recieptents, "share", msg);
                                        finish();
                                    }
                                });
                                f[0].show();
                            }
                        }
                    });
                    contactsForm.addComponent(BorderLayout.CENTER, contacts);
                    Command back = new Command("Back") {

                        public void actionPerformed(ActionEvent evt) {
                            currentForm.showBack();
                        }
                    };
                    contactsForm.addCommand(back);
                    contactsForm.setBackCommand(back);
                    contactsForm.revalidate();
                }
            });
        }
    }, "Email Thread").start();
}
Also used : Message(com.codename1.messaging.Message) ActionEvent(com.codename1.ui.events.ActionEvent) Hashtable(java.util.Hashtable) BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionListener(com.codename1.ui.events.ActionListener) ContactsModel(com.codename1.contacts.ContactsModel)

Aggregations

Contact (com.codename1.contacts.Contact)6 Hashtable (java.util.Hashtable)6 Address (com.codename1.contacts.Address)4 IOException (java.io.IOException)3 Cursor (android.database.Cursor)2 ContactsModel (com.codename1.contacts.ContactsModel)2 Image (com.codename1.ui.Image)2 ActionEvent (com.codename1.ui.events.ActionEvent)2 ActionListener (com.codename1.ui.events.ActionListener)2 BorderLayout (com.codename1.ui.layouts.BorderLayout)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 Message (com.codename1.messaging.Message)1 EncodedImage (com.codename1.ui.EncodedImage)1 BufferedImage (java.awt.image.BufferedImage)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1