From 49efd91e50a11dc7bdef8382a0ceac01bc060f77 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Tue, 19 May 2015 12:17:26 -0700 Subject: Performance improvements to call log scrolling. - Remove call to CallUtil to check if video is enabled. It seems like it's fine to include the content description of what the call was, if it was a video call, even if there is not a video-enabled call account. - Factor out PhoneNumberDisplayHelper so it doesn't need to be an instance. This reduces some extra calls to getDisplayNameHelper. Probably a marginal difference, performance-wise, but it probably helps a smidgen and also simplifies the need for creating and passing or recalculating various instances of things. TODO: It'd be much better if PhoneCallDetails had a builder. It's terribly painful to fix all the tests when adding fields... Change-Id: I6da13dc8b6b047043aba871796a8ed13b112a227 --- .../dialer/calllog/PhoneNumberDisplayUtil.java | 88 ++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/com/android/dialer/calllog/PhoneNumberDisplayUtil.java (limited to 'src/com/android/dialer/calllog/PhoneNumberDisplayUtil.java') diff --git a/src/com/android/dialer/calllog/PhoneNumberDisplayUtil.java b/src/com/android/dialer/calllog/PhoneNumberDisplayUtil.java new file mode 100644 index 000000000..e7fcde263 --- /dev/null +++ b/src/com/android/dialer/calllog/PhoneNumberDisplayUtil.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.dialer.calllog; + +import android.content.Context; +import android.content.res.Resources; +import android.provider.CallLog.Calls; +import android.telecom.PhoneAccountHandle; +import android.text.TextUtils; +import android.util.Log; + +import com.android.dialer.R; + +/** + * Helper for formatting and managing the display of phone numbers. + */ +public class PhoneNumberDisplayUtil { + + /** + * Returns the string to display for the given phone number if there is no matching contact. + */ + /* package */ static CharSequence getDisplayName( + Context context, + PhoneAccountHandle accountHandle, + CharSequence number, + int presentation, + boolean isVoicemail) { + if (presentation == Calls.PRESENTATION_UNKNOWN) { + return context.getResources().getString(R.string.unknown); + } + if (presentation == Calls.PRESENTATION_RESTRICTED) { + return context.getResources().getString(R.string.private_num); + } + if (presentation == Calls.PRESENTATION_PAYPHONE) { + return context.getResources().getString(R.string.payphone); + } + if (isVoicemail) { + return context.getResources().getString(R.string.voicemail); + } + if (PhoneNumberUtilsWrapper.isLegacyUnknownNumbers(number)) { + return context.getResources().getString(R.string.unknown); + } + return ""; + } + + /** + * Returns the string to display for the given phone number. + * + * @param accountHandle The handle for the account corresponding to the call + * @param number the number to display + * @param formattedNumber the formatted number if available, may be null + */ + public static CharSequence getDisplayNumber( + Context context, + PhoneAccountHandle accountHandle, + CharSequence number, + int presentation, + CharSequence formattedNumber, + boolean isVoicemail) { + if (!TextUtils.isEmpty(formattedNumber)) { + return formattedNumber; + } + + final CharSequence displayName = + getDisplayName(context, accountHandle, number, presentation, isVoicemail); + if (!TextUtils.isEmpty(displayName)) { + return displayName; + } else if (!TextUtils.isEmpty(number)) { + return number; + } else { + return ""; + } + } +} -- cgit v1.2.3