First step to remove legacy ContactHelper class
This commit is contained in:
parent
cd098600f7
commit
dd85cada65
4 changed files with 73 additions and 10 deletions
|
@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License
|
|||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
import org.linphone.compatibility.Compatibility;
|
||||
import org.linphone.ui.AddressAware;
|
||||
import org.linphone.ui.AddressText;
|
||||
import org.linphone.ui.CallButton;
|
||||
|
@ -70,7 +71,7 @@ public class DialerFragment extends Fragment {
|
|||
addContactListener = new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = ContactHelper.prepareAddContactIntent(mAddress);
|
||||
Intent intent = Compatibility.prepareAddContactIntent(mAddress.getDisplayedName(), mAddress.getText().toString());
|
||||
startActivity(intent);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -115,18 +115,16 @@ public final class LinphoneUtils {
|
|||
* @param contact sip uri
|
||||
* @return url/uri of the resource
|
||||
*/
|
||||
// public static Uri findUriPictureOfContactAndSetDisplayName(LinphoneAddress address, ContentResolver resolver) {
|
||||
// return Compatibility.findUriPictureOfContactAndSetDisplayName(address, resolver);
|
||||
// }
|
||||
|
||||
public static Uri findUriPictureOfContactAndSetDisplayName(LinphoneAddress address, ContentResolver resolver) {
|
||||
ContactHelper helper = new ContactHelper(address, resolver);
|
||||
helper.query();
|
||||
return helper.getUri();
|
||||
}
|
||||
|
||||
public static String findDisplayNameOfContact(LinphoneAddress address, ContentResolver resolver) {
|
||||
ContactHelper helper = new ContactHelper(address, resolver);
|
||||
helper.query();
|
||||
return helper.getDisplayName();
|
||||
}
|
||||
|
||||
public static Bitmap downloadBitmap(Uri uri) {
|
||||
URL url;
|
||||
InputStream is = null;
|
||||
|
|
|
@ -7,6 +7,8 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
import org.linphone.Contact;
|
||||
import org.linphone.core.LinphoneAddress;
|
||||
import org.linphone.core.Log;
|
||||
import org.linphone.mediastream.Version;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
|
@ -74,6 +76,14 @@ public class ApiFivePlus {
|
|||
return intent;
|
||||
}
|
||||
|
||||
public static Intent prepareEditContactIntent(int id) {
|
||||
Intent intent = new Intent(Intent.ACTION_EDIT, Contacts.CONTENT_URI);
|
||||
Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, id);
|
||||
intent.setData(contactUri);
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
||||
public static List<String> extractContactNumbersAndAddresses(String id, ContentResolver cr) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
|
||||
|
@ -140,7 +150,7 @@ public class ApiFivePlus {
|
|||
+ " AND lower(" + CommonDataKinds.Im.CUSTOM_PROTOCOL + ") = 'sip')";
|
||||
}
|
||||
|
||||
return getGeneralContactCursor(cr, req);
|
||||
return getGeneralContactCursor(cr, req, true);
|
||||
}
|
||||
|
||||
public static Cursor getSIPContactsCursor(ContentResolver cr) {
|
||||
|
@ -153,16 +163,34 @@ public class ApiFivePlus {
|
|||
+ " AND lower(" + CommonDataKinds.Im.CUSTOM_PROTOCOL + ") = 'sip'";
|
||||
}
|
||||
|
||||
return getGeneralContactCursor(cr, req);
|
||||
return getGeneralContactCursor(cr, req, true);
|
||||
}
|
||||
|
||||
private static Cursor getGeneralContactCursor(ContentResolver cr, String select) {
|
||||
private static Cursor getSIPContactCursor(ContentResolver cr, String id) {
|
||||
String req = null;
|
||||
if (Version.sdkAboveOrEqual(Version.API09_GINGERBREAD_23)) {
|
||||
req = Data.MIMETYPE + " = '" + CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE
|
||||
+ "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + " LIKE '" + id + "'";
|
||||
} else {
|
||||
req = Contacts.Data.MIMETYPE + " = '" + CommonDataKinds.Im.CONTENT_ITEM_TYPE
|
||||
+ " AND lower(" + CommonDataKinds.Im.CUSTOM_PROTOCOL + ") = 'sip' AND "
|
||||
+ android.provider.ContactsContract.CommonDataKinds.Im.DATA + " LIKE '" + id + "'";
|
||||
}
|
||||
|
||||
return getGeneralContactCursor(cr, req, false);
|
||||
}
|
||||
|
||||
private static Cursor getGeneralContactCursor(ContentResolver cr, String select, boolean shouldGroupBy) {
|
||||
|
||||
String[] projection = new String[] { Data.CONTACT_ID, Data.DISPLAY_NAME };
|
||||
|
||||
String query = Data.DISPLAY_NAME + " IS NOT NULL AND (" + select + ")";
|
||||
Cursor cursor = cr.query(Data.CONTENT_URI, projection, query, null, Data.DISPLAY_NAME + " ASC");
|
||||
|
||||
if (!shouldGroupBy) {
|
||||
return cursor;
|
||||
}
|
||||
|
||||
MatrixCursor result = new MatrixCursor(cursor.getColumnNames());
|
||||
Set<String> groupBy = new HashSet<String>();
|
||||
while (cursor.moveToNext()) {
|
||||
|
@ -228,4 +256,20 @@ public class ApiFivePlus {
|
|||
private static Uri getContactPictureUri(String id) {
|
||||
return ContentUris.withAppendedId(Contacts.CONTENT_URI, Long.parseLong(id));
|
||||
}
|
||||
|
||||
public static Uri findUriPictureOfContactAndSetDisplayName(LinphoneAddress address, ContentResolver cr) {
|
||||
String username = address.getUserName();
|
||||
String domain = address.getDomain();
|
||||
String sipUri = username + "@" + domain;
|
||||
Log.e("Looking for " + sipUri);
|
||||
|
||||
Cursor cursor = getSIPContactCursor(cr, sipUri);
|
||||
Contact contact = getContact(cr, cursor, 0);
|
||||
if (contact != null && contact.getNumerosOrAddresses().contains(sipUri)) {
|
||||
address.setDisplayName(contact.getName());
|
||||
return contact.getPhotoUri();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,12 +21,14 @@ import java.io.InputStream;
|
|||
import java.util.List;
|
||||
|
||||
import org.linphone.Contact;
|
||||
import org.linphone.core.LinphoneAddress;
|
||||
import org.linphone.mediastream.Version;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
/**
|
||||
* @author Sylvain Berfini
|
||||
*/
|
||||
|
@ -46,6 +48,15 @@ public class Compatibility {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static Intent prepareEditContactIntent(int id) {
|
||||
if (Version.sdkAboveOrEqual(5)) {
|
||||
return ApiFivePlus.prepareEditContactIntent(id);
|
||||
} else {
|
||||
//TODO
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<String> extractContactNumbersAndAddresses(String id, ContentResolver cr) {
|
||||
if (Version.sdkAboveOrEqual(5)) {
|
||||
return ApiFivePlus.extractContactNumbersAndAddresses(id, cr);
|
||||
|
@ -99,4 +110,13 @@ public class Compatibility {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Uri findUriPictureOfContactAndSetDisplayName(LinphoneAddress address, ContentResolver cr) {
|
||||
if (Version.sdkAboveOrEqual(5)) {
|
||||
return ApiFivePlus.findUriPictureOfContactAndSetDisplayName(address, cr);
|
||||
} else {
|
||||
//TODO
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue