A tool that facilitates working with Spans on TextViews or any extension of them (EditTexts, Buttons...).

Overview

AwesomeText

Android Arsenal

Hex.pm Platform

Download

Working with Spans is ugly and difficult to manage, it's like working with a goblin of Moria. Don't understand the Spans? With AwesomeText you will only have to work with the classic Adapter Pattern. All the ease and potential of a pattern you already know how to use.

Screenshots

Demo Screenshot

Download

Download via Gradle:

    dependencies {
        compile 'com.jmpergar:AwesomeText:1.0.0'
    }

Or via Maven:

    <dependency>
        <groupId>com.jmpergar</groupId>
        <artifactId>AwesomeText</artifactId>
        <version>1.0.0</version>
        <type>aar</type>
    </dependency>

Usage

On the same way that you working with ListAdapter, you must implement an interface to delegate the creation of the view, in this case AwesomeTextHandler.ViewSpanRenderer interface. The method getView is the responsible of this.

    public class HashtagsSpanRenderer implements AwesomeTextHandler.ViewSpanRenderer {

        @Override
        public View getView(String text, Context context) {
            LayoutInflater inflater = LayoutInflater.from(context);
            TextView hashtagView = inflater.inflate(R.layout.hashtag);
            hashtagView.setText(text);
            return hashtagView;
        }
    }

If you want to manage click events only must to implement AwesomeTextHandler.ViewSpanClickListener.

    public class MentionSpanRenderer implements AwesomeTextHandler.ViewSpanRenderer, AwesomeTextHandler.ViewSpanClickListener {

        @Override
        public View getView(String text, Context context) {
            LayoutInflater inflater = LayoutInflater.from(context);
            TextView mentionView = inflater.inflate(R.layout.mention);
            mentionView.setText(text);
            return mentionView;
        }

        @Override
        public void onClick(String text, Context context) {
            Toast.makeText(context, "Hello " + text, Toast.LENGTH_SHORT).show();
        }
    }

And finally you configure AwesomeTextHandler to view the changes. Now, when you call AwesomeTextHandler.setText the change will be rendered automatically.

    public class MainActivity extends ActionBarActivity {
    
        private static final String HASHTAG_PATTERN = "(#[\\p{L}0-9-_]+)";
        private static final String MENTION_PATTERN = "(@[\\p{L}0-9-_]+)";

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            TextView textView = (TextView) findViewById(R.id.textview);
            EditText editText = (EditText) findViewById(R.id.editText);

            AwesomeTextHandler awesomeTextViewHandler = new AwesomeTextHandler();
            awesomeTextViewHandler
                .addViewSpanRenderer(HASHTAG_PATTERN, new HashtagsSpanRenderer())
                .addViewSpanRenderer(MENTION_PATTERN, new MentionSpanRenderer())
                .setView(textView);

            AwesomeTextHandler awesomeEditTextHandler = new AwesomeTextHandler();
            awesomeEditTextHandler
                .addViewSpanRenderer(HASHTAG_PATTERN, new HashtagsSpanRenderer())
                .addViewSpanRenderer(MENTION_PATTERN, new MentionSpanRenderer())
                .setView(editText);
        }
    }

Developed By

Follow me on Twitter Add me to Linkedin

Who's using it

Does your app use AwesomeText? If you want to be featured on this list drop me a line.

Contributors

License

Copyright 2015 José Manuel Pereira García

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.
You might also like...
A Mobile application (Android), which facilitates the search for a medication, a pharmacy using geolocation.

#Pharmacom Pharmacom, est une application mobile natif - compatible avec mobile et tablette. Cette application a comme but principale de servir les ci

💰 A library to dynamically format your EditTexts to take currency inputs
💰 A library to dynamically format your EditTexts to take currency inputs

CurrencyEditText A library to dynamically format your EditTexts to take currency inputs. Gradle Dependency Add the dependency to your app's build.grad

BlackDex is an Android unpack tool, it supports Android 5.0~12 and need not rely to any environment. BlackDex can run on any Android mobile phones or emulators, you can unpack APK File in several seconds.
BlackDex is an Android unpack tool, it supports Android 5.0~12 and need not rely to any environment. BlackDex can run on any Android mobile phones or emulators, you can unpack APK File in several seconds.

BlackDex is an Android unpack tool, it supports Android 5.0~12 and need not rely to any environment. BlackDex can run on any Android mobile phones or emulators, you can unpack APK File in several seconds.

Extension functions over Android's callback-based APIs which allows writing them in a sequential way within coroutines or observe multiple callbacks through kotlin flow.

callback-ktx A lightweight Android library that wraps Android's callback-based APIs into suspending extension functions which allow writing them in a

A simpler way to style your TextViews
A simpler way to style your TextViews

BabushkaText BabushkaText is a custom TextView which lets you customize the styling of parts of your text via Spannables, but without the hassle of ha

A simpler way to style your TextViews
A simpler way to style your TextViews

BabushkaText BabushkaText is a custom TextView which lets you customize the styling of parts of your text via Spannables, but without the hassle of ha

A simpler way to style your TextViews
A simpler way to style your TextViews

BabushkaText BabushkaText is a custom TextView which lets you customize the styling of parts of your text via Spannables, but without the hassle of ha

🪄 This is an animation library with an increasing number of TextViews
🪄 This is an animation library with an increasing number of TextViews

CountNumberEvent 🪄 This is an animation library with an increasing number of TextViews Demo Setup Add it in your root build.gradle at the end of repo

FadeOutParticle is an animation for disappearing views like TextViews
FadeOutParticle is an animation for disappearing views like TextViews

FadeOutParticle is an animation for disappearing views like TextViews

Support extension to use Android ViewBinding quickly and smooth transform from kotlin-synthetic-extension.

ViewBinding Delegate Extension Support extension to use Android ViewBinding quickly and smooth transform from kotlin-synthetic-extension. Binding inst

A simple Android utils library to write any type of data into cache files and read them later.

CacheUtilsLibrary This is a simple Android utils library to write any type of data into cache files and then read them later, using Gson to serialize

Note app that allows user to save/edit/delete/search any type of notes and view them in a list

NoteApp Note app that allows user to save/edit/delete/search any type of notes a

Kotlin extension function provides a facility to "add" methods to class without inheriting a class or using any type of design pattern

What is Kotlin Extension Function ? Kotlin extension function provides a facility to "add" methods to class without inheriting a class or using any ty

DevTools for Android Chrome — works on any website, on any Chromium browser.
DevTools for Android Chrome — works on any website, on any Chromium browser.

DevTools for Android Chrome — works on any website, on any Chromium browser.

Com.hhvvg.anytext - An application provides features to modify any TextView in any other applications

AnyText What's this This application provides features to modify any TextView in

Automatically generates UI demos which allow users to call any function with any parameters
Automatically generates UI demos which allow users to call any function with any parameters

Automatically generates UI demos which allow users to call any function (including composable ones) with any parameters. Useful for building demo screens in playground apps of various design systems.

Android Buttons With Built-in Progress Meters.
Android Buttons With Built-in Progress Meters.

Description Android Buttons With Built-in Progress Meters. Wiki Home Screenshots User Guide Integration The lib is available on Maven Central, you can

A nicer-looking, more intuitive and highly customizable alternative for radio buttons and dropdowns for Android.
A nicer-looking, more intuitive and highly customizable alternative for radio buttons and dropdowns for Android.

SwipeSelector Undergoing for some API changes for a 2.0 major version, see example usage in the sample module! What and why? Bored of dull looking rad

Comments
  • If my TextView's context has the text-face like @_0...

    If my TextView's context has the text-face like @_0...

    The MENTION_PATTERN will put the text-face renderer to a clickable-span, The lib can provide another method that user can define the sapn text without using the addViewSpanRenderer(pattern,xx)?

    opened by eling13 1
  • Changing the Text of a Span

    Changing the Text of a Span

    Any idea how I could replace the text of a span on user interaction?

    Example scenario based on the sample app:

    User clicks on ChuckNorris and I use the onClick to pop up a list of names, and the user selects a name. I want to replace "ChuckNorris" with the newly selected name.

    opened by janakagamini 0
  • Text is not consistently scaled properly across different devices

    Text is not consistently scaled properly across different devices

    Running the sample app on a Samsung S3 and a Motorola X (2nd gen) the text spans are not scaled the same. I am using AwesomeText in an app I am working on, so if you could point me in the right direction I could see about finding a fix.

    Samsung screenshot_samsungs3

    Moto X screenshot_motox2

    opened by sjay13 0
  • ImageSpan alignment (i.e., BASELINE over BOTTOM)

    ImageSpan alignment (i.e., BASELINE over BOTTOM)

    I made a tiny fork of this library because my span was not properly aligned. A default ImageSpan uses DynamicDrawableSpan.ALIGN_BOTTOM with no configuration to have the AwesomeTextHandler to use ALIGN_BASELINE.

    It's a rather tiny change, but I'd like to know if there's interest to add that to this library before I make a PR.

    opened by tomrenn 1
Owner
José Manuel Pereira García
Head of Mobile in @99markets. Formerly in @seedtag, @jobandtalent and @redbooth. Photography lover, boardgamer and Andalú.
José Manuel Pereira García
A simpler way to style your TextViews

BabushkaText BabushkaText is a custom TextView which lets you customize the styling of parts of your text via Spannables, but without the hassle of ha

Henrique Boregio 752 Dec 29, 2022
A simpler way to style your TextViews

BabushkaText BabushkaText is a custom TextView which lets you customize the styling of parts of your text via Spannables, but without the hassle of ha

Henrique Boregio 753 Jun 7, 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
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

Txus Ballesteros 354 Nov 28, 2022
An extension of Android's TextView, EditText and Button that let's you use the font of your choice

AnyTextView (deprecated) Note: AnyTextView is no longer being maintained. I recommend replacing AnyTextView with the Calligraphy library instead. Frus

Hans Petter Eide 165 Nov 11, 2022
Simple extension for account suggestion and auto completion.

AccountAutoCompleteEditText Just a simple implementation for use of auto complete text view with device account suggestion Usage Just simply put an cu

Keishin Yokomaku 100 Feb 22, 2022
****. Use the native and support library variants instead - https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml.html. An android library that makes it easy to add custom fonts to edittexts and textviews

Add to your project Add this line to your dependencies in build.gradle compile 'in.workarounds.typography:typography:0.0.8' Using the views There are

Workarounds 43 Nov 6, 2021
Custom font library for android | Library to change/add font of Entire Android Application at once without wasting your time - TextViews, EditText, Buttons, Views etc.,

AppFontChanger In a Single shot change font of Entire Android Application - TextViews, EditText, Buttons, Views etc., Kindly use the following links t

Prabhakar Thota 48 Aug 10, 2022
Compose-buttons - A set of Loading animations used in Buttons to convey a "loading" state after the button is clicked.

Loading Buttons A set of Loading animations used in Buttons to convey a "loading" state after the button is clicked. A simple demo application that sh

Brad Ball 16 Jul 5, 2022
Kirill Rakhman 4 Sep 15, 2022