Add linphone friend management
This commit is contained in:
parent
6ed49c1f32
commit
bd0c2df61e
19 changed files with 709 additions and 818 deletions
|
@ -356,7 +356,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
Log.e("Chat view cannot parse address",e);
|
Log.e("Chat view cannot parse address",e);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
LinphoneUtils.findUriPictureOfContactAndSetDisplayName(address, view.getContext().getContentResolver());
|
Contact lContact = ContactsManager.getInstance().findContactWithAddress(address);
|
||||||
|
|
||||||
String message = "";
|
String message = "";
|
||||||
if (useNativeAPI) {
|
if (useNativeAPI) {
|
||||||
|
@ -394,13 +394,12 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
TextView sipUri = (TextView) view.findViewById(R.id.sipUri);
|
TextView sipUri = (TextView) view.findViewById(R.id.sipUri);
|
||||||
sipUri.setSelected(true); // For animation
|
sipUri.setSelected(true); // For animation
|
||||||
|
|
||||||
if (getResources().getBoolean(R.bool.only_display_username_if_unknown) && address.getDisplayName() != null && LinphoneUtils.isSipAddress(address.getDisplayName())) {
|
if (getResources().getBoolean(R.bool.only_display_username_if_unknown)) {
|
||||||
address.setDisplayName(LinphoneUtils.getUsernameFromAddress(address.getDisplayName()));
|
sipUri.setText(lContact == null ? address.getUserName() : lContact.getName());
|
||||||
} else if (getResources().getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(contact)) {
|
} else {
|
||||||
contact = LinphoneUtils.getUsernameFromAddress(contact);
|
sipUri.setText(lContact == null ? address.asStringUriOnly() : lContact.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
sipUri.setText(address.getDisplayName() == null ? contact : address.getDisplayName());
|
|
||||||
if (isDraft) {
|
if (isDraft) {
|
||||||
view.findViewById(R.id.draft).setVisibility(View.VISIBLE);
|
view.findViewById(R.id.draft).setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,13 +39,14 @@ public class Contact implements Serializable {
|
||||||
private transient Uri photoUri;
|
private transient Uri photoUri;
|
||||||
private transient Bitmap photo;
|
private transient Bitmap photo;
|
||||||
private List<String> numbersOrAddresses;
|
private List<String> numbersOrAddresses;
|
||||||
private LinphoneFriend friend;
|
private boolean hasFriends;
|
||||||
|
|
||||||
public Contact(String id, String name) {
|
public Contact(String id, String name) {
|
||||||
super();
|
super();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.photoUri = null;
|
this.photoUri = null;
|
||||||
|
this.hasFriends = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Contact(String id, String name, Uri photo) {
|
public Contact(String id, String name, Uri photo) {
|
||||||
|
@ -54,6 +55,7 @@ public class Contact implements Serializable {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.photoUri = photo;
|
this.photoUri = photo;
|
||||||
this.photo = null;
|
this.photo = null;
|
||||||
|
this.hasFriends = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Contact(String id, String name, Uri photo, Bitmap picture) {
|
public Contact(String id, String name, Uri photo, Bitmap picture) {
|
||||||
|
@ -62,14 +64,12 @@ public class Contact implements Serializable {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.photoUri = photo;
|
this.photoUri = photo;
|
||||||
this.photo = picture;
|
this.photo = picture;
|
||||||
|
this.hasFriends = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFriend(LinphoneFriend friend) {
|
|
||||||
this.friend = friend;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LinphoneFriend getFriend() {
|
public boolean hasFriends() {
|
||||||
return friend;
|
return hasFriends;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getID() {
|
public String getID() {
|
||||||
|
@ -96,6 +96,12 @@ public class Contact implements Serializable {
|
||||||
|
|
||||||
public void refresh(ContentResolver cr) {
|
public void refresh(ContentResolver cr) {
|
||||||
this.numbersOrAddresses = Compatibility.extractContactNumbersAndAddresses(id, cr);
|
this.numbersOrAddresses = Compatibility.extractContactNumbersAndAddresses(id, cr);
|
||||||
|
for(LinphoneFriend friend : LinphoneManager.getLc().getFriendList()) {
|
||||||
|
if (friend.getRefKey().equals(id)) {
|
||||||
|
hasFriends = true;
|
||||||
|
this.numbersOrAddresses.add(friend.getAddress().asStringUriOnly());
|
||||||
|
}
|
||||||
|
}
|
||||||
this.name = Compatibility.refreshContactName(cr, id);
|
this.name = Compatibility.refreshContactName(cr, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,6 +122,7 @@ public class ContactFragment extends Fragment implements OnClickListener {
|
||||||
TextView contactName = (TextView) view.findViewById(R.id.contactName);
|
TextView contactName = (TextView) view.findViewById(R.id.contactName);
|
||||||
contactName.setText(contact.getName());
|
contactName.setText(contact.getName());
|
||||||
|
|
||||||
|
|
||||||
TableLayout controls = (TableLayout) view.findViewById(R.id.controls);
|
TableLayout controls = (TableLayout) view.findViewById(R.id.controls);
|
||||||
controls.removeAllViews();
|
controls.removeAllViews();
|
||||||
for (String numberOrAddress : contact.getNumbersOrAddresses()) {
|
for (String numberOrAddress : contact.getNumbersOrAddresses()) {
|
||||||
|
@ -170,7 +171,7 @@ public class ContactFragment extends Fragment implements OnClickListener {
|
||||||
friend.setOnClickListener(new OnClickListener() {
|
friend.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (LinphoneActivity.instance().newFriend(contact, finalNumberOrAddress)) {
|
if (ContactsManager.getInstance().createNewFriend(contact, finalNumberOrAddress)) {
|
||||||
displayContact(ContactFragment.this.inflater, ContactFragment.this.view);
|
displayContact(ContactFragment.this.inflater, ContactFragment.this.view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,7 +181,7 @@ public class ContactFragment extends Fragment implements OnClickListener {
|
||||||
friend.setOnClickListener(new OnClickListener() {
|
friend.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (LinphoneActivity.instance().removeFriend(contact, finalNumberOrAddress)) {
|
if (ContactsManager.getInstance().removeFriend(finalNumberOrAddress)) {
|
||||||
displayContact(ContactFragment.this.inflater, ContactFragment.this.view);
|
displayContact(ContactFragment.this.inflater, ContactFragment.this.view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,7 +229,7 @@ public class ContactFragment extends Fragment implements OnClickListener {
|
||||||
alertDialog.setPositiveButton(getString(R.string.button_ok),new DialogInterface.OnClickListener() {
|
alertDialog.setPositiveButton(getString(R.string.button_ok),new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
deleteExistingContact();
|
deleteExistingContact();
|
||||||
LinphoneActivity.instance().removeContactFromLists(contact);
|
ContactsManager.getInstance().removeContactFromLists(getActivity().getContentResolver(),contact);
|
||||||
LinphoneActivity.instance().displayContacts(false);
|
LinphoneActivity.instance().displayContacts(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -249,6 +250,7 @@ public class ContactFragment extends Fragment implements OnClickListener {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
|
getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
|
||||||
|
ContactsManager.getInstance().removeAllFriends(contact);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.w(e.getMessage() + ":" + e.getStackTrace());
|
Log.w(e.getMessage() + ":" + e.getStackTrace());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,297 +0,0 @@
|
||||||
/*
|
|
||||||
ContactHelper.java
|
|
||||||
Copyright (C) 2011 Belledonne Communications, Grenoble, France
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public License
|
|
||||||
as published by the Free Software Foundation; either version 2
|
|
||||||
of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
*/
|
|
||||||
package org.linphone;
|
|
||||||
|
|
||||||
import org.linphone.core.LinphoneAddress;
|
|
||||||
import org.linphone.core.LinphoneCore;
|
|
||||||
import org.linphone.core.LinphoneProxyConfig;
|
|
||||||
import org.linphone.mediastream.Version;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.ContentUris;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.provider.ContactsContract;
|
|
||||||
import android.provider.ContactsContract.Contacts;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
public final class ContactHelper {
|
|
||||||
private String username;
|
|
||||||
private String domain;
|
|
||||||
private ContentResolver resolver;
|
|
||||||
|
|
||||||
private Uri foundPhotoUri;
|
|
||||||
public Uri getUri() {
|
|
||||||
return foundPhotoUri;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String displayName;
|
|
||||||
public String getDisplayName() {
|
|
||||||
return displayName;
|
|
||||||
}
|
|
||||||
|
|
||||||
private LinphoneAddress address;
|
|
||||||
public ContactHelper(LinphoneAddress address, ContentResolver resolver) {
|
|
||||||
username = address.getUserName();
|
|
||||||
domain = address.getDomain();
|
|
||||||
this.resolver = resolver;
|
|
||||||
this.address = address;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean query() {
|
|
||||||
boolean succeeded = queryContact();
|
|
||||||
if (succeeded && !TextUtils.isEmpty(displayName)) {
|
|
||||||
address.setDisplayName(displayName);
|
|
||||||
}
|
|
||||||
return succeeded;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Intent prepareEditContactIntent(int id) {
|
|
||||||
Intent intent = new Intent(Intent.ACTION_EDIT, Contacts.CONTENT_URI);
|
|
||||||
Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, id);
|
|
||||||
intent.setData(contactUri);
|
|
||||||
|
|
||||||
return intent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean testPhotoUri(Cursor c) {
|
|
||||||
if (c == null) return false;
|
|
||||||
if (!c.moveToNext()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
byte[] data = c.getBlob(0);
|
|
||||||
if (data == null) {
|
|
||||||
// TODO: simplify all this stuff
|
|
||||||
// which is here only to check that the
|
|
||||||
// photoUri really points to some data.
|
|
||||||
// Not retrieving the data now would be better.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean testPhotoUriAndCloseCursor(Cursor c) {
|
|
||||||
boolean valid = testPhotoUri(c);
|
|
||||||
if (c != null) c.close();
|
|
||||||
return valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean testPhotoUri(ContentResolver resolver, Uri photoUriToTest, String photoCol) {
|
|
||||||
Cursor cursor = resolver.query(photoUriToTest, new String[]{photoCol}, null, null, null);
|
|
||||||
return testPhotoUriAndCloseCursor(cursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String queryAddressOrNumber(ContentResolver resolver, Uri contactUri) {
|
|
||||||
// Phone Numbers
|
|
||||||
String[] projection = new String[]{ContactsContract.CommonDataKinds.Phone.NUMBER};
|
|
||||||
Cursor c = resolver.query(contactUri, projection, null, null, null);
|
|
||||||
if (c != null) {
|
|
||||||
while (c.moveToNext()) {
|
|
||||||
int numberIndex = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
|
|
||||||
String number = c.getString(numberIndex);
|
|
||||||
c.close();
|
|
||||||
return number;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SIP addresses
|
|
||||||
projection = new String[] {ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS};
|
|
||||||
c = resolver.query(contactUri, projection, null, null, null);
|
|
||||||
if (c != null) {
|
|
||||||
while (c.moveToNext()) {
|
|
||||||
int numberIndex = c.getColumnIndex(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS);
|
|
||||||
String address = c.getString(numberIndex);
|
|
||||||
c.close();
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
c.close();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkPhotosUris(ContentResolver resolver, Cursor c, String idCol, String nameCol) {
|
|
||||||
displayName = c.getString(c.getColumnIndex(nameCol));
|
|
||||||
|
|
||||||
long id = c.getLong(c.getColumnIndex(idCol));
|
|
||||||
Uri contactUri = ContentUris.withAppendedId(android.provider.ContactsContract.Contacts.CONTENT_URI, id);
|
|
||||||
Uri photoUri = Uri.withAppendedPath(contactUri, android.provider.ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
|
|
||||||
|
|
||||||
if (photoUri != null) {
|
|
||||||
String[] projection = { android.provider.ContactsContract.CommonDataKinds.Photo.PHOTO };
|
|
||||||
Cursor photoCursor = resolver.query(photoUri, projection, null, null, null);
|
|
||||||
|
|
||||||
boolean isPhotoValid = testPhotoUriAndCloseCursor(photoCursor);
|
|
||||||
if (isPhotoValid) {
|
|
||||||
foundPhotoUri = photoUri;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkSIPQueryResult(Cursor c, String columnSip) {
|
|
||||||
boolean contactFound = false;
|
|
||||||
|
|
||||||
if (c != null) {
|
|
||||||
while (!contactFound && c.moveToNext()) {
|
|
||||||
String contact = c.getString(c.getColumnIndex(columnSip));
|
|
||||||
if (contact.equals(username + "@" + domain) || contact.equals(username)) {
|
|
||||||
contactFound = true;
|
|
||||||
checkPhotosUris(resolver, c, android.provider.ContactsContract.Data.CONTACT_ID, android.provider.ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
|
|
||||||
} else {
|
|
||||||
String normalizedUsername = null;
|
|
||||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
|
||||||
if (lc != null) {
|
|
||||||
LinphoneProxyConfig lpc = lc.getDefaultProxyConfig();
|
|
||||||
if (lpc != null) {
|
|
||||||
if (contact.contains("@")) {
|
|
||||||
normalizedUsername = lpc.normalizePhoneNumber(contact.split("@")[0]);
|
|
||||||
} else {
|
|
||||||
normalizedUsername = lpc.normalizePhoneNumber(contact);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (normalizedUsername != null && normalizedUsername.equals(username)) {
|
|
||||||
contactFound = true;
|
|
||||||
checkPhotosUris(resolver, c, android.provider.ContactsContract.Data.CONTACT_ID, android.provider.ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
c.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
return contactFound;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkPhoneQueryResult(Cursor c, String columnPhone) {
|
|
||||||
boolean contactFound = false;
|
|
||||||
|
|
||||||
if (c != null) {
|
|
||||||
while (!contactFound && c.moveToNext()) {
|
|
||||||
String contact = c.getString(c.getColumnIndex(columnPhone));
|
|
||||||
if (contact.equals(username)) {
|
|
||||||
contactFound = true;
|
|
||||||
checkPhotosUris(resolver, c, android.provider.ContactsContract.PhoneLookup._ID, android.provider.ContactsContract.PhoneLookup.DISPLAY_NAME);
|
|
||||||
} else {
|
|
||||||
String normalizedUsername = null;
|
|
||||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
|
||||||
if (lc != null) {
|
|
||||||
LinphoneProxyConfig lpc = lc.getDefaultProxyConfig();
|
|
||||||
if (lpc != null) {
|
|
||||||
normalizedUsername = lpc.normalizePhoneNumber(contact);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (normalizedUsername != null && normalizedUsername.equals(username)) {
|
|
||||||
contactFound = true;
|
|
||||||
checkPhotosUris(resolver, c, android.provider.ContactsContract.PhoneLookup._ID, android.provider.ContactsContract.PhoneLookup.DISPLAY_NAME);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
c.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
return contactFound;
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean isContactHasLinphoneTag(Contact contact, ContentResolver cr) {
|
|
||||||
String select = ContactsContract.Data.CONTACT_ID + " = ?";
|
|
||||||
String[] args = new String[] { contact.getID() };
|
|
||||||
|
|
||||||
String[] projection = new String[] {ContactsContract.Data.MIMETYPE };
|
|
||||||
|
|
||||||
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI, projection, select, args, null);
|
|
||||||
|
|
||||||
if (cursor != null) {
|
|
||||||
while (cursor.moveToNext()) {
|
|
||||||
if(cursor.getString(cursor.getColumnIndex(ContactsContract.Data.MIMETYPE)).equals("vnd.android.cursor.item/org.linphone.profile")){
|
|
||||||
cursor.close();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cursor.close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String findRawContactID(ContentResolver cr, String contactID) {
|
|
||||||
Cursor c = cr.query(ContactsContract.RawContacts.CONTENT_URI,
|
|
||||||
new String[]{ContactsContract.RawContacts._ID},
|
|
||||||
ContactsContract.RawContacts.CONTACT_ID + "=?",
|
|
||||||
new String[]{contactID}, null);
|
|
||||||
if (c != null) {
|
|
||||||
String result = null;
|
|
||||||
if (c.moveToFirst()) {
|
|
||||||
result = c.getString(c.getColumnIndex(ContactsContract.RawContacts._ID));
|
|
||||||
}
|
|
||||||
|
|
||||||
c.close();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("InlinedApi")
|
|
||||||
private final boolean queryContact() {
|
|
||||||
boolean contactFound = false;
|
|
||||||
|
|
||||||
Uri uri = android.provider.ContactsContract.Data.CONTENT_URI;
|
|
||||||
String[] projection = { android.provider.ContactsContract.Data.CONTACT_ID, android.provider.ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
|
|
||||||
android.provider.ContactsContract.CommonDataKinds.Im.DATA };
|
|
||||||
|
|
||||||
String selection = new StringBuilder()
|
|
||||||
.append(android.provider.ContactsContract.Data.MIMETYPE)
|
|
||||||
.append(" = '")
|
|
||||||
.append(android.provider.ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE)
|
|
||||||
.append("' AND lower(")
|
|
||||||
.append(android.provider.ContactsContract.CommonDataKinds.Im.CUSTOM_PROTOCOL)
|
|
||||||
.append(") = 'sip'").toString();
|
|
||||||
|
|
||||||
Cursor c = resolver.query(uri, projection, selection, null, null);
|
|
||||||
contactFound = checkSIPQueryResult(c, android.provider.ContactsContract.CommonDataKinds.Im.DATA);
|
|
||||||
if (contactFound) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Version.sdkAboveOrEqual(Version.API09_GINGERBREAD_23)) {
|
|
||||||
selection = new StringBuilder()
|
|
||||||
.append(android.provider.ContactsContract.Data.MIMETYPE)
|
|
||||||
.append(" = '")
|
|
||||||
.append(android.provider.ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE)
|
|
||||||
.append("'")
|
|
||||||
.toString();
|
|
||||||
c = resolver.query(uri, projection, selection, null, null);
|
|
||||||
contactFound = checkSIPQueryResult(c, android.provider.ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS);
|
|
||||||
if (contactFound) {
|
|
||||||
c.close();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Uri lookupUri = Uri.withAppendedPath(android.provider.ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(username));
|
|
||||||
projection = new String[] {
|
|
||||||
android.provider.ContactsContract.PhoneLookup._ID,
|
|
||||||
android.provider.ContactsContract.PhoneLookup.NUMBER,
|
|
||||||
android.provider.ContactsContract.PhoneLookup.DISPLAY_NAME };
|
|
||||||
c = resolver.query(lookupUri, projection, null, null, null);
|
|
||||||
contactFound = checkPhoneQueryResult(c, android.provider.ContactsContract.PhoneLookup.NUMBER);
|
|
||||||
c.close();
|
|
||||||
return contactFound;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -22,6 +22,7 @@ import java.util.List;
|
||||||
import org.linphone.compatibility.Compatibility;
|
import org.linphone.compatibility.Compatibility;
|
||||||
import org.linphone.core.LinphoneFriend;
|
import org.linphone.core.LinphoneFriend;
|
||||||
import org.linphone.core.PresenceActivityType;
|
import org.linphone.core.PresenceActivityType;
|
||||||
|
import org.linphone.mediastream.Log;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
@ -169,7 +170,6 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
||||||
changeContactsAdapter();
|
changeContactsAdapter();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
changeContactsToggle();
|
changeContactsToggle();
|
||||||
|
|
||||||
if (searchCursor != null) {
|
if (searchCursor != null) {
|
||||||
|
@ -177,11 +177,11 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onlyDisplayLinphoneContacts) {
|
if (onlyDisplayLinphoneContacts) {
|
||||||
searchCursor = Compatibility.getSIPContactsCursor(getActivity().getContentResolver(), search);
|
searchCursor = Compatibility.getSIPContactsCursor(getActivity().getContentResolver(), search, ContactsManager.getInstance().getContactsId());
|
||||||
indexer = new AlphabetIndexer(searchCursor, Compatibility.getCursorDisplayNameColumnIndex(searchCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
indexer = new AlphabetIndexer(searchCursor, Compatibility.getCursorDisplayNameColumnIndex(searchCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||||
contactsList.setAdapter(new ContactsListAdapter(null, searchCursor));
|
contactsList.setAdapter(new ContactsListAdapter(null, searchCursor));
|
||||||
} else {
|
} else {
|
||||||
searchCursor = Compatibility.getContactsCursor(getActivity().getContentResolver(), search);
|
searchCursor = Compatibility.getContactsCursor(getActivity().getContentResolver(), search, ContactsManager.getInstance().getContactsId());
|
||||||
indexer = new AlphabetIndexer(searchCursor, Compatibility.getCursorDisplayNameColumnIndex(searchCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
indexer = new AlphabetIndexer(searchCursor, Compatibility.getCursorDisplayNameColumnIndex(searchCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||||
contactsList.setAdapter(new ContactsListAdapter(null, searchCursor));
|
contactsList.setAdapter(new ContactsListAdapter(null, searchCursor));
|
||||||
}
|
}
|
||||||
|
@ -194,8 +194,8 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
||||||
searchCursor.close();
|
searchCursor.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
Cursor allContactsCursor = LinphoneActivity.instance().getAllContactsCursor();
|
Cursor allContactsCursor = ContactsManager.getInstance().getAllContactsCursor();
|
||||||
Cursor sipContactsCursor = LinphoneActivity.instance().getSIPContactsCursor();
|
Cursor sipContactsCursor = ContactsManager.getInstance().getSIPContactsCursor();
|
||||||
|
|
||||||
noSipContact.setVisibility(View.GONE);
|
noSipContact.setVisibility(View.GONE);
|
||||||
noContact.setVisibility(View.GONE);
|
noContact.setVisibility(View.GONE);
|
||||||
|
@ -207,7 +207,7 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
||||||
contactsList.setVisibility(View.GONE);
|
contactsList.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
indexer = new AlphabetIndexer(sipContactsCursor, Compatibility.getCursorDisplayNameColumnIndex(sipContactsCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
indexer = new AlphabetIndexer(sipContactsCursor, Compatibility.getCursorDisplayNameColumnIndex(sipContactsCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||||
contactsList.setAdapter(new ContactsListAdapter(LinphoneActivity.instance().getSIPContacts(), sipContactsCursor));
|
contactsList.setAdapter(new ContactsListAdapter(ContactsManager.getInstance().getSIPContacts(), sipContactsCursor));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (allContactsCursor.getCount() == 0) {
|
if (allContactsCursor.getCount() == 0) {
|
||||||
|
@ -215,10 +215,10 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
||||||
contactsList.setVisibility(View.GONE);
|
contactsList.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
indexer = new AlphabetIndexer(allContactsCursor, Compatibility.getCursorDisplayNameColumnIndex(allContactsCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
indexer = new AlphabetIndexer(allContactsCursor, Compatibility.getCursorDisplayNameColumnIndex(allContactsCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||||
contactsList.setAdapter(new ContactsListAdapter(LinphoneActivity.instance().getAllContacts(), allContactsCursor));
|
contactsList.setAdapter(new ContactsListAdapter(ContactsManager.getInstance().getAllContacts(), allContactsCursor));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LinphoneActivity.instance().setLinphoneContactsPrefered(onlyDisplayLinphoneContacts);
|
ContactsManager.getInstance().setLinphoneContactsPrefered(onlyDisplayLinphoneContacts);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeContactsToggle() {
|
private void changeContactsToggle() {
|
||||||
|
@ -255,7 +255,7 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
||||||
|
|
||||||
if (LinphoneActivity.isInstanciated()) {
|
if (LinphoneActivity.isInstanciated()) {
|
||||||
LinphoneActivity.instance().selectMenu(FragmentsAvailable.CONTACTS);
|
LinphoneActivity.instance().selectMenu(FragmentsAvailable.CONTACTS);
|
||||||
onlyDisplayLinphoneContacts = LinphoneActivity.instance().isLinphoneContactsPrefered();
|
onlyDisplayLinphoneContacts = ContactsManager.getInstance().isLinphoneContactsPrefered();
|
||||||
|
|
||||||
if (getResources().getBoolean(R.bool.show_statusbar_only_on_dialer)) {
|
if (getResources().getBoolean(R.bool.show_statusbar_only_on_dialer)) {
|
||||||
LinphoneActivity.instance().hideStatusBar();
|
LinphoneActivity.instance().hideStatusBar();
|
||||||
|
@ -350,10 +350,10 @@ public class ContactsFragment extends Fragment implements OnClickListener, OnIte
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageView friendStatus = (ImageView) view.findViewById(R.id.friendStatus);
|
ImageView friendStatus = (ImageView) view.findViewById(R.id.friendStatus);
|
||||||
LinphoneFriend friend = contact.getFriend();
|
LinphoneFriend[] friends = LinphoneManager.getLc().getFriendList();
|
||||||
if (!LinphoneActivity.instance().isContactPresenceDisabled() && friend != null) {
|
if (!ContactsManager.getInstance().isContactPresenceDisabled() && friends != null) {
|
||||||
friendStatus.setVisibility(View.VISIBLE);
|
friendStatus.setVisibility(View.VISIBLE);
|
||||||
PresenceActivityType presenceActivity = friend.getPresenceModel().getActivity().getType();
|
PresenceActivityType presenceActivity = friends[0].getPresenceModel().getActivity().getType();
|
||||||
if (presenceActivity == PresenceActivityType.Online) {
|
if (presenceActivity == PresenceActivityType.Online) {
|
||||||
friendStatus.setImageResource(R.drawable.led_connected);
|
friendStatus.setImageResource(R.drawable.led_connected);
|
||||||
} else if (presenceActivity == PresenceActivityType.Busy) {
|
} else if (presenceActivity == PresenceActivityType.Busy) {
|
||||||
|
|
464
src/org/linphone/ContactsManager.java
Normal file
464
src/org/linphone/ContactsManager.java
Normal file
|
@ -0,0 +1,464 @@
|
||||||
|
package org.linphone;
|
||||||
|
/*
|
||||||
|
CallManager.java
|
||||||
|
Copyright (C) 2015 Belledonne Communications, Grenoble, France
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import android.accounts.Account;
|
||||||
|
import android.accounts.AccountManager;
|
||||||
|
import android.content.ContentProviderOperation;
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.provider.ContactsContract;
|
||||||
|
import org.linphone.compatibility.Compatibility;
|
||||||
|
import org.linphone.core.LinphoneAddress;
|
||||||
|
import org.linphone.core.LinphoneCoreException;
|
||||||
|
import org.linphone.core.LinphoneCoreFactory;
|
||||||
|
import org.linphone.core.LinphoneFriend;
|
||||||
|
import org.linphone.mediastream.Log;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ContactsManager {
|
||||||
|
private static ContactsManager instance;
|
||||||
|
private List<Contact> contactList, sipContactList;
|
||||||
|
private Cursor contactCursor, sipContactCursor, friendContactCursor;
|
||||||
|
private Account mAccount;
|
||||||
|
private boolean preferLinphoneContacts = false, isContactPresenceDisabled = true;
|
||||||
|
private ContentResolver contentResolver;
|
||||||
|
private Context context;
|
||||||
|
|
||||||
|
private ContactsManager() {}
|
||||||
|
|
||||||
|
public static final synchronized ContactsManager getInstance() {
|
||||||
|
if (instance == null) instance = new ContactsManager();
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Contact> getAllContacts() {
|
||||||
|
return contactList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Contact> getSIPContacts() {
|
||||||
|
return sipContactList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Cursor getAllContactsCursor() {
|
||||||
|
return contactCursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Cursor getSIPContactsCursor() {
|
||||||
|
if (sipContactCursor.getCount() > 0)
|
||||||
|
return sipContactCursor;
|
||||||
|
else
|
||||||
|
return friendContactCursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLinphoneContactsPrefered(boolean isPrefered) {
|
||||||
|
preferLinphoneContacts = isPrefered;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLinphoneContactsPrefered() {
|
||||||
|
return preferLinphoneContacts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isContactPresenceDisabled() {
|
||||||
|
return isContactPresenceDisabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initializeSyncAccount(Context context, ContentResolver contentResolver) {
|
||||||
|
this.context = context;
|
||||||
|
this.contentResolver = contentResolver;
|
||||||
|
Account newAccount = new Account(context.getString(R.string.sync_account_name), context.getString(R.string.sync_account_type));
|
||||||
|
AccountManager accountManager = (AccountManager) context.getSystemService(context.ACCOUNT_SERVICE);
|
||||||
|
accountManager.addAccountExplicitly(newAccount, null, null);
|
||||||
|
mAccount = newAccount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDisplayName(String firstName, String lastName) {
|
||||||
|
String displayName = null;
|
||||||
|
if (firstName.length() > 0 && lastName.length() > 0)
|
||||||
|
displayName = firstName + " " + lastName;
|
||||||
|
else if (firstName.length() > 0)
|
||||||
|
displayName = firstName;
|
||||||
|
else if (lastName.length() > 0)
|
||||||
|
displayName = lastName.toString();
|
||||||
|
return displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createNewContact(ArrayList<ContentProviderOperation> ops, String firstName, String lastName){
|
||||||
|
int contactID = 0;
|
||||||
|
|
||||||
|
ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
|
||||||
|
.withValue(ContactsContract.RawContacts.AGGREGATION_MODE, ContactsContract.RawContacts.AGGREGATION_MODE_DEFAULT)
|
||||||
|
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
|
||||||
|
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (getDisplayName(firstName, lastName) != null) {
|
||||||
|
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||||
|
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, contactID)
|
||||||
|
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
|
||||||
|
.withValue(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, firstName)
|
||||||
|
.withValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, lastName)
|
||||||
|
.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, getDisplayName(firstName,lastName))
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateExistingContact(ArrayList<ContentProviderOperation> ops, Contact contact, String firstName, String lastName) {
|
||||||
|
if (getDisplayName(firstName, lastName) != null) {
|
||||||
|
String select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE + "'" ;
|
||||||
|
String[] args = new String[] { String.valueOf(contact.getID()) };
|
||||||
|
|
||||||
|
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
||||||
|
.withSelection(select, args)
|
||||||
|
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
|
||||||
|
.withValue(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, firstName)
|
||||||
|
.withValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, lastName)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Manage Linphone Friend if we cannot use Sip address
|
||||||
|
public boolean createNewFriend(Contact contact, String sipUri) {
|
||||||
|
if (!sipUri.startsWith("sip:")) {
|
||||||
|
sipUri = "sip:" + sipUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
LinphoneFriend friend = LinphoneCoreFactory.instance().createLinphoneFriend(sipUri);
|
||||||
|
friend.edit();
|
||||||
|
friend.setRefKey(contact.getID());
|
||||||
|
friend.done();
|
||||||
|
try {
|
||||||
|
LinphoneManager.getLc().addFriend(friend);
|
||||||
|
return true;
|
||||||
|
} catch (LinphoneCoreException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateFriend(String oldSipUri, String newSipUri) {
|
||||||
|
if (!newSipUri.startsWith("sip:")) {
|
||||||
|
newSipUri = "sip:" + newSipUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!oldSipUri.startsWith("sip:")) {
|
||||||
|
oldSipUri = "sip:" + oldSipUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
LinphoneFriend friend = LinphoneManager.getLc().findFriendByAddress(oldSipUri);
|
||||||
|
if(friend != null) {
|
||||||
|
friend.edit();
|
||||||
|
try {
|
||||||
|
friend.setAddress(LinphoneCoreFactory.instance().createLinphoneAddress(newSipUri));
|
||||||
|
} catch (LinphoneCoreException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
friend.done();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean removeFriend(String sipUri) {
|
||||||
|
if (!sipUri.startsWith("sip:")) {
|
||||||
|
sipUri = "sip:" + sipUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
LinphoneFriend friend = LinphoneManager.getLc().findFriendByAddress(sipUri);
|
||||||
|
if (friend != null) {
|
||||||
|
LinphoneManager.getLc().removeFriend(friend);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeAllFriends(Contact contact) {
|
||||||
|
for(LinphoneFriend friend : LinphoneManager.getLc().getFriendList()){
|
||||||
|
if(friend.getRefKey().equals(contact.getID())) {
|
||||||
|
LinphoneManager.getLc().removeFriend(friend);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Contact findContactWithDisplayName(String displayName) {
|
||||||
|
String[] projection = { ContactsContract.Data.CONTACT_ID, ContactsContract.Data.DISPLAY_NAME };
|
||||||
|
String selection = new StringBuilder()
|
||||||
|
.append(ContactsContract.Data.DISPLAY_NAME)
|
||||||
|
.append(" = ?").toString();
|
||||||
|
|
||||||
|
Cursor c = contentResolver.query(ContactsContract.Data.CONTENT_URI,projection,selection,
|
||||||
|
new String[]{displayName}, null);
|
||||||
|
if (c != null) {
|
||||||
|
if (c.moveToFirst()) {
|
||||||
|
Contact contact = Compatibility.getContact(contentResolver,c,c.getPosition());
|
||||||
|
c.close();
|
||||||
|
|
||||||
|
if(contact != null) {
|
||||||
|
return contact;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.close();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getContactsId(){
|
||||||
|
List<String> ids = new ArrayList<String>();
|
||||||
|
if(LinphoneManager.getLc().getFriendList() == null) return null;
|
||||||
|
for(LinphoneFriend friend : LinphoneManager.getLc().getFriendList()) {
|
||||||
|
if(!ids.contains(friend.getRefKey())){
|
||||||
|
ids.add(friend.getRefKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
//End linphone Friend
|
||||||
|
|
||||||
|
public Contact findContactWithAddress(LinphoneAddress address){
|
||||||
|
for(Contact contact : contactList){
|
||||||
|
if(contact.getNumbersOrAddresses().contains(address.asStringUriOnly()) || contact.getNumbersOrAddresses().contains(address.getUserName())){
|
||||||
|
return contact;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeContactFromLists(ContentResolver contentResolver, Contact contact) {
|
||||||
|
for (Contact c : contactList) {
|
||||||
|
if (c != null && c.getID().equals(contact.getID())) {
|
||||||
|
contactList.remove(c);
|
||||||
|
contactCursor = Compatibility.getContactsCursor(contentResolver,getContactsId());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Contact c : sipContactList) {
|
||||||
|
if (c != null && c.getID().equals(contact.getID())) {
|
||||||
|
sipContactList.remove(c);
|
||||||
|
sipContactCursor = Compatibility.getSIPContactsCursor(contentResolver,getContactsId());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isContactHasAddress(Contact contact, String address){
|
||||||
|
if(contact != null) {
|
||||||
|
contact.refresh(contentResolver);
|
||||||
|
if (contact.getNumbersOrAddresses().contains("sip:" + address)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Migrate old IM contacts into SIP addresses or linphoneFriends
|
||||||
|
public void migrateContacts() {
|
||||||
|
Cursor oldContacts = Compatibility.getImContactsCursor(contentResolver);
|
||||||
|
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
|
||||||
|
|
||||||
|
if(oldContacts != null){
|
||||||
|
for (int i = 0; i < oldContacts.getCount(); i++) {
|
||||||
|
Contact contact = Compatibility.getContact(contentResolver, oldContacts, i);
|
||||||
|
for (String address : Compatibility.extractContactImAddresses(contact.getID(), contentResolver)) {
|
||||||
|
|
||||||
|
if (LinphoneUtils.isSipAddress(address)) {
|
||||||
|
if (address.startsWith("sip:")) {
|
||||||
|
address = address.substring(4);
|
||||||
|
}
|
||||||
|
Compatibility.addSipAddressToContact(context, ops, address, findRawContactID(contentResolver,contact.getID()));
|
||||||
|
try {
|
||||||
|
contentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
ops.clear();
|
||||||
|
|
||||||
|
if(isContactHasAddress(contact,address)){
|
||||||
|
Compatibility.deleteImAddressFromContact(ops, address, contact.getID());
|
||||||
|
try {
|
||||||
|
contentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
ops.clear();
|
||||||
|
} else {
|
||||||
|
if (!address.startsWith("sip:")) {
|
||||||
|
address = "sip:" + address;
|
||||||
|
}
|
||||||
|
|
||||||
|
createNewFriend(contact, address);
|
||||||
|
|
||||||
|
contact.refresh(contentResolver);
|
||||||
|
|
||||||
|
if (address.startsWith("sip:")) {
|
||||||
|
address = address.substring(4);
|
||||||
|
}
|
||||||
|
Compatibility.deleteImAddressFromContact(ops, address, contact.getID());
|
||||||
|
try {
|
||||||
|
contentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
|
}
|
||||||
|
ops.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ops.clear();
|
||||||
|
contact.refresh(contentResolver);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void prepareContactsInBackground() {
|
||||||
|
if (contactCursor != null) {
|
||||||
|
contactCursor.close();
|
||||||
|
}
|
||||||
|
if (sipContactCursor != null) {
|
||||||
|
sipContactCursor.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
contactCursor = Compatibility.getContactsCursor(contentResolver, getContactsId());
|
||||||
|
sipContactCursor = Compatibility.getSIPContactsCursor(contentResolver, getContactsId());
|
||||||
|
|
||||||
|
Thread sipContactsHandler = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if(sipContactCursor.getCount() > 0) {
|
||||||
|
for (int i = 0; i < sipContactCursor.getCount(); i++) {
|
||||||
|
Contact contact = Compatibility.getContact(contentResolver, sipContactCursor, i);
|
||||||
|
if (contact == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
contact.refresh(contentResolver);
|
||||||
|
//Add tag to Linphone contact if it not existed
|
||||||
|
if(!isContactHasLinphoneTag(contact,contentResolver)){
|
||||||
|
Compatibility.createLinphoneContactTag(context,contentResolver,contact,
|
||||||
|
findRawContactID(contentResolver, String.valueOf(contact.getID())));
|
||||||
|
}
|
||||||
|
|
||||||
|
sipContactList.add(contact);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (contactCursor != null) {
|
||||||
|
for (int i = 0; i < contactCursor.getCount(); i++) {
|
||||||
|
Contact contact = Compatibility.getContact(contentResolver, contactCursor, i);
|
||||||
|
|
||||||
|
if (contact == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (Contact c : sipContactList) {
|
||||||
|
if (c != null && c.getID().equals(contact.getID())) {
|
||||||
|
contact = c;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
contactList.add(contact);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
contactList = new ArrayList<Contact>();
|
||||||
|
sipContactList = new ArrayList<Contact>();
|
||||||
|
|
||||||
|
sipContactsHandler.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String queryAddressOrNumber(ContentResolver resolver, Uri contactUri) {
|
||||||
|
// Phone Numbers
|
||||||
|
String[] projection = new String[]{ContactsContract.CommonDataKinds.Phone.NUMBER};
|
||||||
|
Cursor c = resolver.query(contactUri, projection, null, null, null);
|
||||||
|
if (c != null) {
|
||||||
|
while (c.moveToNext()) {
|
||||||
|
int numberIndex = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
|
||||||
|
String number = c.getString(numberIndex);
|
||||||
|
c.close();
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SIP addresses
|
||||||
|
projection = new String[] {ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS};
|
||||||
|
c = resolver.query(contactUri, projection, null, null, null);
|
||||||
|
if (c != null) {
|
||||||
|
while (c.moveToNext()) {
|
||||||
|
int numberIndex = c.getColumnIndex(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS);
|
||||||
|
String address = c.getString(numberIndex);
|
||||||
|
c.close();
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c.close();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isContactHasLinphoneTag(Contact contact, ContentResolver cr) {
|
||||||
|
String select = ContactsContract.Data.CONTACT_ID + " = ?";
|
||||||
|
String[] args = new String[] { contact.getID() };
|
||||||
|
|
||||||
|
String[] projection = new String[] {ContactsContract.Data.MIMETYPE };
|
||||||
|
|
||||||
|
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI, projection, select, args, null);
|
||||||
|
|
||||||
|
if (cursor != null) {
|
||||||
|
while (cursor.moveToNext()) {
|
||||||
|
if(cursor.getString(cursor.getColumnIndex(ContactsContract.Data.MIMETYPE)).equals("vnd.android.cursor.item/org.linphone.profile")){
|
||||||
|
cursor.close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String findRawContactID(ContentResolver cr, String contactID) {
|
||||||
|
Cursor c = cr.query(ContactsContract.RawContacts.CONTENT_URI,
|
||||||
|
new String[]{ContactsContract.RawContacts._ID},
|
||||||
|
ContactsContract.RawContacts.CONTACT_ID + "=?",
|
||||||
|
new String[]{contactID}, null);
|
||||||
|
if (c != null) {
|
||||||
|
String result = null;
|
||||||
|
if (c.moveToFirst()) {
|
||||||
|
result = c.getString(c.getColumnIndex(ContactsContract.RawContacts._ID));
|
||||||
|
}
|
||||||
|
|
||||||
|
c.close();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -199,7 +199,7 @@ public class DialerFragment extends Fragment {
|
||||||
mAddress.setText(intent.getData().getSchemeSpecificPart());
|
mAddress.setText(intent.getData().getSchemeSpecificPart());
|
||||||
} else {
|
} else {
|
||||||
Uri contactUri = intent.getData();
|
Uri contactUri = intent.getData();
|
||||||
String address = ContactHelper.queryAddressOrNumber(getActivity().getContentResolver(),contactUri);
|
String address = ContactsManager.getInstance().queryAddressOrNumber(getActivity().getContentResolver(),contactUri);
|
||||||
if(address != null) {
|
if(address != null) {
|
||||||
mAddress.setText(address);
|
mAddress.setText(address);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.linphone.compatibility.Compatibility;
|
import org.linphone.compatibility.Compatibility;
|
||||||
import org.linphone.mediastream.Version;
|
import org.linphone.mediastream.Version;
|
||||||
|
import org.linphone.mediastream.Log;
|
||||||
import org.linphone.ui.AvatarWithShadow;
|
import org.linphone.ui.AvatarWithShadow;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.ContentProviderOperation;
|
import android.content.ContentProviderOperation;
|
||||||
|
@ -41,6 +42,7 @@ public class EditContactFragment extends Fragment {
|
||||||
private ArrayList<ContentProviderOperation> ops;
|
private ArrayList<ContentProviderOperation> ops;
|
||||||
private int firstSipAddressIndex = -1;
|
private int firstSipAddressIndex = -1;
|
||||||
private String newSipOrNumberToAdd;
|
private String newSipOrNumberToAdd;
|
||||||
|
private ContactsManager contactsManager;
|
||||||
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
this.inflater = inflater;
|
this.inflater = inflater;
|
||||||
|
@ -59,6 +61,8 @@ public class EditContactFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contactsManager = ContactsManager.getInstance();
|
||||||
|
|
||||||
view = inflater.inflate(R.layout.edit_contact, container, false);
|
view = inflater.inflate(R.layout.edit_contact, container, false);
|
||||||
|
|
||||||
TextView cancel = (TextView) view.findViewById(R.id.cancel);
|
TextView cancel = (TextView) view.findViewById(R.id.cancel);
|
||||||
|
@ -87,9 +91,9 @@ public class EditContactFragment extends Fragment {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
createNewContact();
|
contactsManager.createNewContact(ops, firstName.getText().toString(), lastName.getText().toString());
|
||||||
} else {
|
} else {
|
||||||
updateExistingContact();
|
contactsManager.updateExistingContact(ops, contact, firstName.getText().toString(), lastName.getText().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (NewOrUpdatedNumberOrAddress numberOrAddress : numbersAndAddresses) {
|
for (NewOrUpdatedNumberOrAddress numberOrAddress : numbersAndAddresses) {
|
||||||
|
@ -98,7 +102,8 @@ public class EditContactFragment extends Fragment {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
|
getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
|
||||||
LinphoneActivity.instance().prepareContactsInBackground();
|
checkSipAddress();
|
||||||
|
contactsManager.prepareContactsInBackground();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -355,53 +360,6 @@ public class EditContactFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createNewContact() {
|
|
||||||
contactID = 0;
|
|
||||||
|
|
||||||
ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
|
|
||||||
.withValue(ContactsContract.RawContacts.AGGREGATION_MODE, ContactsContract.RawContacts.AGGREGATION_MODE_DEFAULT)
|
|
||||||
.withValue(RawContacts.ACCOUNT_TYPE, null)
|
|
||||||
.withValue(RawContacts.ACCOUNT_NAME, null)
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
|
|
||||||
if (getDisplayName() != null) {
|
|
||||||
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
|
||||||
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, contactID)
|
|
||||||
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
|
|
||||||
.withValue(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, firstName.getText().toString())
|
|
||||||
.withValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, lastName.getText().toString())
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateExistingContact() {
|
|
||||||
if (getDisplayName() != null) {
|
|
||||||
String select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE + "'" ;
|
|
||||||
String[] args = new String[] { String.valueOf(contactID) };
|
|
||||||
|
|
||||||
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
|
||||||
.withSelection(select, args)
|
|
||||||
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
|
|
||||||
.withValue(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, firstName.getText().toString())
|
|
||||||
.withValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, lastName.getText().toString())
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getDisplayName() {
|
|
||||||
String displayName = null;
|
|
||||||
if (firstName.getText().length() > 0 && lastName.getText().length() > 0)
|
|
||||||
displayName = firstName.getText().toString() + " " + lastName.getText().toString();
|
|
||||||
else if (firstName.getText().length() > 0)
|
|
||||||
displayName = firstName.getText().toString();
|
|
||||||
else if (lastName.getText().length() > 0)
|
|
||||||
displayName = lastName.getText().toString();
|
|
||||||
return displayName;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String findRawContactID(String contactID) {
|
private String findRawContactID(String contactID) {
|
||||||
Cursor c = getActivity().getContentResolver().query(RawContacts.CONTENT_URI,
|
Cursor c = getActivity().getContentResolver().query(RawContacts.CONTENT_URI,
|
||||||
new String[]{RawContacts._ID},RawContacts.CONTACT_ID + "=?",
|
new String[]{RawContacts._ID},RawContacts.CONTACT_ID + "=?",
|
||||||
|
@ -467,6 +425,37 @@ public class EditContactFragment extends Fragment {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean checkSipAddress(){
|
||||||
|
boolean check = true;
|
||||||
|
for (NewOrUpdatedNumberOrAddress numberOrAddress : numbersAndAddresses) {
|
||||||
|
if(numberOrAddress.newNumberOrAddress != null){
|
||||||
|
if(numberOrAddress.isSipAddress) {
|
||||||
|
if(isNewContact){
|
||||||
|
Contact c = ContactsManager.getInstance().findContactWithDisplayName(ContactsManager.getInstance().getDisplayName(firstName.getText().toString(), lastName.getText().toString()));
|
||||||
|
if (!ContactsManager.getInstance().isContactHasAddress(c, numberOrAddress.newNumberOrAddress)) {
|
||||||
|
if (c != null) {
|
||||||
|
ContactsManager.getInstance().createNewFriend(c, numberOrAddress.newNumberOrAddress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!ContactsManager.getInstance().isContactHasAddress(contact, numberOrAddress.newNumberOrAddress)) {
|
||||||
|
check = false;
|
||||||
|
if (numberOrAddress.oldNumberOrAddress == null) {
|
||||||
|
ContactsManager.getInstance().createNewFriend(contact, numberOrAddress.newNumberOrAddress);
|
||||||
|
} else {
|
||||||
|
if(contact.hasFriends())
|
||||||
|
ContactsManager.getInstance().updateFriend(numberOrAddress.oldNumberOrAddress, numberOrAddress.newNumberOrAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return check;
|
||||||
|
}
|
||||||
|
|
||||||
class NewOrUpdatedNumberOrAddress {
|
class NewOrUpdatedNumberOrAddress {
|
||||||
private String oldNumberOrAddress;
|
private String oldNumberOrAddress;
|
||||||
private String newNumberOrAddress;
|
private String newNumberOrAddress;
|
||||||
|
@ -515,7 +504,11 @@ public class EditContactFragment extends Fragment {
|
||||||
|
|
||||||
public void delete() {
|
public void delete() {
|
||||||
if (isSipAddress) {
|
if (isSipAddress) {
|
||||||
|
if(contact.hasFriends()) {
|
||||||
|
ContactsManager.getInstance().removeFriend(oldNumberOrAddress);
|
||||||
|
} else {
|
||||||
Compatibility.deleteSipAddressFromContact(ops, oldNumberOrAddress, String.valueOf(contactID));
|
Compatibility.deleteSipAddressFromContact(ops, oldNumberOrAddress, String.valueOf(contactID));
|
||||||
|
}
|
||||||
Compatibility.deleteLinphoneContactTag(ops, oldNumberOrAddress, findRawLinphoneContactID(String.valueOf(contactID)));
|
Compatibility.deleteLinphoneContactTag(ops, oldNumberOrAddress, findRawLinphoneContactID(String.valueOf(contactID)));
|
||||||
} else {
|
} else {
|
||||||
String select = ContactsContract.Data.CONTACT_ID + "=? AND "
|
String select = ContactsContract.Data.CONTACT_ID + "=? AND "
|
||||||
|
@ -559,9 +552,9 @@ public class EditContactFragment extends Fragment {
|
||||||
newNumberOrAddress = newNumberOrAddress.substring(4);
|
newNumberOrAddress = newNumberOrAddress.substring(4);
|
||||||
if(!newNumberOrAddress.contains("@"))
|
if(!newNumberOrAddress.contains("@"))
|
||||||
newNumberOrAddress = newNumberOrAddress + "@" + getResources().getString(R.string.default_domain);
|
newNumberOrAddress = newNumberOrAddress + "@" + getResources().getString(R.string.default_domain);
|
||||||
|
|
||||||
Compatibility.addSipAddressToContact(getActivity(), ops, newNumberOrAddress, rawContactId);
|
Compatibility.addSipAddressToContact(getActivity(), ops, newNumberOrAddress, rawContactId);
|
||||||
Compatibility.addLinphoneContactTag(getActivity(), ops, newNumberOrAddress, findRawLinphoneContactID(String.valueOf(contactID)));
|
Compatibility.addLinphoneContactTag(getActivity(), ops, newNumberOrAddress, findRawLinphoneContactID(String.valueOf(contactID)));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||||
.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactId)
|
.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactId)
|
||||||
|
|
|
@ -112,12 +112,12 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
|
||||||
LinphoneAddress lAddress;
|
LinphoneAddress lAddress;
|
||||||
try {
|
try {
|
||||||
lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri);
|
lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri);
|
||||||
Uri pictureUri = LinphoneUtils.findUriPictureOfContactAndSetDisplayName(lAddress, view.getContext().getContentResolver());
|
Contact contact = ContactsManager.getInstance().findContactWithAddress(lAddress);
|
||||||
if(pictureUri != null)
|
if (contact != null) {
|
||||||
LinphoneUtils.setImagePictureFromUri(view.getContext(), contactPicture.getView(), Uri.parse(pictureUri.toString()), R.drawable.unknown_small);
|
LinphoneUtils.setImagePictureFromUri(view.getContext(), contactPicture.getView(),contact.getPhotoUri(), R.drawable.unknown_small);
|
||||||
String displayName = lAddress.getDisplayName();
|
|
||||||
if (displayName != null) {
|
|
||||||
view.findViewById(R.id.addContactRow).setVisibility(View.GONE);
|
view.findViewById(R.id.addContactRow).setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
LinphoneUtils.setImagePictureFromUri(view.getContext(), contactPicture.getView(),null ,R.drawable.unknown_small);
|
||||||
}
|
}
|
||||||
} catch (LinphoneCoreException e) {
|
} catch (LinphoneCoreException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -178,15 +178,16 @@ public class HistoryFragment extends Fragment implements OnClickListener, OnChil
|
||||||
address = log.getTo();
|
address = log.getTo();
|
||||||
}
|
}
|
||||||
|
|
||||||
LinphoneUtils.findUriPictureOfContactAndSetDisplayName(address, getActivity().getContentResolver());
|
Contact contact = ContactsManager.getInstance().findContactWithAddress(address);
|
||||||
displayName = address.getDisplayName();
|
|
||||||
String sipUri = address.asStringUriOnly();
|
String sipUri = address.asStringUriOnly();
|
||||||
if (displayName == null) {
|
if (contact == null) {
|
||||||
if (getResources().getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(sipUri)) {
|
if (getResources().getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(sipUri)) {
|
||||||
displayName = LinphoneUtils.getUsernameFromAddress(sipUri);
|
displayName = address.getUserName();
|
||||||
} else {
|
} else {
|
||||||
displayName = sipUri;
|
displayName = sipUri;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
displayName = contact.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
return displayName;
|
return displayName;
|
||||||
|
@ -390,7 +391,6 @@ public class HistoryFragment extends Fragment implements OnClickListener, OnChil
|
||||||
callDirection.setImageBitmap(outgoingCall);
|
callDirection.setImageBitmap(outgoingCall);
|
||||||
}
|
}
|
||||||
|
|
||||||
LinphoneUtils.findUriPictureOfContactAndSetDisplayName(address, view.getContext().getContentResolver());
|
|
||||||
String sipUri = address.asStringUriOnly();
|
String sipUri = address.asStringUriOnly();
|
||||||
dateAndTime.setText(log.getStartDate() + " " + log.getCallDuration());
|
dateAndTime.setText(log.getStartDate() + " " + log.getCallDuration());
|
||||||
view.setTag(sipUri);
|
view.setTag(sipUri);
|
||||||
|
@ -456,7 +456,6 @@ public class HistoryFragment extends Fragment implements OnClickListener, OnChil
|
||||||
address = log.getTo();
|
address = log.getTo();
|
||||||
}
|
}
|
||||||
|
|
||||||
LinphoneUtils.findUriPictureOfContactAndSetDisplayName(address, view.getContext().getContentResolver());
|
|
||||||
String displayName = getCorrespondentDisplayName(log);
|
String displayName = getCorrespondentDisplayName(log);
|
||||||
String sipUri = address.asStringUriOnly();
|
String sipUri = address.asStringUriOnly();
|
||||||
contact.setText(displayName + " (" + getChildrenCount(groupPosition) + ")");
|
contact.setText(displayName + " (" + getChildrenCount(groupPosition) + ")");
|
||||||
|
|
|
@ -392,21 +392,24 @@ public class HistorySimpleFragment extends Fragment implements OnClickListener,
|
||||||
callDirection.setImageBitmap(outgoingCall);
|
callDirection.setImageBitmap(outgoingCall);
|
||||||
}
|
}
|
||||||
|
|
||||||
LinphoneUtils.findUriPictureOfContactAndSetDisplayName(address, view.getContext().getContentResolver());
|
Contact c = ContactsManager.getInstance().findContactWithAddress(address);
|
||||||
String displayName = address.getDisplayName();
|
String displayName = null;
|
||||||
String sipUri = address.asStringUriOnly();
|
final String sipUri = address.asStringUriOnly();
|
||||||
|
if(c != null){
|
||||||
|
displayName = c.getName();
|
||||||
|
}
|
||||||
|
|
||||||
if (displayName == null) {
|
if (displayName == null) {
|
||||||
if (getResources().getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(sipUri)) {
|
if (getResources().getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(sipUri)) {
|
||||||
contact.setText(LinphoneUtils.getUsernameFromAddress(sipUri));
|
contact.setText(address.getUserName());
|
||||||
} else {
|
} else {
|
||||||
contact.setText(sipUri);
|
contact.setText(sipUri);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (getResources().getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(address.getDisplayName())) {
|
if (getResources().getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(address.getDisplayName())) {
|
||||||
contact.setText(LinphoneUtils.getUsernameFromAddress(address.getDisplayName()));
|
|
||||||
} else {
|
|
||||||
contact.setText(displayName);
|
contact.setText(displayName);
|
||||||
|
} else {
|
||||||
|
contact.setText(sipUri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
view.setTag(sipUri);
|
view.setTag(sipUri);
|
||||||
|
@ -421,7 +424,7 @@ public class HistorySimpleFragment extends Fragment implements OnClickListener,
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (LinphoneActivity.isInstanciated()) {
|
if (LinphoneActivity.isInstanciated()) {
|
||||||
LinphoneActivity.instance().displayHistoryDetail(address.asStringUriOnly(), log);
|
LinphoneActivity.instance().displayHistoryDetail(sipUri, log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1299,8 +1299,12 @@ public class InCallActivity extends FragmentActivity implements OnClickListener
|
||||||
|
|
||||||
// Image Row
|
// Image Row
|
||||||
LinearLayout imageView = (LinearLayout) inflater.inflate(R.layout.active_call_image_row, container, false);
|
LinearLayout imageView = (LinearLayout) inflater.inflate(R.layout.active_call_image_row, container, false);
|
||||||
Uri pictureUri = LinphoneUtils.findUriPictureOfContactAndSetDisplayName(lAddress, imageView.getContext().getContentResolver());
|
Contact contact = ContactsManager.getInstance().findContactWithAddress(lAddress);
|
||||||
displayOrHideContactPicture(imageView, pictureUri, false);
|
if(contact != null) {
|
||||||
|
displayOrHideContactPicture(imageView, contact.getPhotoUri(), false);
|
||||||
|
} else {
|
||||||
|
displayOrHideContactPicture(imageView, null, false);
|
||||||
|
}
|
||||||
callsList.addView(imageView);
|
callsList.addView(imageView);
|
||||||
|
|
||||||
callView.setTag(imageView);
|
callView.setTag(imageView);
|
||||||
|
@ -1322,17 +1326,15 @@ public class InCallActivity extends FragmentActivity implements OnClickListener
|
||||||
private void setContactName(LinearLayout callView, LinphoneAddress lAddress, String sipUri, Resources resources) {
|
private void setContactName(LinearLayout callView, LinphoneAddress lAddress, String sipUri, Resources resources) {
|
||||||
TextView contact = (TextView) callView.findViewById(R.id.contactNameOrNumber);
|
TextView contact = (TextView) callView.findViewById(R.id.contactNameOrNumber);
|
||||||
|
|
||||||
LinphoneUtils.findUriPictureOfContactAndSetDisplayName(lAddress, callView.getContext().getContentResolver());
|
Contact lContact = ContactsManager.getInstance().findContactWithAddress(lAddress);
|
||||||
String displayName = lAddress.getDisplayName();
|
if (lContact == null) {
|
||||||
|
|
||||||
if (displayName == null) {
|
|
||||||
if (resources.getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(sipUri)) {
|
if (resources.getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(sipUri)) {
|
||||||
contact.setText(LinphoneUtils.getUsernameFromAddress(sipUri));
|
contact.setText(lAddress.getUserName());
|
||||||
} else {
|
} else {
|
||||||
contact.setText(sipUri);
|
contact.setText(sipUri);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
contact.setText(displayName);
|
contact.setText(lContact.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,11 +124,11 @@ public class IncomingCallActivity extends Activity implements LinphoneSliderTrig
|
||||||
}
|
}
|
||||||
LinphoneAddress address = mCall.getRemoteAddress();
|
LinphoneAddress address = mCall.getRemoteAddress();
|
||||||
// May be greatly sped up using a drawable cache
|
// May be greatly sped up using a drawable cache
|
||||||
Uri uri = LinphoneUtils.findUriPictureOfContactAndSetDisplayName(address, getContentResolver());
|
Contact contact = ContactsManager.getInstance().findContactWithAddress(address);
|
||||||
LinphoneUtils.setImagePictureFromUri(this, mPictureView.getView(), uri, R.drawable.unknown_small);
|
LinphoneUtils.setImagePictureFromUri(this, mPictureView.getView(), contact != null ? contact.getPhotoUri() : null, R.drawable.unknown_small);
|
||||||
|
|
||||||
// To be done after findUriPictureOfContactAndSetDisplayName called
|
// To be done after findUriPictureOfContactAndSetDisplayName called
|
||||||
mNameView.setText(address.getDisplayName());
|
mNameView.setText(contact != null ? contact.getName() : "");
|
||||||
if (getResources().getBoolean(R.bool.only_display_username_if_unknown)) {
|
if (getResources().getBoolean(R.bool.only_display_username_if_unknown)) {
|
||||||
mNumberView.setText(address.getUserName());
|
mNumberView.setText(address.getUserName());
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -42,29 +42,23 @@ import org.linphone.core.LinphoneCore.RegistrationState;
|
||||||
import org.linphone.core.LinphoneCoreException;
|
import org.linphone.core.LinphoneCoreException;
|
||||||
import org.linphone.core.LinphoneCoreFactory;
|
import org.linphone.core.LinphoneCoreFactory;
|
||||||
import org.linphone.core.LinphoneCoreListenerBase;
|
import org.linphone.core.LinphoneCoreListenerBase;
|
||||||
import org.linphone.core.LinphoneFriend;
|
|
||||||
import org.linphone.core.LinphoneProxyConfig;
|
import org.linphone.core.LinphoneProxyConfig;
|
||||||
import org.linphone.mediastream.Log;
|
import org.linphone.mediastream.Log;
|
||||||
import org.linphone.setup.RemoteProvisioningLoginActivity;
|
import org.linphone.setup.RemoteProvisioningLoginActivity;
|
||||||
import org.linphone.setup.SetupActivity;
|
import org.linphone.setup.SetupActivity;
|
||||||
import org.linphone.ui.AddressText;
|
import org.linphone.ui.AddressText;
|
||||||
|
|
||||||
import android.accounts.Account;
|
|
||||||
import android.accounts.AccountManager;
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.ContentProviderOperation;
|
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.database.Cursor;
|
import android.database.ContentObserver;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
import android.support.v4.app.DialogFragment;
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.Fragment.SavedState;
|
import android.support.v4.app.Fragment.SavedState;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
@ -81,7 +75,6 @@ import android.view.ViewGroup;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.animation.AnimationUtils;
|
import android.view.animation.AnimationUtils;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
|
@ -110,12 +103,9 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
private List<FragmentsAvailable> fragmentsHistory;
|
private List<FragmentsAvailable> fragmentsHistory;
|
||||||
private Fragment dialerFragment, messageListFragment, friendStatusListenerFragment;
|
private Fragment dialerFragment, messageListFragment, friendStatusListenerFragment;
|
||||||
private SavedState dialerSavedState;
|
private SavedState dialerSavedState;
|
||||||
private boolean preferLinphoneContacts = false, isAnimationDisabled = false, isContactPresenceDisabled = true;
|
private boolean isAnimationDisabled = false, preferLinphoneContacts = false;
|
||||||
private List<Contact> contactList, sipContactList;
|
|
||||||
private Cursor contactCursor, sipContactCursor;
|
|
||||||
private OrientationEventListener mOrientationHelper;
|
private OrientationEventListener mOrientationHelper;
|
||||||
private LinphoneCoreListenerBase mListener;
|
private LinphoneCoreListenerBase mListener;
|
||||||
private Account mAccount;
|
|
||||||
|
|
||||||
static final boolean isInstanciated() {
|
static final boolean isInstanciated() {
|
||||||
return instance != null;
|
return instance != null;
|
||||||
|
@ -159,11 +149,12 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ContactsManager.getInstance().initializeSyncAccount(getApplicationContext(), getContentResolver());
|
||||||
|
|
||||||
/*if(!LinphonePreferences.instance().isContactsMigrationDone()){
|
if(!LinphonePreferences.instance().isContactsMigrationDone()){
|
||||||
migrateContacts(this);
|
//ContactsManager.getInstance().migrateContacts();
|
||||||
LinphonePreferences.instance().contactsMigrationDone();
|
//LinphonePreferences.instance().contactsMigrationDone();
|
||||||
}*/
|
}
|
||||||
|
|
||||||
setContentView(R.layout.main);
|
setContentView(R.layout.main);
|
||||||
instance = this;
|
instance = this;
|
||||||
|
@ -181,8 +172,6 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mAccount = initializeSyncAccount(this);
|
|
||||||
|
|
||||||
mListener = new LinphoneCoreListenerBase(){
|
mListener = new LinphoneCoreListenerBase(){
|
||||||
@Override
|
@Override
|
||||||
public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) {
|
public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) {
|
||||||
|
@ -262,12 +251,6 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
updateAnimationsState();
|
updateAnimationsState();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Account initializeSyncAccount(Context context) {
|
|
||||||
Account newAccount = new Account(context.getString(R.string.sync_account_name), context.getString(R.string.sync_account_type));
|
|
||||||
AccountManager accountManager = (AccountManager) context.getSystemService(ACCOUNT_SERVICE);
|
|
||||||
accountManager.addAccountExplicitly(newAccount, null, null);
|
|
||||||
return newAccount;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initButtons() {
|
private void initButtons() {
|
||||||
menu = (LinearLayout) findViewById(R.id.menu);
|
menu = (LinearLayout) findViewById(R.id.menu);
|
||||||
|
@ -421,17 +404,12 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
|
|
||||||
private void updateAnimationsState() {
|
private void updateAnimationsState() {
|
||||||
isAnimationDisabled = getResources().getBoolean(R.bool.disable_animations) || !LinphonePreferences.instance().areAnimationsEnabled();
|
isAnimationDisabled = getResources().getBoolean(R.bool.disable_animations) || !LinphonePreferences.instance().areAnimationsEnabled();
|
||||||
isContactPresenceDisabled = !getResources().getBoolean(R.bool.enable_linphone_friends);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAnimationDisabled() {
|
public boolean isAnimationDisabled() {
|
||||||
return isAnimationDisabled;
|
return isAnimationDisabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isContactPresenceDisabled() {
|
|
||||||
return isContactPresenceDisabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void changeFragment(Fragment newFragment, FragmentsAvailable newFragmentType, boolean withoutAnimation) {
|
private void changeFragment(Fragment newFragment, FragmentsAvailable newFragmentType, boolean withoutAnimation) {
|
||||||
if (statusFragment != null) {
|
if (statusFragment != null) {
|
||||||
statusFragment.closeStatusBar();
|
statusFragment.closeStatusBar();
|
||||||
|
@ -538,10 +516,10 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
Log.e("Cannot display history details",e);
|
Log.e("Cannot display history details",e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Uri uri = LinphoneUtils.findUriPictureOfContactAndSetDisplayName(lAddress, getContentResolver());
|
Contact c = ContactsManager.getInstance().findContactWithAddress(lAddress);
|
||||||
|
|
||||||
String displayName = lAddress.getDisplayName();
|
String displayName = c != null ? c.getName() : null;
|
||||||
String pictureUri = uri == null ? null : uri.toString();
|
String pictureUri = c != null && c.getPhotoUri() != null ? c.getPhotoUri().toString() : null;
|
||||||
|
|
||||||
String status;
|
String status;
|
||||||
if (log.getDirection() == CallDirection.Outgoing) {
|
if (log.getDirection() == CallDirection.Outgoing) {
|
||||||
|
@ -631,9 +609,9 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
Log.e("Cannot display chat",e);
|
Log.e("Cannot display chat",e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Uri uri = LinphoneUtils.findUriPictureOfContactAndSetDisplayName(lAddress, getContentResolver());
|
Contact contact = ContactsManager.getInstance().findContactWithAddress(lAddress);
|
||||||
String displayName = lAddress.getDisplayName();
|
String displayName = contact != null ? contact.getName() : null;
|
||||||
String pictureUri = uri == null ? null : uri.toString();
|
String pictureUri = contact != null && contact.getPhotoUri() != null ? contact.getPhotoUri().toString() : null;
|
||||||
|
|
||||||
if (currentFragment == FragmentsAvailable.CHATLIST || currentFragment == FragmentsAvailable.CHAT) {
|
if (currentFragment == FragmentsAvailable.CHATLIST || currentFragment == FragmentsAvailable.CHAT) {
|
||||||
if (isTablet()) {
|
if (isTablet()) {
|
||||||
|
@ -650,17 +628,17 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
}
|
}
|
||||||
changeCurrentFragment(FragmentsAvailable.CHAT, extras);
|
changeCurrentFragment(FragmentsAvailable.CHAT, extras);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Intent intent = new Intent(this, ChatActivity.class);
|
Intent intent = new Intent(this, ChatActivity.class);
|
||||||
intent.putExtra("SipUri", sipUri);
|
intent.putExtra("SipUri", sipUri);
|
||||||
if (lAddress.getDisplayName() != null) {
|
if (contact != null) {
|
||||||
intent.putExtra("DisplayName", displayName);
|
intent.putExtra("DisplayName", contact.getName());
|
||||||
intent.putExtra("PictureUri", pictureUri);
|
intent.putExtra("PictureUri", contact.getPhotoUri());
|
||||||
}
|
}
|
||||||
startOrientationSensor();
|
startOrientationSensor();
|
||||||
startActivityForResult(intent, CHAT_ACTIVITY);
|
startActivityForResult(intent, CHAT_ACTIVITY);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
LinphoneService.instance().resetMessageNotifCount();
|
LinphoneService.instance().resetMessageNotifCount();
|
||||||
LinphoneService.instance().removeMessageNotification();
|
LinphoneService.instance().removeMessageNotification();
|
||||||
|
@ -927,7 +905,6 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
}
|
}
|
||||||
|
|
||||||
private int mAlwaysChangingPhoneAngle = -1;
|
private int mAlwaysChangingPhoneAngle = -1;
|
||||||
private AcceptNewFriendDialog acceptNewFriendDialog;
|
|
||||||
|
|
||||||
private class LocalOrientationEventListener extends OrientationEventListener {
|
private class LocalOrientationEventListener extends OrientationEventListener {
|
||||||
public LocalOrientationEventListener(Context context) {
|
public LocalOrientationEventListener(Context context) {
|
||||||
|
@ -966,251 +943,6 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showPreferenceErrorDialog(String message) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Contact> getAllContacts() {
|
|
||||||
return contactList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Contact> getSIPContacts() {
|
|
||||||
return sipContactList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cursor getAllContactsCursor() {
|
|
||||||
return contactCursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cursor getSIPContactsCursor() {
|
|
||||||
return sipContactCursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLinphoneContactsPrefered(boolean isPrefered) {
|
|
||||||
preferLinphoneContacts = isPrefered;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isLinphoneContactsPrefered() {
|
|
||||||
return preferLinphoneContacts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onNewSubscriptionRequestReceived(LinphoneFriend friend,
|
|
||||||
String sipUri) {
|
|
||||||
if (isContactPresenceDisabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sipUri = sipUri.replace("<", "").replace(">", "");
|
|
||||||
if (LinphonePreferences.instance().shouldAutomaticallyAcceptFriendsRequests()) {
|
|
||||||
Contact contact = findContactWithSipAddress(sipUri);
|
|
||||||
if (contact != null) {
|
|
||||||
friend.enableSubscribes(true);
|
|
||||||
try {
|
|
||||||
LinphoneManager.getLc().addFriend(friend);
|
|
||||||
contact.setFriend(friend);
|
|
||||||
} catch (LinphoneCoreException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Contact contact = findContactWithSipAddress(sipUri);
|
|
||||||
if (contact != null) {
|
|
||||||
FragmentManager fm = getSupportFragmentManager();
|
|
||||||
acceptNewFriendDialog = new AcceptNewFriendDialog(contact, sipUri);
|
|
||||||
acceptNewFriendDialog.show(fm, "New Friend Request Dialog");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Contact findContactWithSipAddress(String sipUri) {
|
|
||||||
if (!sipUri.startsWith("sip:")) {
|
|
||||||
sipUri = "sip:" + sipUri;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Contact contact : sipContactList) {
|
|
||||||
for (String addr : contact.getNumbersOrAddresses()) {
|
|
||||||
if (addr.equals(sipUri)) {
|
|
||||||
return contact;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onNotifyPresenceReceived(LinphoneFriend friend) {
|
|
||||||
if (!isContactPresenceDisabled && currentFragment == FragmentsAvailable.CONTACTS && friendStatusListenerFragment != null) {
|
|
||||||
((ContactsFragment) friendStatusListenerFragment).invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean newFriend(Contact contact, String sipUri) {
|
|
||||||
LinphoneFriend friend = LinphoneCoreFactory.instance().createLinphoneFriend(sipUri);
|
|
||||||
friend.enableSubscribes(true);
|
|
||||||
friend.setIncSubscribePolicy(LinphoneFriend.SubscribePolicy.SPAccept);
|
|
||||||
try {
|
|
||||||
LinphoneManager.getLc().addFriend(friend);
|
|
||||||
contact.setFriend(friend);
|
|
||||||
return true;
|
|
||||||
} catch (LinphoneCoreException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void acceptNewFriend(Contact contact, String sipUri, boolean accepted) {
|
|
||||||
acceptNewFriendDialog.dismissAllowingStateLoss();
|
|
||||||
if (accepted) {
|
|
||||||
newFriend(contact, sipUri);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean removeFriend(Contact contact, String sipUri) {
|
|
||||||
LinphoneFriend friend = LinphoneManager.getLc().findFriendByAddress(sipUri);
|
|
||||||
if (friend != null) {
|
|
||||||
friend.enableSubscribes(false);
|
|
||||||
LinphoneManager.getLc().removeFriend(friend);
|
|
||||||
contact.setFriend(null);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void searchFriendAndAddToContact(Contact contact) {
|
|
||||||
if (contact == null || contact.getNumbersOrAddresses() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String sipUri : contact.getNumbersOrAddresses()) {
|
|
||||||
if (LinphoneUtils.isSipAddress(sipUri)) {
|
|
||||||
LinphoneFriend friend = LinphoneManager.getLc().findFriendByAddress(sipUri);
|
|
||||||
if (friend != null) {
|
|
||||||
friend.enableSubscribes(true);
|
|
||||||
friend.setIncSubscribePolicy(LinphoneFriend.SubscribePolicy.SPAccept);
|
|
||||||
contact.setFriend(friend);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeContactFromLists(Contact contact) {
|
|
||||||
for (Contact c : contactList) {
|
|
||||||
if (c != null && c.getID().equals(contact.getID())) {
|
|
||||||
contactList.remove(c);
|
|
||||||
contactCursor = Compatibility.getContactsCursor(getContentResolver());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Contact c : sipContactList) {
|
|
||||||
if (c != null && c.getID().equals(contact.getID())) {
|
|
||||||
sipContactList.remove(c);
|
|
||||||
sipContactCursor = Compatibility.getSIPContactsCursor(getContentResolver());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void migrateContacts(Context context) {
|
|
||||||
ContentResolver cr = getContentResolver();
|
|
||||||
Cursor oldContacts = Compatibility.getImContactsCursor(cr);
|
|
||||||
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
|
|
||||||
|
|
||||||
if(oldContacts != null){
|
|
||||||
for (int i = 0; i < oldContacts.getCount(); i++) {
|
|
||||||
Contact c = Compatibility.getContact(cr, oldContacts, i);
|
|
||||||
for (String address : Compatibility.extractContactImAddresses(c.getID(), cr)) {
|
|
||||||
if (LinphoneUtils.isSipAddress(address)) {
|
|
||||||
if (address.startsWith("sip:")) {
|
|
||||||
address = address.substring(4);
|
|
||||||
}
|
|
||||||
Compatibility.addSipAddressToContact(context, ops, address, ContactHelper.findRawContactID(cr,c.getID()));
|
|
||||||
try {
|
|
||||||
cr.applyBatch(ContactsContract.AUTHORITY, ops);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
ops.clear();
|
|
||||||
c.refresh(cr);
|
|
||||||
if(c.getNumbersOrAddresses().contains("sip:"+address)){
|
|
||||||
Compatibility.deleteImAddressFromContact(ops, address, c.getID());
|
|
||||||
try {
|
|
||||||
cr.applyBatch(ContactsContract.AUTHORITY, ops);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Log.w("Cannot migrate this contact " + c.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ops.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public synchronized void prepareContactsInBackground() {
|
|
||||||
if (contactCursor != null) {
|
|
||||||
contactCursor.close();
|
|
||||||
}
|
|
||||||
if (sipContactCursor != null) {
|
|
||||||
sipContactCursor.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
contactCursor = Compatibility.getContactsCursor(getContentResolver());
|
|
||||||
sipContactCursor = Compatibility.getSIPContactsCursor(getContentResolver());
|
|
||||||
|
|
||||||
Thread sipContactsHandler = new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if(sipContactCursor != null) {
|
|
||||||
Log.w(sipContactCursor.getCount());
|
|
||||||
for (int i = 0; i < sipContactCursor.getCount(); i++) {
|
|
||||||
Contact contact = Compatibility.getContact(getContentResolver(), sipContactCursor, i);
|
|
||||||
if (contact == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
contact.refresh(getContentResolver());
|
|
||||||
//Add tag to Linphone contact if it not existed
|
|
||||||
if(!ContactHelper.isContactHasLinphoneTag(contact,getContentResolver())){
|
|
||||||
Compatibility.createLinphoneContactTag(getApplicationContext(),getContentResolver(),contact,
|
|
||||||
ContactHelper.findRawContactID(getContentResolver(),String.valueOf(contact.getID())));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isContactPresenceDisabled) {
|
|
||||||
searchFriendAndAddToContact(contact);
|
|
||||||
}
|
|
||||||
sipContactList.add(contact);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(contactCursor != null){
|
|
||||||
for (int i = 0; i < contactCursor.getCount(); i++) {
|
|
||||||
Contact contact = Compatibility.getContact(getContentResolver(), contactCursor, i);
|
|
||||||
|
|
||||||
if (contact == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
for (Contact c : sipContactList) {
|
|
||||||
if (c != null && c.getID().equals(contact.getID())) {
|
|
||||||
contact = c;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
contactList.add(contact);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
getContentResolver().requestSync(mAccount, ContactsContract.AUTHORITY, new Bundle());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
contactList = new ArrayList<Contact>();
|
|
||||||
sipContactList = new ArrayList<Contact>();
|
|
||||||
|
|
||||||
sipContactsHandler.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initInCallMenuLayout(boolean callTransfer) {
|
private void initInCallMenuLayout(boolean callTransfer) {
|
||||||
selectMenu(FragmentsAvailable.DIALER);
|
selectMenu(FragmentsAvailable.DIALER);
|
||||||
if (dialerFragment != null) {
|
if (dialerFragment != null) {
|
||||||
|
@ -1323,7 +1055,7 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
startService(new Intent(ACTION_MAIN).setClass(this, LinphoneService.class));
|
startService(new Intent(ACTION_MAIN).setClass(this, LinphoneService.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareContactsInBackground();
|
ContactsManager.getInstance().prepareContactsInBackground();
|
||||||
|
|
||||||
updateMissedChatCount();
|
updateMissedChatCount();
|
||||||
|
|
||||||
|
@ -1467,42 +1199,6 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
}
|
}
|
||||||
return super.onKeyDown(keyCode, event);
|
return super.onKeyDown(keyCode, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ValidFragment")
|
|
||||||
class AcceptNewFriendDialog extends DialogFragment {
|
|
||||||
private Contact contact;
|
|
||||||
private String sipUri;
|
|
||||||
|
|
||||||
public AcceptNewFriendDialog(Contact c, String a) {
|
|
||||||
contact = c;
|
|
||||||
sipUri = a;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
||||||
View view = inflater.inflate(R.layout.new_friend_request_dialog, container);
|
|
||||||
|
|
||||||
getDialog().setTitle(R.string.linphone_friend_new_request_title);
|
|
||||||
|
|
||||||
Button yes = (Button) view.findViewById(R.id.yes);
|
|
||||||
yes.setOnClickListener(new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
acceptNewFriend(contact, sipUri, true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Button no = (Button) view.findViewById(R.id.no);
|
|
||||||
no.setOnClickListener(new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
acceptNewFriend(contact, sipUri, false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ContactPicked {
|
interface ContactPicked {
|
||||||
|
|
|
@ -715,9 +715,13 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LinphoneUtils.findUriPictureOfContactAndSetDisplayName(from, mServiceContext.getContentResolver());
|
Contact contact = ContactsManager.getInstance().findContactWithAddress(from);
|
||||||
if (!mServiceContext.getResources().getBoolean(R.bool.disable_chat__message_notification)) {
|
if (!mServiceContext.getResources().getBoolean(R.bool.disable_chat__message_notification)) {
|
||||||
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), from.getDisplayName(), textMessage);
|
if(contact != null) {
|
||||||
|
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), contact.getName(), textMessage);
|
||||||
|
} else {
|
||||||
|
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), from.getUserName(), textMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) { }
|
} catch (Exception e) { }
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,19 +137,8 @@ public final class LinphoneUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param contact sip uri
|
|
||||||
* @return url/uri of the resource
|
|
||||||
*/
|
|
||||||
// public static Uri findUriPictureOfContactAndSetDisplayName(LinphoneAddress address, ContentResolver resolver) {
|
|
||||||
// return Compatibility.findUriPictureOfContactAndSetDisplayName(address, resolver);
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static Uri findUriPictureOfContactAndSetDisplayName(LinphoneAddress address, ContentResolver resolver) {
|
|
||||||
ContactHelper helper = new ContactHelper(address, resolver);
|
|
||||||
helper.query();
|
|
||||||
return helper.getUri();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Bitmap downloadBitmap(Uri uri) {
|
public static Bitmap downloadBitmap(Uri uri) {
|
||||||
URL url;
|
URL url;
|
||||||
|
|
|
@ -33,6 +33,7 @@ import android.provider.ContactsContract.CommonDataKinds.Phone;
|
||||||
import android.provider.ContactsContract.Contacts;
|
import android.provider.ContactsContract.Contacts;
|
||||||
import android.provider.ContactsContract.Data;
|
import android.provider.ContactsContract.Data;
|
||||||
import android.text.ClipboardManager;
|
import android.text.ClipboardManager;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.view.ViewTreeObserver;
|
import android.view.ViewTreeObserver;
|
||||||
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
|
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
|
||||||
|
|
||||||
|
@ -132,21 +133,31 @@ public class ApiFivePlus {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor getContactsCursor(ContentResolver cr) {
|
public static Cursor getContactsCursor(ContentResolver cr, List<String> ids) {
|
||||||
String req = Data.MIMETYPE + " = '" + CommonDataKinds.Phone.CONTENT_ITEM_TYPE
|
String req = Data.MIMETYPE + " = '" + CommonDataKinds.Phone.CONTENT_ITEM_TYPE
|
||||||
+ "' AND " + CommonDataKinds.Phone.NUMBER + " IS NOT NULL";
|
+ "' AND " + CommonDataKinds.Phone.NUMBER + " IS NOT NULL";
|
||||||
|
|
||||||
req += " OR (" + Contacts.Data.MIMETYPE + " = '" + CommonDataKinds.Im.CONTENT_ITEM_TYPE
|
req += " OR (" + Contacts.Data.MIMETYPE + " = '" + CommonDataKinds.Im.CONTENT_ITEM_TYPE
|
||||||
+ "' AND lower(" + CommonDataKinds.Im.CUSTOM_PROTOCOL + ") = 'sip')";
|
+ "' AND lower(" + CommonDataKinds.Im.CUSTOM_PROTOCOL + ") = 'sip')";
|
||||||
|
|
||||||
|
if(ids != null){
|
||||||
|
String s = TextUtils.join(",", ids);
|
||||||
|
req += " OR (" + Data.CONTACT_ID + " IN (" + s + "))";
|
||||||
|
}
|
||||||
|
|
||||||
return getGeneralContactCursor(cr, req, true);
|
return getGeneralContactCursor(cr, req, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor getSIPContactsCursor(ContentResolver cr) {
|
public static Cursor getSIPContactsCursor(ContentResolver cr, List<String> ids) {
|
||||||
String req = null;
|
String req = null;
|
||||||
req = Contacts.Data.MIMETYPE + " = '" + CommonDataKinds.Im.CONTENT_ITEM_TYPE
|
req = Contacts.Data.MIMETYPE + " = '" + CommonDataKinds.Im.CONTENT_ITEM_TYPE
|
||||||
+ "' AND lower(" + CommonDataKinds.Im.CUSTOM_PROTOCOL + ") = 'sip'";
|
+ "' AND lower(" + CommonDataKinds.Im.CUSTOM_PROTOCOL + ") = 'sip'";
|
||||||
|
|
||||||
|
if(ids != null){
|
||||||
|
String s = TextUtils.join(",", ids);
|
||||||
|
req += " OR (" + Data.CONTACT_ID + " IN (" + s + "))";
|
||||||
|
}
|
||||||
|
|
||||||
return getGeneralContactCursor(cr, req, true);
|
return getGeneralContactCursor(cr, req, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,10 +171,11 @@ public class ApiFivePlus {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor getGeneralContactCursor(ContentResolver cr, String select, boolean shouldGroupBy) {
|
public static Cursor getGeneralContactCursor(ContentResolver cr, String select, boolean shouldGroupBy) {
|
||||||
|
|
||||||
String[] projection = new String[] { Data.CONTACT_ID, Data.DISPLAY_NAME };
|
String[] projection = new String[] { Data.CONTACT_ID, Data.DISPLAY_NAME };
|
||||||
|
String query;
|
||||||
|
|
||||||
|
query = Data.DISPLAY_NAME + " IS NOT NULL AND (" + select + ")";
|
||||||
|
|
||||||
String query = Data.DISPLAY_NAME + " IS NOT NULL AND (" + select + ")";
|
|
||||||
Cursor cursor = cr.query(Data.CONTENT_URI, projection, query, null, " lower(" + Data.DISPLAY_NAME + ") COLLATE UNICODE ASC");
|
Cursor cursor = cr.query(Data.CONTENT_URI, projection, query, null, " lower(" + Data.DISPLAY_NAME + ") COLLATE UNICODE ASC");
|
||||||
|
|
||||||
if (!shouldGroupBy || cursor == null) {
|
if (!shouldGroupBy || cursor == null) {
|
||||||
|
|
|
@ -19,6 +19,7 @@ import android.provider.ContactsContract.CommonDataKinds;
|
||||||
import android.provider.ContactsContract.Contacts;
|
import android.provider.ContactsContract.Contacts;
|
||||||
import android.provider.ContactsContract.CommonDataKinds.Phone;
|
import android.provider.ContactsContract.CommonDataKinds.Phone;
|
||||||
import android.provider.ContactsContract.Data;
|
import android.provider.ContactsContract.Data;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
ApiNinePlus.java
|
ApiNinePlus.java
|
||||||
|
@ -130,11 +131,20 @@ public class ApiNinePlus {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor getContactsCursor(ContentResolver cr, String search) {
|
public static Cursor getContactsCursor(ContentResolver cr, String search, List<String> ids) {
|
||||||
String req = Data.MIMETYPE + " = '" + CommonDataKinds.Phone.CONTENT_ITEM_TYPE
|
String req;
|
||||||
+ "' AND " + CommonDataKinds.Phone.NUMBER + " IS NOT NULL OR ("
|
if(ids != null && ids.size() > 0) {
|
||||||
+ Data.MIMETYPE + " = '" + CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE
|
req = "(" + Data.MIMETYPE + " = '" + CommonDataKinds.Phone.CONTENT_ITEM_TYPE
|
||||||
+ "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + " IS NOT NULL)";
|
+ "' AND " + CommonDataKinds.Phone.NUMBER + " IS NOT NULL "
|
||||||
|
+ " OR (" + Data.MIMETYPE + " = '" + CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE
|
||||||
|
+ "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + " IS NOT NULL)"
|
||||||
|
+ " OR (" + Data.CONTACT_ID + " IN (" + TextUtils.join(" , ", ids) + ")))";
|
||||||
|
} else {
|
||||||
|
req = "(" + Data.MIMETYPE + " = '" + CommonDataKinds.Phone.CONTENT_ITEM_TYPE
|
||||||
|
+ "' AND " + CommonDataKinds.Phone.NUMBER + " IS NOT NULL "
|
||||||
|
+ " OR (" + Data.MIMETYPE + " = '" + CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE
|
||||||
|
+ "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + " IS NOT NULL))";
|
||||||
|
}
|
||||||
|
|
||||||
if (search != null) {
|
if (search != null) {
|
||||||
req += " AND " + Data.DISPLAY_NAME + " LIKE '%" + search + "%'";
|
req += " AND " + Data.DISPLAY_NAME + " LIKE '%" + search + "%'";
|
||||||
|
@ -143,10 +153,14 @@ public class ApiNinePlus {
|
||||||
return ApiFivePlus.getGeneralContactCursor(cr, req, true);
|
return ApiFivePlus.getGeneralContactCursor(cr, req, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor getSIPContactsCursor(ContentResolver cr, String search) {
|
public static Cursor getSIPContactsCursor(ContentResolver cr, String search, List<String> ids) {
|
||||||
String req = null;
|
|
||||||
req = Data.MIMETYPE + " = '" + CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE
|
String req = "(" + Data.MIMETYPE + " = '" + CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE
|
||||||
+ "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + " IS NOT NULL";
|
+ "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + " IS NOT NULL) ";
|
||||||
|
|
||||||
|
if(ids != null && ids.size() > 0) {
|
||||||
|
req += " OR (" + Data.CONTACT_ID + " IN (" + TextUtils.join(" , ", ids) + "))";
|
||||||
|
}
|
||||||
|
|
||||||
if (search != null) {
|
if (search != null) {
|
||||||
req += " AND " + Data.DISPLAY_NAME + " LIKE '%" + search + "%'";
|
req += " AND " + Data.DISPLAY_NAME + " LIKE '%" + search + "%'";
|
||||||
|
@ -162,6 +176,7 @@ public class ApiNinePlus {
|
||||||
|
|
||||||
return ApiFivePlus.getGeneralContactCursor(cr, req, false);
|
return ApiFivePlus.getGeneralContactCursor(cr, req, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Uri findUriPictureOfContactAndSetDisplayName(LinphoneAddress address, ContentResolver cr) {
|
public static Uri findUriPictureOfContactAndSetDisplayName(LinphoneAddress address, ContentResolver cr) {
|
||||||
String username = address.getUserName();
|
String username = address.getUserName();
|
||||||
String domain = address.getDomain();
|
String domain = address.getDomain();
|
||||||
|
@ -205,8 +220,12 @@ public class ApiNinePlus {
|
||||||
|
|
||||||
public static void deleteLinphoneContactTag(ArrayList<ContentProviderOperation> ops , String oldAddress, String rawContactId){
|
public static void deleteLinphoneContactTag(ArrayList<ContentProviderOperation> ops , String oldAddress, String rawContactId){
|
||||||
if(rawContactId != null) {
|
if(rawContactId != null) {
|
||||||
|
String select = ContactsContract.Data.RAW_CONTACT_ID + "=? AND "
|
||||||
|
+ ContactsContract.Data.DATA1 + "= ?";
|
||||||
|
String[] args = new String[]{rawContactId, oldAddress};
|
||||||
|
|
||||||
ops.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
ops.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
||||||
.withSelection(ContactsContract.Data.RAW_CONTACT_ID + "=? AND " + ContactsContract.Data.DATA1 + "=? ", new String[]{rawContactId, oldAddress})
|
.withSelection(select, args)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,40 +84,40 @@ public class Compatibility {
|
||||||
return ApiFivePlus.extractContactNumbersAndAddresses(id, cr);
|
return ApiFivePlus.extractContactNumbersAndAddresses(id, cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor getContactsCursor(ContentResolver cr) {
|
public static Cursor getContactsCursor(ContentResolver cr, List<String> contactsId) {
|
||||||
if (Version.sdkAboveOrEqual(Version.API09_GINGERBREAD_23)) {
|
if (Version.sdkAboveOrEqual(Version.API09_GINGERBREAD_23)) {
|
||||||
return ApiNinePlus.getContactsCursor(cr, null);
|
return ApiNinePlus.getContactsCursor(cr, null, contactsId);
|
||||||
} else {
|
} else {
|
||||||
return ApiFivePlus.getContactsCursor(cr);
|
return ApiFivePlus.getContactsCursor(cr, contactsId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor getContactsCursor(ContentResolver cr, String search) {
|
public static Cursor getContactsCursor(ContentResolver cr, String search, List<String> contactsId) {
|
||||||
if (Version.sdkAboveOrEqual(Version.API09_GINGERBREAD_23)) {
|
if (Version.sdkAboveOrEqual(Version.API09_GINGERBREAD_23)) {
|
||||||
return ApiNinePlus.getContactsCursor(cr, search);
|
return ApiNinePlus.getContactsCursor(cr, search, contactsId);
|
||||||
} else {
|
} else {
|
||||||
return ApiFivePlus.getContactsCursor(cr);
|
return ApiFivePlus.getContactsCursor(cr, contactsId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor getSIPContactsCursor(ContentResolver cr) {
|
public static Cursor getSIPContactsCursor(ContentResolver cr, List<String> contactsId) {
|
||||||
if (Version.sdkAboveOrEqual(Version.API09_GINGERBREAD_23)) {
|
if (Version.sdkAboveOrEqual(Version.API09_GINGERBREAD_23)) {
|
||||||
return ApiNinePlus.getSIPContactsCursor(cr, null);
|
return ApiNinePlus.getSIPContactsCursor(cr, null, contactsId);
|
||||||
} else {
|
} else {
|
||||||
return ApiFivePlus.getSIPContactsCursor(cr);
|
return ApiFivePlus.getSIPContactsCursor(cr, contactsId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor getSIPContactsCursor(ContentResolver cr, String search) {
|
public static Cursor getSIPContactsCursor(ContentResolver cr, String search, List<String> contactsId) {
|
||||||
if (Version.sdkAboveOrEqual(Version.API09_GINGERBREAD_23)) {
|
if (Version.sdkAboveOrEqual(Version.API09_GINGERBREAD_23)) {
|
||||||
return ApiNinePlus.getSIPContactsCursor(cr, search);
|
return ApiNinePlus.getSIPContactsCursor(cr, search, contactsId);
|
||||||
} else {
|
} else {
|
||||||
return ApiFivePlus.getSIPContactsCursor(cr);
|
return ApiFivePlus.getSIPContactsCursor(cr, contactsId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cursor getImContactsCursor(ContentResolver cr) {
|
public static Cursor getImContactsCursor(ContentResolver cr) {
|
||||||
return ApiFivePlus.getSIPContactsCursor(cr);
|
return ApiFivePlus.getSIPContactsCursor(cr,null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getCursorDisplayNameColumnIndex(Cursor cursor) {
|
public static int getCursorDisplayNameColumnIndex(Cursor cursor) {
|
||||||
|
|
Loading…
Reference in a new issue