Commit b1395139 authored by Finnur Thorarinsson's avatar Finnur Thorarinsson Committed by Commit Bot

Contacts Picker: Add support for two letter rounded icons.

Bug: 860467
Change-Id: Iadfd17c687682a52786753c0a8e7c8c5229a40ec
Reviewed-on: https://chromium-review.googlesource.com/1177712Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Finnur Thorarinsson <finnur@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584478}
parent 0547b7af
...@@ -124,7 +124,7 @@ public class ContactView extends SelectableItemView<ContactDetails> { ...@@ -124,7 +124,7 @@ public class ContactView extends SelectableItemView<ContactDetails> {
mDisplayName.setText(displayName); mDisplayName.setText(displayName);
mEmails.setText(contactDetails.getEmailsAsString()); mEmails.setText(contactDetails.getEmailsAsString());
Bitmap icon = mCategoryView.getIconGenerator().generateIconForText( Bitmap icon = mCategoryView.getIconGenerator().generateIconForText(
contactDetails.getDisplayNameAbbreviation()); contactDetails.getDisplayNameAbbreviation(), 2);
mImage.setImageBitmap(icon); mImage.setImageBitmap(icon);
updateSelectionState(); updateSelectionState();
......
...@@ -99,18 +99,30 @@ public class RoundedIconGenerator { ...@@ -99,18 +99,30 @@ public class RoundedIconGenerator {
} }
/** /**
* Generates an icon based on |text|. * Generates an icon based on |text| (using the first character).
* *
* @param text The text to render the first character of on the icon. * @param text The text to render the first character of on the icon.
* @return The generated icon. * @return The generated icon.
*/ */
public Bitmap generateIconForText(String text) { public Bitmap generateIconForText(String text) {
return generateIconForText(text, 1);
}
/**
* Generates an icon based on |text|.
*
* @param text The text to render on the icon.
* @param numChars The maximum number of characters to return.
* @return The generated icon.
*/
public Bitmap generateIconForText(String text, int numChars) {
Bitmap icon = Bitmap.createBitmap(mIconWidthPx, mIconHeightPx, Bitmap.Config.ARGB_8888); Bitmap icon = Bitmap.createBitmap(mIconWidthPx, mIconHeightPx, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(icon); Canvas canvas = new Canvas(icon);
canvas.drawRoundRect(mBackgroundRect, mCornerRadiusPx, mCornerRadiusPx, mBackgroundPaint); canvas.drawRoundRect(mBackgroundRect, mCornerRadiusPx, mCornerRadiusPx, mBackgroundPaint);
String displayText = text.substring(0, 1).toUpperCase(Locale.getDefault()); int length = Math.min(numChars, text.length());
String displayText = text.substring(0, length).toUpperCase(Locale.getDefault());
float textWidth = mTextPaint.measureText(displayText); float textWidth = mTextPaint.measureText(displayText);
canvas.drawText( canvas.drawText(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment