Don't store the font-family preference with plain text messages.
Dynamically generate the CSS style for <pre> elements for inclusion in the HTML <head> element when messages are displayed. This permits a user to change their font-family preference for plain text messages and see the results immediately. Obviously any old locally-stored messages that had their font-family stored with them will continue to display using that font-family, irrespective of the user's current preference setting.
This commit is contained in:
parent
c21ea14af1
commit
c790fa73c1
4 changed files with 34 additions and 17 deletions
|
@ -317,6 +317,7 @@ public class HtmlConverter {
|
|||
protected static final String QUOTE_COLOR_LEVEL_3 = "#8ae234";
|
||||
protected static final String QUOTE_COLOR_LEVEL_4 = "#fcaf3e";
|
||||
protected static final String QUOTE_COLOR_LEVEL_5 = "#e9b96e";
|
||||
private static final String K9MAIL_CSS_CLASS = "k9mail";
|
||||
|
||||
/**
|
||||
* Return an HTML hex color string for a given quote level.
|
||||
|
@ -1230,16 +1231,34 @@ public class HtmlConverter {
|
|||
}
|
||||
|
||||
private static String htmlifyMessageHeader() {
|
||||
final String font = K9.messageViewFixedWidthFont()
|
||||
? "monospace"
|
||||
: "sans-serif";
|
||||
return "<pre style=\"white-space: pre-wrap; word-wrap:break-word; font-family: " + font + "; margin-top: 0px\">";
|
||||
return "<pre class=\"" + K9MAIL_CSS_CLASS + "\">";
|
||||
}
|
||||
|
||||
private static String htmlifyMessageFooter() {
|
||||
return "</pre>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically generate a CSS style for {@code <pre>} elements.
|
||||
*
|
||||
* <p>
|
||||
* The style incorporates the user's current preference
|
||||
* setting for the font family used for plain text messages.
|
||||
* </p>
|
||||
*
|
||||
* @return
|
||||
* A {@code <style>} element that can be dynamically included in the HTML
|
||||
* {@code <head>} element when messages are displayed.
|
||||
*/
|
||||
public static String cssStylePre() {
|
||||
final String font = K9.messageViewFixedWidthFont()
|
||||
? "monospace"
|
||||
: "sans-serif";
|
||||
return "<style type=\"text/css\"> pre." + K9MAIL_CSS_CLASS +
|
||||
" {white-space: pre-wrap; word-wrap:break-word; " +
|
||||
"font-family: " + font + "; margin-top: 0px}</style>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a plain text string into an HTML fragment.
|
||||
* @param text Plain text.
|
||||
|
|
|
@ -11,6 +11,8 @@ import android.webkit.WebSettings;
|
|||
import android.widget.Toast;
|
||||
import com.fsck.k9.K9;
|
||||
import com.fsck.k9.R;
|
||||
import com.fsck.k9.helper.HtmlConverter;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import com.nobu_games.android.view.web.TitleBarWebView;
|
||||
|
||||
|
@ -171,6 +173,7 @@ public class MessageWebView extends TitleBarWebView {
|
|||
":link, :link * { color: #CCFF33 !important }" +
|
||||
":visited, :visited * { color: #551A8B !important }</style> ";
|
||||
}
|
||||
content += HtmlConverter.cssStylePre();
|
||||
content += "</head><body>" + text + "</body></html>";
|
||||
loadDataWithBaseURL("http://", content, "text/html", "utf-8", null);
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public class HtmlConverterTest extends TestCase {
|
|||
">> Guess!";
|
||||
String result = HtmlConverter.textToHtml(message);
|
||||
writeToFile(result);
|
||||
assertEquals("<pre style=\"white-space: pre-wrap; word-wrap:break-word; font-family: sans-serif; margin-top: 0px\">Panama!<br /><br />Bob Barker <bob@aol.com> wrote:<br /><blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;\">a canal<br /><br />Dorothy Jo Gideon <dorothy@aol.com> espoused:<br /><blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;\">A man, a plan...<br /></blockquote>Too easy!</blockquote><br />Nice job :)<br /><blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;\"><blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;\">Guess!</blockquote></blockquote></pre>", result);
|
||||
assertEquals("<pre class=\"k9mail\">Panama!<br /><br />Bob Barker <bob@aol.com> wrote:<br /><blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;\">a canal<br /><br />Dorothy Jo Gideon <dorothy@aol.com> espoused:<br /><blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;\">A man, a plan...<br /></blockquote>Too easy!</blockquote><br />Nice job :)<br /><blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;\"><blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;\">Guess!</blockquote></blockquote></pre>", result);
|
||||
}
|
||||
|
||||
public void testTextQuoteToHtmlBlockquoteIndented() {
|
||||
|
@ -39,7 +39,7 @@ public class HtmlConverterTest extends TestCase {
|
|||
"> :)";
|
||||
String result = HtmlConverter.textToHtml(message);
|
||||
writeToFile(result);
|
||||
assertEquals("<pre style=\"white-space: pre-wrap; word-wrap:break-word; font-family: sans-serif; margin-top: 0px\">*facepalm*<br /><br />Bob Barker <bob@aol.com> wrote:<br /><blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;\">A wise man once said...<br /><br />LOL F1RST!!!!!<br /><br />:)</blockquote></pre>", result);
|
||||
assertEquals("<pre class=\"k9mail\">*facepalm*<br /><br />Bob Barker <bob@aol.com> wrote:<br /><blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;\">A wise man once said...<br /><br />LOL F1RST!!!!!<br /><br />:)</blockquote></pre>", result);
|
||||
}
|
||||
|
||||
public void testQuoteDepthColor() {
|
||||
|
@ -62,7 +62,7 @@ public class HtmlConverterTest extends TestCase {
|
|||
">>>>>> six";
|
||||
String result = HtmlConverter.textToHtml(message);
|
||||
writeToFile(result);
|
||||
assertEquals("<pre style=\"white-space: pre-wrap; word-wrap:break-word; font-family: sans-serif; margin-top: 0px\">zero<br /><blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;\">one<br /><blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;\">two<br /><blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;\">three<br /><blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #fcaf3e; padding-left: 1ex;\">four<br /><blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #e9b96e; padding-left: 1ex;\">five<br /><blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;\">six</blockquote></blockquote></blockquote></blockquote></blockquote></blockquote></pre>", result);
|
||||
assertEquals("<pre class=\"k9mail\">zero<br /><blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;\">one<br /><blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;\">two<br /><blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;\">three<br /><blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #fcaf3e; padding-left: 1ex;\">four<br /><blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #e9b96e; padding-left: 1ex;\">five<br /><blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;\">six</blockquote></blockquote></blockquote></blockquote></blockquote></blockquote></pre>", result);
|
||||
}
|
||||
|
||||
private void writeToFile(final String content) {
|
||||
|
|
|
@ -29,8 +29,7 @@ public class ViewablesTest extends AndroidTestCase {
|
|||
|
||||
String expectedText = bodyText;
|
||||
String expectedHtml =
|
||||
"<pre style=\"white-space: pre-wrap; word-wrap:break-word; " +
|
||||
"font-family: sans-serif; margin-top: 0px\">" +
|
||||
"<pre class=\"k9mail\">" +
|
||||
"K-9 Mail rocks :>" +
|
||||
"</pre>";
|
||||
|
||||
|
@ -87,14 +86,12 @@ public class ViewablesTest extends AndroidTestCase {
|
|||
"------------------------------------------------------------------------\n\n" +
|
||||
bodyText2;
|
||||
String expectedHtml =
|
||||
"<pre style=\"white-space: pre-wrap; word-wrap:break-word; " +
|
||||
"font-family: sans-serif; margin-top: 0px\">" +
|
||||
"<pre class=\"k9mail\">" +
|
||||
bodyText1 +
|
||||
"</pre>" +
|
||||
"<p style=\"margin-top: 2.5em; margin-bottom: 1em; " +
|
||||
"border-bottom: 1px solid #000\"></p>" +
|
||||
"<pre style=\"white-space: pre-wrap; word-wrap:break-word; " +
|
||||
"font-family: sans-serif; margin-top: 0px\">" +
|
||||
"<pre class=\"k9mail\">" +
|
||||
bodyText2 +
|
||||
"</pre>";
|
||||
|
||||
|
@ -152,8 +149,7 @@ public class ViewablesTest extends AndroidTestCase {
|
|||
"\n" +
|
||||
innerBodyText;
|
||||
String expectedHtml =
|
||||
"<pre style=\"white-space: pre-wrap; word-wrap:break-word; " +
|
||||
"font-family: sans-serif; margin-top: 0px\">" +
|
||||
"<pre class=\"k9mail\">" +
|
||||
bodyText +
|
||||
"</pre>" +
|
||||
"<p style=\"margin-top: 2.5em; margin-bottom: 1em; border-bottom: " +
|
||||
|
@ -173,8 +169,7 @@ public class ViewablesTest extends AndroidTestCase {
|
|||
"<td>Subject</td>" +
|
||||
"</tr>" +
|
||||
"</table>" +
|
||||
"<pre style=\"white-space: pre-wrap; word-wrap:break-word; " +
|
||||
"font-family: sans-serif; margin-top: 0px\">" +
|
||||
"<pre class=\"k9mail\">" +
|
||||
innerBodyText +
|
||||
"</pre>";
|
||||
|
||||
|
|
Loading…
Reference in a new issue