From 2b8f7c0bbccbbaea7bb7e46473969cbd4199fde3 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sun, 28 Nov 2010 21:48:25 +0000 Subject: [PATCH] unify all our beeping, buzzing and flashing codepaths --- src/com/fsck/k9/K9.java | 12 +++-- .../k9/controller/MessagingController.java | 46 ++++++++++--------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/com/fsck/k9/K9.java b/src/com/fsck/k9/K9.java index 59bb20997..ebde1c748 100644 --- a/src/com/fsck/k9/K9.java +++ b/src/com/fsck/k9/K9.java @@ -255,19 +255,21 @@ public class K9 extends Application public static final int BOOT_RECEIVER_WAKE_LOCK_TIMEOUT = 60000; /** - * Time the LED is on when blinking on new email notification + * Time the LED is on/off when blinking on new email notification */ public static final int NOTIFICATION_LED_ON_TIME = 500; - - /** - * Time the LED is off when blicking on new email notification - */ public static final int NOTIFICATION_LED_OFF_TIME = 2000; public static final boolean NOTIFICATION_LED_WHILE_SYNCING = false; public static final int NOTIFICATION_LED_FAST_ON_TIME = 100; public static final int NOTIFICATION_LED_FAST_OFF_TIME = 100; + + public static final int NOTIFICATION_LED_BLINK_SLOW = 0; + public static final int NOTIFICATION_LED_BLINK_FAST = 1; + + + public static final int NOTIFICATION_LED_SENDING_FAILURE_COLOR = 0xffff0000; // Must not conflict with an account number diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index 6807d7109..1841f5077 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -3433,10 +3433,7 @@ public class MessagingController implements Runnable if (K9.NOTIFICATION_LED_WHILE_SYNCING) { - notif.flags |= Notification.FLAG_SHOW_LIGHTS; - notif.ledARGB = account.getNotificationSetting().getLedColor(); - notif.ledOnMS = K9.NOTIFICATION_LED_FAST_ON_TIME; - notif.ledOffMS = K9.NOTIFICATION_LED_FAST_OFF_TIME; + configureNotification(notif, null, null, account.getNotificationSetting().getLedColor(), K9.NOTIFICATION_LED_BLINK_FAST, true); } notifMgr.notify(K9.FETCHING_EMAIL_NOTIFICATION - account.getAccountNumber(), notif); @@ -3453,11 +3450,8 @@ public class MessagingController implements Runnable notif.setLatestEventInfo(mApplication, mApplication.getString(R.string.send_failure_subject), lastFailure.getMessage(), pi); - notif.flags |= Notification.FLAG_SHOW_LIGHTS; + configureNotification(notif, null, null, K9.NOTIFICATION_LED_SENDING_FAILURE_COLOR, K9.NOTIFICATION_LED_BLINK_FAST, true); notif.flags |= Notification.FLAG_AUTO_CANCEL; - notif.ledARGB = K9.NOTIFICATION_LED_SENDING_FAILURE_COLOR; - notif.ledOnMS = K9.NOTIFICATION_LED_FAST_ON_TIME; - notif.ledOffMS = K9.NOTIFICATION_LED_FAST_OFF_TIME; notifMgr.notify(-1500 - account.getAccountNumber(), notif); } @@ -3476,12 +3470,10 @@ public class MessagingController implements Runnable notif.setLatestEventInfo(mApplication, mApplication.getString(R.string.notification_bg_sync_title), account.getDescription() + mApplication.getString(R.string.notification_bg_title_separator) + folder.getName(), pi); notif.flags = Notification.FLAG_ONGOING_EVENT; + if (K9.NOTIFICATION_LED_WHILE_SYNCING) { - notif.flags |= Notification.FLAG_SHOW_LIGHTS; - notif.ledARGB = account.getNotificationSetting().getLedColor(); - notif.ledOnMS = K9.NOTIFICATION_LED_FAST_ON_TIME; - notif.ledOffMS = K9.NOTIFICATION_LED_FAST_OFF_TIME; + configureNotification(notif, null, null, account.getNotificationSetting().getLedColor(), K9.NOTIFICATION_LED_BLINK_FAST, true); } notifMgr.notify(K9.FETCHING_EMAIL_NOTIFICATION - account.getAccountNumber(), notif); @@ -4716,7 +4708,7 @@ public class MessagingController implements Runnable NotificationSetting n = account.getNotificationSetting(); - configureNotification(notif, ( n.shouldRing() ? n.getRingtone() : null), (n.shouldVibrate() ? n.getVibration() : null), (n.isLed() ? n.getLedColor() : null), ringAndVibrate); + configureNotification(notif, ( n.shouldRing() ? n.getRingtone() : null), (n.shouldVibrate() ? n.getVibration() : null), (n.isLed() ? n.getLedColor() : null), K9.NOTIFICATION_LED_BLINK_SLOW, ringAndVibrate); notifMgr.notify(account.getAccountNumber(), notif); return true; @@ -4731,17 +4723,19 @@ public class MessagingController implements Runnable * long[] vibration pattern. null if no vibration should be played * @param ledColor * Integer Color to flash LED. null if no LED flash should happen + * @param ledSpeed + * int should LEDs flash K9.NOTIFICATION_LED_BLINK_SLOW or K9.NOTIFICATION_LED_BLINK_FAST * @param ringAndVibrate * true if ringtone/vibration are allowed, * false otherwise. */ - private void configureNotification(final Notification notification, - final String ringtone, - final long[] vibrationPattern, - final Integer ledColor, - - - final boolean ringAndVibrate) + private void configureNotification(final Notification notification, + final String ringtone, + final long[] vibrationPattern, + final Integer ledColor, + final int ledSpeed, + + final boolean ringAndVibrate) { if (ringAndVibrate) { @@ -4760,8 +4754,16 @@ public class MessagingController implements Runnable { notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.ledARGB = ledColor; - notification.ledOnMS = K9.NOTIFICATION_LED_ON_TIME; - notification.ledOffMS = K9.NOTIFICATION_LED_OFF_TIME; + if (ledSpeed == K9.NOTIFICATION_LED_BLINK_SLOW) + { + notification.ledOnMS = K9.NOTIFICATION_LED_ON_TIME; + notification.ledOffMS = K9.NOTIFICATION_LED_OFF_TIME; + } + else if (ledSpeed == K9.NOTIFICATION_LED_BLINK_FAST) + { + notification.ledOnMS = K9.NOTIFICATION_LED_FAST_ON_TIME; + notification.ledOffMS = K9.NOTIFICATION_LED_FAST_OFF_TIME; + } } }