Merge "Refresh email notifications (part I)"

This commit is contained in:
Andy Stadler 2011-02-16 16:39:01 -08:00 committed by Android (Google) Code Review
commit d25610356d
3 changed files with 53 additions and 62 deletions

View File

@ -40,6 +40,14 @@
<string name="upgrade_accounts_title"></string>
<!-- Do Not Translate. Unused string. -->
<string name="upgrade_accounts_error"></string>
<!-- Do Not Translate. Unused string. -->
<string name="forward_download_failed_notification"></string>
<!-- Do Not Translate. Unused string. -->
<string name="login_failed_notification"></string>
<!-- Do Not Translate. Unused string. -->
<string name="password_expire_warning_content_text_fmt"></string>
<!-- Do Not Translate. Unused string. -->
<string name="password_expired_content_text"></string>
<!-- Name of application on Home screen -->
<string name="app_name">Email</string>
@ -413,16 +421,17 @@ save attachment.</string>
<item quantity="other" ><xliff:g id="num_message" example="5" >%1$d</xliff:g>
messages moved to <xliff:g id="mailbox_name" example="Inbox" >%2$s</xliff:g></item>
</plurals>
<!-- Notification ticker when a forwarded attachment couldn't be sent [CHAR LIMIT=none] -->
<string name="forward_download_failed_ticker">Could not forward one or more attachments</string>
<!-- Notification text when a forwarded attachment couldn't be sent [CHAR LIMIT=30]-->
<string name="forward_download_failed_notification">Could not forward <xliff:g id="filename">
%s</xliff:g></string>
<!-- Notification ticker when email account authentication fails [CHAR LIMIT=20] -->
<string name="login_failed_ticker"><xliff:g id="account_name">%s
</xliff:g> sign-in failed</string>
<!-- Notification text when email account authentication fails [CHAR LIMIT=75]-->
<string name="login_failed_notification">Touch to change account settings</string>
<!-- Notification title when a forwarded attachment couldn't be sent [CHAR LIMIT=30]-->
<string name="forward_download_failed_title">Attachment not forwarded</string>
<!-- Notification ticker when email account authentication fails [CHAR LIMIT=none] -->
<string name="login_failed_ticker">
<xliff:g id="account_name">%s</xliff:g> sign-in failed</string>
<!-- Notification title when email account authentication fails [CHAR LIMIT=30]-->
<string name="login_failed_title">Sign-in failed</string>
<!-- Size unit for bytes for attachments [CHAR LIMIT=10] -->
<plurals name="message_view_attachment_bytes">
@ -726,12 +735,12 @@ save attachment.</string>
to administer your device will delete all Email accounts that require it, along with their
email, contacts, calendar events, and other data.</string>
<!-- Notification ticker when device security required -->
<!-- Notification ticker when device security required (note: unused in Holo XL) -->
<string name="security_notification_ticker_fmt">
Account \"<xliff:g id="account">%s</xliff:g>\" requires security settings update.
</string>
<!-- Notification content title when device security required -->
<string name="security_notification_content_title">Update Security Settings</string>
<!-- Notification content title when device security required [CHAR_LIMIT=30] -->
<string name="security_notification_content_title">Security update required</string>
<!-- Title of the activity that dispatches changes to device security. Not normally seen. -->
<string name="account_security_title">Device Security</string>
<!-- Additional diagnostic text when the email app asserts control of the phone.
@ -745,24 +754,16 @@ save attachment.</string>
<!-- Notification ticker when device password is getting ready to expire [CHAR_LIMIT=80] -->
<string name="password_expire_warning_ticker_fmt">
Account \"<xliff:g id="account">%s</xliff:g>\" requires you to update your screen
unlock code.</string>
\"<xliff:g id="account">%s</xliff:g>\" requires you to change your lock screen
PIN or password.</string>
<!-- Notification content title when device password is getting ready to expire
[CHAR_LIMIT=28] -->
<string name="password_expire_warning_content_title">New screen unlock required</string>
<!-- Notification content text when device password is getting ready to expire
[CHAR_LIMIT=2 lines] -->
<string name="password_expire_warning_content_text_fmt">
Account \"<xliff:g id="account">%s</xliff:g>\" requires you to update your screen
unlock code. Touch here to update it.</string>
[CHAR_LIMIT=30] -->
<string name="password_expire_warning_content_title">Lock screen password expiring</string>
<!-- Notification ticker when device password has expired [CHAR_LIMIT=80] -->
<string name="password_expired_ticker">Your screen unlock code has expired.</string>
<string name="password_expired_ticker">Your lock screen PIN or password has expired.</string>
<!-- Notification content title when device password has expired [CHAR_LIMIT=28] -->
<string name="password_expired_content_title">New screen unlock required</string>
<!-- Notification content text when device password has expired [CHAR_LIMIT=2 lines] -->
<string name="password_expired_content_text">
Your screen unlock code has expired. Touch here to update it.</string>
<string name="password_expired_content_title">Lock screen password expired</string>
<!-- On AccountSettingsXL, dialog text if you try to exit in/out/eas fragment (server settings)
without checking/saving [CHAR LIMIT=none]-->

View File

@ -83,6 +83,7 @@ public class NotificationController {
/**
* Generic notifier for any account. Uses notification rules from account.
* NOTE: Ticker is not shown in Holo XL notifications.
*
* @param account The account for which the notification is posted
* @param ticker String for ticker
@ -95,8 +96,11 @@ public class NotificationController {
String contentText, Intent intent, int notificationId) {
// Pending Intent
PendingIntent pending =
PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pending = null;
if (intent != null) {
pending =
PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
// Ringtone & Vibration
String ringtoneString = account.getRingtone();
@ -293,37 +297,20 @@ public class NotificationController {
notification.defaults |= Notification.DEFAULT_LIGHTS;
}
/**
* Generic warning notification
*/
public void showWarningNotification(int id, String tickerText, String notificationText,
Intent intent) {
PendingIntent pendingIntent = null;
if (intent != null) {
pendingIntent = PendingIntent.getActivity(mContext, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
}
Builder b = new Builder(mContext);
b.setSmallIcon(android.R.drawable.stat_notify_error)
.setTicker(tickerText)
.setWhen(mClock.getTime())
.setContentTitle(tickerText)
.setContentText(notificationText)
.setContentIntent(pendingIntent)
.setAutoCancel(true);
Notification n = b.getNotification();
mNotificationManager.notify(id, n);
}
/**
* Alert the user that an attachment couldn't be forwarded. This is a very unusual case, and
* perhaps we shouldn't even send a notification. For now, it's helpful for debugging.
* NOTE: DO NOT CALL THIS METHOD FROM THE UI THREAD (DATABASE ACCESS)
*/
public void showDownloadForwardFailedNotification(Attachment att) {
showWarningNotification(NOTIFICATION_ID_ATTACHMENT_WARNING,
public void showDownloadForwardFailedNotification(Attachment attachment) {
final Account account = Account.restoreAccountWithId(mContext, attachment.mAccountKey);
if (account == null) return;
postAccountNotification(account,
mContext.getString(R.string.forward_download_failed_ticker),
mContext.getString(R.string.forward_download_failed_notification,
att.mFileName), null);
mContext.getString(R.string.forward_download_failed_title),
attachment.mFileName,
null,
NOTIFICATION_ID_ATTACHMENT_WARNING);
}
/**
@ -333,14 +320,19 @@ public class NotificationController {
return NOTIFICATION_ID_BASE_LOGIN_WARNING + (int)accountId;
}
// NOTE: DO NOT CALL THIS METHOD FROM THE UI THREAD (DATABASE ACCESS)
/**
* Alert the user that login failed on a particular account.
* NOTE: DO NOT CALL THIS METHOD FROM THE UI THREAD (DATABASE ACCESS)
*/
public void showLoginFailedNotification(long accountId) {
final Account account = Account.restoreAccountWithId(mContext, accountId);
if (account == null) return;
showWarningNotification(getLoginFailedNotificationId(accountId),
postAccountNotification(account,
mContext.getString(R.string.login_failed_ticker, account.mDisplayName),
mContext.getString(R.string.login_failed_notification),
AccountSettingsXL.createAccountSettingsIntent(mContext, accountId));
mContext.getString(R.string.login_failed_title),
account.getDisplayName(),
AccountSettingsXL.createAccountSettingsIntent(mContext, accountId),
getLoginFailedNotificationId(accountId));
}
public void cancelLoginFailedNotification(long accountId) {

View File

@ -586,8 +586,7 @@ public class SecurityPolicy {
R.string.password_expire_warning_ticker_fmt, account.getDisplayName());
String contentTitle = context.getString(
R.string.password_expire_warning_content_title);
String contentText = context.getString(
R.string.password_expire_warning_content_text_fmt, account.getDisplayName());
String contentText = account.getDisplayName();
NotificationController nc = NotificationController.getInstance(mContext);
nc.postAccountNotification(account, ticker, contentTitle, contentText, intent,
NotificationController.NOTIFICATION_ID_PASSWORD_EXPIRING);
@ -598,11 +597,10 @@ public class SecurityPolicy {
// Post notification
Account account = Account.restoreAccountWithId(context, nextExpiringAccountId);
if (account == null) return;
Intent intent =
new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
String ticker = context.getString(R.string.password_expired_ticker);
String contentTitle = context.getString(R.string.password_expired_content_title);
String contentText = context.getString(R.string.password_expired_content_text);
String contentText = account.getDisplayName();
NotificationController nc = NotificationController.getInstance(mContext);
nc.postAccountNotification(account, ticker, contentTitle,
contentText, intent,