Use HTML to format welcome message / make URL clickable

This commit is contained in:
cketti 2012-12-17 12:41:12 +01:00
parent 75329c45b3
commit caa26311f1
4 changed files with 84 additions and 26 deletions

View file

@ -16,10 +16,10 @@
android:orientation="vertical" >
<TextView
android:id="@+id/welcome_message"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="8dip"
android:text="@string/accounts_welcome"
android:textColor="?android:attr/textColorPrimary"
android:textSize="14sp" />

View file

@ -22,32 +22,37 @@
<!-- Welcome message -->
<string name="welcome_message_title">Welcome to K-9 Mail!</string>
<string name="accounts_welcome">
Welcome to K-9 Mail! K-9 is a powerful free email client for Android.
\n\n
\nK-9\'s improved features include:
\n * Push mail using IMAP IDLE
\n * Better performance
\n * Message refiling
\n * Email signatures
\n * Bcc-to-self
\n * Folder subscriptions
\n * All folder synchronization
\n * Return-address configuration
\n * Keyboard shortcuts
\n * Better IMAP support
\n * Saving attachments to SD
\n * Empty Trash
\n * Message sorting
\n * …and more
\n
\nPlease note that K-9 does not support most free Hotmail accounts and, like many mail clients, has
<string name="welcome_message_title">Welcome to K-9 Mail</string>
<string name="accounts_welcome"><![CDATA[
<p>
K-9 Mail is a powerful free email client for Android.
</p><p>
Its improved features include:
</p>
<ul>
<li>Push mail using IMAP IDLE</li>
<li>Better performance</li>
<li>Message refiling</li>
<li>Email signatures</li>
<li>Bcc-to-self</li>
<li>Folder subscriptions</li>
<li>All folder synchronization</li>
<li>Return-address configuration</li>
<li>Keyboard shortcuts</li>
<li>Better IMAP support</li>
<li>Saving attachments to SD</li>
<li>Empty Trash</li>
<li>Message sorting</li>
<li>…and more</li>
</ul>
<p>
Please note that K-9 does not support most free Hotmail accounts and, like many mail clients, has
some quirks when talking to Microsoft Exchange.
\n
\nPlease submit bug reports, contribute new features and ask questions at
http://k9mail.googlecode.com/
</string>
</p><p>
Please submit bug reports, contribute new features and ask questions at
<a href="http://k9mail.googlecode.com/">http://k9mail.googlecode.com/</a>.
</p>
]]></string>
<!-- Default signature -->

View file

@ -3,12 +3,15 @@ package com.fsck.k9.activity.setup;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.fsck.k9.R;
import com.fsck.k9.activity.K9Activity;
import com.fsck.k9.helper.HtmlConverter;
/**
* Displays a welcome message when no accounts have been created yet.
@ -24,6 +27,11 @@ public class WelcomeMessage extends K9Activity implements OnClickListener{
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.welcome_message);
TextView welcome = (TextView) findViewById(R.id.welcome_message);
welcome.setText(HtmlConverter.htmlToSpanned(getString(R.string.accounts_welcome)));
welcome.setMovementMethod(LinkMovementMethod.getInstance());
((Button) findViewById(R.id.next)).setOnClickListener(this);
}

View file

@ -1,6 +1,7 @@
package com.fsck.k9.helper;
import android.text.*;
import android.text.Html.TagHandler;
import android.util.Log;
import com.fsck.k9.K9;
import org.xml.sax.XMLReader;
@ -1272,4 +1273,48 @@ public class HtmlConverter {
// standard, but Gmail doesn't recognize it as an HTML entity. We unescape that here.
return linkified.toString().replace("\n", "<br>\n").replace("&apos;", "&#39;");
}
/**
* Convert HTML to a {@link Spanned} that can be used in a {@link android.widget.TextView}.
*
* @param html
* The HTML fragment to be converted.
*
* @return A {@link Spanned} containing the text in {@code html} formatted using spans.
*/
public static Spanned htmlToSpanned(String html) {
return Html.fromHtml(html, null, new ListTagHandler());
}
/**
* {@link TagHandler} that supports unordered lists.
*
* @see HtmlConverter#htmlToSpanned(String)
*/
public static class ListTagHandler implements TagHandler {
@Override
public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {
if (tag.equals("ul")) {
if (opening) {
char lastChar = 0;
if (output.length() > 0) {
lastChar = output.charAt(output.length() - 1);
}
if (lastChar != '\n') {
output.append("\n");
}
} else {
output.append("\n");
}
}
if (tag.equals("li")) {
if (opening) {
output.append("\t• ");
} else {
output.append("\n");
}
}
}
}
}