diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 7cbac40df..1fb8cc8f1 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -118,6 +118,24 @@ list + + + @string/general_preference_text_zoom_tiny + @string/general_preference_text_zoom_small + @string/general_preference_text_zoom_normal + @string/general_preference_text_zoom_large + @string/general_preference_text_zoom_huge + + + + + tiny + small + normal + large + huge + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 9cd3c7e93..7187e2940 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -894,6 +894,32 @@ save attachment. This option is for "move back to the message list" [CHAR LIMIT=32] --> Message list + + Message text size + + + Display content of messages in tiny sized text + Display content of messages in small sized text + Display content of messages in normal sized text + Display content of messages in large sized text + Display content of messages in huge sized text + + + Message text size + + Tiny + + Small + + Normal + + Large + + Huge + - - - + + + + diff --git a/src/com/android/email/Preferences.java b/src/com/android/email/Preferences.java index c238c4b54..9d8d631ec 100644 --- a/src/com/android/email/Preferences.java +++ b/src/com/android/email/Preferences.java @@ -38,6 +38,7 @@ public class Preferences { private static final String DEVICE_UID = "deviceUID"; private static final String ONE_TIME_INITIALIZATION_PROGRESS = "oneTimeInitializationProgress"; private static final String AUTO_ADVANCE_DIRECTION = "autoAdvance"; + private static final String TEXT_ZOOM = "textZoom"; public static final int AUTO_ADVANCE_NEWER = 0; public static final int AUTO_ADVANCE_OLDER = 1; @@ -45,6 +46,14 @@ public class Preferences { // "move to older" was the behavior on older versions. public static final int AUTO_ADVANCE_DEFAULT = AUTO_ADVANCE_OLDER; + public static final int TEXT_ZOOM_TINY = 0; + public static final int TEXT_ZOOM_SMALL = 1; + public static final int TEXT_ZOOM_NORMAL = 2; + public static final int TEXT_ZOOM_LARGE = 3; + public static final int TEXT_ZOOM_HUGE = 4; + // "large" will be the default + public static final int TEXT_ZOOM_DEFAULT = TEXT_ZOOM_LARGE; + private static Preferences sPreferences; final SharedPreferences mSharedPreferences; @@ -202,6 +211,14 @@ public class Preferences { mSharedPreferences.edit().putInt(AUTO_ADVANCE_DIRECTION, direction).apply(); } + public int getTextZoom() { + return mSharedPreferences.getInt(TEXT_ZOOM, TEXT_ZOOM_DEFAULT); + } + + public void setTextZoom(int zoom) { + mSharedPreferences.edit().putInt(TEXT_ZOOM, zoom).apply(); + } + public void save() { } diff --git a/src/com/android/email/activity/MessageViewFragmentBase.java b/src/com/android/email/activity/MessageViewFragmentBase.java index 3ed51d9a3..ad4a18eb3 100644 --- a/src/com/android/email/activity/MessageViewFragmentBase.java +++ b/src/com/android/email/activity/MessageViewFragmentBase.java @@ -19,6 +19,7 @@ package com.android.email.activity; import com.android.email.Controller; import com.android.email.ControllerResultUiThreadWrapper; import com.android.email.Email; +import com.android.email.Preferences; import com.android.email.R; import com.android.email.Throttle; import com.android.email.Utility; @@ -59,6 +60,7 @@ import android.util.Patterns; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Button; @@ -351,6 +353,18 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O Log.d(Email.LOG_TAG, "MessageViewFragment onResume"); } super.onResume(); + + // Dynamic configuration of WebView + WebSettings.TextSize textZoom; + switch (Preferences.getPreferences(mContext).getTextZoom()) { + case Preferences.TEXT_ZOOM_TINY: textZoom = WebSettings.TextSize.SMALLEST; break; + case Preferences.TEXT_ZOOM_SMALL: textZoom = WebSettings.TextSize.SMALLER; break; + case Preferences.TEXT_ZOOM_NORMAL: textZoom = WebSettings.TextSize.NORMAL; break; + case Preferences.TEXT_ZOOM_LARGE: textZoom = WebSettings.TextSize.LARGER; break; + case Preferences.TEXT_ZOOM_HUGE: textZoom = WebSettings.TextSize.LARGEST; break; + default: textZoom = WebSettings.TextSize.NORMAL; break; + } + mMessageContentView.getSettings().setTextSize(textZoom); } @Override diff --git a/src/com/android/email/activity/setup/GeneralPreferences.java b/src/com/android/email/activity/setup/GeneralPreferences.java index 3f00d42e6..299c98fe1 100644 --- a/src/com/android/email/activity/setup/GeneralPreferences.java +++ b/src/com/android/email/activity/setup/GeneralPreferences.java @@ -21,14 +21,20 @@ import com.android.email.R; import android.os.Bundle; import android.preference.ListPreference; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; import android.preference.PreferenceFragment; -public class GeneralPreferences extends PreferenceFragment { +public class GeneralPreferences extends PreferenceFragment implements OnPreferenceChangeListener { - private static final String PREFERENCE_AUTO_ADVANCE= "auto_advance"; + private static final String PREFERENCE_KEY_AUTO_ADVANCE = "auto_advance"; + private static final String PREFERENCE_KEY_TEXT_ZOOM = "text_zoom"; private Preferences mPreferences; private ListPreference mAutoAdvance; + private ListPreference mTextZoom; + + CharSequence[] mSizeSummaries; @Override public void onCreate(Bundle savedInstanceState) { @@ -45,19 +51,47 @@ public class GeneralPreferences extends PreferenceFragment { } @Override - public void onPause() { - super.onPause(); - saveSettings(); + public boolean onPreferenceChange(Preference preference, Object newValue) { + String key = preference.getKey(); + + if (PREFERENCE_KEY_AUTO_ADVANCE.equals(key)) { + mPreferences.setAutoAdvanceDirection(mAutoAdvance.findIndexOfValue((String) newValue)); + return true; + } else if (PREFERENCE_KEY_TEXT_ZOOM.equals(key)) { + mPreferences.setTextZoom(mTextZoom.findIndexOfValue((String) newValue)); + reloadDynamicSummaries(); + return true; + } + return false; } private void loadSettings() { mPreferences = Preferences.getPreferences(getActivity()); - mAutoAdvance = (ListPreference) findPreference(PREFERENCE_AUTO_ADVANCE); + mAutoAdvance = (ListPreference) findPreference(PREFERENCE_KEY_AUTO_ADVANCE); mAutoAdvance.setValueIndex(mPreferences.getAutoAdvanceDirection()); + mAutoAdvance.setOnPreferenceChangeListener(this); + + mTextZoom = (ListPreference) findPreference(PREFERENCE_KEY_TEXT_ZOOM); + mTextZoom.setValueIndex(mPreferences.getTextZoom()); + mTextZoom.setOnPreferenceChangeListener(this); + + reloadDynamicSummaries(); } - private void saveSettings() { - mPreferences.setAutoAdvanceDirection( - mAutoAdvance.findIndexOfValue(mAutoAdvance.getValue())); + /** + * Reload any preference summaries that are updated dynamically + */ + private void reloadDynamicSummaries() { + int textZoomIndex = mPreferences.getTextZoom(); + // Update summary - but only load the array once + if (mSizeSummaries == null) { + mSizeSummaries = getActivity().getResources() + .getTextArray(R.array.general_preference_text_zoom_summary_array); + } + CharSequence summary = null; + if (textZoomIndex >= 0 && textZoomIndex < mSizeSummaries.length) { + summary = mSizeSummaries[textZoomIndex]; + } + mTextZoom.setSummary(summary); } }