Dealing with Android Text by simple way to get high performance.

Overview

Gapo Android RichText

RichText supports Hashtag, Mention, Url, Phone Number, Email, Markdown, Custom Span, SeeMore/SeeLess by limited line or length, and ability to handle clicks and long clicks on spanned content. Ability prepare data on background thread before it was drawn on main thread.

Installation

Gradle

implementation 'vn.gapowork.android:rich-text:1.0.0-alpha04'

Usage

Example:

private val richTextHelper = RichTextHelper(binding.textView)
richTextHelper.setRichTextLinkMovementMethod()
richTextHelper.removeHighLight()
richTextHelper.setOnClickNotSpanListener { }

val color = Color.parseColor("#30A960")

val richText = RichText.Builder()
    .setText(text)
    .addSpanner(
       RichTextMetadataSpanner.Params()
           .setForegroundColor(color)
           .setUnderline(true)
           .setMetadataParser(RichTextHashtagMetadataParser())
           .setOnClickListener(
               object : RichTextOnClickSpanListener {
                   override fun onClickSpan(view: View, metadata: RichTextMetadata) {
                       Log.e("TAG", "onClickSpan: = $metadata")
                   }

                   override fun onLongClickSpan(
                       view: View,
                       metadata: RichTextMetadata
                   ) {
                       Log.e("TAG", "onLongClickSpan: = $metadata")
                   }
               }
           )
           .create()
    )
    .build()

binding.textView.text = richText.spannable

RecyclerView

richTextHelper.setSpannableFactory()

Supported Cases

  • Hashtag: #hashtag
.addSpanner(
    RichTextMetadataSpanner.Params()
        .setMetadataParser(RichTextHashtagMetadataParser())
        .create()
)
  • Mention: @mention
val mentionMetadata = listOf(
    RichTextMetadata("kienht", 0, 14),
    RichTextMetadata("vietth", 15, 30),
)
.addSpanner(
    RichTextMetadataSpanner.Params()
        .setMetadata(mentionMetadata) // or
        .setMetadataParser(RichTextMentionMetadataParser())
        .create()
)
  • URL:
.addSpanner(
    RichTextMetadataSpanner.Params()
        .setMetadataParser(RichTextUrlMetadataParser())
        .create()
)
  • Phone Number:
.addSpanner(
    RichTextMetadataSpanner.Params()
        .setMetadataParser(RichTextPhoneNumberMetadataParser())
        .create()
)
  • Email:
.addSpanner(
    RichTextMetadataSpanner.Params()
        .setMetadataParser(RichTextEmailMetadataParser())
        .create()
)
  • Markdown:
implementation "io.noties.markwon:core:latest_version"
private val markwon by lazy(LazyThreadSafetyMode.NONE) {
    Markwon.builder(context)
        .usePlugin(object : AbstractMarkwonPlugin() {
            override fun configureTheme(builder: MarkwonTheme.Builder) {
                builder
                    .bulletWidth(8)
                    .headingBreakHeight(0)
                    .headingTextSizeMultipliers(floatArrayOf(1.43f, 1.21f, 1f, 1f, 1f, 1f))

                builder.headingTypeface(Typeface.DEFAULT_BOLD)
            }
        })
        .usePlugin(SoftBreakAddsNewLinePlugin.create())
        .usePlugin(StrikethroughPlugin.create())
        .usePlugin(TablePlugin.create(this))
        .usePlugin(TaskListPlugin.create(this))
        .build()
}
.addSpanner(RichTextMarkdownSpanner(markwon))
val seeMore = "...\nXem thêm"

val richText = RichText.Builder()
    .setOriginal(text)
    .addSpanner(...)
    .setSeeMoreType(
        RichTextSeeMoreType.Line(
            seeMore = RichTextMetadataSpanner.Params()
                .setForegroundColor(color)
                .setMetadata(listOf(RichTextMetadata(seeMore, 4, seeMore.length)))
                .create()
                .span(seeMore),
            line = 24,
            measurementParams = RichTextMeasurement.Params.Builder().from(binding.text).build()
        )
    )
binding.text.text = if (richText.seeMoreSpannable != null) {
    richText.seeMoreSpannable
} else {
    richText.spannable
}

SeeMore/SeeLess is limited by line count, TextView's layout_width must be match_parent.

">
<androidx.appcompat.widget.AppCompatTextView 
    android:id="@+id/text"
    android:layout_width="match_parent".../>

License

Copyright (c) 2021, Gapo Technology JSC
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of Gapo Technology JSC nor the names of its contributors
      may be used to endorse or promote products derived from this software
      without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL GAPO TECHNOLOGY JSC BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
You might also like...
[DISCONTINUED] Rrich text editor for android platform. 安卓富文本编辑器,暂停维护

icarus-android Maybe the best rich text editor on android platform. Base on Simditor Features Alignment (left/center/right) Bold Blockquote Code Horiz

Android library contain custom realisation of EditText component for masking and formatting input text
Android library contain custom realisation of EditText component for masking and formatting input text

Masked-Edittext Masked-Edittext android library EditText widget wrapper add masking and formatting input text functionality. Install Maven dependency

An address-autocompleting text field for Android
An address-autocompleting text field for Android

android-PlacesAutocompleteTextView An AutocompleteTextView that interacts with the Google Maps Places API to provide location results and caches selec

Chips EditText, Token EditText, Bubble EditText, Spannable EditText and etc.. There are many names of this control. Here I develop easy to understand , modify and integrate Chips Edit Text widget for Android
Chips EditText, Token EditText, Bubble EditText, Spannable EditText and etc.. There are many names of this control. Here I develop easy to understand , modify and integrate Chips Edit Text widget for Android

Chips EditText Library Chips EditText, Token EditText, Bubble EditText, Spannable EditText and etc.. There are many names of this control. Here I deve

AutosizeEditText for Android is an extension of native EditText that offer a smooth auto scale text size.
AutosizeEditText for Android is an extension of native EditText that offer a smooth auto scale text size.

AutoscaleEditText AutosizeEditText for Android is an extension of native EditText that offer a smooth auto scale text size. Latest Version How to use

Add text masking functionality to Android EditText. It will prevent user from inserting not allowed signs, and format input as well.
Add text masking functionality to Android EditText. It will prevent user from inserting not allowed signs, and format input as well.

MaskFormatter MaskFormatter adds mask functionality to your EditText. It will prevent user from inserting not allowed signs, and format input as well.

Markdown Text for Android Jetpack Compose 📋.

Markdown Text for Android Jetpack Compose 📋.

Android Custom View for prevent the view behind on-screen keyboard when edit text is focused
Android Custom View for prevent the view behind on-screen keyboard when edit text is focused

Group Focusable Prevent the view behind on-screen keyboard when edit text is focused in Android UI Download Gradle implementation 'com.akexorcist:grou

Light-weighted, convenient implementation of expandable text view that supports expanding & collapsing animations for Android projects

ExpandableTextView Light-weighted, convenient implementation of expandable text view that supports expanding & collapsing animations for Android proje

Releases(1.0.0-alpha04)
Simple way to create linked text, such as @username or #hashtag, in Android TextView and EditText

Simple Linkable Text Simple way to create link text, such as @username or #hashtag, in Android TextView and EditText Installation Gradle Add dependenc

Aditya Pradana Sugiarto 76 Nov 29, 2022
A editable text with a constant text/placeholder for Android.

ParkedTextView A EditText with a constant text in the end. How to use <com.goka.parkedtextview.ParkedTextView xmlns:app="http://schemas.android.co

goka 270 Nov 11, 2022
RTL marquee text view android right to left moving text - persian - farsi - arabic - urdo

RTL marquee text view android right to left moving text - persian - farsi - arabic - urdo

mehran elyasi 4 Feb 14, 2022
A simple Android library to protect part of text using Span

Text Protector A simple Android library to "protect" part of text using Span What is this? This is a small library for replacing part of a text in a T

Oleg Nestyuk 4 May 16, 2022
A simple library for hide and show text with animation.

ViewMore TextView ViewMore TextView allows you to use a TextView by hiding the content of the text by a number of established lines and to display all

Michele Quintavalle 81 Dec 23, 2022
Micro Template 📃 A very tiny and simple text templating library for Kotlin.

Micro Template ?? A very tiny and simple text templating library for Kotlin. It has very limited features, so it's intended to be used for short templ

Matteo Mirk 24 Aug 20, 2022
RichEditor for Android is a beautiful Rich Text WYSIWYG Editor for Android.

RichEditor for Android is a beautiful Rich Text WYSIWYG Editor for Android. Looking for iOS? Check out cjwirth/RichEditorView Supported Functions Bold

Daichi Furiya 6k Jan 2, 2023
MarkdownView is an Android webview with the capablity of loading Markdown text or file and display it as HTML, it uses MarkdownJ and extends Android webview.

MarkdownView is an Android webview with the capablity of loading Markdown text or file and display it as HTML, it uses MarkdownJ and extends Android webview.

Feras Alnatsheh 1k Dec 20, 2022
:page_facing_up: Android Text Full Jusiftication / Wrapping / Justify / Hyphenate - V2.0

LIBRARY IS NO LONGER MAINTAINED If you want to adopt + maintain this library, please drop me a message - [email protected] Android Full Justific

Mathew Kurian 1.9k Dec 29, 2022
Android form edit text is an extension of EditText that brings data validation facilities to the edittext.

Android Form EditText Android form edit text is an extension of EditText that brings data validation facilities to the edittext. Example App I built a

Andrea 1.5k Dec 14, 2022