1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.dialer.calllog; 18 19 import android.content.Context; 20 import android.content.res.Resources; 21 import android.provider.CallLog.Calls; 22 import android.text.TextUtils; 23 import android.util.Log; 24 25 import com.android.dialer.R; 26 import com.android.dialer.util.PhoneNumberUtil; 27 28 /** 29 * Helper for formatting and managing the display of phone numbers. 30 */ 31 public class PhoneNumberDisplayUtil { 32 33 /** 34 * Returns the string to display for the given phone number if there is no matching contact. 35 */ 36 /* package */ static CharSequence getDisplayName( 37 Context context, 38 CharSequence number, 39 int presentation, 40 boolean isVoicemail) { 41 if (presentation == Calls.PRESENTATION_UNKNOWN) { 42 return context.getResources().getString(R.string.unknown); 43 } 44 if (presentation == Calls.PRESENTATION_RESTRICTED) { 45 return context.getResources().getString(R.string.private_num); 46 } 47 if (presentation == Calls.PRESENTATION_PAYPHONE) { 48 return context.getResources().getString(R.string.payphone); 49 } 50 if (isVoicemail) { 51 return context.getResources().getString(R.string.voicemail); 52 } 53 if (PhoneNumberUtil.isLegacyUnknownNumbers(number)) { 54 return context.getResources().getString(R.string.unknown); 55 } 56 return ""; 57 } 58 59 /** 60 * Returns the string to display for the given phone number. 61 * 62 * @param number the number to display 63 * @param formattedNumber the formatted number if available, may be null 64 */ 65 public static CharSequence getDisplayNumber( 66 Context context, 67 CharSequence number, 68 int presentation, 69 CharSequence formattedNumber, 70 boolean isVoicemail) { 71 final CharSequence displayName = getDisplayName(context, number, presentation, isVoicemail); 72 if (!TextUtils.isEmpty(displayName)) { 73 return displayName; 74 } 75 76 if (!TextUtils.isEmpty(formattedNumber)) { 77 return formattedNumber; 78 } else if (!TextUtils.isEmpty(number)) { 79 return number; 80 } else { 81 return ""; 82 } 83 } 84 } 85