summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Kennedy <skennedy@google.com>2013-06-27 14:42:41 -0700
committerScott Kennedy <skennedy@google.com>2013-06-27 15:13:08 -0700
commitc94c80c8b8c92c019f19f2e315dea1ff03ad573f (patch)
treebf1744bb0d5786fbd07763f3674b65cbe1ed274a
parent4046d0695e102368201bb2f3a268a4f85c8bc4db (diff)
downloadandroid_packages_apps_UnifiedEmail-c94c80c8b8c92c019f19f2e315dea1ff03ad573f.tar.gz
android_packages_apps_UnifiedEmail-c94c80c8b8c92c019f19f2e315dea1ff03ad573f.tar.bz2
android_packages_apps_UnifiedEmail-c94c80c8b8c92c019f19f2e315dea1ff03ad573f.zip
Use letter tiles in notifications
For notifications where we would display a contact photo if it existed, we will now show a letter tile if we can make one. Bug: 9597536 Change-Id: Idb060d2c055074ff930154c12ddfff7d960dbf75
-rw-r--r--src/com/android/mail/photomanager/LetterTileProvider.java35
-rw-r--r--src/com/android/mail/utils/NotificationUtils.java57
2 files changed, 63 insertions, 29 deletions
diff --git a/src/com/android/mail/photomanager/LetterTileProvider.java b/src/com/android/mail/photomanager/LetterTileProvider.java
index 36dc6c2e6..39730b5eb 100644
--- a/src/com/android/mail/photomanager/LetterTileProvider.java
+++ b/src/com/android/mail/photomanager/LetterTileProvider.java
@@ -102,19 +102,28 @@ public class LetterTileProvider implements DefaultImageProvider {
return;
}
- Bitmap bitmap = null;
+ dividedImageView.getDesiredDimensions(address, mDims);
+
+ final Bitmap bitmap = getLetterTile(mDims, displayName, address);
+
+ if (bitmap == null) {
+ return;
+ }
+
+ dividedImageView.addDivisionImage(bitmap, address);
+ }
+
+ public Bitmap getLetterTile(final Dimensions dimensions, final String displayName,
+ final String address) {
final String display = !TextUtils.isEmpty(displayName) ? displayName : address;
final char firstChar = display.charAt(0);
- dividedImageView.getDesiredDimensions(address, mDims);
// get an empty bitmap
- bitmap = getBitmap(mDims, false /* getDefault */);
+ final Bitmap bitmap = getBitmap(dimensions, false /* getDefault */);
if (bitmap == null) {
- LogUtils.w(TAG, "LetterTileProvider width(%d) or height(%d) is 0" +
- " for name %s and address %s.",
- dividedImageView.getWidth(), dividedImageView.getHeight(), displayName,
- address);
- return;
+ LogUtils.w(TAG, "LetterTileProvider width(%d) or height(%d) is 0 for name %s and "
+ + "address %s.", dimensions.width, dimensions.height, displayName, address);
+ return null;
}
final Canvas c = mCanvas;
@@ -125,15 +134,15 @@ public class LetterTileProvider implements DefaultImageProvider {
// draw the letter on top of the color
if (isEnglishLetterOrDigit(firstChar)) {
mFirstChar[0] = Character.toUpperCase(firstChar);
- mPaint.setTextSize(getFontSize(mDims.scale));
+ mPaint.setTextSize(getFontSize(dimensions.scale));
mPaint.getTextBounds(mFirstChar, 0, 1, mBounds);
- c.drawText(mFirstChar, 0, 1, 0 + mDims.width / 2,
- 0 + mDims.height / 2 + (mBounds.bottom - mBounds.top) / 2, mPaint);
+ c.drawText(mFirstChar, 0, 1, 0 + dimensions.width / 2,
+ 0 + dimensions.height / 2 + (mBounds.bottom - mBounds.top) / 2, mPaint);
} else { // draw the generic icon on top
- c.drawBitmap(getBitmap(mDims, true /* getDefault */), 0, 0, null);
+ c.drawBitmap(getBitmap(dimensions, true /* getDefault */), 0, 0, null);
}
- dividedImageView.addDivisionImage(bitmap, address);
+ return bitmap;
}
private static boolean isEnglishLetterOrDigit(char c) {
diff --git a/src/com/android/mail/utils/NotificationUtils.java b/src/com/android/mail/utils/NotificationUtils.java
index ffd6a47e3..7873ffe1f 100644
--- a/src/com/android/mail/utils/NotificationUtils.java
+++ b/src/com/android/mail/utils/NotificationUtils.java
@@ -46,6 +46,7 @@ import com.android.mail.MailIntentService;
import com.android.mail.R;
import com.android.mail.browse.MessageCursor;
import com.android.mail.browse.SendersView;
+import com.android.mail.photomanager.ContactPhotoManager;
import com.android.mail.preferences.AccountPreferences;
import com.android.mail.preferences.FolderPreferences;
import com.android.mail.preferences.MailPrefs;
@@ -55,6 +56,7 @@ import com.android.mail.providers.Conversation;
import com.android.mail.providers.Folder;
import com.android.mail.providers.Message;
import com.android.mail.providers.UIProvider;
+import com.android.mail.ui.ImageCanvas.Dimensions;
import com.android.mail.utils.NotificationActionUtils.NotificationAction;
import com.google.android.common.html.parser.HTML;
import com.google.android.common.html.parser.HTML4;
@@ -673,14 +675,21 @@ public class NotificationUtils {
private static Bitmap getDefaultNotificationIcon(
final Context context, final Folder folder, final boolean multipleNew) {
- final Bitmap icon;
+ final int resId;
if (folder.notificationIconResId != 0) {
- icon = getIcon(context, folder.notificationIconResId);
+ resId = folder.notificationIconResId;
} else if (multipleNew) {
- icon = getIcon(context, R.drawable.ic_notification_multiple_mail_holo_dark);
+ resId = R.drawable.ic_notification_multiple_mail_holo_dark;
} else {
- icon = getIcon(context, R.drawable.ic_contact_picture);
+ resId = R.drawable.ic_contact_picture;
}
+
+ final Bitmap icon = getIcon(context, resId);
+
+ if (icon == null) {
+ LogUtils.e(LOG_TAG, "Couldn't decode notif icon res id %d", resId);
+ }
+
return icon;
}
@@ -841,7 +850,7 @@ public class NotificationUtils {
fromAddress = message.getFrom();
from = getDisplayableSender(fromAddress);
notification.setLargeIcon(
- getContactIcon(context, getSenderAddress(fromAddress), folder));
+ getContactIcon(context, from, getSenderAddress(fromAddress), folder));
}
// Assume that the last message in this conversation is unread
@@ -1284,22 +1293,25 @@ public class NotificationUtils {
return contactIds;
}
- private static Bitmap getContactIcon(
- Context context, String senderAddress, final Folder folder) {
+ private static Bitmap getContactIcon(final Context context, final String displayName,
+ final String senderAddress, final Folder folder) {
if (senderAddress == null) {
return null;
}
+
Bitmap icon = null;
- final List<Long> contactIds = findContacts(
- context, Arrays.asList(new String[] { senderAddress }));
+
+ final List<Long> contactIds = findContacts( context, Arrays.asList(
+ new String[] { senderAddress }));
+
+ // Get the ideal size for this icon.
+ final Resources res = context.getResources();
+ final int idealIconHeight =
+ res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
+ final int idealIconWidth =
+ res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
if (contactIds != null) {
- // Get the ideal size for this icon.
- final Resources res = context.getResources();
- final int idealIconHeight =
- res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
- final int idealIconWidth =
- res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
for (final long id : contactIds) {
final Uri contactUri =
ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id);
@@ -1329,8 +1341,21 @@ public class NotificationUtils {
}
}
}
+
+ if (icon == null) {
+ // Make a colorful tile!
+ final ContactPhotoManager contactPhotoManager =
+ ContactPhotoManager.getInstance(context);
+
+ final Dimensions dimensions = new Dimensions(idealIconWidth, idealIconHeight,
+ Dimensions.SCALE_ONE);
+
+ icon = contactPhotoManager.getDefaultImageProvider().getLetterTile(dimensions,
+ displayName, senderAddress);
+ }
+
if (icon == null) {
- // icon should be the default gmail icon.
+ // Icon should be the default mail icon.
icon = getDefaultNotificationIcon(context, folder, false /* single new message */);
}
return icon;