summaryrefslogtreecommitdiff
path: root/InCallUI/src
diff options
context:
space:
mode:
authorBrandon Maxwell <maxwelb@google.com>2015-10-30 17:03:38 -0700
committerBrandon Maxwell <maxwelb@google.com>2015-11-03 12:50:11 -0800
commit8c03464c2c348af3bcd3bdfb911cd1bf17a760d0 (patch)
treeae3ec01aeda2ed8ac059f0dc3d20e94d0df99ac2 /InCallUI/src
parentb121fac65ada38d92ac8dca298eadde163f443fb (diff)
Updating InCallUI to respect name display and sort preferences
+ CallCardPresenter, StatusBarNotifier, ConferenceParticipantListAdapter respect display name preferences + ConferenceParticipantListAdapter sorts names in conference call based on sort order preference ~ Still need to populate data objects with real data, currently it's just stubbed Bug: 19364093 Change-Id: I77ad9cb063bf439ae7e5551e40946ea29e414b7f
Diffstat (limited to 'InCallUI/src')
-rw-r--r--InCallUI/src/com/android/incallui/CallCardPresenter.java39
-rw-r--r--InCallUI/src/com/android/incallui/CallerInfo.java11
-rw-r--r--InCallUI/src/com/android/incallui/ConferenceParticipantListAdapter.java49
-rw-r--r--InCallUI/src/com/android/incallui/ContactInfoCache.java27
-rw-r--r--InCallUI/src/com/android/incallui/StatusBarNotifier.java16
-rw-r--r--InCallUI/src/com/android/incallui/VideoCallPresenter.java8
6 files changed, 93 insertions, 57 deletions
diff --git a/InCallUI/src/com/android/incallui/CallCardPresenter.java b/InCallUI/src/com/android/incallui/CallCardPresenter.java
index e7d6f0c3e..28311c9d6 100644
--- a/InCallUI/src/com/android/incallui/CallCardPresenter.java
+++ b/InCallUI/src/com/android/incallui/CallCardPresenter.java
@@ -16,15 +16,14 @@
package com.android.incallui;
+import com.google.common.base.Preconditions;
+
import android.Manifest;
-import android.app.Activity;
-import android.app.FragmentManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
-import android.location.Address;
import android.net.Uri;
import android.os.Bundle;
import android.telecom.Call.Details;
@@ -40,9 +39,9 @@ import android.view.View;
import android.view.accessibility.AccessibilityManager;
import android.widget.ListAdapter;
-import com.android.incallui.Call.LogState;
+import com.android.contacts.common.preference.ContactsPreferences;
+import com.android.contacts.common.util.ContactDisplayUtils;
import com.android.incallui.Call.State;
-import com.android.incallui.InCallContactInteractions.ContactContextInfo;
import com.android.incallui.ContactInfoCache.ContactCacheEntry;
import com.android.incallui.ContactInfoCache.ContactInfoCacheCallback;
import com.android.incallui.InCallPresenter.InCallDetailsListener;
@@ -52,11 +51,7 @@ import com.android.incallui.InCallPresenter.InCallStateListener;
import com.android.incallui.InCallPresenter.IncomingCallListener;
import com.android.incalluibind.ObjectFactory;
-import java.io.IOException;
import java.lang.ref.WeakReference;
-import java.util.List;
-
-import com.google.common.base.Preconditions;
/**
* Presenter for the Call Card Fragment.
@@ -84,6 +79,7 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi>
private ContactCacheEntry mSecondaryContactInfo;
private CallTimer mCallTimer;
private Context mContext;
+ private ContactsPreferences mContactsPreferences;
private boolean mSpinnerShowing = false;
private boolean mHasShownToast = false;
private InCallContactInteractions mInCallContactInteractions;
@@ -135,6 +131,7 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi>
public void init(Context context, Call call) {
mContext = Preconditions.checkNotNull(context);
mDistanceHelper = ObjectFactory.newDistanceHelper(mContext, this);
+ mContactsPreferences = new ContactsPreferences(mContext);
// Call may be null if disconnect happened already.
if (call != null) {
@@ -162,6 +159,10 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi>
public void onUiReady(CallCardUi ui) {
super.onUiReady(ui);
+ if (mContactsPreferences != null) {
+ mContactsPreferences.refreshValue(ContactsPreferences.DISPLAY_ORDER_KEY);
+ }
+
// Contact search may have completed before ui is ready.
if (mPrimaryContactInfo != null) {
updatePrimaryDisplayInfo();
@@ -549,9 +550,6 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi>
Log.w(this, "Dropping stale contact lookup info for " + callId);
}
- if (entry.name != null) {
- Log.d(TAG, "Contact found: " + entry);
- }
final Call call = CallList.getInstance().getCallById(callId);
if (call != null) {
call.getLogState().contactLookupResult = entry.contactLookupResult;
@@ -896,20 +894,27 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi>
/**
* Gets the name to display for the call.
*/
- private static String getNameForCall(ContactCacheEntry contactInfo) {
- if (TextUtils.isEmpty(contactInfo.name)) {
+ private String getNameForCall(ContactCacheEntry contactInfo) {
+ String preferredName = ContactDisplayUtils.getPreferredDisplayName(
+ contactInfo.namePrimary,
+ contactInfo.nameAlternative,
+ mContactsPreferences.getDisplayOrder());
+ if (TextUtils.isEmpty(preferredName)) {
return contactInfo.number;
}
- return contactInfo.name;
+ return preferredName;
}
/**
* Gets the number to display for a call.
*/
- private static String getNumberForCall(ContactCacheEntry contactInfo) {
+ private String getNumberForCall(ContactCacheEntry contactInfo) {
// If the name is empty, we use the number for the name...so dont show a second
// number in the number field
- if (TextUtils.isEmpty(contactInfo.name)) {
+ if (TextUtils.isEmpty(ContactDisplayUtils.getPreferredDisplayName(
+ contactInfo.namePrimary,
+ contactInfo.nameAlternative,
+ mContactsPreferences.getDisplayOrder()))) {
return contactInfo.location;
}
return contactInfo.number;
diff --git a/InCallUI/src/com/android/incallui/CallerInfo.java b/InCallUI/src/com/android/incallui/CallerInfo.java
index 06703b93d..3ddeb71b1 100644
--- a/InCallUI/src/com/android/incallui/CallerInfo.java
+++ b/InCallUI/src/com/android/incallui/CallerInfo.java
@@ -16,8 +16,6 @@
package com.android.incallui;
-import com.android.contacts.common.util.PhoneNumberHelper;
-import com.android.contacts.common.util.TelephonyManagerUtils;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
@@ -31,12 +29,8 @@ import android.provider.ContactsContract.RawContacts;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
-import com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder;
-import com.google.i18n.phonenumbers.NumberParseException;
-import com.google.i18n.phonenumbers.PhoneNumberUtil;
-import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
-
-import java.util.Locale;
+import com.android.contacts.common.util.PhoneNumberHelper;
+import com.android.contacts.common.util.TelephonyManagerUtils;
/**
* Looks up caller information for the given phone number.
@@ -72,6 +66,7 @@ public class CallerInfo {
* for a connection, but the number should be displayable.
*/
public String name;
+ public String nameAlternative;
public String phoneNumber;
public String normalizedNumber;
public String forwardingNumber;
diff --git a/InCallUI/src/com/android/incallui/ConferenceParticipantListAdapter.java b/InCallUI/src/com/android/incallui/ConferenceParticipantListAdapter.java
index a0588a11e..a595c43ef 100644
--- a/InCallUI/src/com/android/incallui/ConferenceParticipantListAdapter.java
+++ b/InCallUI/src/com/android/incallui/ConferenceParticipantListAdapter.java
@@ -16,6 +16,8 @@
package com.android.incallui;
+import com.google.common.base.MoreObjects;
+
import android.content.Context;
import android.net.Uri;
import android.telephony.PhoneNumberUtils;
@@ -32,6 +34,8 @@ import android.widget.TextView;
import com.android.contacts.common.ContactPhotoManager;
import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest;
+import com.android.contacts.common.preference.ContactsPreferences;
+import com.android.contacts.common.util.ContactDisplayUtils;
import com.android.incallui.ContactInfoCache.ContactCacheEntry;
import java.lang.ref.WeakReference;
@@ -199,6 +203,11 @@ public class ConferenceParticipantListAdapter extends BaseAdapter {
private final Context mContext;
/**
+ * ContactsPreferences used to lookup displayName preferences
+ */
+ private final ContactsPreferences mContactsPreferences;
+
+ /**
* The layout inflater used to inflate new views.
*/
private final LayoutInflater mLayoutInflater;
@@ -226,6 +235,7 @@ public class ConferenceParticipantListAdapter extends BaseAdapter {
mListView = listView;
mContext = context;
+ mContactsPreferences = new ContactsPreferences(mContext);
mLayoutInflater = layoutInflater;
mContactPhotoManager = contactPhotoManager;
}
@@ -238,6 +248,8 @@ public class ConferenceParticipantListAdapter extends BaseAdapter {
* conference.
*/
public void updateParticipants(List<Call> conferenceParticipants, boolean parentCanSeparate) {
+ mContactsPreferences.refreshValue(ContactsPreferences.DISPLAY_ORDER_KEY);
+ mContactsPreferences.refreshValue(ContactsPreferences.SORT_ORDER_KEY);
mParentCanSeparate = parentCanSeparate;
updateParticipantInfo(conferenceParticipants);
}
@@ -345,7 +357,10 @@ public class ConferenceParticipantListAdapter extends BaseAdapter {
boolean thisRowCanDisconnect = call.getTelecomCall().getDetails().can(
android.telecom.Call.Details.CAPABILITY_DISCONNECT_FROM_CONFERENCE);
- setCallerInfoForRow(result, contactCache.name, contactCache.number, contactCache.label,
+ setCallerInfoForRow(result, contactCache.namePrimary,
+ ContactDisplayUtils.getPreferredDisplayName(contactCache.namePrimary,
+ contactCache.nameAlternative, mContactsPreferences.getDisplayOrder()),
+ contactCache.number, contactCache.label,
contactCache.lookupKey, contactCache.displayPhotoUri, thisRowCanSeparate,
thisRowCanDisconnect);
@@ -383,9 +398,9 @@ public class ConferenceParticipantListAdapter extends BaseAdapter {
* @param thisRowCanSeparate {@code True} if this participant can separate from the conference.
* @param thisRowCanDisconnect {@code True} if this participant can be disconnected.
*/
- private final void setCallerInfoForRow(View view, String callerName, String callerNumber,
- String callerNumberType, String lookupKey, Uri photoUri, boolean thisRowCanSeparate,
- boolean thisRowCanDisconnect) {
+ private final void setCallerInfoForRow(View view, String callerName, String preferredName,
+ String callerNumber, String callerNumberType, String lookupKey, Uri photoUri,
+ boolean thisRowCanSeparate, boolean thisRowCanDisconnect) {
final ImageView photoView = (ImageView) view.findViewById(R.id.callerPhoto);
final TextView nameTextView = (TextView) view.findViewById(R.id.conferenceCallerName);
@@ -415,7 +430,7 @@ public class ConferenceParticipantListAdapter extends BaseAdapter {
mContactPhotoManager.loadDirectoryPhoto(photoView, photoUri, false, true, imageRequest);
// set the caller name
- nameTextView.setText(callerName);
+ nameTextView.setText(preferredName);
// set the caller number in subscript, or make the field disappear.
if (TextUtils.isEmpty(callerNumber)) {
@@ -491,15 +506,21 @@ public class ConferenceParticipantListAdapter extends BaseAdapter {
Collections.sort(mConferenceParticipants, new Comparator<ParticipantInfo>() {
public int compare(ParticipantInfo p1, ParticipantInfo p2) {
// Contact names might be null, so replace with empty string.
- String p1Name = p1.getContactCacheEntry().name;
- if (p1Name == null) {
- p1Name = "";
- }
-
- String p2Name = p2.getContactCacheEntry().name;
- if (p2Name == null) {
- p2Name = "";
- }
+ ContactCacheEntry c1 = p1.getContactCacheEntry();
+ String p1Name = MoreObjects.firstNonNull(
+ ContactDisplayUtils.getPreferredSortName(
+ c1.namePrimary,
+ c1.nameAlternative,
+ mContactsPreferences.getSortOrder()),
+ "");
+
+ ContactCacheEntry c2 = p2.getContactCacheEntry();
+ String p2Name = MoreObjects.firstNonNull(
+ ContactDisplayUtils.getPreferredSortName(
+ c2.namePrimary,
+ c2.nameAlternative,
+ mContactsPreferences.getSortOrder()),
+ "");
return p1Name.compareToIgnoreCase(p2Name);
}
diff --git a/InCallUI/src/com/android/incallui/ContactInfoCache.java b/InCallUI/src/com/android/incallui/ContactInfoCache.java
index e3457d5cb..098f82b81 100644
--- a/InCallUI/src/com/android/incallui/ContactInfoCache.java
+++ b/InCallUI/src/com/android/incallui/ContactInfoCache.java
@@ -16,6 +16,11 @@
package com.android.incallui;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
@@ -25,9 +30,9 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.os.Looper;
import android.provider.ContactsContract;
+import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.DisplayNameSources;
-import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.telecom.TelecomManager;
import android.text.TextUtils;
import android.util.Pair;
@@ -44,11 +49,6 @@ import com.android.incalluibind.ObjectFactory;
import org.json.JSONException;
import org.json.JSONObject;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import com.google.common.base.MoreObjects;
-import com.google.common.base.Preconditions;
-
import java.util.HashMap;
import java.util.Set;
@@ -218,7 +218,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete
ContactCacheEntry cacheEntry = mInfoMap.get(callId);
// Ensure we always have a cacheEntry. Replace the existing entry if
// it has no name or if we found a local contact.
- if (cacheEntry == null || TextUtils.isEmpty(cacheEntry.name) ||
+ if (cacheEntry == null || TextUtils.isEmpty(cacheEntry.namePrimary) ||
callerInfo.contactExists) {
cacheEntry = buildEntry(mContext, callId, callerInfo, presentationMode, isIncoming);
mInfoMap.put(callId, cacheEntry);
@@ -273,7 +273,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete
}
ContactCacheEntry entry = new ContactCacheEntry();
- entry.name = info.getDisplayName();
+ entry.namePrimary = info.getDisplayName();
entry.number = info.getNumber();
entry.contactLookupResult = info.getLookupSource();
final int type = info.getPhoneType();
@@ -512,7 +512,10 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete
Log.d(TAG, " ==> valid name, but presentation not allowed!" +
" displayName = " + displayName);
} else {
+ // Causes cce.namePrimary to be set as info.name below. CallCardPresenter will
+ // later determine whether to use the name or nameAlternative when presenting
displayName = info.name;
+ cce.nameAlternative = info.nameAlternative;
displayNumber = number;
label = info.phoneLabel;
Log.d(TAG, " ==> name is present in CallerInfo: displayName '" + displayName
@@ -520,7 +523,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete
}
}
- cce.name = displayName;
+ cce.namePrimary = displayName;
cce.number = displayNumber;
cce.location = displayLocation;
cce.label = label;
@@ -604,7 +607,8 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete
}
public static class ContactCacheEntry {
- public String name;
+ public String namePrimary;
+ public String nameAlternative;
public String number;
public String location;
public String label;
@@ -623,7 +627,8 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
- .add("name", MoreStrings.toSafeString(name))
+ .add("name", MoreStrings.toSafeString(namePrimary))
+ .add("nameAlternative", MoreStrings.toSafeString(nameAlternative))
.add("number", MoreStrings.toSafeString(number))
.add("location", MoreStrings.toSafeString(location))
.add("label", label)
diff --git a/InCallUI/src/com/android/incallui/StatusBarNotifier.java b/InCallUI/src/com/android/incallui/StatusBarNotifier.java
index 76a95f1a6..79a0b2cac 100644
--- a/InCallUI/src/com/android/incallui/StatusBarNotifier.java
+++ b/InCallUI/src/com/android/incallui/StatusBarNotifier.java
@@ -33,7 +33,9 @@ import android.text.BidiFormatter;
import android.text.TextDirectionHeuristics;
import android.text.TextUtils;
+import com.android.contacts.common.preference.ContactsPreferences;
import com.android.contacts.common.util.BitmapUtil;
+import com.android.contacts.common.util.ContactDisplayUtils;
import com.android.incallui.ContactInfoCache.ContactCacheEntry;
import com.android.incallui.ContactInfoCache.ContactInfoCacheCallback;
import com.android.incallui.InCallPresenter.InCallState;
@@ -57,6 +59,7 @@ public class StatusBarNotifier implements InCallPresenter.InCallStateListener,
private static final int NOTIFICATION_INCOMING_CALL = 2;
private final Context mContext;
+ private final ContactsPreferences mContactsPreferences;
private final ContactInfoCache mContactInfoCache;
private final NotificationManager mNotificationManager;
private int mCurrentNotification = NOTIFICATION_NONE;
@@ -71,6 +74,7 @@ public class StatusBarNotifier implements InCallPresenter.InCallStateListener,
public StatusBarNotifier(Context context, ContactInfoCache contactInfoCache) {
Preconditions.checkNotNull(context);
mContext = context;
+ mContactsPreferences = new ContactsPreferences(context);
mContactInfoCache = contactInfoCache;
mNotificationManager =
(NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
@@ -360,13 +364,15 @@ public class StatusBarNotifier implements InCallPresenter.InCallStateListener,
if (call.isConferenceCall() && !call.hasProperty(Details.PROPERTY_GENERIC_CONFERENCE)) {
return mContext.getResources().getString(R.string.card_title_conf_call);
}
- if (TextUtils.isEmpty(contactInfo.name)) {
- return TextUtils.isEmpty(contactInfo.number) ? null
- : BidiFormatter.getInstance().unicodeWrap(
- contactInfo.number.toString(), TextDirectionHeuristics.LTR);
+
+ String preferredName = ContactDisplayUtils.getPreferredDisplayName(contactInfo.namePrimary,
+ contactInfo.nameAlternative, mContactsPreferences.getDisplayOrder());
+ if (TextUtils.isEmpty(preferredName)) {
+ return TextUtils.isEmpty(contactInfo.number) ? null : BidiFormatter.getInstance()
+ .unicodeWrap(contactInfo.number, TextDirectionHeuristics.LTR);
}
- return contactInfo.name;
+ return preferredName;
}
private void addPersonReference(Notification.Builder builder, ContactCacheEntry contactInfo,
diff --git a/InCallUI/src/com/android/incallui/VideoCallPresenter.java b/InCallUI/src/com/android/incallui/VideoCallPresenter.java
index b829ab03a..12b718862 100644
--- a/InCallUI/src/com/android/incallui/VideoCallPresenter.java
+++ b/InCallUI/src/com/android/incallui/VideoCallPresenter.java
@@ -1265,6 +1265,7 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
ContactsContract.CommonDataKinds.Phone.PHOTO_URI,
ContactsContract.CommonDataKinds.Phone.LOOKUP_KEY,
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
+ ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME_ALTERNATIVE
}, null, null, null);
if (cursor != null) {
try {
@@ -1275,8 +1276,11 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
ContactsContract.CommonDataKinds.Phone.PHOTO_URI));
mProfileInfo.displayPhotoUri = photoUri == null ? null
: Uri.parse(photoUri);
- mProfileInfo.name = cursor.getString(cursor.getColumnIndex(
+ mProfileInfo.namePrimary = cursor.getString(cursor.getColumnIndex(
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
+ mProfileInfo.nameAlternative = cursor.getString(
+ cursor.getColumnIndex(ContactsContract.CommonDataKinds
+ .Phone.DISPLAY_NAME_ALTERNATIVE));
}
} finally {
cursor.close();
@@ -1296,7 +1300,7 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
}
ContactPhotoManager.DefaultImageRequest imageRequest = (mProfileInfo != null)
? null :
- new ContactPhotoManager.DefaultImageRequest(mProfileInfo.name,
+ new ContactPhotoManager.DefaultImageRequest(mProfileInfo.namePrimary,
mProfileInfo.lookupKey, false /* isCircularPhoto */);
ImageView photoView = ui.getPreviewPhotoView();