|
|
@@ -23,8 +23,20 @@ import android.view.View;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
import com.baidu.mapapi.map.SupportMapFragment;
|
|
|
-import com.usai.Contacts.Contact;
|
|
|
-import com.usai.Contacts.ContactsManager;
|
|
|
+import com.usai.redant.rautils.contactkit.Contact;
|
|
|
+import com.usai.redant.rautils.contactkit.ContactHelper;
|
|
|
+import com.usai.redant.rautils.contactkit.ContactUIHelper;
|
|
|
+import com.usai.redant.rautils.contactkit.element.BaseElement;
|
|
|
+import com.usai.redant.rautils.contactkit.element.EmailAddress;
|
|
|
+import com.usai.redant.rautils.contactkit.element.Name;
|
|
|
+import com.usai.redant.rautils.contactkit.element.PhoneNumber;
|
|
|
+import com.usai.redant.rautils.contactkit.element.Photo;
|
|
|
+import com.usai.redant.rautils.contactkit.element.PostalAddress;
|
|
|
+import com.usai.redant.rautils.contactkit.element.WebSite;
|
|
|
+
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.util.ArrayList;
|
|
|
+
|
|
|
|
|
|
//import com.baidu.mapapi.MKGeneralListener;
|
|
|
//import com.baidu.mapapi.map.MKEvent;
|
|
|
@@ -38,7 +50,8 @@ public class InnerMapActivity extends AppCompatActivity implements BaiduMapFragm
|
|
|
private static final String LTAG = "test";
|
|
|
SupportMapFragment map;
|
|
|
|
|
|
- boolean m_bhasgoogleframework = true;
|
|
|
+ boolean m_bhasgoogleframework = true;
|
|
|
+ private InnerMapActivity self = this;
|
|
|
|
|
|
// static class MyGeneralListener implements MKGeneralListener
|
|
|
// {
|
|
|
@@ -166,7 +179,7 @@ public class InnerMapActivity extends AppCompatActivity implements BaiduMapFragm
|
|
|
}
|
|
|
// setUpMapIfNeeded();
|
|
|
|
|
|
-// m_bhasgoogleframework = false;
|
|
|
+ m_bhasgoogleframework = false;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -247,63 +260,137 @@ public class InnerMapActivity extends AppCompatActivity implements BaiduMapFragm
|
|
|
}
|
|
|
String homePage = "http://www.apexshipping.com";
|
|
|
Bitmap photo = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
|
|
|
+ byte[] data = Photo.bytesFromBitmap(photo);
|
|
|
|
|
|
- final Contact contact = new Contact();
|
|
|
- contact.setName(detail.Name);
|
|
|
- contact.setAddress(detail.Addr);
|
|
|
- contact.setNumber(detail.Tel);
|
|
|
- contact.setFax(detail.Fax);
|
|
|
- contact.setEmail(detail.Email);
|
|
|
- contact.setHomePage(homePage);
|
|
|
- contact.setPhoto(photo);
|
|
|
+ String name = detail.Name;
|
|
|
+ String addr = detail.Addr;
|
|
|
+ String tel = detail.Tel;
|
|
|
+ String fax = detail.Fax;
|
|
|
+ String email = detail.Email;
|
|
|
|
|
|
- final ContactsManager cm = new ContactsManager(this.getContentResolver());
|
|
|
- if (cm.contactExist(contact.getName())) {
|
|
|
+ final Contact contact = new Contact();
|
|
|
+ // name
|
|
|
+ Name cName = new Name(BaseElement.NEW_ELEMENT_ID);
|
|
|
+ cName.givenName = name;
|
|
|
+ contact.name = cName;
|
|
|
+
|
|
|
+ // photo
|
|
|
+ Photo cPhoto = new Photo(BaseElement.NEW_ELEMENT_ID);
|
|
|
+ cPhoto.thumbnail = data;
|
|
|
+ contact.photo = cPhoto;
|
|
|
+
|
|
|
+ // phone
|
|
|
+ PhoneNumber phoneNumber = new PhoneNumber(BaseElement.NEW_ELEMENT_ID);
|
|
|
+ phoneNumber.type = PhoneNumber.PhoneNumberType.TYPE_WORK;
|
|
|
+ phoneNumber.value = tel;
|
|
|
+
|
|
|
+ // fax
|
|
|
+ PhoneNumber faxNumber = new PhoneNumber(BaseElement.NEW_ELEMENT_ID);
|
|
|
+ faxNumber.type = PhoneNumber.PhoneNumberType.TYPE_FAX_WORK;
|
|
|
+ faxNumber.value = fax;
|
|
|
+
|
|
|
+ ArrayList<PhoneNumber> phoneNumbers = new ArrayList<>();
|
|
|
+ phoneNumbers.add(phoneNumber);
|
|
|
+ phoneNumbers.add(faxNumber);
|
|
|
+ contact.phoneNumbers = phoneNumbers;
|
|
|
+
|
|
|
+ // addr
|
|
|
+ PostalAddress postalAddress = new PostalAddress(BaseElement.NEW_ELEMENT_ID);
|
|
|
+ postalAddress.type = PostalAddress.AddressType.TYPE_WORK;
|
|
|
+ postalAddress.street = addr;
|
|
|
+
|
|
|
+ ArrayList<PostalAddress> postalAddressArrayList = new ArrayList<>();
|
|
|
+ postalAddressArrayList.add(postalAddress);
|
|
|
+ contact.postalAddresses = postalAddressArrayList;
|
|
|
+
|
|
|
+ // email
|
|
|
+ EmailAddress emailAddress = new EmailAddress(BaseElement.NEW_ELEMENT_ID);
|
|
|
+ emailAddress.type = EmailAddress.EmailType.TYPE_WORK;
|
|
|
+ emailAddress.value = email;
|
|
|
+
|
|
|
+ ArrayList<EmailAddress> emailAddressArrayList = new ArrayList<>();
|
|
|
+ emailAddressArrayList.add(emailAddress);
|
|
|
+ contact.emailAddresses = emailAddressArrayList;
|
|
|
+
|
|
|
+ // web
|
|
|
+ WebSite webSite = new WebSite(BaseElement.NEW_ELEMENT_ID);
|
|
|
+ webSite.url = homePage;
|
|
|
+
|
|
|
+ ArrayList<WebSite> webSiteArrayList = new ArrayList<>();
|
|
|
+ webSiteArrayList.add(webSite);
|
|
|
+ contact.webSites = webSiteArrayList;
|
|
|
+
|
|
|
+
|
|
|
+ final ContactHelper cm = ContactHelper.sharedHelper(getApplicationContext());
|
|
|
+ final ArrayList<Contact> contacts = cm.searchContactsByKeyword(name);
|
|
|
+ boolean exists = contacts != null && contacts.size() > 0;
|
|
|
+ if (exists) {
|
|
|
|
|
|
new AlertDialog.Builder(this)
|
|
|
.setTitle("Warning")
|
|
|
- .setMessage(contact.getName() + " has exist in contacts,do you want to update it?")
|
|
|
+ .setMessage(name + " has exist in contacts,do you want to update it?")
|
|
|
.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
- // 添加一条新记录
|
|
|
- cm.insertContact(contact,mContext);
|
|
|
-// Contact existContact = cm.searchContact(contact.getName());
|
|
|
-// String contactId = cm.getContactID(existContact.getName());
|
|
|
-// Intent editIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://com.android.contacts/contacts/"+contactId));
|
|
|
-// startActivity(editIntent);
|
|
|
+// // 添加一条新记录
|
|
|
+// cm.insertContact(contact,mContext);
|
|
|
+//// Contact existContact = cm.searchContact(contact.getName());
|
|
|
+//// String contactId = cm.getContactID(existContact.getName());
|
|
|
+//// Intent editIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://com.android.contacts/contacts/"+contactId));
|
|
|
+//// startActivity(editIntent);
|
|
|
+
|
|
|
+ ContactUIHelper.startActivityForNewContact(self, contact, 0);
|
|
|
+
|
|
|
}
|
|
|
})
|
|
|
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
|
- //Intent.ACTION_INSERT_OR_EDIT
|
|
|
- //参考 https://blog.csdn.net/mls1454001840/article/details/60764351 之二
|
|
|
- Contact existContact = cm.searchContact(contact.getName());
|
|
|
- cm.updateContact(existContact,contact);
|
|
|
-
|
|
|
- String contactId = cm.getContactID(existContact.getName());
|
|
|
- Intent editIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://com.android.contacts/contacts/"+contactId));
|
|
|
- startActivity(editIntent);
|
|
|
+// //Intent.ACTION_INSERT_OR_EDIT
|
|
|
+// //参考 https://blog.csdn.net/mls1454001840/article/details/60764351 之二
|
|
|
+// Contact existContact = cm.searchContact(contact.getName());
|
|
|
+// cm.updateContact(existContact,contact);
|
|
|
+//
|
|
|
+// String contactId = cm.getContactID(existContact.getName());
|
|
|
+// Intent editIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://com.android.contacts/contacts/"+contactId));
|
|
|
+// startActivity(editIntent);
|
|
|
//
|
|
|
// // 显示编辑界面
|
|
|
// String contactId = cm.getContactID(existContact.getName());
|
|
|
// cm.editContact(contactId,mContext);
|
|
|
|
|
|
+ Contact oldContact = contacts.get(0);
|
|
|
+
|
|
|
+ // 删除旧的
|
|
|
+ ArrayList<Contact> deleteArr = new ArrayList<>();
|
|
|
+ deleteArr.add(oldContact);
|
|
|
+ cm.deleteContact(deleteArr);
|
|
|
+
|
|
|
+ // 导入新的
|
|
|
+ ArrayList<Contact> newContacts = new ArrayList<>();
|
|
|
+ newContacts.add(contact);
|
|
|
+ ArrayList<Uri> uris = cm.insertContact(newContacts);
|
|
|
+
|
|
|
+ if (uris != null && uris.size() > 0) {
|
|
|
+ // 显示编辑界面
|
|
|
+ ContactUIHelper.startActivityForEditContact(self,uris.get(0));
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
})
|
|
|
.show();
|
|
|
} else {
|
|
|
// 自动保存,然后显示编辑
|
|
|
-// cm.addContact(contact,true);
|
|
|
-// // 显示编辑界面
|
|
|
-// String contactId = cm.getContactID(contact.getName());
|
|
|
-// editContact(contactId);
|
|
|
+//// cm.addContact(contact,true);
|
|
|
+//// // 显示编辑界面
|
|
|
+//// String contactId = cm.getContactID(contact.getName());
|
|
|
+//// editContact(contactId);
|
|
|
+//
|
|
|
+// // 需要用户手动保存
|
|
|
+// cm.insertContact(contact,mContext);
|
|
|
|
|
|
- // 需要用户手动保存
|
|
|
- cm.insertContact(contact,mContext);
|
|
|
+ ContactUIHelper.startActivityForNewContact(self, contact, 0);
|
|
|
}
|
|
|
|
|
|
}
|