diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 40b72b962..eb0b23bc0 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -56,6 +56,11 @@ android:label="@string/prefs_title" > + + @string/date_format_common @string/date_format_iso8601 + + + + @string/font_size_tiniest + @string/font_size_tiny + @string/font_size_smaller + @string/font_size_small + @string/font_size_medium + @string/font_size_large + @string/font_size_larger + + + + 10 + 12 + 14 + 16 + 18 + 20 + 22 + + + + @string/font_size_webview_smaller + @string/font_size_webview_small + @string/font_size_webview_normal + @string/font_size_webview_large + @string/font_size_webview_larger + + + + + 1 + 2 + 3 + 4 + 5 + diff --git a/res/values/strings.xml b/res/values/strings.xml index 91558196d..5d4887ed3 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -709,7 +709,47 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin All Displayable None - + K-9 Mail remote control Allows this application to control K-9 Mail activities and settings. + + Font size + Configure font size + + Account list + Account name + Account description + + Folder list + Folder name + Folder status + + Message list + Message subject + Message sender + Message date + + Message view + Message sender + Message receiver (To) + Message receiver (CC) + Message subject + Message time + Message date + Message content + + Tiniest + Tiny + Smaller + Small + Medium + Large + Larger + + Smallest + Smaller + Normal + Larger + Largest + diff --git a/res/xml/font_preferences.xml b/res/xml/font_preferences.xml new file mode 100644 index 000000000..1a9385745 --- /dev/null +++ b/res/xml/font_preferences.xml @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/xml/global_preferences.xml b/res/xml/global_preferences.xml index d166330d3..01e86c3ac 100644 --- a/res/xml/global_preferences.xml +++ b/res/xml/global_preferences.xml @@ -16,7 +16,7 @@ - + - - + + - - - + + + + + - - + + + android:summary="@string/measure_accounts_summary" /> + - - - + android:summary="@string/count_search_summary" /> - + + + + + + - - + + - + android:summary="@string/global_settings_checkbox_summary" /> + + + - - + + + - - - - + + + + + + + diff --git a/src/com/fsck/k9/FontSizes.java b/src/com/fsck/k9/FontSizes.java new file mode 100644 index 000000000..73ff7b696 --- /dev/null +++ b/src/com/fsck/k9/FontSizes.java @@ -0,0 +1,348 @@ +package com.fsck.k9; + +import android.content.SharedPreferences; +import android.webkit.WebSettings.TextSize; + +/** + * Manage font size of the information displayed in the account list, folder + * list, message list and in the message view. + */ +public class FontSizes +{ + /* + * Keys for the preference storage. + */ + private static final String ACCOUNT_NAME = "fontSizeAccountName"; + private static final String ACCOUNT_DESCRIPTION = "fontSizeAccountDescription"; + private static final String FOLDER_NAME = "fontSizeFolderName"; + private static final String FOLDER_STATUS = "fontSizeFolderStatus"; + private static final String MESSAGE_LIST_SUBJECT = "fontSizeMessageListSubject"; + private static final String MESSAGE_LIST_SENDER = "fontSizeMessageListSender"; + private static final String MESSAGE_LIST_DATE = "fontSizeMessageListDate"; + private static final String MESSAGE_VIEW_SENDER = "fontSizeMessageViewSender"; + private static final String MESSAGE_VIEW_TO = "fontSizeMessageViewTo"; + private static final String MESSAGE_VIEW_CC = "fontSizeMessageViewCC"; + private static final String MESSAGE_VIEW_SUBJECT = "fontSizeMessageViewSubject"; + private static final String MESSAGE_VIEW_TIME = "fontSizeMessageViewTime"; + private static final String MESSAGE_VIEW_DATE = "fontSizeMessageViewDate"; + private static final String MESSAGE_VIEW_CONTENT = "fontSizeMessageViewContent"; + + /* + * Values for the font sizes in DIP (device independent pixel) + */ + public static final int FONT_10DIP = 10; + public static final int FONT_12DIP = 12; + public static final int SMALL = 14; // ?android:attr/textAppearanceSmall + public static final int FONT_16DIP = 16; + public static final int MEDIUM = 18; // ?android:attr/textAppearanceMedium + public static final int FONT_20DIP = 20; + public static final int LARGE = 22; // ?android:attr/textAppearanceLarge + + + /** + * Font size of account names in the account list activity. + */ + private int accountName; + + /** + * Font size of account descriptions in the account list activity. + */ + private int accountDescription; + + /** + * Font size of folder names in the folder list activity. + */ + private int folderName; + + /** + * Font size of the folder status in the folder list activity. + */ + private int folderStatus; + + /** + * Font size of message subjects in the message list activity. + */ + private int messageListSubject; + + /** + * Font size of message senders in the message list activity. + */ + private int messageListSender; + + /** + * Font size of message dates in the message list activity. + */ + private int messageListDate; + + /** + * Font size of the message sender in the message view activity. + */ + private int messageViewSender; + + /** + * Font size of the message receiver(s) (To) in the message view activity. + */ + private int messageViewTo; + + /** + * Font size of the message receiver(s) (CC) in the message view activity. + */ + private int messageViewCC; + + /** + * Font size of the message subject in the message view activity. + */ + private int messageViewSubject; + + /** + * Font size of the message time in the message view activity. + */ + private int messageViewTime; + + /** + * Font size of the message date in the message view activity. + */ + private int messageViewDate; + + /** + * Font size of the message content in the message view activity. + * + * Note: The unit is WebSettings.TextSize + */ + private TextSize messageViewContent = TextSize.NORMAL; + + /** + * Create a FontSizes object with default values. + */ + public FontSizes() + { + accountName = MEDIUM; + accountDescription = SMALL; + + folderName = LARGE; + folderStatus = SMALL; + + messageListSubject = SMALL; + messageListSender = SMALL; + messageListDate = SMALL; + + messageViewSender = SMALL; + messageViewTo = FONT_12DIP; + messageViewCC = FONT_12DIP; + messageViewSubject = FONT_12DIP; + messageViewTime = FONT_10DIP; + messageViewDate = FONT_10DIP; + } + + /** + * Permanently save the font size settings. + * + * @param editor Used to save the font size settings. + */ + public void save(SharedPreferences.Editor editor) + { + editor.putInt(ACCOUNT_NAME, accountName); + editor.putInt(ACCOUNT_DESCRIPTION, accountDescription); + + editor.putInt(FOLDER_NAME, folderName); + editor.putInt(FOLDER_STATUS, folderStatus); + + editor.putInt(MESSAGE_LIST_SUBJECT, messageListSubject); + editor.putInt(MESSAGE_LIST_SENDER, messageListSender); + editor.putInt(MESSAGE_LIST_DATE, messageListDate); + + editor.putInt(MESSAGE_VIEW_SUBJECT, messageViewSubject); + editor.putInt(MESSAGE_VIEW_TO, messageViewTo); + editor.putInt(MESSAGE_VIEW_CC, messageViewCC); + editor.putInt(MESSAGE_VIEW_SENDER, messageViewSender); + editor.putInt(MESSAGE_VIEW_TIME, messageViewTime); + editor.putInt(MESSAGE_VIEW_DATE, messageViewDate); + editor.putInt(MESSAGE_VIEW_CONTENT, getMessageViewContentAsInt()); + } + + /** + * Load the font size settings from permanent storage. + * + * @param prefs Used to load the font size settings. + */ + public void load(SharedPreferences prefs) + { + accountName = prefs.getInt(ACCOUNT_NAME, accountName); + accountDescription = prefs.getInt(ACCOUNT_DESCRIPTION, accountDescription); + + folderName = prefs.getInt(FOLDER_NAME, folderName); + folderStatus = prefs.getInt(FOLDER_STATUS, folderStatus); + + messageListSubject = prefs.getInt(MESSAGE_LIST_SUBJECT, messageListSubject); + messageListSender = prefs.getInt(MESSAGE_LIST_SENDER, messageListSender); + messageListDate = prefs.getInt(MESSAGE_LIST_DATE, messageListDate); + + messageViewSubject = prefs.getInt(MESSAGE_VIEW_SENDER, FONT_12DIP); + messageViewTo = prefs.getInt(MESSAGE_VIEW_TO, messageViewTo); + messageViewCC = prefs.getInt(MESSAGE_VIEW_CC, messageViewCC); + messageViewSender = prefs.getInt(MESSAGE_VIEW_SUBJECT, messageViewSender); + messageViewTime = prefs.getInt(MESSAGE_VIEW_TIME, messageViewTime); + messageViewDate = prefs.getInt(MESSAGE_VIEW_DATE, messageViewDate); + setMessageViewContent(prefs.getInt(MESSAGE_VIEW_CONTENT, 3)); + } + + public int getAccountName() + { + return accountName; + } + + public void setAccountName(int accountName) + { + this.accountName = accountName; + } + + public int getAccountDescription() + { + return accountDescription; + } + + public void setAccountDescription(int accountDescription) + { + this.accountDescription = accountDescription; + } + + public int getFolderName() + { + return folderName; + } + + public void setFolderName(int folderName) + { + this.folderName = folderName; + } + + public int getFolderStatus() + { + return folderStatus; + } + + public void setFolderStatus(int folderStatus) + { + this.folderStatus = folderStatus; + } + + public int getMessageListSubject() + { + return messageListSubject; + } + + public void setMessageListSubject(int messageListSubject) + { + this.messageListSubject = messageListSubject; + } + + public int getMessageListSender() + { + return messageListSender; + } + + public void setMessageListSender(int messageListSender) + { + this.messageListSender = messageListSender; + } + + public int getMessageListDate() + { + return messageListDate; + } + + public void setMessageListDate(int messageListDate) + { + this.messageListDate = messageListDate; + } + + public int getMessageViewSender() + { + return messageViewSender; + } + + public void setMessageViewSender(int messageViewSender) + { + this.messageViewSender = messageViewSender; + } + + public int getMessageViewTo() + { + return messageViewTo; + } + + public void setMessageViewTo(int messageViewTo) + { + this.messageViewTo = messageViewTo; + } + + public int getMessageViewCC() + { + return messageViewCC; + } + + public void setMessageViewCC(int messageViewCC) + { + this.messageViewCC = messageViewCC; + } + + public int getMessageViewSubject() + { + return messageViewSubject; + } + + public void setMessageViewSubject(int messageViewSubject) + { + this.messageViewSubject = messageViewSubject; + } + + public int getMessageViewTime() + { + return messageViewTime; + } + + public void setMessageViewTime(int messageViewTime) + { + this.messageViewTime = messageViewTime; + } + + public int getMessageViewDate() + { + return messageViewDate; + } + + public void setMessageViewDate(int messageViewDate) + { + this.messageViewDate = messageViewDate; + } + + public TextSize getMessageViewContent() + { + return messageViewContent; + } + + public int getMessageViewContentAsInt() + { + switch (messageViewContent) + { + case SMALLEST: return 1; + case SMALLER: return 2; + default: + case NORMAL: return 3; + case LARGER: return 4; + case LARGEST: return 5; + } + } + + public void setMessageViewContent(int size) + { + switch (size) + { + case 1: messageViewContent = TextSize.SMALLEST; break; + case 2: messageViewContent = TextSize.SMALLER; break; + case 3: messageViewContent = TextSize.NORMAL; break; + case 4: messageViewContent = TextSize.LARGER; break; + case 5: messageViewContent = TextSize.LARGEST; break; + } + } +} diff --git a/src/com/fsck/k9/K9.java b/src/com/fsck/k9/K9.java index 1d319b1b8..2d2f719b0 100644 --- a/src/com/fsck/k9/K9.java +++ b/src/com/fsck/k9/K9.java @@ -35,6 +35,8 @@ public class K9 extends Application private static int theme = android.R.style.Theme_Light; + private static final FontSizes fontSizes = new FontSizes(); + private static BACKGROUND_OPS backgroundOps = BACKGROUND_OPS.WHEN_CHECKED; /** * Some log messages can be sent to a file, so that the logs @@ -327,6 +329,8 @@ public class K9 extends Application editor.putBoolean("messageListCheckboxes",mMessageListCheckboxes); editor.putBoolean("messageListTouchable",mMessageListTouchable); editor.putInt("theme", theme); + + fontSizes.save(editor); } @Override @@ -346,6 +350,7 @@ public class K9 extends Application mMessageListCheckboxes = sprefs.getBoolean("messageListCheckboxes",false); mMessageListTouchable = sprefs.getBoolean("messageListTouchable",false); + fontSizes.load(sprefs); try { @@ -542,6 +547,11 @@ public class K9 extends Application } } + public static FontSizes getFontSizes() + { + return fontSizes; + } + public static boolean measureAccounts() { return mMeasureAccounts; diff --git a/src/com/fsck/k9/activity/Accounts.java b/src/com/fsck/k9/activity/Accounts.java index 8bcae3f4b..f36a68b01 100644 --- a/src/com/fsck/k9/activity/Accounts.java +++ b/src/com/fsck/k9/activity/Accounts.java @@ -11,6 +11,7 @@ import android.content.pm.PackageManager; import android.os.Bundle; import android.os.Handler; import android.util.Log; +import android.util.TypedValue; import android.view.*; import android.view.ContextMenu.ContextMenuInfo; import android.view.View.OnClickListener; @@ -45,7 +46,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC private SearchAccount flaggedAccount = null; private SearchAccount integratedInboxAccount = null; private SearchAccount integratedInboxStarredAccount = null; - + private FontSizes mFontSizes = K9.getFontSizes(); class AccountsHandler extends Handler { @@ -853,6 +854,9 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC holder.chip.getBackground().setAlpha(0); } + holder.description.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getAccountName()); + holder.email.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getAccountDescription()); + return view; } diff --git a/src/com/fsck/k9/activity/FolderList.java b/src/com/fsck/k9/activity/FolderList.java index 581fe6bcf..40ca2628c 100644 --- a/src/com/fsck/k9/activity/FolderList.java +++ b/src/com/fsck/k9/activity/FolderList.java @@ -13,6 +13,7 @@ import android.os.PowerManager; import android.os.PowerManager.WakeLock; import android.util.Config; import android.util.Log; +import android.util.TypedValue; import android.view.*; import android.view.ContextMenu.ContextMenuInfo; import android.widget.*; @@ -65,6 +66,8 @@ public class FolderList extends K9ListActivity private int mUnreadMessageCount; private int mFlaggedMessageCount; + private FontSizes mFontSizes = K9.getFontSizes(); + class FolderListHandler extends Handler { @@ -1259,6 +1262,10 @@ public class FolderList extends K9ListActivity holder.chip.getBackground().setAlpha(folder.unreadMessageCount == 0 ? 127 : 255); + holder.folderName.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getAccountName()); + holder.folderStatus.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getAccountDescription()); + + return view; } diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java index bcc89a0cb..a060db899 100644 --- a/src/com/fsck/k9/activity/MessageList.java +++ b/src/com/fsck/k9/activity/MessageList.java @@ -15,6 +15,7 @@ import android.text.Spannable; import android.text.style.TextAppearanceSpan; import android.util.Config; import android.util.Log; +import android.util.TypedValue; import android.view.*; import android.view.ContextMenu.ContextMenuInfo; import android.view.View.OnClickListener; @@ -116,6 +117,8 @@ public class MessageList private Button mBatchFlagButton; private Button mBatchDoneButton; + private FontSizes mFontSizes = K9.getFontSizes(); + class MessageListHandler extends Handler { @@ -2028,6 +2031,11 @@ public class MessageList holder.selected.setVisibility(View.GONE); holder.flagged.setChecked(false); } + + holder.subject.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getMessageListSubject()); + holder.from.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getMessageListSender()); + holder.date.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getMessageListDate()); + return view; } diff --git a/src/com/fsck/k9/activity/MessageView.java b/src/com/fsck/k9/activity/MessageView.java index b36035704..c0158461d 100644 --- a/src/com/fsck/k9/activity/MessageView.java +++ b/src/com/fsck/k9/activity/MessageView.java @@ -17,12 +17,14 @@ import android.provider.Contacts; import android.provider.Contacts.Intents; import android.util.Config; import android.util.Log; +import android.util.TypedValue; import android.view.*; import android.view.View.OnClickListener; import android.view.animation.AccelerateInterpolator; import android.view.animation.Animation; import android.view.animation.TranslateAnimation; import android.webkit.*; +import android.webkit.WebSettings.TextSize; import android.widget.*; import com.fsck.k9.*; import com.fsck.k9.mail.*; @@ -90,6 +92,8 @@ public class MessageView extends K9Activity implements OnClickListener private Listener mListener = new Listener(); private MessageViewHandler mHandler = new MessageViewHandler(); + private FontSizes mFontSizes = K9.getFontSizes(); + @Override public boolean dispatchKeyEvent(KeyEvent event) @@ -443,7 +447,6 @@ public class MessageView extends K9Activity implements OnClickListener mSubjectView = (TextView)findViewById(R.id.subject); defaultSubjectColor = mSubjectView.getCurrentTextColor(); - mDateView = (TextView)findViewById(R.id.date); mTimeView = (TextView)findViewById(R.id.time); mTopView = (ScrollView)findViewById(R.id.top_view); @@ -475,6 +478,17 @@ public class MessageView extends K9Activity implements OnClickListener //webSettings.setBuiltInZoomControls(true); webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); + webSettings.setTextSize(mFontSizes.getMessageViewContent()); + + mFromView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getMessageViewSender()); + mToView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getMessageViewTo()); + ((TextView)findViewById(R.id.to_label)).setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getMessageViewTo()); + mCcView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getMessageViewCC()); + ((TextView)findViewById(R.id.cc_label)).setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getMessageViewCC()); + mSubjectView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getMessageViewSubject()); + mTimeView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getMessageViewTime()); + mDateView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getMessageViewDate()); + mAttachments.setVisibility(View.GONE); mAttachmentIcon.setVisibility(View.GONE); diff --git a/src/com/fsck/k9/activity/setup/FontSizeSettings.java b/src/com/fsck/k9/activity/setup/FontSizeSettings.java new file mode 100644 index 000000000..9ecc2b957 --- /dev/null +++ b/src/com/fsck/k9/activity/setup/FontSizeSettings.java @@ -0,0 +1,176 @@ + +package com.fsck.k9.activity.setup; + +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.SharedPreferences.Editor; +import android.os.Bundle; +import android.preference.*; +import android.view.KeyEvent; +import com.fsck.k9.*; + +/** + * Activity to configure the font size of the information displayed in the + * account list, folder list, message list and in the message view. + * + * @see FontSizes + */ +public class FontSizeSettings extends K9PreferenceActivity +{ + /* + * Keys of the preferences defined in res/xml/font_preferences.xml + */ + private static final String PREFERENCE_ACCOUNT_NAME_FONT = "account_name_font"; + private static final String PREFERENCE_ACCOUNT_DESCRIPTION_FONT = "account_description_font"; + private static final String PREFERENCE_FOLDER_NAME_FONT = "folder_name_font"; + private static final String PREFERENCE_FOLDER_STATUS_FONT = "folder_status_font"; + private static final String PREFERENCE_MESSAGE_LIST_SUBJECT_FONT = "message_list_subject_font"; + private static final String PREFERENCE_MESSAGE_LIST_SENDER_FONT = "message_list_sender_font"; + private static final String PREFERENCE_MESSAGE_LIST_DATE_FONT = "message_list_date_font"; + private static final String PREFERENCE_MESSAGE_VIEW_SENDER_FONT = "message_view_sender_font"; + private static final String PREFERENCE_MESSAGE_VIEW_TO_FONT = "message_view_to_font"; + private static final String PREFERENCE_MESSAGE_VIEW_CC_FONT = "message_view_cc_font"; + private static final String PREFERENCE_MESSAGE_VIEW_SUBJECT_FONT = "message_view_subject_font"; + private static final String PREFERENCE_MESSAGE_VIEW_TIME_FONT = "message_view_time_font"; + private static final String PREFERENCE_MESSAGE_VIEW_DATE_FONT = "message_view_date_font"; + private static final String PREFERENCE_MESSAGE_VIEW_CONTENT_FONT = "message_view_content_font"; + + private ListPreference mAccountName; + private ListPreference mAccountDescription; + private ListPreference mFolderName; + private ListPreference mFolderStatus; + private ListPreference mMessageListSubject; + private ListPreference mMessageListSender; + private ListPreference mMessageListDate; + private ListPreference mMessageViewSender; + private ListPreference mMessageViewTo; + private ListPreference mMessageViewCC; + private ListPreference mMessageViewSubject; + private ListPreference mMessageViewTime; + private ListPreference mMessageViewDate; + private ListPreference mMessageViewContent; + + + /** + * Start the FontSizeSettings activity. + * + * @param context The application context. + */ + public static void actionEditSettings(Context context) + { + Intent i = new Intent(context, FontSizeSettings.class); + context.startActivity(i); + } + + @Override + public void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + + FontSizes fontSizes = K9.getFontSizes(); + addPreferencesFromResource(R.xml.font_preferences); + + mAccountName = initializeListPreference(PREFERENCE_ACCOUNT_NAME_FONT, fontSizes.getAccountName()); + mAccountDescription = initializeListPreference(PREFERENCE_ACCOUNT_DESCRIPTION_FONT, fontSizes.getAccountDescription()); + + mFolderName = initializeListPreference(PREFERENCE_FOLDER_NAME_FONT, fontSizes.getFolderName()); + mFolderStatus = initializeListPreference(PREFERENCE_FOLDER_STATUS_FONT, fontSizes.getFolderStatus()); + + mMessageListSubject = initializeListPreference(PREFERENCE_MESSAGE_LIST_SUBJECT_FONT, fontSizes.getMessageListSubject()); + mMessageListSender = initializeListPreference(PREFERENCE_MESSAGE_LIST_SENDER_FONT, fontSizes.getMessageListSender()); + mMessageListDate = initializeListPreference(PREFERENCE_MESSAGE_LIST_DATE_FONT, fontSizes.getMessageListDate()); + + mMessageViewSender = initializeListPreference(PREFERENCE_MESSAGE_VIEW_SENDER_FONT, fontSizes.getMessageViewSender()); + mMessageViewTo = initializeListPreference(PREFERENCE_MESSAGE_VIEW_TO_FONT, fontSizes.getMessageViewTo()); + mMessageViewCC = initializeListPreference(PREFERENCE_MESSAGE_VIEW_CC_FONT, fontSizes.getMessageViewCC()); + mMessageViewSubject = initializeListPreference(PREFERENCE_MESSAGE_VIEW_SUBJECT_FONT, fontSizes.getMessageViewSubject()); + mMessageViewTime = initializeListPreference(PREFERENCE_MESSAGE_VIEW_TIME_FONT, fontSizes.getMessageViewTime()); + mMessageViewDate = initializeListPreference(PREFERENCE_MESSAGE_VIEW_DATE_FONT, fontSizes.getMessageViewDate()); + mMessageViewContent = initializeListPreference(PREFERENCE_MESSAGE_VIEW_CONTENT_FONT, fontSizes.getMessageViewContentAsInt()); + } + + /** + * Update the global FontSize object and permanently store the (possibly + * changed) font size settings. + */ + private void saveSettings() + { + FontSizes fontSizes = K9.getFontSizes(); + + fontSizes.setAccountName(Integer.parseInt(mAccountName.getValue())); + fontSizes.setAccountDescription(Integer.parseInt(mAccountDescription.getValue())); + + fontSizes.setFolderName(Integer.parseInt(mFolderName.getValue())); + fontSizes.setFolderStatus(Integer.parseInt(mFolderStatus.getValue())); + + fontSizes.setMessageListSubject(Integer.parseInt(mMessageListSubject.getValue())); + fontSizes.setMessageListSender(Integer.parseInt(mMessageListSender.getValue())); + fontSizes.setMessageListDate(Integer.parseInt(mMessageListDate.getValue())); + + fontSizes.setMessageViewSender(Integer.parseInt(mMessageViewSender.getValue())); + fontSizes.setMessageViewTo(Integer.parseInt(mMessageViewTo.getValue())); + fontSizes.setMessageViewCC(Integer.parseInt(mMessageViewCC.getValue())); + fontSizes.setMessageViewSubject(Integer.parseInt(mMessageViewSubject.getValue())); + fontSizes.setMessageViewTime(Integer.parseInt(mMessageViewTime.getValue())); + fontSizes.setMessageViewDate(Integer.parseInt(mMessageViewDate.getValue())); + fontSizes.setMessageViewContent(Integer.parseInt(mMessageViewContent.getValue())); + + SharedPreferences preferences = Preferences.getPreferences(this).getPreferences(); + Editor editor = preferences.edit(); + fontSizes.save(editor); + editor.commit(); + } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) + { + if (keyCode == KeyEvent.KEYCODE_BACK) + { + saveSettings(); + } + return super.onKeyDown(keyCode, event); + } + + /** + * Set up the ListPreference instance identified by key. + * + * @param key The key of the ListPreference object. + * @param value Initial value for the ListPreference object. + * @return The ListPreference instance identified by key. + */ + private ListPreference initializeListPreference(String key, int value) + { + ListPreference prefView = (ListPreference) findPreference(key); + prefView.setValue(Integer.toString(value)); + prefView.setSummary(prefView.getEntry()); + prefView.setOnPreferenceChangeListener(new PreferenceChangeListener(prefView)); + return prefView; + } + + /** + * This class handles value changes of the ListPreference objects. + */ + private class PreferenceChangeListener implements Preference.OnPreferenceChangeListener + { + private ListPreference mPrefView; + + private PreferenceChangeListener(ListPreference prefView) + { + this.mPrefView = prefView; + } + + /** + * Show the preference value in the preference summary field. + */ + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) + { + final String summary = newValue.toString(); + int index = mPrefView.findIndexOfValue(summary); + mPrefView.setSummary(mPrefView.getEntries()[index]); + mPrefView.setValue(summary); + return false; + } + } +} diff --git a/src/com/fsck/k9/activity/setup/Prefs.java b/src/com/fsck/k9/activity/setup/Prefs.java index a48aafae7..40ab89354 100644 --- a/src/com/fsck/k9/activity/setup/Prefs.java +++ b/src/com/fsck/k9/activity/setup/Prefs.java @@ -20,6 +20,7 @@ public class Prefs extends K9PreferenceActivity { private static final String PREFERENCE_THEME = "theme"; + private static final String PREFERENCE_FONT_SIZE = "font_size"; private static final String PREFERENCE_DATE_FORMAT = "dateFormat"; private static final String PREFERENCE_BACKGROUND_OPS = "background_ops"; private static final String PREFERENCE_DEBUG_LOGGING = "debug_logging"; @@ -79,6 +80,16 @@ public class Prefs extends K9PreferenceActivity } }); + findPreference(PREFERENCE_FONT_SIZE).setOnPreferenceClickListener( + new Preference.OnPreferenceClickListener() + { + public boolean onPreferenceClick(Preference preference) + { + onFontSizeSettings(); + return true; + } + }); + mDateFormat = (ListPreference) findPreference(PREFERENCE_DATE_FORMAT); String[] formats = DateFormatter.getFormats(this); CharSequence[] entries = new CharSequence[formats.length]; @@ -193,4 +204,9 @@ public class Prefs extends K9PreferenceActivity return super.onKeyDown(keyCode, event); } + private void onFontSizeSettings() + { + FontSizeSettings.actionEditSettings(this); + } + }