private void cloneContact() {
Contacts.find(new ContactFields("nickname", "name"), new ContactFindCallback() {
@Override
public void onSuccess(JsArray<Contact> contacts) {
if (contacts.length() > 0) {
final Contact contact = contacts.get(0);
final Contact clone = contact.clone();
clone.getName().setGivenName(clone.getName().getGivenName() + "-Clone");
clone.getName().setFamilyName(clone.getName().getFamilyName() + "-Clone");
clone.setNickname(clone.getNickname() + "-Clone");
clone.setDisplayName(clone.getDisplayName() + "-Clone");
clone.save(new Callback() {
@Override
public void onSuccess() {
text.setHTML(clone.getNickname() +
" (" + clone.getName().getGivenName() +
" " + clone.getName().getFamilyName() +
") saved.<br/>");
}
@Override
public void onError(ContactError error) {
text.setHTML(text.getHTML() + "<br/> Failed to save cloned contact. " + error.getCode());