diff options
author | Chiao Cheng <chiaocheng@google.com> | 2013-09-03 17:00:23 -0700 |
---|---|---|
committer | Chiao Cheng <chiaocheng@google.com> | 2013-09-03 17:00:23 -0700 |
commit | 7d2fb8620b808c28c49bde99dc54f6de46fdcb44 (patch) | |
tree | c5a0b04c8b456c76f2b76dd6772685aebf240eb7 | |
parent | c6d8461a2b7f0684a1246ba36b3da5638cfada37 (diff) |
Fix incall image for local contacts.
The contact info callback was being called back at a minimum of two times. Once
for the name and text data and a second time for the photo. The results of the
first call triggers reverse lookups and was causing it to trigger twice. To fix
it for both cases, break out the callback into two separate calls to the client
can properly handle the cases differently.
Bug: 10607629
Change-Id: I2e0754d2d7c46bc2797a1a672827bd2f8d56e5d8
4 files changed, 46 insertions, 7 deletions
diff --git a/InCallUI/src/com/android/incallui/CallCardFragment.java b/InCallUI/src/com/android/incallui/CallCardFragment.java index 60090365f..bf3c42c73 100644 --- a/InCallUI/src/com/android/incallui/CallCardFragment.java +++ b/InCallUI/src/com/android/incallui/CallCardFragment.java @@ -215,6 +215,13 @@ public class CallCardFragment extends BaseFragment<CallCardPresenter, CallCardPr } @Override + public void setSecondaryImage(Bitmap bitmap) { + if (bitmap != null) { + setDrawableToImageView(mSecondaryPhoto, new BitmapDrawable(getResources(), bitmap)); + } + } + + @Override public void setCallState(int state, Call.DisconnectCause cause, boolean bluetoothOn) { String callStateLabel = null; diff --git a/InCallUI/src/com/android/incallui/CallCardPresenter.java b/InCallUI/src/com/android/incallui/CallCardPresenter.java index a0ad3ce88..5b6520d7c 100644 --- a/InCallUI/src/com/android/incallui/CallCardPresenter.java +++ b/InCallUI/src/com/android/incallui/CallCardPresenter.java @@ -259,6 +259,16 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi> updateContactEntry(entry, isPrimary, isConference); } } + + @Override + public void onImageLoadComplete(int callId, Bitmap photo) { + if (callId == mPrimary.getCallId()) { + getUi().setPrimaryImage(photo); + } else if (callId == mSecondary.getCallId()) { + getUi().setSecondaryImage(photo); + } + + } }); } else { Log.d(TAG, "Contact lookup. Found in memory cache: " + entry); @@ -481,6 +491,7 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi> void setPrimary(String number, String name, boolean nameIsNumber, String label, Drawable photo, boolean isConference, String gatewayLabel, String gatewayNumber); void setSecondary(boolean show, String name, String label, Drawable photo); + void setSecondaryImage(Bitmap bitmap); void setCallState(int state, Call.DisconnectCause cause, boolean bluetoothOn); void setPrimaryCallElapsedTime(boolean show, String duration); diff --git a/InCallUI/src/com/android/incallui/ContactInfoCache.java b/InCallUI/src/com/android/incallui/ContactInfoCache.java index 079679478..aa96a9096 100644 --- a/InCallUI/src/com/android/incallui/ContactInfoCache.java +++ b/InCallUI/src/com/android/incallui/ContactInfoCache.java @@ -174,7 +174,22 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete entry.photo = null; } - sendNotification(callId, entry); + final List<ContactInfoCacheCallback> callBacks; + synchronized (mCallBackLock) { + callBacks = mCallBacksGuarded.get(callId); + // Do not clear mInfoMap here because we still need the data. + mCallBacksGuarded.clear(); + } + if (callBacks != null) { + for (ContactInfoCacheCallback callBack : callBacks) { + if (entry.photo == null) { + callBack.onImageLoadComplete(callId, null); + } else { + callBack.onImageLoadComplete(callId, ((BitmapDrawable) entry.photo) + .getBitmap()); + } + } + } } /** @@ -342,12 +357,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete * Sends the updated information to call the callbacks for the entry. */ private void sendNotification(int callId, ContactCacheEntry entry) { - final List<ContactInfoCacheCallback> callBacks; - synchronized (mCallBackLock) { - callBacks = mCallBacksGuarded.get(callId); - // Do not clear mInfoMap here because we still need the data. - mCallBacksGuarded.clear(); - } + final List<ContactInfoCacheCallback> callBacks = mCallBacksGuarded.get(callId);; if (callBacks != null) { for (ContactInfoCacheCallback callBack : callBacks) { callBack.onContactInfoComplete(callId, entry); @@ -373,6 +383,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete */ public interface ContactInfoCacheCallback { public void onContactInfoComplete(int callId, ContactCacheEntry entry); + public void onImageLoadComplete(int callId, Bitmap photo); } public static class ContactCacheEntry { diff --git a/InCallUI/src/com/android/incallui/StatusBarNotifier.java b/InCallUI/src/com/android/incallui/StatusBarNotifier.java index 658eac950..ecdf53238 100644 --- a/InCallUI/src/com/android/incallui/StatusBarNotifier.java +++ b/InCallUI/src/com/android/incallui/StatusBarNotifier.java @@ -26,6 +26,7 @@ import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; import android.text.TextUtils; import com.android.incallui.ContactInfoCache.ContactCacheEntry; @@ -93,10 +94,19 @@ public class StatusBarNotifier implements InCallPresenter.InCallStateListener, // it has available, and may make a subsequent call later (same thread) if it had to // call into the contacts provider for more data. mContactInfoCache.findInfo(call.getIdentification(), true, new ContactInfoCacheCallback() { + private ContactCacheEntry mEntry; + @Override public void onContactInfoComplete(int callId, ContactCacheEntry entry) { + mEntry = entry; buildAndSendNotification(InCallState.INCOMING, call, entry, false); } + + @Override + public void onImageLoadComplete(int callId, Bitmap photo) { + mEntry.photo = new BitmapDrawable(mContext.getResources(), photo); + buildAndSendNotification(InCallState.INCOMING, call, mEntry, false); + } }); } |