Coder Social home page Coder Social logo

Support for Picasso about roundedimageview HOT 13 CLOSED

vinc3m1 avatar vinc3m1 commented on July 3, 2024
Support for Picasso

from roundedimageview.

Comments (13)

dexcell avatar dexcell commented on July 3, 2024

Please make it also work for ion
https://github.com/koush/ion

My current problem is:
I have RoundedImageView in ListView item,
The image view just wont changed after it downloaded the image from internet and it wait until the listview redrawed again before it update it's image view.

For example:
In ActivityOne i have RoundedImageView loaded using ion / picasso, then after it downloaded the image it won't refreshed the image after i go to ActivityTwo and go back to ActivityOne.

from roundedimageview.

maciekish avatar maciekish commented on July 3, 2024

+1 on Picasso support. First time around it doesn't show the image, and when you try loading it again then it pops up.

from roundedimageview.

dexcell avatar dexcell commented on July 3, 2024

Probably this old code of yours works with current Picasso version, but it doesn't work with ion.
Maybe you will get some hint?

https://gist.github.com/dexcell/ecf70cf8f3024932094f
https://gist.github.com/dexcell/836d72745aa3b5c08756

from roundedimageview.

vinc3m1 avatar vinc3m1 commented on July 3, 2024

Both Picasso and RoundedImageView use custom drawables, so I'd have to make a custom RoundedPicassoDrawable which has a dependency on Picasso, and would probably be released as a separate add-on package

from roundedimageview.

vinc3m1 avatar vinc3m1 commented on July 3, 2024

I looked into solutions, but due to private packages in Picasso, it's difficult to correctly access the bitmaps and sources of a PicassoDrawable. For now, if you use .noFade() it will work, but it is still creating an extra bitmap through drawableToBitmap().

from roundedimageview.

vinc3m1 avatar vinc3m1 commented on July 3, 2024

Maybe @JakeWharton can chime in on best possible solutions?

from roundedimageview.

JakeWharton avatar JakeWharton commented on July 3, 2024

I just create a Picasso Transformation which does the rounding and don't even bother with a library.

from roundedimageview.

vinc3m1 avatar vinc3m1 commented on July 3, 2024

Thanks Jake, I didn't notice that class existed. Seems like Ion has a similar Transform class that can be used the same way. I added a toBitmap() helper function on RoundedDrawable that makes it fairly trivial to make a Transformation. There is now a PicassoActivity example that shows this, but the following is the main logic:

private final Transformation mTransformation = new Transformation() {

  final float radius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 30, getResources().getDisplayMetrics());
  final int border = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3, getResources().getDisplayMetrics());
  final boolean oval = false;
  final int color = Color.BLACK;

  @Override public Bitmap transform(Bitmap bitmap) {
    Bitmap transformed = RoundedDrawable.fromBitmap(bitmap)
        .setBorderColor(color)
        .setBorderWidth(border)
        .setCornerRadius(radius)
        .setOval(oval)
        .toBitmap();
    if (!bitmap.equals(transformed)) {
      bitmap.recycle();
    }
    return transformed;
  }

  @Override public String key() {
    return "rounded_radius_" + radius + "_border_" + border + "_color_" + color +  "_oval_" + oval ;
  }
};

// Later in your adapter...
Picasso.with(PicassoActivity.this)
    .load(item.mUrl)
    .fit()
    .transform(mTransformation)
    .into(imageView);

from roundedimageview.

vinc3m1 avatar vinc3m1 commented on July 3, 2024

Also toBitmap() is just a wrapper for RoundedDrawable.drawableToBitmap() so older releases can already support Picasso with:

Bitmap transformed = RoundedDrawable.drawableToBitmap(
                  RoundedDrawable.fromBitmap(bitmap)
                      .setBorderColor(color)
                      .setBorderWidth(border)
                      .setCornerRadius(radius)
                      .setOval(oval));

from roundedimageview.

Bencodes avatar Bencodes commented on July 3, 2024

👍

from roundedimageview.

JakeWharton avatar JakeWharton commented on July 3, 2024

Awesome! Just a nit: you shouldn't create the transformation every time. It should be thread safe and only created once.

from roundedimageview.

vinc3m1 avatar vinc3m1 commented on July 3, 2024

Agreed, updated. I figured it was enough for demo purposes, but probably a good idea to make examples with best practices :)

from roundedimageview.

JakeWharton avatar JakeWharton commented on July 3, 2024

Haha yeah. People love to copy/paste.


Jake Wharton
http://about.me/jakewharton

On Tue, Jan 21, 2014 at 3:37 PM, Vince Mi [email protected] wrote:

Agreed, updatedhttps://github.com/vinc3m1/RoundedImageView/commit/45ea8ffb11e2df6484e9f627e8302814bb544864.
I figured it was enough for demo purposes, but probably a good idea to make
examples with best practices :)


Reply to this email directly or view it on GitHubhttps://github.com//issues/20#issuecomment-32977120
.

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.