Coder Social home page Coder Social logo

Comments (10)

vinc3m1 avatar vinc3m1 commented on July 22, 2024

There is already support for setImageResource, but it's not very efficient and effectively sets the drawable twice: https://github.com/vinc3m1/RoundedImageView/blob/master/roundedimageview/src/com/makeramen/RoundedImageView.java#L262

Actually, holding the resource id isn't that bad, I'm not sure why I didn't do that in the first place... I think I got it confused with setImageURI

from roundedimageview.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 22, 2024

maybe that's because i've done a checkout a long time ago that i couldn't see this function and added my "patch" to it.

maybe you should look at the android code of imageView and get other ideas? even though their code is quite large, it could help you with possible optimizations...

from roundedimageview.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 22, 2024

I think my code suggestion is flawed. Not sure what's the reason.

from roundedimageview.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 22, 2024

I think this could be the correct changes:

@OverRide
public void setImageDrawable(final Drawable drawable) {
mResId = 0;
if (drawable != null) {
mDrawable = RoundedDrawable.fromDrawable(drawable);
updateDrawableAttrs();
} else {
mDrawable = null;
}
super.setImageDrawable(mDrawable);
}

@OverRide
public void setImageBitmap(final Bitmap bm) {
mResId = 0;
if (bm != null) {
mDrawable = new RoundedDrawable(bm);
updateDrawableAttrs();
} else {
mDrawable = null;
}
super.setImageDrawable(mDrawable);
}

@OverRide
public void setImageResource(final int resId) {
if (mResId == resId && resId != 0)
return;
if (resId == 0)
setImageDrawable(null);
else
setImageDrawable(getResources().getDrawable(resId));
mResId = resId;
}

from roundedimageview.

vinc3m1 avatar vinc3m1 commented on July 22, 2024

see 97b04ea

Should theoretically be faster, but might not be complete if getResources() is ever null for some reason...

from roundedimageview.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 22, 2024

on which cases getResources returns null?
i don't think it's possible...

from roundedimageview.

vinc3m1 avatar vinc3m1 commented on July 22, 2024

Not sure, but there's a null check in resolveUri in ImageView.java source.

from roundedimageview.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 22, 2024

weird.

anyway, so now the code on this library is better, and uses the resources' drawable in a better way?

from roundedimageview.

vinc3m1 avatar vinc3m1 commented on July 22, 2024

it should, but the way it was working before was fine too

from roundedimageview.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 22, 2024

thanks.

from roundedimageview.

Related Issues (20)

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.