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="default_vibrate_highlight">true</string>
<string name="key_sound_highlight">sound_highlight</string>
<string name="default_sound_highlight">false</string>
</resources>

View File

@ -161,6 +161,7 @@
<string name="settings_connection">Connection</string>
<string name="settings_reconnect_title">Reconnect</string>
<string name="settings_reconnect_desc">Automatically reconnect on disconnect</string>
<string name="settings_chat">Chat</string>
<string name="settings_icons_title">Show icons</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_24h_title">24 hour format</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_quitmessage_title">Quit message</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_voice_recognition_title">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_desc">Show join and part messages in channels</string>
</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:defaultValue="@string/default_show_joinpart" />
</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
android:title="@string/settings_misc">
<CheckBoxPreference
@ -85,10 +98,5 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
android:defaultValue="@string/default_quitmessage"
android:dialogTitle="@string/settings_quitmessage_dialog_title"
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>
</PreferenceScreen>

View File

@ -25,12 +25,9 @@ import java.util.Collection;
import java.util.Vector;
import java.util.regex.Pattern;
import android.content.Intent;
import org.jibble.pircbot.Colors;
import org.jibble.pircbot.PircBot;
import org.jibble.pircbot.User;
import org.yaaic.R;
import org.yaaic.Yaaic;
import org.yaaic.command.CommandParser;
@ -43,6 +40,8 @@ import org.yaaic.model.Server;
import org.yaaic.model.ServerInfo;
import org.yaaic.model.Status;
import android.content.Intent;
/**
* 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
{
private IRCService service;
private Server server;
private final IRCService service;
private final Server server;
private ArrayList<String> autojoinChannels;
private Pattern mNickMatch;
@ -200,7 +199,11 @@ public class IRCConnection extends PircBot
if (isMentioned(action)) {
// highlight
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);
}
@ -395,7 +398,11 @@ public class IRCConnection extends PircBot
if (isMentioned(text)) {
// highlight
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);
}
@ -544,7 +551,11 @@ public class IRCConnection extends PircBot
if (isMentioned(text)) {
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);
}
@ -1117,6 +1128,7 @@ public class IRCConnection extends PircBot
public void quitServer()
{
new Thread() {
@Override
public void run() {
quitServer(service.getSettings().getQuitMessage());
}

View File

@ -187,7 +187,7 @@ public class IRCService extends Service
*/
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 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) {
notificationManager.cancel(R.string.app_name);

View File

@ -39,8 +39,8 @@ import android.preference.PreferenceManager;
*/
public class Settings
{
private SharedPreferences preferences;
private Resources resources;
private final SharedPreferences preferences;
private final Resources resources;
/**
* 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?
*