Uma biblioteca completa e performática para destacar trechos de textos usando Spannable com Expressões Regulares (Regex) para Android.

Overview

Highlight

Uma biblioteca completa e performática para destacar trechos de textos usando Spannable com Expressões Regulares (Regex) para Android totalmente em Java.

Processamento por linhas alteradas (opcional)

Quando ativado (por padrão é), a classe HighlightTextWatcher processa apenas as linhas alteradas e não todo o texto, melhorando consideravelmente a performance. Mas você pode desabilitar essa funcionalidade com setRange(HighlightTextWatcher.RANGE_PROCESS.MODIFIED);

Por que em Java?

Para maior compatibilidade... Mas você pode utilizar em Kotlin.

Como usar

A forma mais básica de utilizar a lib é com as implementações padrões, como HighlightTextWatcher e os Scheme (ColorScheme, StyleScheme etc.)

//crie uma instância de Hightlight
Highlight highlight = new Highlight();

//adicione seus Scheme, a lib possui alguns prontos
highlight.addScheme(
        new ColorScheme(
                "\\b(J|j)ava\\b",
                Color.parseColor("#FC0400")
        )
);

highlight.addScheme(
        new ColorScheme(
                "\\b(K|k)otlin\\b",
                Color.parseColor("#FC8500")
        )
);

//crie uma HighlightTextWatcher passando a instância de Highlight pelo construtor
HighlightTextWatcher textWatcher = new HighlightTextWatcher(highlight);

//adicione o HighlightTextWatcher ao EditText
binding.edittext.addTextChangedListener(textWatcher);

Mais você pode fazer suas próprias implementações, por exemplo estendendo a classe LinesTextWatcher que fornece o processamento por linhas alteradas ou criar seus próprios Scheme, apenas estendendo a interface Scheme e implementando os métodos.

//custom scheme example
highlight.addScheme(
        new Scheme() {
            final Pattern pattern =
                    Pattern.compile("\\b([Jj])ava([Ss])cript\\b");

            @Override
            public Pattern getRegex() {
                return pattern;
            }

            @Override
            public Object getSpan() {
                return new StrikethroughSpan();
            }
        }
);

//para que a classe Hightlight saiba remover esse span
highlight.addSpanType(StrikethroughSpan.class);

A classe Highlight possui as implementaçõs de adicionar e remover spans em todo Editable ou apenas em trechos específicos, você pode usá-la idividualmente também.

highlight.removeSpan(editable, start, end);
highlight.setSpan(editable, start, end);

highlight.removeSpan(editable);
highlight.setSpan(editable);

Adicionar a seu projeto

Adicione o jitpack a seu projeto em settings.gradle

maven { url 'https://jitpack.io' }

Adicione a dependencia ao gradle do módulo (geralmente o módulo app)

implementation 'com.github.Irineu333:Highlight:version'
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 Bubble View

BubbleTextView Custom arrow position Custom fillet radius Custom background color Can be placed anywhere Two default style Two default theme Snapshot

A Material Android password view that toggles password visibility via an eye icon.
A Material Android password view that toggles password visibility via an eye icon.

8/17/2016: As of about an hour ago, this library is deprecated! Support for password visibility is now included in the Design Support Library in TextI

RoundedLetterView like the one in Android 5.0 Contacts app
RoundedLetterView like the one in Android 5.0 Contacts app

RoundedLetterView RoundedLetterView like the one in Android 5.0 Contacts app Attributes to choose from: rlv_titleText - The text in the first row. rlv

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

Circular timer on Android platform.

CircleTimerView [No Longer Support] Circle timer on Android platform. System Requirement Android v2.2+ TODO Developed by AndroidStudio Usage com.gith

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

library to implement and render emojis For Android
library to implement and render emojis For Android

Release Notes SuperNova-Emoji SuperNova-Emoji is a library to implement and render emojis. Minimum SDK Level: 9 (2.3) Contact Java Usage To use defaul

Float Label Edit Texts for Android

Floating Label Edit Text for Android For more info, see this blog post. Salient features Simple and clean library (open up the source to see for yours

Comments
  • [FEAT] FontScheme created

    [FEAT] FontScheme created

    • Added font processing Scheme #6
    //how to use
    highlight.addScheme(
            new ColorScheme(
                    Pattern.compile("Project"),
                    Color.BLACK
            ).addScopeScheme(
                    new FontScheme(
                            FontScheme.getFont(this, R.font.pacifico_regular)
                    )
            )
    );
    
    enhancement 
    opened by Irineu333 0
  • Release/v1.0.3

    Release/v1.0.3

    feat : add scheme scope

    Each scheme has a scope, which is the region it highlights, and other schemes can be added to its scope and only process within that scope.

    enhancement 
    opened by Irineu333 0
Releases(1.0.4)
Owner
Irineu A. Silva
Desenvolvedor Android e exímio consumidor de café.
Irineu A. Silva
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

kpbird 381 Nov 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
Android's TextView that can expand/collapse like the Google Play's app description

ExpandableTextView ExpandableTextView is an Android library that allows developers to easily create an TextView which can expand/collapse just like th

Manabu S. 4k Dec 28, 2022
A library to show emoji in TextView, EditText (like WhatsApp) for Android

Discontinued This projected is discontinued. Please consider using other alternative, i.e EmojiCompat. Contact me if you want to continue working on a

Hieu Rocker 3.6k Jan 5, 2023
Android experiment showing a sinking TextView

Titanic is an Android experiment reproducing this effect.

Romain Piel 1.8k Dec 15, 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
Gmail style MultiAutoCompleteTextView for Android

Version 3.0 The 3.0.1 version is now available! This should resolve a number of text handling issues and lay the groundwork for better support of mixe

Splitwise 1.3k Nov 14, 2022
Advanced Android TextView

Advanced Android TextView Companion app for my Advanced Android TextView talk, demostrating: Animated CompoundDrawable Text shadow Custom font Non-bre

Chiu-Ki Chan 1.2k Dec 9, 2022