1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-08-13 17:03:48 -04:00

Remove unused code in HtmlConverter.

HtmlConverter.getHtmlHeader() and getHtmlFooter() are
no longer used.  Remove them and other related code.
This commit is contained in:
Joe Steele 2013-03-01 07:13:48 -05:00
parent e2c5229e85
commit 6a844a2553
4 changed files with 18 additions and 44 deletions

View File

@ -3047,7 +3047,7 @@ public class MessageCompose extends K9Activity implements OnClickListener {
if (part != null) { if (part != null) {
if (K9.DEBUG) if (K9.DEBUG)
Log.d(K9.LOG_TAG, "getBodyTextFromMessage: HTML requested, text found."); Log.d(K9.LOG_TAG, "getBodyTextFromMessage: HTML requested, text found.");
return HtmlConverter.textToHtml(MimeUtility.getTextFromPart(part), false); return HtmlConverter.textToHtml(MimeUtility.getTextFromPart(part));
} }
} else if (format == SimpleMessageFormat.TEXT) { } else if (format == SimpleMessageFormat.TEXT) {
// Text takes precedence, then html. // Text takes precedence, then html.

View File

@ -126,41 +126,27 @@ public class HtmlConverter {
private static final int MAX_SMART_HTMLIFY_MESSAGE_LENGTH = 1024 * 256 ; private static final int MAX_SMART_HTMLIFY_MESSAGE_LENGTH = 1024 * 256 ;
public static final String getHtmlHeader() {
// Include a meta tag so the MessageWebView will not use a fixed viewport width of 980 px
return "<html><head><meta name=\"viewport\" content=\"width=device-width\"/></head><body>";
}
public static final String getHtmlFooter() {
return "</body></html>";
}
/** /**
* Naively convert a text string into an HTML document. * Naively convert a text string into an HTML document.
* *
* <p> * <p>
* This method avoids using regular expressions on the entire message body to save memory. * This method avoids using regular expressions on the entire message body to save memory.
* </p> * </p>
* <p>
* No HTML headers or footers are added to the result.
* </p>
* *
* @param text * @param text
* Plain text string. * Plain text string.
* @param useHtmlTag
* If {@code true} this method adds headers and footers to create a proper HTML
* document.
*
* @return HTML string. * @return HTML string.
*/ */
private static String simpleTextToHtml(String text, boolean useHtmlTag) { private static String simpleTextToHtml(String text) {
// Encode HTML entities to make sure we don't display something evil. // Encode HTML entities to make sure we don't display something evil.
text = TextUtils.htmlEncode(text); text = TextUtils.htmlEncode(text);
StringReader reader = new StringReader(text); StringReader reader = new StringReader(text);
StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH);
if (useHtmlTag) {
buff.append(getHtmlHeader());
}
buff.append(htmlifyMessageHeader()); buff.append(htmlifyMessageHeader());
int c; int c;
@ -185,10 +171,6 @@ public class HtmlConverter {
buff.append(htmlifyMessageFooter()); buff.append(htmlifyMessageFooter());
if (useHtmlTag) {
buff.append(getHtmlFooter());
}
return buff.toString(); return buff.toString();
} }
@ -202,26 +184,26 @@ public class HtmlConverter {
* Convert a text string into an HTML document. * Convert a text string into an HTML document.
* *
* <p> * <p>
* Attempts to do smart replacement for large documents to prevent OOM errors. This method * Attempts to do smart replacement for large documents to prevent OOM
* optionally adds headers and footers to create a proper HTML document. To convert to a * errors.
* fragment, use {@link #textToHtmlFragment(String)}. * <p>
* No HTML headers or footers are added to the result.
* </p>
* <p>
* To convert to a fragment, use {@link #textToHtmlFragment(String)} .
* </p> * </p>
* *
* @param text * @param text
* Plain text string. * Plain text string.
* @param useHtmlTag
* If {@code true} this method adds headers and footers to create a proper HTML
* document.
*
* @return HTML string. * @return HTML string.
*/ */
public static String textToHtml(String text, boolean useHtmlTag) { public static String textToHtml(String text) {
// Our HTMLification code is somewhat memory intensive // Our HTMLification code is somewhat memory intensive
// and was causing lots of OOM errors on the market // and was causing lots of OOM errors on the market
// if the message is big and plain text, just do // if the message is big and plain text, just do
// a trivial htmlification // a trivial htmlification
if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) { if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) {
return simpleTextToHtml(text, useHtmlTag); return simpleTextToHtml(text);
} }
StringReader reader = new StringReader(text); StringReader reader = new StringReader(text);
StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH);
@ -313,18 +295,10 @@ public class HtmlConverter {
StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH); StringBuffer sb = new StringBuffer(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH);
if (useHtmlTag) {
sb.append(getHtmlHeader());
}
sb.append(htmlifyMessageHeader()); sb.append(htmlifyMessageHeader());
linkifyText(text, sb); linkifyText(text, sb);
sb.append(htmlifyMessageFooter()); sb.append(htmlifyMessageFooter());
if (useHtmlTag) {
sb.append(getHtmlFooter());
}
text = sb.toString(); text = sb.toString();
// Above we replaced > with <gt>, now make it &gt; // Above we replaced > with <gt>, now make it &gt;

View File

@ -1920,7 +1920,7 @@ public class MimeUtility {
* Use the contents of a {@link Viewable} to create the HTML to be displayed. * Use the contents of a {@link Viewable} to create the HTML to be displayed.
* *
* <p> * <p>
* This will use {@link HtmlConverter#textToHtml(String, boolean)} to convert plain text parts * This will use {@link HtmlConverter#textToHtml(String)} to convert plain text parts
* to HTML if necessary. * to HTML if necessary.
* </p> * </p>
* *
@ -1943,7 +1943,7 @@ public class MimeUtility {
if (t == null) { if (t == null) {
t = ""; t = "";
} else if (viewable instanceof Text) { } else if (viewable instanceof Text) {
t = HtmlConverter.textToHtml(t, false); t = HtmlConverter.textToHtml(t);
} }
html.append(t); html.append(t);
} else if (viewable instanceof Alternative) { } else if (viewable instanceof Alternative) {
@ -3352,7 +3352,7 @@ public class MimeUtility {
String bodyText = getTextFromPart(part); String bodyText = getTextFromPart(part);
if (bodyText != null) { if (bodyText != null) {
text = fixDraftTextBody(bodyText); text = fixDraftTextBody(bodyText);
html = HtmlConverter.textToHtml(text, false); html = HtmlConverter.textToHtml(text);
} }
} else if (part.isMimeType("multipart/alternative") && } else if (part.isMimeType("multipart/alternative") &&
firstBody instanceof MimeMultipart) { firstBody instanceof MimeMultipart) {

View File

@ -551,7 +551,7 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
if (pgpData != null) { if (pgpData != null) {
text = pgpData.getDecryptedData(); text = pgpData.getDecryptedData();
if (text != null) { if (text != null) {
text = HtmlConverter.textToHtml(text, false); text = HtmlConverter.textToHtml(text);
} }
} }