From 89ff98b93d89fd8378d2606024ef9cc6cf3416ce Mon Sep 17 00:00:00 2001 From: "Daniel E. Moctezuma" Date: Thu, 27 Sep 2012 16:18:20 -0700 Subject: [PATCH] Added support for LED light notification on nickname highlight --- application/res/values/settings.xml | 3 +++ application/res/values/strings.xml | 2 ++ application/res/xml/preferences.xml | 6 +++++ .../src/org/yaaic/irc/IRCConnection.java | 10 ++++--- application/src/org/yaaic/irc/IRCService.java | 26 +++++++++++++------ application/src/org/yaaic/model/Settings.java | 14 ++++++++++ 6 files changed, 50 insertions(+), 11 deletions(-) diff --git a/application/res/values/settings.xml b/application/res/values/settings.xml index 7e92dd5..f783f46 100644 --- a/application/res/values/settings.xml +++ b/application/res/values/settings.xml @@ -42,6 +42,9 @@ sound_highlight false + led_highlight + true + notice_server_window false diff --git a/application/res/values/strings.xml b/application/res/values/strings.xml index a2f5d57..4e7fbdb 100644 --- a/application/res/values/strings.xml +++ b/application/res/values/strings.xml @@ -205,6 +205,8 @@ Play sound when your nick is mentioned Vibrate on highlight Vibrate when your nick is mentioned + Flash LED on highlight + Flash LED light when your nick is mentioned Misc Quit message diff --git a/application/res/xml/preferences.xml b/application/res/xml/preferences.xml index 64fb475..6590956 100644 --- a/application/res/xml/preferences.xml +++ b/application/res/xml/preferences.xml @@ -3,6 +3,7 @@ Yaaic - Yet Another Android IRC Client Copyright 2009-2012 Sebastian Kaspari +Copyright 2012 Daniel E. Moctezuma This file is part of Yaaic. @@ -133,6 +134,11 @@ along with Yaaic. If not, see . android:summary="@string/settings_vibrate_highlight_desc" android:key="@string/key_vibrate_highlight" android:defaultValue="@string/default_vibrate_highlight" /> + diff --git a/application/src/org/yaaic/irc/IRCConnection.java b/application/src/org/yaaic/irc/IRCConnection.java index 2bf1a3b..102524e 100644 --- a/application/src/org/yaaic/irc/IRCConnection.java +++ b/application/src/org/yaaic/irc/IRCConnection.java @@ -2,6 +2,7 @@ Yaaic - Yet Another Android IRC Client Copyright 2009-2012 Sebastian Kaspari +Copyright 2012 Daniel E. Moctezuma This file is part of Yaaic. @@ -281,7 +282,8 @@ public class IRCConnection extends PircBot conversation, conversation.getName() + ": " + sender + " " + action, service.getSettings().isVibrateHighlightEnabled(), - service.getSettings().isSoundHighlightEnabled() + service.getSettings().isSoundHighlightEnabled(), + service.getSettings().isLedHighlightEnabled() ); } } @@ -458,7 +460,8 @@ public class IRCConnection extends PircBot conversation, target + ": <" + sender + "> " + text, service.getSettings().isVibrateHighlightEnabled(), - service.getSettings().isSoundHighlightEnabled() + service.getSettings().isSoundHighlightEnabled(), + service.getSettings().isLedHighlightEnabled() ); } @@ -669,7 +672,8 @@ public class IRCConnection extends PircBot conversation, "<" + sender + "> " + text, service.getSettings().isVibrateHighlightEnabled(), - service.getSettings().isSoundHighlightEnabled() + service.getSettings().isSoundHighlightEnabled(), + service.getSettings().isLedHighlightEnabled() ); } diff --git a/application/src/org/yaaic/irc/IRCService.java b/application/src/org/yaaic/irc/IRCService.java index f7008d1..818aa76 100644 --- a/application/src/org/yaaic/irc/IRCService.java +++ b/application/src/org/yaaic/irc/IRCService.java @@ -2,6 +2,7 @@ Yaaic - Yet Another Android IRC Client Copyright 2009-2012 Sebastian Kaspari +Copyright 2012 Daniel E. Moctezuma This file is part of Yaaic. @@ -211,14 +212,15 @@ public class IRCService extends Service } /** - * Update notification and vibrate if needed + * Update notification and vibrate and/or flash a LED light if needed * * @param text The ticker text to display * @param contentText The text to display in the notification dropdown * @param vibrate True if the device should vibrate, false otherwise * @param sound True if the device should make sound, false otherwise + * @param light True if the device should flash a LED light, false otherwise */ - private void updateNotification(String text, String contentText, boolean vibrate, boolean sound) + private void updateNotification(String text, String contentText, boolean vibrate, boolean sound, boolean light) { if (foreground) { notification = new Notification(R.drawable.icon, text, System.currentTimeMillis()); @@ -254,6 +256,13 @@ public class IRCService extends Service notification.defaults |= Notification.DEFAULT_SOUND; } + if (light) { + notification.ledARGB = 0xff00ff00; + notification.ledOnMS = 300; + notification.ledOffMS = 1000; + notification.flags |= Notification.FLAG_SHOW_LIGHTS; + } + notification.number = newMentions; notificationManager.notify(FOREGROUND_NOTIFICATION, notification); @@ -274,8 +283,9 @@ public class IRCService extends Service * @param msg The text of the new message * @param vibrate Whether the notification should include vibration * @param sound Whether the notification should include sound + * @param light Whether the notification should include a flashing LED light */ - public synchronized void addNewMention(int serverId, Conversation conversation, String msg, boolean vibrate, boolean sound) + public synchronized void addNewMention(int serverId, Conversation conversation, String msg, boolean vibrate, boolean sound, boolean light) { if (conversation == null) { return; @@ -289,9 +299,9 @@ public class IRCService extends Service } if (newMentions == 1) { - updateNotification(msg, msg, vibrate, sound); + updateNotification(msg, msg, vibrate, sound, light); } else { - updateNotification(msg, null, vibrate, sound); + updateNotification(msg, null, vibrate, sound, light); } } @@ -316,7 +326,7 @@ public class IRCService extends Service newMentions = 0; } - updateNotification(null, null, false, false); + updateNotification(null, null, false, false, false); } /** @@ -327,7 +337,7 @@ public class IRCService extends Service public synchronized void notifyConnected(String title) { connectedServerTitles.add(title); - updateNotification(getString(R.string.notification_connected, title), null, false, false); + updateNotification(getString(R.string.notification_connected, title), null, false, false, false); } /** @@ -338,7 +348,7 @@ public class IRCService extends Service public synchronized void notifyDisconnected(String title) { connectedServerTitles.remove(title); - updateNotification(getString(R.string.notification_disconnected, title), null, false, false); + updateNotification(getString(R.string.notification_disconnected, title), null, false, false, false); } diff --git a/application/src/org/yaaic/model/Settings.java b/application/src/org/yaaic/model/Settings.java index 6d5ce96..d0ca20e 100644 --- a/application/src/org/yaaic/model/Settings.java +++ b/application/src/org/yaaic/model/Settings.java @@ -2,6 +2,7 @@ Yaaic - Yet Another Android IRC Client Copyright 2009-2012 Sebastian Kaspari +Copyright 2012 Daniel E. Moctezuma This file is part of Yaaic. @@ -222,6 +223,19 @@ public class Settings ); } + /** + * LED light notification on highlight? + * + * @return True if LED light on highlight is enabled, false otherwise + */ + public boolean isLedHighlightEnabled() + { + return preferences.getBoolean( + resources.getString(R.string.key_led_highlight), + Boolean.parseBoolean(resources.getString(R.string.default_led_highlight)) + ); + } + /** * Should join, part and quit messages be displayed? *