Started rework of contacts
This commit is contained in:
parent
9139ff69ed
commit
a75da820ed
27 changed files with 525 additions and 1005 deletions
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
<bool name="assistant_use_linphone_login_as_first_fragment">false</bool>
|
<bool name="assistant_use_linphone_login_as_first_fragment">false</bool>
|
||||||
<bool name="hide_in_call_stats">false</bool>
|
<bool name="hide_in_call_stats">false</bool>
|
||||||
<bool name="use_linphone_friend">false</bool>
|
|
||||||
<bool name="orientation_portrait_only">false</bool>
|
<bool name="orientation_portrait_only">false</bool>
|
||||||
<bool name="show_statusbar_only_on_dialer">false</bool>
|
<bool name="show_statusbar_only_on_dialer">false</bool>
|
||||||
<bool name="replace_assistant_with_old_interface">false</bool>
|
<bool name="replace_assistant_with_old_interface">false</bool>
|
||||||
|
|
|
@ -1557,12 +1557,12 @@ public class CallActivity extends Activity implements OnClickListener, SensorEve
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setContactInformation(TextView contactName, ImageView contactPicture, LinphoneAddress lAddress) {
|
private void setContactInformation(TextView contactName, ImageView contactPicture, LinphoneAddress lAddress) {
|
||||||
Contact lContact = ContactsManager.getInstance().findContactWithAddress(contactName.getContext().getContentResolver(), lAddress);
|
LinphoneContact lContact = ContactsManager.getInstance().findContactFromAddress(contactName.getContext().getContentResolver(), lAddress);
|
||||||
if (lContact == null) {
|
if (lContact == null) {
|
||||||
contactName.setText(LinphoneUtils.getAddressDisplayName(lAddress));
|
contactName.setText(LinphoneUtils.getAddressDisplayName(lAddress));
|
||||||
contactPicture.setImageResource(R.drawable.avatar);
|
contactPicture.setImageResource(R.drawable.avatar);
|
||||||
} else {
|
} else {
|
||||||
contactName.setText(lContact.getName());
|
contactName.setText(lContact.getFullName());
|
||||||
LinphoneUtils.setImagePictureFromUri(contactPicture.getContext(), contactPicture, lContact.getPhotoUri(), lContact.getThumbnailUri());
|
LinphoneUtils.setImagePictureFromUri(contactPicture.getContext(), contactPicture, lContact.getPhotoUri(), lContact.getThumbnailUri());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1720,11 +1720,11 @@ public class CallActivity extends Activity implements OnClickListener, SensorEve
|
||||||
conferenceList.setId(index + 1);
|
conferenceList.setId(index + 1);
|
||||||
TextView contact = (TextView) confView.findViewById(R.id.contactNameOrNumber);
|
TextView contact = (TextView) confView.findViewById(R.id.contactNameOrNumber);
|
||||||
|
|
||||||
Contact lContact = ContactsManager.getInstance().findContactWithAddress(getContentResolver(),call.getRemoteAddress());
|
LinphoneContact lContact = ContactsManager.getInstance().findContactFromAddress(getContentResolver(),call.getRemoteAddress());
|
||||||
if (lContact == null) {
|
if (lContact == null) {
|
||||||
contact.setText(call.getRemoteAddress().getUserName());
|
contact.setText(call.getRemoteAddress().getUserName());
|
||||||
} else {
|
} else {
|
||||||
contact.setText(lContact.getName());
|
contact.setText(lContact.getFullName());
|
||||||
}
|
}
|
||||||
|
|
||||||
registerCallDurationTimer(confView, call);
|
registerCallDurationTimer(confView, call);
|
||||||
|
|
|
@ -41,7 +41,6 @@ public class CallAudioFragment extends Fragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
super.onAttach(activity);
|
|
||||||
incallActvityInstance = (CallActivity) activity;
|
incallActvityInstance = (CallActivity) activity;
|
||||||
|
|
||||||
if (incallActvityInstance != null) {
|
if (incallActvityInstance != null) {
|
||||||
|
|
|
@ -54,7 +54,6 @@ public class CallIncomingActivity extends Activity implements LinphoneSliderTrig
|
||||||
private LinphoneCoreListenerBase mListener;
|
private LinphoneCoreListenerBase mListener;
|
||||||
private LinearLayout acceptUnlock;
|
private LinearLayout acceptUnlock;
|
||||||
private LinearLayout declineUnlock;
|
private LinearLayout declineUnlock;
|
||||||
private StatusFragment status;
|
|
||||||
private boolean isActive;
|
private boolean isActive;
|
||||||
private float answerX;
|
private float answerX;
|
||||||
private float declineX;
|
private float declineX;
|
||||||
|
@ -233,10 +232,10 @@ public class CallIncomingActivity extends Activity implements LinphoneSliderTrig
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LinphoneAddress address = mCall.getRemoteAddress();
|
LinphoneAddress address = mCall.getRemoteAddress();
|
||||||
Contact contact = ContactsManager.getInstance().findContactWithAddress(getContentResolver(), address);
|
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(getContentResolver(), address);
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
LinphoneUtils.setImagePictureFromUri(this, contactPicture, contact.getPhotoUri(), contact.getThumbnailUri());
|
LinphoneUtils.setImagePictureFromUri(this, contactPicture, contact.getPhotoUri(), contact.getThumbnailUri());
|
||||||
name.setText(contact.getName());
|
name.setText(contact.getFullName());
|
||||||
} else {
|
} else {
|
||||||
name.setText(LinphoneUtils.getAddressDisplayName(address));
|
name.setText(LinphoneUtils.getAddressDisplayName(address));
|
||||||
}
|
}
|
||||||
|
@ -267,10 +266,6 @@ public class CallIncomingActivity extends Activity implements LinphoneSliderTrig
|
||||||
return super.onKeyDown(keyCode, event);
|
return super.onKeyDown(keyCode, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateStatusFragment(StatusFragment fragment) {
|
|
||||||
status = fragment;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void decline() {
|
private void decline() {
|
||||||
LinphoneManager.getLc().terminateCall(mCall);
|
LinphoneManager.getLc().terminateCall(mCall);
|
||||||
finish();
|
finish();
|
||||||
|
|
|
@ -47,7 +47,6 @@ public class CallOutgoingActivity extends Activity implements OnClickListener{
|
||||||
private LinphoneCall mCall;
|
private LinphoneCall mCall;
|
||||||
private LinphoneCoreListenerBase mListener;
|
private LinphoneCoreListenerBase mListener;
|
||||||
private boolean isMicMuted, isSpeakerEnabled;
|
private boolean isMicMuted, isSpeakerEnabled;
|
||||||
private StatusFragment status;
|
|
||||||
|
|
||||||
public static CallOutgoingActivity instance() {
|
public static CallOutgoingActivity instance() {
|
||||||
return instance;
|
return instance;
|
||||||
|
@ -57,10 +56,6 @@ public class CallOutgoingActivity extends Activity implements OnClickListener{
|
||||||
return instance != null;
|
return instance != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateStatusFragment(StatusFragment fragment) {
|
|
||||||
status = fragment;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -148,10 +143,10 @@ public class CallOutgoingActivity extends Activity implements OnClickListener{
|
||||||
}
|
}
|
||||||
|
|
||||||
LinphoneAddress address = mCall.getRemoteAddress();
|
LinphoneAddress address = mCall.getRemoteAddress();
|
||||||
Contact contact = ContactsManager.getInstance().findContactWithAddress(getContentResolver(), address);
|
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(getContentResolver(), address);
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
LinphoneUtils.setImagePictureFromUri(this, contactPicture, contact.getPhotoUri(), contact.getThumbnailUri());
|
LinphoneUtils.setImagePictureFromUri(this, contactPicture, contact.getPhotoUri(), contact.getThumbnailUri());
|
||||||
name.setText(contact.getName());
|
name.setText(contact.getFullName());
|
||||||
} else {
|
} else {
|
||||||
name.setText(LinphoneUtils.getAddressDisplayName(address));
|
name.setText(LinphoneUtils.getAddressDisplayName(address));
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,15 +21,13 @@ import org.linphone.compatibility.Compatibility;
|
||||||
import org.linphone.compatibility.CompatibilityScaleGestureDetector;
|
import org.linphone.compatibility.CompatibilityScaleGestureDetector;
|
||||||
import org.linphone.compatibility.CompatibilityScaleGestureListener;
|
import org.linphone.compatibility.CompatibilityScaleGestureListener;
|
||||||
import org.linphone.core.LinphoneCall;
|
import org.linphone.core.LinphoneCall;
|
||||||
import org.linphone.core.LinphoneCore;
|
|
||||||
import org.linphone.mediastream.Log;
|
import org.linphone.mediastream.Log;
|
||||||
import org.linphone.mediastream.video.AndroidVideoWindowImpl;
|
import org.linphone.mediastream.video.AndroidVideoWindowImpl;
|
||||||
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
|
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
//import android.opengl.GLSurfaceView;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.view.GestureDetector;
|
import android.view.GestureDetector;
|
||||||
import android.view.GestureDetector.OnDoubleTapListener;
|
import android.view.GestureDetector.OnDoubleTapListener;
|
||||||
import android.view.GestureDetector.OnGestureListener;
|
import android.view.GestureDetector.OnGestureListener;
|
||||||
|
@ -40,6 +38,7 @@ import android.view.SurfaceView;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnTouchListener;
|
import android.view.View.OnTouchListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
//import android.opengl.GLSurfaceView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Sylvain Berfini
|
* @author Sylvain Berfini
|
||||||
|
@ -260,8 +259,6 @@ public class CallVideoFragment extends Fragment implements OnGestureListener, On
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
super.onAttach(activity);
|
|
||||||
|
|
||||||
inCallActivity = (CallActivity) activity;
|
inCallActivity = (CallActivity) activity;
|
||||||
if (inCallActivity != null) {
|
if (inCallActivity != null) {
|
||||||
inCallActivity.bindVideoFragment(this);
|
inCallActivity.bindVideoFragment(this);
|
||||||
|
|
|
@ -21,33 +21,27 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.app.Fragment;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.Matrix;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.linphone.compatibility.Compatibility;
|
import org.linphone.compatibility.Compatibility;
|
||||||
import org.linphone.core.LinphoneAddress;
|
import org.linphone.core.LinphoneAddress;
|
||||||
import org.linphone.core.LinphoneBuffer;
|
import org.linphone.core.LinphoneBuffer;
|
||||||
import org.linphone.core.LinphoneChatMessage;
|
import org.linphone.core.LinphoneChatMessage;
|
||||||
|
import org.linphone.core.LinphoneChatMessage.State;
|
||||||
import org.linphone.core.LinphoneChatRoom;
|
import org.linphone.core.LinphoneChatRoom;
|
||||||
import org.linphone.core.LinphoneContent;
|
import org.linphone.core.LinphoneContent;
|
||||||
import org.linphone.core.LinphoneCore;
|
import org.linphone.core.LinphoneCore;
|
||||||
import org.linphone.core.LinphoneChatMessage.State;
|
|
||||||
import org.linphone.core.LinphoneCoreFactory;
|
import org.linphone.core.LinphoneCoreFactory;
|
||||||
import org.linphone.core.LinphoneCoreListenerBase;
|
import org.linphone.core.LinphoneCoreListenerBase;
|
||||||
import org.linphone.mediastream.Log;
|
import org.linphone.mediastream.Log;
|
||||||
import org.linphone.ui.BubbleChat;
|
import org.linphone.ui.BubbleChat;
|
||||||
|
|
||||||
import android.media.ExifInterface;
|
|
||||||
import android.support.v4.content.CursorLoader;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.app.Fragment;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -55,13 +49,16 @@ import android.content.res.Configuration;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.graphics.Matrix;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
import android.media.ExifInterface;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
import android.support.v4.content.CursorLoader;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
|
@ -106,21 +103,18 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
|
|
||||||
private LinphoneChatRoom chatRoom;
|
private LinphoneChatRoom chatRoom;
|
||||||
private String sipUri;
|
private String sipUri;
|
||||||
private String displayName;
|
|
||||||
private String pictureUri;
|
|
||||||
private EditText message;
|
private EditText message;
|
||||||
private ImageView edit, selectAll, deselectAll, startCall, delete, sendImage, sendMessage, cancel;
|
private ImageView edit, selectAll, deselectAll, startCall, delete, sendImage, sendMessage, cancel;
|
||||||
private TextView contactName, remoteComposing;
|
private TextView contactName, remoteComposing;
|
||||||
private ImageView back, backToCall;
|
private ImageView back, backToCall;
|
||||||
private EditText searchContactField;
|
private EditText searchContactField;
|
||||||
private LinearLayout topBar, editList;
|
private LinearLayout topBar, editList;
|
||||||
private LinearLayout textLayout;
|
|
||||||
private SearchContactsListAdapter searchAdapter;
|
private SearchContactsListAdapter searchAdapter;
|
||||||
private ListView messagesList, resultContactsSearch;
|
private ListView messagesList, resultContactsSearch;
|
||||||
private LayoutInflater inflater;
|
private LayoutInflater inflater;
|
||||||
|
|
||||||
private boolean isEditMode = false;
|
private boolean isEditMode = false;
|
||||||
private Contact contact;
|
private LinphoneContact contact;
|
||||||
private Uri imageToUploadUri;
|
private Uri imageToUploadUri;
|
||||||
private String filePathToUpload;
|
private String filePathToUpload;
|
||||||
private TextWatcher textWatcher;
|
private TextWatcher textWatcher;
|
||||||
|
@ -152,8 +146,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
} else {
|
} else {
|
||||||
//Retrieve parameter from intent
|
//Retrieve parameter from intent
|
||||||
sipUri = getArguments().getString("SipUri");
|
sipUri = getArguments().getString("SipUri");
|
||||||
displayName = getArguments().getString("DisplayName");
|
|
||||||
pictureUri = getArguments().getString("PictureUri");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Initialize UI
|
//Initialize UI
|
||||||
|
@ -163,7 +155,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
resultContactsSearch = (ListView) view.findViewById(R.id.result_contacts);
|
resultContactsSearch = (ListView) view.findViewById(R.id.result_contacts);
|
||||||
|
|
||||||
editList = (LinearLayout) view.findViewById(R.id.edit_list);
|
editList = (LinearLayout) view.findViewById(R.id.edit_list);
|
||||||
textLayout = (LinearLayout) view.findViewById(R.id.message_layout);
|
|
||||||
topBar = (LinearLayout) view.findViewById(R.id.top_bar);
|
topBar = (LinearLayout) view.findViewById(R.id.top_bar);
|
||||||
|
|
||||||
sendMessage = (ImageView) view.findViewById(R.id.send_message);
|
sendMessage = (ImageView) view.findViewById(R.id.send_message);
|
||||||
|
@ -468,7 +459,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
chatRoom = lc.getChatRoom(lAddress);
|
chatRoom = lc.getChatRoom(lAddress);
|
||||||
chatRoom.markAsRead();
|
chatRoom.markAsRead();
|
||||||
LinphoneActivity.instance().updateMissedChatCount();
|
LinphoneActivity.instance().updateMissedChatCount();
|
||||||
contact = ContactsManager.getInstance().findContactWithAddress(getActivity().getContentResolver(), lAddress);
|
contact = ContactsManager.getInstance().findContactFromAddress(getActivity().getContentResolver(), lAddress);
|
||||||
if (chatRoom != null) {
|
if (chatRoom != null) {
|
||||||
displayChatHeader(lAddress);
|
displayChatHeader(lAddress);
|
||||||
dispayMessageList();
|
dispayMessageList();
|
||||||
|
@ -487,7 +478,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
|
|
||||||
private void displayChatHeader(LinphoneAddress address) {
|
private void displayChatHeader(LinphoneAddress address) {
|
||||||
if(contact != null) {
|
if(contact != null) {
|
||||||
contactName.setText(contact.getName());
|
contactName.setText(contact.getFullName());
|
||||||
} else if(address != null){
|
} else if(address != null){
|
||||||
contactName.setText(LinphoneUtils.getAddressDisplayName(address));
|
contactName.setText(LinphoneUtils.getAddressDisplayName(address));
|
||||||
}
|
}
|
||||||
|
@ -495,9 +486,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
|
|
||||||
public void changeDisplayedChat(String newSipUri, String displayName, String pictureUri) {
|
public void changeDisplayedChat(String newSipUri, String displayName, String pictureUri) {
|
||||||
this.sipUri = newSipUri;
|
this.sipUri = newSipUri;
|
||||||
this.displayName = displayName;
|
|
||||||
this.pictureUri = pictureUri;
|
|
||||||
|
|
||||||
initChatRoom(sipUri);
|
initChatRoom(sipUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -732,7 +720,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
|
|
||||||
//Start new conversation in fast chat
|
//Start new conversation in fast chat
|
||||||
if(newChatConversation && chatRoom == null) {
|
if(newChatConversation && chatRoom == null) {
|
||||||
String address = searchContactField.getText().toString().toLowerCase();
|
String address = searchContactField.getText().toString().toLowerCase(Locale.getDefault());
|
||||||
if (address != null && !address.equals("")) {
|
if (address != null && !address.equals("")) {
|
||||||
initChatRoom(address);
|
initChatRoom(address);
|
||||||
}
|
}
|
||||||
|
@ -748,7 +736,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
|
|
||||||
message.setListener(LinphoneManager.getInstance());
|
message.setListener(LinphoneManager.getInstance());
|
||||||
if (newChatConversation) {
|
if (newChatConversation) {
|
||||||
exitNewConversationMode(contact, lAddress.asStringUriOnly(), null);
|
exitNewConversationMode(lAddress.asStringUriOnly());
|
||||||
} else {
|
} else {
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
@ -860,12 +848,10 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
|
|
||||||
class FileUploadPrepareTask extends AsyncTask<Bitmap, Void, byte[]> {
|
class FileUploadPrepareTask extends AsyncTask<Bitmap, Void, byte[]> {
|
||||||
private String path;
|
private String path;
|
||||||
private int imageSize;
|
|
||||||
private ProgressDialog progressDialog;
|
private ProgressDialog progressDialog;
|
||||||
|
|
||||||
public FileUploadPrepareTask(Context context, String fileToUploadPath, int size) {
|
public FileUploadPrepareTask(Context context, String fileToUploadPath, int size) {
|
||||||
path = fileToUploadPath;
|
path = fileToUploadPath;
|
||||||
imageSize = size;
|
|
||||||
|
|
||||||
progressDialog = new ProgressDialog(context);
|
progressDialog = new ProgressDialog(context);
|
||||||
progressDialog.setIndeterminate(true);
|
progressDialog.setIndeterminate(true);
|
||||||
|
@ -931,15 +917,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showPopupMenuAskingImageSize(final String filePath) {
|
|
||||||
filePathToUpload = filePath;
|
|
||||||
try {
|
|
||||||
sendImage.showContextMenu();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (requestCode == ADD_PHOTO && resultCode == Activity.RESULT_OK) {
|
if (requestCode == ADD_PHOTO && resultCode == Activity.RESULT_OK) {
|
||||||
|
@ -961,7 +938,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
|
|
||||||
//New conversation
|
//New conversation
|
||||||
private void exitNewConversationMode(Contact c, String address, String username){
|
private void exitNewConversationMode(String address) {
|
||||||
sipUri = address;
|
sipUri = address;
|
||||||
searchContactField.setVisibility(View.GONE);
|
searchContactField.setVisibility(View.GONE);
|
||||||
resultContactsSearch.setVisibility(View.GONE);
|
resultContactsSearch.setVisibility(View.GONE);
|
||||||
|
@ -1006,10 +983,10 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ContactAddress {
|
private class ContactAddress {
|
||||||
Contact contact;
|
LinphoneContact contact;
|
||||||
String address;
|
String address;
|
||||||
|
|
||||||
private ContactAddress(Contact c, String a){
|
private ContactAddress(LinphoneContact c, String a){
|
||||||
this.contact = c;
|
this.contact = c;
|
||||||
this.address = a;
|
this.address = a;
|
||||||
}
|
}
|
||||||
|
@ -1026,7 +1003,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
for (ContactAddress c : searchAdapter.contacts) {
|
for (ContactAddress c : searchAdapter.contacts) {
|
||||||
String address = c.address;
|
String address = c.address;
|
||||||
if(address.startsWith("sip:")) address = address.substring(4);
|
if(address.startsWith("sip:")) address = address.substring(4);
|
||||||
if (c.contact.getName().toLowerCase().startsWith(search.toLowerCase()) || address.toLowerCase().startsWith(search.toLowerCase())) {
|
if (c.contact.getFullName().toLowerCase(Locale.getDefault()).startsWith(search.toLowerCase(Locale.getDefault()))
|
||||||
|
|| address.toLowerCase(Locale.getDefault()).startsWith(search.toLowerCase(Locale.getDefault()))) {
|
||||||
result.add(c);
|
result.add(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1049,12 +1027,12 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ContactAddress>getContactsList(){
|
public List<ContactAddress> getContactsList() {
|
||||||
List<ContactAddress> list = new ArrayList<ContactAddress>();
|
List<ContactAddress> list = new ArrayList<ContactAddress>();
|
||||||
if(ContactsManager.getInstance().getAllContacts() != null) {
|
if(ContactsManager.getInstance().hasContacts()) {
|
||||||
for (Contact con : ContactsManager.getInstance().getAllContacts()) {
|
for (LinphoneContact con : ContactsManager.getInstance().getContacts()) {
|
||||||
for (String numberOrAddress : con.getNumbersOrAddresses()) {
|
for (LinphoneNumberOrAddress noa : con.getNumbersOrAddresses()) {
|
||||||
list.add(new ContactAddress(con, numberOrAddress));
|
list.add(new ContactAddress(con, noa.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1092,10 +1070,10 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
|
|
||||||
final String a = contact.address;
|
final String a = contact.address;
|
||||||
final Contact c = contact.contact;
|
final LinphoneContact c = contact.contact;
|
||||||
|
|
||||||
TextView name = (TextView) view.findViewById(R.id.contact_name);
|
TextView name = (TextView) view.findViewById(R.id.contact_name);
|
||||||
name.setText(c.getName());
|
name.setText(c.getFullName());
|
||||||
|
|
||||||
TextView address = (TextView) view.findViewById(R.id.contact_address);
|
TextView address = (TextView) view.findViewById(R.id.contact_address);
|
||||||
address.setText(a);
|
address.setText(a);
|
||||||
|
@ -1103,7 +1081,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
view.setOnClickListener(new OnClickListener() {
|
view.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
exitNewConversationMode(c, a, null);
|
exitNewConversationMode(a);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,6 @@ You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.linphone.core.LinphoneAddress;
|
import org.linphone.core.LinphoneAddress;
|
||||||
|
@ -30,17 +27,9 @@ import org.linphone.core.LinphoneCoreFactory;
|
||||||
import org.linphone.mediastream.Log;
|
import org.linphone.mediastream.Log;
|
||||||
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.ProgressDialog;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.Typeface;
|
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Environment;
|
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.graphics.Typeface;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.view.ContextMenu.ContextMenuInfo;
|
import android.view.ContextMenu.ContextMenuInfo;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -59,7 +48,6 @@ import android.widget.CompoundButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,7 +58,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
private List<String> mConversations, mDrafts;
|
private List<String> mConversations, mDrafts;
|
||||||
private ListView chatList;
|
private ListView chatList;
|
||||||
private TextView noChatHistory;
|
private TextView noChatHistory;
|
||||||
private ImageView edit, selectAll, deselectAll, delete, newDiscussion, contactPicture, cancel, backInCall;
|
private ImageView edit, selectAll, deselectAll, delete, newDiscussion, cancel, backInCall;
|
||||||
private LinearLayout editList, topbar;
|
private LinearLayout editList, topbar;
|
||||||
private boolean isEditMode = false;
|
private boolean isEditMode = false;
|
||||||
|
|
||||||
|
@ -323,32 +311,6 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
LinphoneActivity.instance().displayChat(sipUri);
|
LinphoneActivity.instance().displayChat(sipUri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String saveImageAsFile(int id, Bitmap bm) {
|
|
||||||
try {
|
|
||||||
String path = Environment.getExternalStorageDirectory().toString();
|
|
||||||
if (!path.endsWith("/"))
|
|
||||||
path += "/";
|
|
||||||
path += "Pictures/";
|
|
||||||
File directory = new File(path);
|
|
||||||
directory.mkdirs();
|
|
||||||
|
|
||||||
String filename = getString(R.string.picture_name_format).replace("%s", String.valueOf(id));
|
|
||||||
File file = new File(path, filename);
|
|
||||||
|
|
||||||
OutputStream fOut = null;
|
|
||||||
fOut = new FileOutputStream(file);
|
|
||||||
|
|
||||||
bm.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
|
|
||||||
fOut.flush();
|
|
||||||
fOut.close();
|
|
||||||
|
|
||||||
return path + filename;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
class ChatListAdapter extends BaseAdapter {
|
class ChatListAdapter extends BaseAdapter {
|
||||||
|
|
||||||
|
@ -386,7 +348,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
Contact contact = ContactsManager.getInstance().findContactWithAddress(getActivity().getContentResolver(), address);
|
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(getActivity().getContentResolver(), address);
|
||||||
String message = "";
|
String message = "";
|
||||||
Long time;
|
Long time;
|
||||||
|
|
||||||
|
@ -416,7 +378,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
|
||||||
}
|
}
|
||||||
|
|
||||||
displayName.setSelected(true); // For animation
|
displayName.setSelected(true); // For animation
|
||||||
displayName.setText(contact == null ? LinphoneUtils.getAddressDisplayName(address) : contact.getName());
|
displayName.setText(contact == null ? LinphoneUtils.getAddressDisplayName(address) : contact.getFullName());
|
||||||
|
|
||||||
|
|
||||||
if(contact != null){
|
if(contact != null){
|
||||||
|
|
|
@ -32,6 +32,7 @@ import android.net.Uri;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Sylvain Berfini
|
* @author Sylvain Berfini
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
public class Contact implements Serializable {
|
public class Contact implements Serializable {
|
||||||
private static final long serialVersionUID = 3790717505065723499L;
|
private static final long serialVersionUID = 3790717505065723499L;
|
||||||
|
|
|
@ -17,23 +17,13 @@ You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import org.linphone.compatibility.Compatibility;
|
|
||||||
import org.linphone.core.LinphoneCore;
|
import org.linphone.core.LinphoneCore;
|
||||||
import org.linphone.core.LinphoneProxyConfig;
|
import org.linphone.core.LinphoneProxyConfig;
|
||||||
import org.linphone.mediastream.Log;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.ContentProviderOperation;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.provider.ContactsContract;
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
|
@ -47,7 +37,7 @@ import android.widget.TextView;
|
||||||
* @author Sylvain Berfini
|
* @author Sylvain Berfini
|
||||||
*/
|
*/
|
||||||
public class ContactDetailsFragment extends Fragment implements OnClickListener {
|
public class ContactDetailsFragment extends Fragment implements OnClickListener {
|
||||||
private Contact contact;
|
private LinphoneContact contact;
|
||||||
private ImageView editContact, deleteContact, back;
|
private ImageView editContact, deleteContact, back;
|
||||||
private LayoutInflater inflater;
|
private LayoutInflater inflater;
|
||||||
private View view;
|
private View view;
|
||||||
|
@ -71,7 +61,7 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
|
||||||
} else {
|
} else {
|
||||||
to = v.getTag().toString();
|
to = v.getTag().toString();
|
||||||
}
|
}
|
||||||
LinphoneActivity.instance().setAddresGoToDialerAndCall(to, contact.getName(), contact.getPhotoUri());
|
LinphoneActivity.instance().setAddresGoToDialerAndCall(to, contact.getFullName(), contact.getPhotoUri());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +77,7 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
|
||||||
};
|
};
|
||||||
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
contact = (Contact) getArguments().getSerializable("Contact");
|
contact = (LinphoneContact) getArguments().getSerializable("Contact");
|
||||||
|
|
||||||
this.inflater = inflater;
|
this.inflater = inflater;
|
||||||
view = inflater.inflate(R.layout.contact, container, false);
|
view = inflater.inflate(R.layout.contact, container, false);
|
||||||
|
@ -112,38 +102,37 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeDisplayedContact(Contact newContact) {
|
public void changeDisplayedContact(LinphoneContact newContact) {
|
||||||
contact = newContact;
|
contact = newContact;
|
||||||
contact.refresh(getActivity().getContentResolver());
|
//contact.refresh();
|
||||||
displayContact(inflater, view);
|
displayContact(inflater, view);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
private void displayContact(LayoutInflater inflater, View view) {
|
private void displayContact(LayoutInflater inflater, View view) {
|
||||||
ImageView contactPicture = (ImageView) view.findViewById(R.id.contact_picture);
|
ImageView contactPicture = (ImageView) view.findViewById(R.id.contact_picture);
|
||||||
if (contact.getPhotoUri() != null) {
|
if (contact.hasPhoto()) {
|
||||||
InputStream input = Compatibility.getContactPictureInputStream(LinphoneActivity.instance().getContentResolver(), contact.getID());
|
LinphoneUtils.setImagePictureFromUri(getActivity(), contactPicture, contact.getPhotoUri(), contact.getThumbnailUri());
|
||||||
contactPicture.setImageBitmap(BitmapFactory.decodeStream(input));
|
|
||||||
} else {
|
} else {
|
||||||
contactPicture.setImageResource(R.drawable.avatar);
|
contactPicture.setImageResource(R.drawable.avatar);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextView contactName = (TextView) view.findViewById(R.id.contact_name);
|
TextView contactName = (TextView) view.findViewById(R.id.contact_name);
|
||||||
contactName.setText(contact.getName());
|
contactName.setText(contact.getFullName());
|
||||||
|
|
||||||
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 (LinphoneNumberOrAddress noa : contact.getNumbersOrAddresses()) {
|
||||||
boolean skip = false;
|
boolean skip = false;
|
||||||
View v = inflater.inflate(R.layout.contact_control_row, null);
|
View v = inflater.inflate(R.layout.contact_control_row, null);
|
||||||
|
|
||||||
String displayednumberOrAddress = numberOrAddress;
|
String displayednumberOrAddress = noa.getValue();
|
||||||
if (numberOrAddress.startsWith("sip:")) {
|
if (displayednumberOrAddress.startsWith("sip:")) {
|
||||||
displayednumberOrAddress = displayednumberOrAddress.replace("sip:", "");
|
displayednumberOrAddress = displayednumberOrAddress.replace("sip:", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
TextView label = (TextView) v.findViewById(R.id.address_label);
|
TextView label = (TextView) v.findViewById(R.id.address_label);
|
||||||
if(LinphoneUtils.isSipAddress(numberOrAddress)) {
|
if (noa.isSIPAddress()) {
|
||||||
label.setText(R.string.sip_address);
|
label.setText(R.string.sip_address);
|
||||||
skip |= getResources().getBoolean(R.bool.hide_contact_sip_addresses);
|
skip |= getResources().getBoolean(R.bool.hide_contact_sip_addresses);
|
||||||
} else {
|
} else {
|
||||||
|
@ -166,20 +155,19 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
|
||||||
LinphoneProxyConfig lpc = LinphoneManager.getLc().getDefaultProxyConfig();
|
LinphoneProxyConfig lpc = LinphoneManager.getLc().getDefaultProxyConfig();
|
||||||
if (lpc != null) {
|
if (lpc != null) {
|
||||||
displayednumberOrAddress = lpc.normalizePhoneNumber(displayednumberOrAddress);
|
displayednumberOrAddress = lpc.normalizePhoneNumber(displayednumberOrAddress);
|
||||||
if (!displayednumberOrAddress.startsWith("sip:")) {
|
String tag = noa.getValue();
|
||||||
numberOrAddress = "sip:" + displayednumberOrAddress;
|
if (!tag.startsWith("sip:")) {
|
||||||
|
tag = "sip:" + tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
String tag = numberOrAddress;
|
if (!tag.contains("@")) {
|
||||||
if (!numberOrAddress.contains("@")) {
|
tag = tag + "@" + lpc.getDomain();
|
||||||
tag = numberOrAddress + "@" + lpc.getDomain();
|
|
||||||
}
|
}
|
||||||
v.findViewById(R.id.contact_chat).setTag(tag);
|
v.findViewById(R.id.contact_chat).setTag(tag);
|
||||||
} else {
|
} else {
|
||||||
v.findViewById(R.id.contact_chat).setTag(numberOrAddress);
|
v.findViewById(R.id.contact_chat).setTag(noa.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
final String finalNumberOrAddress = numberOrAddress;
|
|
||||||
/*ImageView friend = (ImageView) v.findViewById(R.id.addFriend);
|
/*ImageView friend = (ImageView) v.findViewById(R.id.addFriend);
|
||||||
if (getResources().getBoolean(R.bool.enable_linphone_friends) && !displayChatAddressOnly) {
|
if (getResources().getBoolean(R.bool.enable_linphone_friends) && !displayChatAddressOnly) {
|
||||||
friend.setVisibility(View.VISIBLE);
|
friend.setVisibility(View.VISIBLE);
|
||||||
|
@ -226,8 +214,8 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
|
||||||
LinphoneActivity.instance().selectMenu(FragmentsAvailable.CONTACT_DETAIL);
|
LinphoneActivity.instance().selectMenu(FragmentsAvailable.CONTACT_DETAIL);
|
||||||
LinphoneActivity.instance().hideTabBar(false);
|
LinphoneActivity.instance().hideTabBar(false);
|
||||||
}
|
}
|
||||||
contact.refresh(getActivity().getContentResolver());
|
contact.refresh();
|
||||||
if (contact.getName() == null || contact.getName().equals("")) {
|
if (contact.getFullName() == null || contact.getFullName().equals("")) {
|
||||||
//Contact has been deleted, return
|
//Contact has been deleted, return
|
||||||
LinphoneActivity.instance().displayContacts(false);
|
LinphoneActivity.instance().displayContacts(false);
|
||||||
} else {
|
} else {
|
||||||
|
@ -250,8 +238,7 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
|
||||||
delete.setOnClickListener(new OnClickListener() {
|
delete.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
deleteExistingContact();
|
contact.delete();
|
||||||
ContactsManager.getInstance().removeContactFromLists(getActivity().getContentResolver(), contact);
|
|
||||||
LinphoneActivity.instance().displayContacts(false);
|
LinphoneActivity.instance().displayContacts(false);
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
|
@ -270,22 +257,4 @@ public class ContactDetailsFragment extends Fragment implements OnClickListener
|
||||||
LinphoneActivity.instance().displayContacts(false);
|
LinphoneActivity.instance().displayContacts(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteExistingContact() {
|
|
||||||
String select = ContactsContract.Data.CONTACT_ID + " = ?";
|
|
||||||
String[] args = new String[] { contact.getID() };
|
|
||||||
|
|
||||||
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
|
|
||||||
ops.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI)
|
|
||||||
.withSelection(select, args)
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
|
||||||
getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
|
|
||||||
ContactsManager.getInstance().removeAllFriends(contact);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.w(e.getMessage() + ":" + e.getStackTrace());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,9 +77,9 @@ public class ContactEditorFragment extends Fragment {
|
||||||
private static final int ADD_PHOTO = 1337;
|
private static final int ADD_PHOTO = 1337;
|
||||||
|
|
||||||
private boolean isNewContact = true;
|
private boolean isNewContact = true;
|
||||||
private Contact contact;
|
private LinphoneContact contact;
|
||||||
private int contactID;
|
private int contactID;
|
||||||
private List<NewOrUpdatedNumberOrAddress> numbersAndAddresses;
|
//private List<NewOrUpdatedNumberOrAddress> numbersAndAddresses;
|
||||||
private ArrayList<ContentProviderOperation> ops;
|
private ArrayList<ContentProviderOperation> ops;
|
||||||
private int firstSipAddressIndex = -1;
|
private int firstSipAddressIndex = -1;
|
||||||
private LinearLayout sipAddresses, numbers;
|
private LinearLayout sipAddresses, numbers;
|
||||||
|
@ -88,16 +88,15 @@ public class ContactEditorFragment extends Fragment {
|
||||||
private Uri imageToUploadUri;
|
private Uri imageToUploadUri;
|
||||||
private String fileToUploadPath;
|
private String fileToUploadPath;
|
||||||
private Bitmap imageToUpload;
|
private Bitmap imageToUpload;
|
||||||
private Bitmap bitmapUnknown;
|
|
||||||
byte[] photoToAdd;
|
byte[] photoToAdd;
|
||||||
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
this.inflater = inflater;
|
this.inflater = inflater;
|
||||||
|
|
||||||
contact = null;
|
/*contact = null;
|
||||||
if (getArguments() != null) {
|
if (getArguments() != null) {
|
||||||
if (getArguments().getSerializable("Contact") != null) {
|
if (getArguments().getSerializable("Contact") != null) {
|
||||||
contact = (Contact) getArguments().getSerializable("Contact");
|
contact = (LinphoneContact) getArguments().getSerializable("Contact");
|
||||||
isNewContact = false;
|
isNewContact = false;
|
||||||
contactID = Integer.parseInt(contact.getID());
|
contactID = Integer.parseInt(contact.getID());
|
||||||
contact.refresh(getActivity().getContentResolver());
|
contact.refresh(getActivity().getContentResolver());
|
||||||
|
@ -181,7 +180,7 @@ public class ContactEditorFragment extends Fragment {
|
||||||
}
|
}
|
||||||
getFragmentManager().popBackStackImmediate();
|
getFragmentManager().popBackStackImmediate();
|
||||||
} else {
|
} else {
|
||||||
Contact updatedContact = contactsManager.findContactWithDisplayName(contactsManager.getDisplayName(firstName.getText().toString(), lastName.getText().toString()));
|
LinphoneContact updatedContact = contactsManager.findContactWithDisplayName(contactsManager.getDisplayName(firstName.getText().toString(), lastName.getText().toString()));
|
||||||
if (updatedContact != null) {
|
if (updatedContact != null) {
|
||||||
LinphoneActivity.instance().displayContact(updatedContact, false);
|
LinphoneActivity.instance().displayContact(updatedContact, false);
|
||||||
} else {
|
} else {
|
||||||
|
@ -249,7 +248,7 @@ public class ContactEditorFragment extends Fragment {
|
||||||
firstName.setText(fn);
|
firstName.setText(fn);
|
||||||
lastName.setText(ln);
|
lastName.setText(ln);
|
||||||
} else {
|
} else {
|
||||||
lastName.setText(contact.getName());
|
lastName.setText(contact.getFullName());
|
||||||
firstName.setText("");
|
firstName.setText("");
|
||||||
}
|
}
|
||||||
deleteContact.setOnClickListener(new OnClickListener() {
|
deleteContact.setOnClickListener(new OnClickListener() {
|
||||||
|
@ -262,8 +261,7 @@ public class ContactEditorFragment extends Fragment {
|
||||||
delete.setOnClickListener(new OnClickListener() {
|
delete.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
deleteExistingContact();
|
contact.delete();
|
||||||
ContactsManager.getInstance().removeContactFromLists(getActivity().getContentResolver(), contact);
|
|
||||||
LinphoneActivity.instance().displayContacts(false);
|
LinphoneActivity.instance().displayContacts(false);
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
|
@ -319,7 +317,7 @@ public class ContactEditorFragment extends Fragment {
|
||||||
});
|
});
|
||||||
|
|
||||||
ops = new ArrayList<ContentProviderOperation>();
|
ops = new ArrayList<ContentProviderOperation>();
|
||||||
lastName.requestFocus();
|
lastName.requestFocus();*/
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
@ -348,7 +346,7 @@ public class ContactEditorFragment extends Fragment {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pickImage() {
|
/*private void pickImage() {
|
||||||
imageToUploadUri = null;
|
imageToUploadUri = null;
|
||||||
final List<Intent> cameraIntents = new ArrayList<Intent>();
|
final List<Intent> cameraIntents = new ArrayList<Intent>();
|
||||||
final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||||
|
@ -419,24 +417,6 @@ public class ContactEditorFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteExistingContact() {
|
|
||||||
String select = ContactsContract.Data.CONTACT_ID + " = ?";
|
|
||||||
String[] args = new String[] { contact.getID() };
|
|
||||||
|
|
||||||
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
|
|
||||||
ops.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI)
|
|
||||||
.withSelection(select, args)
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
|
||||||
getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
|
|
||||||
ContactsManager.getInstance().removeAllFriends(contact);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.w(e.getMessage() + ":" + e.getStackTrace());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showPopupMenuAskingImageSize(final String filePath, final Bitmap image) {
|
private void showPopupMenuAskingImageSize(final String filePath, final Bitmap image) {
|
||||||
fileToUploadPath = filePath;
|
fileToUploadPath = filePath;
|
||||||
imageToUpload = image;
|
imageToUpload = image;
|
||||||
|
@ -962,5 +942,5 @@ public class ContactEditorFragment extends Fragment {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
|
@ -1,4 +1,3 @@
|
||||||
package org.linphone;
|
|
||||||
/*
|
/*
|
||||||
ContactsListFragment.java
|
ContactsListFragment.java
|
||||||
Copyright (C) 2015 Belledonne Communications, Grenoble, France
|
Copyright (C) 2015 Belledonne Communications, Grenoble, France
|
||||||
|
@ -17,23 +16,18 @@ You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
import java.util.ArrayList;
|
|
||||||
|
package org.linphone;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
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.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.ContentProviderOperation;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.provider.ContactsContract;
|
import android.os.Bundle;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -43,7 +37,6 @@ import android.view.ViewGroup;
|
||||||
import android.widget.AbsListView;
|
import android.widget.AbsListView;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
import android.widget.AlphabetIndexer;
|
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.BaseAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
|
@ -52,8 +45,6 @@ import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
import android.widget.SectionIndexer;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,12 +60,10 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
||||||
private View allContactsSelected, linphoneContactsSelected;
|
private View allContactsSelected, linphoneContactsSelected;
|
||||||
private LinearLayout editList, topbar;
|
private LinearLayout editList, topbar;
|
||||||
private int lastKnownPosition;
|
private int lastKnownPosition;
|
||||||
private AlphabetIndexer indexer;
|
|
||||||
private boolean editOnClick = false, editConsumed = false, onlyDisplayChatAddress = false;
|
private boolean editOnClick = false, editConsumed = false, onlyDisplayChatAddress = false;
|
||||||
private String sipAddressToAdd;
|
private String sipAddressToAdd;
|
||||||
private ImageView clearSearchField;
|
private ImageView clearSearchField;
|
||||||
private EditText searchField;
|
private EditText searchField;
|
||||||
private Cursor searchCursor;
|
|
||||||
|
|
||||||
private static ContactsListFragment instance;
|
private static ContactsListFragment instance;
|
||||||
|
|
||||||
|
@ -284,31 +273,12 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteExistingContact(Contact contact) {
|
|
||||||
String select = ContactsContract.Data.CONTACT_ID + " = ?";
|
|
||||||
String[] args = new String[] { contact.getID() };
|
|
||||||
|
|
||||||
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
|
|
||||||
ops.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI)
|
|
||||||
.withSelection(select, args)
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
|
||||||
getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
|
|
||||||
ContactsManager.getInstance().removeAllFriends(contact);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.w(e.getMessage() + ":" + e.getStackTrace());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeContacts(){
|
private void removeContacts(){
|
||||||
int size = contactsList.getAdapter().getCount();
|
int size = contactsList.getAdapter().getCount();
|
||||||
for(int i=0; i<size; i++) {
|
for(int i=0; i<size; i++) {
|
||||||
if(contactsList.isItemChecked(i)){
|
if(contactsList.isItemChecked(i)){
|
||||||
Contact contact = (Contact) contactsList.getAdapter().getItem(i);
|
LinphoneContact contact = (LinphoneContact) contactsList.getAdapter().getItem(i);
|
||||||
deleteExistingContact(contact);
|
contact.delete();
|
||||||
ContactsManager.getInstance().removeContactFromLists(getActivity().getContentResolver(), contact);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -325,7 +295,7 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
||||||
|
|
||||||
public void displayFirstContact(){
|
public void displayFirstContact(){
|
||||||
if(contactsList.getAdapter() != null && contactsList.getAdapter().getCount() > 0) {
|
if(contactsList.getAdapter() != null && contactsList.getAdapter().getCount() > 0) {
|
||||||
LinphoneActivity.instance().displayContact((Contact) contactsList.getAdapter().getItem(0), false);
|
LinphoneActivity.instance().displayContact((LinphoneContact) contactsList.getAdapter().getItem(0), false);
|
||||||
} else {
|
} else {
|
||||||
LinphoneActivity.instance().displayEmptyFragment();
|
LinphoneActivity.instance().displayEmptyFragment();
|
||||||
}
|
}
|
||||||
|
@ -341,73 +311,31 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
changeContactsToggle();
|
changeContactsToggle();
|
||||||
|
|
||||||
if (searchCursor != null) {
|
|
||||||
searchCursor.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(LinphoneActivity.instance().getResources().getBoolean(R.bool.use_linphone_friend)) {
|
if (onlyDisplayLinphoneContacts) {
|
||||||
//searchCursor = Compatibility.getSIPContactsCursor(getActivity().getContentResolver(), search, ContactsManager.getInstance().getContactsId());
|
contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
||||||
//indexer = new AlphabetIndexer(searchCursor, Compatibility.getCursorDisplayNameColumnIndex(searchCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
contactsList.setAdapter(new ContactsListAdapter(ContactsManager.getInstance().getSIPContacts()));
|
||||||
//contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
} else {
|
||||||
//contactsList.setAdapter(new ContactsListAdapter(null, searchCursor));
|
contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
||||||
} else{
|
contactsList.setAdapter(new ContactsListAdapter(ContactsManager.getInstance().getContacts()));
|
||||||
if (onlyDisplayLinphoneContacts) {
|
|
||||||
searchCursor = Compatibility.getSIPContactsCursor(getActivity().getContentResolver(), search, ContactsManager.getInstance().getContactsId());
|
|
||||||
indexer = new AlphabetIndexer(searchCursor, Compatibility.getCursorDisplayNameColumnIndex(searchCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
|
||||||
contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
|
||||||
contactsList.setAdapter(new ContactsListAdapter(null, searchCursor));
|
|
||||||
} else {
|
|
||||||
searchCursor = Compatibility.getContactsCursor(getActivity().getContentResolver(), search, ContactsManager.getInstance().getContactsId());
|
|
||||||
contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
|
||||||
indexer = new AlphabetIndexer(searchCursor, Compatibility.getCursorDisplayNameColumnIndex(searchCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
|
||||||
contactsList.setAdapter(new ContactsListAdapter(null, searchCursor));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeContactsAdapter() {
|
private void changeContactsAdapter() {
|
||||||
changeContactsToggle();
|
changeContactsToggle();
|
||||||
|
|
||||||
if (searchCursor != null) {
|
|
||||||
searchCursor.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
Cursor allContactsCursor = ContactsManager.getInstance().getAllContactsCursor();
|
|
||||||
Cursor sipContactsCursor = ContactsManager.getInstance().getSIPContactsCursor();
|
|
||||||
|
|
||||||
noSipContact.setVisibility(View.GONE);
|
noSipContact.setVisibility(View.GONE);
|
||||||
noContact.setVisibility(View.GONE);
|
noContact.setVisibility(View.GONE);
|
||||||
contactsList.setVisibility(View.VISIBLE);
|
contactsList.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
if(LinphoneActivity.instance().getResources().getBoolean(R.bool.use_linphone_friend)) {
|
if (onlyDisplayLinphoneContacts) {
|
||||||
indexer = new AlphabetIndexer(allContactsCursor, Compatibility.getCursorDisplayNameColumnIndex(allContactsCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
|
||||||
contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
||||||
contactsList.setAdapter(new ContactsListAdapter(ContactsManager.getInstance().getAllContacts(), allContactsCursor));
|
contactsList.setAdapter(new ContactsListAdapter(ContactsManager.getInstance().getSIPContacts()));
|
||||||
|
edit.setEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
if (onlyDisplayLinphoneContacts) {
|
contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
||||||
if (sipContactsCursor != null && sipContactsCursor.getCount() > 0) {
|
contactsList.setAdapter(new ContactsListAdapter(ContactsManager.getInstance().getContacts()));
|
||||||
indexer = new AlphabetIndexer(sipContactsCursor, Compatibility.getCursorDisplayNameColumnIndex(sipContactsCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
edit.setEnabled(true);
|
||||||
contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
|
||||||
contactsList.setAdapter(new ContactsListAdapter(ContactsManager.getInstance().getSIPContacts(), sipContactsCursor));
|
|
||||||
edit.setEnabled(true);
|
|
||||||
} else {
|
|
||||||
noSipContact.setVisibility(View.VISIBLE);
|
|
||||||
contactsList.setVisibility(View.GONE);
|
|
||||||
edit.setEnabled(false);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (allContactsCursor != null && allContactsCursor.getCount() > 0) {
|
|
||||||
indexer = new AlphabetIndexer(allContactsCursor, Compatibility.getCursorDisplayNameColumnIndex(allContactsCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
|
||||||
contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
|
||||||
contactsList.setAdapter(new ContactsListAdapter(ContactsManager.getInstance().getAllContacts(), allContactsCursor));
|
|
||||||
edit.setEnabled(true);
|
|
||||||
} else {
|
|
||||||
noContact.setVisibility(View.VISIBLE);
|
|
||||||
contactsList.setVisibility(View.GONE);
|
|
||||||
edit.setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ContactsManager.getInstance().setLinphoneContactsPrefered(onlyDisplayLinphoneContacts);
|
ContactsManager.getInstance().setLinphoneContactsPrefered(onlyDisplayLinphoneContacts);
|
||||||
}
|
}
|
||||||
|
@ -428,7 +356,7 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
|
||||||
Contact contact = (Contact) adapter.getItemAtPosition(position);
|
LinphoneContact contact = (LinphoneContact) adapter.getItemAtPosition(position);
|
||||||
if (editOnClick) {
|
if (editOnClick) {
|
||||||
editConsumed = true;
|
editConsumed = true;
|
||||||
LinphoneActivity.instance().editContact(contact, sipAddressToAdd);
|
LinphoneActivity.instance().editContact(contact, sipAddressToAdd);
|
||||||
|
@ -460,9 +388,6 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
instance = null;
|
instance = null;
|
||||||
if (searchCursor != null) {
|
|
||||||
searchCursor.close();
|
|
||||||
}
|
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -475,34 +400,19 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
||||||
contactsList.setSelectionFromTop(lastKnownPosition, 0);
|
contactsList.setSelectionFromTop(lastKnownPosition, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
class ContactsListAdapter extends BaseAdapter implements SectionIndexer {
|
class ContactsListAdapter extends BaseAdapter {
|
||||||
private int margin;
|
private List<LinphoneContact> contacts;
|
||||||
private Bitmap bitmapUnknown;
|
|
||||||
private List<Contact> contacts;
|
|
||||||
private Cursor cursor;
|
|
||||||
|
|
||||||
ContactsListAdapter(List<Contact> contactsList, Cursor c) {
|
ContactsListAdapter(List<LinphoneContact> contactsList) {
|
||||||
contacts = contactsList;
|
contacts = contactsList;
|
||||||
cursor = c;
|
|
||||||
|
|
||||||
margin = LinphoneUtils.pixelsToDpi(LinphoneActivity.instance().getResources(), 10);
|
|
||||||
bitmapUnknown = BitmapFactory.decodeResource(LinphoneActivity.instance().getResources(), R.drawable.avatar);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
if(LinphoneActivity.instance().getResources().getBoolean(R.bool.use_linphone_friend)) {
|
return contacts.size();
|
||||||
return LinphoneManager.getLc().getFriendList().length;
|
|
||||||
} else {
|
|
||||||
return cursor.getCount();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getItem(int position) {
|
public Object getItem(int position) {
|
||||||
if (contacts == null || position >= contacts.size()) {
|
return contacts.get(position);
|
||||||
return Compatibility.getContact(getActivity().getContentResolver(), cursor, position);
|
|
||||||
} else {
|
|
||||||
return contacts.get(position);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getItemId(int position) {
|
public long getItemId(int position) {
|
||||||
|
@ -511,9 +421,9 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
||||||
|
|
||||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||||
View view = null;
|
View view = null;
|
||||||
Contact contact = null;
|
LinphoneContact contact = null;
|
||||||
do {
|
do {
|
||||||
contact = (Contact) getItem(position);
|
contact = (LinphoneContact) getItem(position);
|
||||||
} while (contact == null);
|
} while (contact == null);
|
||||||
|
|
||||||
if (convertView != null) {
|
if (convertView != null) {
|
||||||
|
@ -525,20 +435,14 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
||||||
CheckBox delete = (CheckBox) view.findViewById(R.id.delete);
|
CheckBox delete = (CheckBox) view.findViewById(R.id.delete);
|
||||||
|
|
||||||
TextView name = (TextView) view.findViewById(R.id.name);
|
TextView name = (TextView) view.findViewById(R.id.name);
|
||||||
name.setText(contact.getName());
|
name.setText(contact.getFullName());
|
||||||
|
|
||||||
LinearLayout separator = (LinearLayout) view.findViewById(R.id.separator);
|
LinearLayout separator = (LinearLayout) view.findViewById(R.id.separator);
|
||||||
TextView separatorText = (TextView) view.findViewById(R.id.separator_text);
|
separator.setVisibility(View.GONE);
|
||||||
if (getPositionForSection(getSectionForPosition(position)) != position) {
|
|
||||||
separator.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
separator.setVisibility(View.VISIBLE);
|
|
||||||
separatorText.setText(String.valueOf(contact.getName().charAt(0)));
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageView icon = (ImageView) view.findViewById(R.id.contact_picture);
|
ImageView icon = (ImageView) view.findViewById(R.id.contact_picture);
|
||||||
if (contact.getPhoto() != null) {
|
if (contact.hasPhoto()) {
|
||||||
icon.setImageBitmap(contact.getPhoto());
|
LinphoneUtils.setImagePictureFromUri(getActivity(), icon, contact.getPhotoUri(), contact.getThumbnailUri());
|
||||||
} else if (contact.getPhotoUri() != null) {
|
} else if (contact.getPhotoUri() != null) {
|
||||||
icon.setImageURI(contact.getPhotoUri());
|
icon.setImageURI(contact.getPhotoUri());
|
||||||
} else {
|
} else {
|
||||||
|
@ -568,7 +472,7 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(contactsList.isItemChecked(position)) {
|
if (contactsList.isItemChecked(position)) {
|
||||||
delete.setChecked(true);
|
delete.setChecked(true);
|
||||||
} else {
|
} else {
|
||||||
delete.setChecked(false);
|
delete.setChecked(false);
|
||||||
|
@ -597,20 +501,5 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getPositionForSection(int section) {
|
|
||||||
return indexer.getPositionForSection(section);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSectionForPosition(int position) {
|
|
||||||
return indexer.getSectionForPosition(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object[] getSections() {
|
|
||||||
return indexer.getSections();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.linphone;
|
|
||||||
/*
|
/*
|
||||||
CallManager.java
|
ContactsManager.java
|
||||||
Copyright (C) 2015 Belledonne Communications, Grenoble, France
|
Copyright (C) 2015 Belledonne Communications, Grenoble, France
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
|
@ -18,63 +17,57 @@ along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import android.accounts.Account;
|
package org.linphone;
|
||||||
import android.accounts.AccountManager;
|
|
||||||
import android.content.ContentProviderOperation;
|
import java.util.ArrayList;
|
||||||
import android.content.ContentResolver;
|
import java.util.List;
|
||||||
import android.content.Context;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.database.MatrixCursor;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.provider.ContactsContract;
|
|
||||||
|
|
||||||
import org.linphone.compatibility.Compatibility;
|
import org.linphone.compatibility.Compatibility;
|
||||||
import org.linphone.core.LinphoneAddress;
|
import org.linphone.core.LinphoneAddress;
|
||||||
import org.linphone.core.LinphoneCore;
|
|
||||||
import org.linphone.core.LinphoneCoreException;
|
|
||||||
import org.linphone.core.LinphoneCoreFactory;
|
|
||||||
import org.linphone.core.LinphoneFriend;
|
import org.linphone.core.LinphoneFriend;
|
||||||
import org.linphone.core.LinphoneProxyConfig;
|
|
||||||
import org.linphone.mediastream.Log;
|
import org.linphone.mediastream.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import android.accounts.Account;
|
||||||
import java.util.HashSet;
|
import android.accounts.AccountManager;
|
||||||
import java.util.List;
|
import android.content.ContentResolver;
|
||||||
import java.util.Set;
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.provider.ContactsContract;
|
||||||
|
import android.provider.ContactsContract.Data;
|
||||||
|
|
||||||
public class ContactsManager {
|
public class ContactsManager {
|
||||||
private static ContactsManager instance;
|
private static ContactsManager instance;
|
||||||
private List<Contact> contactList, sipContactList;
|
private List<LinphoneContact> contacts;
|
||||||
private Cursor contactCursor, sipContactCursor;
|
//private Cursor contactCursor, sipContactCursor;
|
||||||
private Account mAccount;
|
private Account mAccount;
|
||||||
private boolean preferLinphoneContacts = false, isContactPresenceDisabled = true, hasContactAccess = false;
|
private boolean preferLinphoneContacts = false, isContactPresenceDisabled = true, hasContactAccess = false;
|
||||||
private ContentResolver contentResolver;
|
private ContentResolver contentResolver;
|
||||||
private Context context;
|
|
||||||
|
|
||||||
private ContactsManager() {}
|
private ContactsManager() {}
|
||||||
|
|
||||||
|
public ContentResolver getContentResolver() {
|
||||||
|
return contentResolver;
|
||||||
|
}
|
||||||
|
|
||||||
public static final synchronized ContactsManager getInstance() {
|
public static final synchronized ContactsManager getInstance() {
|
||||||
if (instance == null) instance = new ContactsManager();
|
if (instance == null) instance = new ContactsManager();
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Contact> getAllContacts() {
|
public boolean hasContacts() {
|
||||||
return contactList;
|
return contacts.size() > 0;
|
||||||
}
|
|
||||||
|
|
||||||
public List<Contact> getSIPContacts() {
|
|
||||||
return sipContactList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cursor getAllContactsCursor() {
|
|
||||||
return contactCursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cursor getSIPContactsCursor() {
|
|
||||||
return sipContactCursor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enabledContactsAccess(){
|
public List<LinphoneContact> getContacts() {
|
||||||
|
return contacts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<LinphoneContact> getSIPContacts() {
|
||||||
|
return contacts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enableContactsAccess() {
|
||||||
hasContactAccess = true;
|
hasContactAccess = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +84,6 @@ public class ContactsManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initializeContactManager(Context context, ContentResolver contentResolver){
|
public void initializeContactManager(Context context, ContentResolver contentResolver){
|
||||||
this.context = context;
|
|
||||||
this.contentResolver = contentResolver;
|
this.contentResolver = contentResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,529 +105,59 @@ public class ContactsManager {
|
||||||
} else {
|
} else {
|
||||||
mAccount = accounts[0];
|
mAccount = accounts[0];
|
||||||
}
|
}
|
||||||
initializeContactManager(context,contentResolver);
|
initializeContactManager(context, contentResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDisplayName(String firstName, String lastName) {
|
public LinphoneContact findContactFromAddress(LinphoneAddress address) {
|
||||||
String displayName = null;
|
return findContactFromAddress(null, address);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Contacts
|
public LinphoneContact findContactFromAddress(ContentResolver contentResolver, LinphoneAddress address) {
|
||||||
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()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateExistingContactPicture(ArrayList<ContentProviderOperation> ops, Contact contact, String path){
|
|
||||||
String select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Photo.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.Photo.CONTENT_ITEM_TYPE)
|
|
||||||
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO_FILE_ID, path)
|
|
||||||
//.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO_FILE_ID, )
|
|
||||||
.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);
|
|
||||||
if (friend != null) {
|
|
||||||
friend.edit();
|
|
||||||
friend.enableSubscribes(false);
|
|
||||||
friend.setRefKey(contact.getID());
|
|
||||||
friend.done();
|
|
||||||
try {
|
|
||||||
LinphoneManager.getLcIfManagerNotDestroyedOrNull().addFriend(friend);
|
|
||||||
return true;
|
|
||||||
} catch (LinphoneCoreException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
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.getLcIfManagerNotDestroyedOrNull().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.getLcIfManagerNotDestroyedOrNull().findFriendByAddress(sipUri);
|
|
||||||
if (friend != null) {
|
|
||||||
LinphoneManager.getLcIfManagerNotDestroyedOrNull().removeFriend(friend);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeAllFriends(Contact contact) {
|
|
||||||
for (LinphoneFriend friend : LinphoneManager.getLcIfManagerNotDestroyedOrNull().getFriendList()) {
|
|
||||||
if (friend.getRefKey().equals(contact.getID())) {
|
|
||||||
LinphoneManager.getLcIfManagerNotDestroyedOrNull().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 Contact getContact(String id, ContentResolver contentResolver){
|
|
||||||
String[] projection = {ContactsContract.Data.CONTACT_ID, ContactsContract.Data.DISPLAY_NAME};
|
|
||||||
String selection = new StringBuilder()
|
|
||||||
.append(ContactsContract.Data.CONTACT_ID)
|
|
||||||
.append(" = ?").toString();
|
|
||||||
|
|
||||||
Cursor c = contentResolver.query(ContactsContract.Data.CONTENT_URI, projection, selection, new String[]{id}, 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.getLcIfManagerNotDestroyedOrNull().getFriendList() == null) return null;
|
|
||||||
for(LinphoneFriend friend : LinphoneManager.getLcIfManagerNotDestroyedOrNull().getFriendList()) {
|
|
||||||
friend.edit();
|
|
||||||
friend.enableSubscribes(false);
|
|
||||||
friend.done();
|
|
||||||
if(!ids.contains(friend.getRefKey())){
|
|
||||||
ids.add(friend.getRefKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ids;
|
|
||||||
}
|
|
||||||
//End linphone Friend
|
|
||||||
|
|
||||||
public boolean removeContactTagIsNeeded(Contact contact){
|
|
||||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
|
||||||
if (lc != null) {
|
|
||||||
LinphoneProxyConfig lpc = lc.createProxyConfig();
|
|
||||||
contact.refresh(contentResolver);
|
|
||||||
for (String address : contact.getNumbersOrAddresses()) {
|
|
||||||
if (!lpc.isPhoneNumber(address)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeLinphoneContactTag(Contact contact){
|
|
||||||
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
|
|
||||||
String select = ContactsContract.RawContacts._ID + " = ?";
|
|
||||||
String[] args = new String[] { findRawLinphoneContactID(contact.getID()) };
|
|
||||||
|
|
||||||
|
|
||||||
ops.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI)
|
|
||||||
.withSelection(select, args)
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
|
||||||
contentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.w(e.getMessage() + ":" + e.getStackTrace());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Contact checkPhoneQueryResult(ContentResolver contentResolver, Cursor c, String columnPhone, String columnId, String username) {
|
|
||||||
boolean contactFound = false;
|
|
||||||
|
|
||||||
if (c != null) {
|
|
||||||
while (!contactFound && c.moveToNext()) {
|
|
||||||
String phone = c.getString(c.getColumnIndex(columnPhone));
|
|
||||||
if (phone.equals(username)) {
|
|
||||||
contactFound = true;
|
|
||||||
} else {
|
|
||||||
String normalizedUsername = null;
|
|
||||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
|
||||||
if (lc != null) {
|
|
||||||
LinphoneProxyConfig lpc = lc.getDefaultProxyConfig();
|
|
||||||
if (lpc != null) {
|
|
||||||
normalizedUsername = lpc.normalizePhoneNumber(phone);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (normalizedUsername != null && normalizedUsername.equals(username)) {
|
|
||||||
contactFound = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(contactFound){
|
|
||||||
Contact contact = getContact(c.getString(c.getColumnIndex(columnId)), contentResolver);
|
|
||||||
c.close();
|
|
||||||
return contact;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
c.close();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Contact findContactWithAddress(LinphoneAddress address) {
|
|
||||||
String sipUri = address.asStringUriOnly();
|
String sipUri = address.asStringUriOnly();
|
||||||
if (sipUri.startsWith("sip:"))
|
if (sipUri.startsWith("sip:")) {
|
||||||
sipUri = sipUri.substring(4);
|
sipUri = sipUri.substring(4);
|
||||||
|
}
|
||||||
|
|
||||||
for(Contact c: getAllContacts()){
|
for (LinphoneContact c: getContacts()) {
|
||||||
for(String a: c.getNumbersOrAddresses()){
|
for (LinphoneNumberOrAddress noa: c.getNumbersOrAddresses()) {
|
||||||
if(a.equals(sipUri))
|
if (noa.getValue().equals(sipUri)) {
|
||||||
return c;
|
return c;
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Contact findContactWithAddress(ContentResolver contentResolver, LinphoneAddress address){
|
|
||||||
String sipUri = address.asStringUriOnly();
|
|
||||||
if (sipUri.startsWith("sip:"))
|
|
||||||
sipUri = sipUri.substring(4);
|
|
||||||
|
|
||||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
|
||||||
if(lc != null && lc.getFriendList() != null && LinphoneManager.getLcIfManagerNotDestroyedOrNull().getFriendList().length > 0) {
|
|
||||||
for (LinphoneFriend friend : LinphoneManager.getLcIfManagerNotDestroyedOrNull().getFriendList()) {
|
|
||||||
if (friend.getAddress().equals(address)) {
|
|
||||||
return getContact(friend.getRefKey(), contentResolver);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Find Sip address
|
|
||||||
if(hasContactAccess) {
|
|
||||||
Contact contact;
|
|
||||||
String[] projection = new String[]{ContactsContract.Data.CONTACT_ID, ContactsContract.Data.DISPLAY_NAME};
|
|
||||||
String selection = new StringBuilder()
|
|
||||||
.append(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS)
|
|
||||||
.append(" = ?").toString();
|
|
||||||
|
|
||||||
Cursor cur = contentResolver.query(ContactsContract.Data.CONTENT_URI, projection, selection,
|
|
||||||
new String[]{sipUri}, null);
|
|
||||||
if (cur != null) {
|
|
||||||
if (cur.moveToFirst()) {
|
|
||||||
contact = Compatibility.getContact(contentResolver, cur, cur.getPosition());
|
|
||||||
cur.close();
|
|
||||||
|
|
||||||
if (contact != null) {
|
|
||||||
return contact;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cur.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Find number
|
|
||||||
Uri lookupUri = Uri.withAppendedPath(android.provider.ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address.getUserName()));
|
|
||||||
projection = new String[]{ContactsContract.PhoneLookup._ID, ContactsContract.PhoneLookup.NUMBER, ContactsContract.PhoneLookup.DISPLAY_NAME};
|
|
||||||
Cursor c = contentResolver.query(lookupUri, projection, null, null, null);
|
|
||||||
contact = checkPhoneQueryResult(contentResolver, c, ContactsContract.PhoneLookup.NUMBER, ContactsContract.PhoneLookup._ID, address.getUserName());
|
|
||||||
|
|
||||||
if (contact != null) {
|
|
||||||
return contact;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
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);
|
|
||||||
return contact.getNumbersOrAddresses().contains(address) || contact.getNumbersOrAddresses().contains("sip:" + address);
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String findRawLinphoneContactID(String contactID) {
|
|
||||||
String result = null;
|
|
||||||
String[] projection = { ContactsContract.RawContacts._ID };
|
|
||||||
|
|
||||||
String selection = ContactsContract.RawContacts.CONTACT_ID + "=? AND "
|
|
||||||
+ ContactsContract.RawContacts.ACCOUNT_TYPE + "=? ";
|
|
||||||
|
|
||||||
Cursor c = contentResolver.query(ContactsContract.RawContacts.CONTENT_URI, projection,
|
|
||||||
selection, new String[]{contactID, "org.linphone"}, null);
|
|
||||||
if (c != null) {
|
|
||||||
if (c.moveToFirst()) {
|
|
||||||
result = c.getString(c.getColumnIndex(ContactsContract.RawContacts._ID));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
c.close();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Add new sip address
|
|
||||||
Compatibility.addSipAddressToContact(context, ops, address, findRawContactID(contentResolver, contact.getID()));
|
|
||||||
try {
|
|
||||||
contentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
ops.clear();
|
|
||||||
|
|
||||||
contact.refresh(contentResolver);
|
|
||||||
|
|
||||||
//If address sip is correctly add, remove the im address
|
|
||||||
if(contact.getNumbersOrAddresses().contains(address)){
|
|
||||||
Compatibility.deleteImAddressFromContact(ops, address, contact.getID());
|
|
||||||
try {
|
|
||||||
contentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
ops.clear();
|
|
||||||
} else {
|
|
||||||
//Add linphone friend instead
|
|
||||||
if(createNewFriend(contact, address)) {
|
|
||||||
contact.refresh(contentResolver);
|
|
||||||
|
|
||||||
//Remove IM address
|
|
||||||
Compatibility.deleteImAddressFromContact(ops, address, contact.getID());
|
|
||||||
try {
|
|
||||||
contentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ops.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
oldContacts.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void prepareContactsInBackground() {
|
public synchronized void prepareContactsInBackground() {
|
||||||
if (contactCursor != null) {
|
contacts = new ArrayList<LinphoneContact>();
|
||||||
contactCursor.close();
|
|
||||||
}
|
for (LinphoneFriend friend : LinphoneManager.getLc().getFriendList()) {
|
||||||
if (sipContactCursor != null) {
|
LinphoneContact contact = new LinphoneContact();
|
||||||
sipContactCursor.close();
|
LinphoneAddress addr = friend.getAddress();
|
||||||
|
contact.setFullName(addr.getDisplayName());
|
||||||
|
contact.addNumberOrAddress(new LinphoneNumberOrAddress(addr.asStringUriOnly(), true));
|
||||||
|
contacts.add(contact);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(LinphoneActivity.instance().getResources().getBoolean(R.bool.use_linphone_friend)){
|
if (mAccount == null || !hasContactAccess) return;
|
||||||
contactList = new ArrayList<Contact>();
|
|
||||||
for(LinphoneFriend friend : LinphoneManager.getLc().getFriendList()){
|
Cursor c = Compatibility.getContactsCursor(contentResolver, null);
|
||||||
Contact contact = new Contact(friend.getRefKey(),friend.getAddress());
|
if (c != null) {
|
||||||
contactList.add(contact);
|
c.moveToFirst();
|
||||||
|
do {
|
||||||
|
String id = c.getString(c.getColumnIndex(Data.CONTACT_ID));
|
||||||
|
LinphoneContact contact = new LinphoneContact();
|
||||||
|
contact.setAndroidId(id);
|
||||||
|
contact.refresh();
|
||||||
|
contacts.add(contact);
|
||||||
}
|
}
|
||||||
|
while (c.moveToNext());
|
||||||
contactCursor = getFriendListCursor(contactList,true);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mAccount == null) return;
|
|
||||||
|
|
||||||
contactCursor = Compatibility.getContactsCursor(contentResolver, getContactsId());
|
|
||||||
sipContactCursor = Compatibility.getSIPContactsCursor(contentResolver, getContactsId());
|
|
||||||
|
|
||||||
Thread sipContactsHandler = new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if(sipContactCursor != null && 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 (LinphoneActivity.isInstanciated() && LinphoneActivity.instance().getResources().getBoolean(R.bool.use_linphone_tag)) {
|
|
||||||
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;
|
|
||||||
|
|
||||||
//Remove linphone contact tag if the contact has no sip address
|
|
||||||
if (LinphoneActivity.isInstanciated() && LinphoneActivity.instance().getResources().getBoolean(R.bool.use_linphone_tag)) {
|
|
||||||
if (removeContactTagIsNeeded(contact) && findRawLinphoneContactID(contact.getID()) != null) {
|
|
||||||
removeLinphoneContactTag(contact);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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) {
|
public static String getAddressOrNumberForAndroidContact(ContentResolver resolver, Uri contactUri) {
|
||||||
// Phone Numbers
|
// Phone Numbers
|
||||||
String[] projection = new String[]{ContactsContract.CommonDataKinds.Phone.NUMBER};
|
String[] projection = new String[]{ ContactsContract.CommonDataKinds.Phone.NUMBER };
|
||||||
Cursor c = resolver.query(contactUri, projection, null, null, null);
|
Cursor c = resolver.query(contactUri, projection, null, null, null);
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
while (c.moveToNext()) {
|
while (c.moveToNext()) {
|
||||||
|
@ -647,7 +169,7 @@ public class ContactsManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SIP addresses
|
// SIP addresses
|
||||||
projection = new String[] {ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS};
|
projection = new String[] { ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS };
|
||||||
c = resolver.query(contactUri, projection, null, null, null);
|
c = resolver.query(contactUri, projection, null, null, null);
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
while (c.moveToNext()) {
|
while (c.moveToNext()) {
|
||||||
|
@ -660,50 +182,4 @@ public class ContactsManager {
|
||||||
}
|
}
|
||||||
return null;
|
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 Cursor getFriendListCursor(List<Contact> contacts, boolean shouldGroupBy){
|
|
||||||
String[] columns = new String[] { ContactsContract.Data.CONTACT_ID, ContactsContract.Data.DISPLAY_NAME };
|
|
||||||
|
|
||||||
|
|
||||||
if (!shouldGroupBy) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
MatrixCursor result = new MatrixCursor(columns);
|
|
||||||
Set<String> groupBy = new HashSet<String>();
|
|
||||||
for (Contact contact: contacts) {
|
|
||||||
String name = contact.getName();
|
|
||||||
if (!groupBy.contains(name)) {
|
|
||||||
groupBy.add(name);
|
|
||||||
Object[] newRow = new Object[2];
|
|
||||||
|
|
||||||
newRow[0] = contact.getID();
|
|
||||||
newRow[1] = contact.getName();
|
|
||||||
|
|
||||||
result.addRow(newRow);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -209,7 +209,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 = ContactsManager.getInstance().queryAddressOrNumber(LinphoneService.instance().getContentResolver(),contactUri);
|
String address = ContactsManager.getAddressOrNumberForAndroidContact(LinphoneService.instance().getContentResolver(), contactUri);
|
||||||
if(address != null) {
|
if(address != null) {
|
||||||
mAddress.setText(address);
|
mAddress.setText(address);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -17,17 +17,13 @@ You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Calendar;
|
|
||||||
|
|
||||||
import org.linphone.core.LinphoneAddress;
|
import org.linphone.core.LinphoneAddress;
|
||||||
import org.linphone.core.LinphoneCoreException;
|
import org.linphone.core.LinphoneCoreException;
|
||||||
import org.linphone.core.LinphoneCoreFactory;
|
import org.linphone.core.LinphoneCoreFactory;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.app.Fragment;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.app.Fragment;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
|
@ -112,9 +108,9 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
|
||||||
|
|
||||||
if(lAddress != null) {
|
if(lAddress != null) {
|
||||||
contactAddress.setText(lAddress.asStringUriOnly());
|
contactAddress.setText(lAddress.asStringUriOnly());
|
||||||
Contact contact = ContactsManager.getInstance().findContactWithAddress(getActivity().getContentResolver(), lAddress);
|
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(getActivity().getContentResolver(), lAddress);
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
contactName.setText(contact.getName());
|
contactName.setText(contact.getFullName());
|
||||||
LinphoneUtils.setImagePictureFromUri(view.getContext(),contactPicture,contact.getPhotoUri(),contact.getThumbnailUri());
|
LinphoneUtils.setImagePictureFromUri(view.getContext(),contactPicture,contact.getPhotoUri(),contact.getThumbnailUri());
|
||||||
addToContacts.setVisibility(View.INVISIBLE);
|
addToContacts.setVisibility(View.INVISIBLE);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -440,11 +440,11 @@ public class HistoryListFragment extends Fragment implements OnClickListener, On
|
||||||
holder.callDirection.setImageResource(R.drawable.call_status_outgoing);
|
holder.callDirection.setImageResource(R.drawable.call_status_outgoing);
|
||||||
}
|
}
|
||||||
|
|
||||||
Contact c = ContactsManager.getInstance().findContactWithAddress(getActivity().getContentResolver(), address);
|
LinphoneContact c = ContactsManager.getInstance().findContactFromAddress(getActivity().getContentResolver(), address);
|
||||||
String displayName = null;
|
String displayName = null;
|
||||||
final String sipUri = address.asString();
|
final String sipUri = address.asString();
|
||||||
if(c != null){
|
if(c != null){
|
||||||
displayName = c.getName();
|
displayName = c.getFullName();
|
||||||
LinphoneUtils.setImagePictureFromUri(view.getContext(),holder.contactPicture,c.getPhotoUri(),c.getThumbnailUri());
|
LinphoneUtils.setImagePictureFromUri(view.getContext(),holder.contactPicture,c.getPhotoUri(),c.getThumbnailUri());
|
||||||
} else {
|
} else {
|
||||||
holder.contactPicture.setImageResource(R.drawable.avatar);
|
holder.contactPicture.setImageResource(R.drawable.avatar);
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.util.List;
|
||||||
|
|
||||||
import org.linphone.LinphoneManager.AddressType;
|
import org.linphone.LinphoneManager.AddressType;
|
||||||
import org.linphone.assistant.AssistantActivity;
|
import org.linphone.assistant.AssistantActivity;
|
||||||
|
import org.linphone.assistant.RemoteProvisioningLoginActivity;
|
||||||
import org.linphone.core.CallDirection;
|
import org.linphone.core.CallDirection;
|
||||||
import org.linphone.core.LinphoneAddress;
|
import org.linphone.core.LinphoneAddress;
|
||||||
import org.linphone.core.LinphoneAuthInfo;
|
import org.linphone.core.LinphoneAuthInfo;
|
||||||
|
@ -44,7 +45,6 @@ import org.linphone.core.LinphoneCoreListenerBase;
|
||||||
import org.linphone.core.LinphoneProxyConfig;
|
import org.linphone.core.LinphoneProxyConfig;
|
||||||
import org.linphone.core.Reason;
|
import org.linphone.core.Reason;
|
||||||
import org.linphone.mediastream.Log;
|
import org.linphone.mediastream.Log;
|
||||||
import org.linphone.assistant.RemoteProvisioningLoginActivity;
|
|
||||||
import org.linphone.ui.AddressText;
|
import org.linphone.ui.AddressText;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
|
@ -99,7 +99,6 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
||||||
private static final int CALL_ACTIVITY = 19;
|
private static final int CALL_ACTIVITY = 19;
|
||||||
private static final int PERMISSIONS_REQUEST_READ_CONTACTS = 200;
|
private static final int PERMISSIONS_REQUEST_READ_CONTACTS = 200;
|
||||||
private static final int PERMISSIONS_REQUEST_RECORD_AUDIO = 201;
|
private static final int PERMISSIONS_REQUEST_RECORD_AUDIO = 201;
|
||||||
private static final int PERMISSIONS_REQUEST_CAMERA = 202;
|
|
||||||
private static final int PERMISSIONS_REQUEST_RECORD_AUDIO_INCOMING_CALL = 203;
|
private static final int PERMISSIONS_REQUEST_RECORD_AUDIO_INCOMING_CALL = 203;
|
||||||
|
|
||||||
private static LinphoneActivity instance;
|
private static LinphoneActivity instance;
|
||||||
|
@ -116,7 +115,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
||||||
private ChatFragment chatFragment;
|
private ChatFragment chatFragment;
|
||||||
private Fragment.SavedState dialerSavedState;
|
private Fragment.SavedState dialerSavedState;
|
||||||
private boolean newProxyConfig;
|
private boolean newProxyConfig;
|
||||||
private boolean isAnimationDisabled = true, preferLinphoneContacts = false, emptyFragment = false, permissionAsked = false;
|
private boolean isAnimationDisabled = true, emptyFragment = false, permissionAsked = false;
|
||||||
private OrientationEventListener mOrientationHelper;
|
private OrientationEventListener mOrientationHelper;
|
||||||
private LinphoneCoreListenerBase mListener;
|
private LinphoneCoreListenerBase mListener;
|
||||||
private LinearLayout mTabBar;
|
private LinearLayout mTabBar;
|
||||||
|
@ -126,7 +125,6 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
||||||
private RelativeLayout sideMenuContent, quitLayout, defaultAccount;
|
private RelativeLayout sideMenuContent, quitLayout, defaultAccount;
|
||||||
private ListView accountsList, sideMenuItemList;
|
private ListView accountsList, sideMenuItemList;
|
||||||
private ImageView menu;
|
private ImageView menu;
|
||||||
private Dialog authInfoPassword;
|
|
||||||
|
|
||||||
static final boolean isInstanciated() {
|
static final boolean isInstanciated() {
|
||||||
return instance != null;
|
return instance != null;
|
||||||
|
@ -547,9 +545,9 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
||||||
//TODO display error message
|
//TODO display error message
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Contact c = ContactsManager.getInstance().findContactWithAddress(getContentResolver(), lAddress);
|
LinphoneContact c = ContactsManager.getInstance().findContactFromAddress(getContentResolver(), lAddress);
|
||||||
|
|
||||||
String displayName = c != null ? c.getName() : LinphoneUtils.getAddressDisplayName(sipUri);
|
String displayName = c != null ? c.getFullName() : LinphoneUtils.getAddressDisplayName(sipUri);
|
||||||
String pictureUri = c != null && c.getPhotoUri() != null ? c.getPhotoUri().toString() : null;
|
String pictureUri = c != null && c.getPhotoUri() != null ? c.getPhotoUri().toString() : null;
|
||||||
|
|
||||||
String status;
|
String status;
|
||||||
|
@ -597,7 +595,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
||||||
return dateFormat.format(cal.getTime());
|
return dateFormat.format(cal.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayContact(Contact contact, boolean chatOnly) {
|
public void displayContact(LinphoneContact contact, boolean chatOnly) {
|
||||||
Fragment fragment2 = getFragmentManager().findFragmentById(R.id.fragmentContainer2);
|
Fragment fragment2 = getFragmentManager().findFragmentById(R.id.fragmentContainer2);
|
||||||
if (fragment2 != null && fragment2.isVisible() && currentFragment == FragmentsAvailable.CONTACT_DETAIL) {
|
if (fragment2 != null && fragment2.isVisible() && currentFragment == FragmentsAvailable.CONTACT_DETAIL) {
|
||||||
ContactDetailsFragment contactFragment = (ContactDetailsFragment) fragment2;
|
ContactDetailsFragment contactFragment = (ContactDetailsFragment) fragment2;
|
||||||
|
@ -611,14 +609,9 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayContacts(boolean chatOnly) {
|
public void displayContacts(boolean chatOnly) {
|
||||||
if (chatOnly) {
|
|
||||||
preferLinphoneContacts = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Bundle extras = new Bundle();
|
Bundle extras = new Bundle();
|
||||||
extras.putBoolean("ChatAddressOnly", chatOnly);
|
extras.putBoolean("ChatAddressOnly", chatOnly);
|
||||||
changeCurrentFragment(FragmentsAvailable.CONTACTS_LIST, extras);
|
changeCurrentFragment(FragmentsAvailable.CONTACTS_LIST, extras);
|
||||||
preferLinphoneContacts = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayChatList() {
|
public void displayChatList() {
|
||||||
|
@ -677,8 +670,8 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
||||||
Log.e("Cannot display chat", e);
|
Log.e("Cannot display chat", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Contact contact = ContactsManager.getInstance().findContactWithAddress(getContentResolver(), lAddress);
|
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(getContentResolver(), lAddress);
|
||||||
displayName = contact != null ? contact.getName() : null;
|
displayName = contact != null ? contact.getFullName() : null;
|
||||||
|
|
||||||
if (contact != null && contact.getPhotoUri() != null) {
|
if (contact != null && contact.getPhotoUri() != null) {
|
||||||
pictureUri = contact.getPhotoUri().toString();
|
pictureUri = contact.getPhotoUri().toString();
|
||||||
|
@ -1148,7 +1141,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
||||||
changeCurrentFragment(FragmentsAvailable.CONTACT_EDITOR, extras);
|
changeCurrentFragment(FragmentsAvailable.CONTACT_EDITOR, extras);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void editContact(Contact contact)
|
public void editContact(LinphoneContact contact)
|
||||||
{
|
{
|
||||||
Bundle extras = new Bundle();
|
Bundle extras = new Bundle();
|
||||||
extras.putSerializable("Contact", contact);
|
extras.putSerializable("Contact", contact);
|
||||||
|
@ -1156,7 +1149,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void editContact(Contact contact, String sipAddress)
|
public void editContact(LinphoneContact contact, String sipAddress)
|
||||||
{
|
{
|
||||||
|
|
||||||
Bundle extras = new Bundle();
|
Bundle extras = new Bundle();
|
||||||
|
@ -1241,7 +1234,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getPackageManager().checkPermission(Manifest.permission.READ_CONTACTS, getPackageName()) == PackageManager.PERMISSION_GRANTED){
|
if (getPackageManager().checkPermission(Manifest.permission.READ_CONTACTS, getPackageName()) == PackageManager.PERMISSION_GRANTED){
|
||||||
ContactsManager.getInstance().enabledContactsAccess();
|
ContactsManager.getInstance().enableContactsAccess();
|
||||||
ContactsManager.getInstance().prepareContactsInBackground();
|
ContactsManager.getInstance().prepareContactsInBackground();
|
||||||
} else {
|
} else {
|
||||||
checkAndRequestPermission(Manifest.permission.READ_CONTACTS, PERMISSIONS_REQUEST_READ_CONTACTS);
|
checkAndRequestPermission(Manifest.permission.READ_CONTACTS, PERMISSIONS_REQUEST_READ_CONTACTS);
|
||||||
|
|
254
src/org/linphone/LinphoneContact.java
Normal file
254
src/org/linphone/LinphoneContact.java
Normal file
|
@ -0,0 +1,254 @@
|
||||||
|
/*
|
||||||
|
LinphoneContact.java
|
||||||
|
Copyright (C) 2016 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 java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.linphone.core.LinphoneAddress;
|
||||||
|
import org.linphone.core.LinphoneCoreFactory;
|
||||||
|
import org.linphone.core.LinphoneFriend;
|
||||||
|
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.ContentUris;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.provider.ContactsContract;
|
||||||
|
|
||||||
|
public class LinphoneContact implements Serializable {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 9015568163905205244L;
|
||||||
|
|
||||||
|
private LinphoneFriend friend;
|
||||||
|
private String fullName, androidId;
|
||||||
|
private Uri photoUri, thumbnailUri;
|
||||||
|
private List<LinphoneNumberOrAddress> addresses;
|
||||||
|
|
||||||
|
public LinphoneContact() {
|
||||||
|
addresses = new ArrayList<LinphoneNumberOrAddress>();
|
||||||
|
androidId = null;
|
||||||
|
thumbnailUri = null;
|
||||||
|
photoUri = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFullName(String name) {
|
||||||
|
if (name == null) return;
|
||||||
|
|
||||||
|
fullName = name;
|
||||||
|
if (friend != null) {
|
||||||
|
friend.setName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFullName() {
|
||||||
|
return fullName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPhoto() {
|
||||||
|
return photoUri != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPhotoUri(Uri uri) {
|
||||||
|
photoUri = uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Uri getPhotoUri() {
|
||||||
|
return photoUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setThumbnailUri(Uri uri) {
|
||||||
|
thumbnailUri = uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Uri getThumbnailUri() {
|
||||||
|
return thumbnailUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addNumberOrAddress(LinphoneNumberOrAddress noa) {
|
||||||
|
if (noa == null) return;
|
||||||
|
addresses.add(noa);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<LinphoneNumberOrAddress> getNumbersOrAddresses() {
|
||||||
|
return addresses;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasAddress(String address) {
|
||||||
|
for (LinphoneNumberOrAddress noa : getNumbersOrAddresses()) {
|
||||||
|
if (noa.isSIPAddress()) {
|
||||||
|
String value = noa.getValue();
|
||||||
|
if (value.equals(address) || value.equals("sip:" + address)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasAddress() {
|
||||||
|
for (LinphoneNumberOrAddress noa : getNumbersOrAddresses()) {
|
||||||
|
if (noa.isSIPAddress()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAndroidId(String id) {
|
||||||
|
androidId = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAndroidId() {
|
||||||
|
return androidId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete() {
|
||||||
|
if (isAndroidContact()) {
|
||||||
|
// TODO
|
||||||
|
/*String select = ContactsContract.Data.CONTACT_ID + " = ?";
|
||||||
|
String[] args = new String[] { contact.getID() };
|
||||||
|
|
||||||
|
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
|
||||||
|
ops.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI)
|
||||||
|
.withSelection(select, args)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
|
||||||
|
ContactsManager.getInstance().removeAllFriends(contact);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.w(e.getMessage() + ":" + e.getStackTrace());
|
||||||
|
}
|
||||||
|
ContactsManager.getInstance().removeContactFromLists(getActivity().getContentResolver(), contact);*/
|
||||||
|
}
|
||||||
|
if (friend != null) {
|
||||||
|
LinphoneManager.getLcIfManagerNotDestroyedOrNull().removeFriend(friend);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refresh() {
|
||||||
|
addresses = new ArrayList<LinphoneNumberOrAddress>();
|
||||||
|
if (friend != null) {
|
||||||
|
LinphoneAddress addr = friend.getAddress();
|
||||||
|
if (addr != null) {
|
||||||
|
addresses.add(new LinphoneNumberOrAddress(addr.asStringUriOnly(), true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isAndroidContact()) {
|
||||||
|
fullName = friend.getName();
|
||||||
|
thumbnailUri = null;
|
||||||
|
photoUri = null;
|
||||||
|
} else {
|
||||||
|
String id = getAndroidId();
|
||||||
|
String name = getName(id);
|
||||||
|
Uri thumbnail = getContactPictureUri(id);
|
||||||
|
Uri photo = getContactPhotoUri(id);
|
||||||
|
|
||||||
|
setFullName(name);
|
||||||
|
setThumbnailUri(thumbnail);
|
||||||
|
setPhotoUri(photo);
|
||||||
|
for (LinphoneNumberOrAddress noa : getAddressesAndNumbersForAndroidContact(id)) {
|
||||||
|
addresses.add(noa);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAndroidContact() {
|
||||||
|
return androidId != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LinphoneContact createLinphoneFriend(String name, String address) {
|
||||||
|
LinphoneContact contact = new LinphoneContact();
|
||||||
|
LinphoneFriend friend = LinphoneCoreFactory.instance().createLinphoneFriend();
|
||||||
|
contact.friend = friend;
|
||||||
|
|
||||||
|
if (name != null) {
|
||||||
|
contact.setFullName(name);
|
||||||
|
}
|
||||||
|
if (address != null) {
|
||||||
|
contact.addNumberOrAddress(new LinphoneNumberOrAddress(address, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
return contact;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Uri getContactUri(String id) {
|
||||||
|
Uri person = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, id);
|
||||||
|
return person;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Uri getContactPictureUri(String id) {
|
||||||
|
Uri person = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(id));
|
||||||
|
return Uri.withAppendedPath(person, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Uri getContactPhotoUri(String id) {
|
||||||
|
Uri person = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(id));
|
||||||
|
return Uri.withAppendedPath(person, ContactsContract.Contacts.Photo.DISPLAY_PHOTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getName(String id) {
|
||||||
|
ContentResolver resolver = ContactsManager.getInstance().getContentResolver();
|
||||||
|
Cursor cursor = resolver.query(getContactUri(id), null, null, null, null);
|
||||||
|
String name = null;
|
||||||
|
if (cursor != null) {
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<LinphoneNumberOrAddress> getAddressesAndNumbersForAndroidContact(String id) {
|
||||||
|
List<LinphoneNumberOrAddress> result = new ArrayList<LinphoneNumberOrAddress>();
|
||||||
|
ContentResolver resolver = ContactsManager.getInstance().getContentResolver();
|
||||||
|
|
||||||
|
Uri uri = ContactsContract.Data.CONTENT_URI;
|
||||||
|
String[] projection;
|
||||||
|
|
||||||
|
// SIP addresses
|
||||||
|
String selection2 = new StringBuilder().append(ContactsContract.Data.CONTACT_ID).append(" = ? AND ").append(ContactsContract.Data.MIMETYPE).append(" = '").append(ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE).append("'").toString();
|
||||||
|
projection = new String[] { ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS };
|
||||||
|
Cursor c = resolver.query(uri, projection, selection2, new String[]{ id }, null);
|
||||||
|
if (c != null) {
|
||||||
|
while (c.moveToNext()) {
|
||||||
|
result.add(new LinphoneNumberOrAddress("sip:" + c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS)), true));
|
||||||
|
}
|
||||||
|
c.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Phone Numbers
|
||||||
|
c = resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER }, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + id, null, null);
|
||||||
|
if (c != null) {
|
||||||
|
while (c.moveToNext()) {
|
||||||
|
String number = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
|
||||||
|
result.add(new LinphoneNumberOrAddress(number, false));
|
||||||
|
}
|
||||||
|
c.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -171,7 +171,6 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
|
||||||
mCallLogDatabaseFile = basePath + "/linphone-log-history.db";
|
mCallLogDatabaseFile = basePath + "/linphone-log-history.db";
|
||||||
mFriendsDatabaseFile = basePath + "/linphone-friends.db";
|
mFriendsDatabaseFile = basePath + "/linphone-friends.db";
|
||||||
mErrorToneFile = basePath + "/error.wav";
|
mErrorToneFile = basePath + "/error.wav";
|
||||||
mConfigFile = basePath + "/configrc";
|
|
||||||
mUserCertificatePath = basePath;
|
mUserCertificatePath = basePath;
|
||||||
|
|
||||||
mPrefs = LinphonePreferences.instance();
|
mPrefs = LinphonePreferences.instance();
|
||||||
|
@ -197,7 +196,6 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
|
||||||
private final String mCallLogDatabaseFile;
|
private final String mCallLogDatabaseFile;
|
||||||
private final String mFriendsDatabaseFile;
|
private final String mFriendsDatabaseFile;
|
||||||
private final String mErrorToneFile;
|
private final String mErrorToneFile;
|
||||||
private final String mConfigFile;
|
|
||||||
private final String mUserCertificatePath;
|
private final String mUserCertificatePath;
|
||||||
private ByteArrayInputStream mUploadingImageStream;
|
private ByteArrayInputStream mUploadingImageStream;
|
||||||
|
|
||||||
|
@ -866,13 +864,13 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Contact contact = ContactsManager.getInstance().findContactWithAddress(mServiceContext.getContentResolver(), from);
|
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(mServiceContext.getContentResolver(), from);
|
||||||
if (!mServiceContext.getResources().getBoolean(R.bool.disable_chat_message_notification)) {
|
if (!mServiceContext.getResources().getBoolean(R.bool.disable_chat_message_notification)) {
|
||||||
if (LinphoneActivity.isInstanciated() && !LinphoneActivity.instance().displayChatMessageNotification(from.asStringUriOnly())) {
|
if (LinphoneActivity.isInstanciated() && !LinphoneActivity.instance().displayChatMessageNotification(from.asStringUriOnly())) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), contact.getName(), textMessage);
|
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), contact.getFullName(), textMessage);
|
||||||
} else {
|
} else {
|
||||||
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), from.getUserName(), textMessage);
|
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), from.getUserName(), textMessage);
|
||||||
}
|
}
|
||||||
|
|
42
src/org/linphone/LinphoneNumberOrAddress.java
Normal file
42
src/org/linphone/LinphoneNumberOrAddress.java
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
LinphoneNumberOrAddress.java
|
||||||
|
Copyright (C) 2016 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;
|
||||||
|
|
||||||
|
public class LinphoneNumberOrAddress {
|
||||||
|
private boolean isSIPAddress;
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
public LinphoneNumberOrAddress(String v, boolean isSIP) {
|
||||||
|
value = v;
|
||||||
|
isSIPAddress = isSIP;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSIPAddress() {
|
||||||
|
return isSIPAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String v) {
|
||||||
|
value = v;
|
||||||
|
}
|
||||||
|
}
|
|
@ -315,7 +315,7 @@ public final class LinphoneService extends Service {
|
||||||
LinphoneAddress address = LinphoneCoreFactory.instance().createLinphoneAddress(userName,domain,null);
|
LinphoneAddress address = LinphoneCoreFactory.instance().createLinphoneAddress(userName,domain,null);
|
||||||
address.setDisplayName(displayName);
|
address.setDisplayName(displayName);
|
||||||
|
|
||||||
Contact contact = ContactsManager.getInstance().findContactWithAddress(getContentResolver(), address);
|
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(getContentResolver(), address);
|
||||||
Uri pictureUri = contact != null ? contact.getPhotoUri() : null;
|
Uri pictureUri = contact != null ? contact.getPhotoUri() : null;
|
||||||
Bitmap bm = null;
|
Bitmap bm = null;
|
||||||
try {
|
try {
|
||||||
|
@ -393,7 +393,7 @@ public final class LinphoneService extends Service {
|
||||||
|
|
||||||
Uri pictureUri = null;
|
Uri pictureUri = null;
|
||||||
try {
|
try {
|
||||||
Contact contact = ContactsManager.getInstance().findContactWithAddress(getContentResolver(), LinphoneCoreFactory.instance().createLinphoneAddress(fromSipUri));
|
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(getContentResolver(), LinphoneCoreFactory.instance().createLinphoneAddress(fromSipUri));
|
||||||
if (contact != null)
|
if (contact != null)
|
||||||
pictureUri = contact.getThumbnailUri();
|
pictureUri = contact.getThumbnailUri();
|
||||||
} catch (LinphoneCoreException e1) {
|
} catch (LinphoneCoreException e1) {
|
||||||
|
@ -489,7 +489,6 @@ public final class LinphoneService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private void dumpDeviceInformation() {
|
private void dumpDeviceInformation() {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("DEVICE=").append(Build.DEVICE).append("\n");
|
sb.append("DEVICE=").append(Build.DEVICE).append("\n");
|
||||||
|
|
|
@ -35,9 +35,11 @@ import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
import org.linphone.compatibility.Compatibility;
|
||||||
import org.linphone.core.LinphoneAddress;
|
import org.linphone.core.LinphoneAddress;
|
||||||
import org.linphone.core.LinphoneCall;
|
import org.linphone.core.LinphoneCall;
|
||||||
import org.linphone.core.LinphoneCall.State;
|
import org.linphone.core.LinphoneCall.State;
|
||||||
|
@ -46,7 +48,6 @@ import org.linphone.core.LinphoneCoreException;
|
||||||
import org.linphone.core.LinphoneCoreFactory;
|
import org.linphone.core.LinphoneCoreFactory;
|
||||||
import org.linphone.core.LinphoneProxyConfig;
|
import org.linphone.core.LinphoneProxyConfig;
|
||||||
import org.linphone.mediastream.Log;
|
import org.linphone.mediastream.Log;
|
||||||
import org.linphone.mediastream.Version;
|
|
||||||
import org.linphone.mediastream.video.capture.hwconf.Hacks;
|
import org.linphone.mediastream.video.capture.hwconf.Hacks;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
@ -54,6 +55,7 @@ import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.database.Cursor;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
|
@ -148,9 +150,9 @@ public final class LinphoneUtils {
|
||||||
|
|
||||||
SimpleDateFormat dateFormat;
|
SimpleDateFormat dateFormat;
|
||||||
if (isToday(cal)) {
|
if (isToday(cal)) {
|
||||||
dateFormat = new SimpleDateFormat(context.getResources().getString(R.string.today_date_format));
|
dateFormat = new SimpleDateFormat(context.getResources().getString(R.string.today_date_format), Locale.getDefault());
|
||||||
} else {
|
} else {
|
||||||
dateFormat = new SimpleDateFormat(format);
|
dateFormat = new SimpleDateFormat(format, Locale.getDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
return dateFormat.format(cal.getTime());
|
return dateFormat.format(cal.getTime());
|
||||||
|
@ -226,7 +228,7 @@ public final class LinphoneUtils {
|
||||||
try {
|
try {
|
||||||
bm = MediaStore.Images.Media.getBitmap(c.getContentResolver(),uri);
|
bm = MediaStore.Images.Media.getBitmap(c.getContentResolver(),uri);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if(tUri != null){
|
if (tUri != null) {
|
||||||
try {
|
try {
|
||||||
bm = MediaStore.Images.Media.getBitmap(c.getContentResolver(),tUri);
|
bm = MediaStore.Images.Media.getBitmap(c.getContentResolver(),tUri);
|
||||||
} catch (IOException ie) {
|
} catch (IOException ie) {
|
||||||
|
@ -234,10 +236,11 @@ public final class LinphoneUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(bm != null) {
|
if (bm != null) {
|
||||||
view.setImageBitmap(bm);
|
view.setImageBitmap(bm);
|
||||||
|
} else {
|
||||||
|
view.setImageResource(R.drawable.avatar);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,5 +459,13 @@ public final class LinphoneUtils {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<LinphoneContact> contactCursorToList(ContentResolver cr, Cursor cursor) {
|
||||||
|
ArrayList<LinphoneContact> list = new ArrayList<LinphoneContact>();
|
||||||
|
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
|
||||||
|
list.add(Compatibility.getContact(cr, cursor, cursor.getPosition()));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,15 +35,13 @@ import org.linphone.core.PayloadType;
|
||||||
import org.linphone.mediastream.Log;
|
import org.linphone.mediastream.Log;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
|
import android.app.Fragment;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.app.Fragment;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
|
@ -170,12 +168,6 @@ public class StatusFragment extends Fragment {
|
||||||
} else if (activity instanceof AssistantActivity) {
|
} else if (activity instanceof AssistantActivity) {
|
||||||
((AssistantActivity) activity).updateStatusFragment(this);
|
((AssistantActivity) activity).updateStatusFragment(this);
|
||||||
isInCall = false;
|
isInCall = false;
|
||||||
} else if (activity instanceof CallIncomingActivity) {
|
|
||||||
((CallIncomingActivity) activity).updateStatusFragment(this);
|
|
||||||
isInCall = true;
|
|
||||||
} else if (activity instanceof CallOutgoingActivity) {
|
|
||||||
((CallOutgoingActivity) activity).updateStatusFragment(this);
|
|
||||||
isInCall = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +184,7 @@ public class StatusFragment extends Fragment {
|
||||||
voicemailCount.setVisibility(View.GONE);
|
voicemailCount.setVisibility(View.GONE);
|
||||||
|
|
||||||
if (isInCall && isAttached) {
|
if (isInCall && isAttached) {
|
||||||
LinphoneCall call = LinphoneManager.getLc().getCurrentCall();
|
//LinphoneCall call = LinphoneManager.getLc().getCurrentCall();
|
||||||
//initCallStatsRefresher(call, callStats);
|
//initCallStatsRefresher(call, callStats);
|
||||||
} else if (!isInCall) {
|
} else if (!isInCall) {
|
||||||
voicemailCount.setVisibility(View.VISIBLE);
|
voicemailCount.setVisibility(View.VISIBLE);
|
||||||
|
|
|
@ -6,7 +6,7 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.linphone.Contact;
|
import org.linphone.LinphoneContact;
|
||||||
import org.linphone.R;
|
import org.linphone.R;
|
||||||
import org.linphone.core.LinphoneAddress;
|
import org.linphone.core.LinphoneAddress;
|
||||||
|
|
||||||
|
@ -21,8 +21,6 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.MatrixCursor;
|
import android.database.MatrixCursor;
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
|
@ -208,7 +206,7 @@ public class ApiFivePlus {
|
||||||
return cursor.getColumnIndex(Data.DISPLAY_NAME);
|
return cursor.getColumnIndex(Data.DISPLAY_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Contact getContact(ContentResolver cr, Cursor cursor, int position) {
|
public static LinphoneContact getContact(ContentResolver cr, Cursor cursor, int position) {
|
||||||
try {
|
try {
|
||||||
if(cursor != null) {
|
if(cursor != null) {
|
||||||
cursor.moveToFirst();
|
cursor.moveToFirst();
|
||||||
|
@ -222,16 +220,12 @@ public class ApiFivePlus {
|
||||||
Uri photo = getContactPhotoUri(id);
|
Uri photo = getContactPhotoUri(id);
|
||||||
InputStream input = getContactPictureInputStream(cr, id);
|
InputStream input = getContactPictureInputStream(cr, id);
|
||||||
|
|
||||||
Contact contact;
|
LinphoneContact contact = new LinphoneContact();
|
||||||
if (input == null) {
|
contact.setAndroidId(id);
|
||||||
contact = new Contact(id, name);
|
contact.setFullName(name);
|
||||||
} else {
|
if (input != null) {
|
||||||
Bitmap bm = null;
|
contact.setPhotoUri(photo);
|
||||||
try {
|
contact.setThumbnailUri(thumbnail);
|
||||||
bm = BitmapFactory.decodeStream(input);
|
|
||||||
} catch (OutOfMemoryError oome) {
|
|
||||||
}
|
|
||||||
contact = new Contact(id, name, photo, thumbnail, bm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return contact;
|
return contact;
|
||||||
|
@ -270,9 +264,9 @@ public class ApiFivePlus {
|
||||||
|
|
||||||
Cursor cursor = getSIPContactCursor(cr, sipUri);
|
Cursor cursor = getSIPContactCursor(cr, sipUri);
|
||||||
if(cursor != null) {
|
if(cursor != null) {
|
||||||
Contact contact = getContact(cr, cursor, 0);
|
LinphoneContact contact = getContact(cr, cursor, 0);
|
||||||
if (contact != null && contact.getNumbersOrAddresses().contains(sipUri)) {
|
if (contact != null && contact.getNumbersOrAddresses().contains(sipUri)) {
|
||||||
address.setDisplayName(contact.getName());
|
address.setDisplayName(contact.getFullName());
|
||||||
cursor.close();
|
cursor.close();
|
||||||
return contact.getPhotoUri();
|
return contact.getPhotoUri();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.linphone.Contact;
|
import org.linphone.Contact;
|
||||||
|
import org.linphone.LinphoneContact;
|
||||||
import org.linphone.LinphoneUtils;
|
import org.linphone.LinphoneUtils;
|
||||||
import org.linphone.R;
|
import org.linphone.R;
|
||||||
import org.linphone.core.LinphoneAddress;
|
import org.linphone.core.LinphoneAddress;
|
||||||
|
@ -16,8 +17,8 @@ import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
import android.provider.ContactsContract.CommonDataKinds;
|
import android.provider.ContactsContract.CommonDataKinds;
|
||||||
import android.provider.ContactsContract.Contacts;
|
|
||||||
import android.provider.ContactsContract.CommonDataKinds.Phone;
|
import android.provider.ContactsContract.CommonDataKinds.Phone;
|
||||||
|
import android.provider.ContactsContract.Contacts;
|
||||||
import android.provider.ContactsContract.Data;
|
import android.provider.ContactsContract.Data;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
@ -183,9 +184,9 @@ public class ApiNinePlus {
|
||||||
String sipUri = username + "@" + domain;
|
String sipUri = username + "@" + domain;
|
||||||
|
|
||||||
Cursor cursor = getSIPContactCursor(cr, sipUri);
|
Cursor cursor = getSIPContactCursor(cr, sipUri);
|
||||||
Contact contact = ApiFivePlus.getContact(cr, cursor, 0);
|
LinphoneContact contact = ApiFivePlus.getContact(cr, cursor, 0);
|
||||||
if (contact != null && contact.getNumbersOrAddresses().contains(sipUri)) {
|
if (contact != null && contact.getNumbersOrAddresses().contains(sipUri)) {
|
||||||
address.setDisplayName(contact.getName());
|
address.setDisplayName(contact.getFullName());
|
||||||
cursor.close();
|
cursor.close();
|
||||||
return contact.getPhotoUri();
|
return contact.getPhotoUri();
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.linphone.Contact;
|
import org.linphone.Contact;
|
||||||
|
import org.linphone.LinphoneContact;
|
||||||
import org.linphone.core.LinphoneAddress;
|
import org.linphone.core.LinphoneAddress;
|
||||||
import org.linphone.mediastream.Version;
|
import org.linphone.mediastream.Version;
|
||||||
|
|
||||||
|
@ -131,7 +132,7 @@ public class Compatibility {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Contact getContact(ContentResolver cr, Cursor cursor, int position) {
|
public static LinphoneContact getContact(ContentResolver cr, Cursor cursor, int position) {
|
||||||
if (Version.sdkAboveOrEqual(Version.API05_ECLAIR_20)) {
|
if (Version.sdkAboveOrEqual(Version.API05_ECLAIR_20)) {
|
||||||
return ApiFivePlus.getContact(cr, cursor, position);
|
return ApiFivePlus.getContact(cr, cursor, position);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ import java.util.Calendar;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.linphone.Contact;
|
import org.linphone.LinphoneContact;
|
||||||
import org.linphone.LinphoneManager;
|
import org.linphone.LinphoneManager;
|
||||||
import org.linphone.LinphoneUtils;
|
import org.linphone.LinphoneUtils;
|
||||||
import org.linphone.R;
|
import org.linphone.R;
|
||||||
|
@ -81,7 +81,7 @@ public class BubbleChat implements LinphoneChatMessage.LinphoneChatMessageListen
|
||||||
private Bitmap defaultBitmap;
|
private Bitmap defaultBitmap;
|
||||||
|
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
public BubbleChat(final Context context, LinphoneChatMessage message, Contact c) {
|
public BubbleChat(final Context context, LinphoneChatMessage message, LinphoneContact c) {
|
||||||
if (message == null) {
|
if (message == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -211,10 +211,9 @@ public class BubbleChat implements LinphoneChatMessage.LinphoneChatMessageListen
|
||||||
contactPicture = (ImageView) view.findViewById(R.id.contact_picture);
|
contactPicture = (ImageView) view.findViewById(R.id.contact_picture);
|
||||||
|
|
||||||
String displayName = nativeMessage.getFrom().getUserName();
|
String displayName = nativeMessage.getFrom().getUserName();
|
||||||
final String sipUri = nativeMessage.getFrom().asStringUriOnly();
|
|
||||||
if(!nativeMessage.isOutgoing()) {
|
if(!nativeMessage.isOutgoing()) {
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
displayName = c.getName();
|
displayName = c.getFullName();
|
||||||
LinphoneUtils.setImagePictureFromUri(view.getContext(), contactPicture, c.getPhotoUri(), c.getThumbnailUri());
|
LinphoneUtils.setImagePictureFromUri(view.getContext(), contactPicture, c.getPhotoUri(), c.getThumbnailUri());
|
||||||
} else {
|
} else {
|
||||||
contactPicture.setImageResource(R.drawable.avatar);
|
contactPicture.setImageResource(R.drawable.avatar);
|
||||||
|
|
Loading…
Reference in a new issue