Use geocoded description in the call log.
If a number is not associated with a contact, try to get the location
for that phone number and show that instead.
This is shown below the phone number, since the phone number is still
the most useful information for the user.
Bug: 4968253
Change-Id: If9c29c2e20f96f10e24fcf97ccac85eada237b71
diff --git a/src/com/android/contacts/CallDetailActivity.java b/src/com/android/contacts/CallDetailActivity.java
index 9fd1b03..d2c193e 100644
--- a/src/com/android/contacts/CallDetailActivity.java
+++ b/src/com/android/contacts/CallDetailActivity.java
@@ -419,7 +419,9 @@
numberText = candidateNumberText;
}
}
- return new PhoneCallDetails(number, numberText, new int[]{ callType }, date, duration,
+ return new PhoneCallDetails(number, numberText,
+ mPhoneNumberHelper.parsePhoneNumber(number, countryIso),
+ new int[]{ callType }, date, duration,
nameText, numberType, numberLabel, personId, photoUri);
} finally {
if (callCursor != null) {
diff --git a/src/com/android/contacts/PhoneCallDetails.java b/src/com/android/contacts/PhoneCallDetails.java
index d4786d9..0672673 100644
--- a/src/com/android/contacts/PhoneCallDetails.java
+++ b/src/com/android/contacts/PhoneCallDetails.java
@@ -16,6 +16,8 @@
package com.android.contacts;
+import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
+
import android.net.Uri;
import android.provider.CallLog.Calls;
import android.provider.ContactsContract.CommonDataKinds.Phone;
@@ -28,6 +30,8 @@
public final CharSequence number;
/** The formatted version of {@link #number}. */
public final CharSequence formattedNumber;
+ /** The structured phone number corresponding to {@link #number}. */
+ public final PhoneNumber structuredPhoneNumber;
/**
* The type of calls, as defined in the call log table, e.g., {@link Calls#INCOMING_TYPE}.
* <p>
@@ -53,17 +57,20 @@
public final Uri photoUri;
/** Create the details for a call with a number not associated with a contact. */
- public PhoneCallDetails(CharSequence number, CharSequence formattedNumber, int[] callTypes,
- long date, long duration) {
- this(number, formattedNumber, callTypes, date, duration, "", 0, "", -1L, null);
+ public PhoneCallDetails(CharSequence number, CharSequence formattedNumber,
+ PhoneNumber structuredPhoneNumber, int[] callTypes, long date, long duration) {
+ this(number, formattedNumber, structuredPhoneNumber, callTypes, date, duration,
+ "", 0, "", -1L, null);
}
/** Create the details for a call with a number associated with a contact. */
- public PhoneCallDetails(CharSequence number, CharSequence formattedNumber, int[] callTypes,
- long date, long duration, CharSequence name, int numberType, CharSequence numberLabel,
- long personId, Uri photoUri) {
+ public PhoneCallDetails(CharSequence number, CharSequence formattedNumber,
+ PhoneNumber structuredPhoneNumber, int[] callTypes, long date, long duration,
+ CharSequence name, int numberType, CharSequence numberLabel, long personId,
+ Uri photoUri) {
this.number = number;
this.formattedNumber = formattedNumber;
+ this.structuredPhoneNumber = structuredPhoneNumber;
this.callTypes = callTypes;
this.date = date;
this.duration = duration;
diff --git a/src/com/android/contacts/PhoneCallDetailsHelper.java b/src/com/android/contacts/PhoneCallDetailsHelper.java
index 8369a0c..db3928e 100644
--- a/src/com/android/contacts/PhoneCallDetailsHelper.java
+++ b/src/com/android/contacts/PhoneCallDetailsHelper.java
@@ -118,7 +118,7 @@
mPhoneNumberHelper.getDisplayNumber(details.number, details.formattedNumber);
if (TextUtils.isEmpty(details.name)) {
nameText = displayNumber;
- numberText = "";
+ numberText = mPhoneNumberHelper.getGeocodeForNumber(details.structuredPhoneNumber);
} else {
nameText = details.name;
if (numberFormattedLabel != null) {
diff --git a/src/com/android/contacts/calllog/CallLogFragment.java b/src/com/android/contacts/calllog/CallLogFragment.java
index 49a6043..5d51713 100644
--- a/src/com/android/contacts/calllog/CallLogFragment.java
+++ b/src/com/android/contacts/calllog/CallLogFragment.java
@@ -29,6 +29,7 @@
import com.android.contacts.util.ExpirableCache;
import com.android.internal.telephony.CallerInfo;
import com.google.common.annotations.VisibleForTesting;
+import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
import android.app.ListFragment;
import android.content.ContentUris;
@@ -267,6 +268,8 @@
private CharArrayBuffer mBuffer2 = new CharArrayBuffer(128);
/** Helper to set up contact photos. */
private final ContactPhotoManager mContactPhotoManager;
+ /** Helper to parse and process phone numbers. */
+ private PhoneNumberHelper mPhoneNumberHelper;
/** Can be set to true by tests to disable processing of requests. */
private volatile boolean mRequestProcessingDisabled = false;
@@ -321,12 +324,11 @@
R.drawable.ic_call_log_list_action_play);
mContactPhotoManager = ContactPhotoManager.getInstance(getActivity());
- PhoneNumberHelper phoneNumberHelper =
- new PhoneNumberHelper(getResources(), mVoiceMailNumber);
+ mPhoneNumberHelper = new PhoneNumberHelper(getResources(), mVoiceMailNumber);
PhoneCallDetailsHelper phoneCallDetailsHelper = new PhoneCallDetailsHelper(
- getActivity(), resources, callTypeHelper, phoneNumberHelper );
+ getActivity(), resources, callTypeHelper, mPhoneNumberHelper );
mCallLogViewsHelper = new CallLogListItemHelper(phoneCallDetailsHelper,
- phoneNumberHelper, callDrawable, playDrawable);
+ mPhoneNumberHelper, callDrawable, playDrawable);
}
/**
@@ -788,11 +790,14 @@
final int[] callTypes = getCallTypes(c, count);
final PhoneCallDetails details;
+ PhoneNumber structuredPhoneNumber =
+ mPhoneNumberHelper.parsePhoneNumber(number, countryIso);
if (TextUtils.isEmpty(name)) {
- details = new PhoneCallDetails(number, formattedNumber, callTypes, date, duration);
+ details = new PhoneCallDetails(number, formattedNumber, structuredPhoneNumber,
+ callTypes, date, duration);
} else {
- details = new PhoneCallDetails(number, formattedNumber, callTypes, date, duration,
- name, ntype, label, personId, thumbnailUri);
+ details = new PhoneCallDetails(number, formattedNumber, structuredPhoneNumber,
+ callTypes, date, duration, name, ntype, label, personId, thumbnailUri);
}
final boolean isNew = isNewSection(c);
diff --git a/src/com/android/contacts/calllog/PhoneNumberHelper.java b/src/com/android/contacts/calllog/PhoneNumberHelper.java
index 4d96f4f..c898a09 100644
--- a/src/com/android/contacts/calllog/PhoneNumberHelper.java
+++ b/src/com/android/contacts/calllog/PhoneNumberHelper.java
@@ -18,6 +18,10 @@
import com.android.contacts.R;
import com.android.internal.telephony.CallerInfo;
+import com.google.i18n.phonenumbers.NumberParseException;
+import com.google.i18n.phonenumbers.PhoneNumberUtil;
+import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
+import com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder;
import android.content.res.Resources;
import android.net.Uri;
@@ -30,10 +34,14 @@
public class PhoneNumberHelper {
private final Resources mResources;
private final String mVoicemailNumber;
+ private final PhoneNumberUtil mPhoneNumberUtil;
+ private final PhoneNumberOfflineGeocoder mPhoneNumberOfflineGeocoder;
public PhoneNumberHelper(Resources resources, String voicemailNumber) {
mResources = resources;
mVoicemailNumber = voicemailNumber;
+ mPhoneNumberUtil = PhoneNumberUtil.getInstance();
+ mPhoneNumberOfflineGeocoder = PhoneNumberOfflineGeocoder.getInstance();
}
/** Returns true if it is possible to place a call to the given number. */
@@ -98,4 +106,26 @@
public boolean isSipNumber(CharSequence number) {
return PhoneNumberUtils.isUriNumber(number.toString());
}
+
+ /**
+ * Returns a structured phone number from the given text representation, or null if the number
+ * cannot be parsed.
+ */
+ public PhoneNumber parsePhoneNumber(String number, String countryIso) {
+ try {
+ return mPhoneNumberUtil.parse(number, countryIso);
+ } catch (NumberParseException e) {
+ return null;
+ }
+ }
+
+ /** Returns the geocode associated with a phone number or the empty string if not available. */
+ public String getGeocodeForNumber(PhoneNumber structuredPhoneNumber) {
+ if (structuredPhoneNumber != null) {
+ return mPhoneNumberOfflineGeocoder.getDescriptionForNumber(
+ structuredPhoneNumber, mResources.getConfiguration().locale);
+ } else {
+ return "";
+ }
+ }
}