|
|
@@ -1,9 +1,15 @@
|
|
|
package com.usai.apex;
|
|
|
|
|
|
+import android.app.AlertDialog;
|
|
|
+import android.content.ContentResolver;
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
import android.content.pm.PackageInfo;
|
|
|
import android.content.pm.PackageManager.NameNotFoundException;
|
|
|
+import android.database.Cursor;
|
|
|
+import android.net.Uri;
|
|
|
import android.os.Bundle;
|
|
|
+import android.provider.ContactsContract;
|
|
|
import android.support.v4.app.Fragment;
|
|
|
import android.support.v4.app.FragmentManager;
|
|
|
import android.support.v4.app.FragmentTransaction;
|
|
|
@@ -18,10 +24,12 @@ import android.widget.TextView;
|
|
|
|
|
|
import com.baidu.mapapi.map.SupportMapFragment;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+
|
|
|
//import com.baidu.mapapi.MKGeneralListener;
|
|
|
//import com.baidu.mapapi.map.MKEvent;
|
|
|
|
|
|
-public class InnerMapActivity extends AppCompatActivity
|
|
|
+public class InnerMapActivity extends AppCompatActivity implements BaiduMapFragment.BaiduMarkerClickListener,ServiceLocationFragment.MarkerClickListener
|
|
|
{
|
|
|
// public static boolean m_bKeyRight = true;
|
|
|
// BMapManager mBMapManager = null;
|
|
|
@@ -166,13 +174,14 @@ public class InnerMapActivity extends AppCompatActivity
|
|
|
{
|
|
|
setContentView(R.layout.activity_inner_map);
|
|
|
slFragment = new ServiceLocationFragment();
|
|
|
-
|
|
|
+ ((ServiceLocationFragment)slFragment).markerClickListener = this;
|
|
|
FragmentTransaction ft = getSupportFragmentManager()
|
|
|
.beginTransaction();
|
|
|
ft.replace(R.id.inner_map, slFragment);
|
|
|
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
|
|
|
ft.addToBackStack("Location");
|
|
|
ft.commit();
|
|
|
+
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -194,9 +203,13 @@ public class InnerMapActivity extends AppCompatActivity
|
|
|
FragmentManager manager = getSupportFragmentManager();
|
|
|
manager.beginTransaction().add(R.id.inner_map, f, "map_fragment")
|
|
|
.commit();
|
|
|
+ f.markerClickListener = this;
|
|
|
}
|
|
|
|
|
|
setCustomActionBar();
|
|
|
+
|
|
|
+// LocationDetail detail = new LocationDetail("Kerry Freight (USA), Inc","3200 NW 67th Ave. Bldg. 3 Suite 390 Miami, FL 33122 Miami","+1(305)402-0637","+1(305)747-5035",null,"mario.alfonso@kerrylogistics.com");
|
|
|
+// markerClicked(detail);
|
|
|
}
|
|
|
|
|
|
// @Override
|
|
|
@@ -220,4 +233,187 @@ public class InnerMapActivity extends AppCompatActivity
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void markerClicked(LocationDetail detail) {
|
|
|
+
|
|
|
+ if (detail == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ ArrayList<String> phoneArr = new ArrayList<>();
|
|
|
+ phoneArr.add(detail.Tel);
|
|
|
+ ArrayList<String> faxArr = new ArrayList<>();
|
|
|
+ faxArr.add(detail.Fax);
|
|
|
+ ArrayList<String> emailArr = new ArrayList<>();
|
|
|
+ emailArr.add(detail.Email);
|
|
|
+
|
|
|
+ final Contact newContact = new Contact();
|
|
|
+ newContact.name = detail.Name;
|
|
|
+ newContact.street = detail.Addr;
|
|
|
+ newContact.phoneArray = phoneArr;
|
|
|
+ newContact.faxArray = faxArr;
|
|
|
+ newContact.emailArray = emailArr;
|
|
|
+
|
|
|
+ Contact contact = null;
|
|
|
+ try {
|
|
|
+ contact = getContact(newContact.name);
|
|
|
+ } catch (Throwable throwable) {
|
|
|
+ throwable.printStackTrace();
|
|
|
+ contact = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (contact == null) {
|
|
|
+
|
|
|
+ insertContact(newContact);
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ final Contact deleteContact = contact;
|
|
|
+ new AlertDialog.Builder(this)
|
|
|
+ .setTitle("Warning")
|
|
|
+ .setMessage(contact.name + " has exist in Contacts,do you wan to update it?")
|
|
|
+ .setNegativeButton("No", new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ insertContact(newContact);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ try {
|
|
|
+ deleteContact(deleteContact.contactId);
|
|
|
+ insertContact(newContact);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .show();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void deleteContact(String contactId)throws Exception{
|
|
|
+
|
|
|
+ ContentResolver cr = getContentResolver();
|
|
|
+
|
|
|
+ //第一步先删除Contacts表中的数据
|
|
|
+ cr.delete(ContactsContract.Contacts.CONTENT_URI, ContactsContract.Contacts._ID + " =?", new String[]{contactId+""});
|
|
|
+ //第二步再删除RawContacts表的数据
|
|
|
+ cr.delete(ContactsContract.RawContacts.CONTENT_URI, ContactsContract.RawContacts.CONTACT_ID + " =?", new String[]{contactId+""});
|
|
|
+ }
|
|
|
+
|
|
|
+ public Contact getContact(String contactName) throws Throwable {
|
|
|
+
|
|
|
+ if (contactName == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取联系人信息的Uri
|
|
|
+ Uri uri = ContactsContract.Contacts.CONTENT_URI;
|
|
|
+ //获取ContentResolver
|
|
|
+ ContentResolver contentResolver = getContentResolver();
|
|
|
+ //查询数据,返回Cursor
|
|
|
+ Cursor cursor = contentResolver.query(uri, null, null, null, null);
|
|
|
+
|
|
|
+
|
|
|
+ while (cursor.moveToNext()) {
|
|
|
+
|
|
|
+ //获取联系人的ID
|
|
|
+ String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
|
|
|
+ //获取联系人的姓名
|
|
|
+ String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
|
|
|
+
|
|
|
+ String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (name != null && name.equals(contactName)) {
|
|
|
+
|
|
|
+ Contact contact = new Contact();
|
|
|
+
|
|
|
+ contact.name = name;
|
|
|
+ contact.contactId = contactId;
|
|
|
+ contact.uri = ContactsContract.Contacts.getLookupUri(Integer.valueOf(contactId), lookupKey);
|
|
|
+ return contact;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void insertContact(Contact contact) {
|
|
|
+
|
|
|
+ if (contact == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // Creates a new Intent to insert a contact
|
|
|
+ Intent intent = new Intent(ContactsContract.Intents.Insert.ACTION);
|
|
|
+// Sets the MIME type to match the Contacts Provider
|
|
|
+ intent.setType(ContactsContract.RawContacts.CONTENT_TYPE);
|
|
|
+
|
|
|
+ // Name
|
|
|
+ intent.putExtra(ContactsContract.Intents.Insert.NAME,contact.name);
|
|
|
+
|
|
|
+
|
|
|
+ // Photo
|
|
|
+// editIntent.putExtra(ContactsContract.Intents.ATTACH_IMAGE, ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK);
|
|
|
+
|
|
|
+
|
|
|
+ // HomePage
|
|
|
+// editIntent.putExtra(ContactsContract.Intents.Insert.IM_HANDLE,);
|
|
|
+// editIntent.putExtra(ContactsContract.Intents.Insert., ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK);
|
|
|
+
|
|
|
+ // Street
|
|
|
+ if (contact.city == null) {
|
|
|
+ contact.city = "";
|
|
|
+ }
|
|
|
+ intent.putExtra(ContactsContract.Intents.Insert.POSTAL, contact.city + " " + contact.street);
|
|
|
+ intent.putExtra(ContactsContract.Intents.Insert.POSTAL_TYPE, ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK);
|
|
|
+
|
|
|
+ // Phone
|
|
|
+ for (int i = 0;i < contact.phoneArray.size(); i++) {
|
|
|
+ String phone = contact.phoneArray.get(i);
|
|
|
+ // Inserts a phone number
|
|
|
+ intent.putExtra(ContactsContract.Intents.Insert.PHONE, phone);
|
|
|
+ intent.putExtra(ContactsContract.Intents.Insert.PHONE_TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_WORK);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Fax
|
|
|
+ for (int i = 0;i < contact.faxArray.size(); i++) {
|
|
|
+ String fax = contact.faxArray.get(i);
|
|
|
+ // Inserts a phone number
|
|
|
+ intent.putExtra(ContactsContract.Intents.Insert.PHONE, fax);
|
|
|
+ intent.putExtra(ContactsContract.Intents.Insert.PHONE_TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_FAX_WORK);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Email
|
|
|
+ for (int i = 0;i < contact.emailArray.size(); i++) {
|
|
|
+ String email = contact.emailArray.get(i);
|
|
|
+ // Inserts a phone number
|
|
|
+ intent.putExtra(ContactsContract.Intents.Insert.EMAIL, email);
|
|
|
+ intent.putExtra(ContactsContract.Intents.Insert.EMAIL_TYPE, ContactsContract.CommonDataKinds.Email.TYPE_WORK);
|
|
|
+ }
|
|
|
+
|
|
|
+ startActivity(intent);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public class Contact {
|
|
|
+ ArrayList<String> phoneArray = new ArrayList<>();
|
|
|
+ ArrayList<String> emailArray = new ArrayList<>();
|
|
|
+ ArrayList<String> faxArray = new ArrayList<>();
|
|
|
+ String city;
|
|
|
+ String street;
|
|
|
+ String homePage;
|
|
|
+ String photo;
|
|
|
+ String name;
|
|
|
+
|
|
|
+ Uri uri;
|
|
|
+ String contactId;
|
|
|
+ }
|
|
|
}
|