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.res.Resources; 20 import android.provider.CallLog.Calls; 21 import android.telephony.PhoneNumberUtils; 22 import android.text.TextUtils; 23 24 import com.android.dialer.R; 25 26 /** 27 * Helper for formatting and managing phone numbers. 28 */ 29 public class PhoneNumberHelper { 30 private final Resources mResources; 31 32 public PhoneNumberHelper(Resources resources) { 33 mResources = resources; 34 } 35 36 /* package */ CharSequence getDisplayName(CharSequence number, int presentation) { 37 if (presentation == Calls.PRESENTATION_UNKNOWN) { 38 return mResources.getString(R.string.unknown); 39 } 40 if (presentation == Calls.PRESENTATION_RESTRICTED) { 41 return mResources.getString(R.string.private_num); 42 } 43 if (presentation == Calls.PRESENTATION_PAYPHONE) { 44 return mResources.getString(R.string.payphone); 45 } 46 if (new PhoneNumberUtilsWrapper().isVoicemailNumber(number)) { 47 return mResources.getString(R.string.voicemail); 48 } 49 if (PhoneNumberUtilsWrapper.isLegacyUnknownNumbers(number)) { 50 return mResources.getString(R.string.unknown); 51 } 52 return ""; 53 } 54 55 /** 56 * Returns the string to display for the given phone number. 57 * 58 * @param number the number to display 59 * @param formattedNumber the formatted number if available, may be null 60 */ 61 public CharSequence getDisplayNumber(CharSequence number, 62 int presentation, CharSequence formattedNumber) { 63 64 final CharSequence displayName = getDisplayName(number, presentation); 65 66 if (!TextUtils.isEmpty(displayName)) { 67 return displayName; 68 } 69 70 if (TextUtils.isEmpty(number)) { 71 return ""; 72 } 73 74 if (TextUtils.isEmpty(formattedNumber)) { 75 return number; 76 } else { 77 return formattedNumber; 78 } 79 } 80 } 81