1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-30 13:12:25 -05:00

Fixes issue 2282

Added an option whether the registered name color is change or not
Avoid "Connection error" when MessageView is opened. The contacts.getName() might return null.
This commit is contained in:
Koji Arai 2010-09-26 14:39:52 +00:00
parent a2fe3bda34
commit 2a39cd5206
5 changed files with 98 additions and 16 deletions

View File

@ -314,6 +314,10 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
<string name="global_settings_touchable_label">Touch-friendly view</string>
<string name="global_settings_touchable_summary">Roomier list items with message previews</string>
<string name="global_settings_registered_name_color_label">Choose registered name color</string>
<string name="global_settings_registered_name_color_default">Default theme color</string>
<string name="global_settings_registered_name_color_changed">Choosed color</string>
<string name="global_settings_messageview_fixedwidth_label">Fixed-width fonts</string>
<string name="global_settings_messageview_fixedwidth_summary">Use a fixed-width font when showing plain-text messages</string>
<string name="global_settings_messageview_return_to_list_label">Return to list after delete</string>

View File

@ -125,6 +125,11 @@
<PreferenceCategory android:title="@string/messageview_preferences" android:key="messageview_preferences">
<CheckBoxPreference
android:key="change_registered_name_color"
android:title="@string/global_settings_registered_name_color_label"
android:summary="@string/global_settings_registered_name_color_default" />
<CheckBoxPreference
android:key="messageview_fixedwidth_font"
android:title="@string/global_settings_messageview_fixedwidth_label"

View File

@ -113,6 +113,8 @@ public class K9 extends Application
private static boolean mMessageListCheckboxes = false;
private static boolean mMessageListTouchable = false;
private static boolean mChangeRegisteredNameColor = false;
private static int mRegisteredNameColor = 0xff00008f;
private static boolean mMessageViewFixedWidthFont = false;
private static boolean mMessageViewReturnToList = false;
@ -350,6 +352,9 @@ public class K9 extends Application
editor.putBoolean("messageListCheckboxes",mMessageListCheckboxes);
editor.putBoolean("messageListTouchable",mMessageListTouchable);
editor.putBoolean("changeRegisteredNameColor",mChangeRegisteredNameColor);
editor.putInt("registeredNameColor",mRegisteredNameColor);
editor.putBoolean("messageViewFixedWidthFont",mMessageViewFixedWidthFont);
editor.putBoolean("messageViewReturnToList", mMessageViewReturnToList);
@ -388,6 +393,8 @@ public class K9 extends Application
mMessageListCheckboxes = sprefs.getBoolean("messageListCheckboxes",false);
mMessageListTouchable = sprefs.getBoolean("messageListTouchable",false);
mChangeRegisteredNameColor = sprefs.getBoolean("changeRegisteredNameColor", false);
mRegisteredNameColor = sprefs.getInt("registeredNameColor", 0xff00008f);
mMessageViewFixedWidthFont = sprefs.getBoolean("messageViewFixedWidthFont", false);
mMessageViewReturnToList = sprefs.getBoolean("messageViewReturnToList", false);
@ -611,6 +618,23 @@ public class K9 extends Application
mMessageListCheckboxes = checkboxes;
}
public static boolean changeRegisteredNameColor()
{
return mChangeRegisteredNameColor;
}
public static void setChangeRegisteredNameColor(boolean checkboxes)
{
mChangeRegisteredNameColor = checkboxes;
}
public static int getRegisteredNameColor() {
return mRegisteredNameColor;
}
public static void setRegisteredNameColor(int registeredNameColor) {
mRegisteredNameColor = registeredNameColor;
}
public static boolean messageViewFixedWidthFont()
{

View File

@ -19,6 +19,7 @@ import com.fsck.k9.K9;
import com.fsck.k9.Preferences;
import com.fsck.k9.R;
import com.fsck.k9.activity.Accounts;
import com.fsck.k9.activity.ColorPickerDialog;
import com.fsck.k9.activity.DateFormatter;
import com.fsck.k9.activity.K9PreferenceActivity;
import com.fsck.k9.preferences.CheckboxListPreference;
@ -49,6 +50,7 @@ public class Prefs extends K9PreferenceActivity
private static final String PREFERENCE_MESSAGELIST_CHECKBOXES = "messagelist_checkboxes";
private static final String PREFERENCE_MESSAGELIST_TOUCHABLE = "messagelist_touchable";
private static final String PREFERENCE_CHANGE_REGISTERED_NAME_COLOR = "change_registered_name_color";
private static final String PREFERENCE_MESSAGEVIEW_FIXEDWIDTH = "messageview_fixedwidth_font";
private static final String PREFERENCE_MESSAGEVIEW_RETURN_TO_LIST = "messageview_return_to_list";
@ -75,6 +77,7 @@ public class Prefs extends K9PreferenceActivity
private CheckBoxPreference mCheckboxes;
private CheckBoxPreference mTouchable;
private CheckBoxPreference mChangeRegisteredNameColor;
private CheckBoxPreference mFixedWidth;
private CheckBoxPreference mReturnToList;
@ -230,6 +233,28 @@ public class Prefs extends K9PreferenceActivity
mTouchable = (CheckBoxPreference)findPreference(PREFERENCE_MESSAGELIST_TOUCHABLE);
mTouchable.setChecked(K9.messageListTouchable());
mChangeRegisteredNameColor = (CheckBoxPreference)findPreference(PREFERENCE_CHANGE_REGISTERED_NAME_COLOR);
mChangeRegisteredNameColor.setChecked(K9.changeRegisteredNameColor());
if (K9.changeRegisteredNameColor())
mChangeRegisteredNameColor.setSummary(R.string.global_settings_registered_name_color_changed);
else
mChangeRegisteredNameColor.setSummary(R.string.global_settings_registered_name_color_default);
mChangeRegisteredNameColor.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
{
public boolean onPreferenceChange(Preference preference, Object newValue)
{
if ((boolean)(Boolean)newValue == true) {
onChooseRegisteredNameColor();
mChangeRegisteredNameColor.setSummary(R.string.global_settings_registered_name_color_changed);
}
else {
mChangeRegisteredNameColor.setSummary(R.string.global_settings_registered_name_color_default);
}
mChangeRegisteredNameColor.setChecked((Boolean)newValue);
return false;
}
});
mFixedWidth = (CheckBoxPreference)findPreference(PREFERENCE_MESSAGEVIEW_FIXEDWIDTH);
mFixedWidth.setChecked(K9.messageViewFixedWidthFont());
@ -283,6 +308,7 @@ public class Prefs extends K9PreferenceActivity
K9.setMessageListCheckboxes(mCheckboxes.isChecked());
K9.setMessageListTouchable(mTouchable.isChecked());
K9.setChangeRegisteredNameColor(mChangeRegisteredNameColor.isChecked());
K9.setMessageViewFixedWidthFont(mFixedWidth.isChecked());
K9.setMessageViewReturnToList(mReturnToList.isChecked());
@ -326,4 +352,15 @@ public class Prefs extends K9PreferenceActivity
FontSizeSettings.actionEditSettings(this);
}
public void onChooseRegisteredNameColor()
{
new ColorPickerDialog(this, new ColorPickerDialog.OnColorChangedListener()
{
public void colorChanged(int color)
{
K9.setRegisteredNameColor(color);
}
},
K9.getRegisteredNameColor()).show();
}
}

View File

@ -263,14 +263,19 @@ public class Address
if (name != null && name != NO_ENTRY)
{
if (K9.changeRegisteredNameColor()) {
SpannableString sname = new SpannableString(name);
sname.setSpan(new ForegroundColorSpan(Color.BLUE),
sname.setSpan(new ForegroundColorSpan(K9.getRegisteredNameColor()),
0,
sname.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
);
return sname;
}
else {
return name;
}
}
if (name == null)
{
Cursor cursor = contacts.searchByAddress(mAddress);
@ -281,17 +286,24 @@ public class Address
if (cursor.getCount() > 0)
{
cursor.moveToFirst();
name = contacts.getName(cursor);
name = contacts.getName(cursor); // name might return null
if (name != null) {
sContactsName.put(mAddress, name);
if (K9.changeRegisteredNameColor()) {
SpannableString sname = new SpannableString(name);
sname.setSpan(new ForegroundColorSpan(Color.BLUE),
sname.setSpan(new ForegroundColorSpan(K9.getRegisteredNameColor()),
0,
sname.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
);
return sname;
}
else {
return name;
}
}
}
else
{
sContactsName.put(mAddress, NO_ENTRY);