Update contact for linphoen friend
This commit is contained in:
parent
54841c8d5a
commit
d724d20d3c
6 changed files with 278 additions and 273 deletions
|
@ -6,7 +6,7 @@
|
|||
<bool name="hide_in_call_stats">false</bool>
|
||||
<string name="default_domain">sip.linphone.org</string>
|
||||
<string name="default_stun">stun.linphone.org</string>
|
||||
<bool name="use_linphone_friend">true</bool>
|
||||
<bool name="use_linphone_friend">false</bool>
|
||||
|
||||
<string name="wizard_url">https://www.linphone.org/wizard.php</string>
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.linphone.compatibility.Compatibility;
|
||||
import org.linphone.core.LinphoneAddress;
|
||||
import org.linphone.core.LinphoneCore;
|
||||
import org.linphone.core.LinphoneFriend;
|
||||
|
||||
|
@ -42,6 +43,7 @@ public class Contact implements Serializable {
|
|||
private transient Bitmap photo;
|
||||
private List<String> numbersOrAddresses;
|
||||
private boolean hasFriends;
|
||||
private LinphoneAddress address;
|
||||
|
||||
public Contact(String id, String name) {
|
||||
super();
|
||||
|
@ -50,8 +52,19 @@ public class Contact implements Serializable {
|
|||
this.photoUri = null;
|
||||
this.thumbnailUri = null;
|
||||
this.hasFriends = false;
|
||||
this.address = null;
|
||||
}
|
||||
|
||||
|
||||
public Contact(String id, LinphoneAddress address) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.name = LinphoneUtils.getAddressDisplayName(address);
|
||||
this.photoUri = null;
|
||||
this.thumbnailUri = null;
|
||||
this.address = address;
|
||||
|
||||
}
|
||||
|
||||
public Contact(String id, String name, Uri photo, Uri thumbnail) {
|
||||
super();
|
||||
this.id = id;
|
||||
|
@ -60,6 +73,7 @@ public class Contact implements Serializable {
|
|||
this.thumbnailUri = thumbnail;
|
||||
this.photo = null;
|
||||
this.hasFriends = false;
|
||||
this.address = null;
|
||||
}
|
||||
|
||||
public Contact(String id, String name, Uri photo, Uri thumbnail, Bitmap picture) {
|
||||
|
@ -70,6 +84,7 @@ public class Contact implements Serializable {
|
|||
this.thumbnailUri = thumbnail;
|
||||
this.photo = picture;
|
||||
this.hasFriends = false;
|
||||
this.address = null;
|
||||
}
|
||||
|
||||
|
||||
|
@ -85,6 +100,10 @@ public class Contact implements Serializable {
|
|||
return name;
|
||||
}
|
||||
|
||||
public LinphoneAddress getLinphoneAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public Uri getPhotoUri() {
|
||||
return photoUri;
|
||||
}
|
||||
|
|
|
@ -18,20 +18,32 @@ package org.linphone;
|
|||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.SyncFailedException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.linphone.compatibility.Compatibility;
|
||||
import org.linphone.core.LinphoneProxyConfig;
|
||||
import org.linphone.mediastream.Log;
|
||||
import org.linphone.mediastream.Version;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.ContentProviderOperation;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.BitmapShader;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Shader;
|
||||
import android.media.ExifInterface;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
|
@ -58,7 +70,6 @@ public class ContactEditorFragment extends Fragment {
|
|||
private ImageView addNumber, addSipAddress, contactPicture;
|
||||
private EditText firstName, lastName;
|
||||
private LayoutInflater inflater;
|
||||
private Uri imageToUploadUri;
|
||||
private static final int ADD_PHOTO = 1337;
|
||||
|
||||
private boolean isNewContact = true;
|
||||
|
@ -70,6 +81,11 @@ public class ContactEditorFragment extends Fragment {
|
|||
private LinearLayout sipAddresses, numbers;
|
||||
private String newSipOrNumberToAdd;
|
||||
private ContactsManager contactsManager;
|
||||
private Uri imageToUploadUri;
|
||||
private String fileToUploadPath;
|
||||
private Bitmap imageToUpload;
|
||||
private Bitmap bitmapUnknown;
|
||||
byte[] photoToAdd;
|
||||
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
this.inflater = inflater;
|
||||
|
@ -120,8 +136,10 @@ public class ContactEditorFragment extends Fragment {
|
|||
return;
|
||||
}
|
||||
contactsManager.createNewContact(ops, firstName.getText().toString(), lastName.getText().toString());
|
||||
setContactPhoto();
|
||||
} else {
|
||||
contactsManager.updateExistingContact(ops, contact, firstName.getText().toString(), lastName.getText().toString());
|
||||
setContactPhoto();
|
||||
}
|
||||
|
||||
for (NewOrUpdatedNumberOrAddress numberOrAddress : numbersAndAddresses) {
|
||||
|
@ -257,18 +275,26 @@ public class ContactEditorFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void pickImage() {
|
||||
List<Intent> cameraIntents = new ArrayList<Intent>();
|
||||
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||
File file = new File(Environment.getExternalStorageDirectory(), getString(R.string.temp_photo_name_with_date).replace("%s", String.valueOf(System.currentTimeMillis())));
|
||||
imageToUploadUri = null;
|
||||
final List<Intent> cameraIntents = new ArrayList<Intent>();
|
||||
final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||
File file = new File(Environment.getExternalStorageDirectory(), getString(R.string.temp_photo_name));
|
||||
imageToUploadUri = Uri.fromFile(file);
|
||||
captureIntent.putExtra("crop", "true");
|
||||
captureIntent.putExtra("outputX",256);
|
||||
captureIntent.putExtra("outputY", 256);
|
||||
captureIntent.putExtra("aspectX", 0);
|
||||
captureIntent.putExtra("aspectY", 0);
|
||||
captureIntent.putExtra("scale", true);
|
||||
captureIntent.putExtra("return-data", false);
|
||||
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageToUploadUri);
|
||||
cameraIntents.add(captureIntent);
|
||||
|
||||
Intent galleryIntent = new Intent();
|
||||
final Intent galleryIntent = new Intent();
|
||||
galleryIntent.setType("image/*");
|
||||
galleryIntent.setAction(Intent.ACTION_PICK);
|
||||
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
|
||||
|
||||
Intent chooserIntent = Intent.createChooser(galleryIntent, getString(R.string.image_picker_title));
|
||||
final Intent chooserIntent = Intent.createChooser(galleryIntent, getString(R.string.image_picker_title));
|
||||
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[]{}));
|
||||
|
||||
startActivityForResult(chooserIntent, ADD_PHOTO);
|
||||
|
@ -290,41 +316,151 @@ public class ContactEditorFragment extends Fragment {
|
|||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == ADD_PHOTO && resultCode == Activity.RESULT_OK) {
|
||||
String filePicturePath = null;
|
||||
|
||||
if (data != null && data.getData() != null) {
|
||||
filePicturePath = getRealPathFromURI(data.getData());
|
||||
} else if (imageToUploadUri != null) {
|
||||
filePicturePath = imageToUploadUri.getPath();
|
||||
if (data != null && data.getExtras() != null && data.getExtras().get("data") != null) {
|
||||
Bitmap bm = (Bitmap) data.getExtras().get("data");
|
||||
showPopupMenuAskingImageSize(null, bm);
|
||||
}
|
||||
|
||||
if (filePicturePath != null) {
|
||||
int SIZE_SMALL = 256;
|
||||
int COMPRESSOR_QUALITY = 100;
|
||||
|
||||
/*Bitmap bm = null;
|
||||
|
||||
int pixelsMax = SIZE_SMALL;
|
||||
//Resize image
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inSampleSize = 1;
|
||||
bm = BitmapFactory.decodeFile(filePicturePath,options);
|
||||
if (bm != null) {
|
||||
if (bm.getWidth() > bm.getHeight() && bm.getWidth() > pixelsMax) {
|
||||
bm = Bitmap.createScaledBitmap(bm, 256, 256, false);
|
||||
}
|
||||
}
|
||||
|
||||
ByteArrayOutputStream bstream = new ByteArrayOutputStream();
|
||||
bm.compress(Bitmap.CompressFormat.PNG , 100, bstream);
|
||||
byte[] bArray = bstream.toByteArray();
|
||||
contactPicture.setImageBitmap(bm);*/
|
||||
contactsManager.updateExistingContactPicture(ops, contact, filePicturePath);
|
||||
else if (data != null && data.getData() != null) {
|
||||
Uri selectedImageUri = data.getData();
|
||||
try {
|
||||
Bitmap selectedImage = MediaStore.Images.Media.getBitmap(LinphoneManager.getInstance().getContext().getContentResolver(), selectedImageUri);
|
||||
selectedImage = Bitmap.createScaledBitmap(selectedImage, 256, 256, false);
|
||||
showPopupMenuAskingImageSize(null, selectedImage);
|
||||
} catch (IOException e) { e.printStackTrace(); }
|
||||
}
|
||||
else if (imageToUploadUri != null) {
|
||||
String filePath = imageToUploadUri.getPath();
|
||||
showPopupMenuAskingImageSize(filePath, null);
|
||||
}
|
||||
else {
|
||||
File file = new File(Environment.getExternalStorageDirectory(), getString(R.string.temp_photo_name));
|
||||
if (file.exists()) {
|
||||
imageToUploadUri = Uri.fromFile(file);
|
||||
String filePath = imageToUploadUri.getPath();
|
||||
showPopupMenuAskingImageSize(filePath, null);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
||||
private void showPopupMenuAskingImageSize(final String filePath, final Bitmap image) {
|
||||
fileToUploadPath = filePath;
|
||||
imageToUpload = image;
|
||||
editContactPicture(fileToUploadPath,imageToUpload);
|
||||
}
|
||||
|
||||
private void editContactPicture(final String filePath, final Bitmap image) {
|
||||
int SIZE_SMALL = 256;
|
||||
int COMPRESSOR_QUALITY = 100;
|
||||
Bitmap bitmapUnknown = BitmapFactory.decodeResource(getResources(), R.drawable.avatar);
|
||||
Bitmap bm = null;
|
||||
|
||||
if(filePath != null){
|
||||
int pixelsMax = SIZE_SMALL;
|
||||
//Resize image
|
||||
bm = BitmapFactory.decodeFile(filePath);
|
||||
if (bm != null) {
|
||||
if (bm.getWidth() > bm.getHeight() && bm.getWidth() > pixelsMax) {
|
||||
bm = Bitmap.createScaledBitmap(bm, 256, 256, false);
|
||||
}
|
||||
}
|
||||
} else if (image != null) {
|
||||
bm = image;
|
||||
}
|
||||
|
||||
// Rotate the bitmap if possible/needed, using EXIF data
|
||||
try {
|
||||
if (imageToUploadUri != null && filePath != null) {
|
||||
ExifInterface exif = new ExifInterface(filePath);
|
||||
int pictureOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
|
||||
Matrix matrix = new Matrix();
|
||||
if (pictureOrientation == 6) {
|
||||
matrix.postRotate(90);
|
||||
} else if (pictureOrientation == 3) {
|
||||
matrix.postRotate(180);
|
||||
} else if (pictureOrientation == 8) {
|
||||
matrix.postRotate(270);
|
||||
}
|
||||
bm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Bitmap bitmapRounded;
|
||||
if(bm != null)
|
||||
{
|
||||
bitmapRounded = Bitmap.createScaledBitmap(bm,bitmapUnknown.getWidth(), bitmapUnknown.getWidth(), false);
|
||||
|
||||
Canvas canvas = new Canvas(bitmapRounded);
|
||||
Paint paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
paint.setShader(new BitmapShader(bitmapRounded, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
|
||||
canvas.drawCircle(bitmapRounded.getWidth() / 2+0.7f, bitmapRounded.getHeight() / 2+0.7f,bitmapRounded.getWidth() / 2+0.1f, paint);
|
||||
contactPicture.setImageBitmap(bitmapRounded);
|
||||
|
||||
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
||||
bm.compress(Bitmap.CompressFormat.PNG,COMPRESSOR_QUALITY, outStream);
|
||||
photoToAdd = outStream.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void setContactPhoto(){
|
||||
ContentResolver cr = getActivity().getContentResolver();
|
||||
Uri updateUri = ContactsContract.Data.CONTENT_URI;
|
||||
|
||||
if(photoToAdd != null){
|
||||
//New contact
|
||||
if(isNewContact){
|
||||
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, contactID)
|
||||
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
|
||||
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photoToAdd)
|
||||
.build()
|
||||
);
|
||||
} else { //update contact picture
|
||||
String w = ContactsContract.Data.CONTACT_ID + "='"
|
||||
+ contact.getID() + "' AND "
|
||||
+ ContactsContract.Data.MIMETYPE + " = '"
|
||||
+ ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'";
|
||||
|
||||
Cursor queryCursor = cr.query(updateUri,new String[] { ContactsContract.Data._ID}, w, null, null);
|
||||
if (queryCursor == null) {
|
||||
try {
|
||||
throw new SyncFailedException("EE");
|
||||
} catch (SyncFailedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
if(contact.getPhoto() == null) {
|
||||
String rawContactId = ContactsManager.getInstance().findRawContactID(cr,String.valueOf(contactID));
|
||||
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||
.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactId)
|
||||
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
|
||||
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photoToAdd)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
if (queryCursor.moveToFirst()) { // otherwise no photo
|
||||
int colIdx = queryCursor.getColumnIndex(ContactsContract.Data._ID);
|
||||
long id = queryCursor.getLong(colIdx);
|
||||
|
||||
|
||||
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
||||
.withSelection(ContactsContract.Data._ID + "= ?",new String[] { String.valueOf(id) })
|
||||
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
|
||||
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photoToAdd)
|
||||
.build());
|
||||
}
|
||||
queryCursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private LinearLayout initNumbersFields(final Contact contact) {
|
||||
LinearLayout controls = (LinearLayout) view.findViewById(R.id.controls_numbers);
|
||||
|
|
|
@ -338,15 +338,24 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
|||
if (searchCursor != null) {
|
||||
searchCursor.close();
|
||||
}
|
||||
|
||||
if (onlyDisplayLinphoneContacts) {
|
||||
searchCursor = Compatibility.getSIPContactsCursor(getActivity().getContentResolver(), search, ContactsManager.getInstance().getContactsId());
|
||||
indexer = new AlphabetIndexer(searchCursor, Compatibility.getCursorDisplayNameColumnIndex(searchCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
contactsList.setAdapter(new ContactsListAdapter(null, searchCursor));
|
||||
} else {
|
||||
searchCursor = Compatibility.getContactsCursor(getActivity().getContentResolver(), search, ContactsManager.getInstance().getContactsId());
|
||||
indexer = new AlphabetIndexer(searchCursor, Compatibility.getCursorDisplayNameColumnIndex(searchCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
contactsList.setAdapter(new ContactsListAdapter(null, searchCursor));
|
||||
|
||||
if(LinphoneActivity.instance().getResources().getBoolean(R.bool.use_linphone_friend)) {
|
||||
//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{
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -363,24 +372,30 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
|||
noSipContact.setVisibility(View.GONE);
|
||||
noContact.setVisibility(View.GONE);
|
||||
contactsList.setVisibility(View.VISIBLE);
|
||||
|
||||
if (onlyDisplayLinphoneContacts) {
|
||||
if (sipContactsCursor != null && sipContactsCursor.getCount() == 0) {
|
||||
noSipContact.setVisibility(View.VISIBLE);
|
||||
contactsList.setVisibility(View.GONE);
|
||||
} else {
|
||||
indexer = new AlphabetIndexer(sipContactsCursor, Compatibility.getCursorDisplayNameColumnIndex(sipContactsCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
||||
contactsList.setAdapter(new ContactsListAdapter(ContactsManager.getInstance().getSIPContacts(), sipContactsCursor));
|
||||
}
|
||||
|
||||
if(LinphoneActivity.instance().getResources().getBoolean(R.bool.use_linphone_friend)) {
|
||||
indexer = new AlphabetIndexer(allContactsCursor, Compatibility.getCursorDisplayNameColumnIndex(allContactsCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
||||
contactsList.setAdapter(new ContactsListAdapter(ContactsManager.getInstance().getAllContacts(), allContactsCursor));
|
||||
} else {
|
||||
if (allContactsCursor != null && allContactsCursor.getCount() == 0) {
|
||||
noContact.setVisibility(View.VISIBLE);
|
||||
contactsList.setVisibility(View.GONE);
|
||||
if (onlyDisplayLinphoneContacts) {
|
||||
if (sipContactsCursor != null && sipContactsCursor.getCount() == 0) {
|
||||
noSipContact.setVisibility(View.VISIBLE);
|
||||
contactsList.setVisibility(View.GONE);
|
||||
} else {
|
||||
indexer = new AlphabetIndexer(sipContactsCursor, Compatibility.getCursorDisplayNameColumnIndex(sipContactsCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
||||
contactsList.setAdapter(new ContactsListAdapter(ContactsManager.getInstance().getSIPContacts(), sipContactsCursor));
|
||||
}
|
||||
} else {
|
||||
indexer = new AlphabetIndexer(allContactsCursor, Compatibility.getCursorDisplayNameColumnIndex(allContactsCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
||||
contactsList.setAdapter(new ContactsListAdapter(ContactsManager.getInstance().getAllContacts(), allContactsCursor));
|
||||
if (allContactsCursor != null && allContactsCursor.getCount() == 0) {
|
||||
noContact.setVisibility(View.VISIBLE);
|
||||
contactsList.setVisibility(View.GONE);
|
||||
} else {
|
||||
indexer = new AlphabetIndexer(allContactsCursor, Compatibility.getCursorDisplayNameColumnIndex(allContactsCursor), " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
||||
contactsList.setAdapter(new ContactsListAdapter(ContactsManager.getInstance().getAllContacts(), allContactsCursor));
|
||||
}
|
||||
}
|
||||
}
|
||||
ContactsManager.getInstance().setLinphoneContactsPrefered(onlyDisplayLinphoneContacts);
|
||||
|
@ -460,7 +475,11 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
|||
}
|
||||
|
||||
public int getCount() {
|
||||
return cursor.getCount();
|
||||
if(LinphoneActivity.instance().getResources().getBoolean(R.bool.use_linphone_friend)) {
|
||||
return LinphoneManager.getLc().getFriendList().length;
|
||||
} else {
|
||||
return cursor.getCount();
|
||||
}
|
||||
}
|
||||
|
||||
public Object getItem(int position) {
|
||||
|
|
|
@ -24,6 +24,7 @@ import android.content.ContentProviderOperation;
|
|||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.MatrixCursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.ContactsContract;
|
||||
|
||||
|
@ -37,7 +38,9 @@ import org.linphone.core.LinphoneProxyConfig;
|
|||
import org.linphone.mediastream.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ContactsManager {
|
||||
private static ContactsManager instance;
|
||||
|
@ -103,7 +106,6 @@ public class ContactsManager {
|
|||
mAccount = null;
|
||||
}
|
||||
} else {
|
||||
Log.w("Get Account");
|
||||
mAccount = accounts[0];
|
||||
}
|
||||
initializeContactManager(context,contentResolver);
|
||||
|
@ -374,8 +376,6 @@ public class ContactsManager {
|
|||
|
||||
for(Contact c: getAllContacts()){
|
||||
for(String a: c.getNumbersOrAddresses()){
|
||||
Log.w(a);
|
||||
Log.w(address.asStringUriOnly());
|
||||
if(a.equals(sipUri))
|
||||
return c;
|
||||
}
|
||||
|
@ -563,6 +563,18 @@ public class ContactsManager {
|
|||
sipContactCursor.close();
|
||||
}
|
||||
|
||||
if(LinphoneActivity.instance().getResources().getBoolean(R.bool.use_linphone_friend)){
|
||||
contactList = new ArrayList<Contact>();
|
||||
for(LinphoneFriend friend : LinphoneManager.getLc().getFriendList()){
|
||||
Contact contact = new Contact(friend.getRefKey(),friend.getAddress());
|
||||
contactList.add(contact);
|
||||
}
|
||||
|
||||
contactCursor = getFriendListCursor(contactList,true);
|
||||
Log.w(contactCursor.getCount());
|
||||
return;
|
||||
}
|
||||
|
||||
if(mAccount == null) return;
|
||||
|
||||
contactCursor = Compatibility.getContactsCursor(contentResolver, getContactsId());
|
||||
|
@ -667,4 +679,29 @@ public class ContactsManager {
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,206 +0,0 @@
|
|||
/*
|
||||
IncomingCallActivity.java
|
||||
Copyright (C) 2011 Belledonne Communications, Grenoble, France
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
package org.linphone;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.linphone.core.LinphoneAddress;
|
||||
import org.linphone.core.LinphoneCall;
|
||||
import org.linphone.core.LinphoneCall.State;
|
||||
import org.linphone.core.LinphoneCallParams;
|
||||
import org.linphone.core.LinphoneCore;
|
||||
import org.linphone.core.LinphoneCoreListenerBase;
|
||||
import org.linphone.mediastream.Log;
|
||||
import org.linphone.ui.AvatarWithShadow;
|
||||
import org.linphone.ui.LinphoneSliders;
|
||||
import org.linphone.ui.LinphoneSliders.LinphoneSliderTriggered;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* Activity displayed when a call comes in.
|
||||
* It should bypass the screen lock mechanism.
|
||||
*
|
||||
* @author Guillaume Beraudo
|
||||
*/
|
||||
public class IncomingCallActivity extends Activity implements LinphoneSliderTriggered {
|
||||
|
||||
private static IncomingCallActivity instance;
|
||||
|
||||
private TextView mNameView;
|
||||
private TextView mNumberView;
|
||||
private AvatarWithShadow mPictureView;
|
||||
private LinphoneCall mCall;
|
||||
private LinphoneSliders mIncomingCallWidget;
|
||||
private LinphoneCoreListenerBase mListener;
|
||||
|
||||
public static IncomingCallActivity instance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static boolean isInstanciated() {
|
||||
return instance != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
setContentView(R.layout.incoming);
|
||||
|
||||
mNameView = (TextView) findViewById(R.id.incoming_caller_name);
|
||||
mNumberView = (TextView) findViewById(R.id.incoming_caller_number);
|
||||
mPictureView = (AvatarWithShadow) findViewById(R.id.incoming_picture);
|
||||
|
||||
// set this flag so this activity will stay in front of the keyguard
|
||||
int flags = WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
|
||||
getWindow().addFlags(flags);
|
||||
|
||||
// "Dial-to-answer" widget for incoming calls.
|
||||
mIncomingCallWidget = (LinphoneSliders) findViewById(R.id.sliding_widget);
|
||||
mIncomingCallWidget.setOnTriggerListener(this);
|
||||
|
||||
mListener = new LinphoneCoreListenerBase(){
|
||||
@Override
|
||||
public void callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State state, String message) {
|
||||
if (call == mCall && State.CallEnd == state) {
|
||||
finish();
|
||||
}
|
||||
if (state == State.StreamsRunning) {
|
||||
// The following should not be needed except some devices need it (e.g. Galaxy S).
|
||||
LinphoneManager.getLc().enableSpeaker(LinphoneManager.getLc().isSpeakerEnabled());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
instance = this;
|
||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||
if (lc != null) {
|
||||
lc.addListener(mListener);
|
||||
}
|
||||
|
||||
// Only one call ringing at a time is allowed
|
||||
if (LinphoneManager.getLcIfManagerNotDestroyedOrNull() != null) {
|
||||
List<LinphoneCall> calls = LinphoneUtils.getLinphoneCalls(LinphoneManager.getLc());
|
||||
for (LinphoneCall call : calls) {
|
||||
if (State.IncomingReceived == call.getState()) {
|
||||
mCall = call;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mCall == null) {
|
||||
Log.e("Couldn't find incoming call");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
LinphoneAddress address = mCall.getRemoteAddress();
|
||||
// May be greatly sped up using a drawable cache
|
||||
Contact contact = ContactsManager.getInstance().findContactWithAddress(getContentResolver(), address);
|
||||
LinphoneUtils.setImagePictureFromUri(this, mPictureView.getView(), contact != null ? contact.getPhotoUri() : null,
|
||||
contact != null ? contact.getThumbnailUri() : null, R.drawable.unknown_small);
|
||||
|
||||
// To be done after findUriPictureOfContactAndSetDisplayName called
|
||||
mNameView.setText(contact != null ? contact.getName() : "");
|
||||
if (getResources().getBoolean(R.bool.only_display_username_if_unknown)) {
|
||||
mNumberView.setText(address.getUserName());
|
||||
} else {
|
||||
mNumberView.setText(address.asStringUriOnly());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||
if (lc != null) {
|
||||
lc.removeListener(mListener);
|
||||
}
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
instance = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (LinphoneManager.isInstanciated() && (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_HOME)) {
|
||||
LinphoneManager.getLc().terminateCall(mCall);
|
||||
finish();
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void decline() {
|
||||
LinphoneManager.getLc().terminateCall(mCall);
|
||||
}
|
||||
|
||||
private void answer() {
|
||||
LinphoneCallParams params = LinphoneManager.getLc().createCallParams(mCall);
|
||||
|
||||
boolean isLowBandwidthConnection = !LinphoneUtils.isHighBandwidthConnection(this);
|
||||
if (isLowBandwidthConnection) {
|
||||
params.enableLowBandwidth(true);
|
||||
Log.d("Low bandwidth enabled in call params");
|
||||
}
|
||||
|
||||
if (!LinphoneManager.getInstance().acceptCallWithParams(mCall, params)) {
|
||||
// the above method takes care of Samsung Galaxy S
|
||||
Toast.makeText(this, R.string.couldnt_accept_call, Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
if (!LinphoneActivity.isInstanciated()) {
|
||||
return;
|
||||
}
|
||||
final LinphoneCallParams remoteParams = mCall.getRemoteParams();
|
||||
if (remoteParams != null && remoteParams.getVideoEnabled() && LinphonePreferences.instance().shouldAutomaticallyAcceptVideoRequests()) {
|
||||
LinphoneActivity.instance().startVideoActivity(mCall);
|
||||
} else {
|
||||
LinphoneActivity.instance().startIncallActivity(mCall);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLeftHandleTriggered() {
|
||||
answer();
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRightHandleTriggered() {
|
||||
decline();
|
||||
finish();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue