Merge pull request #1193 from adithyaphilip/auto-refresh-contacts
Immediate display of contact card, fixed contact picture display issue, hides card if no contact
This commit is contained in:
@@ -220,15 +220,14 @@ public class ContactHelper {
|
||||
*/
|
||||
public static long getMainProfileContactId(ContentResolver resolver) {
|
||||
Cursor profileCursor = resolver.query(ContactsContract.Profile.CONTENT_URI,
|
||||
new String[]{ ContactsContract.Profile._ID}, null, null, null);
|
||||
new String[]{ContactsContract.Profile._ID}, null, null, null);
|
||||
|
||||
if(profileCursor != null && profileCursor.getCount() != 0 && profileCursor.moveToNext()) {
|
||||
if (profileCursor != null && profileCursor.getCount() != 0 && profileCursor.moveToNext()) {
|
||||
long contactId = profileCursor.getLong(0);
|
||||
profileCursor.close();
|
||||
return contactId;
|
||||
}
|
||||
else {
|
||||
if(profileCursor != null) {
|
||||
} else {
|
||||
if (profileCursor != null) {
|
||||
profileCursor.close();
|
||||
}
|
||||
return -1;
|
||||
@@ -330,7 +329,9 @@ public class ContactHelper {
|
||||
ContactsContract.RawContacts.SOURCE_ID + "=? AND " +
|
||||
ContactsContract.RawContacts.DELETED + "=?",
|
||||
new String[]{//"0" for "not deleted"
|
||||
Constants.ACCOUNT_TYPE, Long.toString(masterKeyId), "0"
|
||||
Constants.ACCOUNT_TYPE,
|
||||
Long.toString(masterKeyId),
|
||||
"0"
|
||||
}, null);
|
||||
if (raw != null) {
|
||||
if (raw.moveToNext()) {
|
||||
@@ -385,23 +386,37 @@ public class ContactHelper {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
long rawContactId = findRawContactId(contentResolver, masterKeyId);
|
||||
if (rawContactId == -1) {
|
||||
return null;
|
||||
}
|
||||
Uri rawContactUri = ContentUris.withAppendedId(ContactsContract.RawContacts.CONTENT_URI, rawContactId);
|
||||
Uri contactUri = ContactsContract.RawContacts.getContactLookupUri(contentResolver, rawContactUri);
|
||||
InputStream photoInputStream =
|
||||
ContactsContract.Contacts.openContactPhotoInputStream(contentResolver, contactUri, highRes);
|
||||
if (photoInputStream == null) {
|
||||
return null;
|
||||
}
|
||||
return BitmapFactory.decodeStream(photoInputStream);
|
||||
long contactId = findContactId(contentResolver, masterKeyId);
|
||||
return loadPhotoByContactId(contentResolver, contactId, highRes);
|
||||
|
||||
} catch (Throwable ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Bitmap loadPhotoByContactId(ContentResolver contentResolver, long contactId,
|
||||
boolean highRes) {
|
||||
if (contactId == -1) {
|
||||
return null;
|
||||
}
|
||||
Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId);
|
||||
// older android versions (tested on API level 15) fail on lookupuris being passed to
|
||||
// openContactPhotoInputStream
|
||||
// http://stackoverflow.com/a/21214524/3000919
|
||||
// Uri lookupUri = ContactsContract.Contacts.getLookupUri(contentResolver, contactUri);
|
||||
// Also, we don't need a permanent shortcut to the contact since we load it afresh each time
|
||||
|
||||
InputStream photoInputStream = ContactsContract.Contacts.openContactPhotoInputStream(
|
||||
contentResolver,
|
||||
contactUri,
|
||||
highRes);
|
||||
|
||||
if (photoInputStream == null) {
|
||||
return null;
|
||||
}
|
||||
return BitmapFactory.decodeStream(photoInputStream);
|
||||
}
|
||||
|
||||
public static final String[] KEYS_TO_CONTACT_PROJECTION = new String[]{
|
||||
KeychainContract.KeyRings.MASTER_KEY_ID,
|
||||
KeychainContract.KeyRings.USER_ID,
|
||||
|
||||
Reference in New Issue
Block a user