1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 03:32:16 -05:00

. Added silent 'on going' notification when checking email

This commit is contained in:
Bao-Long Nguyen-Trong 2008-12-19 22:30:55 +00:00
parent b9dec4064e
commit 56d1ede846
3 changed files with 73 additions and 45 deletions

View File

@ -69,6 +69,9 @@
<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>
<string name="notification_bg_sync_ticker">Checking email: <xliff:g id="account">%s</xliff:g></string>
<string name="notification_bg_sync_title">Checking email</string>
<string name="special_mailbox_name_inbox">Inbox</string>
<string name="special_mailbox_name_outbox">Outbox</string>
<!-- The following mailbox names will be used if the user has not specified one from the server -->

View File

@ -121,6 +121,7 @@ public class Email extends Application {
public static final int NOTIFICATION_LED_OFF_TIME = 2000;
public static final int NEW_EMAIL_NOTIFICATION_ID = 1;
public static final int FETCHING_EMAIL_NOTIFICATION_ID = 2;
/**
* Called throughout the application when the number of accounts has changed. This method

View File

@ -10,11 +10,16 @@ import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import android.app.Application;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Process;
import android.util.Config;
import android.util.Log;
import com.android.email.activity.FolderMessageList;
import com.android.email.mail.FetchProfile;
import com.android.email.mail.Flag;
import com.android.email.mail.Folder;
@ -1432,6 +1437,9 @@ s * critical data as fast as possible, and then we'll fill in the de
}
put("checkMail", listener, new Runnable() {
public void run() {
NotificationManager notifMgr = (NotificationManager)context
.getSystemService(Context.NOTIFICATION_SERVICE);
try {
Account[] accounts;
if (account != null) {
accounts = new Account[] {
@ -1448,6 +1456,13 @@ s * critical data as fast as possible, and then we'll fill in the de
long lastAutoCheckTime = (long)Math.ceil(account.getLastAutomaticCheckTime() / 1000);
if (autoCheckIntervalTime>0
&& (now-lastAutoCheckTime)>autoCheckIntervalTime) {
Notification notif = new Notification(R.drawable.ic_menu_refresh, context.getString(R.string.notification_bg_sync_ticker, account.getDescription()), System.currentTimeMillis());
Intent intent = FolderMessageList.actionHandleAccountIntent(context, account, Email.INBOX);
PendingIntent pi = PendingIntent.getActivity(context, 0, intent, 0);
notif.setLatestEventInfo(context, context.getString(R.string.notification_bg_sync_title), account.getDescription(), pi);
notif.flags = Notification.FLAG_ONGOING_EVENT;
notifMgr.notify(Email.FETCHING_EMAIL_NOTIFICATION_ID, notif);
sendPendingMessagesSynchronous(account);
synchronizeMailboxSynchronous(account, Email.INBOX);
//This saves the last auto check time even if sync fails
@ -1461,6 +1476,15 @@ s * critical data as fast as possible, and then we'll fill in the de
l.checkMailFinished(context, account);
}
}
catch (Exception e) {
for (MessagingListener l : mListeners) {
l.checkMailFailed(context, account, e.getMessage());
}
}
finally {
notifMgr.cancel(Email.FETCHING_EMAIL_NOTIFICATION_ID);
}
}
});
}