mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
Now display a new email notification per account. Each notification now opens the account (does not go to the Accounts screen anymore)
Note: Notifications are displayed after all accounts are sync'ed but are delayed to be 1sec. apart TODO: Display notifications at the end of each individual sync
This commit is contained in:
parent
3dfabbbd0c
commit
41dc1ca8d8
@ -89,6 +89,14 @@
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.android.email.activity.FolderMessageList">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.view" />
|
||||
<data
|
||||
android:scheme="content"
|
||||
android:path="/email/accounts/*"
|
||||
/>
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.android.email.activity.MessageView">
|
||||
|
@ -82,6 +82,7 @@
|
||||
<string name="notification_new_title">New email</string>
|
||||
<string name="notification_new_scrolling">New email from <xliff:g id="sender">%s</xliff:g></string>
|
||||
<string name="notification_new_one_account_fmt"><xliff:g id="unread_message_count">%d</xliff:g> Unread (<xliff:g id="account">%s</xliff:g>)</string> <!-- 279 Unread (someone@google.com) -->
|
||||
<string name="notification_new_one_account_unknown_unread_count_fmt"><xliff:g id="new_message_count">%d</xliff:g> New Email(s) (<xliff:g id="account">%s</xliff:g>)</string> <!-- 2 New Email(s) (someone@google.com) -->
|
||||
<string name="notification_new_multi_account_fmt">in <xliff:g id="number_accounts">%d</xliff:g> accounts</string>
|
||||
<string name="notification_unsent_title">Message not sent</string>
|
||||
|
||||
|
@ -151,6 +151,10 @@ public class Email extends Application {
|
||||
|
||||
public static final int FLAGGED_COLOR = 0xffff4444;
|
||||
|
||||
public static final String INTENT_DATA_URI_SCHEMA = "content";
|
||||
public static final String INTENT_DATA_UR_PATH_PREFIX = "email";
|
||||
public static final String INTENT_DATA_URI_PREFIX = INTENT_DATA_URI_SCHEMA + "://" + INTENT_DATA_UR_PATH_PREFIX;
|
||||
|
||||
/**
|
||||
* Called throughout the application when the number of accounts has changed. This method
|
||||
* enables or disables the Compose activity, the boot receiver and the service based on
|
||||
|
@ -16,6 +16,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Process;
|
||||
@ -80,6 +81,8 @@ import com.android.email.mail.store.LocalStore;
|
||||
*/
|
||||
public class FolderMessageList extends ExpandableListActivity
|
||||
{
|
||||
private static final String INTENT_DATA_PATH_SUFFIX = "/accounts";
|
||||
|
||||
private static final String EXTRA_ACCOUNT = "account";
|
||||
|
||||
private static final String EXTRA_CLEAR_NOTIFICATION = "clearNotification";
|
||||
@ -453,7 +456,8 @@ public class FolderMessageList extends ExpandableListActivity
|
||||
public static Intent actionHandleAccountIntent(Context context,
|
||||
Account account, String initialFolder)
|
||||
{
|
||||
Intent intent = new Intent(context, FolderMessageList.class);
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Email.INTENT_DATA_URI_PREFIX + INTENT_DATA_PATH_SUFFIX + "/" + account.getAccountNumber()), context, FolderMessageList.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra(EXTRA_ACCOUNT, account);
|
||||
intent.putExtra(EXTRA_CLEAR_NOTIFICATION, true);
|
||||
if (initialFolder != null)
|
||||
|
@ -221,86 +221,67 @@ public class MailService extends Service {
|
||||
|
||||
private void checkMailDone(Context context, Account doNotUseaccount)
|
||||
{
|
||||
if (accountsWithNewMail.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
StringBuffer notice = new StringBuffer();
|
||||
int accountNumber = Email.FETCHING_EMAIL_NOTIFICATION_NO_ACCOUNT;
|
||||
if (accountsWithNewMail.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
boolean vibrate = false;
|
||||
String ringtone = null;
|
||||
for (Account thisAccount : Preferences.getPreferences(context).getAccounts()) {
|
||||
if (thisAccount.isNotifyNewMail())
|
||||
{
|
||||
int unreadMessageCount = 0;
|
||||
try
|
||||
{
|
||||
unreadMessageCount = thisAccount.getUnreadMessageCount(context, getApplication());
|
||||
if (unreadMessageCount > 0)
|
||||
{
|
||||
notice.append(getString(R.string.notification_new_one_account_fmt, unreadMessageCount,
|
||||
thisAccount.getDescription()) + "\n");
|
||||
if (accountNumber != Email.FETCHING_EMAIL_NOTIFICATION_MULTI_ACCOUNT_ID) // if already set to Multi, nothing to do
|
||||
{
|
||||
if (accountNumber == Email.FETCHING_EMAIL_NOTIFICATION_NO_ACCOUNT) // Haven't set to anything, yet, set to this account number
|
||||
{
|
||||
accountNumber = thisAccount.getAccountNumber();
|
||||
}
|
||||
else // Another account was already set, so there is more than one with new mail
|
||||
{
|
||||
accountNumber = Email.FETCHING_EMAIL_NOTIFICATION_MULTI_ACCOUNT_ID;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (MessagingException me)
|
||||
{
|
||||
Log.e(Email.LOG_TAG, "***** MailService *****: couldn't get unread count for account " +
|
||||
thisAccount.getDescription(), me);
|
||||
}
|
||||
if (accountsWithNewMail.containsKey(thisAccount.getUuid()))
|
||||
{
|
||||
if (ringtone == null)
|
||||
{
|
||||
ringtone = thisAccount.getRingtone();
|
||||
}
|
||||
vibrate |= thisAccount.isVibrate();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (notice.length() > 0)
|
||||
{
|
||||
NotificationManager notifMgr =
|
||||
(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
NotificationManager notifMgr =
|
||||
(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
Notification notif = new Notification(R.drawable.stat_notify_email_generic,
|
||||
getString(R.string.notification_new_title), System.currentTimeMillis());
|
||||
int index = 0;
|
||||
for (Account thisAccount : Preferences.getPreferences(context).getAccounts()) {
|
||||
//No need to filter out accounts that do not require notification
|
||||
//since only the one that require so are in this map
|
||||
if (accountsWithNewMail.containsKey(thisAccount.getUuid()))
|
||||
{
|
||||
String notice = null;
|
||||
try
|
||||
{
|
||||
int unreadMessageCount = thisAccount.getUnreadMessageCount(context, getApplication());
|
||||
if (unreadMessageCount > 0)
|
||||
{
|
||||
notice = getString(R.string.notification_new_one_account_fmt, unreadMessageCount,
|
||||
thisAccount.getDescription());
|
||||
}
|
||||
//Can this ever happen?
|
||||
else
|
||||
{
|
||||
notice = getString(R.string.notification_new_one_account_unknown_unread_count_fmt, (int)accountsWithNewMail.get(thisAccount.getUuid()), thisAccount.getDescription());
|
||||
}
|
||||
}
|
||||
catch (MessagingException me)
|
||||
{
|
||||
Log.e(Email.LOG_TAG, "***** MailService *****: couldn't get unread count for account " +
|
||||
thisAccount.getDescription(), me);
|
||||
notice = getString(R.string.notification_new_one_account_unknown_unread_count_fmt, (int)accountsWithNewMail.get(thisAccount.getUuid()), thisAccount.getDescription());
|
||||
}
|
||||
|
||||
// If only one account has mail, maybe go back to the old way of targetting the account.
|
||||
Intent i = new Intent(context, Accounts.class);
|
||||
PendingIntent pi = PendingIntent.getActivity(context, 0, i, 0);
|
||||
Notification notif = new Notification(R.drawable.stat_notify_email_generic,
|
||||
getString(R.string.notification_new_title), System.currentTimeMillis() + (index*1000));
|
||||
|
||||
notif.setLatestEventInfo(context, getString(R.string.notification_new_title),
|
||||
notice, pi);
|
||||
Intent i = FolderMessageList.actionHandleAccountIntent(context, thisAccount, Email.INBOX);
|
||||
|
||||
Log.v(Email.LOG_TAG, "Using ringtone " + ringtone + " and vibrate = " + vibrate);
|
||||
PendingIntent pi = PendingIntent.getActivity(context, 0, i, 0);
|
||||
|
||||
// notif.defaults = Notification.DEFAULT_LIGHTS;
|
||||
notif.sound = TextUtils.isEmpty(ringtone) ? null : Uri.parse(ringtone);
|
||||
if (vibrate) {
|
||||
notif.defaults |= Notification.DEFAULT_VIBRATE;
|
||||
}
|
||||
notif.setLatestEventInfo(context, getString(R.string.notification_new_title), notice, pi);
|
||||
|
||||
notif.flags |= Notification.FLAG_SHOW_LIGHTS;
|
||||
notif.ledARGB = Email.NOTIFICATION_LED_COLOR;
|
||||
notif.ledOnMS = Email.NOTIFICATION_LED_ON_TIME;
|
||||
notif.ledOffMS = Email.NOTIFICATION_LED_OFF_TIME;
|
||||
String ringtone = thisAccount.getRingtone();
|
||||
notif.sound = TextUtils.isEmpty(ringtone) ? null : Uri.parse(ringtone);
|
||||
|
||||
notifMgr.notify(accountNumber, notif);
|
||||
}
|
||||
if (thisAccount.isVibrate()) {
|
||||
notif.defaults |= Notification.DEFAULT_VIBRATE;
|
||||
}
|
||||
|
||||
}
|
||||
notif.flags |= Notification.FLAG_SHOW_LIGHTS;
|
||||
notif.ledARGB = Email.NOTIFICATION_LED_COLOR;
|
||||
notif.ledOnMS = Email.NOTIFICATION_LED_ON_TIME;
|
||||
notif.ledOffMS = Email.NOTIFICATION_LED_OFF_TIME;
|
||||
|
||||
notifMgr.notify(thisAccount.getAccountNumber(), notif);
|
||||
}
|
||||
}//for accounts
|
||||
}//checkMailDone
|
||||
|
||||
private void release()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user