summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Lee <anwlee@google.com>2015-05-19 12:17:26 -0700
committerAndrew Lee <anwlee@google.com>2015-05-19 18:14:53 -0700
commit49efd91e50a11dc7bdef8382a0ceac01bc060f77 (patch)
tree1968b01c927c95d5359022af481c56fea2a22f78 /src
parentd9602d00913bfc8e93444ac70645bc82cff7db69 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/com/android/dialer/CallDetailActivity.java65
-rw-r--r--src/com/android/dialer/PhoneCallDetails.java41
-rw-r--r--src/com/android/dialer/PhoneCallDetailsHelper.java16
-rw-r--r--src/com/android/dialer/calllog/CallLogAdapter.java27
-rw-r--r--src/com/android/dialer/calllog/CallLogListItemHelper.java16
-rw-r--r--src/com/android/dialer/calllog/CallLogListItemViewHolder.java5
-rw-r--r--src/com/android/dialer/calllog/DefaultVoicemailNotifier.java25
-rw-r--r--src/com/android/dialer/calllog/PhoneNumberDisplayUtil.java (renamed from src/com/android/dialer/calllog/PhoneNumberDisplayHelper.java)67
8 files changed, 113 insertions, 149 deletions
diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java
index 2401c4767..18cf753ec 100644
--- a/src/com/android/dialer/CallDetailActivity.java
+++ b/src/com/android/dialer/CallDetailActivity.java
@@ -60,7 +60,7 @@ import com.android.dialer.calllog.CallTypeHelper;
import com.android.dialer.calllog.ContactInfo;
import com.android.dialer.calllog.ContactInfoHelper;
import com.android.dialer.calllog.PhoneAccountUtils;
-import com.android.dialer.calllog.PhoneNumberDisplayHelper;
+import com.android.dialer.calllog.PhoneNumberDisplayUtil;
import com.android.dialer.calllog.PhoneNumberUtilsWrapper;
import com.android.dialer.util.AsyncTaskExecutor;
import com.android.dialer.util.AsyncTaskExecutors;
@@ -106,7 +106,6 @@ public class CallDetailActivity extends Activity {
public static final String VOICEMAIL_FRAGMENT_TAG = "voicemail_fragment";
private CallTypeHelper mCallTypeHelper;
- private PhoneNumberDisplayHelper mPhoneNumberHelper;
private QuickContactBadge mQuickContactBadge;
private TextView mCallerName;
private TextView mCallerNumber;
@@ -173,7 +172,6 @@ public class CallDetailActivity extends Activity {
mResources = getResources();
mCallTypeHelper = new CallTypeHelper(getResources());
- mPhoneNumberHelper = new PhoneNumberDisplayHelper(this, mResources);
mVoicemailUri = getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI);
@@ -344,12 +342,7 @@ public class CallDetailActivity extends Activity {
final CharSequence callLocationOrType = getNumberTypeOrLocation(firstDetails);
- final CharSequence displayNumber =
- mPhoneNumberHelper.getDisplayNumber(
- firstDetails.accountHandle,
- firstDetails.number,
- firstDetails.numberPresentation,
- firstDetails.formattedNumber);
+ final CharSequence displayNumber = firstDetails.displayNumber;
final String displayNumberStr = mBidiFormatter.unicodeWrap(
displayNumber.toString(), TextDirectionHeuristics.LTR);
@@ -396,11 +389,7 @@ public class CallDetailActivity extends Activity {
String nameForDefaultImage;
if (TextUtils.isEmpty(firstDetails.name)) {
- nameForDefaultImage = mPhoneNumberHelper.getDisplayNumber(
- firstDetails.accountHandle,
- firstDetails.number,
- firstDetails.numberPresentation,
- firstDetails.formattedNumber).toString();
+ nameForDefaultImage = firstDetails.displayNumber.toString();
} else {
nameForDefaultImage = firstDetails.name.toString();
}
@@ -459,47 +448,37 @@ public class CallDetailActivity extends Activity {
// Formatted phone number.
final CharSequence formattedNumber;
- // Read contact specifics.
- final CharSequence nameText;
- final int numberType;
- final CharSequence numberLabel;
- final Uri photoUri;
- final Uri lookupUri;
- int sourceType;
+
// If this is not a regular number, there is no point in looking it up in the contacts.
- ContactInfo info =
- PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation)
- && !new PhoneNumberUtilsWrapper(this).isVoicemailNumber(accountHandle, number)
- ? mContactInfoHelper.lookupNumber(number, countryIso)
- : null;
+ ContactInfo info = ContactInfo.EMPTY;
+ final boolean isVoicemail = new PhoneNumberUtilsWrapper(this)
+ .isVoicemailNumber(accountHandle, number);
+ if (PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation)
+ && !isVoicemail) {
+ mContactInfoHelper.lookupNumber(number, countryIso);
+ }
if (info == null) {
- formattedNumber = mPhoneNumberHelper.getDisplayNumber(accountHandle, number,
- numberPresentation, null);
- nameText = "";
- numberType = 0;
- numberLabel = "";
- photoUri = null;
- lookupUri = null;
- sourceType = 0;
+ formattedNumber = PhoneNumberDisplayUtil.getDisplayNumber(
+ this,
+ accountHandle,
+ number,
+ numberPresentation,
+ null /* formattedNumber */,
+ isVoicemail);
} else {
formattedNumber = info.formattedNumber;
- nameText = info.name;
- numberType = info.type;
- numberLabel = info.label;
- photoUri = info.photoUri;
- lookupUri = info.lookupUri;
- sourceType = info.sourceType;
}
final int features = callCursor.getInt(FEATURES);
Long dataUsage = null;
if (!callCursor.isNull(DATA_USAGE)) {
dataUsage = callCursor.getLong(DATA_USAGE);
}
- return new PhoneCallDetails(number, numberPresentation,
+ return new PhoneCallDetails(this, number, numberPresentation,
formattedNumber, countryIso, geocode,
new int[]{ callType }, date, duration,
- nameText, numberType, numberLabel, lookupUri, photoUri, sourceType,
- accountHandle, features, dataUsage, transcription);
+ info.name, info.type, info.label, info.lookupUri, info.photoUri,
+ info.sourceType, accountHandle, features, dataUsage, transcription,
+ isVoicemail);
} finally {
if (callCursor != null) {
callCursor.close();
diff --git a/src/com/android/dialer/PhoneCallDetails.java b/src/com/android/dialer/PhoneCallDetails.java
index ec9657ed8..843e19352 100644
--- a/src/com/android/dialer/PhoneCallDetails.java
+++ b/src/com/android/dialer/PhoneCallDetails.java
@@ -17,15 +17,20 @@
package com.android.dialer;
import com.google.common.annotations.VisibleForTesting;
+import com.android.dialer.calllog.PhoneNumberDisplayUtil;
+import android.content.Context;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.provider.CallLog.Calls;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.telecom.PhoneAccountHandle;
+import android.text.TextUtils;
/**
* The details of a phone call to be shown in the UI.
+ *
+ * TODO: Create a builder, to make it easier to construct an instance.
*/
public class PhoneCallDetails {
/** The number of the other party involved in the call. */
@@ -85,35 +90,40 @@ public class PhoneCallDetails {
*/
public final String transcription;
+ public final String displayNumber;
+ public final boolean isVoicemail;
+
/**
* Create the details for a call, with empty defaults specified for extra fields that are
* not necessary for testing.
*/
@VisibleForTesting
- public PhoneCallDetails(CharSequence number, int numberPresentation,
+ public PhoneCallDetails(Context context, CharSequence number, int numberPresentation,
CharSequence formattedNumber, String countryIso, String geocode,
- int[] callTypes, long date, long duration) {
- this (number, numberPresentation, formattedNumber, countryIso, geocode,
- callTypes, date, duration, "", 0, "", null, null, 0, null, 0, null, null);
+ int[] callTypes, long date, long duration, boolean isVoicemail) {
+ this(context, number, numberPresentation, formattedNumber, countryIso, geocode,
+ callTypes, date, duration, "", 0, "", null, null, 0, null, 0, null, null,
+ isVoicemail);
}
/** Create the details for a call with a number not associated with a contact. */
- public PhoneCallDetails(CharSequence number, int numberPresentation,
+ public PhoneCallDetails(Context context, CharSequence number, int numberPresentation,
CharSequence formattedNumber, String countryIso, String geocode,
int[] callTypes, long date, long duration,
- PhoneAccountHandle accountHandle, int features, Long dataUsage, String transcription) {
- this(number, numberPresentation, formattedNumber, countryIso, geocode, callTypes, date,
- duration, "", 0, "", null, null, 0, accountHandle, features, dataUsage,
- transcription);
+ PhoneAccountHandle accountHandle, int features, Long dataUsage, String transcription,
+ boolean isVoicemail) {
+ this(context, number, numberPresentation, formattedNumber, countryIso, geocode,
+ callTypes, date, duration, "", 0, "", null, null, 0, accountHandle, features,
+ dataUsage, transcription, isVoicemail);
}
/** Create the details for a call with a number associated with a contact. */
- public PhoneCallDetails(CharSequence number, int numberPresentation,
+ public PhoneCallDetails(Context context, CharSequence number, int numberPresentation,
CharSequence formattedNumber, String countryIso, String geocode,
int[] callTypes, long date, long duration, CharSequence name,
int numberType, CharSequence numberLabel, Uri contactUri, Uri photoUri,
int sourceType, PhoneAccountHandle accountHandle, int features, Long dataUsage,
- String transcription) {
+ String transcription, boolean isVoicemail) {
this.number = number;
this.numberPresentation = numberPresentation;
this.formattedNumber = formattedNumber;
@@ -132,5 +142,14 @@ public class PhoneCallDetails {
this.features = features;
this.dataUsage = dataUsage;
this.transcription = transcription;
+ this.isVoicemail = isVoicemail;
+
+ this.displayNumber = PhoneNumberDisplayUtil.getDisplayNumber(
+ context,
+ this.accountHandle,
+ this.number,
+ this.numberPresentation,
+ this.formattedNumber,
+ this.isVoicemail).toString();
}
}
diff --git a/src/com/android/dialer/PhoneCallDetailsHelper.java b/src/com/android/dialer/PhoneCallDetailsHelper.java
index 7855a1d13..db37bb3f3 100644
--- a/src/com/android/dialer/PhoneCallDetailsHelper.java
+++ b/src/com/android/dialer/PhoneCallDetailsHelper.java
@@ -32,7 +32,6 @@ import com.android.contacts.common.testing.NeededForTesting;
import com.android.contacts.common.util.PhoneNumberHelper;
import com.android.dialer.calllog.ContactInfo;
import com.android.dialer.calllog.PhoneAccountUtils;
-import com.android.dialer.calllog.PhoneNumberDisplayHelper;
import com.android.dialer.calllog.PhoneNumberUtilsWrapper;
import com.android.dialer.util.DialerUtils;
@@ -52,7 +51,6 @@ public class PhoneCallDetailsHelper {
/** The injected current time in milliseconds since the epoch. Used only by tests. */
private Long mCurrentTimeMillisForTest;
// Helper classes.
- private final PhoneNumberDisplayHelper mPhoneNumberHelper;
private final PhoneNumberUtilsWrapper mPhoneNumberUtilsWrapper;
/**
@@ -72,7 +70,6 @@ public class PhoneCallDetailsHelper {
mContext = context;
mResources = resources;
mPhoneNumberUtilsWrapper = phoneUtils;
- mPhoneNumberHelper = new PhoneNumberDisplayHelper(context, resources, phoneUtils);
}
/** Fills the call details views with content. */
@@ -125,9 +122,7 @@ public class PhoneCallDetailsHelper {
}
final CharSequence nameText;
- final CharSequence displayNumber =
- mPhoneNumberHelper.getDisplayNumber(details.accountHandle, details.number,
- details.numberPresentation, details.formattedNumber);
+ final CharSequence displayNumber = details.displayNumber;
if (TextUtils.isEmpty(details.name)) {
nameText = displayNumber;
// We have a real phone number as "nameView" so make it always LTR
@@ -195,8 +190,7 @@ public class PhoneCallDetailsHelper {
}
if (!TextUtils.isEmpty(details.name) && TextUtils.isEmpty(numberFormattedLabel)) {
- numberFormattedLabel = mPhoneNumberHelper.getDisplayNumber(details.accountHandle,
- details.number, details.numberPresentation, details.formattedNumber);
+ numberFormattedLabel = details.displayNumber;
}
return numberFormattedLabel;
}
@@ -218,12 +212,8 @@ public class PhoneCallDetailsHelper {
@NeededForTesting
public void setCallDetailsHeader(TextView nameView, PhoneCallDetails details) {
final CharSequence nameText;
- final CharSequence displayNumber =
- mPhoneNumberHelper.getDisplayNumber(details.accountHandle, details.number,
- details.numberPresentation,
- mResources.getString(R.string.recentCalls_addToContact));
if (TextUtils.isEmpty(details.name)) {
- nameText = displayNumber;
+ nameText = mResources.getString(R.string.recentCalls_addToContact);
} else {
nameText = details.name;
}
diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java
index b4fed867f..608475e0b 100644
--- a/src/com/android/dialer/calllog/CallLogAdapter.java
+++ b/src/com/android/dialer/calllog/CallLogAdapter.java
@@ -22,6 +22,7 @@ import android.content.res.Resources;
import android.database.Cursor;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
+import android.os.Trace;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.telecom.PhoneAccountHandle;
import android.telephony.PhoneNumberUtils;
@@ -98,8 +99,6 @@ public class CallLogAdapter extends GroupingListAdapter
/** Instance of helper class for managing views. */
private final CallLogListItemHelper mCallLogViewsHelper;
- /** Helper to parse and process phone numbers. */
- private PhoneNumberDisplayHelper mPhoneNumberHelper;
/** Helper to access Telephony phone number utils class */
protected final PhoneNumberUtilsWrapper mPhoneNumberUtilsWrapper;
/** Helper to group call log entries. */
@@ -210,12 +209,10 @@ public class CallLogAdapter extends GroupingListAdapter
Resources resources = mContext.getResources();
CallTypeHelper callTypeHelper = new CallTypeHelper(resources);
- mPhoneNumberHelper = new PhoneNumberDisplayHelper(mContext, resources);
mPhoneNumberUtilsWrapper = new PhoneNumberUtilsWrapper(mContext);
PhoneCallDetailsHelper phoneCallDetailsHelper =
new PhoneCallDetailsHelper(mContext, resources, mPhoneNumberUtilsWrapper);
- mCallLogViewsHelper =
- new CallLogListItemHelper(phoneCallDetailsHelper, mPhoneNumberHelper, resources);
+ mCallLogViewsHelper = new CallLogListItemHelper(phoneCallDetailsHelper, resources);
mCallLogGroupBuilder = new CallLogGroupBuilder(this);
}
@@ -312,9 +309,10 @@ public class CallLogAdapter extends GroupingListAdapter
if (getItemViewType(position) == VIEW_TYPE_SHOW_CALL_HISTORY_LIST_ITEM) {
return;
}
-
+ Trace.beginSection("onBindViewHolder: " + position);
Cursor c = (Cursor) getItem(position);
if (c == null) {
+ Trace.endSection();
return;
}
int count = getGroupSize(position);
@@ -408,21 +406,21 @@ public class CallLogAdapter extends GroupingListAdapter
views.showActions(mCurrentlyExpandedPosition == position, mOnReportButtonClickListener);
if (TextUtils.isEmpty(name)) {
- details = new PhoneCallDetails(number, numberPresentation, formattedNumber, countryIso,
- geocode, callTypes, date, duration, accountHandle, features, dataUsage,
- transcription);
+ details = new PhoneCallDetails(mContext, number, numberPresentation, formattedNumber,
+ countryIso, geocode, callTypes, date, duration, accountHandle, features,
+ dataUsage, transcription, isVoicemailNumber);
} else {
- details = new PhoneCallDetails(number, numberPresentation, formattedNumber, countryIso,
- geocode, callTypes, date, duration, name, ntype, label, lookupUri, photoUri,
- sourceType, accountHandle, features, dataUsage, transcription);
+ details = new PhoneCallDetails(mContext, number, numberPresentation, formattedNumber,
+ countryIso, geocode, callTypes, date, duration, name, ntype, label, lookupUri,
+ photoUri, sourceType, accountHandle, features, dataUsage, transcription,
+ isVoicemailNumber);
}
mCallLogViewsHelper.setPhoneCallDetails(mContext, views, details);
String nameForDefaultImage = null;
if (TextUtils.isEmpty(name)) {
- nameForDefaultImage = mPhoneNumberHelper.getDisplayNumber(details.accountHandle,
- details.number, details.numberPresentation, details.formattedNumber).toString();
+ nameForDefaultImage = details.displayNumber;
} else {
nameForDefaultImage = name;
}
@@ -437,6 +435,7 @@ public class CallLogAdapter extends GroupingListAdapter
mViewTreeObserver = views.rootView.getViewTreeObserver();
mViewTreeObserver.addOnPreDrawListener(this);
}
+ Trace.endSection();
}
@Override
diff --git a/src/com/android/dialer/calllog/CallLogListItemHelper.java b/src/com/android/dialer/calllog/CallLogListItemHelper.java
index 7ec6752e4..147a192e3 100644
--- a/src/com/android/dialer/calllog/CallLogListItemHelper.java
+++ b/src/com/android/dialer/calllog/CallLogListItemHelper.java
@@ -23,7 +23,6 @@ import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.util.Log;
-import com.android.contacts.common.CallUtil;
import com.android.dialer.PhoneCallDetails;
import com.android.dialer.PhoneCallDetailsHelper;
import com.android.dialer.R;
@@ -36,8 +35,6 @@ import com.android.dialer.R;
/** Helper for populating the details of a phone call. */
private final PhoneCallDetailsHelper mPhoneCallDetailsHelper;
- /** Helper for handling phone numbers. */
- private final PhoneNumberDisplayHelper mPhoneNumberHelper;
/** Resources to look up strings. */
private final Resources mResources;
@@ -47,10 +44,9 @@ import com.android.dialer.R;
* @param phoneCallDetailsHelper used to set the details of a phone call
* @param phoneNumberHelper used to process phone number
*/
- public CallLogListItemHelper(PhoneCallDetailsHelper phoneCallDetailsHelper,
- PhoneNumberDisplayHelper phoneNumberHelper, Resources resources) {
+ public CallLogListItemHelper(
+ PhoneCallDetailsHelper phoneCallDetailsHelper, Resources resources) {
mPhoneCallDetailsHelper = phoneCallDetailsHelper;
- mPhoneNumberHelper = phoneNumberHelper;
mResources = resources;
}
@@ -73,7 +69,7 @@ import com.android.dialer.R;
// Cache name or number of caller. Used when setting the content descriptions of buttons
// when the actions ViewStub is inflated.
- views.nameOrNumber = this.getNameOrNumber(details);
+ views.nameOrNumber = getNameOrNumber(details);
}
/**
@@ -190,8 +186,7 @@ import com.android.dialer.R;
}
// If call had video capabilities, add the "Video Call" string.
- if ((details.features & Calls.FEATURES_VIDEO) == Calls.FEATURES_VIDEO &&
- CallUtil.isVideoEnabled(context)) {
+ if ((details.features & Calls.FEATURES_VIDEO) == Calls.FEATURES_VIDEO) {
callDescription.append(mResources.getString(R.string.description_video_call));
}
@@ -264,8 +259,7 @@ import com.android.dialer.R;
if (!TextUtils.isEmpty(details.name)) {
recipient = details.name;
} else {
- recipient = mPhoneNumberHelper.getDisplayNumber(details.accountHandle,
- details.number, details.numberPresentation, details.formattedNumber);
+ recipient = details.displayNumber;
}
return recipient;
}
diff --git a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java
index a7dd6aff8..ccd480ec6 100644
--- a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java
+++ b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java
@@ -411,8 +411,6 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder {
@NeededForTesting
public static CallLogListItemViewHolder createForTest(Context context) {
Resources resources = context.getResources();
- PhoneNumberDisplayHelper phoneNumberHelper =
- new PhoneNumberDisplayHelper(context, resources);
PhoneNumberUtilsWrapper phoneNumberUtilsWrapper = new PhoneNumberUtilsWrapper(context);
PhoneCallDetailsHelper phoneCallDetailsHelper = new PhoneCallDetailsHelper(
context, resources, phoneNumberUtilsWrapper);
@@ -421,8 +419,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder {
context,
null /* actionListener */,
phoneNumberUtilsWrapper,
- new CallLogListItemHelper(
- phoneCallDetailsHelper, phoneNumberHelper, resources),
+ new CallLogListItemHelper(phoneCallDetailsHelper, resources),
new View(context),
new QuickContactBadge(context),
new View(context),
diff --git a/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java b/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java
index 99ca8db10..7c2a96638 100644
--- a/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java
+++ b/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java
@@ -58,7 +58,6 @@ public class DefaultVoicemailNotifier {
private final NotificationManager mNotificationManager;
private final NewCallsQuery mNewCallsQuery;
private final NameLookupQuery mNameLookupQuery;
- private final PhoneNumberDisplayHelper mPhoneNumberHelper;
/** Returns the singleton instance of the {@link DefaultVoicemailNotifier}. */
public static synchronized DefaultVoicemailNotifier getInstance(Context context) {
@@ -68,20 +67,18 @@ public class DefaultVoicemailNotifier {
ContentResolver contentResolver = context.getContentResolver();
sInstance = new DefaultVoicemailNotifier(context, notificationManager,
createNewCallsQuery(contentResolver),
- createNameLookupQuery(contentResolver),
- createPhoneNumberHelper(context));
+ createNameLookupQuery(contentResolver));
}
return sInstance;
}
private DefaultVoicemailNotifier(Context context,
NotificationManager notificationManager, NewCallsQuery newCallsQuery,
- NameLookupQuery nameLookupQuery, PhoneNumberDisplayHelper phoneNumberHelper) {
+ NameLookupQuery nameLookupQuery) {
mContext = context;
mNotificationManager = notificationManager;
mNewCallsQuery = newCallsQuery;
mNameLookupQuery = nameLookupQuery;
- mPhoneNumberHelper = phoneNumberHelper;
}
/**
@@ -128,8 +125,12 @@ public class DefaultVoicemailNotifier {
PhoneAccountHandle accountHandle = PhoneAccountUtils.getAccount(
newCall.accountComponentName,
newCall.accountId);
- name = mPhoneNumberHelper.getDisplayName(accountHandle, newCall.number,
- newCall.numberPresentation).toString();
+ name = PhoneNumberDisplayUtil.getDisplayName(
+ mContext,
+ accountHandle,
+ newCall.number,
+ newCall.numberPresentation,
+ /* isVoicemail */ false).toString();
// If we cannot lookup the contact, use the number instead.
if (TextUtils.isEmpty(name)) {
// Look it up in the database.
@@ -338,14 +339,4 @@ public class DefaultVoicemailNotifier {
}
}
}
-
- /**
- * Create a new PhoneNumberHelper.
- * <p>
- * This will cause some Disk I/O, at least the first time it is created, so it should not be
- * called from the main thread.
- */
- public static PhoneNumberDisplayHelper createPhoneNumberHelper(Context context) {
- return new PhoneNumberDisplayHelper(context, context.getResources());
- }
}
diff --git a/src/com/android/dialer/calllog/PhoneNumberDisplayHelper.java b/src/com/android/dialer/calllog/PhoneNumberDisplayUtil.java
index c1a5abfe1..e7fcde263 100644
--- a/src/com/android/dialer/calllog/PhoneNumberDisplayHelper.java
+++ b/src/com/android/dialer/calllog/PhoneNumberDisplayUtil.java
@@ -28,40 +28,31 @@ import com.android.dialer.R;
/**
* Helper for formatting and managing the display of phone numbers.
*/
-public class PhoneNumberDisplayHelper {
- private final Context mContext;
- private final Resources mResources;
- private final PhoneNumberUtilsWrapper mPhoneNumberUtilsWrapper;
+public class PhoneNumberDisplayUtil {
- public PhoneNumberDisplayHelper(Context context, Resources resources) {
- mContext = context;
- mResources = resources;
- mPhoneNumberUtilsWrapper = new PhoneNumberUtilsWrapper(context);
- }
-
- public PhoneNumberDisplayHelper(Context context, Resources resources,
- PhoneNumberUtilsWrapper phoneNumberUtils) {
- mContext = context;
- mResources = resources;
- mPhoneNumberUtilsWrapper = phoneNumberUtils;
- }
-
- /* package */ CharSequence getDisplayName(PhoneAccountHandle accountHandle, CharSequence number,
- int presentation) {
+ /**
+ * 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 mResources.getString(R.string.unknown);
+ return context.getResources().getString(R.string.unknown);
}
if (presentation == Calls.PRESENTATION_RESTRICTED) {
- return mResources.getString(R.string.private_num);
+ return context.getResources().getString(R.string.private_num);
}
if (presentation == Calls.PRESENTATION_PAYPHONE) {
- return mResources.getString(R.string.payphone);
+ return context.getResources().getString(R.string.payphone);
}
- if (mPhoneNumberUtilsWrapper.isVoicemailNumber(accountHandle, number)) {
- return mResources.getString(R.string.voicemail);
+ if (isVoicemail) {
+ return context.getResources().getString(R.string.voicemail);
}
if (PhoneNumberUtilsWrapper.isLegacyUnknownNumbers(number)) {
- return mResources.getString(R.string.unknown);
+ return context.getResources().getString(R.string.unknown);
}
return "";
}
@@ -73,21 +64,25 @@ public class PhoneNumberDisplayHelper {
* @param number the number to display
* @param formattedNumber the formatted number if available, may be null
*/
- public CharSequence getDisplayNumber(PhoneAccountHandle accountHandle, CharSequence number,
- int presentation, CharSequence formattedNumber) {
- final CharSequence displayName = getDisplayName(accountHandle, number, presentation);
- if (!TextUtils.isEmpty(displayName)) {
- return displayName;
- }
-
- if (TextUtils.isEmpty(number)) {
- return "";
+ public static CharSequence getDisplayNumber(
+ Context context,
+ PhoneAccountHandle accountHandle,
+ CharSequence number,
+ int presentation,
+ CharSequence formattedNumber,
+ boolean isVoicemail) {
+ if (!TextUtils.isEmpty(formattedNumber)) {
+ return formattedNumber;
}
- if (TextUtils.isEmpty(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 formattedNumber;
+ return "";
}
}
}