``.
+
+This also includes a workaround to prevent TextView crashing on [specific Android versions](http://code.google.com/p/android/issues/detail?id=35466).
+
+This library is kept very tiny with no external dependencies.
+I am using it to provide Help/About Activities in my apps.
+
+## Example
+
+```
+HtmlTextView text = new HtmlTextView(this);
+
+// loads html from string
+text.setHtmlFromString("Hello- world
- cats
");
+```
+or
+```
+HtmlTextView text = new HtmlTextView(this);
+
+// loads html from raw resource, i.e., a html file in res/raw/, this allows translatable resource (e.g., res/raw-de/ for german)
+text.setHtmlFromRawResource(this, R.raw.help);
+```
+
+## Use library as Gradle dependency (Android library project)
+
+1. Copy this folder to your project and include it in ``settings.gradle`` with ``include ':html-textview'``
+2. Add dependency ``compile project(':html-textview')`` to your project's ``build.gradle``.
+
+## License
+
+Apache License v2
+
+## Authors
+- This library was hacked together by Dominik Schürmann
+- Original [TagHandler](https://gist.github.com/mlakkadshaw/5983704) developed by [Mohammed Lakkadshaw](http://blog.mohammedlakkadshaw.com/)
+- Original [UrlImageGetter](https://gist.github.com/Antarix/4167655) developed by Antarix Tandon
+- [JellyBeanSpanFixTextView](https://gist.github.com/pyricau/3424004) (with fix from comment) developed by Pierre-Yves Ricau
+
+## Contributions
+
+Feel free to fork and do pull requests. I am more than happy to merge them.
+Please do not introduce external dependencies.
\ No newline at end of file
diff --git a/libraries/HtmlTextView/build.gradle b/libraries/HtmlTextView/build.gradle
new file mode 100644
index 000000000..40a586dab
--- /dev/null
+++ b/libraries/HtmlTextView/build.gradle
@@ -0,0 +1,24 @@
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:0.5.+'
+ }
+}
+
+apply plugin: 'android-library'
+
+
+android {
+ compileSdkVersion 17
+ buildToolsVersion '17'
+
+ sourceSets {
+ main {
+ manifest.srcFile 'AndroidManifest.xml'
+ java.srcDirs = ['src']
+ res.srcDirs = ['res']
+ }
+ }
+}
diff --git a/libraries/HtmlTextView/project.properties b/libraries/HtmlTextView/project.properties
new file mode 100644
index 000000000..5ca3505c8
--- /dev/null
+++ b/libraries/HtmlTextView/project.properties
@@ -0,0 +1,15 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-7
+android.library=true
diff --git a/libraries/HtmlTextView/src/org/sufficientlysecure/htmltextview/HtmlTagHandler.java b/libraries/HtmlTextView/src/org/sufficientlysecure/htmltextview/HtmlTagHandler.java
new file mode 100644
index 000000000..c40c8dec3
--- /dev/null
+++ b/libraries/HtmlTextView/src/org/sufficientlysecure/htmltextview/HtmlTagHandler.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2013 Mohammed Lakkadshaw
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.sufficientlysecure.htmltextview;
+
+import java.util.Vector;
+
+import org.xml.sax.XMLReader;
+
+import android.text.Editable;
+import android.text.Html;
+import android.text.Spannable;
+import android.text.style.BulletSpan;
+import android.text.style.LeadingMarginSpan;
+import android.text.style.TypefaceSpan;
+import android.util.Log;
+
+public class HtmlTagHandler implements Html.TagHandler {
+ private int mListItemCount = 0;
+ private Vector mListParents = new Vector();
+
+ @Override
+ public void handleTag(final boolean opening, final String tag, Editable output, final XMLReader xmlReader) {
+
+ if (tag.equals("ul") || tag.equals("ol") || tag.equals("dd")) {
+ if (opening) {
+ mListParents.add(tag);
+ } else mListParents.remove(tag);
+
+ mListItemCount = 0;
+ } else if (tag.equals("li") && !opening) {
+ handleListTag(output);
+ } else if (tag.equalsIgnoreCase("code")) {
+ if (opening) {
+ output.setSpan(new TypefaceSpan("monospace"), output.length(), output.length(), Spannable.SPAN_MARK_MARK);
+ } else {
+ Log.d(HtmlTextView.TAG, "Code tag encountered");
+ Object obj = getLast(output, TypefaceSpan.class);
+ int where = output.getSpanStart(obj);
+ output.setSpan(new TypefaceSpan("monospace"), where, output.length(), 0);
+ }
+ }
+ }
+
+ private Object getLast(Editable text, Class kind) {
+ Object[] objs = text.getSpans(0, text.length(), kind);
+ if (objs.length == 0) {
+ return null;
+ } else {
+ for (int i = objs.length; i > 0; i--) {
+ if (text.getSpanFlags(objs[i - 1]) == Spannable.SPAN_MARK_MARK) {
+ return objs[i - 1];
+ }
+ }
+ return null;
+ }
+ }
+
+ private void handleListTag(Editable output) {
+ if (mListParents.lastElement().equals("ul")) {
+ output.append("\n");
+ String[] split = output.toString().split("\n");
+
+ int lastIndex = split.length - 1;
+ int start = output.length() - split[lastIndex].length() - 1;
+ output.setSpan(new BulletSpan(15 * mListParents.size()), start, output.length(), 0);
+ } else if (mListParents.lastElement().equals("ol")) {
+ mListItemCount++;
+
+ output.append("\n");
+ String[] split = output.toString().split("\n");
+
+ int lastIndex = split.length - 1;
+ int start = output.length() - split[lastIndex].length() - 1;
+ output.insert(start, mListItemCount + ". ");
+ output.setSpan(new LeadingMarginSpan.Standard(15 * mListParents.size()), start, output.length(), 0);
+ }
+ }
+}
diff --git a/libraries/HtmlTextView/src/org/sufficientlysecure/htmltextview/HtmlTextView.java b/libraries/HtmlTextView/src/org/sufficientlysecure/htmltextview/HtmlTextView.java
new file mode 100644
index 000000000..317c25aaf
--- /dev/null
+++ b/libraries/HtmlTextView/src/org/sufficientlysecure/htmltextview/HtmlTextView.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2013 Dominik Schürmann
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.sufficientlysecure.htmltextview;
+
+import android.content.Context;
+import android.text.Html;
+import android.text.method.LinkMovementMethod;
+import android.util.AttributeSet;
+
+import java.io.InputStream;
+
+public class HtmlTextView extends JellyBeanSpanFixTextView {
+
+ public static final String TAG = "HtmlTextView";
+
+ public HtmlTextView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ public HtmlTextView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public HtmlTextView(Context context) {
+ super(context);
+ }
+
+ /**
+ * http://stackoverflow.com/questions/309424/read-convert-an-inputstream-to-a-string
+ *
+ * @param is
+ * @return
+ */
+ static private String convertStreamToString(java.io.InputStream is) {
+ java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
+ return s.hasNext() ? s.next() : "";
+ }
+
+ /**
+ * Loads HTML from a raw resource, i.e., a HTML file in res/raw/.
+ * This allows translatable resource (e.g., res/raw-de/ for german).
+ * The containing HTML is parsed to Android's Spannable format and then displayed.
+ *
+ * @param context
+ * @param id for example: R.raw.help
+ */
+ public void setHtmlFromRawResource(Context context, int id) {
+ // load html from html file from /res/raw
+ InputStream inputStreamText = context.getResources().openRawResource(id);
+
+ setHtmlFromString(convertStreamToString(inputStreamText));
+ }
+
+ /**
+ * Parses String containing HTML to Android's Spannable format and displays it in this TextView.
+ *
+ * @param html String containing HTML, for example: "Hello world!"
+ */
+ public void setHtmlFromString(String html) {
+ // this uses Android's Html class for basic parsing, and HtmlTagHandler
+ setText(Html.fromHtml(html, new UrlImageGetter(this, getContext()), new HtmlTagHandler()));
+
+ // make links work
+ setMovementMethod(LinkMovementMethod.getInstance());
+
+ // no flickering when clicking textview for Android < 4
+// text.setTextColor(getResources().getColor(android.R.color.secondary_text_dark_nodisable));
+ }
+}
diff --git a/libraries/HtmlTextView/src/org/sufficientlysecure/htmltextview/JellyBeanSpanFixTextView.java b/libraries/HtmlTextView/src/org/sufficientlysecure/htmltextview/JellyBeanSpanFixTextView.java
new file mode 100644
index 000000000..94bf45849
--- /dev/null
+++ b/libraries/HtmlTextView/src/org/sufficientlysecure/htmltextview/JellyBeanSpanFixTextView.java
@@ -0,0 +1,212 @@
+/*
+ * Copyright (C) 2013 Dominik Schürmann
+ * Copyright (C) 2012 Pierre-Yves Ricau
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.sufficientlysecure.htmltextview;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.content.Context;
+import android.text.SpannableStringBuilder;
+import android.text.Spanned;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.widget.TextView;
+
+/**
+ *
+ * A {@link android.widget.TextView} that insert spaces around its text spans where needed to prevent
+ * {@link IndexOutOfBoundsException} in {@link #onMeasure(int, int)} on Jelly Bean.
+ *
+ * When {@link #onMeasure(int, int)} throws an exception, we try to fix the text by adding spaces
+ * around spans, until it works again. We then try removing some of the added spans, to minimize the
+ * insertions.
+ *
+ * The fix is time consuming (a few ms, it depends on the size of your text), but it should only
+ * happen once per text change.
+ *
+ * See http://code.google.com/p/android/issues/detail?id=35466
+ *
+ */
+public class JellyBeanSpanFixTextView extends TextView {
+
+ private static class FixingResult {
+ public final boolean fixed;
+ public final List