Add support for surrogate pairs when getting the icon for the contact picture
@@ -22,6 +22,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
+import android.support.annotation.VisibleForTesting;
import android.support.v4.util.LruCache;
import android.text.TextUtils;
import android.widget.ImageView;
@@ -74,6 +75,21 @@ public class ContactPictureLoader {
0xffCC0000
};
+ @VisibleForTesting
+ protected static String calcUnknownContactLetter(Address address) {
+ String letter = null;
+ String personal = address.getPersonal();
+ String str = (personal != null) ? personal : address.getAddress();
+
+ Matcher m = EXTRACT_LETTER_PATTERN.matcher(str);
+ if (m.find()) {
+ letter = m.group(0).toUpperCase(Locale.US);
+ }
+
+ return (TextUtils.isEmpty(letter)) ?
+ FALLBACK_CONTACT_LETTER : letter;
+ }
+
/**
* Constructor.
*
@@ -160,20 +176,6 @@ public class ContactPictureLoader {
return CONTACT_DUMMY_COLORS_ARGB[colorIndex];
}
- private String calcUnknownContactLetter(Address address) {
- String letter = null;
- String personal = address.getPersonal();
- String str = (personal != null) ? personal : address.getAddress();
-
- Matcher m = EXTRACT_LETTER_PATTERN.matcher(str);
- if (m.find()) {
- letter = m.group(0).toUpperCase(Locale.US);
- }
-
- return (TextUtils.isEmpty(letter)) ?
- FALLBACK_CONTACT_LETTER : letter.substring(0, 1);
- }
-
/**
* Calculates a bitmap with a color and a capital letter for contacts without picture.
*/
