diff options
| author | Alon Albert <aalbert@google.com> | 2013-09-04 15:18:07 -0700 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2013-09-04 15:18:07 -0700 |
| commit | f0262164c53dfc51c2df18d4a9b781db69f2e840 (patch) | |
| tree | 4a4e2e27493c08d02a467990a2eb61fcf0c99b2a | |
| parent | adcbcbe9df5165594aa3fa324456cd116fa5bc0d (diff) | |
| parent | 363dc0f2c02e08f8fb71f2c30476b4fe4175fd1d (diff) | |
| download | android_packages_apps_ContactsCommon-f0262164c53dfc51c2df18d4a9b781db69f2e840.tar.gz android_packages_apps_ContactsCommon-f0262164c53dfc51c2df18d4a9b781db69f2e840.tar.bz2 android_packages_apps_ContactsCommon-f0262164c53dfc51c2df18d4a9b781db69f2e840.zip | |
am 363dc0f2: am 6af66a80: Show Address Instead of Number in Nearby Places
* commit '363dc0f2c02e08f8fb71f2c30476b4fe4175fd1d':
Show Address Instead of Number in Nearby Places
3 files changed, 56 insertions, 6 deletions
diff --git a/src/com/android/contacts/common/GeoUtil.java b/src/com/android/contacts/common/GeoUtil.java index aaf47153..5ca04b0c 100644 --- a/src/com/android/contacts/common/GeoUtil.java +++ b/src/com/android/contacts/common/GeoUtil.java @@ -20,6 +20,11 @@ import android.content.Context; import android.location.Country; import android.location.CountryDetector; +import com.android.i18n.phonenumbers.NumberParseException; +import com.android.i18n.phonenumbers.PhoneNumberUtil; +import com.android.i18n.phonenumbers.Phonenumber; +import com.android.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder; + import java.util.Locale; /** @@ -31,7 +36,7 @@ public class GeoUtil { * @return The ISO 3166-1 two letters country code of the country the user * is in. */ - public static final String getCurrentCountryIso(Context context) { + public static String getCurrentCountryIso(Context context) { final CountryDetector detector = (CountryDetector) context.getSystemService(Context.COUNTRY_DETECTOR); if (detector != null) { @@ -43,4 +48,19 @@ public class GeoUtil { // Fallback to Locale if have issues with CountryDetector return Locale.getDefault().getCountry(); } + + public static String getGeocodedLocationFor(Context context, String phoneNumber) { + final PhoneNumberOfflineGeocoder geocoder = PhoneNumberOfflineGeocoder.getInstance(); + final PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance(); + final CountryDetector countryDetector = + (CountryDetector) context.getSystemService(Context.COUNTRY_DETECTOR); + try { + final Phonenumber.PhoneNumber structuredPhoneNumber = + phoneNumberUtil.parse(phoneNumber, getCurrentCountryIso(context)); + final Locale locale = context.getResources().getConfiguration().locale; + return geocoder.getDescriptionForNumber(structuredPhoneNumber, locale); + } catch (NumberParseException e) { + return null; + } + } } diff --git a/src/com/android/contacts/common/list/DirectoryPartition.java b/src/com/android/contacts/common/list/DirectoryPartition.java index 1340af40..ca0dc110 100644 --- a/src/com/android/contacts/common/list/DirectoryPartition.java +++ b/src/com/android/contacts/common/list/DirectoryPartition.java @@ -38,6 +38,7 @@ public final class DirectoryPartition extends CompositeCursorAdapter.Partition { private boolean mPriorityDirectory; private boolean mPhotoSupported; private int mResultLimit = RESULT_LIMIT_DEFAULT; + private boolean mDisplayNumber = true; private String mLabel; @@ -163,4 +164,16 @@ public final class DirectoryPartition extends CompositeCursorAdapter.Partition { ", mLabel='" + mLabel + '\'' + '}'; } + + /** + * Whether or not to display the phone number in app that have that option - Dialer. If false, + * Phone Label should be used instead of Phone Number. + */ + public boolean isDisplayNumber() { + return mDisplayNumber; + } + + public void setDisplayNumber(boolean displayNumber) { + mDisplayNumber = displayNumber; + } } diff --git a/src/com/android/contacts/common/list/PhoneNumberListAdapter.java b/src/com/android/contacts/common/list/PhoneNumberListAdapter.java index 889a0917..2af055ec 100644 --- a/src/com/android/contacts/common/list/PhoneNumberListAdapter.java +++ b/src/com/android/contacts/common/list/PhoneNumberListAdapter.java @@ -33,6 +33,7 @@ import android.util.Log; import android.view.View; import android.view.ViewGroup; +import com.android.contacts.common.GeoUtil; import com.android.contacts.common.R; import com.android.contacts.common.extensions.ExtendedPhoneDirectoriesManager; import com.android.contacts.common.extensions.ExtensionsFactory; @@ -259,7 +260,8 @@ public class PhoneNumberListAdapter extends ContactEntryListAdapter { } public Uri getDataUri(int partitionIndex, Cursor cursor) { - final long directoryId = ((DirectoryPartition)getPartition(partitionIndex)).getDirectoryId(); + final long directoryId = + ((DirectoryPartition)getPartition(partitionIndex)).getDirectoryId(); if (!isRemoteDirectory(directoryId)) { final long phoneId = cursor.getLong(PhoneQuery.PHONE_ID); return ContentUris.withAppendedId(Data.CONTENT_URI, phoneId); @@ -352,13 +354,15 @@ public class PhoneNumberListAdapter extends ContactEntryListAdapter { view.removePhotoView(true, false); } - bindPhoneNumber(view, cursor); + + final DirectoryPartition directory = (DirectoryPartition) getPartition(partition); + bindPhoneNumber(view, cursor, directory.isDisplayNumber()); view.setDividerVisible(showBottomDivider); } - protected void bindPhoneNumber(ContactListItemView view, Cursor cursor) { + protected void bindPhoneNumber(ContactListItemView view, Cursor cursor, boolean displayNumber) { CharSequence label = null; - if (!cursor.isNull(PhoneQuery.PHONE_TYPE)) { + if (displayNumber && !cursor.isNull(PhoneQuery.PHONE_TYPE)) { final int type = cursor.getInt(PhoneQuery.PHONE_TYPE); final String customLabel = cursor.getString(PhoneQuery.PHONE_LABEL); @@ -366,7 +370,20 @@ public class PhoneNumberListAdapter extends ContactEntryListAdapter { label = Phone.getTypeLabel(getContext().getResources(), type, customLabel); } view.setLabel(label); - view.showPhoneNumber(cursor, PhoneQuery.PHONE_NUMBER); + final String text; + if (displayNumber) { + text = cursor.getString(PhoneQuery.PHONE_NUMBER); + } else { + // Display phone label. If that's null, display geocoded location for the number + final String phoneLabel = cursor.getString(PhoneQuery.PHONE_LABEL); + if (phoneLabel != null) { + text = phoneLabel; + } else { + final String phoneNumber = cursor.getString(PhoneQuery.PHONE_NUMBER); + text = GeoUtil.getGeocodedLocationFor(mContext, phoneNumber); + } + } + view.setPhoneNumber(text); } protected void bindSectionHeaderAndDivider(final ContactListItemView view, int position) { |
