summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/phonelookup/PhoneLookupSelector.java
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2017-12-12 23:18:50 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2017-12-12 23:18:50 +0000
commit888e6b1499f7be68f2d33f870a57cd7e2a58dd93 (patch)
tree85148446a15528867fba0d7353b024081d9e0a5a /java/com/android/dialer/phonelookup/PhoneLookupSelector.java
parentab544521b21566b12a42e539d119c76dd5243a2d (diff)
parent75d67f5d83bdb28c6254cf064d09ac24fc9ae928 (diff)
Merge changes I45978ea4,Ia85b1008,I9e68c561,I9255dd3c
* changes: BEGIN_PUBLIC Automated rollback of changelist 172683494 BEGIN_PUBLIC Automated rollback of changelist 172956409 Download and play voicemails from server when not locally available. Updated writing of PhoneLookup columns in annotated call log.
Diffstat (limited to 'java/com/android/dialer/phonelookup/PhoneLookupSelector.java')
-rw-r--r--java/com/android/dialer/phonelookup/PhoneLookupSelector.java79
1 files changed, 75 insertions, 4 deletions
diff --git a/java/com/android/dialer/phonelookup/PhoneLookupSelector.java b/java/com/android/dialer/phonelookup/PhoneLookupSelector.java
index a746ea44f..af8b849e5 100644
--- a/java/com/android/dialer/phonelookup/PhoneLookupSelector.java
+++ b/java/com/android/dialer/phonelookup/PhoneLookupSelector.java
@@ -16,6 +16,8 @@
package com.android.dialer.phonelookup;
import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import com.android.dialer.phonelookup.PhoneLookupInfo.Cp2Info.Cp2ContactInfo;
/**
* Prioritizes information from a {@link PhoneLookupInfo}.
@@ -37,11 +39,80 @@ public final class PhoneLookupSelector {
*/
@NonNull
public static String selectName(PhoneLookupInfo phoneLookupInfo) {
- if (phoneLookupInfo.getCp2Info().getCp2ContactInfoCount() > 0) {
- // Arbitrarily select the first contact's name. In the future, it may make sense to join the
- // names such as "Mom, Dad" in the case that multiple contacts share the same number.
- return phoneLookupInfo.getCp2Info().getCp2ContactInfo(0).getName();
+ Cp2ContactInfo firstLocalContact = firstLocalContact(phoneLookupInfo);
+ if (firstLocalContact != null) {
+ String name = firstLocalContact.getName();
+ if (!name.isEmpty()) {
+ return firstLocalContact.getName();
+ }
+ }
+ return "";
+ }
+
+ /** Select the photo URI associated with this number. */
+ @NonNull
+ public static String selectPhotoUri(PhoneLookupInfo phoneLookupInfo) {
+ Cp2ContactInfo firstLocalContact = firstLocalContact(phoneLookupInfo);
+ if (firstLocalContact != null) {
+ String photoUri = firstLocalContact.getPhotoUri();
+ if (!photoUri.isEmpty()) {
+ return photoUri;
+ }
+ }
+ return "";
+ }
+
+ /** Select the photo ID associated with this number, or 0 if there is none. */
+ public static long selectPhotoId(PhoneLookupInfo phoneLookupInfo) {
+ Cp2ContactInfo firstLocalContact = firstLocalContact(phoneLookupInfo);
+ if (firstLocalContact != null) {
+ long photoId = firstLocalContact.getPhotoId();
+ if (photoId > 0) {
+ return photoId;
+ }
+ }
+ return 0;
+ }
+
+ /** Select the lookup URI associated with this number. */
+ @NonNull
+ public static String selectLookupUri(PhoneLookupInfo phoneLookupInfo) {
+ Cp2ContactInfo firstLocalContact = firstLocalContact(phoneLookupInfo);
+ if (firstLocalContact != null) {
+ String lookupUri = firstLocalContact.getLookupUri();
+ if (!lookupUri.isEmpty()) {
+ return lookupUri;
+ }
}
return "";
}
+
+ /**
+ * A localized string representing the number type such as "Home" or "Mobile", or a custom value
+ * set by the user.
+ */
+ @NonNull
+ public static String selectNumberLabel(PhoneLookupInfo phoneLookupInfo) {
+ Cp2ContactInfo firstLocalContact = firstLocalContact(phoneLookupInfo);
+ if (firstLocalContact != null) {
+ String label = firstLocalContact.getLabel();
+ if (!label.isEmpty()) {
+ return label;
+ }
+ }
+ return "";
+ }
+
+ /**
+ * Arbitrarily select the first contact. In the future, it may make sense to display contact
+ * information from all contacts with the same number (for example show the name as "Mom, Dad" or
+ * show a synthesized photo containing photos of both "Mom" and "Dad").
+ */
+ @Nullable
+ private static Cp2ContactInfo firstLocalContact(PhoneLookupInfo phoneLookupInfo) {
+ if (phoneLookupInfo.getCp2Info().getCp2ContactInfoCount() > 0) {
+ return phoneLookupInfo.getCp2Info().getCp2ContactInfo(0);
+ }
+ return null;
+ }
}