GithubHelp home page GithubHelp logo

amulyakhare / textdrawable Goto Github PK

View Code? Open in Web Editor NEW
3.2K 119.0 612.0 1.12 MB

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.

License: MIT License

Java 100.00%

textdrawable's Introduction

###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.

textdrawable's People

Contributors

amulyakhare avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

textdrawable's Issues

Color Generator Config

Hello,

Thanks for such a great and nice lib that you have created. It saved a lot of time.

Just wanted to know whether it is possible for the ColorGenerator Class to generate only dark color. So, if I want Red Color so it has to be RED but with the with dark material color such as RED500 , RED600 aur so.

Please let me know so that it can be helpful

Avatars are not rounded on API 16

I am using this library to built simple rounded avatars this way:
TextDrawable.builder().buildRound(letter, backgroundColor.toColor())
Everythings works fine on API =< 21. Unfortunately it is not working on API 16. It creates rectangle avatars instead. Do you have any idea how to solve it?

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.

Wont work with Glide...

                        TextDrawable drawable = TextDrawable.builder()
                                .buildRect(takeoffUserProfileModel.displayName, Color.RED);
                        
                        Glide.with(context).load(drawable.getCurrent()).into(
                                profilePhotoImageView);

and throws

java.lang.IllegalArgumentException: Unknown type class com.amulyakhare.textdrawable.TextDrawable. You must provide a Model of a type for which there is a registered ModelLoader, if you are using a custom model, you must first call Glide#register with a ModelLoaderFactory for your custom model class

any solutions?

Generate specific group of Color

Hi Thanks for your well written Lib;)
is it possible to generate a group of specific colors ? for example some light blue colors ?
in your color generator when i use Key for generating color it's give me some color which is not proper for my app theme , i want to know is it possible to change this ?

Thanks.

Can import into AS, but can't use class

I did add TextDawerable as library in Android Studio, but somehow I can't use these classes like ColorGenerator, I don't know it's AS's problem or the jar file, or me?

Cannot resolve dependency with gradle

Whatever I try, I always get

Error:(28, 13) Failed to resolve: com.amulyakhare:com.amulyakhare.textdrawable:1.0.1
Show in File  
Show in Project Structure dialog

I tried all combinations of

repositories {
    jcenter()
    mavenCentral()
}

put them in both gradle files. In buildscript {}, in allprojects{} and in the root of the app's gradle, it simply won't work. I can resolve any other 3rd party dependecy, but not this one.

I don't know if more people have experienced this issue, I can't find anything on google. Any help is greatly appreciated.

Gradle version is 1.3.0

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.

Does not scale with material transitions

When I use a transition like changeImageBounds the outcome is much outcentered. When I call the activity without makeSceneTransitionAnimation, the TextDrawable is scaled correctly.

Video

Display in SimpleAdapter in Fragment

I have a data coming from Remote database (MySQL), which i set to the SimpleAdapter and then this adapter to ListView.
How do i set TextDrawable to the SimpleAdapter

Below is my HomeFragment which includes everything:

` @OverRide
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_home, container, false);

   mainListView = (ListView) rootView.findViewById(R.id.newsListView);


    //Circular image
    TextDrawable drawable1 = TextDrawable.builder().beginConfig().
            withBorder(4).textColor(Color.RED).useFont(Typeface.DEFAULT).fontSize(30).bold().toUpperCase()
            .endConfig().buildRoundRect("A", Color.GREEN, 10);

    ColorGenerator generator = ColorGenerator.MATERIAL;
    int color1 = generator.getRandomColor();

    TextDrawable.IBuilder builder = TextDrawable.builder().beginConfig().withBorder(4).endConfig().rect();
    TextDrawable ic1 = builder.build("A", color1);

    View justAview = inflater.inflate(R.layout.list_homefragment, container, false);
    image = (ImageView)justAview.findViewById(R.id.image_view);
    image.setImageDrawable(drawable1);

    //End


    new getHomeFragmentList().execute();



    String up = "▲";
    String down = "▼";



    //Getting Data From ListView on onClick
    mainListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {


           // String text = mainListView.getItemAtPosition(position).toString();

            TextView pname = (TextView) view.findViewById(R.id.FNAME);
            String pName = pname.getText().toString();

            /*TextView pid = (TextView) view.findViewById(android.R.id.text2);
            String pID = pid.getText().toString();*/

            //Toast.makeText(getActivity(), "Name:" + pName + "\n ID:" + pID, Toast.LENGTH_SHORT).show();

            //Sending Data To DetailViewFragment
            DetailViewFragment DVF = new DetailViewFragment();
            Bundle something = new Bundle();
            something.putString("key", pName); //takes <Key, Value> pair
            DVF.setArguments(something);
            //Now Commit Transaction
            getFragmentManager().beginTransaction().replace(R.id.fragment_container, DVF).addToBackStack(null).commit();
            //END


        }
    });
    // END
    return rootView;


}


private class getHomeFragmentList extends AsyncTask<Void, Void, String>
{
    ProgressDialog pDialog;

    @Override
    protected void onPreExecute() {
        pDialog = ProgressDialog.show(HomeFragment.this.getActivity(), "Please Wait...", "" , false, false);
    }

    @Override
    protected String doInBackground(Void... params) {
        RequestHandler rh = new RequestHandler();

        String data = rh.sendGetRequest(Configuration.URL_GET_HOMEFragmentList);
        Log.d("Received Data", ":" + data);
        if(data !=null)
        {

            JSONArray jsonArray = null;
            try {
                jsonArray = new JSONArray(data);

                for (int i=0; i<jsonArray.length();i++)
                {
                    JSONObject jo = jsonArray.getJSONObject(i);

                    String pid = jo.getString(pID);
                    String fname = jo.getString(fNAME);
                    String lname = jo.getString(lNAME);
                    String brreading = jo.getString(BRREADING);
                    String bsrdate = jo.getString(BSRDATE);
                    String bsrtime = jo.getString(BSRTIME);



                    HashMap<String, String> hashMap = new HashMap<>();
                    hashMap.put()
                    hashMap.put(fNAME, fname);
                    hashMap.put(lNAME, lname);
                    hashMap.put(BRREADING, brreading);
                    hashMap.put(BSRDATE, bsrdate);
                    hashMap.put(BSRTIME, bsrtime);




                    homepatientList.add(hashMap);
                }

            } catch (JSONException e) {
                e.printStackTrace();
            }

        }else
        {
            Log.v("", "No Data from URL");
        }


        return null;
    }


    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        pDialog.dismiss();

        mainlistAdapter = new SimpleAdapter(getActivity(), homepatientList, R.layout.list_homefragment,
        new String[] {fNAME,lNAME,BRREADING, BSRDATE, BSRTIME}, new int[]{R.id.FNAME, R.id.LNAME, R.id.READING, R.id.DATE, R.id.TIME});
        mainListView.setAdapter(mainlistAdapter);
    }
}`

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

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?

Way to specify a custom path

Could the builder pattern allow us to specify any Path? That way we could do triangles, hexagons, etc. easily.

How to change background and text color same time?

Hi
I'm using your Repo.I try to change background and text color same time.How I can do this?
Here is my source

` public void setDrawableText(String text, int fontSize, int textColor,int backgroundColor) {
drawable = TextDrawable.builder().
beginConfig().
fontSize(fontSize).toUpperCase().
useFont(typeface).
endConfig().
buildRound(text, textColor);

    if (imageView != null && drawable != null)
        imageView.setImageDrawable(drawable);
}`

Library is very memory inefficient

It's pretty irresponsible based on how many people use this library.


This library allocates Typefaces over and over again rather than caching them, resulting in a lot of memory usage. You should be caching Typefaces using something like TypefaceHelper.

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.

The letter is missing in the image.

Hi,

I am creating TextDrawable in following way, but the resulting image doesn't contain the letter. Could you please check what i am missing.

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

compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'

ColorGenerator generator = ColorGenerator.MATERIAL; // or use DEFAULT
// generate random color
int color1 = generator.getRandomColor();
TextDrawable drawable = TextDrawable.builder()
.beginConfig()
.width(50) // width in px
.height(50) // height in px
.endConfig()
.buildRound("X", color1);

leftImage.setImageDrawable(drawable);

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. :)

Does not work with vinc3m1/RoundedImageView

imageView = (RoundedImageView) findViewById(R.id.imageView1);
int mineColor = getResources().getColor(R.color.thumbnail_bg_one);
TextDrawable drawable;
drawable = TextDrawable.builder().buildRoundRect("R", mineColor, 6);
imageView.setImageDrawable(drawable);

The RoundedImageView only has a background but not text is draw.

How to set border color?

TextDrawable.builder()
.beginConfig()
.withBorder(4) /* thickness in px */
.toUpperCase()
.endConfig()
.buildRound("AB", color);

How to set this border color?

Can not be used in the RadioButton?

Invalid setting with Border.
TextDrawable drawable = TextDrawable.builder() .beginConfig() .width(com.duia.duiba.kjb_lib.util.KJBUtils.dip2px(context , 17)) .height(com.duia.duiba.kjb_lib.util.KJBUtils.dip2px(context , 17)) .withBorder(com.duia.duiba.kjb_lib.util.KJBUtils.dip2px(context , 2)) .endConfig() .buildRound("F", 0xff64b5f6); radioButton.setCompoundDrawables(drawable , null , null , null);

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?

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

thk

very good Just what I needed, thank you!!!

Maven Central

Please add this to Maven Central / Bintray / Jcenter

Crashes on AIDE when app starts

I only use AIDE on my nexus 5. Everytime a textdrawable or colorgenerator created, the app crashes. No logcat output so I can't tell why it's crashing. It's not in my code cause when I comment the textdrawable initialization code, my app does not crash.

Sample code that crashes my app:
TextDrawable drawable = TextDrawable.builder()
.buildRect("A", Color.RED);
ColorGenerator mGenerator = ColorGenerator.MATERIAL;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.