public Task <AndroidPerson> GetAndroidPersonDetail() { if (androidPerson != null) { return(androidPerson.Task); } if (parseData == null) { throw new NoParseDataException("TabPerson"); } androidPerson = new TaskCompletionSource <AndroidPerson> (); if (temporaryAndroidPersons.ContainsKey(parseData.ObjectId)) { androidPerson.TrySetResult(temporaryAndroidPersons[parseData.ObjectId]); return(androidPerson.Task); } var query = GetAndroidPersonQuery(); query.GetFirstInBackground(new TabGetCallback((o, e) => { var ap = new AndroidPerson(o); androidPerson.TrySetResult(ap); // Protect against faulty Parse cache if (o == null) { temporaryAndroidPersons[parseData.ObjectId] = ap; } })); return(androidPerson.Task); }
Bitmap GetPersonPicture(AndroidPerson androidDetails) { if (string.IsNullOrEmpty(androidDetails.LookupID)) { return(null); } Bitmap bmp = null; if (faceCache.TryGet(androidDetails.LookupID, out bmp)) { return(bmp); } var lookupUri = AUri.WithAppendedPath(AUri.WithAppendedPath(ContactsContract.Contacts.ContentLookupUri, androidDetails.LookupID), androidDetails.ContactID); var contactUri = ContactsContract.Contacts.LookupContact(activity.ContentResolver, lookupUri); if (contactUri == null) { return(null); } var photo = ContactsContract.Contacts.OpenContactPhotoInputStream(activity.ContentResolver, contactUri, true); if (photo == null) { return(null); } bmp = Bitmap.CreateScaledBitmap(BitmapFactory.DecodeStream(photo), 64.ToPixels (), 64.ToPixels (), true); faceCache.AddOrUpdate(androidDetails.LookupID, bmp, TimeSpan.FromDays(1)); return(bmp); }
Bitmap GetPersonPicture(AndroidPerson androidDetails) { if (string.IsNullOrEmpty (androidDetails.LookupID)) return null; Bitmap bmp = null; if (faceCache.TryGet (androidDetails.LookupID, out bmp)) return bmp; var lookupUri = AUri.WithAppendedPath (AUri.WithAppendedPath (ContactsContract.Contacts.ContentLookupUri, androidDetails.LookupID), androidDetails.ContactID); var contactUri = ContactsContract.Contacts.LookupContact (activity.ContentResolver, lookupUri); if (contactUri == null) return null; var photo = ContactsContract.Contacts.OpenContactPhotoInputStream (activity.ContentResolver, contactUri, true); if (photo == null) return null; bmp = Bitmap.CreateScaledBitmap (BitmapFactory.DecodeStream (photo), 64.ToPixels (), 64.ToPixels (), true); faceCache.AddOrUpdate (androidDetails.LookupID, bmp, TimeSpan.FromDays (1)); return bmp; }