1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-11 11:44:59 -05:00

New setting: Play (notification) sound on highlight

This commit is contained in:
Sebastian Kaspari 2010-12-17 22:29:33 +01:00
parent 4b3e47c799
commit e014165a17
6 changed files with 196 additions and 154 deletions

View File

@ -32,4 +32,7 @@
<string name="key_vibrate_highlight">vibrate_highlight</string> <string name="key_vibrate_highlight">vibrate_highlight</string>
<string name="default_vibrate_highlight">true</string> <string name="default_vibrate_highlight">true</string>
<string name="key_sound_highlight">sound_highlight</string>
<string name="default_sound_highlight">false</string>
</resources> </resources>

View File

@ -161,6 +161,7 @@
<string name="settings_connection">Connection</string> <string name="settings_connection">Connection</string>
<string name="settings_reconnect_title">Reconnect</string> <string name="settings_reconnect_title">Reconnect</string>
<string name="settings_reconnect_desc">Automatically reconnect on disconnect</string> <string name="settings_reconnect_desc">Automatically reconnect on disconnect</string>
<string name="settings_chat">Chat</string> <string name="settings_chat">Chat</string>
<string name="settings_icons_title">Show icons</string> <string name="settings_icons_title">Show icons</string>
<string name="settings_icons_desc">Show icons to highlight special events</string> <string name="settings_icons_desc">Show icons to highlight special events</string>
@ -172,6 +173,13 @@
<string name="settings_timestamp_desc">Prefix all messages with a timestamp</string> <string name="settings_timestamp_desc">Prefix all messages with a timestamp</string>
<string name="settings_24h_title">24 hour format</string> <string name="settings_24h_title">24 hour format</string>
<string name="settings_24h_desc">Use 24 hour format for timestamps</string> <string name="settings_24h_desc">Use 24 hour format for timestamps</string>
<string name="settings_highlight">Highlight</string>
<string name="settings_sound_highlight_title">Play sound on highlight</string>
<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_misc">Misc</string> <string name="settings_misc">Misc</string>
<string name="settings_quitmessage_title">Quit message</string> <string name="settings_quitmessage_title">Quit message</string>
<string name="settings_quitmessage_desc">Message to show when you disconnect</string> <string name="settings_quitmessage_desc">Message to show when you disconnect</string>
@ -182,8 +190,6 @@
<string name="settings_fontsize_dialog_title">Font size</string> <string name="settings_fontsize_dialog_title">Font size</string>
<string name="settings_voice_recognition_title">Voice recognition</string> <string name="settings_voice_recognition_title">Voice recognition</string>
<string name="settings_voice_recognition_desc">Show button for voice recognition</string> <string name="settings_voice_recognition_desc">Show button for voice recognition</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_joinpart_title">Show join and part</string> <string name="settings_joinpart_title">Show join and part</string>
<string name="settings_joinpart_desc">Show join and part messages in channels</string> <string name="settings_joinpart_desc">Show join and part messages in channels</string>
</resources> </resources>

View File

@ -71,6 +71,19 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
android:key="@string/key_show_joinpart" android:key="@string/key_show_joinpart"
android:defaultValue="@string/default_show_joinpart" /> android:defaultValue="@string/default_show_joinpart" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory
android:title="@string/settings_highlight">
<CheckBoxPreference
android:title="@string/settings_sound_highlight_title"
android:summary="@string/settings_sound_highlight_desc"
android:key="@string/key_sound_highlight"
android:defaultValue="@string/default_sound_highlight" />
<CheckBoxPreference
android:title="@string/settings_vibrate_highlight_title"
android:summary="@string/settings_vibrate_highlight_desc"
android:key="@string/key_vibrate_highlight"
android:defaultValue="@string/default_vibrate_highlight" />
</PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:title="@string/settings_misc"> android:title="@string/settings_misc">
<CheckBoxPreference <CheckBoxPreference
@ -85,10 +98,5 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
android:defaultValue="@string/default_quitmessage" android:defaultValue="@string/default_quitmessage"
android:dialogTitle="@string/settings_quitmessage_dialog_title" android:dialogTitle="@string/settings_quitmessage_dialog_title"
android:dialogMessage="@string/settings_quitmessage_dialog_desc" /> android:dialogMessage="@string/settings_quitmessage_dialog_desc" />
<CheckBoxPreference
android:title="@string/settings_vibrate_highlight_title"
android:summary="@string/settings_vibrate_highlight_desc"
android:key="@string/key_vibrate_highlight"
android:defaultValue="@string/default_vibrate_highlight" />
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>

View File

@ -17,7 +17,7 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with Yaaic. If not, see <http://www.gnu.org/licenses/>. along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.yaaic.irc; package org.yaaic.irc;
import java.util.ArrayList; import java.util.ArrayList;
@ -25,12 +25,9 @@ import java.util.Collection;
import java.util.Vector; import java.util.Vector;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import android.content.Intent;
import org.jibble.pircbot.Colors; import org.jibble.pircbot.Colors;
import org.jibble.pircbot.PircBot; import org.jibble.pircbot.PircBot;
import org.jibble.pircbot.User; import org.jibble.pircbot.User;
import org.yaaic.R; import org.yaaic.R;
import org.yaaic.Yaaic; import org.yaaic.Yaaic;
import org.yaaic.command.CommandParser; import org.yaaic.command.CommandParser;
@ -43,6 +40,8 @@ import org.yaaic.model.Server;
import org.yaaic.model.ServerInfo; import org.yaaic.model.ServerInfo;
import org.yaaic.model.Status; import org.yaaic.model.Status;
import android.content.Intent;
/** /**
* The class that actually handles the connection to an IRC server * The class that actually handles the connection to an IRC server
* *
@ -50,8 +49,8 @@ import org.yaaic.model.Status;
*/ */
public class IRCConnection extends PircBot public class IRCConnection extends PircBot
{ {
private IRCService service; private final IRCService service;
private Server server; private final Server server;
private ArrayList<String> autojoinChannels; private ArrayList<String> autojoinChannels;
private Pattern mNickMatch; private Pattern mNickMatch;
@ -115,9 +114,9 @@ public class IRCConnection extends PircBot
protected void onVersion(String sourceNick, String sourceLogin, String sourceHostname, String target) protected void onVersion(String sourceNick, String sourceLogin, String sourceHostname, String target)
{ {
this.sendRawLine( this.sendRawLine(
"NOTICE " + sourceNick + " :\u0001VERSION " + "NOTICE " + sourceNick + " :\u0001VERSION " +
"Yaaic - Yet another Android IRC client - http://www.yaaic.org" + "Yaaic - Yet another Android IRC client - http://www.yaaic.org" +
"\u0001" "\u0001"
); );
} }
@ -200,7 +199,11 @@ public class IRCConnection extends PircBot
if (isMentioned(action)) { if (isMentioned(action)) {
// highlight // highlight
message.setColor(Message.COLOR_RED); message.setColor(Message.COLOR_RED);
service.updateNotification(target + ": " + sender + " " + action, service.getSettings().isVibrateHighlightEnabled()); service.updateNotification(
target + ": " + sender + " " + action,
service.getSettings().isVibrateHighlightEnabled(),
service.getSettings().isSoundHighlightEnabled()
);
server.getConversation(target).setStatus(Conversation.STATUS_HIGHLIGHT); server.getConversation(target).setStatus(Conversation.STATUS_HIGHLIGHT);
} }
@ -395,7 +398,11 @@ public class IRCConnection extends PircBot
if (isMentioned(text)) { if (isMentioned(text)) {
// highlight // highlight
message.setColor(Message.COLOR_RED); message.setColor(Message.COLOR_RED);
service.updateNotification(target + ": <" + sender + "> " + text, service.getSettings().isVibrateHighlightEnabled()); service.updateNotification(
target + ": <" + sender + "> " + text,
service.getSettings().isVibrateHighlightEnabled(),
service.getSettings().isSoundHighlightEnabled()
);
server.getConversation(target).setStatus(Conversation.STATUS_HIGHLIGHT); server.getConversation(target).setStatus(Conversation.STATUS_HIGHLIGHT);
} }
@ -424,7 +431,7 @@ public class IRCConnection extends PircBot
intent.putExtra(Broadcast.EXTRA_SERVER, server.getId()); intent.putExtra(Broadcast.EXTRA_SERVER, server.getId());
intent.putExtra(Broadcast.EXTRA_CHANNEL, target); intent.putExtra(Broadcast.EXTRA_CHANNEL, target);
service.sendBroadcast(intent); service.sendBroadcast(intent);
*/ */
} }
/** /**
@ -544,7 +551,11 @@ public class IRCConnection extends PircBot
if (isMentioned(text)) { if (isMentioned(text)) {
message.setColor(Message.COLOR_RED); message.setColor(Message.COLOR_RED);
service.updateNotification("<" + sender + "> " + text, service.getSettings().isVibrateHighlightEnabled()); service.updateNotification(
"<" + sender + "> " + text,
service.getSettings().isVibrateHighlightEnabled(),
service.getSettings().isSoundHighlightEnabled()
);
server.getConversation(sender).setStatus(Conversation.STATUS_HIGHLIGHT); server.getConversation(sender).setStatus(Conversation.STATUS_HIGHLIGHT);
} }
@ -1117,6 +1128,7 @@ public class IRCConnection extends PircBot
public void quitServer() public void quitServer()
{ {
new Thread() { new Thread() {
@Override
public void run() { public void run() {
quitServer(service.getSettings().getQuitMessage()); quitServer(service.getSettings().getQuitMessage());
} }

View File

@ -187,7 +187,7 @@ public class IRCService extends Service
*/ */
public void updateNotification(String text) public void updateNotification(String text)
{ {
updateNotification(text, false); updateNotification(text, false, false);
} }
/** /**
@ -196,7 +196,7 @@ public class IRCService extends Service
* @param text The text to display * @param text The text to display
* @param vibrate True if the device should vibrate, false otherwise * @param vibrate True if the device should vibrate, false otherwise
*/ */
public void updateNotification(String text, boolean vibrate) public void updateNotification(String text, boolean vibrate, boolean sound)
{ {
if (foreground) { if (foreground) {
notificationManager.cancel(R.string.app_name); notificationManager.cancel(R.string.app_name);

View File

@ -17,7 +17,7 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with Yaaic. If not, see <http://www.gnu.org/licenses/>. along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.yaaic.model; package org.yaaic.model;
import org.yaaic.R; import org.yaaic.R;
@ -36,11 +36,11 @@ import android.preference.PreferenceManager;
* be gone. Otherwise this could leak memory. * be gone. Otherwise this could leak memory.
* *
* @author Sebastian Kaspari <sebastian@yaaic.org> * @author Sebastian Kaspari <sebastian@yaaic.org>
*/ */
public class Settings public class Settings
{ {
private SharedPreferences preferences; private final SharedPreferences preferences;
private Resources resources; private final Resources resources;
/** /**
* Create a new Settings instance * Create a new Settings instance
@ -170,6 +170,19 @@ public class Settings
); );
} }
/**
* Play notification sound on highlight?
*
* @return True if sound should be played on highlight, false otherwise
*/
public boolean isSoundHighlightEnabled()
{
return preferences.getBoolean(
resources.getString(R.string.key_sound_highlight),
Boolean.parseBoolean(resources.getString(R.string.default_sound_highlight))
);
}
/** /**
* Vibrate on highlight? * Vibrate on highlight?
* *