Implement text zoom for Message View

* Add preference for default text size
* Move saveSettings logic into onPreferenceChange handler
* Per user tests, default setting is large (not "normal") for XL devices.
* Use setting in MessageView's WebView

TODO: Investigate zooming header (to/from/subject/etc) as well.

Bug: 2282390
Change-Id: If32ed3626244b046941a461f974b3dbdb535f592
This commit is contained in:
Andrew Stadler 2010-11-02 14:57:22 -07:00
parent 278cb8e3d5
commit ba0b1bbc8d
6 changed files with 127 additions and 12 deletions

View File

@ -118,6 +118,24 @@
<item>list</item>
</string-array>
<!-- Text Zoom options (DO NOT change the order. Code assumes this order)-->
<string-array name="general_preference_text_zoom_entries">
<item>@string/general_preference_text_zoom_tiny</item>
<item>@string/general_preference_text_zoom_small</item>
<item>@string/general_preference_text_zoom_normal</item>
<item>@string/general_preference_text_zoom_large</item>
<item>@string/general_preference_text_zoom_huge</item>
</string-array>
<!-- Text Zoom option values (DO NOT change the order. Code assumes this order)-->
<string-array translatable="false" name="general_preference_text_zoom_values">
<item>tiny</item>
<item>small</item>
<item>normal</item>
<item>large</item>
<item>huge</item>
</string-array>
<!-- Arrays "mailbox_display_names" and "mailbox_display_icons" MUST match the order
of the types of mailboxes defined in EmailContent -->
<string-array name="mailbox_display_names" translatable="false">

View File

@ -894,6 +894,32 @@ save attachment.</string>
This option is for "move back to the message list" [CHAR LIMIT=32] -->
<string name="general_preference_auto_advance_message_list">Message list</string>
<!-- General preference: Label of the setting for the text zoom. [CHAR LIMIT=32] -->
<string name="general_preference_text_zoom_label">Message text size</string>
<!-- General preference: Description of each setting for text zoom. The entries here must
correspond to the strings general_preference_text_zoom_tiny,
general_preference_text_zoom_small, general_preference_text_zoom_normal, etc.
[CHAR LIMIT=64] -->
<string-array name="general_preference_text_zoom_summary_array">
<item>Display content of messages in tiny sized text</item>
<item>Display content of messages in small sized text</item>
<item>Display content of messages in normal sized text</item>
<item>Display content of messages in large sized text</item>
<item>Display content of messages in huge sized text</item>
</string-array>
<!-- General preference: Title of the dialog box with options for text zoom. [CHAR LIMIT=32] -->
<string name="general_preference_text_zoom_dialog_title">Message text size</string>
<!-- General preference: Text zoom. Value is "tiny" (-2) [CHAR LIMIT=32] -->
<string name="general_preference_text_zoom_tiny">Tiny</string>
<!-- General preference: Text zoom. Value is "small" (-1) [CHAR LIMIT=32] -->
<string name="general_preference_text_zoom_small">Small</string>
<!-- General preference: Text zoom. Value is "normal" (0) [CHAR LIMIT=32] -->
<string name="general_preference_text_zoom_normal">Normal</string>
<!-- General preference: Text zoom. Value is "large" (+1) [CHAR LIMIT=32] -->
<string name="general_preference_text_zoom_large">Large</string>
<!-- General preference: Text zoom. Value is "huge" (+2) [CHAR LIMIT=32] -->
<string name="general_preference_text_zoom_huge">Huge</string>
<!--
Strings for temporary UI
STOPSHIP Remove them or move them up and make translatable

View File

@ -14,9 +14,7 @@
limitations under the License.
-->
<!-- This is a primitive example showing the different types of preferences available. -->
<!-- STOPSHIP add some real preferences -->
<!-- App-wide preferences -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
@ -30,5 +28,13 @@
android:entryValues="@array/general_preference_auto_advance_values"
android:dialogTitle="@string/general_preference_auto_advance_dialog_title" />
<!-- Note, summary is set dynamically in GeneralPreferences.java -->
<ListPreference
android:key="text_zoom"
android:title="@string/general_preference_text_zoom_label"
android:entries="@array/general_preference_text_zoom_entries"
android:entryValues="@array/general_preference_text_zoom_values"
android:dialogTitle="@string/general_preference_text_zoom_dialog_title" />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -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() {
}

View File

@ -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

View File

@ -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);
}
}