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 --- .../calllogutils/PhoneNumberDisplayUtil.java | 28 +++++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'java/com/android/dialer/calllogutils/PhoneNumberDisplayUtil.java') 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