Reputation: 1302
I need to set an image to an ImageSwitcher by downloading it from server. But the universal image loader seems to take ImageView as a parameter.
I read that we can use ImageAware to display image on any android view.
Can someone help me how to go about this ?
Thanks, Sneha
Upvotes: 0
Views: 1167
Reputation: 541
you can check that Loader display image for ImageAware finally
the code displayImage(String,ImageView) is below
public void displayImage(String uri, ImageView imageView) { this.displayImage(uri, (ImageAware)(new ImageViewAware(imageView)), (DisplayImageOptions)null, (ImageLoadingListener)null, (ImageLoadingProgressListener)null); }
And the ImageAware extends the abstract class ViewAware,here is the two important methods in it
protected abstract void setImageDrawableInto(Drawable var1, View var2);
protected abstract void setImageBitmapInto(Bitmap var1, View var2);
check the two method implement by ImageAware
protected void setImageDrawableInto(Drawable drawable, View view) {
((ImageView)view).setImageDrawable(drawable);
if(drawable instanceof AnimationDrawable) {
((AnimationDrawable)drawable).start();
}
}
protected void setImageBitmapInto(Bitmap bitmap, View view) {
((ImageView)view).setImageBitmap(bitmap);
}
so you can see that the ImageView use setImageBitmap to display bitmap,while the other view will use setBackground,here is my class for other view
public class CustomViewAware extends ViewAware {
public CustomViewAware(View view) {
super(view);
}
@Override
protected void setImageDrawableInto(Drawable drawable, View view) {
view.setBackgroundDrawable(drawable);
}
@Override
protected void setImageBitmapInto(Bitmap bitmap, View view) {
view.setBackgroundDrawable(new BitmapDrawable(bitmap));
}
Upvotes: 0
Reputation: 12407
You also can wrap your view with ImageAware
interface. And then you can pass this wrapper into displayImage(...)
method.
You can look into ImageViewAware
to understand how it wraps ImageView
. So you can wrap any view in the same way.
Upvotes: 0
Reputation: 20500
Use loadImage
instead. That will get you a bitmap that you can use to do whatever you want with it.
// Load image, decode it to Bitmap and return Bitmap to callback
imageLoader.loadImage(imageUri, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
// Do whatever you want with Bitmap
}
});
Upvotes: 1