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 (K9.DEBUG)
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) {
// 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 ;
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.
*
* <p>
* This method avoids using regular expressions on the entire message body to save memory.
* </p>
* <p>
* No HTML headers or footers are added to the result.
* </p>
*
* @param text
* Plain text string.
* @param useHtmlTag
* If {@code true} this method adds headers and footers to create a proper HTML
* document.
*
* @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.
text = TextUtils.htmlEncode(text);
StringReader reader = new StringReader(text);
StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH);
if (useHtmlTag) {
buff.append(getHtmlHeader());
}
buff.append(htmlifyMessageHeader());
int c;
@ -185,10 +171,6 @@ public class HtmlConverter {
buff.append(htmlifyMessageFooter());
if (useHtmlTag) {
buff.append(getHtmlFooter());
}
return buff.toString();
}
@ -202,26 +184,26 @@ public class HtmlConverter {
* Convert a text string into an HTML document.
*
* <p>
* Attempts to do smart replacement for large documents to prevent OOM errors. This method
* optionally adds headers and footers to create a proper HTML document. To convert to a
* fragment, use {@link #textToHtmlFragment(String)}.
* Attempts to do smart replacement for large documents to prevent OOM
* errors.
* <p>
* No HTML headers or footers are added to the result.
* </p>
* <p>
* To convert to a fragment, use {@link #textToHtmlFragment(String)} .
* </p>
*
* @param text
* Plain text string.
* @param useHtmlTag
* If {@code true} this method adds headers and footers to create a proper HTML
* document.
*
* @return HTML string.
*/
public static String textToHtml(String text, boolean useHtmlTag) {
public static String textToHtml(String text) {
// Our HTMLification code is somewhat memory intensive
// and was causing lots of OOM errors on the market
// if the message is big and plain text, just do
// a trivial htmlification
if (text.length() > MAX_SMART_HTMLIFY_MESSAGE_LENGTH) {
return simpleTextToHtml(text, useHtmlTag);
return simpleTextToHtml(text);
}
StringReader reader = new StringReader(text);
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);
if (useHtmlTag) {
sb.append(getHtmlHeader());
}
sb.append(htmlifyMessageHeader());
linkifyText(text, sb);
sb.append(htmlifyMessageFooter());
if (useHtmlTag) {
sb.append(getHtmlFooter());
}
text = sb.toString();
// 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.
*
* <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.
* </p>
*
@ -1943,7 +1943,7 @@ public class MimeUtility {
if (t == null) {
t = "";
} else if (viewable instanceof Text) {
t = HtmlConverter.textToHtml(t, false);
t = HtmlConverter.textToHtml(t);
}
html.append(t);
} else if (viewable instanceof Alternative) {
@ -3352,7 +3352,7 @@ public class MimeUtility {
String bodyText = getTextFromPart(part);
if (bodyText != null) {
text = fixDraftTextBody(bodyText);
html = HtmlConverter.textToHtml(text, false);
html = HtmlConverter.textToHtml(text);
}
} else if (part.isMimeType("multipart/alternative") &&
firstBody instanceof MimeMultipart) {

View File

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