Skip to content
This repository has been archived by the owner on Jan 27, 2023. It is now read-only.

ColorDrawable support #30

Closed
hamidp opened this issue Feb 7, 2014 · 13 comments
Closed

ColorDrawable support #30

hamidp opened this issue Feb 7, 2014 · 13 comments
Assignees

Comments

@hamidp
Copy link

hamidp commented Feb 7, 2014

No description provided.

@vinc3m1 vinc3m1 self-assigned this Feb 9, 2014
@vinc3m1
Copy link
Owner

vinc3m1 commented Feb 9, 2014

If you don't mind testing, please update your dependencies to use the snapshot and let me know how it performs:

repositories {
    mavenCentral()
    maven {
        url "https://oss.sonatype.org/content/repositories/snapshots"
    }
}
dependencies {
    compile 'com.makeramen:roundedimageview:1.2.4-SNAPSHOT'
}

@hamidp
Copy link
Author

hamidp commented Feb 9, 2014

Will try it out.

I actually ended up implementing a RoundedColorDrawable that works very well that I had planned to PR

@thevery
Copy link

thevery commented Feb 9, 2014

doesn't work for me with custom drawable (it seems that wrong canvas size (1x1) is passed)

@vinc3m1
Copy link
Owner

vinc3m1 commented Feb 9, 2014

what custom drawable are you passing in?

@thevery
Copy link

thevery commented Feb 9, 2014

nothing very special, just public class AvatarDrawable extends Drawable with it's own onDraw implementation with some drawText's.

@vinc3m1
Copy link
Owner

vinc3m1 commented Feb 9, 2014

Ah, I would do one of 2 things:

  • Return a value > 1 in getInstrinsicHeight() and getIntrinsicWidth(). This method would fix the canvas size of 1 issue, but whatever size you return will be the size of the bitmap that gets drawn, and later stretched to fit (probably not what you want).
  • Instead I recommend extending RoundedImageDrawable instead of Drawable and simply doing your text drawing after calling super.onDraw

@thevery
Copy link

thevery commented Feb 9, 2014

first one is obviously not a solution, neither is the second one - I must call super(null); in constructor and this causes NPE.
NB: I override draw, not onDraw in Drawable (later one is for View).

@vinc3m1
Copy link
Owner

vinc3m1 commented Feb 9, 2014

why must you call super(null)? you can just let RoundedDrawable handle the bitmap part of your avatar, so call super.draw(canvas) and just use super.setBitmap() (or res or drawable).

Otherwise if you're already doing all the custom drawing just do canvas.drawCircle(cx, cy, r, bitmapPaint) and you don't even need this library...

@thevery
Copy link

thevery commented Feb 9, 2014

I don't have any bitmap part of avatar.
All custom drawing (and especially round cropping) is already done, but using some library will make my code much more simple.

@vinc3m1
Copy link
Owner

vinc3m1 commented Feb 9, 2014

This library is a convenience for people who don't want to write custom views and specifically optimizes for the case of rounded bitmaps. It's not meant to augment custom views/drawables well since the behavior most custom views is, well... very custom. It's impossible to predict how all custom views will work and accommodate for all of them.

Like I said, if your view has extra behavior on top of being rounded, I suggest extending or forking this library to reuse the code, otherwise supporting arbitrary custom drawables and views is not the aim of this library.

@hamidp
Copy link
Author

hamidp commented Feb 10, 2014

Snapshot build does round the corners for us on color drawables. Once it's officially released we'll switch to using it.

Thanks!

@vinc3m1
Copy link
Owner

vinc3m1 commented Feb 10, 2014

Cool, there are still some bugs I can't seem to hunt down (see example app), but if it works for most cases I'll push up the new version now.

@vinc3m1 vinc3m1 closed this as completed Feb 10, 2014
@thevery
Copy link

thevery commented Feb 10, 2014

@vinc3m1 I fully agree on your points about limited features support and forking, the only problem is that you realize limitations only after the first run and spend useless efforts on adding library to your project.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants