From 03b13198537df025febb842db7f95794a1faad8f Mon Sep 17 00:00:00 2001 From: zachh Date: Fri, 26 Jan 2018 10:56:46 -0800 Subject: Added number presentation to AnnotatedCallLog. Updated the new call log UI to properly show text based on the presentation. Bug: 70989592 Test: unit PiperOrigin-RevId: 183414195 Change-Id: I2123f37cd3c733060125b6e894c1a80be4193ad6 --- .../dialer/calllogutils/CallLogContactTypes.java | 2 +- .../dialer/calllogutils/CallLogEntryText.java | 34 +++++++++++++++++----- .../dialer/calllogutils/CallLogIntents.java | 12 ++++---- .../calllogutils/PhoneNumberDisplayUtil.java | 28 ++++++++++++------ 4 files changed, 51 insertions(+), 25 deletions(-) (limited to 'java/com/android/dialer/calllogutils') diff --git a/java/com/android/dialer/calllogutils/CallLogContactTypes.java b/java/com/android/dialer/calllogutils/CallLogContactTypes.java index 01ae653b4..58651560f 100644 --- a/java/com/android/dialer/calllogutils/CallLogContactTypes.java +++ b/java/com/android/dialer/calllogutils/CallLogContactTypes.java @@ -29,7 +29,7 @@ public class CallLogContactTypes { boolean isVoicemail = false; boolean isSpam = false; boolean isBusiness = false; - int numberPresentation = 0; + int numberPresentation = row.numberPresentation(); boolean isConference = false; return LetterTileDrawable.getContactTypeFromPrimitives( diff --git a/java/com/android/dialer/calllogutils/CallLogEntryText.java b/java/com/android/dialer/calllogutils/CallLogEntryText.java index aa45a697a..49f5e42ca 100644 --- a/java/com/android/dialer/calllogutils/CallLogEntryText.java +++ b/java/com/android/dialer/calllogutils/CallLogEntryText.java @@ -21,6 +21,7 @@ import android.provider.CallLog.Calls; import android.text.TextUtils; import com.android.dialer.calllog.model.CoalescedRow; import com.android.dialer.time.Clock; +import com.google.common.base.Optional; import com.google.common.collect.Collections2; import java.util.ArrayList; import java.util.List; @@ -40,16 +41,25 @@ public final class CallLogEntryText { * following the primary text.) */ public static CharSequence buildPrimaryText(Context context, CoalescedRow row) { - StringBuilder primaryText = new StringBuilder(); + // Always prefer the presentation name, like "Restricted". + Optional presentationName = + PhoneNumberDisplayUtil.getNameForPresentation(context, row.numberPresentation()); + if (presentationName.isPresent()) { + return presentationName.get(); + } + + // Otherwise prefer the name. if (!TextUtils.isEmpty(row.numberAttributes().getName())) { - primaryText.append(row.numberAttributes().getName()); - } else if (!TextUtils.isEmpty(row.formattedNumber())) { - primaryText.append(row.formattedNumber()); - } else { - // TODO(zachh): Handle CallLog.Calls.PRESENTATION_*, including Verizon restricted numbers. - primaryText.append(context.getText(R.string.new_call_log_unknown)); + return row.numberAttributes().getName(); + } + + // Otherwise prefer the formatted number. + if (!TextUtils.isEmpty(row.formattedNumber())) { + return row.formattedNumber(); } - return primaryText.toString(); + + // If there's no formatted number, just return "Unknown". + return context.getText(R.string.new_call_log_unknown); } /** @@ -112,6 +122,14 @@ public final class CallLogEntryText { components.add(getNumberTypeLabel(context, row)); + // If there's a presentation name, we showed it in the primary text and shouldn't show any name + // or number here. + Optional presentationName = + PhoneNumberDisplayUtil.getNameForPresentation(context, row.numberPresentation()); + if (presentationName.isPresent()) { + return joinSecondaryTextComponents(components); + } + if (TextUtils.isEmpty(row.numberAttributes().getName())) { // If the name is empty the number is shown as the primary text and there's nothing to add. return joinSecondaryTextComponents(components); diff --git a/java/com/android/dialer/calllogutils/CallLogIntents.java b/java/com/android/dialer/calllogutils/CallLogIntents.java index 05af8bfc7..227b15eed 100644 --- a/java/com/android/dialer/calllogutils/CallLogIntents.java +++ b/java/com/android/dialer/calllogutils/CallLogIntents.java @@ -19,10 +19,10 @@ import android.content.Context; import android.content.Intent; import android.provider.CallLog.Calls; import android.support.annotation.Nullable; -import android.text.TextUtils; import com.android.dialer.callintent.CallInitiationType; import com.android.dialer.callintent.CallIntentBuilder; import com.android.dialer.calllog.model.CoalescedRow; +import com.android.dialer.phonenumberutil.PhoneNumberHelper; import com.android.dialer.precall.PreCall; import com.android.dialer.telecom.TelecomUtil; @@ -39,18 +39,16 @@ public final class CallLogIntents { */ @Nullable public static Intent getCallBackIntent(Context context, CoalescedRow row) { - // TODO(zachh): Do something with parsed values to make more dialable? - String originalNumber = row.number().getRawInput().getNumber(); - // TODO(zachh): Make this more sophisticated, e.g. return null for non-dialable numbers? - if (TextUtils.isEmpty(originalNumber)) { + // TODO(zachh): Don't use raw input. + String normalizedNumber = row.number().getRawInput().getNumber(); + if (!PhoneNumberHelper.canPlaceCallsTo(normalizedNumber, row.numberPresentation())) { return null; } // TODO(zachh): More granular logging? - // TODO(zachh): Support assisted dialing. return PreCall.getIntent( context, - new CallIntentBuilder(originalNumber, CallInitiationType.Type.CALL_LOG) + new CallIntentBuilder(normalizedNumber, CallInitiationType.Type.CALL_LOG) .setPhoneAccountHandle( TelecomUtil.composePhoneAccountHandle( row.phoneAccountComponentName(), row.phoneAccountId())) diff --git a/java/com/android/dialer/calllogutils/PhoneNumberDisplayUtil.java b/java/com/android/dialer/calllogutils/PhoneNumberDisplayUtil.java index 9bebfacac..f0f696396 100644 --- a/java/com/android/dialer/calllogutils/PhoneNumberDisplayUtil.java +++ b/java/com/android/dialer/calllogutils/PhoneNumberDisplayUtil.java @@ -23,6 +23,7 @@ import android.text.TextDirectionHeuristics; import android.text.TextUtils; import com.android.contacts.common.compat.PhoneNumberUtilsCompat; import com.android.dialer.phonenumberutil.PhoneNumberHelper; +import com.google.common.base.Optional; /** Helper for formatting and managing the display of phone numbers. */ public class PhoneNumberDisplayUtil { @@ -30,14 +31,9 @@ public class PhoneNumberDisplayUtil { /** Returns the string to display for the given phone number if there is no matching contact. */ public static CharSequence getDisplayName( Context context, CharSequence number, int presentation, boolean isVoicemail) { - if (presentation == Calls.PRESENTATION_UNKNOWN) { - return context.getResources().getString(R.string.unknown); - } - if (presentation == Calls.PRESENTATION_RESTRICTED) { - return PhoneNumberHelper.getDisplayNameForRestrictedNumber(context); - } - if (presentation == Calls.PRESENTATION_PAYPHONE) { - return context.getResources().getString(R.string.payphone); + Optional presentationString = getNameForPresentation(context, presentation); + if (presentationString.isPresent()) { + return presentationString.get(); } if (isVoicemail) { return context.getResources().getString(R.string.voicemail_string); @@ -48,13 +44,27 @@ public class PhoneNumberDisplayUtil { return ""; } + /** Returns the string associated with the given presentation. */ + public static Optional getNameForPresentation(Context appContext, int presentation) { + if (presentation == Calls.PRESENTATION_UNKNOWN) { + return Optional.of(appContext.getResources().getString(R.string.unknown)); + } + if (presentation == Calls.PRESENTATION_RESTRICTED) { + return Optional.of(PhoneNumberHelper.getDisplayNameForRestrictedNumber(appContext)); + } + if (presentation == Calls.PRESENTATION_PAYPHONE) { + return Optional.of(appContext.getResources().getString(R.string.payphone)); + } + return Optional.absent(); + } + /** * Returns the string to display for the given phone number. * * @param number the number to display * @param formattedNumber the formatted number if available, may be null */ - public static CharSequence getDisplayNumber( + static CharSequence getDisplayNumber( Context context, CharSequence number, int presentation, -- cgit v1.2.3