This light-weight library provides images with letter/text like the Gmail app. It extends the Drawable class thus can be used with existing/custom/network ImageView classes. Also included is a fluent interface for creating drawables and a customizable ColorGenerator.

Overview

###TextDrawable This light-weight library provides images with letter/text like the Gmail app. It extends the Drawable class thus can be used with existing/custom/network ImageView classes. Also included is a fluent interface for creating drawables and a customizable ColorGenerator.

###How to use

Import with Gradle:

repositories{
    maven {
        url 'http://dl.bintray.com/amulyakhare/maven'
    }
}

dependencies {
    compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
}

####1. Create simple tile:

<ImageView android:layout_width="60dp"
	       android:layout_height="60dp"
	       android:id="@+id/image_view"/>

Note: Specify width/height for the ImageView and the drawable will auto-scale to fit the size.

TextDrawable drawable = TextDrawable.builder()
                .buildRect("A", Color.RED);

ImageView image = (ImageView) findViewById(R.id.image_view);
image.setImageDrawable(drawable);

####2. Create rounded corner or circular tiles:

TextDrawable drawable1 = TextDrawable.builder()
                .buildRoundRect("A", Color.RED, 10); // radius in px

TextDrawable drawable2 = TextDrawable.builder()
                .buildRound("A", Color.RED);

####3. Add border:

TextDrawable drawable = TextDrawable.builder()
                .beginConfig()
                    .withBorder(4) /* thickness in px */
                .endConfig()
                .buildRoundRect("A", Color.RED, 10);

####4. Modify font style:

TextDrawable drawable = TextDrawable.builder()
                .beginConfig()
	                .textColor(Color.BLACK)
                    .useFont(Typeface.DEFAULT)
                    .fontSize(30) /* size in px */
                    .bold()
                    .toUpperCase()
                .endConfig()
                .buildRect("a", Color.RED)

####5. Built-in color generator:

ColorGenerator generator = ColorGenerator.MATERIAL; // or use DEFAULT
// generate random color
int color1 = generator.getRandomColor();
// generate color based on a key (same key returns the same color), useful for list/grid views
int color2 = generator.getColor("[email protected]")

// declare the builder object once.
TextDrawable.IBuilder builder = TextDrawable.builder()
				.beginConfig()
					.withBorder(4)
				.endConfig()
				.rect();

// reuse the builder specs to create multiple drawables
TextDrawable ic1 = builder.build("A", color1);
TextDrawable ic2 = builder.build("B", color2);

####6. Specify the width / height:

<ImageView android:layout_width="wrap_content"
	       android:layout_height="wrap_content"
	       android:id="@+id/image_view"/>

Note: The ImageView could use wrap_content width/height. You could set the width/height of the drawable using code.

TextDrawable drawable = TextDrawable.builder()
				.beginConfig()
					.width(60)  // width in px
					.height(60) // height in px
				.endConfig()
                .buildRect("A", Color.RED);

ImageView image = (ImageView) findViewById(R.id.image_view);
image.setImageDrawable(drawable);

####7. Other features:

  1. Mix-match with other drawables. Use it in conjunction with LayerDrawable, InsetDrawable, AnimationDrawable, TransitionDrawable etc.

  2. Compatible with other views (not just ImageView). Use it as background drawable, compound drawable for TextView, Button etc.

  3. Use multiple letters or unicode characters to create interesting tiles.

Comments
  • Lots of updates, important optimizations, and enhancements

    Lots of updates, important optimizations, and enhancements

    1. Updates:
      • Updated Gradle Plugin to 1.3.0
      • Updated Gradle to 2.5
      • Updated Build Tools to 23.0.1
      • Updated the Target SDK to 23, and the compile API level to 23
      • Updated AppCompat to 23.0.1
    2. TypefaceHelper is used to avoid duplicate allocations of fonts. For an example, if you had a list of 1,000 items using TextDrawables, 1,000 Typefaces would be allocated before. Now, typefaces are cached and re-used.
      • I took this class from my own library, Material Dialogs (https://github.com/afollestad/material-dialogs). I originally did this at recommendation of Nova Launcher's developer.
    3. The default font (sans-serif-light) is only allocated if the user does not set their own font before making a call to build() or one of the variants of that method.
    4. Added versions of build methods that take resource IDs for colors and dimensions.
    5. Added annotations to builder method parameters to enforce the use of correct parameter values (e.g. numbers greater than 0, colors, dimensions, etc.)

    If you end up looking at this pull request, I'll put your original Bintray dependency back in the README. I'd recommend using JitPack.io instead though. Bintray is only useful if you actually publish to jCenter, which you don't.

    opened by afollestad 7
  • Convert TextDrawable to Bitmap generates no text

    Convert TextDrawable to Bitmap generates no text

    Hello, I am trying to generate a Bitmap from TextDrawable but the final result has no text, only appears the background.

    Here is my declaration and the function I use:

    Bitmap icon = Utilities.getBitmapFromUser(user);
    // ...
    TextDrawable userDrawable = TextDrawable.builder()
                    .buildRound(firstLetter, colors[i]);
    // ...
    public static Bitmap drawableToBitmap (Drawable drawable) {
            if (drawable instanceof BitmapDrawable) {
                return ((BitmapDrawable)drawable).getBitmap();
            }
    
            int width = drawable.getIntrinsicWidth();
            width = width > 0 ? width : 1;
            int height = drawable.getIntrinsicHeight();
            height = height > 0 ? height : 1;
    
            Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);
            drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
            drawable.draw(canvas);
    
            return bitmap;
        }
    

    Do you know any way to do it?

    opened by MarcAragones 5
  • Using AAR from gradle overrides app launcher icons

    Using AAR from gradle overrides app launcher icons

    When using as a BinTray dependency in Android Studio v1.0.1, app gets its main icon (ic_launcher) from this library instead of app's default icon. This results in app appearing with android-robot default icon.

    I've found posts in StackOverflow regarding this issue, but proposed solutions not worked from me.

    Please, remove ic_launcher icons from the generated AAR library. Thanks

    opened by pulimento 5
  • What about the performance of the listview with large number of items?

    What about the performance of the listview with large number of items?

    Calling

    TextDrawable drawable = TextDrawable.builder() .buildRect("A", Color.RED);

    continuously in any AdapterView will exhaust the app out of memory. How will this be handeled?

    opened by jaydeepw 2
  • Custom colors

    Custom colors

    Hi, thanks so much for the library. I have a small request, related to the random colors. The current implementation uses a fixed set of colors. Could you please add an option so that we can use our own?

    Thank you. :)

    opened by saket 2
  • Selected drawable like Gmail

    Selected drawable like Gmail

    Hey,

    Thank for such an amazing & simple to use library. I was checking the screenshots in the Readme & 2nd screenshot got my attention. It shows a list of items & few of them are selected & there is a selected image over the image view. I want to achieve that effect.

    Can you tell me how did you achieve it using your library?

    opened by AkshayChordiya 2
  • Unable to fetch artifact from maven repository

    Unable to fetch artifact from maven repository

    The directions in the README.md reference a personal maven repository which seems to no longer be available.

    repositories{
        maven {
            url 'http://dl.bintray.com/amulyakhare/maven'
        }
    }
    
    dependencies {
        compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
    }
    

    Gradle fails to build

    FAILURE: Build failed with an exception.
    
    * What went wrong:
    A problem occurred configuring project ':purecloud'.
    > Could not download com.amulyakhare.textdrawable.aar (com.amulyakhare:com.amulyakhare.textdrawable:1.0.1)
       > Could not get resource 'http://dl.bintray.com/amulyakhare/maven/com/amulyakhare/com.amulyakhare.textdrawable/1.0.1/com.amulyakhare.textdrawable-1.0.1.aar'.
          > Could not GET 'http://dl.bintray.com/amulyakhare/maven/com/amulyakhare/com.amulyakhare.textdrawable/1.0.1/com.amulyakhare.textdrawable-1.0.1.aar'. Received status code 401 from server: Unauthorized
    

    I'm able to work around this by removing the custom repository as shown above and obtaining the artifact from jcenter instead, since it seems to have been picked up there

    repositories{
        jcenter()
    }
    

    For the sake of the library's existing user base with build scripts depending on it, consider fixing the issue with the maven repository. If that is not possible, perhaps update the readme.

    opened by carltonwhitehead 1
  • This library is not working at all

    This library is not working at all

    Hello,

    I tried using this library for showing user initials in my app. But unfortunately, it seems that the library is not working and the code is broken. When I used it, it just shows a blank area where my ImageView is placed.

    Can you tell me that are you going to fix this library because there is no use of putting a library on Git which doesn't work at all. Let me know.

    opened by puneetagarwal 1
  • Cannot resolve .builder()

    Cannot resolve .builder()

    Android says that builder() cannot be resolved when I call TextDrawable.builder(). Does someone know the reason why?

    I want to use it with android wear 2.0

    opened by dfrits 0
  • Add support for emojis (Android 5.0 +)

    Add support for emojis (Android 5.0 +)

    I'm not sure if they've been added from Android 5.0 but is it possible to add support for emojis too? Some of them gets displayed correctly but the majority instead of showing the emojis displays a question mark, like in the screen attached.

    opened by Signoo 0
  • Can you please publish your library to a Maven Central ? I can offer you some help for this

    Can you please publish your library to a Maven Central ? I can offer you some help for this

    Rationale: https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/ Quote (from a link above):

    May 1st | Bintray, JCenter, GoCenter, and ChartCenter services will no longer be available

    Further more: it seems that Signal Android app depends on this library (fetched via Bintray): https://github.com/signalapp/Signal-Android/blob/v5.3.12/app/build.gradle#L37

        maven { // textdrawable
            url 'https://dl.bintray.com/amulyakhare/maven'
            content {
                includeGroupByRegex "com\\.amulyakhare.*"
            }
        }
    

    One more note: there is a slim chance that your library is also published to a springio-plugins-release but I will have to do some more research:

    • https://mvnrepository.com/artifact/com.amulyakhare/com.amulyakhare.textdrawable?repo=springio-plugins-release
    • https://repo.spring.io/webapp/#/artifacts/browse/tree/General/plugins-release
    opened by dejan2609 6
Owner
Amulya Khare
Amulya Khare
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 Jan 8, 2023
A periodic text updating library

RotatingText Rotating text is an Android library that can be used to make text switching painless and beautiful, with the use of interpolators, typefa

Mobile Development Group 1.6k Dec 30, 2022
A TextView that automatically resizes text to fit perfectly within its bounds.

AutoFitTextView A TextView that automatically resizes text to fit perfectly within its bounds. Usage dependencies { compile 'me.grantland:autofitt

Grantland Chew 4.2k Jan 8, 2023
: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
Floating hint from edit text - inspired by Matt D. Smith's design: http://dribbble.com/shots/1254439--GIF-Mobile-Form-Interaction?list=users

Float Labeled EditText Simple implementation of a Float Labeled EditText: An Android ViewGroup which uses a child EditText and puts the hint on top of

Wrapp Archive 1.1k Nov 14, 2022
A different beautiful Floating Edit Text

MaterialTextField A different beautiful Floating Edit Text Usage Surround your EditText by a MaterialTextField <com.github.florent37.materialtextfield

Florent CHAMPIGNY 1.5k Nov 11, 2022
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

Pavlos-Petros Tournaris 653 Nov 11, 2022
Include MatchTextView and MatchButton..Come..you will like it

Android MatchView This project is learned from (https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh) . Thanks for liaohuqiu.. I like the animat

Roger 858 Dec 7, 2022
Android Library to make it easy to create CodeEditor or IDE that support any languages and themes

CodeView Android Library to make it easy to create your CodeEditor or IDE for any programming language even for your programming language, just config

Amr Hesham 294 Jan 6, 2023
A lightweight Kotlin library for a form state management and field validation.

Chassis A lightweight Kotlin library for a form state management and field validation. Setup Library and it's snapshots are available on Maven Central

Bogusz Pawłowski 30 Dec 12, 2022
An easy, flexible way to add a shimmering effect to any view in an Android app.

Shimmer for Android Shimmer is an Android library that provides an easy way to add a shimmer effect to any view in your Android app. It is useful as a

Facebook 5.1k Dec 31, 2022
A TextView that simulates the effect from the app Secret where the characters fade in/out at different speeds.

SecretTextView A TextView that simulates the effect from the app Secret where the characters fade in/out at different speeds. How To Use Use it just l

Matt Kula 611 Nov 7, 2022
Android library to generate image avatar from the first letter of a username. Letter avatar like Gmail Android best practice

AvatarImageGenerator Generate first letter avatar Image like gmail's contact avatar. It generates an drawable that can be be set to an ImageView. Inst

Korir Amos 61 Sep 25, 2022
A library that extends the existing JDBC API so that data objects can be used as input (to set parameters) and output (from ResultSet's rows).

SqlObjectMapper This is a library that extends the existing JDBC API so that data objects can be used as input (to set parameters) and output (from Re

Qualified Cactus 2 Nov 7, 2022
🛠️ The missing drawable toolbox for Android. Create drawables programmatically and get rid of the boring and always repeated drawable.xml files.

DrawableToolbox English | 中文 The missing DrawableToolbox for Android. Create drawables programmatically and get rid of the boring and always repeated

Hong Duan 1.1k Jan 4, 2023
Annotation Processing Library. Generates proxy class on top of interface/abstract class, that allows to intercept calls. Also known as a design pattern: proxy, delegate, interceptor.

1. AutoProxy Annotation Processing Library. Generates proxy class on top of interface/abstract class, that allows to intercept calls. Also known as a

Oleksandr 19 Nov 24, 2022
Spantastic - an Android library that provides a simple and Kotlin fluent API for creating Android Spannable

Spantastic is an Android library that provides a simple and Kotlin fluent API for creating Android Spannable. This library wrappers SpannableStringBuilder and add methods to easily decorate the text with multiple spans.

Wellington Cabral da Silva 12 Nov 27, 2022
Gmail clone project, that uses Jetpack Compose to draw UI content for gmail home screen

Gmail clone project, that uses Jetpack Compose to draw UI content for gmail home screen following Udemy course: Android 12 Jetpack Compose Developer Course - From 0 To Hero

SaraAlshamy 3 Sep 2, 2022
Some beautiful android loading drawable, can be combined with any view as the LoadingView or the ProgressBar. Besides, some Drawable can customize the loading progress too.

LoadingDrawable: Android cool animation collection 前言 CircleRotate源码解析 Fish源码解析 LoadingDrawable is some android animations implement of drawable: a li

dinus_developer 4.1k Dec 27, 2022