2010-03-13 13:56:42 -05:00
|
|
|
/*
|
|
|
|
Yaaic - Yet Another Android IRC Client
|
|
|
|
|
2011-02-05 07:00:12 -05:00
|
|
|
Copyright 2009-2011 Sebastian Kaspari
|
2010-03-13 13:56:42 -05:00
|
|
|
|
|
|
|
This file is part of Yaaic.
|
|
|
|
|
|
|
|
Yaaic is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Yaaic is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
2010-12-17 16:29:33 -05:00
|
|
|
*/
|
2010-03-13 13:56:42 -05:00
|
|
|
package org.yaaic.model;
|
|
|
|
|
|
|
|
import org.yaaic.R;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The settings class is a helper class to access the different preferences via
|
|
|
|
* small and simple methods.
|
|
|
|
*
|
2010-11-21 06:58:17 -05:00
|
|
|
* Note: As this class carries a Context instance as private member, instances of
|
2010-11-18 12:52:19 -05:00
|
|
|
* this class should be thrown away not later than when the Context should
|
2010-12-17 16:29:33 -05:00
|
|
|
* be gone. Otherwise this could leak memory.
|
2010-03-13 13:56:42 -05:00
|
|
|
*
|
|
|
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
2010-12-17 16:29:33 -05:00
|
|
|
*/
|
2010-03-13 13:56:42 -05:00
|
|
|
public class Settings
|
|
|
|
{
|
2010-12-17 16:29:33 -05:00
|
|
|
private final SharedPreferences preferences;
|
|
|
|
private final Resources resources;
|
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Create a new Settings instance
|
|
|
|
*
|
|
|
|
* @param context
|
|
|
|
*/
|
|
|
|
public Settings(Context context)
|
|
|
|
{
|
|
|
|
this.preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
this.resources = context.getApplicationContext().getResources();
|
|
|
|
}
|
2010-12-17 16:29:33 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Prefix all messages with a timestamp?
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean showTimestamp()
|
|
|
|
{
|
|
|
|
return preferences.getBoolean(
|
|
|
|
resources.getString(R.string.key_show_timestamp),
|
|
|
|
Boolean.parseBoolean(resources.getString(R.string.default_show_timestamp))
|
|
|
|
);
|
|
|
|
}
|
2010-12-17 16:29:33 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Show icons to highlight special events
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean showIcons()
|
|
|
|
{
|
|
|
|
return preferences.getBoolean(
|
|
|
|
resources.getString(R.string.key_show_icons),
|
|
|
|
Boolean.parseBoolean(resources.getString(R.string.default_show_icons))
|
|
|
|
);
|
|
|
|
}
|
2010-12-17 16:29:33 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Show colors to highlight special events?
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean showColors()
|
|
|
|
{
|
|
|
|
return preferences.getBoolean(
|
|
|
|
resources.getString(R.string.key_show_colors),
|
|
|
|
Boolean.parseBoolean(resources.getString(R.string.default_show_colors))
|
|
|
|
);
|
|
|
|
}
|
2010-12-17 16:29:33 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Show colors to highlight nicknames?
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean showColorsNick()
|
|
|
|
{
|
|
|
|
return preferences.getBoolean(
|
|
|
|
resources.getString(R.string.key_show_colors_nick),
|
|
|
|
Boolean.parseBoolean(resources.getString(R.string.default_show_colors_nick))
|
|
|
|
);
|
|
|
|
}
|
2010-09-09 14:41:55 -04:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Use 24 hour format for timestamps?
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean use24hFormat()
|
|
|
|
{
|
|
|
|
return preferences.getBoolean(
|
|
|
|
resources.getString(R.string.key_24h_format),
|
|
|
|
Boolean.parseBoolean(resources.getString(R.string.default_24h_format))
|
|
|
|
);
|
|
|
|
}
|
2010-12-17 16:29:33 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Is reconnect on disconnect enabled?
|
|
|
|
*
|
2010-12-17 16:29:33 -05:00
|
|
|
* @return
|
2010-11-18 12:52:19 -05:00
|
|
|
*/
|
|
|
|
public boolean isReconnectEnabled()
|
|
|
|
{
|
|
|
|
return preferences.getBoolean(
|
|
|
|
resources.getString(R.string.key_reconnect),
|
|
|
|
Boolean.parseBoolean(resources.getString(R.string.default_reconnect))
|
|
|
|
);
|
|
|
|
}
|
2010-12-17 16:29:33 -05:00
|
|
|
|
2011-06-29 04:20:02 -04:00
|
|
|
/**
|
|
|
|
* Get the reconnect interval
|
|
|
|
*
|
|
|
|
* @return The reconnect interval in minutes
|
|
|
|
*/
|
|
|
|
public int getReconnectInterval()
|
|
|
|
{
|
|
|
|
return Integer.parseInt(preferences.getString(
|
|
|
|
resources.getString(R.string.key_reconnect_interval),
|
|
|
|
resources.getString(R.string.default_reconnect_interval)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get the quit message
|
|
|
|
*
|
|
|
|
* @return The message to display when the user disconnects
|
|
|
|
*/
|
|
|
|
public String getQuitMessage()
|
|
|
|
{
|
|
|
|
return preferences.getString(
|
|
|
|
resources.getString(R.string.key_quitmessage),
|
|
|
|
resources.getString(R.string.default_quitmessage)
|
|
|
|
);
|
|
|
|
}
|
2010-12-17 16:29:33 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Get the font size
|
|
|
|
*
|
|
|
|
* @return The font size for conversation messages
|
|
|
|
*/
|
|
|
|
public int getFontSize()
|
|
|
|
{
|
|
|
|
return Integer.parseInt(preferences.getString(
|
|
|
|
resources.getString(R.string.key_fontsize),
|
|
|
|
resources.getString(R.string.default_fontsize)
|
|
|
|
));
|
|
|
|
}
|
2010-12-17 16:29:33 -05:00
|
|
|
|
2010-11-18 12:52:19 -05:00
|
|
|
/**
|
|
|
|
* Is voice recognition enabled?
|
|
|
|
*
|
|
|
|
* @return True if voice recognition is enabled, false otherwise
|
|
|
|
*/
|
|
|
|
public boolean isVoiceRecognitionEnabled()
|
|
|
|
{
|
|
|
|
return preferences.getBoolean(
|
|
|
|
resources.getString(R.string.key_voice_recognition),
|
|
|
|
Boolean.parseBoolean(resources.getString(R.string.default_voice_recognition))
|
|
|
|
);
|
|
|
|
}
|
2010-12-17 16:29:33 -05:00
|
|
|
|
2010-11-16 19:32:09 -05:00
|
|
|
/**
|
2010-12-17 16:29:33 -05:00
|
|
|
* Play notification sound on highlight?
|
2010-11-16 19:32:09 -05:00
|
|
|
*
|
2010-12-17 16:29:33 -05:00
|
|
|
* @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?
|
|
|
|
*
|
2010-11-16 19:32:09 -05:00
|
|
|
* @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))
|
|
|
|
);
|
2010-11-18 13:25:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-03-15 15:42:35 -04:00
|
|
|
* Should join, part and quit messages be displayed?
|
2010-11-18 13:25:26 -05:00
|
|
|
*
|
2011-03-15 15:42:35 -04:00
|
|
|
* @return True if joins, parts and quits should be displayed, false otherwise
|
2010-11-18 13:25:26 -05:00
|
|
|
*/
|
2011-03-15 15:42:35 -04:00
|
|
|
public boolean showJoinPartAndQuit()
|
2010-11-18 13:25:26 -05:00
|
|
|
{
|
|
|
|
return preferences.getBoolean(
|
2011-03-15 15:42:35 -04:00
|
|
|
resources.getString(R.string.key_show_joinpartquit),
|
|
|
|
Boolean.parseBoolean(resources.getString(R.string.default_show_joinpartquit))
|
2010-11-18 13:25:26 -05:00
|
|
|
);
|
|
|
|
}
|
2011-03-15 15:53:47 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Should notices be shown in the server window instead in the focused window?
|
|
|
|
*
|
|
|
|
* @return True if notices should be shown in the server window
|
|
|
|
*/
|
|
|
|
public boolean showNoticeInServerWindow()
|
|
|
|
{
|
|
|
|
return preferences.getBoolean(
|
|
|
|
resources.getString(R.string.key_notice_server_window),
|
|
|
|
Boolean.parseBoolean(resources.getString(R.string.default_notice_server_window))
|
|
|
|
);
|
|
|
|
}
|
2011-03-15 22:21:48 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Render messages with color and style codes.
|
|
|
|
*
|
|
|
|
* @return True if colors should be rendered, false if they should be removed.
|
|
|
|
*/
|
|
|
|
public boolean showMircColors()
|
|
|
|
{
|
|
|
|
return preferences.getBoolean(
|
|
|
|
resources.getString(R.string.key_mirc_colors),
|
|
|
|
Boolean.parseBoolean(resources.getString(R.string.default_mirc_colors))
|
|
|
|
);
|
|
|
|
}
|
2011-03-17 23:08:21 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Render messages with graphical smilies.
|
|
|
|
*
|
|
|
|
* @return True if text smilies should be rendered as graphical smilies, false otherwise.
|
|
|
|
*/
|
|
|
|
public boolean showGraphicalSmilies()
|
|
|
|
{
|
|
|
|
return preferences.getBoolean(
|
|
|
|
resources.getString(R.string.key_graphical_smilies),
|
|
|
|
Boolean.parseBoolean(resources.getString(R.string.default_graphical_smilies))
|
|
|
|
);
|
|
|
|
}
|
2011-05-29 20:49:49 -04:00
|
|
|
|
2011-05-29 20:50:00 -04:00
|
|
|
/**
|
|
|
|
* Whether message text should be autocorrected.
|
|
|
|
*/
|
|
|
|
public boolean autoCorrectText()
|
|
|
|
{
|
|
|
|
return preferences.getBoolean(
|
|
|
|
resources.getString(R.string.key_autocorrect_text),
|
|
|
|
Boolean.parseBoolean(resources.getString(R.string.default_autocorrect_text))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether sentences in messages should be automatically capitalized.
|
|
|
|
*/
|
|
|
|
public boolean autoCapSentences()
|
|
|
|
{
|
|
|
|
return preferences.getBoolean(
|
|
|
|
resources.getString(R.string.key_autocap_sentences),
|
|
|
|
Boolean.parseBoolean(resources.getString(R.string.default_autocap_sentences))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-05-29 20:49:49 -04:00
|
|
|
/**
|
|
|
|
* Get the conversation history size.
|
|
|
|
*
|
|
|
|
* @return The conversation history size
|
|
|
|
*/
|
|
|
|
public int getHistorySize()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return Integer.parseInt(preferences.getString(
|
|
|
|
resources.getString(R.string.key_history_size),
|
|
|
|
resources.getString(R.string.default_history_size)
|
|
|
|
));
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
return Integer.parseInt(resources.getString(R.string.default_history_size));
|
|
|
|
}
|
|
|
|
}
|
2010-03-13 13:56:42 -05:00
|
|
|
}
|