Skip to content

Commit

Permalink
Added support for LED light notification on nickname highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
democtezuma authored and pocmo committed Oct 4, 2012
1 parent e444354 commit 89ff98b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 11 deletions.
3 changes: 3 additions & 0 deletions application/res/values/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<string name="key_sound_highlight">sound_highlight</string>
<string name="default_sound_highlight">false</string>

<string name="key_led_highlight">led_highlight</string>
<string name="default_led_highlight">true</string>

<string name="key_notice_server_window">notice_server_window</string>
<string name="default_notice_server_window">false</string>

Expand Down
2 changes: 2 additions & 0 deletions application/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@
<string name="settings_sound_highlight_desc">Play sound when your nick is mentioned</string>
<string name="settings_vibrate_highlight_title">Vibrate on highlight</string>
<string name="settings_vibrate_highlight_desc">Vibrate when your nick is mentioned</string>
<string name="settings_led_highlight_title">Flash LED on highlight</string>
<string name="settings_led_highlight_desc">Flash LED light when your nick is mentioned</string>

<string name="settings_misc">Misc</string>
<string name="settings_quitmessage_title">Quit message</string>
Expand Down
6 changes: 6 additions & 0 deletions application/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Yaaic - Yet Another Android IRC Client
Copyright 2009-2012 Sebastian Kaspari
Copyright 2012 Daniel E. Moctezuma <[email protected]>
This file is part of Yaaic.
Expand Down Expand Up @@ -133,6 +134,11 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
android:summary="@string/settings_vibrate_highlight_desc"
android:key="@string/key_vibrate_highlight"
android:defaultValue="@string/default_vibrate_highlight" />
<CheckBoxPreference
android:title="@string/settings_led_highlight_title"
android:summary="@string/settings_led_highlight_desc"
android:key="@string/key_led_highlight"
android:defaultValue="@string/default_led_highlight" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/settings_misc">
Expand Down
10 changes: 7 additions & 3 deletions application/src/org/yaaic/irc/IRCConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Yaaic - Yet Another Android IRC Client
Copyright 2009-2012 Sebastian Kaspari
Copyright 2012 Daniel E. Moctezuma <[email protected]>
This file is part of Yaaic.
Expand Down Expand Up @@ -281,7 +282,8 @@ protected void onAction(String sender, String login, String hostname, String tar
conversation,
conversation.getName() + ": " + sender + " " + action,
service.getSettings().isVibrateHighlightEnabled(),
service.getSettings().isSoundHighlightEnabled()
service.getSettings().isSoundHighlightEnabled(),
service.getSettings().isLedHighlightEnabled()
);
}
}
Expand Down Expand Up @@ -458,7 +460,8 @@ protected void onMessage(String target, String sender, String login, String host
conversation,
target + ": <" + sender + "> " + text,
service.getSettings().isVibrateHighlightEnabled(),
service.getSettings().isSoundHighlightEnabled()
service.getSettings().isSoundHighlightEnabled(),
service.getSettings().isLedHighlightEnabled()
);
}

Expand Down Expand Up @@ -669,7 +672,8 @@ protected void onPrivateMessage(String sender, String login, String hostname, St
conversation,
"<" + sender + "> " + text,
service.getSettings().isVibrateHighlightEnabled(),
service.getSettings().isSoundHighlightEnabled()
service.getSettings().isSoundHighlightEnabled(),
service.getSettings().isLedHighlightEnabled()
);
}

Expand Down
26 changes: 18 additions & 8 deletions application/src/org/yaaic/irc/IRCService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Yaaic - Yet Another Android IRC Client
Copyright 2009-2012 Sebastian Kaspari
Copyright 2012 Daniel E. Moctezuma <[email protected]>
This file is part of Yaaic.
Expand Down Expand Up @@ -211,14 +212,15 @@ private void handleCommand(Intent intent)
}

/**
* 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());
Expand Down Expand Up @@ -254,6 +256,13 @@ private void updateNotification(String text, String contentText, boolean vibrate
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);
Expand All @@ -274,8 +283,9 @@ public String getConversationId(int serverId, String title) {
* @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;
Expand All @@ -289,9 +299,9 @@ public synchronized void addNewMention(int serverId, Conversation conversation,
}

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);
}
}

Expand All @@ -316,7 +326,7 @@ public synchronized void ackNewMentions(int serverId, String convTitle)
newMentions = 0;
}

updateNotification(null, null, false, false);
updateNotification(null, null, false, false, false);
}

/**
Expand All @@ -327,7 +337,7 @@ public synchronized void ackNewMentions(int serverId, String convTitle)
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);
}

/**
Expand All @@ -338,7 +348,7 @@ public synchronized void notifyConnected(String title)
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);
}


Expand Down
14 changes: 14 additions & 0 deletions application/src/org/yaaic/model/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Yaaic - Yet Another Android IRC Client
Copyright 2009-2012 Sebastian Kaspari
Copyright 2012 Daniel E. Moctezuma <[email protected]>
This file is part of Yaaic.
Expand Down Expand Up @@ -222,6 +223,19 @@ public boolean isVibrateHighlightEnabled()
);
}

/**
* 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?
*
Expand Down

0 comments on commit 89ff98b

Please sign in to comment.