1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-08-13 16:53:50 -04:00

Added setting to vibrate on highlight.

This commit is contained in:
liato 2010-11-17 01:32:09 +01:00
parent 1d2f6e5237
commit 81f2c94b87
7 changed files with 41 additions and 8 deletions

View File

@ -94,4 +94,7 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
<uses-sdk android:minSdkVersion="3" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
</manifest>

View File

@ -26,4 +26,7 @@
<string name="key_voice_recognition">voice_recognition</string>
<string name="default_voice_recognition">false</string>
<string name="key_vibrate_highlight">vibrate_highlight</string>
<string name="default_vibrate_highlight">true</string>
</resources>

View File

@ -85,8 +85,8 @@
<string name="query_exists">Query already exists</string>
<string name="line_missing">Line is missing</string>
<string name="nickname_in_use">Nickname %1$s already in use</string>
<string name="irc_login_error">Could not log into the IRC server %1$s:%1$d</string>
<string name="could_not_connect">Could not connect to %1$s:%1$d</string>
<string name="irc_login_error">Could not log into the IRC server %1$s:%2$d</string>
<string name="could_not_connect">Could not connect to %1$s:%2$d</string>
<string name="command_desc_amsg">Send a message to all channels</string>
<string name="command_desc_away">Sets you away</string>
@ -182,4 +182,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>
</resources>

View File

@ -80,5 +80,11 @@ 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

@ -195,7 +195,7 @@ public class IRCConnection extends PircBot
if (action.contains(getNick())) {
// highlight
message.setColor(Message.COLOR_RED);
service.updateNotification(target + ": " + sender + " " + action);
service.updateNotification(target + ": " + sender + " " + action, service.getSettings().isVibrateHighlightEnabled());
server.getConversation(target).setStatus(Conversation.STATUS_HIGHLIGHT);
}
@ -390,7 +390,7 @@ public class IRCConnection extends PircBot
if (text.contains(getNick())) {
// highlight
message.setColor(Message.COLOR_RED);
service.updateNotification(target + ": <" + sender + "> " + text);
service.updateNotification(target + ": <" + sender + "> " + text, service.getSettings().isVibrateHighlightEnabled());
server.getConversation(target).setStatus(Conversation.STATUS_HIGHLIGHT);
}
@ -536,7 +536,7 @@ public class IRCConnection extends PircBot
if (text.contains(getNick())) {
message.setColor(Message.COLOR_RED);
service.updateNotification("<" + sender + "> " + text);
service.updateNotification("<" + sender + "> " + text, service.getSettings().isVibrateHighlightEnabled());
server.getConversation(sender).setStatus(Conversation.STATUS_HIGHLIGHT);
}

View File

@ -43,6 +43,7 @@ import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.util.Log;
/**
* The background service for managing the irc connections
@ -157,11 +158,10 @@ public class IRCService extends Service
*/
private void handleCommand(Intent intent)
{
if (ACTION_FOREGROUND.equals(intent.getAction())) {
if (ACTION_FOREGROUND.equals(intent.getAction())) {
if (foreground) {
return; // XXX: We are already in foreground...
}
foreground = true;
// Set the icon, scrolling text and timestamp
@ -184,13 +184,19 @@ public class IRCService extends Service
*
* @param text The text to display
*/
public void updateNotification(String text)
public void updateNotification(String text) {
updateNotification(text, false);
}
public void updateNotification(String text, boolean vibrate)
{
if (foreground) {
notificationManager.cancel(R.string.app_name);
notification = new Notification(R.drawable.icon, text, System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, ServersActivity.class), 0);
notification.setLatestEventInfo(this, getText(R.string.app_name), text, contentIntent);
if (vibrate) {
notification.defaults |= Notification.DEFAULT_VIBRATE;
}
notificationManager.notify(R.string.app_name, notification);
}
}

View File

@ -169,4 +169,17 @@ public class Settings
Boolean.parseBoolean(resources.getString(R.string.default_voice_recognition))
);
}
/**
* Vibrate on highlight?
*
* @return True if vibrate on highlight is enabled, false otherwise
*/
public boolean isVibrateHighlightEnabled()
{
return preferences.getBoolean(
resources.getString(R.string.key_vibrate_highlight),
Boolean.parseBoolean(resources.getString(R.string.default_vibrate_highlight))
);
}
}