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
DMIV aims to provide a flexible and customizable instrument for automated images moving on display. It provides scroll, gyroscope or time based moving. But you can create your own evaluator.

DexMovingImageView DMIV aims to provide a flexible and customizable instrument for automated images moving on display. It provides scroll, gyroscope o

Diego Grancini 310 Feb 7, 2022
Subclass of ImageView that 'morphs' into a circle shape and can rotates. Useful to be used as album cover in Music apps. :dvd::notes:

Music Cover View A Subclass of ImageView that 'morphs' into a circle shape and can rotates. Useful to be used as album cover in Music apps. It's used

André Mion 254 Dec 23, 2022
Android ImageView that handles animated GIF images

GifImageView Android ImageView that handles Animated GIF images Usage In your build.gradle file: dependencies { compile 'com.felipecsl:gifimageview:

Felipe Lima 1.1k Mar 9, 2021
A library for Android provides blurred drop shadows to ImageView similar to iOS image backdrop shadows

A library for Android provides blurred drop shadows to ImageView similar to iOS image backdrop shadows.Provides fast canvas draw as no renderscript needed .The similar shadow blurred effects can also be seen in iOS Music App.

Vivek Verma 163 Dec 31, 2022
Flickable ImageView for Android. It's like a view of twitter's detail image.

FlickableView Flickable ImageView for Android. It's like a view of twitter's detail image. It's possible that other views animate with FlickableView.

goka 153 Nov 14, 2022
Custom shaped android imageview components

Shape Image View Provides a set of custom shaped android imageview components, and a framework to define more shapes. Implements both shader and bitma

Siyamed SINIR 2.6k Mar 29, 2021
Custom ImageView for moving image around the screen (Android)

MovingImageView Create a custom ImageView for moving image around the screen. Usage To use MovingImageView, add the module into your project and start

Albert Grobas 819 Nov 18, 2022
Custom ImageView for android with polygon shape (Android)

PolygonImageView Create a custom ImageView with polygonal forms. Usage To use PolygonImageView, add the module into your project and start to build xm

Albert Grobas 531 Dec 25, 2022
Custom ImageView to generate captcha image.

CaptchaImageView Custom ImageView to generate captcha image. Add CaptchaImageView to your layout <test.jinesh.captchaimageviewlib.CaptchaImageView

Jinesh Francis 610 Oct 18, 2022
A gallery used to host an array of images

ImageGallery Overview A gallery used to host an array of images You can add one or more images to the gallery Support for using Palette to set the bac

Etienne Lawlor 645 Dec 18, 2022
Custom view for circular images in Android while maintaining the best draw performance

CircularImageView Custom view for circular images in Android while maintaining the best draw performance Usage To make a circular ImageView, add this

Pkmmte Xeleon 1.2k Dec 28, 2022
Visual back-port of the rotating drawer-to-arrow drawable from Android L

DrawerArrowDrawable A simple drawable backport of the new drawer-indicator/back-arrow rotating drawable from the upcoming Android L. License Copyright

Chris Renke 827 Nov 25, 2022
Drawable animation inspired by Tinder.

WaveDrawable Drawable animation inspired by Tinder. Download compile 'me.alexrs:wave-drawable:1.0.0' LinearInterpolator BounceInterpolator CycleInterp

Alejandro Rodríguez Salamanca 213 Oct 11, 2022
Drawable animation inspired by Tinder.

WaveDrawable Drawable animation inspired by Tinder. Download compile 'me.alexrs:wave-drawable:1.0.0' LinearInterpolator BounceInterpolator CycleInterp

Alejandro Rodríguez Salamanca 213 Oct 11, 2022
ImageView and FrameLayout with gestures control and position animation

GestureViews ImageView and FrameLayout with gestures control and position animation. Main goal of this library is to make images viewing process as sm

Alex Vasilkov 2.3k Dec 30, 2022
PinchToZoom - Pinch to zoom used within list like Instagram

Pinch To Zoom ?? Description Pinch to Zoom with Pan Gestures like Instagram ?? Motivation and Context Big Thanks ???? to the guy and his amazing repo

Vivek Sharma 12 Apr 12, 2022
Android ImageView widget with zoom and pan capabilities

ImageViewTouch for Android ImageViewTouch is an android ImageView widget with zoom and pan capabilities. This is an implementation of the ImageView wi

Alessandro Crugnola 1.9k Jan 4, 2023
Crop and Rounded Corners added to an ImageView.

SuperImageView Extra features for your ImageView provided in a modularized way Documentation for v2 coming this week. CropImageView An ImageView that

César Díez Sánchez 657 Jan 5, 2023
Create parallax and any other transformation effects on scrolling android ImageView

Android Parallax Image View Creates effect such as vertical parallax, horizontal parallax etc. on android ImageView when it's being vertically or hori

Aris 164 Dec 7, 2022