diff options
author | Brian Attwell <brianattwell@google.com> | 2015-03-04 21:01:44 -0800 |
---|---|---|
committer | Brian Attwell <brianattwell@google.com> | 2015-03-05 12:28:04 -0800 |
commit | 3cf9ac64046bfd65d419476c900d3d98d3eccfeb (patch) | |
tree | 2221ec8db2917311764cc67be044dbd0ee97244a /src/com/android/providers/contacts/ContactsDatabaseHelper.java | |
parent | ae8f8932b836437e548405387e080388c3686964 (diff) | |
download | packages_providers_ContactsProvider-3cf9ac64046bfd65d419476c900d3d98d3eccfeb.zip packages_providers_ContactsProvider-3cf9ac64046bfd65d419476c900d3d98d3eccfeb.tar.gz packages_providers_ContactsProvider-3cf9ac64046bfd65d419476c900d3d98d3eccfeb.tar.bz2 |
Prioritize regular names over phonetic names. P2/2
When choosing display names, prioritize StructuredNames that
have more than phonetic components.
I make no attempt to handle the case where a StructuredName
with only phonetic components is marked super primary. If
clients do this, the behavior is still undefined.
Bug: 19587274
Change-Id: I503c0fff6da30b9f1d6b6cbeaedfc4d9314f8a00
Diffstat (limited to 'src/com/android/providers/contacts/ContactsDatabaseHelper.java')
-rw-r--r-- | src/com/android/providers/contacts/ContactsDatabaseHelper.java | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/com/android/providers/contacts/ContactsDatabaseHelper.java b/src/com/android/providers/contacts/ContactsDatabaseHelper.java index fc4d343..564bd4c 100644 --- a/src/com/android/providers/contacts/ContactsDatabaseHelper.java +++ b/src/com/android/providers/contacts/ContactsDatabaseHelper.java @@ -4818,7 +4818,14 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { return mMimeTypeIdSip; } - public int getDisplayNameSourceForMimeTypeId(int mimeTypeId) { + /** + * Returns a {@link ContactsContract.DisplayNameSources} value based on {@param mimeTypeId}. + * This does not return {@link ContactsContract.DisplayNameSources#STRUCTURED_PHONETIC_NAME}. + * The calling client needs to inspect the structured name itself to distinguish between + * {@link ContactsContract.DisplayNameSources#STRUCTURED_NAME} and + * {@code STRUCTURED_PHONETIC_NAME}. + */ + private int getDisplayNameSourceForMimeTypeId(int mimeTypeId) { if (mimeTypeId == mMimeTypeIdStructuredName) { return DisplayNameSources.STRUCTURED_NAME; } @@ -5540,6 +5547,22 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { while (c.moveToNext()) { int mimeType = c.getInt(RawContactNameQuery.MIMETYPE); int source = getDisplayNameSourceForMimeTypeId(mimeType); + + if (source == DisplayNameSources.STRUCTURED_NAME) { + final String given = c.getString(RawContactNameQuery.GIVEN_NAME); + final String middle = c.getString(RawContactNameQuery.MIDDLE_NAME); + final String family = c.getString(RawContactNameQuery.FAMILY_NAME); + final String suffix = c.getString(RawContactNameQuery.SUFFIX); + final String prefix = c.getString(RawContactNameQuery.PREFIX); + if (TextUtils.isEmpty(given) && TextUtils.isEmpty(middle) + && TextUtils.isEmpty(family) && TextUtils.isEmpty(suffix) + && TextUtils.isEmpty(prefix)) { + // Every non-phonetic name component is empty. Therefore, lets lower the + // source score to STRUCTURED_PHONETIC_NAME. + source = DisplayNameSources.STRUCTURED_PHONETIC_NAME; + } + } + if (source < bestDisplayNameSource || source == DisplayNameSources.UNDEFINED) { continue; } @@ -5626,7 +5649,8 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { String sortKeyAlternative = null; int displayNameStyle = FullNameStyle.UNDEFINED; - if (bestDisplayNameSource == DisplayNameSources.STRUCTURED_NAME) { + if (bestDisplayNameSource == DisplayNameSources.STRUCTURED_NAME + || bestDisplayNameSource == DisplayNameSources.STRUCTURED_PHONETIC_NAME) { displayNameStyle = bestName.fullNameStyle; if (displayNameStyle == FullNameStyle.CJK || displayNameStyle == FullNameStyle.UNDEFINED) { |