Started to rework contact editor
This commit is contained in:
parent
4d976609bf
commit
2a4a003780
3 changed files with 87 additions and 136 deletions
|
@ -21,19 +21,16 @@ package org.linphone;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.Serializable;
|
||||||
import java.io.SyncFailedException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.linphone.compatibility.Compatibility;
|
|
||||||
import org.linphone.core.LinphoneProxyConfig;
|
|
||||||
import org.linphone.mediastream.Log;
|
|
||||||
import org.linphone.mediastream.Version;
|
import org.linphone.mediastream.Version;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.ContentProviderOperation;
|
import android.app.Fragment;
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
@ -49,8 +46,6 @@ import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.provider.ContactsContract;
|
|
||||||
import android.app.Fragment;
|
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.support.v4.content.CursorLoader;
|
import android.support.v4.content.CursorLoader;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
|
@ -78,28 +73,24 @@ public class ContactEditorFragment extends Fragment {
|
||||||
|
|
||||||
private boolean isNewContact = true;
|
private boolean isNewContact = true;
|
||||||
private LinphoneContact contact;
|
private LinphoneContact contact;
|
||||||
private int contactID;
|
private List<NewOrUpdatedNumberOrAddress> numbersAndAddresses;
|
||||||
//private List<NewOrUpdatedNumberOrAddress> numbersAndAddresses;
|
|
||||||
private ArrayList<ContentProviderOperation> ops;
|
|
||||||
private int firstSipAddressIndex = -1;
|
private int firstSipAddressIndex = -1;
|
||||||
private LinearLayout sipAddresses, numbers;
|
private LinearLayout sipAddresses, numbers;
|
||||||
private String newSipOrNumberToAdd;
|
private String newSipOrNumberToAdd;
|
||||||
private ContactsManager contactsManager;
|
|
||||||
private Uri imageToUploadUri;
|
private Uri imageToUploadUri;
|
||||||
private String fileToUploadPath;
|
private String fileToUploadPath;
|
||||||
private Bitmap imageToUpload;
|
private Bitmap imageToUpload;
|
||||||
byte[] photoToAdd;
|
private byte[] photoToAdd;
|
||||||
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
this.inflater = inflater;
|
this.inflater = inflater;
|
||||||
|
|
||||||
/*contact = null;
|
contact = null;
|
||||||
if (getArguments() != null) {
|
if (getArguments() != null) {
|
||||||
if (getArguments().getSerializable("Contact") != null) {
|
Serializable obj = getArguments().getSerializable("Contact");
|
||||||
contact = (LinphoneContact) getArguments().getSerializable("Contact");
|
if (obj != null) {
|
||||||
|
contact = (LinphoneContact) obj;
|
||||||
isNewContact = false;
|
isNewContact = false;
|
||||||
contactID = Integer.parseInt(contact.getID());
|
|
||||||
contact.refresh(getActivity().getContentResolver());
|
|
||||||
if (getArguments().getString("NewSipAdress") != null) {
|
if (getArguments().getString("NewSipAdress") != null) {
|
||||||
newSipOrNumberToAdd = getArguments().getString("NewSipAdress");
|
newSipOrNumberToAdd = getArguments().getString("NewSipAdress");
|
||||||
}
|
}
|
||||||
|
@ -110,8 +101,6 @@ public class ContactEditorFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contactsManager = ContactsManager.getInstance();
|
|
||||||
|
|
||||||
view = inflater.inflate(R.layout.contact_edit, container, false);
|
view = inflater.inflate(R.layout.contact_edit, container, false);
|
||||||
|
|
||||||
phoneNumbersSection = (LinearLayout) view.findViewById(R.id.phone_numbers);
|
phoneNumbersSection = (LinearLayout) view.findViewById(R.id.phone_numbers);
|
||||||
|
@ -151,10 +140,10 @@ public class ContactEditorFragment extends Fragment {
|
||||||
getFragmentManager().popBackStackImmediate();
|
getFragmentManager().popBackStackImmediate();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
contactsManager.createNewContact(ops, firstName.getText().toString(), lastName.getText().toString());
|
//contactsManager.createNewContact(ops, firstName.getText().toString(), lastName.getText().toString());
|
||||||
setContactPhoto();
|
setContactPhoto();
|
||||||
} else {
|
} else {
|
||||||
contactsManager.updateExistingContact(ops, contact, firstName.getText().toString(), lastName.getText().toString());
|
//contactsManager.updateExistingContact(ops, contact, firstName.getText().toString(), lastName.getText().toString());
|
||||||
setContactPhoto();
|
setContactPhoto();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,32 +151,23 @@ public class ContactEditorFragment extends Fragment {
|
||||||
numberOrAddress.save();
|
numberOrAddress.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
/*try {
|
||||||
getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
|
getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
|
||||||
addLinphoneFriendIfNeeded();
|
addLinphoneFriendIfNeeded();
|
||||||
removeLinphoneTagIfNeeded();
|
removeLinphoneTagIfNeeded();
|
||||||
contactsManager.prepareContactsInBackground();
|
contactsManager.prepareContactsInBackground();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
if(isNewContact) {
|
if(!isNewContact) {
|
||||||
getFragmentManager().popBackStackImmediate();
|
|
||||||
} else {
|
|
||||||
if (LinphoneActivity.instance().getResources().getBoolean(R.bool.isTablet)) {
|
if (LinphoneActivity.instance().getResources().getBoolean(R.bool.isTablet)) {
|
||||||
if(ContactsListFragment.isInstanciated()) {
|
if(ContactsListFragment.isInstanciated()) {
|
||||||
ContactsListFragment.instance().invalidate();
|
ContactsListFragment.instance().invalidate();
|
||||||
}
|
}
|
||||||
getFragmentManager().popBackStackImmediate();
|
|
||||||
} else {
|
|
||||||
LinphoneContact updatedContact = contactsManager.findContactWithDisplayName(contactsManager.getDisplayName(firstName.getText().toString(), lastName.getText().toString()));
|
|
||||||
if (updatedContact != null) {
|
|
||||||
LinphoneActivity.instance().displayContact(updatedContact, false);
|
|
||||||
} else {
|
|
||||||
LinphoneActivity.instance().displayContacts(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
getFragmentManager().popBackStackImmediate();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -242,8 +222,8 @@ public class ContactEditorFragment extends Fragment {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!isNewContact) {
|
if (!isNewContact) {
|
||||||
String fn = findContactFirstName(String.valueOf(contactID));
|
String fn = contact.getFirstName();
|
||||||
String ln = findContactLastName(String.valueOf(contactID));
|
String ln = contact.getLastName();
|
||||||
if (fn != null || ln != null) {
|
if (fn != null || ln != null) {
|
||||||
firstName.setText(fn);
|
firstName.setText(fn);
|
||||||
lastName.setText(ln);
|
lastName.setText(ln);
|
||||||
|
@ -282,12 +262,7 @@ public class ContactEditorFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
contactPicture = (ImageView) view.findViewById(R.id.contact_picture);
|
contactPicture = (ImageView) view.findViewById(R.id.contact_picture);
|
||||||
if (contact != null && contact.getPhotoUri() != null) {
|
LinphoneUtils.setImagePictureFromUri(getActivity(), contactPicture, contact.getPhotoUri(), contact.getThumbnailUri());
|
||||||
InputStream input = Compatibility.getContactPictureInputStream(getActivity().getContentResolver(), contact.getID());
|
|
||||||
contactPicture.setImageBitmap(BitmapFactory.decodeStream(input));
|
|
||||||
} else {
|
|
||||||
contactPicture.setImageResource(R.drawable.avatar);
|
|
||||||
}
|
|
||||||
|
|
||||||
contactPicture.setOnClickListener(new OnClickListener() {
|
contactPicture.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -316,8 +291,7 @@ public class ContactEditorFragment extends Fragment {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ops = new ArrayList<ContentProviderOperation>();
|
lastName.requestFocus();
|
||||||
lastName.requestFocus();*/
|
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
@ -346,7 +320,7 @@ public class ContactEditorFragment extends Fragment {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*private void pickImage() {
|
private void pickImage() {
|
||||||
imageToUploadUri = null;
|
imageToUploadUri = null;
|
||||||
final List<Intent> cameraIntents = new ArrayList<Intent>();
|
final List<Intent> cameraIntents = new ArrayList<Intent>();
|
||||||
final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||||
|
@ -480,8 +454,8 @@ public class ContactEditorFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setContactPhoto(){
|
private void setContactPhoto() {
|
||||||
ContentResolver cr = getActivity().getContentResolver();
|
/*ContentResolver cr = getActivity().getContentResolver();
|
||||||
Uri updateUri = ContactsContract.Data.CONTENT_URI;
|
Uri updateUri = ContactsContract.Data.CONTENT_URI;
|
||||||
|
|
||||||
if(photoToAdd != null){
|
if(photoToAdd != null){
|
||||||
|
@ -495,7 +469,7 @@ public class ContactEditorFragment extends Fragment {
|
||||||
);
|
);
|
||||||
} else { //update contact picture
|
} else { //update contact picture
|
||||||
String w = ContactsContract.Data.CONTACT_ID + "='"
|
String w = ContactsContract.Data.CONTACT_ID + "='"
|
||||||
+ contact.getID() + "' AND "
|
+ contact.getAndroidId() + "' AND "
|
||||||
+ ContactsContract.Data.MIMETYPE + " = '"
|
+ ContactsContract.Data.MIMETYPE + " = '"
|
||||||
+ ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'";
|
+ ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'";
|
||||||
|
|
||||||
|
@ -531,18 +505,17 @@ public class ContactEditorFragment extends Fragment {
|
||||||
queryCursor.close();
|
queryCursor.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private LinearLayout initNumbersFields(final Contact contact) {
|
private LinearLayout initNumbersFields(final LinphoneContact contact) {
|
||||||
LinearLayout controls = (LinearLayout) view.findViewById(R.id.controls_numbers);
|
LinearLayout controls = (LinearLayout) view.findViewById(R.id.controls_numbers);
|
||||||
controls.removeAllViews();
|
controls.removeAllViews();
|
||||||
|
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
for (String numberOrAddress : contact.getNumbersOrAddresses()) {
|
for (LinphoneNumberOrAddress numberOrAddress : contact.getNumbersOrAddresses()) {
|
||||||
boolean isSip = LinphoneUtils.isStrictSipAddress(numberOrAddress) || !LinphoneUtils.isNumberAddress(numberOrAddress);
|
if (!numberOrAddress.isSIPAddress()) {
|
||||||
if(!isSip) {
|
View view = displayNumberOrAddress(controls, numberOrAddress.getValue());
|
||||||
View view = displayNumberOrAddress(controls, numberOrAddress);
|
|
||||||
if (view != null)
|
if (view != null)
|
||||||
controls.addView(view);
|
controls.addView(view);
|
||||||
}
|
}
|
||||||
|
@ -565,15 +538,14 @@ public class ContactEditorFragment extends Fragment {
|
||||||
return controls;
|
return controls;
|
||||||
}
|
}
|
||||||
|
|
||||||
private LinearLayout initSipAddressFields(final Contact contact) {
|
private LinearLayout initSipAddressFields(final LinphoneContact contact) {
|
||||||
LinearLayout controls = (LinearLayout) view.findViewById(R.id.controls_sip_address);
|
LinearLayout controls = (LinearLayout) view.findViewById(R.id.controls_sip_address);
|
||||||
controls.removeAllViews();
|
controls.removeAllViews();
|
||||||
|
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
for (String numberOrAddress : contact.getNumbersOrAddresses()) {
|
for (LinphoneNumberOrAddress numberOrAddress : contact.getNumbersOrAddresses()) {
|
||||||
boolean isSip = LinphoneUtils.isStrictSipAddress(numberOrAddress) || !LinphoneUtils.isNumberAddress(numberOrAddress);
|
if (numberOrAddress.isSIPAddress()) {
|
||||||
if(isSip) {
|
View view = displayNumberOrAddress(controls, numberOrAddress.getValue());
|
||||||
View view = displayNumberOrAddress(controls, numberOrAddress);
|
|
||||||
if (view != null)
|
if (view != null)
|
||||||
controls.addView(view);
|
controls.addView(view);
|
||||||
}
|
}
|
||||||
|
@ -582,7 +554,7 @@ public class ContactEditorFragment extends Fragment {
|
||||||
|
|
||||||
if (newSipOrNumberToAdd != null) {
|
if (newSipOrNumberToAdd != null) {
|
||||||
boolean isSip = LinphoneUtils.isStrictSipAddress(newSipOrNumberToAdd) || !LinphoneUtils.isNumberAddress(newSipOrNumberToAdd);
|
boolean isSip = LinphoneUtils.isStrictSipAddress(newSipOrNumberToAdd) || !LinphoneUtils.isNumberAddress(newSipOrNumberToAdd);
|
||||||
if(isSip) {
|
if (isSip) {
|
||||||
View view = displayNumberOrAddress(controls, newSipOrNumberToAdd);
|
View view = displayNumberOrAddress(controls, newSipOrNumberToAdd);
|
||||||
if (view != null)
|
if (view != null)
|
||||||
controls.addView(view);
|
controls.addView(view);
|
||||||
|
@ -705,40 +677,8 @@ public class ContactEditorFragment extends Fragment {
|
||||||
|
|
||||||
controls.addView(view);
|
controls.addView(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String findContactFirstName(String contactID) {
|
|
||||||
Cursor c = getActivity().getContentResolver().query(ContactsContract.Data.CONTENT_URI,
|
|
||||||
new String[]{ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME},
|
|
||||||
ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "=?",
|
|
||||||
new String[]{contactID, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE}, null);
|
|
||||||
if (c != null) {
|
|
||||||
String result = null;
|
|
||||||
if (c.moveToFirst()) {
|
|
||||||
result = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
|
|
||||||
}
|
|
||||||
c.close();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String findContactLastName(String contactID) {
|
|
||||||
Cursor c = getActivity().getContentResolver().query(ContactsContract.Data.CONTENT_URI,
|
|
||||||
new String[]{ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME},
|
|
||||||
ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "=?",
|
|
||||||
new String[]{contactID, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE}, null);
|
|
||||||
if (c != null) {
|
|
||||||
String result = null;
|
|
||||||
if (c.moveToFirst()) {
|
|
||||||
result = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
|
|
||||||
}
|
|
||||||
c.close();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addLinphoneFriendIfNeeded(){
|
/*private void addLinphoneFriendIfNeeded(){
|
||||||
for (NewOrUpdatedNumberOrAddress numberOrAddress : numbersAndAddresses) {
|
for (NewOrUpdatedNumberOrAddress numberOrAddress : numbersAndAddresses) {
|
||||||
if(numberOrAddress.newNumberOrAddress != null && numberOrAddress.isSipAddress) {
|
if(numberOrAddress.newNumberOrAddress != null && numberOrAddress.isSipAddress) {
|
||||||
if(isNewContact){
|
if(isNewContact){
|
||||||
|
@ -758,9 +698,9 @@ public class ContactEditorFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
private void removeLinphoneTagIfNeeded(){
|
/*private void removeLinphoneTagIfNeeded(){
|
||||||
if(!isNewContact) {
|
if(!isNewContact) {
|
||||||
boolean areAllSipFielsEmpty = true;
|
boolean areAllSipFielsEmpty = true;
|
||||||
for (NewOrUpdatedNumberOrAddress nounoa : numbersAndAddresses) {
|
for (NewOrUpdatedNumberOrAddress nounoa : numbersAndAddresses) {
|
||||||
|
@ -773,7 +713,7 @@ public class ContactEditorFragment extends Fragment {
|
||||||
contactsManager.removeLinphoneContactTag(contact);
|
contactsManager.removeLinphoneContactTag(contact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
class NewOrUpdatedNumberOrAddress {
|
class NewOrUpdatedNumberOrAddress {
|
||||||
private String oldNumberOrAddress;
|
private String oldNumberOrAddress;
|
||||||
|
@ -822,32 +762,10 @@ public class ContactEditorFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete() {
|
public void delete() {
|
||||||
if(contact != null) {
|
|
||||||
if (isSipAddress) {
|
|
||||||
if (contact.hasFriends()) {
|
|
||||||
ContactsManager.getInstance().removeFriend(oldNumberOrAddress);
|
|
||||||
} else {
|
|
||||||
Compatibility.deleteSipAddressFromContact(ops, oldNumberOrAddress, String.valueOf(contactID));
|
|
||||||
}
|
|
||||||
if (getResources().getBoolean(R.bool.use_linphone_tag)) {
|
|
||||||
Compatibility.deleteLinphoneContactTag(ops, oldNumberOrAddress, contactsManager.findRawLinphoneContactID(String.valueOf(contactID)));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
String select = ContactsContract.Data.CONTACT_ID + "=? AND "
|
|
||||||
+ ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "' AND "
|
|
||||||
+ ContactsContract.CommonDataKinds.Phone.NUMBER + "=?";
|
|
||||||
String[] args = new String[]{String.valueOf(contactID), oldNumberOrAddress};
|
|
||||||
|
|
||||||
ops.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
|
||||||
.withSelection(select, args)
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addNewNumber() {
|
private void addNewNumber() {
|
||||||
if (newNumberOrAddress == null || newNumberOrAddress.length() == 0) {
|
/*if (newNumberOrAddress == null || newNumberOrAddress.length() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -904,11 +822,11 @@ public class ContactEditorFragment extends Fragment {
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateNumber() {
|
private void updateNumber() {
|
||||||
if (newNumberOrAddress == null || newNumberOrAddress.length() == 0) {
|
/*if (newNumberOrAddress == null || newNumberOrAddress.length() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -940,7 +858,7 @@ public class ContactEditorFragment extends Fragment {
|
||||||
.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, newNumberOrAddress)
|
.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, newNumberOrAddress)
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}
|
}
|
|
@ -88,6 +88,7 @@ public class ContactsManager extends ContentObserver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChange(boolean selfChange, Uri uri) {
|
public void onChange(boolean selfChange, Uri uri) {
|
||||||
|
Log.e("############################################ OnChange ############################################");
|
||||||
List<LinphoneContact> contacts = fetchContactsAsync();
|
List<LinphoneContact> contacts = fetchContactsAsync();
|
||||||
Message msg = handler.obtainMessage();
|
Message msg = handler.obtainMessage();
|
||||||
msg.what = CONTACTS_UPDATED;
|
msg.what = CONTACTS_UPDATED;
|
||||||
|
@ -104,15 +105,15 @@ public class ContactsManager extends ContentObserver {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasContacts() {
|
public synchronized boolean hasContacts() {
|
||||||
return contacts.size() > 0;
|
return contacts.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<LinphoneContact> getContacts() {
|
public synchronized List<LinphoneContact> getContacts() {
|
||||||
return contacts;
|
return contacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<LinphoneContact> getSIPContacts() {
|
public synchronized List<LinphoneContact> getSIPContacts() {
|
||||||
return contacts;
|
return contacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class LinphoneContact implements Serializable {
|
||||||
private static final long serialVersionUID = 9015568163905205244L;
|
private static final long serialVersionUID = 9015568163905205244L;
|
||||||
|
|
||||||
private transient LinphoneFriend friend;
|
private transient LinphoneFriend friend;
|
||||||
private String fullName, androidId;
|
private String fullName, firstName, lastName, androidId;
|
||||||
private transient Uri photoUri, thumbnailUri;
|
private transient Uri photoUri, thumbnailUri;
|
||||||
private List<LinphoneNumberOrAddress> addresses;
|
private List<LinphoneNumberOrAddress> addresses;
|
||||||
|
|
||||||
|
@ -65,6 +65,14 @@ public class LinphoneContact implements Serializable {
|
||||||
return fullName;
|
return fullName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFirstName() {
|
||||||
|
return firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastName() {
|
||||||
|
return lastName;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasPhoto() {
|
public boolean hasPhoto() {
|
||||||
return photoUri != null;
|
return photoUri != null;
|
||||||
}
|
}
|
||||||
|
@ -162,13 +170,11 @@ public class LinphoneContact implements Serializable {
|
||||||
photoUri = null;
|
photoUri = null;
|
||||||
} else {
|
} else {
|
||||||
String id = getAndroidId();
|
String id = getAndroidId();
|
||||||
String name = getName(id);
|
setFullName(getName(id));
|
||||||
Uri thumbnail = getContactPictureUri(id);
|
setThumbnailUri(getContactPictureUri(id));
|
||||||
Uri photo = getContactPhotoUri(id);
|
setPhotoUri(getContactPhotoUri(id));
|
||||||
|
lastName = getContactLastName(id);
|
||||||
setFullName(name);
|
firstName = getContactFirstName(id);
|
||||||
setThumbnailUri(thumbnail);
|
|
||||||
setPhotoUri(photo);
|
|
||||||
for (LinphoneNumberOrAddress noa : getAddressesAndNumbersForAndroidContact(id)) {
|
for (LinphoneNumberOrAddress noa : getAddressesAndNumbersForAndroidContact(id)) {
|
||||||
addresses.add(noa);
|
addresses.add(noa);
|
||||||
}
|
}
|
||||||
|
@ -208,6 +214,32 @@ public class LinphoneContact implements Serializable {
|
||||||
Uri person = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(id));
|
Uri person = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(id));
|
||||||
return Uri.withAppendedPath(person, ContactsContract.Contacts.Photo.DISPLAY_PHOTO);
|
return Uri.withAppendedPath(person, ContactsContract.Contacts.Photo.DISPLAY_PHOTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getContactFirstName(String id) {
|
||||||
|
String result = null;
|
||||||
|
ContentResolver resolver = ContactsManager.getInstance().getContentResolver();
|
||||||
|
Cursor c = resolver.query(ContactsContract.Data.CONTENT_URI, new String[]{ ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME }, ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "=?", new String[]{ id, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE }, null);
|
||||||
|
if (c != null) {
|
||||||
|
if (c.moveToFirst()) {
|
||||||
|
result = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
|
||||||
|
}
|
||||||
|
c.close();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getContactLastName(String id) {
|
||||||
|
String result = null;
|
||||||
|
ContentResolver resolver = ContactsManager.getInstance().getContentResolver();
|
||||||
|
Cursor c = resolver.query(ContactsContract.Data.CONTENT_URI, new String[]{ ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME }, ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "=?", new String[]{ id, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE }, null);
|
||||||
|
if (c != null) {
|
||||||
|
if (c.moveToFirst()) {
|
||||||
|
result = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
|
||||||
|
}
|
||||||
|
c.close();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private String getName(String id) {
|
private String getName(String id) {
|
||||||
ContentResolver resolver = ContactsManager.getInstance().getContentResolver();
|
ContentResolver resolver = ContactsManager.getInstance().getContentResolver();
|
||||||
|
|
Loading…
Reference in a new issue