summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/calllogutils/PhoneNumberDisplayUtil.java
diff options
context:
space:
mode:
authorzachh <zachh@google.com>2018-01-26 10:56:46 -0800
committerCopybara-Service <copybara-piper@google.com>2018-01-26 12:13:04 -0800
commit03b13198537df025febb842db7f95794a1faad8f (patch)
tree2e013c45154e63429d9c4db817d07d3e79a06658 /java/com/android/dialer/calllogutils/PhoneNumberDisplayUtil.java
parent268aed51f835788ef44329db50b62b34215b9203 (diff)
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
Diffstat (limited to 'java/com/android/dialer/calllogutils/PhoneNumberDisplayUtil.java')
-rw-r--r--java/com/android/dialer/calllogutils/PhoneNumberDisplayUtil.java28
1 files changed, 19 insertions, 9 deletions
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<String> 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<String> 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,