From c5b35dd8c6a5af6a4b82fc83e3b25801eace525f Mon Sep 17 00:00:00 2001 From: Yorke Lee Date: Tue, 19 Nov 2013 13:52:45 -0800 Subject: Rename PhoneNumberHelper in Dialer Rename PhoneNumberHelper to more appropriate PhoneNumberDisplayHelper Change-Id: I2c03f5cbb04c1e03f1fc1e0051a1cea641160dca (cherry picked from commit 24ec319f8d410be8a1923c4033f927165876cbab) --- src/com/android/dialer/CallDetailActivity.java | 6 +- src/com/android/dialer/PhoneCallDetailsHelper.java | 6 +- src/com/android/dialer/calllog/CallLogAdapter.java | 4 +- .../dialer/calllog/CallLogListItemHelper.java | 4 +- .../dialer/calllog/DefaultVoicemailNotifier.java | 8 +-- .../dialer/calllog/PhoneNumberDisplayHelper.java | 80 ++++++++++++++++++++++ .../android/dialer/calllog/PhoneNumberHelper.java | 80 ---------------------- .../dialer/calllog/CallLogListItemHelperTest.java | 2 +- .../calllog/TestPhoneNumberUtilsWrapper.java | 2 +- 9 files changed, 96 insertions(+), 96 deletions(-) create mode 100644 src/com/android/dialer/calllog/PhoneNumberDisplayHelper.java delete mode 100644 src/com/android/dialer/calllog/PhoneNumberHelper.java diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java index a8d9d6fa7..8a2918b53 100644 --- a/src/com/android/dialer/CallDetailActivity.java +++ b/src/com/android/dialer/CallDetailActivity.java @@ -66,7 +66,7 @@ import com.android.dialer.calllog.CallDetailHistoryAdapter; import com.android.dialer.calllog.CallTypeHelper; import com.android.dialer.calllog.ContactInfo; import com.android.dialer.calllog.ContactInfoHelper; -import com.android.dialer.calllog.PhoneNumberHelper; +import com.android.dialer.calllog.PhoneNumberDisplayHelper; import com.android.dialer.calllog.PhoneNumberUtilsWrapper; import com.android.dialer.util.AsyncTaskExecutor; import com.android.dialer.util.AsyncTaskExecutors; @@ -115,7 +115,7 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION"; private CallTypeHelper mCallTypeHelper; - private PhoneNumberHelper mPhoneNumberHelper; + private PhoneNumberDisplayHelper mPhoneNumberHelper; private PhoneCallDetailsHelper mPhoneCallDetailsHelper; private TextView mHeaderTextView; private View mHeaderOverlayView; @@ -301,7 +301,7 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware mResources = getResources(); mCallTypeHelper = new CallTypeHelper(getResources()); - mPhoneNumberHelper = new PhoneNumberHelper(mResources); + mPhoneNumberHelper = new PhoneNumberDisplayHelper(mResources); mPhoneCallDetailsHelper = new PhoneCallDetailsHelper(mResources, mCallTypeHelper, new PhoneNumberUtilsWrapper()); mVoicemailStatusHelper = new VoicemailStatusHelperImpl(); diff --git a/src/com/android/dialer/PhoneCallDetailsHelper.java b/src/com/android/dialer/PhoneCallDetailsHelper.java index 340168e8b..8e6c943a4 100644 --- a/src/com/android/dialer/PhoneCallDetailsHelper.java +++ b/src/com/android/dialer/PhoneCallDetailsHelper.java @@ -33,7 +33,7 @@ import android.widget.TextView; import com.android.contacts.common.test.NeededForTesting; import com.android.dialer.calllog.CallTypeHelper; import com.android.dialer.calllog.ContactInfo; -import com.android.dialer.calllog.PhoneNumberHelper; +import com.android.dialer.calllog.PhoneNumberDisplayHelper; import com.android.dialer.calllog.PhoneNumberUtilsWrapper; /** @@ -48,7 +48,7 @@ public class PhoneCallDetailsHelper { private Long mCurrentTimeMillisForTest; // Helper classes. private final CallTypeHelper mCallTypeHelper; - private final PhoneNumberHelper mPhoneNumberHelper; + private final PhoneNumberDisplayHelper mPhoneNumberHelper; private final PhoneNumberUtilsWrapper mPhoneNumberUtilsWrapper; /** @@ -62,7 +62,7 @@ public class PhoneCallDetailsHelper { PhoneNumberUtilsWrapper phoneUtils) { mResources = resources; mCallTypeHelper = callTypeHelper; - mPhoneNumberHelper = new PhoneNumberHelper(resources); + mPhoneNumberHelper = new PhoneNumberDisplayHelper(resources); mPhoneNumberUtilsWrapper = phoneUtils; } diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java index e4fd0d897..a668196c5 100644 --- a/src/com/android/dialer/calllog/CallLogAdapter.java +++ b/src/com/android/dialer/calllog/CallLogAdapter.java @@ -176,7 +176,7 @@ public class CallLogAdapter extends GroupingListAdapter /** Helper to set up contact photos. */ private final ContactPhotoManager mContactPhotoManager; /** Helper to parse and process phone numbers. */ - private PhoneNumberHelper mPhoneNumberHelper; + private PhoneNumberDisplayHelper mPhoneNumberHelper; /** Helper to group call log entries. */ private final CallLogGroupBuilder mCallLogGroupBuilder; @@ -263,7 +263,7 @@ public class CallLogAdapter extends GroupingListAdapter CallTypeHelper callTypeHelper = new CallTypeHelper(resources); mContactPhotoManager = ContactPhotoManager.getInstance(mContext); - mPhoneNumberHelper = new PhoneNumberHelper(resources); + mPhoneNumberHelper = new PhoneNumberDisplayHelper(resources); PhoneCallDetailsHelper phoneCallDetailsHelper = new PhoneCallDetailsHelper( resources, callTypeHelper, new PhoneNumberUtilsWrapper()); mCallLogViewsHelper = diff --git a/src/com/android/dialer/calllog/CallLogListItemHelper.java b/src/com/android/dialer/calllog/CallLogListItemHelper.java index 576a432ac..a38ef012b 100644 --- a/src/com/android/dialer/calllog/CallLogListItemHelper.java +++ b/src/com/android/dialer/calllog/CallLogListItemHelper.java @@ -32,7 +32,7 @@ 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 PhoneNumberHelper mPhoneNumberHelper; + private final PhoneNumberDisplayHelper mPhoneNumberHelper; /** Resources to look up strings. */ private final Resources mResources; @@ -43,7 +43,7 @@ import com.android.dialer.R; * @param phoneNumberHelper used to process phone number */ public CallLogListItemHelper(PhoneCallDetailsHelper phoneCallDetailsHelper, - PhoneNumberHelper phoneNumberHelper, Resources resources) { + PhoneNumberDisplayHelper phoneNumberHelper, Resources resources) { mPhoneCallDetailsHelper = phoneCallDetailsHelper; mPhoneNumberHelper = phoneNumberHelper; mResources = resources; diff --git a/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java b/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java index 14e1bedbb..fedd012d9 100644 --- a/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java +++ b/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java @@ -57,7 +57,7 @@ public class DefaultVoicemailNotifier implements VoicemailNotifier { private final NotificationManager mNotificationManager; private final NewCallsQuery mNewCallsQuery; private final NameLookupQuery mNameLookupQuery; - private final PhoneNumberHelper mPhoneNumberHelper; + private final PhoneNumberDisplayHelper mPhoneNumberHelper; /** Returns the singleton instance of the {@link DefaultVoicemailNotifier}. */ public static synchronized DefaultVoicemailNotifier getInstance(Context context) { @@ -75,7 +75,7 @@ public class DefaultVoicemailNotifier implements VoicemailNotifier { private DefaultVoicemailNotifier(Context context, NotificationManager notificationManager, NewCallsQuery newCallsQuery, - NameLookupQuery nameLookupQuery, PhoneNumberHelper phoneNumberHelper) { + NameLookupQuery nameLookupQuery, PhoneNumberDisplayHelper phoneNumberHelper) { mContext = context; mNotificationManager = notificationManager; mNewCallsQuery = newCallsQuery; @@ -340,7 +340,7 @@ public class DefaultVoicemailNotifier implements VoicemailNotifier { * 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 PhoneNumberHelper createPhoneNumberHelper(Context context) { - return new PhoneNumberHelper(context.getResources()); + public static PhoneNumberDisplayHelper createPhoneNumberHelper(Context context) { + return new PhoneNumberDisplayHelper(context.getResources()); } } diff --git a/src/com/android/dialer/calllog/PhoneNumberDisplayHelper.java b/src/com/android/dialer/calllog/PhoneNumberDisplayHelper.java new file mode 100644 index 000000000..81f3ca1e5 --- /dev/null +++ b/src/com/android/dialer/calllog/PhoneNumberDisplayHelper.java @@ -0,0 +1,80 @@ +/* + * 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.res.Resources; +import android.provider.CallLog.Calls; +import android.telephony.PhoneNumberUtils; +import android.text.TextUtils; + +import com.android.dialer.R; + +/** + * Helper for formatting and managing the display of phone numbers. + */ +public class PhoneNumberDisplayHelper { + private final Resources mResources; + + public PhoneNumberDisplayHelper(Resources resources) { + mResources = resources; + } + + /* package */ CharSequence getDisplayName(CharSequence number, int presentation) { + if (presentation == Calls.PRESENTATION_UNKNOWN) { + return mResources.getString(R.string.unknown); + } + if (presentation == Calls.PRESENTATION_RESTRICTED) { + return mResources.getString(R.string.private_num); + } + if (presentation == Calls.PRESENTATION_PAYPHONE) { + return mResources.getString(R.string.payphone); + } + if (new PhoneNumberUtilsWrapper().isVoicemailNumber(number)) { + return mResources.getString(R.string.voicemail); + } + if (PhoneNumberUtilsWrapper.isLegacyUnknownNumbers(number)) { + return mResources.getString(R.string.unknown); + } + return ""; + } + + /** + * 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 CharSequence getDisplayNumber(CharSequence number, + int presentation, CharSequence formattedNumber) { + + final CharSequence displayName = getDisplayName(number, presentation); + + if (!TextUtils.isEmpty(displayName)) { + return displayName; + } + + if (TextUtils.isEmpty(number)) { + return ""; + } + + if (TextUtils.isEmpty(formattedNumber)) { + return number; + } else { + return formattedNumber; + } + } +} diff --git a/src/com/android/dialer/calllog/PhoneNumberHelper.java b/src/com/android/dialer/calllog/PhoneNumberHelper.java deleted file mode 100644 index 336facb37..000000000 --- a/src/com/android/dialer/calllog/PhoneNumberHelper.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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.res.Resources; -import android.provider.CallLog.Calls; -import android.telephony.PhoneNumberUtils; -import android.text.TextUtils; - -import com.android.dialer.R; - -/** - * Helper for formatting and managing phone numbers. - */ -public class PhoneNumberHelper { - private final Resources mResources; - - public PhoneNumberHelper(Resources resources) { - mResources = resources; - } - - /* package */ CharSequence getDisplayName(CharSequence number, int presentation) { - if (presentation == Calls.PRESENTATION_UNKNOWN) { - return mResources.getString(R.string.unknown); - } - if (presentation == Calls.PRESENTATION_RESTRICTED) { - return mResources.getString(R.string.private_num); - } - if (presentation == Calls.PRESENTATION_PAYPHONE) { - return mResources.getString(R.string.payphone); - } - if (new PhoneNumberUtilsWrapper().isVoicemailNumber(number)) { - return mResources.getString(R.string.voicemail); - } - if (PhoneNumberUtilsWrapper.isLegacyUnknownNumbers(number)) { - return mResources.getString(R.string.unknown); - } - return ""; - } - - /** - * 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 CharSequence getDisplayNumber(CharSequence number, - int presentation, CharSequence formattedNumber) { - - final CharSequence displayName = getDisplayName(number, presentation); - - if (!TextUtils.isEmpty(displayName)) { - return displayName; - } - - if (TextUtils.isEmpty(number)) { - return ""; - } - - if (TextUtils.isEmpty(formattedNumber)) { - return number; - } else { - return formattedNumber; - } - } -} diff --git a/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java b/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java index bb940edca..662afa0ca 100644 --- a/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java +++ b/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java @@ -49,7 +49,7 @@ public class CallLogListItemHelperTest extends AndroidTestCase { /** The views used in the tests. */ private CallLogListItemViews mViews; - private PhoneNumberHelper mPhoneNumberHelper; + private PhoneNumberDisplayHelper mPhoneNumberHelper; @Override protected void setUp() throws Exception { diff --git a/tests/src/com/android/dialer/calllog/TestPhoneNumberUtilsWrapper.java b/tests/src/com/android/dialer/calllog/TestPhoneNumberUtilsWrapper.java index 0dbd91479..95f3cc12e 100644 --- a/tests/src/com/android/dialer/calllog/TestPhoneNumberUtilsWrapper.java +++ b/tests/src/com/android/dialer/calllog/TestPhoneNumberUtilsWrapper.java @@ -19,7 +19,7 @@ package com.android.dialer.calllog; import android.content.res.Resources; /** - * Modified version of {@link com.android.dialer.calllog.PhoneNumberHelper} to be used in tests + * Modified version of {@link com.android.dialer.calllog.PhoneNumberDisplayHelper} to be used in tests * that allows injecting the voicemail number. */ public final class TestPhoneNumberUtilsWrapper extends PhoneNumberUtilsWrapper { -- cgit v1.2.3