├── .gitignore ├── .idea ├── .name ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── compiler.xml ├── dictionaries │ └── saka.xml ├── gradle.xml ├── jarRepositories.xml ├── kotlinc.xml ├── misc.xml └── vcs.xml ├── LICENSE.txt ├── README.md ├── _config.yml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── sakacyber │ │ └── android │ │ └── sample │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── sakacyber │ │ │ └── android │ │ │ └── sample │ │ │ ├── Content.kt │ │ │ └── MainActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.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 │ │ ├── raw │ │ └── content.json │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── sakacyber │ └── android │ └── sample │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── html-textview ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── saka │ │ └── android │ │ └── htmltextview │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── saka │ │ │ └── android │ │ │ └── htmltextview │ │ │ ├── HtmlTextView.kt │ │ │ ├── activity │ │ │ ├── ImageActivity.kt │ │ │ ├── OverlayView.kt │ │ │ └── VideoActivity.kt │ │ │ ├── callback │ │ │ └── ClickEventCallback.kt │ │ │ ├── element │ │ │ ├── BaseElement.kt │ │ │ ├── BlockQuoteView.kt │ │ │ ├── DivView.kt │ │ │ ├── HeaderView.kt │ │ │ ├── IFrameView.kt │ │ │ ├── ImageView.kt │ │ │ ├── ParagraphView.kt │ │ │ ├── RoundImageView.kt │ │ │ ├── WebView.kt │ │ │ └── WebViewCompat.kt │ │ │ └── utility │ │ │ ├── Conf.kt │ │ │ ├── EManager.kt │ │ │ ├── Extension.kt │ │ │ ├── MyActivity.kt │ │ │ ├── ThumbnailLoader.kt │ │ │ └── VideoLoader.kt │ └── res │ │ ├── drawable │ │ ├── bg_placeholder.xml │ │ ├── bg_ripple_effect.xml │ │ ├── ic_close_24.xml │ │ ├── ic_more_vert_24.xml │ │ ├── ic_play_circle_24.xml │ │ └── img_holder.png │ │ ├── font │ │ └── font_battambang_regular.ttf │ │ ├── layout │ │ ├── activity_video.xml │ │ ├── main.xml │ │ ├── video_progress.xml │ │ ├── view_overlay.xml │ │ └── view_video_controller.xml │ │ ├── menu │ │ └── save_menu.xml │ │ └── values │ │ ├── attr.xml │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── values.xml │ └── test │ └── java │ └── com │ └── saka │ └── android │ └── htmltextview │ └── ExampleUnitTest.kt ├── jitpack.yml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | HtmlTextView -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | xmlns:android 17 | 18 | ^$ 19 | 20 | 21 | 22 |
23 |
24 | 25 | 26 | 27 | xmlns:.* 28 | 29 | ^$ 30 | 31 | 32 | BY_NAME 33 | 34 |
35 |
36 | 37 | 38 | 39 | .*:id 40 | 41 | http://schemas.android.com/apk/res/android 42 | 43 | 44 | 45 |
46 |
47 | 48 | 49 | 50 | .*:name 51 | 52 | http://schemas.android.com/apk/res/android 53 | 54 | 55 | 56 |
57 |
58 | 59 | 60 | 61 | name 62 | 63 | ^$ 64 | 65 | 66 | 67 |
68 |
69 | 70 | 71 | 72 | style 73 | 74 | ^$ 75 | 76 | 77 | 78 |
79 |
80 | 81 | 82 | 83 | .* 84 | 85 | ^$ 86 | 87 | 88 | BY_NAME 89 | 90 |
91 |
92 | 93 | 94 | 95 | .* 96 | 97 | http://schemas.android.com/apk/res/android 98 | 99 | 100 | ANDROID_ATTRIBUTE_ORDER 101 | 102 |
103 |
104 | 105 | 106 | 107 | .* 108 | 109 | .* 110 | 111 | 112 | BY_NAME 113 | 114 |
115 |
116 |
117 |
118 | 119 | 121 |
122 |
-------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/dictionaries/saka.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | blockquote 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | 34 | 35 | -------------------------------------------------------------------------------- /.idea/kotlinc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 22 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Saka 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![](https://jitpack.io/v/sakacyber/html-textview.svg)](https://jitpack.io/#sakacyber/html-textview) 2 | 3 | # HtmlTextView 4 | 5 | **HtmlTextView** Android project is an open-source library that enables developers to display formatted HTML content in a TextView widget within an Android application. 6 | 7 | With this library, developers can easily display HTML content, including text, images, links, and other media, using a TextView widget without the need for any additional customization or coding. This is particularly useful when developers want to display formatted content that has been obtained from a web API or other online source, or when they want to create rich-text documents within their application. 8 | 9 | Support tag base on build in [Html.fromHtml (String source, 10 | int flags)](https://developer.android.com/reference/android/text/Html#fromHtml(java.lang.String,%20int)) in android 11 | 12 | ## Quick Start 13 | 14 | **HtmlTextView** is available on jitpack. 15 | 16 | Add dependency: 17 | 18 | ```groovy 19 | implementation "com.github.sakacyber:html-textview:1.0.15" 20 | ``` 21 | 22 | ## Usage 23 | 24 | to use **HtmlTextView**: 25 | 26 | ```xml 27 | 32 | ``` 33 | 34 | In Activity or Fragment 35 | 36 | ```kotlin 37 | // activity or fragment 38 | htmlTextView.setText(html, lifecycleScope) 39 | ``` 40 | 41 | update text size 42 | 43 | ```kotlin 44 | // size in dp 45 | htmlTextView.updateTextSize(18f) 46 | ``` -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | apply plugin: "kotlin-android" 3 | 4 | def versionNameStr = "1.0.15" 5 | 6 | android { 7 | 8 | compileSdkVersion 33 9 | 10 | defaultConfig { 11 | applicationId "com.sakacyber.android.sample" 12 | minSdkVersion 23 13 | targetSdkVersion 33 14 | versionCode 14 15 | versionName versionNameStr 16 | 17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 18 | } 19 | 20 | compileOptions { 21 | sourceCompatibility JavaVersion.VERSION_17 22 | targetCompatibility JavaVersion.VERSION_17 23 | } 24 | 25 | kotlinOptions { 26 | jvmTarget = "17" 27 | } 28 | 29 | buildTypes { 30 | release { 31 | minifyEnabled false 32 | proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" 33 | } 34 | } 35 | 36 | buildFeatures { 37 | buildConfig = true 38 | } 39 | 40 | namespace "com.sakacyber.android.sample" 41 | } 42 | 43 | dependencies { 44 | 45 | implementation "androidx.appcompat:appcompat:$appCompatVersion" 46 | implementation "androidx.core:core-ktx:$coreVersion" 47 | implementation "androidx.constraintlayout:constraintlayout:$constrainLayoutVersion" 48 | implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion" 49 | 50 | implementation 'com.google.code.gson:gson:2.10.1' 51 | implementation project(":html-textview") 52 | 53 | testImplementation "junit:junit:$junitVersion" 54 | androidTestImplementation "androidx.test:runner:$testRuner" 55 | androidTestImplementation "androidx.test.espresso:espresso-core:$testEspressoVersion" 56 | } 57 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/sakacyber/android/sample/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.sakacyber.android.sample 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.runner.AndroidJUnit4 5 | import org.junit.Assert.assertEquals 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | /** 10 | * Instrumented test, which will execute on an Android device. 11 | * 12 | * See [testing documentation](http://d.android.com/tools/testing). 13 | */ 14 | @RunWith(AndroidJUnit4::class) 15 | class ExampleInstrumentedTest { 16 | @Test 17 | fun useAppContext() { 18 | // Context of the app under test. 19 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 20 | assertEquals("com.saka.android.htmltextview", appContext.packageName) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 14 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/sakacyber/android/sample/Content.kt: -------------------------------------------------------------------------------- 1 | package com.sakacyber.android.sample 2 | 3 | import android.content.Context 4 | import com.google.gson.Gson 5 | import java.io.BufferedReader 6 | import java.io.IOException 7 | import java.io.InputStream 8 | import java.io.InputStreamReader 9 | 10 | class Content { 11 | 12 | val content: String = "" 13 | 14 | companion object { 15 | 16 | @JvmStatic 17 | fun deserialize(context: Context): Content? { 18 | try { 19 | val jsonString = parseResource(context, R.raw.content) 20 | return Gson().fromJson(jsonString, Content::class.java) 21 | } catch (e: IOException) { 22 | e.printStackTrace() 23 | } 24 | return null 25 | } 26 | 27 | @Throws(IOException::class) 28 | fun parseResource(context: Context, resource: Int): String { 29 | val inputStream: InputStream = context.resources.openRawResource(resource) 30 | val sb = StringBuilder() 31 | val br = BufferedReader(InputStreamReader(inputStream)) 32 | var read = br.readLine() 33 | while (read != null) { 34 | sb.append(read) 35 | read = br.readLine() 36 | } 37 | return sb.toString() 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/sakacyber/android/sample/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.sakacyber.android.sample 2 | 3 | import android.os.Bundle 4 | import android.widget.Button 5 | import androidx.appcompat.app.AppCompatActivity 6 | import androidx.lifecycle.lifecycleScope 7 | import com.saka.android.htmltextview.HtmlTextView 8 | 9 | class MainActivity : AppCompatActivity() { 10 | 11 | private var fontLarge = false 12 | 13 | override fun onCreate(savedInstanceState: Bundle?) { 14 | super.onCreate(savedInstanceState) 15 | setContentView(R.layout.activity_main) 16 | 17 | val content = Content.deserialize(this) 18 | val htmlTextView = findViewById(R.id.htmlTextView) 19 | htmlTextView.setText(content?.content, lifecycleScope) 20 | 21 | val button = findViewById