Last active
July 8, 2020 09:57
-
-
Save codenameone/15f39e1eef77f6059aff to your computer and use it in GitHub Desktop.
Sample listing the contacts entry on the device using the Codename One Contacts API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample usage of Contact API.
From the Codename One project