├── htmltextview ├── pom.xml ├── src │ └── main │ │ ├── res │ │ └── values │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── sysdata │ │ └── kt │ │ └── htmltextview │ │ └── SDHtmlTextView.kt ├── proguard-rules.pro ├── build.gradle └── publishBintray.gradle ├── settings.gradle ├── app ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ └── activity_main.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── sysdata │ │ │ └── kt │ │ │ └── sdhtmltextview │ │ │ └── MainActivity.kt │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── sysdata │ │ │ └── kt │ │ │ └── sdhtmltextview │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── sysdata │ │ └── kt │ │ └── sdhtmltextview │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .idea ├── caches │ └── build_file_checksums.ser ├── vcs.xml ├── runConfigurations.xml ├── modules.xml └── misc.xml ├── release ├── htmlspanner-release-1.0.3.aar └── htmltextview-release-1.0.3.aar ├── HtmlSpanner ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── src │ ├── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── sysdata │ │ │ └── htmlspanner │ │ │ ├── exception │ │ │ └── ParsingCancelledException.java │ │ │ ├── FontResolver.java │ │ │ ├── SpanCallback.java │ │ │ ├── spans │ │ │ ├── CenterSpan.java │ │ │ ├── AlignNormalSpan.java │ │ │ ├── AlignOppositeSpan.java │ │ │ ├── VerticalMarginSpan.java │ │ │ ├── LineHeightSpanImpl.java │ │ │ ├── ListItemSpan.java │ │ │ ├── HorizontalLineSpan.java │ │ │ ├── FontFamilySpan.java │ │ │ └── BorderSpan.java │ │ │ ├── handlers │ │ │ ├── MonoSpaceHandler.java │ │ │ ├── WrappingHandler.java │ │ │ ├── attributes │ │ │ │ ├── HorizontalLineHandler.java │ │ │ │ ├── BorderAttributeHandler.java │ │ │ │ ├── WrappingStyleHandler.java │ │ │ │ ├── AlignmentAttributeHandler.java │ │ │ │ └── StyleAttributeHandler.java │ │ │ ├── SubScriptHandler.java │ │ │ ├── SuperScriptHandler.java │ │ │ ├── UnderlineHandler.java │ │ │ ├── LinkHandler.java │ │ │ ├── StyleNodeHandler.java │ │ │ ├── NewLineHandler.java │ │ │ ├── HeaderHandler.java │ │ │ ├── PreHandler.java │ │ │ ├── FontHandler.java │ │ │ ├── ListItemHandler.java │ │ │ ├── ImageHandler.java │ │ │ ├── StyledTextHandler.java │ │ │ └── TableHandler.java │ │ │ ├── FontFamily.java │ │ │ ├── css │ │ │ └── CompiledRule.java │ │ │ ├── SystemFontResolver.java │ │ │ ├── TextUtil.java │ │ │ ├── style │ │ │ ├── StyleValue.java │ │ │ ├── StyleCallback.java │ │ │ └── Style.java │ │ │ ├── SpanStack.java │ │ │ └── TagNodeHandler.java │ └── test │ │ └── java │ │ └── com │ │ └── sysdata │ │ └── htmlspanner │ │ └── RuleMatchingTest.java ├── README.md ├── pom.xml ├── build.gradle ├── gradlew.bat ├── publishBintray.gradle ├── gradlew └── LICENSE-2.0.txt ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── gradlew ├── README.md └── LICENSE /htmltextview/pom.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':htmltextview', ':htmlspanner' 2 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SDHtmlTextView 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SysdataSpA/SDHtmlTextView/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /htmltextview/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | htmlTextView 3 | 4 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SysdataSpA/SDHtmlTextView/HEAD/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /release/htmlspanner-release-1.0.3.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SysdataSpA/SDHtmlTextView/HEAD/release/htmlspanner-release-1.0.3.aar -------------------------------------------------------------------------------- /release/htmltextview-release-1.0.3.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SysdataSpA/SDHtmlTextView/HEAD/release/htmltextview-release-1.0.3.aar -------------------------------------------------------------------------------- /HtmlSpanner/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SysdataSpA/SDHtmlTextView/HEAD/HtmlSpanner/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SysdataSpA/SDHtmlTextView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SysdataSpA/SDHtmlTextView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SysdataSpA/SDHtmlTextView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SysdataSpA/SDHtmlTextView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SysdataSpA/SDHtmlTextView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SysdataSpA/SDHtmlTextView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SysdataSpA/SDHtmlTextView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SysdataSpA/SDHtmlTextView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /htmltextview/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SysdataSpA/SDHtmlTextView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SysdataSpA/SDHtmlTextView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /htmltextview/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Jul 16 10:56:15 CEST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 7 | -------------------------------------------------------------------------------- /HtmlSpanner/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Feb 28 10:37:10 CET 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.3-bin.zip 7 | -------------------------------------------------------------------------------- /HtmlSpanner/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /HtmlSpanner/src/main/java/com/sysdata/htmlspanner/exception/ParsingCancelledException.java: -------------------------------------------------------------------------------- 1 | package com.sysdata.htmlspanner.exception; 2 | 3 | /** 4 | Simple RuntimeException which is throws when parsing is cancelled by the user. 5 | 6 | @author Alex Kuiper 7 | */ 8 | 9 | public class ParsingCancelledException extends RuntimeException { 10 | } 11 | -------------------------------------------------------------------------------- /HtmlSpanner/src/main/java/com/sysdata/htmlspanner/FontResolver.java: -------------------------------------------------------------------------------- 1 | package com.sysdata.htmlspanner; 2 | 3 | /** 4 | * Interface for font-resolving components. 5 | */ 6 | public interface FontResolver { 7 | 8 | FontFamily getDefaultFont(); 9 | 10 | FontFamily getSansSerifFont(); 11 | 12 | FontFamily getSerifFont(); 13 | 14 | FontFamily getMonoSpaceFont(); 15 | 16 | FontFamily getFont( String name ); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated files 2 | bin/ 3 | gen/ 4 | out/ 5 | 6 | # Gradle files 7 | .gradle/ 8 | build/ 9 | 10 | # Local configuration file (sdk path, etc) 11 | local.properties 12 | 13 | # Proguard folder generated by Eclipse 14 | proguard/ 15 | 16 | # Log Files 17 | *.log 18 | 19 | # Android Studio Navigation editor temp files 20 | .navigation/ 21 | 22 | # Android Studio captures folder 23 | captures/ 24 | 25 | # Intellij 26 | *.iml 27 | .idea/ -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /HtmlSpanner/src/main/java/com/sysdata/htmlspanner/SpanCallback.java: -------------------------------------------------------------------------------- 1 | package com.sysdata.htmlspanner; 2 | 3 | import android.text.SpannableStringBuilder; 4 | 5 | /** 6 | * Created with IntelliJ IDEA. 7 | * User: alex 8 | * Date: 5/6/13 9 | * Time: 3:13 PM 10 | * To change this template use File | Settings | File Templates. 11 | */ 12 | public interface SpanCallback { 13 | 14 | void applySpan( HtmlSpanner spanner, SpannableStringBuilder builder ); 15 | 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/test/java/com/sysdata/kt/sdhtmltextview/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.sysdata.kt.sdhtmltextview 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/sysdata/kt/sdhtmltextview/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.sysdata.kt.sdhtmltextview 2 | 3 | import android.support.test.InstrumentationRegistry 4 | import android.support.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("com.sysdata.kt.sdhtmltextview", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /htmltextview/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 18 | -------------------------------------------------------------------------------- /HtmlSpanner/src/main/java/com/sysdata/htmlspanner/spans/CenterSpan.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Alex Kuiper 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sysdata.htmlspanner.spans; 18 | 19 | import android.text.Layout.Alignment; 20 | import android.text.style.AlignmentSpan; 21 | 22 | public class CenterSpan implements AlignmentSpan { 23 | 24 | @Override 25 | public Alignment getAlignment() { 26 | return Alignment.ALIGN_CENTER; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /HtmlSpanner/src/main/java/com/sysdata/htmlspanner/spans/AlignNormalSpan.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Alex Kuiper 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sysdata.htmlspanner.spans; 18 | 19 | import android.text.Layout.Alignment; 20 | import android.text.style.AlignmentSpan; 21 | 22 | public class AlignNormalSpan implements AlignmentSpan { 23 | 24 | @Override 25 | public Alignment getAlignment() { 26 | return Alignment.ALIGN_NORMAL; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /HtmlSpanner/src/main/java/com/sysdata/htmlspanner/spans/AlignOppositeSpan.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Alex Kuiper 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.sysdata.htmlspanner.spans; 18 | 19 | import android.text.Layout.Alignment; 20 | import android.text.style.AlignmentSpan; 21 | 22 | public class AlignOppositeSpan implements AlignmentSpan { 23 | 24 | @Override 25 | public Alignment getAlignment() { 26 | return Alignment.ALIGN_OPPOSITE; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /HtmlSpanner/src/main/java/com/sysdata/htmlspanner/handlers/MonoSpaceHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Alex Kuiper 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.sysdata.htmlspanner.handlers; 17 | 18 | import com.sysdata.htmlspanner.style.Style; 19 | 20 | /** 21 | * Sets monotype font. 22 | * 23 | * @author Alex Kuiper 24 | * 25 | */ 26 | public class MonoSpaceHandler extends StyledTextHandler { 27 | 28 | @Override 29 | public Style getStyle() { 30 | return new Style().setFontFamily( 31 | getSpanner().getFontResolver().getMonoSpaceFont() ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /HtmlSpanner/src/main/java/com/sysdata/htmlspanner/handlers/WrappingHandler.java: -------------------------------------------------------------------------------- 1 | package com.sysdata.htmlspanner.handlers; 2 | 3 | import android.text.SpannableStringBuilder; 4 | import com.sysdata.htmlspanner.HtmlSpanner; 5 | import com.sysdata.htmlspanner.SpanStack; 6 | import com.sysdata.htmlspanner.TagNodeHandler; 7 | import org.htmlcleaner.TagNode; 8 | 9 | /** 10 | *TagNodeHandler which wraps another handler. 11 | * 12 | * Default implementation just delegates to the wrapped handler. 13 | */ 14 | public class WrappingHandler extends TagNodeHandler { 15 | 16 | private TagNodeHandler wrappedHandler; 17 | 18 | public WrappingHandler(TagNodeHandler wrappedHandler) { 19 | this.wrappedHandler = wrappedHandler; 20 | } 21 | 22 | @Override 23 | public void handleTagNode(TagNode node, SpannableStringBuilder builder, int start, int end, SpanStack spanStack) { 24 | wrappedHandler.handleTagNode(node, builder, start, end, spanStack); 25 | } 26 | 27 | @Override 28 | public void setSpanner(HtmlSpanner spanner) { 29 | super.setSpanner(spanner); 30 | wrappedHandler.setSpanner(spanner); 31 | } 32 | 33 | protected TagNodeHandler getWrappedHandler() { 34 | return wrappedHandler; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /HtmlSpanner/README.md: -------------------------------------------------------------------------------- 1 | # Android HTML rendering library 2 | 3 | HtmlSpanner started as the HTML rendering library for PageTurner, but looking through some questions on StackOverflow I noticed how many people were struggling with the infamous ``Html.fromHtml()`` and getting its results to display properly in TextViews. 4 | 5 | HtmlSpanner allows you full control over how tags are rendered and gives you all the data about the location of a tag in the text. This allows proper handling of anchors, tables, numbered lists and unordered lists. 6 | 7 | The default link implementation just opens URLs, but it can be easily overridden to support anchors. 8 | 9 | HtmlSpanner uses HtmlCleaner to do most of the heavy lifting for parsing HTML files. 10 | 11 | # CSS support 12 | 13 | HtmlSpanner now also supports the most common subset of CSS: both style tags and style attributes are parsed by default, and the style of all built-in tags can be updated. 14 | 15 | # Usage 16 | In its simplest form, just call ``(new HtmlSpanner()).fromHtml()`` to get similar output as Android's ``Html.fromHtml()``. 17 | 18 | # HTMLCleaner Source 19 | see http://htmlcleaner.sourceforge.net/index.php 20 | 21 | The fork under https://github.com/amplafi/htmlcleaner can not be used on Android <= 2.1 as it uses java.lang.String.isEmpty 22 | -------------------------------------------------------------------------------- /HtmlSpanner/src/main/java/com/sysdata/htmlspanner/spans/VerticalMarginSpan.java: -------------------------------------------------------------------------------- 1 | package com.sysdata.htmlspanner.spans; 2 | 3 | import android.graphics.Paint; 4 | import android.text.style.LineHeightSpan; 5 | 6 | /** 7 | * Span used to implement the top- and bottom margin of blocks. 8 | * 9 | * Generally this is placed on a blank line, so that the height of 10 | * that line can be changed to create a margin. 11 | * 12 | * @author Alex Kuiper 13 | */ 14 | public class VerticalMarginSpan implements LineHeightSpan { 15 | 16 | private final Float factor; 17 | private final Integer absolute; 18 | 19 | public VerticalMarginSpan(Float margin) { 20 | this.factor = margin; 21 | this.absolute = null; 22 | } 23 | 24 | public VerticalMarginSpan(Integer value) { 25 | this.absolute = value; 26 | this.factor = null; 27 | } 28 | 29 | @Override 30 | public void chooseHeight(CharSequence text, int start, int end, int spanstartv, int v, 31 | Paint.FontMetricsInt fm) { 32 | 33 | int height = Math.abs( fm.descent - fm.ascent ); 34 | 35 | if ( factor != null ) { 36 | height = (int) (height * factor); 37 | } else if ( absolute != null ) { 38 | height = absolute; 39 | } 40 | 41 | fm.descent = fm.ascent + height; 42 | 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /HtmlSpanner/src/main/java/com/sysdata/htmlspanner/handlers/attributes/HorizontalLineHandler.java: -------------------------------------------------------------------------------- 1 | package com.sysdata.htmlspanner.handlers.attributes; 2 | 3 | import android.text.SpannableStringBuilder; 4 | import android.util.Log; 5 | 6 | import com.sysdata.htmlspanner.SpanStack; 7 | import com.sysdata.htmlspanner.handlers.StyledTextHandler; 8 | import com.sysdata.htmlspanner.spans.HorizontalLineSpan; 9 | import com.sysdata.htmlspanner.style.Style; 10 | 11 | import org.htmlcleaner.TagNode; 12 | 13 | /** 14 | * Created with IntelliJ IDEA. 15 | * User: alex 16 | * Date: 6/23/13 17 | * Time: 3:36 PM 18 | * To change this template use File | Settings | File Templates. 19 | */ 20 | public class HorizontalLineHandler extends WrappingStyleHandler { 21 | 22 | public HorizontalLineHandler(StyledTextHandler handler) { 23 | super(handler); 24 | } 25 | 26 | @Override 27 | public void handleTagNode(TagNode node, SpannableStringBuilder builder, int start, int end, 28 | Style useStyle, SpanStack spanStack) { 29 | 30 | end+=1; 31 | Log.d("HorizontalLineHandler", "Draw hr from " + start + " to " + end); 32 | spanStack.pushSpan(new HorizontalLineSpan(useStyle, start, end), start, end); 33 | appendNewLine(builder); 34 | 35 | super.handleTagNode(node, builder, start, end, useStyle, spanStack); 36 | 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /HtmlSpanner/src/main/java/com/sysdata/htmlspanner/handlers/SubScriptHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Alex Kuiper 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.sysdata.htmlspanner.handlers; 17 | 18 | import com.sysdata.htmlspanner.SpanStack; 19 | import com.sysdata.htmlspanner.TagNodeHandler; 20 | 21 | import org.htmlcleaner.TagNode; 22 | 23 | import android.text.SpannableStringBuilder; 24 | import android.text.style.SubscriptSpan; 25 | 26 | /** 27 | * Applies subscript style. 28 | * 29 | * @author Alex Kuiper 30 | * 31 | */ 32 | public class SubScriptHandler extends TagNodeHandler { 33 | 34 | public void handleTagNode(TagNode node, SpannableStringBuilder builder, 35 | int start, int end, SpanStack spanStack) { 36 | 37 | spanStack.pushSpan(new SubscriptSpan(), start, end); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /HtmlSpanner/src/main/java/com/sysdata/htmlspanner/handlers/SuperScriptHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Alex Kuiper 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.sysdata.htmlspanner.handlers; 17 | 18 | import com.sysdata.htmlspanner.SpanStack; 19 | import com.sysdata.htmlspanner.TagNodeHandler; 20 | 21 | import org.htmlcleaner.TagNode; 22 | 23 | import android.text.SpannableStringBuilder; 24 | import android.text.style.SuperscriptSpan; 25 | 26 | /** 27 | * Applies superscript. 28 | * 29 | * @author Alex Kuiper 30 | * 31 | */ 32 | public class SuperScriptHandler extends TagNodeHandler { 33 | 34 | public void handleTagNode(TagNode node, SpannableStringBuilder builder, 35 | int start, int end, SpanStack spanStack) { 36 | spanStack.pushSpan(new SuperscriptSpan(), start, end); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /HtmlSpanner/src/main/java/com/sysdata/htmlspanner/handlers/UnderlineHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Alex Kuiper 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.sysdata.htmlspanner.handlers; 17 | 18 | 19 | import android.text.SpannableStringBuilder; 20 | import android.text.style.UnderlineSpan; 21 | 22 | import com.sysdata.htmlspanner.SpanStack; 23 | import com.sysdata.htmlspanner.TagNodeHandler; 24 | 25 | import org.htmlcleaner.TagNode; 26 | 27 | /** 28 | * Creates clickable links. 29 | * 30 | * @author Alex Kuiper 31 | * 32 | */ 33 | public class UnderlineHandler extends TagNodeHandler { 34 | 35 | @Override 36 | public void handleTagNode(TagNode node, SpannableStringBuilder builder, 37 | int start, int end, SpanStack spanStack) { 38 | 39 | spanStack.pushSpan(new UnderlineSpan(), start, end); 40 | } 41 | } -------------------------------------------------------------------------------- /HtmlSpanner/src/main/java/com/sysdata/htmlspanner/handlers/attributes/BorderAttributeHandler.java: -------------------------------------------------------------------------------- 1 | package com.sysdata.htmlspanner.handlers.attributes; 2 | 3 | import android.text.SpannableStringBuilder; 4 | import android.util.Log; 5 | import com.sysdata.htmlspanner.SpanStack; 6 | 7 | import com.sysdata.htmlspanner.handlers.StyledTextHandler; 8 | import com.sysdata.htmlspanner.spans.BorderSpan; 9 | import com.sysdata.htmlspanner.style.Style; 10 | import org.htmlcleaner.TagNode; 11 | 12 | /** 13 | * Created with IntelliJ IDEA. 14 | * User: alex 15 | * Date: 6/23/13 16 | * Time: 3:36 PM 17 | * To change this template use File | Settings | File Templates. 18 | */ 19 | public class BorderAttributeHandler extends WrappingStyleHandler { 20 | 21 | public BorderAttributeHandler(StyledTextHandler handler) { 22 | super(handler); 23 | } 24 | 25 | @Override 26 | public void handleTagNode(TagNode node, SpannableStringBuilder builder, int start, int end, 27 | Style useStyle, SpanStack spanStack) { 28 | 29 | if ( node.getAttributeByName("border") != null ) { 30 | Log.d("BorderAttributeHandler", "Adding BorderSpan from " + start + " to " + end); 31 | spanStack.pushSpan(new BorderSpan(useStyle, start, end, getSpanner().isUseColoursFromStyle() ), start, end); 32 | } 33 | 34 | super.handleTagNode(node, builder, start, end, useStyle, spanStack); 35 | 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /HtmlSpanner/src/main/java/com/sysdata/htmlspanner/handlers/LinkHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Alex Kuiper 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.sysdata.htmlspanner.handlers; 17 | 18 | 19 | import com.sysdata.htmlspanner.SpanStack; 20 | import com.sysdata.htmlspanner.TagNodeHandler; 21 | 22 | import org.htmlcleaner.TagNode; 23 | 24 | import android.text.SpannableStringBuilder; 25 | import android.text.style.URLSpan; 26 | 27 | /** 28 | * Creates clickable links. 29 | * 30 | * @author Alex Kuiper 31 | * 32 | */ 33 | public class LinkHandler extends TagNodeHandler { 34 | 35 | @Override 36 | public void handleTagNode(TagNode node, SpannableStringBuilder builder, 37 | int start, int end, SpanStack spanStack) { 38 | 39 | final String href = node.getAttributeByName("href"); 40 | spanStack.pushSpan(new URLSpan(href), start, end); 41 | } 42 | } -------------------------------------------------------------------------------- /htmltextview/src/main/java/com/sysdata/kt/htmltextview/SDHtmlTextView.kt: -------------------------------------------------------------------------------- 1 | package com.sysdata.kt.htmltextview 2 | 3 | import android.content.Context 4 | import android.text.method.LinkMovementMethod 5 | import android.util.AttributeSet 6 | import android.widget.TextView 7 | import com.sysdata.htmlspanner.HtmlSpanner 8 | 9 | class SDHtmlTextView: TextView { 10 | 11 | constructor(context: Context?):this(context, null) 12 | 13 | constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs, 0) 14 | 15 | constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int): super(context, attrs, defStyleAttr){ 16 | if(attrs != null) { 17 | context?.let { ctx -> 18 | val a = ctx.theme.obtainStyledAttributes( 19 | attrs, 20 | R.styleable.SDHtmlTextView, 21 | defStyleAttr, 0) 22 | 23 | isTableHeaderCentered = a.getBoolean(R.styleable.SDHtmlTextView_tableHeaderCentered, true) 24 | 25 | a.recycle() 26 | } 27 | } 28 | this.movementMethod = LinkMovementMethod.getInstance() 29 | 30 | htmlSpanner = HtmlSpanner.Builder() 31 | .textColor(textColors.defaultColor) 32 | .textSize(textSize) 33 | .backgroundColor(solidColor) 34 | .tableHeaderCenter(isTableHeaderCentered) 35 | .build() 36 | } 37 | 38 | private var htmlSpanner: HtmlSpanner 39 | public var isTableHeaderCentered: Boolean = true 40 | 41 | var htmlText:String? = null 42 | set(value) { 43 | text = htmlSpanner.fromHtml(value) 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /HtmlSpanner/src/main/java/com/sysdata/htmlspanner/handlers/StyleNodeHandler.java: -------------------------------------------------------------------------------- 1 | package com.sysdata.htmlspanner.handlers; 2 | 3 | import android.text.SpannableStringBuilder; 4 | import android.util.Log; 5 | import com.osbcp.cssparser.CSSParser; 6 | import com.osbcp.cssparser.Rule; 7 | import com.sysdata.htmlspanner.SpanStack; 8 | import com.sysdata.htmlspanner.TagNodeHandler; 9 | import com.sysdata.htmlspanner.css.CSSCompiler; 10 | import org.htmlcleaner.ContentNode; 11 | import org.htmlcleaner.TagNode; 12 | 13 | /** 14 | * TagNodeHandler that reads